Skip to content

Commit 90d358e

Browse files
timfelsteve-s
authored andcommitted
avoid eager initialization of sulong context
1 parent 7e6f307 commit 90d358e

File tree

9 files changed

+40
-22
lines changed

9 files changed

+40
-22
lines changed

graalpython/com.oracle.graal.python.hpy.test/src/hpytest/debug/test_charptr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def test_charptr_write_ptr(compiler, python_subprocess):
210210
assert result.stderr == b""
211211

212212

213-
@pytest.mark.xfail(__graalpython__.platform_id == "managed", reason="unaligned memcpy is not supported")
213+
@pytest.mark.xfail(__graalpython__.get_platform_id() == "managed", reason="unaligned memcpy is not supported")
214214
def test_charptr_correct_usage(compiler):
215215
mod = compiler.make_module("""
216216
#include <string.h>

graalpython/com.oracle.graal.python.hpy.test/src/hpytest/support.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232

3333
PY2 = sys.version_info[0] == 2
3434
GRAALPYTHON = sys.implementation.name == 'graalpy'
35-
GRAALPYTHON_NATIVE = GRAALPYTHON and __graalpython__.platform_id == 'native'
36-
DARWIN_NATIVE = sys.platform == 'darwin' and (not GRAALPYTHON or __graalpython__.platform_id == 'native')
35+
GRAALPYTHON_NATIVE = GRAALPYTHON and __graalpython__.get_platform_id() == 'native'
36+
DARWIN_NATIVE = sys.platform == 'darwin' and (not GRAALPYTHON or __graalpython__.get_platform_id() == 'native')
3737

3838
HPY_ROOT = Path(__file__).parent.parent
3939
LOCK = FileLock(HPY_ROOT / ".hpy.lock")

graalpython/com.oracle.graal.python.hpy.test/src/hpytest/test_hpybuildvalue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def test_formats(self):
107107
actual = mod.f(i)
108108
assert actual == expected, code
109109

110-
@pytest.mark.xfail(__graalpython__.platform_id == "managed", reason="GR-38126")
110+
@pytest.mark.xfail(__graalpython__.get_platform_id() == "managed", reason="GR-38126")
111111
def test_bad_formats(self):
112112
test_cases = [
113113
('return HPy_BuildValue(ctx, "(q)", 42);',

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_gc.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
from . import CPyExtTestCase, CPyExtFunction, CPyExtType
4444
__dir__ = __file__.rpartition("/")[0]
4545

46-
GRAALPYTHON_NATIVE = sys.implementation.name == 'graalpy' and __graalpython__.platform_id == 'native'
46+
GRAALPYTHON_NATIVE = sys.implementation.name == 'graalpy' and __graalpython__.get_platform_id() == 'native'
4747

4848
# typedef PyObject * (*unaryfunc)(PyObject *);
4949
# typedef PyObject * (*binaryfunc)(PyObject *, PyObject *);
@@ -92,7 +92,7 @@
9292
// printf("free\\n");
9393
free_cnt++;
9494
PyObject_Del(a);
95-
}
95+
}
9696
static int dealloc_cnt = 0;
9797
void test_dealloc(PyObject *self) {
9898
// printf("dealloc\\n");
@@ -116,9 +116,9 @@
116116
tp_dealloc = "test_dealloc",
117117
tp_methods='{"getCounters", (PyCFunction)getCounters, METH_NOARGS | METH_STATIC, ""}, {"resetCounters", (PyCFunction)resetCounters, METH_NOARGS | METH_STATIC, ""}',
118118
)
119-
119+
120120
class TestGC1():
121-
121+
122122
def test_native_class(self):
123123
if GRAALPYTHON_NATIVE:
124124
gc.enable()
@@ -152,13 +152,13 @@ def test_native_class(self):
152152
# Py_ssize_t r2 = Py_REFCNT(o);
153153
# Py_DecRef(o);
154154
# Py_ssize_t r3 = Py_REFCNT(o);
155-
# return Py_BuildValue("(ii)", r2 - r1, r3 - r1);
155+
# return Py_BuildValue("(ii)", r2 - r1, r3 - r1);
156156
# }''',
157157
# resultspec="O",
158158
# argspec='O',
159159
# arguments=("PyObject* o", ),
160160
# callfunction="wrap_simple",
161-
# )
161+
# )
162162
#
163163
#
164164
# test_create = CPyExtFunction(
@@ -171,10 +171,10 @@ def test_native_class(self):
171171
# Py_ssize_t r2 = Py_REFCNT(o);
172172
# Py_DecRef(o);
173173
# Py_ssize_t r3 = Py_REFCNT(o);
174-
# return Py_BuildValue("(ii)", r2 - r1, r3 - r1);
174+
# return Py_BuildValue("(ii)", r2 - r1, r3 - r1);
175175
# }''',
176176
# resultspec="O",
177177
# argspec='O',
178178
# arguments=("PyObject* o", ),
179179
# callfunction="wrap_simple",
180-
# )
180+
# )

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,12 @@ public void postInitialize(Python3Core core) {
243243
TruffleString capiHome = context.getCAPIHome();
244244
Env env = context.getEnv();
245245
LanguageInfo llvmInfo = env.getInternalLanguages().get(J_LLVM_LANGUAGE);
246-
Toolchain toolchain = env.lookup(llvmInfo, Toolchain.class);
247246
mod.setAttribute(tsLiteral("jython_emulation_enabled"), language.getEngineOption(PythonOptions.EmulateJython));
248247
mod.setAttribute(tsLiteral("host_import_enabled"), context.getEnv().isHostLookupAllowed());
249248
mod.setAttribute(tsLiteral("core_home"), coreHome);
250249
mod.setAttribute(tsLiteral("stdlib_home"), stdlibHome);
251250
mod.setAttribute(tsLiteral("capi_home"), capiHome);
252251
mod.setAttribute(tsLiteral("jni_home"), context.getJNIHome());
253-
mod.setAttribute(tsLiteral("platform_id"), toTruffleStringUncached(toolchain.getIdentifier()));
254252
Object[] arr = convertToObjectArray(PythonOptions.getExecutableList(context));
255253
PList executableList = PythonObjectFactory.getUncached().createList(arr);
256254
mod.setAttribute(tsLiteral("executable_list"), executableList);
@@ -647,6 +645,18 @@ protected Object getToolPath(TruffleString tool) {
647645
}
648646
}
649647

648+
@Builtin(name = "get_platform_id", minNumOfPositionalArgs = 0)
649+
@TypeSystemReference(PythonArithmeticTypes.class)
650+
@GenerateNodeFactory
651+
public abstract static class GetPlatformId extends PythonBuiltinNode {
652+
@Specialization
653+
@TruffleBoundary
654+
protected TruffleString getPlatformId() {
655+
return getContext().getPlatformId();
656+
}
657+
658+
}
659+
650660
@Builtin(name = "get_toolchain_paths", minNumOfPositionalArgs = 1)
651661
@TypeSystemReference(PythonArithmeticTypes.class)
652662
@GenerateNodeFactory

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2534,9 +2534,7 @@ public TruffleString getSoAbi() {
25342534
// sys.implementation._multiarch
25352535
TruffleString multiArch = (TruffleString) PInteropGetAttributeNode.executeUncached(implementationObj, T__MULTIARCH);
25362536

2537-
LanguageInfo llvmInfo = env.getInternalLanguages().get(J_LLVM_LANGUAGE);
2538-
Toolchain toolchain = env.lookup(llvmInfo, Toolchain.class);
2539-
TruffleString toolchainId = toTruffleStringUncached(toolchain.getIdentifier());
2537+
TruffleString toolchainId = getPlatformId();
25402538

25412539
// only use '.pyd' if we are on 'Win32-native'
25422540
TruffleString soExt;
@@ -2555,6 +2553,16 @@ public TruffleString getSoAbi() {
25552553
return soABI;
25562554
}
25572555

2556+
public TruffleString getPlatformId() {
2557+
if (!getOption(PythonOptions.NativeModules)) {
2558+
LanguageInfo llvmInfo = env.getInternalLanguages().get(J_LLVM_LANGUAGE);
2559+
Toolchain toolchain = env.lookup(llvmInfo, Toolchain.class);
2560+
return toTruffleStringUncached(toolchain.getIdentifier());
2561+
} else {
2562+
return T_NATIVE;
2563+
}
2564+
}
2565+
25582566
public Thread getMainThread() {
25592567
if (mainThread != null) {
25602568
return mainThread.get();

graalpython/lib-graalpython/_sysconfig.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ def _get_posix_vars():
4343
import _imp
4444
import sys
4545
import os
46-
darwin_native = sys.platform == "darwin" and __graalpython__.platform_id == "native"
47-
win32_native = sys.platform == "win32" and __graalpython__.platform_id == "native"
46+
darwin_native = sys.platform == "darwin" and __graalpython__.get_platform_id() == "native"
47+
win32_native = sys.platform == "win32" and __graalpython__.get_platform_id() == "native"
4848

4949
# note: this must be kept in sync with _imp.extension_suffixes
50-
so_abi = sys.implementation.cache_tag + "-" + __graalpython__.platform_id + "-" + sys.implementation._multiarch
50+
so_abi = sys.implementation.cache_tag + "-" + __graalpython__.get_platform_id() + "-" + sys.implementation._multiarch
5151
if win32_native:
5252
so_ext = ".pyd"
5353
else:

graalpython/lib-python/3/distutils/command/build_ext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ def get_libraries(self, ext):
721721
pythonlib = (template %
722722
(sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
723723
# Begin Truffle change
724-
pythonlib = f"python-{__graalpython__.platform_id}"
724+
pythonlib = f"python-{__graalpython__.get_platform_id()}"
725725
# End Truffle change
726726
# don't extend ext.libraries, it may be shared with other
727727
# extensions, it is a reference to the original list

mx.graalpython/mx_graalpython.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,7 @@ def run_python_unittests(python_binary, args=None, paths=None, aot_compatible=Fa
11081108
# just to be able to verify, print C ext mode (also works for CPython)
11091109
mx.run([python_binary,
11101110
"-c",
1111-
"import sys; print('C EXT MODE: ' + (__graalpython__.platform_id if sys.implementation.name == 'graalpy' else 'cpython'))"],
1111+
"import sys; print('C EXT MODE: ' + (__graalpython__.get_platform_id() if sys.implementation.name == 'graalpy' else 'cpython'))"],
11121112
nonZeroIsFatal=True, env=env, out=out, err=err)
11131113

11141114
# list all 1st-level tests and exclude the SVM-incompatible ones

0 commit comments

Comments
 (0)