Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/downstream-test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ runs:
if: ${{ inputs.platform == 'macos' }}
shell: bash
run: |
tarball="$(curl -sH "Authorization: token $GITHUB_TOKEN" "https://api.github.com/repos/graalvm/graalvm-ce-dev-builds/releases/latest" | jq -r --arg artifact "graalpy-community-dev-${{ inputs.platform }}-${{ inputs.arch }}.tar.gz" '.assets[] | select(.name == $artifact) | .browser_download_url')"
tarball="$(curl -sH "Authorization: token $GITHUB_TOKEN" "https://api.github.com/repos/graalvm/graalvm-ce-dev-builds/releases/latest" | jq -r --arg platform "${{ inputs.platform }}" --arg arch "${{ inputs.arch }}" 'first(.assets[] | select(.name | test("^graalpy[0-9.]+-community-dev-\($platform)-\($arch)\\.(tar\\.gz|zip)$")) | .browser_download_url)')"
curl -sfL "$tarball" | tar xz

- name: Get GraalPy build artifact
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,4 @@ compile_commands.json
.codex
opencode.json
pyrightconfig.json
bench-results.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -123,6 +123,7 @@
import com.oracle.graal.python.runtime.PosixSupportLibrary.Inet6SockAddr;
import com.oracle.graal.python.runtime.PosixSupportLibrary.InvalidAddressException;
import com.oracle.graal.python.runtime.PosixSupportLibrary.InvalidUnixSocketPathException;
import com.oracle.graal.python.runtime.PosixSupportLibrary.PosixErrnoException;
import com.oracle.graal.python.runtime.PosixSupportLibrary.PosixException;
import com.oracle.graal.python.runtime.PosixSupportLibrary.RecvfromResult;
import com.oracle.graal.python.runtime.PosixSupportLibrary.SelectResult;
Expand Down Expand Up @@ -170,20 +171,20 @@ public void setUp() {
}

@Test
public void fillUniversalSockAddrInet4() {
public void fillUniversalSockAddrInet4() throws PosixException {
Inet4SockAddr addr = new Inet4SockAddr(12345, INADDR_LOOPBACK.value);
checkUsa(addr, createUsa(addr));
}

@Test
public void fillUniversalSockAddrInet6() {
public void fillUniversalSockAddrInet6() throws PosixException {
assumeTrue(isInet6Supported());
Inet6SockAddr addr = new Inet6SockAddr(12345, IN6ADDR_LOOPBACK, 12, 1);
checkUsa(addr, createUsa(addr));
}

@Test
public void fillUniversalSockAddrUnix() {
public void fillUniversalSockAddrUnix() throws PosixException {
assumeTrue("native".equals(backendName));
byte[] path = new byte[]{65, 0};
UnixSockAddr addr = new UnixSockAddr(path);
Expand Down Expand Up @@ -638,7 +639,7 @@ public void nonBlockingAccept() throws PosixException {
lib.accept(posixSupport, srv.fd);
fail("Expected accept() to fail with EWOULDBLOCK");
} catch (PosixException e) {
assertEquals(OSErrorEnum.EWOULDBLOCK.getNumber(), e.getErrorCode());
assertTrue(e.hasErrno(OSErrorEnum.EWOULDBLOCK));
}
cli.connect(srv.usa());
srv.accept(cli.address());
Expand Down Expand Up @@ -698,7 +699,7 @@ public void streamSelect() throws PosixException {
}

@Test
public void getnameinfo() throws GetAddrInfoException {
public void getnameinfo() throws PosixException, GetAddrInfoException {
Object[] res = lib.getnameinfo(posixSupport, createUsa(new Inet6SockAddr(443, IN6ADDR_LOOPBACK, 0, 0)), NI_NUMERICSERV.value | NI_NUMERICHOST.value);
assertThat(p2s(res[0]), anyOf(equalTo("::1"), equalTo("0:0:0:0:0:0:0:1%0")));
assertEquals("443", p2s(res[1]));
Expand All @@ -712,7 +713,7 @@ public void getnameinfo() throws GetAddrInfoException {
}

@Test
public void getnameinfoUdp() throws GetAddrInfoException {
public void getnameinfoUdp() throws PosixException, GetAddrInfoException {
assumeTrue(runsOnLinux());
Object[] res = lib.getnameinfo(posixSupport, createUsa(new Inet4SockAddr(512, INADDR_LOOPBACK.value)), NI_NUMERICHOST.value);
assertEquals("exec", p2s(res[1]));
Expand Down Expand Up @@ -774,7 +775,7 @@ public void getaddrinfoBadFlags() {
}

@Test
public void getaddrinfoServiceOnly() throws GetAddrInfoException {
public void getaddrinfoServiceOnly() throws PosixException, GetAddrInfoException {
Object service = s2p("https");
AddrInfoCursor aic = lib.getaddrinfo(posixSupport, null, service, AF_UNSPEC.value, SOCK_STREAM.value, 0, 0);
cleanup.add(() -> aicLib.release(aic));
Expand All @@ -795,7 +796,7 @@ public void getaddrinfoServiceOnly() throws GetAddrInfoException {
}

@Test
public void getaddrinfoPassive() throws GetAddrInfoException {
public void getaddrinfoPassive() throws PosixException, GetAddrInfoException {
Object service = s2p("https");
AddrInfoCursor aic = lib.getaddrinfo(posixSupport, null, service, AF_INET.value, 0, IPPROTO_TCP.value, AI_PASSIVE.value);
cleanup.add(() -> aicLib.release(aic));
Expand All @@ -811,7 +812,7 @@ public void getaddrinfoPassive() throws GetAddrInfoException {
}

@Test
public void getaddrinfoServerOnlyNoCanon() throws GetAddrInfoException {
public void getaddrinfoServerOnlyNoCanon() throws PosixException, GetAddrInfoException {
Object node = s2p("localhost");
AddrInfoCursor aic = lib.getaddrinfo(posixSupport, node, null, AF_UNSPEC.value, SOCK_DGRAM.value, 0, 0);
cleanup.add(() -> aicLib.release(aic));
Expand All @@ -831,7 +832,7 @@ public void getaddrinfoServerOnlyNoCanon() throws GetAddrInfoException {
}

@Test
public void getaddrinfo() throws GetAddrInfoException {
public void getaddrinfo() throws PosixException, GetAddrInfoException {
Object node = s2p("localhost");
Object service = s2p("https");
AddrInfoCursor aic = lib.getaddrinfo(posixSupport, node, service, AF_INET.value, 0, IPPROTO_TCP.value, AI_CANONNAME.value);
Expand Down Expand Up @@ -1066,7 +1067,7 @@ private String p2s(Object p) {
}

private static void expectErrno(ThrowingRunnable runnable, OSErrorEnum... expectedErrorCodes) {
PosixException exception = Assert.assertThrows(PosixException.class, runnable);
PosixErrnoException exception = Assert.assertThrows(PosixErrnoException.class, runnable);
if (Stream.of(expectedErrorCodes).noneMatch(e -> exception.getErrorCode() == e.getNumber())) {
String names = Stream.of(expectedErrorCodes).map(OSErrorEnum::name).collect(Collectors.joining(" or "));
fail("Expected PosixException with error code " + names + " but the actual error code was " + exception.getErrorCode() + " (" + exception + ")");
Expand All @@ -1086,7 +1087,7 @@ private int createSocket(int family, int type, int protocol) throws PosixExcepti
return sockfd;
}

private UniversalSockAddr createUsa(FamilySpecificSockAddr src) {
private UniversalSockAddr createUsa(FamilySpecificSockAddr src) throws PosixException {
if (src instanceof Inet4SockAddr inet4SockAddr) {
return lib.createUniversalSockAddrInet4(posixSupport, inet4SockAddr);
} else if (src instanceof Inet6SockAddr inet6SockAddr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,14 @@
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonClinicBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryClinicBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryClinicBuiltinNode;
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
import com.oracle.graal.python.runtime.ExecutionContext.BoundaryCallContext;
import com.oracle.graal.python.runtime.GilNode;
import com.oracle.graal.python.runtime.IndirectCallData.BoundaryCallData;
import com.oracle.graal.python.runtime.PosixSupportLibrary;
import com.oracle.graal.python.runtime.PosixSupportLibrary.PosixException;
import com.oracle.graal.python.runtime.PosixSupportLibrary.UnsupportedPosixFeatureException;
import com.oracle.graal.python.runtime.PythonContext;
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.exception.ExceptionUtils;
Expand Down Expand Up @@ -291,8 +290,6 @@ private static PNone raiseFatalSignal(VirtualFrame frame, PythonContext context,
}
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
} catch (UnsupportedPosixFeatureException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorUnsupported(frame, e);
}
return PNone.NONE;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -214,103 +214,99 @@ Object ioctl(VirtualFrame frame, int fd, long request, Object arg, boolean mutat
@Cached SysModuleBuiltins.AuditNode auditNode) {
auditNode.audit(inliningTarget, "fcnt.ioctl", fd, request, arg);

try {
int intArg = 0;
if (arg != PNone.NO_VALUE) {
Object buffer = null;
// Buffer argument
if (acquireLib.hasBuffer(arg)) {
boolean writable = false;
int intArg = 0;
if (arg != PNone.NO_VALUE) {
Object buffer = null;
// Buffer argument
if (acquireLib.hasBuffer(arg)) {
boolean writable = false;
try {
buffer = acquireLib.acquireWritable(arg, frame, callData);
writable = true;
} catch (PException e) {
try {
buffer = acquireLib.acquireWritable(arg, frame, callData);
writable = true;
} catch (PException e) {
try {
buffer = acquireLib.acquireReadonly(arg, frame, callData);
} catch (PException e1) {
// ignore
}
buffer = acquireLib.acquireReadonly(arg, frame, callData);
} catch (PException e1) {
// ignore
}
if (buffer != null) {
try {
int len = bufferLib.getBufferLength(buffer);
boolean writeBack = false;
boolean releaseGil = true;
byte[] ioctlArg = null;
if (writable && mutateArg) {
writeBack = true;
if (bufferLib.hasInternalByteArray(buffer)) {
byte[] internalArray = bufferLib.getInternalByteArray(buffer);
if (internalArray.length > len && internalArray[len] == 0) {
writeBack = false;
releaseGil = false; // Could resize concurrently
ioctlArg = internalArray;
}
}
} else {
if (len > IOCTL_BUFSZ) {
throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.IOCTL_STRING_ARG_TOO_LONG);
}
if (buffer != null) {
try {
int len = bufferLib.getBufferLength(buffer);
boolean writeBack = false;
boolean releaseGil = true;
byte[] ioctlArg = null;
if (writable && mutateArg) {
writeBack = true;
if (bufferLib.hasInternalByteArray(buffer)) {
byte[] internalArray = bufferLib.getInternalByteArray(buffer);
if (internalArray.length > len && internalArray[len] == 0) {
writeBack = false;
releaseGil = false; // Could resize concurrently
ioctlArg = internalArray;
}
}
if (ioctlArg == null) {
ioctlArg = new byte[len + 1];
bufferLib.readIntoByteArray(buffer, 0, ioctlArg, 0, len);
} else {
if (len > IOCTL_BUFSZ) {
throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.IOCTL_STRING_ARG_TOO_LONG);
}
try {
int ret = callIoctlBytes(frame, inliningTarget, fd, request, ioctlArg, releaseGil, posixLib, gilNode, constructAndRaiseNode);
if (writable && mutateArg) {
return ret;
} else {
return PFactory.createBytes(context.getLanguage(inliningTarget), ioctlArg, len);
}
} finally {
if (writeBack) {
bufferLib.writeFromByteArray(buffer, 0, ioctlArg, 0, len);
}
}
if (ioctlArg == null) {
ioctlArg = new byte[len + 1];
bufferLib.readIntoByteArray(buffer, 0, ioctlArg, 0, len);
}
try {
int ret = callIoctlBytes(frame, inliningTarget, fd, request, ioctlArg, releaseGil, posixLib, gilNode, constructAndRaiseNode);
if (writable && mutateArg) {
return ret;
} else {
return PFactory.createBytes(context.getLanguage(inliningTarget), ioctlArg, len);
}
} finally {
bufferLib.release(buffer, frame, callData);
if (writeBack) {
bufferLib.writeFromByteArray(buffer, 0, ioctlArg, 0, len);
}
}
} finally {
bufferLib.release(buffer, frame, callData);
}
}
// string arg
TruffleString stringArg = null;
try {
stringArg = castToString.execute(inliningTarget, arg);
} catch (CannotCastException e) {
// ignore
}
if (stringArg != null) {
TruffleString.Encoding utf8 = TruffleString.Encoding.UTF_8;
stringArg = switchEncodingNode.execute(stringArg, utf8);
int len = stringArg.byteLength(utf8);
if (len > IOCTL_BUFSZ) {
throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.IOCTL_STRING_ARG_TOO_LONG);
}
byte[] ioctlArg = new byte[len + 1];
copyToByteArrayNode.execute(stringArg, 0, ioctlArg, 0, len, utf8);
callIoctlBytes(frame, inliningTarget, fd, request, ioctlArg, true, posixLib, gilNode, constructAndRaiseNode);
return PFactory.createBytes(context.getLanguage(inliningTarget), ioctlArg, len);
}
// string arg
TruffleString stringArg = null;
try {
stringArg = castToString.execute(inliningTarget, arg);
} catch (CannotCastException e) {
// ignore
}
if (stringArg != null) {
TruffleString.Encoding utf8 = TruffleString.Encoding.UTF_8;
stringArg = switchEncodingNode.execute(stringArg, utf8);
int len = stringArg.byteLength(utf8);
if (len > IOCTL_BUFSZ) {
throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.IOCTL_STRING_ARG_TOO_LONG);
}

// int arg
intArg = asIntNode.execute(frame, inliningTarget, arg);
// fall through
byte[] ioctlArg = new byte[len + 1];
copyToByteArrayNode.execute(stringArg, 0, ioctlArg, 0, len, utf8);
callIoctlBytes(frame, inliningTarget, fd, request, ioctlArg, true, posixLib, gilNode, constructAndRaiseNode);
return PFactory.createBytes(context.getLanguage(inliningTarget), ioctlArg, len);
}

// default arg or int arg
// int arg
intArg = asIntNode.execute(frame, inliningTarget, arg);
// fall through
}

// default arg or int arg
try {
gilNode.release(true);
try {
gilNode.release(true);
try {
return posixLib.ioctlInt(getPosixSupport(), fd, request, intArg);
} finally {
gilNode.acquire();
}
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
return posixLib.ioctlInt(getPosixSupport(), fd, request, intArg);
} finally {
gilNode.acquire();
}
} catch (PosixSupportLibrary.UnsupportedPosixFeatureException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorUnsupported(frame, e);
} catch (PosixException e) {
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
}
}

Expand Down
Loading
Loading