Skip to content

Commit eae77ef

Browse files
committed
our C api is internal by default
1 parent eedd464 commit eae77ef

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
7070
import com.oracle.graal.python.runtime.PythonContext;
7171
import com.oracle.graal.python.runtime.PythonCore;
72+
import com.oracle.graal.python.runtime.PythonOptions;
7273
import com.oracle.graal.python.runtime.exception.PException;
7374
import com.oracle.graal.python.runtime.exception.PythonErrorType;
7475
import com.oracle.truffle.api.CallTarget;
@@ -91,6 +92,7 @@
9192
import com.oracle.truffle.api.interop.UnsupportedTypeException;
9293
import com.oracle.truffle.api.nodes.Node;
9394
import com.oracle.truffle.api.source.Source;
95+
import com.oracle.truffle.api.source.Source.Builder;
9496

9597
@CoreFunctions(defineModule = "_imp")
9698
public class ImpModuleBuiltins extends PythonBuiltins {
@@ -222,25 +224,30 @@ private Object loadDynamicModuleWithSpec(String name, String path, Node readNode
222224

223225
@TruffleBoundary
224226
private void ensureCapiWasLoaded() {
225-
if (!getContext().capiWasLoaded()) {
226-
Env env = getContext().getEnv();
227+
PythonContext ctxt = getContext();
228+
if (!ctxt.capiWasLoaded()) {
229+
Env env = ctxt.getEnv();
227230
CompilerDirectives.transferToInterpreterAndInvalidate();
228231
TruffleFile capiFile = env.getTruffleFile(PythonCore.getCoreHome(env) + PythonCore.FILE_SEPARATOR + "capi.bc");
229232
Object capi = null;
230233
try {
231-
capi = getContext().getEnv().parse(env.newSourceBuilder(capiFile).language(LLVM_LANGUAGE).build()).call();
234+
Builder<IOException, RuntimeException, RuntimeException> capiSrcBuilder = env.newSourceBuilder(capiFile).language(LLVM_LANGUAGE);
235+
if (!PythonOptions.getOption(ctxt, PythonOptions.ExposeInternalSources)) {
236+
capiSrcBuilder.internal();
237+
}
238+
capi = ctxt.getEnv().parse(capiSrcBuilder.build()).call();
232239
} catch (SecurityException | IOException e) {
233240
throw raise(PythonErrorType.ImportError, "cannot load capi from " + capiFile.getAbsoluteFile().getPath());
234241
}
235242
// call into Python to initialize python_cext module globals
236243
ReadAttributeFromObjectNode readNode = ReadAttributeFromObjectNode.create();
237244
CallUnaryMethodNode callNode = CallUnaryMethodNode.create();
238-
callNode.executeObject(readNode.execute(getContext().getCore().lookupBuiltinModule("python_cext"), INITIALIZE_CAPI), capi);
239-
getContext().setCapiWasLoaded();
245+
callNode.executeObject(readNode.execute(ctxt.getCore().lookupBuiltinModule("python_cext"), INITIALIZE_CAPI), capi);
246+
ctxt.setCapiWasLoaded();
240247

241248
// initialization needs to be finished already but load memoryview implemenation
242249
// immediately
243-
callNode.executeObject(readNode.execute(getContext().getCore().lookupBuiltinModule("python_cext"), IMPORT_NATIVE_MEMORYVIEW), capi);
250+
callNode.executeObject(readNode.execute(ctxt.getCore().lookupBuiltinModule("python_cext"), IMPORT_NATIVE_MEMORYVIEW), capi);
244251
}
245252
}
246253

0 commit comments

Comments
 (0)