Skip to content

Commit 0967368

Browse files
committed
[GR-58703][GR-58704] Preserve capsule name identity
PullRequest: graalpython/3501
2 parents bcaae7f + aaed6ed commit 0967368

File tree

26 files changed

+241
-227
lines changed

26 files changed

+241
-227
lines changed

docs/user/Python-Runtime.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ Alternatively, you can download a compressed GraalPy installation file from [Git
9191
1. Find the download that matches the pattern _graalpy-XX.Y.Z-linux-amd64.tar.gz_ or _graalpy-XX.Y.Z-linux-aarch64.tar.gz_ (depending on your platform) and download.
9292
2. Uncompress the file and update your `PATH` environment variable to include to the _graalpy-XX.Y.Z-linux-amd64/bin_ (or _graalpy-XX.Y.Z-linux-aarch64/bin_) directory.
9393

94-
> Note: On Oracle Linux 9, additionally install the [`libxcrypt` library](https://github.com/besser82/libxcrypt) that is required for the GraalPy native runtime: `yum install libxcrypt-compat`.
95-
9694
### macOS
9795

9896
The easiest way to install GraalPy on macOS is to use [Pyenv](https://github.com/pyenv/pyenv) (the Python version manager).

graalpython/com.oracle.graal.python.cext/src/capi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ PY_TRUFFLE_TYPE_WITH_ITEMSIZE(PyLong_Type, "int", &
321321
PY_TRUFFLE_TYPE(PyBool_Type, "bool", &PyType_Type, sizeof(struct _longobject)) \
322322
PY_TRUFFLE_TYPE(PyByteArray_Type, "bytearray", &PyType_Type, sizeof(PyByteArrayObject)) \
323323
PY_TRUFFLE_TYPE_WITH_ITEMSIZE(PyBytes_Type, "bytes", &PyType_Type, PyBytesObject_SIZE, sizeof(char)) \
324-
PY_TRUFFLE_TYPE_WITH_ALLOC(PyCapsule_Type, "capsule", &PyType_Type, sizeof(PyCapsule), PyType_GenericAlloc, capsule_dealloc, PyObject_Del) \
324+
PY_TRUFFLE_TYPE_WITH_ALLOC(PyCapsule_Type, "PyCapsule", &PyType_Type, sizeof(PyCapsule), PyType_GenericAlloc, capsule_dealloc, PyObject_Del) \
325325
PY_TRUFFLE_TYPE(PyCell_Type, "cell", &PyType_Type, sizeof(PyCellObject)) \
326326
PY_TRUFFLE_TYPE(PyCMethod_Type, "builtin_method", &PyCFunction_Type, sizeof(PyCFunctionObject)) \
327327
PY_TRUFFLE_TYPE(PyCode_Type, "code", &PyType_Type, sizeof(PyTypeObject)) \

graalpython/com.oracle.graal.python.test.integration/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ Additionally, one can change the polyglot artifacts version with
181181
<dependency>
182182
<groupId>junit</groupId>
183183
<artifactId>junit</artifactId>
184-
<version>4.12</version>
184+
<version>4.13.2</version>
185185
</dependency>
186186
</dependencies>
187187
</project>

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_capsule.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,43 @@ class TestPyCapsule(CPyExtTestCase):
8080
cmpfunc=unhandled_error_compare
8181
)
8282

83+
test_PyCapsule_GetName = CPyExtFunction(
84+
lambda args: True,
85+
lambda: (
86+
("hello",),
87+
),
88+
# Test that the returned name is pointer-identical, pybind11 relies on that
89+
code='''int wrap_PyCapsule_Check(char * name) {
90+
PyObject* capsule = PyCapsule_New((void *)1, name, NULL);
91+
return PyCapsule_GetName(capsule) == name;
92+
}
93+
''',
94+
resultspec="i",
95+
argspec='s',
96+
arguments=["char* name"],
97+
callfunction="wrap_PyCapsule_Check",
98+
cmpfunc=unhandled_error_compare
99+
)
100+
101+
test_PyCapsule_SetName = CPyExtFunction(
102+
lambda args: True,
103+
lambda: (
104+
("hello",),
105+
),
106+
# Test that the returned name is pointer-identical, pybind11 relies on that
107+
code='''int wrap_PyCapsule_Check(char * name) {
108+
PyObject* capsule = PyCapsule_New((void *)1, NULL, NULL);
109+
PyCapsule_SetName(capsule, name);
110+
return PyCapsule_GetName(capsule) == name;
111+
}
112+
''',
113+
resultspec="i",
114+
argspec='s',
115+
arguments=["char* name"],
116+
callfunction="wrap_PyCapsule_Check",
117+
cmpfunc=unhandled_error_compare
118+
)
119+
83120
test_PyCapsule_GetContext = CPyExtFunction(
84121
lambda args: True,
85122
lambda: (

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_cmd_line.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*graalpython.lib-python.3.test.test_cmd_line.CmdLineTest.test_site_flag
1919
*graalpython.lib-python.3.test.test_cmd_line.CmdLineTest.test_stdin_readline
2020
*graalpython.lib-python.3.test.test_cmd_line.CmdLineTest.test_unbuffered_input
21-
*graalpython.lib-python.3.test.test_cmd_line.CmdLineTest.test_unbuffered_output
2221
*graalpython.lib-python.3.test.test_cmd_line.CmdLineTest.test_unmached_quote
2322
*graalpython.lib-python.3.test.test_cmd_line.CmdLineTest.test_usage
2423
*graalpython.lib-python.3.test.test_cmd_line.CmdLineTest.test_verbose

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/PythonBuiltinClassType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ public enum PythonBuiltinClassType implements TruffleObject {
548548
// CPython uses separate keys, values, items python types for the iterators.
549549
ContextIterator("context_iterator", J__CONTEXTVARS, Flags.PUBLIC_DERIVED_WODICT),
550550

551-
Capsule("capsule"),
551+
Capsule("PyCapsule"),
552552

553553
PTokenizerIter("TokenizerIter", "_tokenize"),
554554

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.math.BigInteger;
4444
import java.security.SecureRandom;
4545
import java.util.ArrayList;
46+
import java.util.Arrays;
4647
import java.util.Collections;
4748
import java.util.List;
4849
import java.util.Map;
@@ -133,6 +134,7 @@
133134
import com.oracle.graal.python.util.OverflowException;
134135
import com.oracle.truffle.api.CompilerDirectives;
135136
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
137+
import com.oracle.truffle.api.ThreadLocalAction;
136138
import com.oracle.truffle.api.dsl.Bind;
137139
import com.oracle.truffle.api.dsl.Cached;
138140
import com.oracle.truffle.api.dsl.Cached.Exclusive;
@@ -2571,8 +2573,30 @@ public abstract static class ExitNode extends PythonUnaryBuiltinNode {
25712573
@TruffleBoundary
25722574
@Specialization
25732575
Object exit(int status) {
2574-
// TODO: use a safepoint action to throw this exception to all running threads
2575-
throw new PythonExitException(this, status);
2576+
PythonContext context = getContext();
2577+
if (context.getOption(PythonOptions.RunViaLauncher)) {
2578+
Runtime.getRuntime().halt(status);
2579+
}
2580+
List<Thread> otherThreads = new ArrayList<>(Arrays.asList(context.getThreads()));
2581+
otherThreads.remove(context.getMainThread());
2582+
otherThreads.remove(Thread.currentThread());
2583+
context.getEnv().submitThreadLocal(otherThreads.toArray(new Thread[0]), new ThreadLocalAction(true, false) {
2584+
@Override
2585+
protected void perform(Access access) {
2586+
throw new ThreadDeath();
2587+
}
2588+
});
2589+
if (Thread.currentThread() == context.getMainThread()) {
2590+
throw new PythonExitException(this, status);
2591+
} else {
2592+
context.getEnv().submitThreadLocal(new Thread[]{context.getMainThread()}, new ThreadLocalAction(true, false) {
2593+
@Override
2594+
protected void perform(Access access) {
2595+
throw new PythonExitException(ExitNode.this, status);
2596+
}
2597+
});
2598+
}
2599+
throw new ThreadDeath();
25762600
}
25772601
}
25782602

0 commit comments

Comments
 (0)