Skip to content

Commit de1733d

Browse files
committed
[GR-39046] HPy unit tests: use 'gcc' without a full path.
PullRequest: graalpython/2298
2 parents 43ce485 + 910cc65 commit de1733d

File tree

8 files changed

+32
-23
lines changed

8 files changed

+32
-23
lines changed

graalpython/com.oracle.graal.python.jni/src/hpy_jni.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,12 @@ static long augment_Long_AsLong(HPyContext *ctx, HPy h) {
280280
static unsigned long augment_Long_AsUnsignedLong(HPyContext *ctx, HPy h) {
281281
uint64_t bits = toBits(h);
282282
if (isBoxedInt(bits)) {
283-
return unboxInt(bits);
284-
} else {
285-
return original_Long_AsUnsignedLong(ctx, h);
283+
int32_t unboxed = unboxInt(bits);
284+
if (unboxed >= 0) {
285+
return unboxed;
286+
}
286287
}
288+
return original_Long_AsUnsignedLong(ctx, h);
287289
}
288290

289291
static double augment_Long_AsDouble(HPyContext *ctx, HPy h) {
@@ -296,36 +298,32 @@ static double augment_Long_AsDouble(HPyContext *ctx, HPy h) {
296298
}
297299

298300
static HPy augment_Long_FromLong(HPyContext *ctx, long l) {
299-
int32_t i = (int32_t) l;
300-
if (l == i) {
301-
return toPtr(boxInt(i));
301+
if (isBoxableInt(l)) {
302+
return toPtr(boxInt((int32_t) l));
302303
} else {
303304
return original_Long_FromLong(ctx, l);
304305
}
305306
}
306307

307308
static HPy augment_Long_FromUnsignedLong(HPyContext *ctx, unsigned long l) {
308-
int32_t i = (int32_t) l;
309-
if (l == i) {
310-
return toPtr(boxInt(i));
309+
if (isBoxableUnsignedInt(l)) {
310+
return toPtr(boxInt((int32_t) l));
311311
} else {
312312
return original_Long_FromUnsignedLong(ctx, l);
313313
}
314314
}
315315

316316
static HPy augment_Long_FromLongLong(HPyContext *ctx, long long l) {
317-
int32_t i = (int32_t) l;
318-
if (l == i) {
319-
return toPtr(boxInt(i));
317+
if (isBoxableInt(l)) {
318+
return toPtr(boxInt((int32_t) l));
320319
} else {
321320
return original_Long_FromLongLong(ctx, l);
322321
}
323322
}
324323

325324
static HPy augment_Long_FromUnsignedLongLong(HPyContext *ctx, unsigned long long l) {
326-
int32_t i = (int32_t) l;
327-
if (l == i) {
328-
return toPtr(boxInt(i));
325+
if (isBoxableUnsignedInt(l)) {
326+
return toPtr(boxInt((int32_t) l));
329327
} else {
330328
return original_Long_FromUnsignedLongLong(ctx, l);
331329
}

graalpython/com.oracle.graal.python.jni/src/hpy_jni.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747

4848
#include <hpy.h>
4949
#include <jni.h>
50+
#include <stdint.h>
5051

5152
//*************************
5253
// BOXING
@@ -65,6 +66,8 @@
6566
#define unboxHandle(value) (value)
6667
#define boxHandle(handle) (handle)
6768

69+
#define isBoxableInt(value) (INT32_MIN < (value) && (value) < INT32_MAX)
70+
#define isBoxableUnsignedInt(value) ((value) < INT32_MAX)
6871
#define unboxInt(value) ((int32_t) ((value) - NAN_BOXING_INT))
6972
#define boxInt(value) ((((uint64_t) (value)) & NAN_BOXING_INT_MASK) + NAN_BOXING_INT)
7073

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContext.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@
8383
import com.oracle.graal.python.builtins.objects.cext.capi.CApiContext;
8484
import com.oracle.graal.python.builtins.objects.cext.common.CArrayWrappers;
8585
import com.oracle.graal.python.builtins.objects.cext.common.CArrayWrappers.CStringWrapper;
86-
import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodesFactory.AsNativePrimitiveNodeGen;
8786
import com.oracle.graal.python.builtins.objects.cext.common.CExtContext;
8887
import com.oracle.graal.python.builtins.objects.cext.common.LoadCExtException.ApiInitException;
8988
import com.oracle.graal.python.builtins.objects.cext.common.LoadCExtException.ImportException;
89+
import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodesFactory.AsNativePrimitiveNodeGen;
9090
import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyContextFunctions.GraalHPyAsIndex;
9191
import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyContextFunctions.GraalHPyAsPyObject;
9292
import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyContextFunctions.GraalHPyBinaryArithmetic;
@@ -169,12 +169,12 @@
169169
import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyContextFunctions.ReturnType;
170170
import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyNodes.HPyAttachFunctionTypeNode;
171171
import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyNodes.PCallHPyFunction;
172+
import com.oracle.graal.python.builtins.objects.cext.hpy.HPyExternalFunctionNodes.HPyCheckFunctionResultNode;
172173
import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyNodesFactory.HPyAsPythonObjectNodeGen;
173174
import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyNodesFactory.HPyGetNativeSpacePointerNodeGen;
174175
import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyNodesFactory.HPyRaiseNodeGen;
175176
import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyNodesFactory.HPyTransformExceptionToNativeNodeGen;
176177
import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyNodesFactory.PCallHPyFunctionNodeGen;
177-
import com.oracle.graal.python.builtins.objects.cext.hpy.HPyExternalFunctionNodes.HPyCheckFunctionResultNode;
178178
import com.oracle.graal.python.builtins.objects.common.EmptyStorage;
179179
import com.oracle.graal.python.builtins.objects.common.HashMapStorage;
180180
import com.oracle.graal.python.builtins.objects.common.HashingStorage;
@@ -349,7 +349,7 @@ public static Object loadHPyModule(Node location, PythonContext context, String
349349
if (llvmInteropLib.isMemberExisting(llvmLibrary, hpyInitFuncName)) {
350350
return hpyContext.initHPyModule(context, llvmLibrary, hpyInitFuncName, name, path, debug, llvmInteropLib, checkResultNode);
351351
}
352-
throw new ImportException(null, name, path, ErrorMessages.CANNOT_INITIALIZE_WITH, path, basename, "");
352+
throw new ImportException(null, name, path, ErrorMessages.CANNOT_INITIALIZE_EXT_NO_ENTRY, basename, path, hpyInitFuncName);
353353
} catch (UnsupportedTypeException | ArityException | UnsupportedMessageException e) {
354354
throw new ImportException(CExtContext.wrapJavaException(e, location), name, path, ErrorMessages.CANNOT_INITIALIZE_WITH, path, basename, "");
355355
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/ErrorMessages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ public abstract class ErrorMessages {
168168
public static final String CANNOT_IMPORT_NAME = "cannot import name '%s' from '%s' (%s)";
169169
public static final String CANNOT_IMPORT_NAME_CIRCULAR = "cannot import name '%s' from partially initialized module '%s' (most likely due to a circular import)";
170170
public static final String CANNOT_INITIALIZE_WITH = "cannot initialize %s with %s%s";
171+
public static final String CANNOT_INITIALIZE_EXT_NO_ENTRY = "cannot initialize extension '%s' at path '%s', entry point '%s' not found";
171172
public static final String CANNOT_LOAD = "cannot load %s: %s";
172173
public static final String CANNOT_LOAD_M = "cannot load %s: %m";
173174
public static final String CANNOT_RELEASE_UNAQUIRED_LOCK = "cannot release un-acquired lock";

graalpython/lib-graalpython/modules/hpy/test/debug/test_handles_invalid.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ def test_keeping_and_reusing_argument_handle(compiler, hpy_debug_capture):
175175
assert hpy_debug_capture.invalid_handles_count == 1
176176

177177

178+
@pytest.mark.xfail(reason="set_handle_stack_trace_limit not implemented yet")
178179
def test_invalid_handle_crashes_python_if_no_hook(compiler, python_subprocess, fatal_exit_code):
179180
if not SUPPORTS_SYS_EXECUTABLE:
180181
pytest.skip("no sys.executable")

graalpython/lib-graalpython/modules/hpy/test/debug/test_handles_leak.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ def test_leak_from_method(compiler):
135135
leaks = [dh.obj for dh in _debug.get_open_handles(gen)]
136136
assert leaks == ["a"]
137137

138+
@pytest.mark.xfail(reason="set_handle_stack_trace_limit not implemented yet")
138139
def test_DebugHandle_id(compiler, with_alloc_trace):
139140
from hpy.universal import _debug
140141
mod = make_leak_module(compiler)
@@ -183,6 +184,7 @@ def test_DebugHandle_compare(compiler):
183184
with pytest.raises(TypeError):
184185
a1 < 'hello'
185186

187+
@pytest.mark.xfail(reason="set_handle_stack_trace_limit not implemented yet")
186188
def test_DebugHandle_repr(compiler, with_alloc_trace):
187189
from hpy.universal import _debug
188190
mod = make_leak_module(compiler)
@@ -215,6 +217,7 @@ def test_LeakDetector(compiler):
215217
assert 'hello' not in msg
216218
assert 'world' not in msg
217219

220+
@pytest.mark.xfail(reason="set_handle_stack_trace_limit not implemented yet")
218221
def test_closed_handles(compiler, with_alloc_trace):
219222
from hpy.universal import _debug
220223
mod = make_leak_module(compiler)

graalpython/lib-graalpython/modules/hpy/test/support.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,8 @@ def change_compiler(conf, cc, cxx, stdlib):
317317
cxx = join(llvm_toolchain_vanilla, 'clang++')
318318
stdlib = "libc++"
319319
else:
320-
cc = join(os.path.sep, 'usr', 'bin', 'gcc')
321-
cxx = join(os.path.sep, 'usr', 'bin', 'g++')
320+
cc = 'gcc'
321+
cxx = 'g++'
322322
stdlib = None
323323
change_compiler(conf, cc, cxx, stdlib)
324324

mx.graalpython/mx_graalpython.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ def patch_batch_launcher(launcher_path, jvm_args):
758758
launcher.writelines(lines)
759759

760760

761-
def run_hpy_unittests(python_binary, args=None):
761+
def run_hpy_unittests(python_binary, args=None, include_native=True):
762762
args = [] if args is None else args
763763
with tempfile.TemporaryDirectory(prefix='hpy-test-site-') as d:
764764
env = os.environ.copy()
@@ -783,7 +783,10 @@ def run(self):
783783
except Exception as e: # pylint: disable=broad-except;
784784
self.exc = e
785785

786-
for abi in ['cpython', 'universal', 'debug', 'nfi']:
786+
abi_list = ['cpython', 'universal', 'debug']
787+
if include_native:
788+
abi_list.append('nfi')
789+
for abi in abi_list:
787790
env["TEST_HPY_ABI"] = abi
788791
threads.append(RaisingThread(target=run_python_unittests, args=(python_binary, ), kwargs={
789792
"args": args, "paths": [_hpy_test_root()], "env": env.copy(), "use_pytest": True, "lock": lock,
@@ -855,7 +858,7 @@ def graalpython_gate_runner(args, tasks):
855858

856859
with Task('GraalPython HPy sandboxed tests', tasks, tags=[GraalPythonTags.unittest_hpy_sandboxed]) as task:
857860
if task:
858-
run_hpy_unittests(python_managed_svm())
861+
run_hpy_unittests(python_managed_svm(), include_native=False)
859862

860863
with Task('GraalPython posix module tests', tasks, tags=[GraalPythonTags.unittest_posix]) as task:
861864
if task:

0 commit comments

Comments
 (0)