Skip to content

Commit f8a7f82

Browse files
committed
Move _imp module builtins behind a boundary
1 parent ef11439 commit f8a7f82

File tree

10 files changed

+358
-447
lines changed

10 files changed

+358
-447
lines changed

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

Lines changed: 107 additions & 161 deletions
Large diffs are not rendered by default.

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesNodes.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,10 @@ static TruffleString doit(VirtualFrame frame, Object value,
850850
public abstract static class HashBufferNode extends PNodeWithContext {
851851
public abstract long execute(Node inliningTarget, Object buffer);
852852

853+
public static long executeUncached(Object buffer) {
854+
return BytesNodesFactory.HashBufferNodeGen.getUncached().execute(null, buffer);
855+
}
856+
853857
@Specialization(guards = "bufferLib.hasInternalByteArray(buffer)", limit = "2")
854858
static long hashDirect(Object buffer,
855859
@CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib) {

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,12 @@
8383
import com.oracle.graal.python.builtins.objects.PythonAbstractObject;
8484
import com.oracle.graal.python.builtins.objects.capsule.PyCapsule;
8585
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.PCallCapiFunction;
86-
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodesFactory.CreateModuleNodeGen;
8786
import com.oracle.graal.python.builtins.objects.cext.capi.PythonNativeWrapper.PythonAbstractObjectNativeWrapper;
8887
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions;
8988
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.HandleContext;
9089
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonNode;
9190
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.ToPythonWrapperNode;
9291
import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodes;
93-
import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodes.CheckFunctionResultNode;
9492
import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodes.EnsureExecutableNode;
9593
import com.oracle.graal.python.builtins.objects.cext.common.CExtContext;
9694
import com.oracle.graal.python.builtins.objects.cext.common.LoadCExtException.ApiInitException;
@@ -1074,16 +1072,13 @@ private static String dlopenFlagsToString(int flags) {
10741072
* @param context The Python context object.
10751073
* @param spec The name and path of the module (also containing the original module spec
10761074
* object).
1077-
* @param checkFunctionResultNode A node to check that the function result does not indicate
1078-
* that an exception was raised on the native side. It should be an adopted node,
1079-
* because only an adopted node will report useful source locations.
10801075
* @return A Python module.
10811076
* @throws IOException If the specified file cannot be loaded.
10821077
* @throws ApiInitException If the corresponding native context could not be initialized.
10831078
* @throws ImportException If an exception occurred during C extension initialization.
10841079
*/
10851080
@TruffleBoundary
1086-
public static Object loadCExtModule(Node location, PythonContext context, ModuleSpec spec, CheckFunctionResultNode checkFunctionResultNode)
1081+
public static Object loadCExtModule(Node location, PythonContext context, ModuleSpec spec)
10871082
throws IOException, ApiInitException, ImportException {
10881083
if (getLogger(CApiContext.class).isLoggable(Level.WARNING) && context.getOption(PythonOptions.WarnExperimentalFeatures)) {
10891084
if (!C_EXT_SUPPORTED_LIST.contains(spec.name.toJavaStringUncached())) {
@@ -1142,7 +1137,7 @@ public static Object loadCExtModule(Node location, PythonContext context, Module
11421137
}
11431138

11441139
try {
1145-
return cApiContext.initCApiModule(location, library, spec.getInitFunctionName(), spec, interopLib, checkFunctionResultNode);
1140+
return cApiContext.initCApiModule(location, library, spec.getInitFunctionName(), spec, interopLib);
11461141
} catch (UnsupportedTypeException | ArityException | UnsupportedMessageException e) {
11471142
throw new ImportException(CExtContext.wrapJavaException(e, location), spec.name, spec.path, ErrorMessages.CANNOT_INITIALIZE_WITH, spec.path, spec.getEncodedName(), "");
11481143
}
@@ -1283,7 +1278,7 @@ public void finalizeCApi() {
12831278
}
12841279

12851280
@TruffleBoundary
1286-
public Object initCApiModule(Node location, Object sharedLibrary, TruffleString initFuncName, ModuleSpec spec, InteropLibrary llvmInteropLib, CheckFunctionResultNode checkFunctionResultNode)
1281+
public Object initCApiModule(Node node, Object sharedLibrary, TruffleString initFuncName, ModuleSpec spec, InteropLibrary llvmInteropLib)
12871282
throws UnsupportedMessageException, ArityException, UnsupportedTypeException, ImportException {
12881283
PythonContext context = getContext();
12891284
CApiContext cApiContext = context.getCApiContext();
@@ -1307,7 +1302,7 @@ public Object initCApiModule(Node location, Object sharedLibrary, TruffleString
13071302
nativeResult = InteropLibrary.getUncached().execute(pyinitFunc, arguments);
13081303
}
13091304

1310-
checkFunctionResultNode.execute(context, initFuncName, nativeResult);
1305+
ExternalFunctionNodesFactory.DefaultCheckFunctionResultNodeGen.getUncached().execute(context, initFuncName, nativeResult);
13111306

13121307
Object result = NativeToPythonNode.executeUncached(nativeResult);
13131308
if (!(result instanceof PythonModule)) {
@@ -1322,10 +1317,10 @@ public Object initCApiModule(Node location, Object sharedLibrary, TruffleString
13221317
*/
13231318
Object clazz = GetClassNode.executeUncached(result);
13241319
if (clazz == PNone.NO_VALUE) {
1325-
throw PRaiseNode.raiseStatic(location, PythonBuiltinClassType.SystemError, ErrorMessages.INIT_FUNC_RETURNED_UNINT_OBJ, initFuncName);
1320+
throw PRaiseNode.raiseStatic(node, PythonBuiltinClassType.SystemError, ErrorMessages.INIT_FUNC_RETURNED_UNINT_OBJ, initFuncName);
13261321
}
13271322

1328-
return CreateModuleNodeGen.getUncached().execute(cApiContext, spec, result, sharedLibrary);
1323+
return CExtNodes.createModule(node, cApiContext, spec, result, sharedLibrary);
13291324
} else {
13301325
// see: 'import.c: _PyImport_FixupExtensionObject'
13311326
PythonModule module = (PythonModule) result;

0 commit comments

Comments
 (0)