Skip to content

Commit 27aa283

Browse files
committed
[GR-46383] Backport: Improve compatibility with urllib3
PullRequest: graalpython/2810
2 parents bc36981 + 35141cc commit 27aa283

33 files changed

+423
-113
lines changed

graalpython/com.oracle.graal.python.cext/include/cpython/methodobject.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2022, Oracle and/or its affiliates.
1+
/* Copyright (c) 2022, 2023, Oracle and/or its affiliates.
22
* Copyright (C) 1996-2022 Python Software Foundation
33
*
44
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -32,3 +32,10 @@ typedef struct {
3232
PyCFunctionObject func;
3333
PyTypeObject *mm_class; /* Class that defines this method */
3434
} PyCMethodObject;
35+
36+
/*
37+
* XXX These functions are GraalPy-only. We need them to replace field access in our patches.
38+
* Currently used by (at least) cffi patch.
39+
*/
40+
PyAPI_FUNC(PyObject*) _PyCFunction_GetModule(PyObject* a);
41+
PyAPI_FUNC(PyMethodDef*) _PyCFunction_GetMethodDef(PyObject* a);

graalpython/com.oracle.graal.python.cext/src/methodobject.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,11 @@ PyTypeObject * PyCFunction_GetClass(PyObject *func) {
8787
PyMethodDef* def = PyCFunctionObject_m_ml(func);
8888
return PyMethodDef_ml_flags(def) & METH_METHOD ? PyCMethodObject_mm_class(func) : NULL;
8989
}
90+
91+
PyObject* _PyCFunction_GetModule(PyObject *func) {
92+
return PyCFunctionObject_m_module(func);
93+
}
94+
95+
PyMethodDef* _PyCFunction_GetMethodDef(PyObject *func) {
96+
return PyCFunctionObject_m_ml(func);
97+
}

graalpython/com.oracle.graal.python.jni/src/capi_forwards.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,8 @@ void unimplemented(const char* name) {
12401240
#undef _PyBytes_FromHex
12411241
#undef _PyBytes_Join
12421242
#undef _PyBytes_Resize
1243+
#undef _PyCFunction_GetMethodDef
1244+
#undef _PyCFunction_GetModule
12431245
#undef _PyCode_CheckLineNumber
12441246
#undef _PyCode_ConstantKey
12451247
#undef _PyCode_GetExtra
@@ -4809,6 +4811,16 @@ PyAPI_FUNC(int) _PyBytes_Resize(PyObject** a, Py_ssize_t b) {
48094811
int result = (int) __target___PyBytes_Resize(a, b);
48104812
return result;
48114813
}
4814+
PyMethodDef* (*__target___PyCFunction_GetMethodDef)(PyObject*) = NULL;
4815+
PyAPI_FUNC(PyMethodDef*) _PyCFunction_GetMethodDef(PyObject* a) {
4816+
PyMethodDef* result = (PyMethodDef*) __target___PyCFunction_GetMethodDef(a);
4817+
return result;
4818+
}
4819+
PyObject* (*__target___PyCFunction_GetModule)(PyObject*) = NULL;
4820+
PyAPI_FUNC(PyObject*) _PyCFunction_GetModule(PyObject* a) {
4821+
PyObject* result = (PyObject*) __target___PyCFunction_GetModule(a);
4822+
return result;
4823+
}
48124824
PyAPI_FUNC(int) _PyCode_CheckLineNumber(int a, PyCodeAddressRange* b) {
48134825
unimplemented("_PyCode_CheckLineNumber"); exit(-1);
48144826
}
@@ -6409,6 +6421,8 @@ void initializeCAPIForwards(void* (*getAPI)(const char*)) {
64096421
__target___PyBytesWriter_Resize = getAPI("_PyBytesWriter_Resize");
64106422
__target___PyBytesWriter_WriteBytes = getAPI("_PyBytesWriter_WriteBytes");
64116423
__target___PyBytes_Resize = getAPI("_PyBytes_Resize");
6424+
__target___PyCFunction_GetMethodDef = getAPI("_PyCFunction_GetMethodDef");
6425+
__target___PyCFunction_GetModule = getAPI("_PyCFunction_GetModule");
64126426
__target___PyErr_BadInternalCall = getAPI("_PyErr_BadInternalCall");
64136427
__target___PyErr_WriteUnraisableMsg = getAPI("_PyErr_WriteUnraisableMsg");
64146428
__target___PyEval_SliceIndex = getAPI("_PyEval_SliceIndex");

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -231,6 +231,7 @@ public void postInitialize(Python3Core core) {
231231
module.setAttribute(tsLiteral("HAS_ECDH"), false);
232232
module.setAttribute(tsLiteral("HAS_NPN"), false);
233233
module.setAttribute(tsLiteral("HAS_ALPN"), true);
234+
module.setAttribute(tsLiteral("HAS_NEVER_CHECK_COMMON_NAME"), false);
234235
module.setAttribute(tsLiteral("HAS_SSLv2"), false);
235236
boolean hasSSLv3 = supportedProtocols.contains(SSLProtocol.SSLv3);
236237
module.setAttribute(tsLiteral("HAS_SSLv3"), hasSSLv3);
@@ -268,13 +269,15 @@ public void postInitialize(Python3Core core) {
268269
module.setAttribute(tsLiteral("SSL_ERROR_EOF"), SSLErrorCode.ERROR_EOF.getErrno());
269270
module.setAttribute(tsLiteral("SSL_ERROR_INVALID_ERROR_CODE"), 10);
270271

271-
module.setAttribute(tsLiteral("OP_ALL"), SSLOptions.DEFAULT_OPTIONS);
272+
module.setAttribute(tsLiteral("OP_ALL"), SSLOptions.SSL_OP_ALL);
272273
module.setAttribute(tsLiteral("OP_NO_SSLv2"), SSLOptions.SSL_OP_NO_SSLv2);
273274
module.setAttribute(tsLiteral("OP_NO_SSLv3"), SSLOptions.SSL_OP_NO_SSLv3);
274275
module.setAttribute(tsLiteral("OP_NO_TLSv1"), SSLOptions.SSL_OP_NO_TLSv1);
275276
module.setAttribute(tsLiteral("OP_NO_TLSv1_1"), SSLOptions.SSL_OP_NO_TLSv1_1);
276277
module.setAttribute(tsLiteral("OP_NO_TLSv1_2"), SSLOptions.SSL_OP_NO_TLSv1_2);
277278
module.setAttribute(tsLiteral("OP_NO_TLSv1_3"), SSLOptions.SSL_OP_NO_TLSv1_3);
279+
module.setAttribute(tsLiteral("OP_NO_COMPRESSION"), SSLOptions.SSL_OP_NO_COMPRESSION);
280+
module.setAttribute(tsLiteral("OP_NO_TICKET"), SSLOptions.SSL_OP_NO_TICKET);
278281

279282
module.setAttribute(tsLiteral("VERIFY_DEFAULT"), 0);
280283
module.setAttribute(tsLiteral("VERIFY_CRL_CHECK_LEAF"), X509_V_FLAG_CRL_CHECK);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ public void initialize(Python3Core core) {
182182
addConstants(PosixConstants.tcpOptions);
183183
addConstants(PosixConstants.shutdownHow);
184184
addConstants(PosixConstants.ip4Address);
185+
addConstants(PosixConstants.ipv6Options);
185186
}
186187

187188
@Override

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@
103103
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.ArgDescriptor;
104104
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming;
105105
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions;
106+
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.HandlePointerConverter;
106107
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.HandleReleaser;
107-
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.HandleTester;
108108
import com.oracle.graal.python.builtins.objects.cext.common.CArrayWrappers.CArrayWrapper;
109109
import com.oracle.graal.python.builtins.objects.cext.common.CExtParseArgumentsNode;
110110
import com.oracle.graal.python.builtins.objects.cext.common.CExtParseArgumentsNode.SplitFormatStringNode;
@@ -1385,7 +1385,7 @@ static void doNativeWrapper(PythonNativeWrapper nativeWrapper,
13851385
if (LOGGER.isLoggable(Level.FINER)) {
13861386
LOGGER.finer(() -> PythonUtils.formatJString("Releasing handle: %x (object: %s)", nativePointer, nativeWrapper));
13871387
}
1388-
if (HandleTester.pointsToPyHandleSpace(nativePointer)) {
1388+
if (HandlePointerConverter.pointsToPyHandleSpace(nativePointer)) {
13891389
HandleReleaser.release(nativePointer);
13901390
} else {
13911391
callReleaseHandleNode.call(NativeCAPISymbol.FUN_PY_TRUFFLE_FREE, nativePointer);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ public static boolean assertBuiltins(Object capiLibrary) {
541541
"PyMethodDescrObject_GetMethod", "PyObject_GetDoc", "PyObject_SetDoc", "PySlice_Start", "PySlice_Step", "PySlice_Stop", "_PyASCIIObject_LENGTH", "_PyASCIIObject_STATE_ASCII",
542542
"_PyASCIIObject_STATE_COMPACT", "_PyASCIIObject_STATE_KIND", "_PyASCIIObject_STATE_READY", "_PyASCIIObject_WSTR", "_PyByteArray_Start", "_PyEval_SetCoroutineOriginTrackingDepth",
543543
"_PyFrame_SetLineNumber", "_PyMemoryView_GetBuffer", "_PySequence_Fast_ITEMS", "_PySequence_ITEM", "_PyUnicodeObject_DATA", "_PyUnicode_get_wstr_length", "_Py_REFCNT",
544-
"_Py_SET_REFCNT", "_Py_SET_SIZE", "_Py_SET_TYPE", "_Py_SIZE", "_Py_TYPE", "_PyTuple_SET_ITEM"};
544+
"_Py_SET_REFCNT", "_Py_SET_SIZE", "_Py_SET_TYPE", "_Py_SIZE", "_Py_TYPE", "_PyTuple_SET_ITEM", "_PyCFunction_GetModule", "_PyCFunction_GetMethodDef"};
545545

546546
/**
547547
* Check the list of implemented and unimplemented builtins against the list of CPython exported

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,8 @@ public final class CApiFunction {
484484
@CApiBuiltin(name = "PyCFunction_GetFlags", ret = Int, args = {PyObject}, call = PolyglotImpl)
485485
@CApiBuiltin(name = "PyCFunction_GetFunction", ret = PY_C_FUNCTION, args = {PyObject}, call = PolyglotImpl)
486486
@CApiBuiltin(name = "PyCFunction_GetSelf", ret = PyObject, args = {PyObject}, call = PolyglotImpl)
487+
@CApiBuiltin(name = "_PyCFunction_GetModule", ret = PyObject, args = {PyObject}, call = PolyglotImpl)
488+
@CApiBuiltin(name = "_PyCFunction_GetMethodDef", ret = PyMethodDef, args = {PyObject}, call = PolyglotImpl)
487489
@CApiBuiltin(name = "PyCFunction_New", ret = PyObject, args = {PyMethodDef, PyObject}, call = PolyglotImpl)
488490
@CApiBuiltin(name = "PyCFunction_NewEx", ret = PyObject, args = {PyMethodDef, PyObject, PyObject}, call = PolyglotImpl)
489491
@CApiBuiltin(name = "PyCMethod_New", ret = PyObject, args = {PyMethodDef, PyObject, PyObject, PyTypeObject}, call = PolyglotImpl)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@
9292
import com.oracle.graal.python.builtins.objects.cext.capi.PyTruffleObjectFree.FreeNode;
9393
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions;
9494
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.CharPtrToPythonNode;
95+
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.HandlePointerConverter;
9596
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.HandleResolver;
96-
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.HandleTester;
9797
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonNode;
9898
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonStealingNode;
9999
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode;
@@ -2087,7 +2087,7 @@ Object resolveLongCached(long pointer) {
20872087
if (lookup != null) {
20882088
return lookup;
20892089
}
2090-
if (HandleTester.pointsToPyHandleSpace(pointer)) {
2090+
if (HandlePointerConverter.pointsToPyHandleSpace(pointer)) {
20912091
return HandleResolver.resolve(pointer);
20922092
}
20932093
return pointer;
@@ -2108,7 +2108,7 @@ Object resolveGeneric(Object pointerObject,
21082108
if (lookup != null) {
21092109
return lookup;
21102110
}
2111-
if (HandleTester.pointsToPyHandleSpace(pointer)) {
2111+
if (HandlePointerConverter.pointsToPyHandleSpace(pointer)) {
21122112
return HandleResolver.resolve(pointer);
21132113
}
21142114
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,11 @@ public boolean isInternal() {
10021002
return true;
10031003
}
10041004

1005+
@Override
1006+
public boolean setsUpCalleeContext() {
1007+
return true;
1008+
}
1009+
10051010
protected final Object readSelf(VirtualFrame frame) {
10061011
if (readSelfNode != null) {
10071012
return readSelfNode.execute(frame);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444

4545
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.ClearNativeWrapperNode;
4646
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.PCallCapiFunction;
47+
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.HandlePointerConverter;
4748
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.HandleReleaser;
48-
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.HandleTester;
4949
import com.oracle.graal.python.builtins.objects.cext.common.CArrayWrappers.CArrayWrapper;
5050
import com.oracle.graal.python.util.PythonUtils;
5151
import com.oracle.truffle.api.TruffleLogger;
@@ -117,7 +117,7 @@ static void doNativeWrapper(PythonNativeWrapper nativeWrapper,
117117
if (LOGGER.isLoggable(Level.FINER)) {
118118
LOGGER.finer(() -> PythonUtils.formatJString("Releasing handle: %x (object: %s)", nativePointer, nativeWrapper));
119119
}
120-
if (HandleTester.pointsToPyHandleSpace(nativePointer)) {
120+
if (HandlePointerConverter.pointsToPyHandleSpace(nativePointer)) {
121121
HandleReleaser.release(nativePointer);
122122
} else {
123123
callReleaseHandleNode.call(NativeCAPISymbol.FUN_PY_TRUFFLE_FREE, nativePointer);

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

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,8 @@ public static void pollReferenceQueue() {
256256
if (entry instanceof PythonObjectReference reference) {
257257
LOGGER.finer(() -> PythonUtils.formatJString("releasing PythonObjectReference %s", reference));
258258

259-
if (HandleTester.pointsToPyHandleSpace(reference.pointer)) {
260-
int index = (int) (reference.pointer - HandleFactory.HANDLE_BASE);
259+
if (HandlePointerConverter.pointsToPyHandleSpace(reference.pointer)) {
260+
int index = HandlePointerConverter.pointerToHandleIndex(reference.pointer);
261261
assert context.nativeHandles.get(index) != null;
262262
context.nativeHandles.set(index, null);
263263
context.nativeHandlesFreeStack.push(index);
@@ -360,7 +360,7 @@ public Object execute(Object[] args,
360360
throw CompilerDirectives.shouldNotReachHere(e);
361361
}
362362
}
363-
assert HandleTester.pointsToPyHandleSpace(pointer);
363+
assert HandlePointerConverter.pointsToPyHandleSpace(pointer);
364364
release(pointer);
365365
return 0;
366366
}
@@ -402,11 +402,7 @@ public Object execute(Object[] args,
402402
throw CompilerDirectives.shouldNotReachHere(e);
403403
}
404404
}
405-
return pointsToPyHandleSpace(pointer) ? 1 : 0;
406-
}
407-
408-
public static boolean pointsToPyHandleSpace(long pointer) {
409-
return (pointer & HandleFactory.HANDLE_BASE) != 0;
405+
return HandlePointerConverter.pointsToPyHandleSpace(pointer) ? 1 : 0;
410406
}
411407
}
412408

@@ -427,7 +423,7 @@ public Object execute(Object[] args) {
427423
}
428424

429425
public static PythonNativeWrapper resolve(long pointer) {
430-
PythonNativeWrapper wrapper = getContext().nativeHandles.get((int) (pointer - HandleFactory.HANDLE_BASE)).get();
426+
PythonNativeWrapper wrapper = getContext().nativeHandles.get(HandlePointerConverter.pointerToHandleIndex(pointer)).get();
431427
assert wrapper != null : "reference was collected: " + Long.toHexString(pointer);
432428
incRef(wrapper, 1);
433429
return wrapper;
@@ -451,15 +447,35 @@ public Object execute(Object[] args) {
451447
}
452448

453449
public static PythonNativeWrapper resolve(long pointer) {
454-
PythonNativeWrapper wrapper = getContext().nativeHandles.get((int) (pointer - HandleFactory.HANDLE_BASE)).get();
450+
PythonNativeWrapper wrapper = getContext().nativeHandles.get(HandlePointerConverter.pointerToHandleIndex(pointer)).get();
455451
assert wrapper != null : "reference was collected: " + Long.toHexString(pointer);
456452
return wrapper;
457453
}
458454
}
459455

460-
public static final class HandleFactory {
456+
public static final class HandlePointerConverter {
457+
458+
private static final long HANDLE_BASE = 0x8000_0000_0000_0000L;
461459

462-
public static final long HANDLE_BASE = 0x8000_0000_0000_0000L;
460+
/**
461+
* We need to shift the pointers because some libraries, notably cffi, do pointer tagging.
462+
*/
463+
private static final int HANDLE_SHIFT = 3;
464+
465+
public static long handleIndexToPointer(int idx) {
466+
return ((long) idx << HANDLE_SHIFT) | HANDLE_BASE;
467+
}
468+
469+
public static int pointerToHandleIndex(long pointer) {
470+
return (int) ((pointer & ~HANDLE_BASE) >>> HANDLE_SHIFT);
471+
}
472+
473+
public static boolean pointsToPyHandleSpace(long pointer) {
474+
return (pointer & HANDLE_BASE) != 0;
475+
}
476+
}
477+
478+
public static final class HandleFactory {
463479

464480
public static long create(PythonNativeWrapper wrapper) {
465481
CompilerAsserts.neverPartOfCompilation();
@@ -470,11 +486,11 @@ public static long create(PythonNativeWrapper wrapper) {
470486
int idx = handleContext.nativeHandlesFreeStack.pop();
471487
long pointer;
472488
if (idx == -1) {
473-
pointer = HANDLE_BASE + handleContext.nativeHandles.size();
489+
pointer = HandlePointerConverter.handleIndexToPointer(handleContext.nativeHandles.size());
474490
handleContext.nativeHandles.add(new PythonObjectReference(wrapper, pointer));
475491
} else {
476492
assert idx >= 0;
477-
pointer = HANDLE_BASE + idx;
493+
pointer = HandlePointerConverter.handleIndexToPointer(idx);
478494
handleContext.nativeHandles.set(idx, new PythonObjectReference(wrapper, pointer));
479495
}
480496
return pointer;
@@ -661,7 +677,7 @@ public static Object nativeCharToJava(Object value) {
661677
} catch (UnsupportedMessageException e) {
662678
throw CompilerDirectives.shouldNotReachHere(e);
663679
}
664-
if (HandleTester.pointsToPyHandleSpace(pointer)) {
680+
if (HandlePointerConverter.pointsToPyHandleSpace(pointer)) {
665681
PythonNativeWrapper obj = HandleResolver.resolve(pointer);
666682
if (obj != null) {
667683
return logResult(obj.getDelegate());
@@ -842,8 +858,8 @@ Object doNonWrapper(Object value,
842858
return PNone.NO_VALUE;
843859
}
844860
assert pythonContext.ownsGil();
845-
if (isHandleSpaceProfile.profile(inliningTarget, HandleTester.pointsToPyHandleSpace(pointer))) {
846-
PythonObjectReference reference = nativeContext.nativeHandles.get((int) (pointer - HandleFactory.HANDLE_BASE));
861+
if (isHandleSpaceProfile.profile(inliningTarget, HandlePointerConverter.pointsToPyHandleSpace(pointer))) {
862+
PythonObjectReference reference = nativeContext.nativeHandles.get(HandlePointerConverter.pointerToHandleIndex(pointer));
847863
if (reference == null) {
848864
CompilerDirectives.transferToInterpreterAndInvalidate();
849865
throw CompilerDirectives.shouldNotReachHere("reference was freed: " + Long.toHexString(pointer));
@@ -1005,8 +1021,8 @@ public static PythonNativeWrapper nativeToPythonWrapper(Object obj) {
10051021
}
10061022
assert PythonContext.get(null).ownsGil();
10071023
PythonNativeWrapper wrapper;
1008-
if (HandleTester.pointsToPyHandleSpace(pointer)) {
1009-
PythonObjectReference reference = getContext().nativeHandles.get((int) (pointer - HandleFactory.HANDLE_BASE));
1024+
if (HandlePointerConverter.pointsToPyHandleSpace(pointer)) {
1025+
PythonObjectReference reference = getContext().nativeHandles.get(HandlePointerConverter.pointerToHandleIndex(pointer));
10101026
if (reference == null || (wrapper = reference.get()) == null) {
10111027
throw CompilerDirectives.shouldNotReachHere("reference was collected: " + Long.toHexString(pointer));
10121028
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/HPyExternalFunctionNodes.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,11 @@ public boolean isInternal() {
552552
public boolean isPythonInternal() {
553553
return true;
554554
}
555+
556+
@Override
557+
public boolean setsUpCalleeContext() {
558+
return true;
559+
}
555560
}
556561

557562
static final class HPyMethNoargsRoot extends HPyMethodDescriptorRootNode {
@@ -1314,6 +1319,11 @@ public boolean isPythonInternal() {
13141319
public boolean isInternal() {
13151320
return true;
13161321
}
1322+
1323+
@Override
1324+
public boolean setsUpCalleeContext() {
1325+
return true;
1326+
}
13171327
}
13181328

13191329
/**

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SortNodes.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ public boolean isInternal() {
162162
public String getName() {
163163
return "sort_comparator";
164164
}
165+
166+
@Override
167+
public boolean setsUpCalleeContext() {
168+
return true;
169+
}
165170
}
166171

167172
public abstract static class SortSequenceStorageNode extends PNodeWithContext {

0 commit comments

Comments
 (0)