Skip to content

Commit 98bc613

Browse files
committed
[GR-14721] Don't use polyglot namespace for C API.
PullRequest: graalpython/459
2 parents c5f4bc4 + 34c1eda commit 98bc613

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ cache_t cache;
5959

6060
__attribute__((constructor (__COUNTER__)))
6161
static void initialize_upcall_functions() {
62-
PY_TRUFFLE_CEXT = (void*)polyglot_import("python_cext");
63-
PY_BUILTIN = (void*)polyglot_import("python_builtins");
62+
PY_TRUFFLE_CEXT = (void*)polyglot_eval("python", "import python_cext\npython_cext");
63+
PY_BUILTIN = (void*)polyglot_eval("python", "import builtins\nbuiltins");
6464

6565
PY_TRUFFLE_LANDING = ((PyObject*(*)(void *rcv, void* name, ...))polyglot_get_member(PY_TRUFFLE_CEXT, polyglot_from_string("PyTruffle_Upcall", SRC_CS)));
6666
PY_TRUFFLE_LANDING_L = ((PyObject*(*)(void *rcv, void* name, ...))polyglot_get_member(PY_TRUFFLE_CEXT, polyglot_from_string("PyTruffle_Upcall_l", SRC_CS)));

graalpython/com.oracle.graal.python.test/src/tests/test_interop.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,17 @@
4343
import polyglot
4444

4545
def test_import():
46-
imported_cext = polyglot.import_value("python_cext")
47-
import python_cext
48-
assert imported_cext is python_cext
46+
def some_function():
47+
return "hello, polyglot world!"
48+
polyglot.export_value(some_function)
49+
imported_fun0 = polyglot.import_value("some_function")
50+
assert imported_fun0 is some_function
51+
assert imported_fun0() == "hello, polyglot world!"
52+
53+
polyglot.export_value(some_function, "same_function")
54+
imported_fun1 = polyglot.import_value("same_function")
55+
assert imported_fun1 is some_function
56+
assert imported_fun1() == "hello, polyglot world!"
4957

5058
class GetterOnly():
5159
def __get__(self, instance, owner):

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,6 @@ private void initializePythonCore() {
421421
for (String s : coreFiles) {
422422
loadFile(s, coreHome);
423423
}
424-
exportCInterface(getContext());
425424
initialized = true;
426425
}
427426

@@ -480,20 +479,6 @@ private void publishBuiltinModules() {
480479
}
481480
}
482481

483-
public void exportCInterface(PythonContext context) {
484-
Env env = context.getEnv();
485-
if (env != null) {
486-
env.exportSymbol(TruffleCextBuiltins.PYTHON_CEXT, builtinModules.get(TruffleCextBuiltins.PYTHON_CEXT));
487-
env.exportSymbol("python_builtins", builtinsModule);
488-
489-
// export all exception classes for the C API
490-
for (PythonBuiltinClassType errorType : PythonBuiltinClassType.EXCEPTIONS) {
491-
PythonBuiltinClass errorClass = lookupType(errorType);
492-
env.exportSymbol("python_" + GetNameNode.doSlowPath(errorClass), errorClass);
493-
}
494-
}
495-
}
496-
497482
private PythonBuiltinClass initializeBuiltinClass(PythonBuiltinClassType type) {
498483
int index = type.ordinal();
499484
if (builtinTypes[index] == null) {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import com.oracle.graal.python.PythonLanguage;
5252
import com.oracle.graal.python.builtins.Builtin;
5353
import com.oracle.graal.python.builtins.CoreFunctions;
54+
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
5455
import com.oracle.graal.python.builtins.PythonBuiltins;
5556
import com.oracle.graal.python.builtins.objects.PNone;
5657
import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction;
@@ -257,6 +258,11 @@ public Object exportSymbol(PBuiltinMethod fun, @SuppressWarnings("unused") PNone
257258
return fun;
258259
}
259260

261+
@Fallback
262+
public Object exportSymbol(Object value, Object name) {
263+
throw raise(PythonBuiltinClassType.TypeError, "expected argument types (function) or (object, str) but not (%p, %p)", value, name);
264+
}
265+
260266
private String getMethodName(Object o) {
261267
if (getNameAttributeNode == null) {
262268
CompilerDirectives.transferToInterpreterAndInvalidate();

0 commit comments

Comments
 (0)