Skip to content

[GR-68273] Fix two emulated posix shortcomings reported on Github. #528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 31, 2025
Merged
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
25 changes: 25 additions & 0 deletions graalpython/com.oracle.graal.python.test/src/tests/test_posix.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,31 @@ def test_pipe(self):
os.close(fd1)
os.close(fd2)

@unittest.skipIf(sys.platform != 'linux', 'mkfifo is a linux command')
def test_seek_pipe(self):
new_file_path = './myscript.sh'
with io.open(new_file_path, 'w') as script:
script.write("""#!/bin/sh
mkfifo testpipe
echo "4" > testpipe &
""")
try:
st = os.stat(new_file_path)
os.chmod(new_file_path, st.st_mode | stat.S_IEXEC)
os.system(new_file_path)
with io.open("testpipe", "rb") as r:
out = r.read(1)
assert out == b"4", out
finally:
try:
os.remove(new_file_path)
except:
pass
try:
os.remove("testpipe")
except:
pass

def test_mkdir_rmdir(self):
os.mkdir(TEST_FULL_PATH1)
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,21 @@ def test_java_asserts(self):
result = subprocess.run([sys.executable, "-c", "import __graalpython__; not __graalpython__.java_assert()"])
assert result.returncode == 0

def test_subprocess_inherits_environ(self):
import os
import subprocess
prev = os.environ.get("FOOBAR")
try:
expected_value = f"42{prev}".strip()
os.environ["FOOBAR"] = expected_value
out = subprocess.check_output([sys.executable, '-c', "import os; print(os.environ['FOOBAR'])"]).decode().strip()
assert out == expected_value, f"{out!r} != {expected_value!r}"
finally:
if prev:
os.environ["FOOBAR"] = prev
else:
del os.environ["FOOBAR"]

@unittest.skipUnless(sys.implementation.name == 'graalpy', "GraalPy-specific test")
@unittest.skipIf(sys.platform == 'win32', "TODO the cmd replacement breaks the test")
def test_graal_python_args(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2025, 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 @@ -312,7 +312,7 @@ public static ErrorAndMessagePair fromException(Exception e, TruffleString.Equal
return new ErrorAndMessagePair(oserror, oserror.getMessage());
}
} else { // Generic IOException
OSErrorEnum oserror = tryFindErrnoFromMessage(e);
OSErrorEnum oserror = tryFindErrnoFromMessage(e, eqNode);
if (oserror == null) {
return new ErrorAndMessagePair(OSErrorEnum.EIO, getMessage(e));
} else {
Expand Down Expand Up @@ -360,15 +360,13 @@ private static TruffleString getReason(FileSystemException e) {
}

@TruffleBoundary
private static OSErrorEnum tryFindErrnoFromMessage(Exception e) {
if (e.getMessage().contains("Broken pipe")) {
return OSErrorEnum.EPIPE;
}
Matcher m = ERRNO_PATTERN.matcher(e.getMessage());
private static OSErrorEnum tryFindErrnoFromMessage(Exception e, TruffleString.EqualNode eqNode) {
String message = e.getMessage();
Matcher m = ERRNO_PATTERN.matcher(message);
if (m.find()) {
return fromNumber(Integer.parseInt(m.group(1)));
}
return null;
return OSErrorEnum.fromMessage(toTruffleStringUncached(message), eqNode);
}

@ValueType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,15 @@ public Buffer read(int fd, long length,
}

@TruffleBoundary
private static Buffer readBytesFromChannel(ReadableByteChannel channel, long size) throws IOException {
private static Buffer readBytesFromChannel(ReadableByteChannel channel, long sizeIn) throws IOException {
long size = sizeIn;
if (channel instanceof SeekableByteChannel seekableByteChannel) {
long availableSize = seekableByteChannel.size() - seekableByteChannel.position();
size = Math.min(size, availableSize);
try {
long availableSize = seekableByteChannel.size() - seekableByteChannel.position();
size = Math.min(size, availableSize);
} catch (IOException e) {
// pass and read what we can
}
}
size = Math.min(size, MAX_READ);
ByteBuffer dst = ByteBuffer.allocate((int) size);
Expand Down Expand Up @@ -2304,6 +2309,8 @@ public int forkExec(Object[] executables, Object[] args, Object cwd, Object[] en
throw createUnsupportedFeature("Only key=value environment variables are supported in fork_exec");
}
}
} else {
envMap = new HashMap<>(environ);
}

String[] argStrings;
Expand Down