Skip to content

Commit 67d409e

Browse files
fangerertimfel
authored andcommitted
Merge branch 'ss/fix-hpy-tests'
2 parents 7cffe20 + 5f80671 commit 67d409e

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -332,36 +332,32 @@ static double augment_Long_AsDouble(HPyContext *ctx, HPy h) {
332332
}
333333

334334
static HPy augment_Long_FromLong(HPyContext *ctx, long l) {
335-
int32_t i = (int32_t) l;
336-
if (l == i) {
337-
return toPtr(boxInt(i));
335+
if (isBoxableInt(l)) {
336+
return toPtr(boxInt((int32_t) l));
338337
} else {
339338
return original_Long_FromLong(ctx, l);
340339
}
341340
}
342341

343342
static HPy augment_Long_FromUnsignedLong(HPyContext *ctx, unsigned long l) {
344-
int32_t i = (int32_t) l;
345-
if (l == i) {
346-
return toPtr(boxInt(i));
343+
if (isBoxableUnsignedInt(l)) {
344+
return toPtr(boxInt((int32_t) l));
347345
} else {
348346
return original_Long_FromUnsignedLong(ctx, l);
349347
}
350348
}
351349

352350
static HPy augment_Long_FromLongLong(HPyContext *ctx, long long l) {
353-
int32_t i = (int32_t) l;
354-
if (l == i) {
355-
return toPtr(boxInt(i));
351+
if (isBoxableInt(l)) {
352+
return toPtr(boxInt((int32_t) l));
356353
} else {
357354
return original_Long_FromLongLong(ctx, l);
358355
}
359356
}
360357

361358
static HPy augment_Long_FromUnsignedLongLong(HPyContext *ctx, unsigned long long l) {
362-
int32_t i = (int32_t) l;
363-
if (l == i) {
364-
return toPtr(boxInt(i));
359+
if (isBoxableUnsignedInt(l)) {
360+
return toPtr(boxInt((int32_t) l));
365361
} else {
366362
return original_Long_FromUnsignedLongLong(ctx, l);
367363
}

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/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

0 commit comments

Comments
 (0)