|
69 | 69 | import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
|
70 | 70 | import com.oracle.graal.python.runtime.PythonContext;
|
71 | 71 | import com.oracle.graal.python.runtime.PythonCore;
|
| 72 | +import com.oracle.graal.python.runtime.PythonOptions; |
72 | 73 | import com.oracle.graal.python.runtime.exception.PException;
|
73 | 74 | import com.oracle.graal.python.runtime.exception.PythonErrorType;
|
74 | 75 | import com.oracle.truffle.api.CallTarget;
|
|
91 | 92 | import com.oracle.truffle.api.interop.UnsupportedTypeException;
|
92 | 93 | import com.oracle.truffle.api.nodes.Node;
|
93 | 94 | import com.oracle.truffle.api.source.Source;
|
| 95 | +import com.oracle.truffle.api.source.Source.Builder; |
94 | 96 |
|
95 | 97 | @CoreFunctions(defineModule = "_imp")
|
96 | 98 | public class ImpModuleBuiltins extends PythonBuiltins {
|
@@ -222,25 +224,30 @@ private Object loadDynamicModuleWithSpec(String name, String path, Node readNode
|
222 | 224 |
|
223 | 225 | @TruffleBoundary
|
224 | 226 | 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(); |
227 | 230 | CompilerDirectives.transferToInterpreterAndInvalidate();
|
228 | 231 | TruffleFile capiFile = env.getTruffleFile(PythonCore.getCoreHome(env) + PythonCore.FILE_SEPARATOR + "capi.bc");
|
229 | 232 | Object capi = null;
|
230 | 233 | 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(); |
232 | 239 | } catch (SecurityException | IOException e) {
|
233 | 240 | throw raise(PythonErrorType.ImportError, "cannot load capi from " + capiFile.getAbsoluteFile().getPath());
|
234 | 241 | }
|
235 | 242 | // call into Python to initialize python_cext module globals
|
236 | 243 | ReadAttributeFromObjectNode readNode = ReadAttributeFromObjectNode.create();
|
237 | 244 | 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(); |
240 | 247 |
|
241 | 248 | // initialization needs to be finished already but load memoryview implemenation
|
242 | 249 | // 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); |
244 | 251 | }
|
245 | 252 | }
|
246 | 253 |
|
|
0 commit comments