Skip to content

Commit de8a4b1

Browse files
committed
Use isNull message and NULL C constant in {call_}mmap
1 parent 0f0dd22 commit de8a4b1

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

graalpython/com.oracle.graal.python.cext/posix/posix.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ int32_t call_system(const char *pathname) {
508508

509509
void *call_mmap(int64_t length, int32_t prot, int32_t flags, int32_t fd, int64_t offset) {
510510
void *result = mmap(NULL, length, prot, flags, fd, offset);
511-
return result == MAP_FAILED ? 0 : result;
511+
return result == MAP_FAILED ? NULL : result;
512512
}
513513

514514
int32_t call_munmap(void* address, int64_t length) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/NFIPosixSupport.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,14 +1152,8 @@ public MMapHandle(Object pointer, long length) {
11521152
public Object mmap(long length, int prot, int flags, int fd, long offset,
11531153
@Shared("invoke") @Cached InvokeNativeFunction invokeNode) throws PosixException {
11541154
Object address = invokeNode.call(this, PosixNativeFunction.call_mmap, length, prot, flags, fd, offset);
1155-
try {
1156-
InteropLibrary interop = invokeNode.getResultInterop();
1157-
if (interop.fitsInInt(address) &&
1158-
interop.asInt(address) == 0) {
1159-
throw newPosixException(invokeNode, getErrno(invokeNode));
1160-
}
1161-
} catch (UnsupportedMessageException e) {
1162-
throw CompilerDirectives.shouldNotReachHere(e);
1155+
if (invokeNode.getResultInterop().isNull(address)) {
1156+
throw newPosixException(invokeNode, getErrno(invokeNode));
11631157
}
11641158
return new MMapHandle(address, length);
11651159
}

0 commit comments

Comments
 (0)