Skip to content

Commit 84126c7

Browse files
committed
[GR-35311]: Fix loading ujson in Python language servers
PullRequest: graalpython/2048
2 parents 073911d + 21f9efa commit 84126c7

File tree

14 files changed

+94
-69
lines changed

14 files changed

+94
-69
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,17 @@ PyThreadState* PyGILState_GetThisThreadState(void) {
7878
return polyglot_invoke(PY_TRUFFLE_CEXT, "PyThreadState_Get");
7979
}
8080

81-
UPCALL_ID(PyState_FindModule)
81+
typedef PyObject* (*find_module_fun_t)(long index);
82+
UPCALL_TYPED_ID(PyState_FindModule, find_module_fun_t);
8283
PyObject* PyState_FindModule(struct PyModuleDef* module) {
83-
return UPCALL_CEXT_O(_jls_PyState_FindModule, module->m_base.m_index);
84+
Py_ssize_t index = module->m_base.m_index;
85+
if (module->m_slots) {
86+
return NULL;
87+
} else if (index == 0) {
88+
return NULL;
89+
} else {
90+
return _jls_PyState_FindModule(index);
91+
}
8492
}
8593

8694
int PyState_AddModule(PyObject* module, struct PyModuleDef* def) {

graalpython/com.oracle.graal.python/.checkstyle_checks.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
<module name="Checker">
1212
<property name="severity" value="error"/>
1313
<module name="TreeWalker">
14+
<module name="IllegalType">
15+
<property name="illegalClassNames" value="TruffleObject"/>
16+
</module>
1417
<module name="AvoidStarImport">
1518
<property name="allowClassImports" value="true"/>
1619
<property name="allowStaticMemberImports" value="true"/>

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,17 +1452,16 @@ public IsSubClassNode createRecursive(byte newDepth) {
14521452
return BuiltinFunctionsFactory.IsSubClassNodeFactory.create(newDepth);
14531453
}
14541454

1455-
private static boolean isSubclassCheckInternal(VirtualFrame frame, Object derived, Object cls, LookupAndCallBinaryNode subclassCheckNode, CoerceToBooleanNode castToBooleanNode) {
1456-
Object instanceCheckResult = subclassCheckNode.executeObject(frame, cls, derived);
1457-
return instanceCheckResult != NOT_IMPLEMENTED && castToBooleanNode.executeBoolean(frame, instanceCheckResult);
1458-
}
1459-
14601455
@Specialization(guards = "!isPTuple(cls)")
14611456
static boolean isSubclass(VirtualFrame frame, Object derived, Object cls,
14621457
@Cached("create(__SUBCLASSCHECK__)") LookupAndCallBinaryNode subclassCheckNode,
14631458
@Cached("createIfTrueNode()") CoerceToBooleanNode castToBooleanNode,
14641459
@Cached IsSubtypeNode isSubtypeNode) {
1465-
return isSubclassCheckInternal(frame, derived, cls, subclassCheckNode, castToBooleanNode) || isSubtypeNode.execute(frame, derived, cls);
1460+
Object instanceCheckResult = subclassCheckNode.executeObject(frame, cls, derived);
1461+
if (instanceCheckResult != NOT_IMPLEMENTED) {
1462+
return castToBooleanNode.executeBoolean(frame, instanceCheckResult);
1463+
}
1464+
return isSubtypeNode.execute(frame, derived, cls);
14661465
}
14671466
}
14681467

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ boolean isType(Object object) {
220220
@GenerateNodeFactory
221221
abstract static class InstanceOfNode extends PythonBinaryBuiltinNode {
222222
@Specialization(guards = {"!isForeign1.execute(object)", "isForeign2.execute(klass)"}, limit = "1")
223-
boolean check(Object object, TruffleObject klass,
223+
boolean check(Object object, Object klass,
224224
@SuppressWarnings("unused") @Shared("isForeign1") @Cached IsForeignObjectNode isForeign1,
225225
@SuppressWarnings("unused") @Shared("isForeign2") @Cached IsForeignObjectNode isForeign2) {
226226
Env env = getContext().getEnv();
@@ -236,7 +236,7 @@ boolean check(Object object, TruffleObject klass,
236236
}
237237

238238
@Specialization(guards = {"isForeign1.execute(object)", "isForeign2.execute(klass)"}, limit = "1")
239-
boolean checkForeign(Object object, TruffleObject klass,
239+
boolean checkForeign(Object object, Object klass,
240240
@SuppressWarnings("unused") @Shared("isForeign1") @Cached IsForeignObjectNode isForeign1,
241241
@SuppressWarnings("unused") @Shared("isForeign2") @Cached IsForeignObjectNode isForeign2) {
242242
Env env = getContext().getEnv();

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,6 @@
344344
import com.oracle.truffle.api.interop.InteropException;
345345
import com.oracle.truffle.api.interop.InteropLibrary;
346346
import com.oracle.truffle.api.interop.InvalidArrayIndexException;
347-
import com.oracle.truffle.api.interop.TruffleObject;
348347
import com.oracle.truffle.api.interop.UnknownIdentifierException;
349348
import com.oracle.truffle.api.interop.UnsupportedMessageException;
350349
import com.oracle.truffle.api.interop.UnsupportedTypeException;
@@ -2156,7 +2155,7 @@ Object doUnicode(PString s) {
21562155
abstract static class PyTruffle_Unicode_DecodeUTF32 extends NativeUnicodeBuiltin {
21572156

21582157
@Specialization
2159-
Object doUnicodeStringErrors(VirtualFrame frame, TruffleObject o, long size, String errors, int byteorder, Object errorMarker,
2158+
Object doUnicodeStringErrors(VirtualFrame frame, Object o, long size, String errors, int byteorder, Object errorMarker,
21602159
@Shared("toSulongNode") @Cached CExtNodes.ToSulongNode toSulongNode,
21612160
@Shared("getByteArrayNode") @Cached GetByteArrayNode getByteArrayNode) {
21622161
try {
@@ -2174,7 +2173,7 @@ Object doUnicodeStringErrors(VirtualFrame frame, TruffleObject o, long size, Str
21742173
}
21752174

21762175
@Specialization(replaces = "doUnicodeStringErrors")
2177-
Object doUnicode(VirtualFrame frame, TruffleObject o, long size, Object errors, int byteorder, Object errorMarker,
2176+
Object doUnicode(VirtualFrame frame, Object o, long size, Object errors, int byteorder, Object errorMarker,
21782177
@Cached AsPythonObjectNode asPythonObjectNode,
21792178
@Shared("toSulongNode") @Cached CExtNodes.ToSulongNode toSulongNode,
21802179
@Shared("getByteArrayNode") @Cached GetByteArrayNode getByteArrayNode) {
@@ -2826,7 +2825,7 @@ Object doIt(Object object,
28262825
@GenerateNodeFactory
28272826
abstract static class PyTruffleHandleCacheCreate extends PythonUnaryBuiltinNode {
28282827
@Specialization
2829-
static Object createCache(TruffleObject ptrToResolveHandle) {
2828+
static Object createCache(Object ptrToResolveHandle) {
28302829
return new HandleCache(ptrToResolveHandle);
28312830
}
28322831
}
@@ -2896,7 +2895,7 @@ private static BigInteger convertToBigInteger(long n) {
28962895
@GenerateNodeFactory
28972896
abstract static class PyLongFromVoidPtr extends PythonUnaryBuiltinNode {
28982897
@Specialization(limit = "2")
2899-
Object doPointer(TruffleObject pointer,
2898+
Object doPointer(Object pointer,
29002899
@Cached CExtNodes.ToSulongNode toSulongNode,
29012900
@CachedLibrary("pointer") InteropLibrary lib) {
29022901
// We capture the native pointer at the time when we create the wrapper if it exists.

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@
110110
import com.oracle.truffle.api.frame.VirtualFrame;
111111
import com.oracle.truffle.api.interop.ArityException;
112112
import com.oracle.truffle.api.interop.InteropLibrary;
113-
import com.oracle.truffle.api.interop.TruffleObject;
114113
import com.oracle.truffle.api.interop.UnknownIdentifierException;
115114
import com.oracle.truffle.api.interop.UnsupportedMessageException;
116115
import com.oracle.truffle.api.interop.UnsupportedTypeException;
@@ -167,7 +166,7 @@ public final class CApiContext extends CExtContext {
167166
@CompilationFinal private int pyLongBitsInDigit = -1;
168167

169168
/** Cache for polyglot types of primitive and pointer types. */
170-
@CompilationFinal(dimensions = 1) private final TruffleObject[] llvmTypeCache;
169+
@CompilationFinal(dimensions = 1) private final Object[] llvmTypeCache;
171170

172171
/** same as {@code moduleobject.c: max_module_number} */
173172
private long maxModuleNumber;
@@ -207,7 +206,7 @@ public CApiContext(PythonContext context, Object hpyLibrary) {
207206
assert nullID == 0;
208207

209208
// initialize primitive and pointer type cache
210-
llvmTypeCache = new TruffleObject[LLVMType.values().length];
209+
llvmTypeCache = new Object[LLVMType.values().length];
211210

212211
// initialize primitive native wrapper cache
213212
primitiveNativeWrapperCache = new PrimitiveNativeWrapper[262];
@@ -250,11 +249,11 @@ public int getPyLongBitsInDigit() {
250249
return pyLongBitsInDigit;
251250
}
252251

253-
public TruffleObject getLLVMTypeID(LLVMType llvmType) {
252+
public Object getLLVMTypeID(LLVMType llvmType) {
254253
return llvmTypeCache[llvmType.ordinal()];
255254
}
256255

257-
public void setLLVMTypeID(LLVMType llvmType, TruffleObject llvmTypeId) {
256+
public void setLLVMTypeID(LLVMType llvmType, Object llvmTypeId) {
258257
llvmTypeCache[llvmType.ordinal()] = llvmTypeId;
259258
}
260259

@@ -542,12 +541,12 @@ public NativeObjectReference lookupNativeObjectReference(int idx) {
542541
return nativeObjectWrapperList.get(idx);
543542
}
544543

545-
public PythonAbstractNativeObject getPythonNativeObject(TruffleObject nativePtr, ConditionProfile newRefProfile, ConditionProfile validRefProfile, ConditionProfile resurrectProfile,
544+
public PythonAbstractNativeObject getPythonNativeObject(Object nativePtr, ConditionProfile newRefProfile, ConditionProfile validRefProfile, ConditionProfile resurrectProfile,
546545
GetRefCntNode getObRefCntNode, AddRefCntNode addRefCntNode, AttachLLVMTypeNode attachLLVMTypeNode) {
547546
return getPythonNativeObject(nativePtr, newRefProfile, validRefProfile, resurrectProfile, getObRefCntNode, addRefCntNode, false, attachLLVMTypeNode);
548547
}
549548

550-
public PythonAbstractNativeObject getPythonNativeObject(TruffleObject nativePtr, ConditionProfile newRefProfile, ConditionProfile validRefProfile, ConditionProfile resurrectProfile,
549+
public PythonAbstractNativeObject getPythonNativeObject(Object nativePtr, ConditionProfile newRefProfile, ConditionProfile validRefProfile, ConditionProfile resurrectProfile,
551550
GetRefCntNode getObRefCntNode, AddRefCntNode addRefCntNode, boolean steal, AttachLLVMTypeNode attachLLVMTypeNode) {
552551
CompilerAsserts.partialEvaluationConstant(addRefCntNode);
553552
CompilerAsserts.partialEvaluationConstant(steal);
@@ -587,7 +586,7 @@ public PythonAbstractNativeObject getPythonNativeObject(TruffleObject nativePtr,
587586
return new PythonAbstractNativeObject(nativePtr);
588587
}
589588

590-
PythonAbstractNativeObject createPythonAbstractNativeObject(TruffleObject nativePtr, AddRefCntNode addRefCntNode, boolean steal, AttachLLVMTypeNode attachLLVMTypeNode) {
589+
PythonAbstractNativeObject createPythonAbstractNativeObject(Object nativePtr, AddRefCntNode addRefCntNode, boolean steal, AttachLLVMTypeNode attachLLVMTypeNode) {
591590
PythonAbstractNativeObject nativeObject = new PythonAbstractNativeObject(attachLLVMTypeNode.execute(nativePtr));
592591
int nativeRefID = nativeObjectWrapperList.reserve();
593592
assert nativeRefID != -1;

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

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@
195195
import com.oracle.truffle.api.interop.InteropException;
196196
import com.oracle.truffle.api.interop.InteropLibrary;
197197
import com.oracle.truffle.api.interop.InvalidArrayIndexException;
198-
import com.oracle.truffle.api.interop.TruffleObject;
199198
import com.oracle.truffle.api.interop.UnknownIdentifierException;
200199
import com.oracle.truffle.api.interop.UnsupportedMessageException;
201200
import com.oracle.truffle.api.interop.UnsupportedTypeException;
@@ -520,7 +519,7 @@ static Object runAbstractObject(@SuppressWarnings("unused") CExtContext cextCont
520519
}
521520

522521
@Specialization(guards = {"isForeignObjectNode.execute(object)", "!isNativeWrapper(object)", "!isNativeNull(object)"})
523-
static Object doForeignObject(@SuppressWarnings("unused") CExtContext cextContext, TruffleObject object,
522+
static Object doForeignObject(@SuppressWarnings("unused") CExtContext cextContext, Object object,
524523
@SuppressWarnings("unused") @Cached IsForeignObjectNode isForeignObjectNode) {
525524
return TruffleObjectNativeWrapper.wrap(object);
526525
}
@@ -785,7 +784,7 @@ static Object runAbstractObject(@SuppressWarnings("unused") CExtContext cextCont
785784
}
786785

787786
@Specialization(guards = {"isForeignObjectNode.execute(object)", "!isNativeWrapper(object)", "!isNativeNull(object)"})
788-
static Object doForeignObject(CExtContext cextContext, TruffleObject object,
787+
static Object doForeignObject(CExtContext cextContext, Object object,
789788
@Cached IsForeignObjectNode isForeignObjectNode) {
790789
// this will always be a new wrapper; it's implicitly always a new reference in any case
791790
return ToSulongNode.doForeignObject(cextContext, object, isForeignObjectNode);
@@ -960,7 +959,7 @@ static Object runAbstractObject(@SuppressWarnings("unused") CExtContext cextCont
960959
}
961960

962961
@Specialization(guards = {"isForeignObjectNode.execute(object)", "!isNativeWrapper(object)", "!isNativeNull(object)"})
963-
static Object doForeignObject(CExtContext cextContext, TruffleObject object,
962+
static Object doForeignObject(CExtContext cextContext, Object object,
964963
@Cached IsForeignObjectNode isForeignObjectNode) {
965964
// this will always be a new wrapper; it's implicitly always a new reference in any case
966965
return ToSulongNode.doForeignObject(cextContext, object, isForeignObjectNode);
@@ -1137,7 +1136,7 @@ protected static boolean isPrimitiveNativeWrapper(PythonNativeWrapper object) {
11371136
public abstract static class AsPythonObjectNode extends AsPythonObjectBaseNode {
11381137

11391138
@Specialization(guards = {"isForeignObjectNode.execute(object)", "!isNativeWrapper(object)", "!isNativeNull(object)"}, limit = "2")
1140-
static PythonAbstractObject doNativeObject(@SuppressWarnings("unused") CExtContext cextContext, TruffleObject object,
1139+
static PythonAbstractObject doNativeObject(@SuppressWarnings("unused") CExtContext cextContext, Object object,
11411140
@SuppressWarnings("unused") @Cached IsForeignObjectNode isForeignObjectNode,
11421141
@Cached ConditionProfile newRefProfile,
11431142
@Cached ConditionProfile validRefProfile,
@@ -1163,7 +1162,7 @@ static PythonAbstractObject doNativeObject(@SuppressWarnings("unused") CExtConte
11631162
public abstract static class AsPythonObjectStealingNode extends AsPythonObjectBaseNode {
11641163

11651164
@Specialization(guards = {"isForeignObjectNode.execute(object)", "!isNativeWrapper(object)", "!isNativeNull(object)"}, limit = "1")
1166-
static PythonAbstractObject doNativeObject(@SuppressWarnings("unused") CExtContext cextContext, TruffleObject object,
1165+
static PythonAbstractObject doNativeObject(@SuppressWarnings("unused") CExtContext cextContext, Object object,
11671166
@SuppressWarnings("unused") @Cached IsForeignObjectNode isForeignObjectNode,
11681167
@Cached ConditionProfile newRefProfile,
11691168
@Cached ConditionProfile validRefProfile,
@@ -1188,7 +1187,7 @@ static PythonAbstractObject doNativeObject(@SuppressWarnings("unused") CExtConte
11881187
public abstract static class WrapVoidPtrNode extends AsPythonObjectBaseNode {
11891188

11901189
@Specialization(guards = {"isForeignObjectNode.execute(object)", "!isNativeWrapper(object)", "!isNativeNull(object)"}, limit = "1")
1191-
static Object doNativeObject(@SuppressWarnings("unused") CExtContext cextContext, TruffleObject object,
1190+
static Object doNativeObject(@SuppressWarnings("unused") CExtContext cextContext, Object object,
11921191
@SuppressWarnings("unused") @Cached IsForeignObjectNode isForeignObjectNode) {
11931192
// TODO(fa): should we use a different wrapper for non-'PyObject*' pointers; they cannot
11941193
// be used in the user value space but might be passed-through
@@ -1204,7 +1203,7 @@ static Object doNativeObject(@SuppressWarnings("unused") CExtContext cextContext
12041203
public abstract static class WrapCharPtrNode extends AsPythonObjectBaseNode {
12051204

12061205
@Specialization(guards = {"isForeignObjectNode.execute(object)", "!isNativeWrapper(object)", "!isNativeNull(object)"}, limit = "1")
1207-
static Object doNativeObject(@SuppressWarnings("unused") CExtContext cextContext, TruffleObject object,
1206+
static Object doNativeObject(@SuppressWarnings("unused") CExtContext cextContext, Object object,
12081207
@SuppressWarnings("unused") @Cached IsForeignObjectNode isForeignObjectNode,
12091208
@Cached FromCharPointerNode fromCharPointerNode) {
12101209
return fromCharPointerNode.execute(object);
@@ -3226,20 +3225,20 @@ static long doOther(Object object,
32263225

32273226
@GenerateUncached
32283227
public abstract static class GetLLVMType extends Node {
3229-
public abstract TruffleObject execute(LLVMType llvmType);
3228+
public abstract Object execute(LLVMType llvmType);
32303229

32313230
@Specialization(guards = "llvmType == cachedType", limit = "typeCount()")
3232-
TruffleObject doGeneric(@SuppressWarnings("unused") LLVMType llvmType,
3231+
Object doGeneric(@SuppressWarnings("unused") LLVMType llvmType,
32333232
@Cached("llvmType") LLVMType cachedType) {
32343233

32353234
CApiContext cApiContext = PythonContext.get(this).getCApiContext();
3236-
TruffleObject llvmTypeID = cApiContext.getLLVMTypeID(cachedType);
3235+
Object llvmTypeID = cApiContext.getLLVMTypeID(cachedType);
32373236

32383237
// TODO(fa): get rid of lazy initialization for better sharing
32393238
if (llvmTypeID == null) {
32403239
CompilerDirectives.transferToInterpreterAndInvalidate();
32413240
NativeCAPISymbol getterFunctionSymbol = LLVMType.getGetterFunctionName(llvmType);
3242-
llvmTypeID = (TruffleObject) PCallCapiFunction.getUncached().call(getterFunctionSymbol);
3241+
llvmTypeID = PCallCapiFunction.getUncached().call(getterFunctionSymbol);
32433242
cApiContext.setLLVMTypeID(cachedType, llvmTypeID);
32443243
}
32453244
return llvmTypeID;
@@ -3508,16 +3507,16 @@ private static Object callBuiltin(PythonContext context, String builtinName, Obj
35083507
@GenerateUncached
35093508
public abstract static class AttachLLVMTypeNode extends Node {
35103509

3511-
public abstract TruffleObject execute(TruffleObject ptr);
3510+
public abstract Object execute(Object ptr);
35123511

35133512
@Specialization(guards = "lib.hasMetaObject(ptr)", limit = "1")
3514-
static TruffleObject doTyped(TruffleObject ptr,
3513+
static Object doTyped(Object ptr,
35153514
@CachedLibrary("ptr") @SuppressWarnings("unused") InteropLibrary lib) {
35163515
return ptr;
35173516
}
35183517

35193518
@Specialization(guards = "!lib.hasMetaObject(ptr)", limit = "1", replaces = "doTyped")
3520-
static TruffleObject doUntyped(TruffleObject ptr,
3519+
static Object doUntyped(Object ptr,
35213520
@CachedLibrary("ptr") @SuppressWarnings("unused") InteropLibrary lib,
35223521
@Shared("getSulongTypeNode") @Cached GetSulongTypeNode getSulongTypeNode,
35233522
@Shared("getLLVMType") @Cached GetLLVMType getLLVMType,
@@ -3529,11 +3528,11 @@ static TruffleObject doUntyped(TruffleObject ptr,
35293528
if (llvmType == null) {
35303529
llvmType = getLLVMType.execute(LLVMType.PyObject);
35313530
}
3532-
return (TruffleObject) callPolyglotFromTypedNode.call(FUN_POLYGLOT_FROM_TYPED, ptr, llvmType);
3531+
return callPolyglotFromTypedNode.call(FUN_POLYGLOT_FROM_TYPED, ptr, llvmType);
35333532
}
35343533

35353534
@Specialization(limit = "1", replaces = {"doTyped", "doUntyped"})
3536-
static TruffleObject doGeneric(TruffleObject ptr,
3535+
static Object doGeneric(Object ptr,
35373536
@CachedLibrary("ptr") InteropLibrary lib,
35383537
@Shared("getSulongTypeNode") @Cached GetSulongTypeNode getSulongTypeNode,
35393538
@Shared("getLLVMType") @Cached GetLLVMType getLLVMType,

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@
134134
import com.oracle.truffle.api.frame.VirtualFrame;
135135
import com.oracle.truffle.api.interop.ArityException;
136136
import com.oracle.truffle.api.interop.InteropLibrary;
137-
import com.oracle.truffle.api.interop.TruffleObject;
138137
import com.oracle.truffle.api.interop.UnsupportedMessageException;
139138
import com.oracle.truffle.api.interop.UnsupportedTypeException;
140139
import com.oracle.truffle.api.library.CachedLibrary;
@@ -1883,7 +1882,7 @@ static PException raiseResultWithError(PythonLanguage language, Node node, Strin
18831882
throw PRaiseNode.raise(node, sysExc, PythonOptions.isPExceptionWithJavaStacktrace(language));
18841883
}
18851884

1886-
protected static boolean isNativeNull(TruffleObject object) {
1885+
protected static boolean isNativeNull(Object object) {
18871886
return object instanceof PythonNativeNull;
18881887
}
18891888

0 commit comments

Comments
 (0)