Skip to content

Commit 5b7d4a9

Browse files
OracleLabsAutomationelkorchi
authored andcommitted
[GR-71011] Backport to 25.0: Make native slot wrappers context-specific. Fixes #557.
PullRequest: graalpython/4150
2 parents 6212005 + 14b1cb6 commit 5b7d4a9

1 file changed

Lines changed: 27 additions & 6 deletions

File tree

  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyProcsWrapper.java

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import static com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.checkThrowableBeforeNative;
4444
import static com.oracle.graal.python.util.PythonUtils.EMPTY_OBJECT_ARRAY;
4545

46+
import com.oracle.graal.python.PythonLanguage;
4647
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
4748
import com.oracle.graal.python.builtins.objects.PNone;
4849
import com.oracle.graal.python.builtins.objects.cext.capi.PythonNativeWrapper.PythonStructNativeWrapper;
@@ -136,13 +137,30 @@ protected Object execute(Object[] arguments) throws UnsupportedTypeException, Ar
136137
}
137138

138139
@ExportMessage
139-
protected boolean isPointer() {
140-
return isNative();
140+
protected boolean isPointer(
141+
@Bind Node inliningTarget) {
142+
if (PythonLanguage.get(inliningTarget).isSingleContext()) {
143+
return isNative();
144+
}
145+
return getClosurePointerMultiContext() != -1;
141146
}
142147

143148
@ExportMessage
144-
protected long asPointer() {
145-
return getNativePointer();
149+
protected long asPointer(
150+
@Bind Node inliningTarget) throws UnsupportedMessageException {
151+
if (PythonLanguage.get(inliningTarget).isSingleContext()) {
152+
return getNativePointer();
153+
}
154+
long pointer = getClosurePointerMultiContext();
155+
if (pointer == -1) {
156+
throw UnsupportedMessageException.create();
157+
}
158+
return pointer;
159+
}
160+
161+
@TruffleBoundary
162+
private long getClosurePointerMultiContext() {
163+
return PythonContext.get(null).getCApiContext().getClosurePointer(this);
146164
}
147165

148166
protected abstract String getSignature();
@@ -151,9 +169,12 @@ protected long asPointer() {
151169
@TruffleBoundary
152170
protected void toNative(
153171
@CachedLibrary(limit = "1") SignatureLibrary signatureLibrary) {
154-
if (!isPointer()) {
172+
if (!isPointer(null)) {
155173
CApiContext cApiContext = PythonContext.get(null).getCApiContext();
156-
setNativePointer(cApiContext.registerClosure(getSignature(), this, getDelegate(), signatureLibrary));
174+
long pointer = cApiContext.registerClosure(getSignature(), this, getDelegate(), signatureLibrary);
175+
if (PythonLanguage.get(null).isSingleContext()) {
176+
setNativePointer(pointer);
177+
}
157178
}
158179
}
159180

0 commit comments

Comments
 (0)