Skip to content

Commit daf3e1f

Browse files
committed
Update HPy inlined files: b0fbdf73
1 parent 9baaf7c commit daf3e1f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1047
-81
lines changed

graalpython/com.oracle.graal.python.hpy.llvm/include/hpy/version.h

Lines changed: 0 additions & 4 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import pytest
22
from .support import ExtensionCompiler, DefaultExtensionTemplate,\
33
PythonSubprocessRunner, HPyDebugCapture, make_hpy_abi_fixture
4-
from hpy.debug.leakdetector import LeakDetector
54
from pathlib import Path
65

76
IS_VALGRIND_RUN = False
@@ -48,6 +47,7 @@ def leakdetector(hpy_abi):
4847
"""
4948
Automatically detect leaks when the hpy_abi == 'debug'
5049
"""
50+
from hpy.debug.leakdetector import LeakDetector
5151
if 'debug' in hpy_abi:
5252
with LeakDetector() as ld:
5353
yield ld

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

Whitespace-only changes.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import pytest
3-
from test.support import SUPPORTS_SYS_EXECUTABLE, SUPPORTS_MEM_PROTECTION
3+
from ..support import SUPPORTS_SYS_EXECUTABLE, SUPPORTS_MEM_PROTECTION
44

55
# Tests detection of usage of char pointers associated with invalid already
66
# closed handles. For now, the debug mode does not provide any hook for this
@@ -293,4 +293,4 @@ def clear_raw_data_in_closed_handles():
293293
assert h.raw_data_size == -1
294294
finally:
295295
_debug.set_protected_raw_data_max_size(old_raw_data_max_size)
296-
_debug.set_closed_handles_queue_max_size(old_closed_handles_max_size)
296+
_debug.set_closed_handles_queue_max_size(old_closed_handles_max_size)

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import pytest
2+
import sys
23
from hpy.debug.leakdetector import LeakDetector
3-
from test.support import SUPPORTS_SYS_EXECUTABLE, IS_PYTHON_DEBUG_BUILD
4-
from test.conftest import IS_VALGRIND_RUN
4+
from ..support import SUPPORTS_SYS_EXECUTABLE, IS_PYTHON_DEBUG_BUILD
5+
from ..conftest import IS_VALGRIND_RUN
56

67
@pytest.fixture
78
def hpy_abi():
89
with LeakDetector():
910
yield "debug"
1011

1112

13+
@pytest.mark.skipif(sys.implementation.name == 'pypy',
14+
reason="Cannot recover from use-after-close on pypy")
1215
def test_no_invalid_handle(compiler, hpy_debug_capture):
1316
# Basic sanity check that valid code does not trigger any error reports
1417
mod = compiler.make_module("""
@@ -33,6 +36,8 @@ def test_no_invalid_handle(compiler, hpy_debug_capture):
3336
assert hpy_debug_capture.invalid_handles_count == 0
3437

3538

39+
@pytest.mark.skipif(sys.implementation.name == 'pypy',
40+
reason="Cannot recover from use-after-close on pypy")
3641
def test_cant_use_closed_handle(compiler, hpy_debug_capture):
3742
mod = compiler.make_module("""
3843
HPyDef_METH(f, "f", HPyFunc_O, .doc="double close")
@@ -106,6 +111,8 @@ def test_cant_use_closed_handle(compiler, hpy_debug_capture):
106111
assert hpy_debug_capture.invalid_handles_count == 6
107112

108113

114+
@pytest.mark.skipif(sys.implementation.name == 'pypy',
115+
reason="Cannot recover from use-after-close on pypy")
109116
def test_keeping_and_reusing_argument_handle(compiler, hpy_debug_capture):
110117
mod = compiler.make_module("""
111118
HPy keep;
@@ -197,4 +204,4 @@ def test_invalid_handle_crashes_python_if_no_hook(compiler, python_subprocess, f
197204
""")
198205
result = python_subprocess.run(mod, "mod.f(42);")
199206
assert result.returncode == fatal_exit_code
200-
assert b"Invalid usage of already closed handle" in result.stderr
207+
assert b"Invalid usage of already closed handle" in result.stderr

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pytest
2-
from test.support import SUPPORTS_SYS_EXECUTABLE, SUPPORTS_MEM_PROTECTION
2+
from ..support import SUPPORTS_SYS_EXECUTABLE, SUPPORTS_MEM_PROTECTION
33

44
@pytest.fixture
55
def hpy_abi():

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

Whitespace-only changes.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import py
1717
import pytest
1818

19-
from test.support import atomic_run, HPY_ROOT
19+
from ..support import atomic_run, HPY_ROOT
2020

2121
# ====== IMPORTANT DEVELOPMENT TIP =====
2222
# You can use py.test --reuse-venv to speed up local testing.

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

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,19 @@ def make_hpy_abi_fixture(ABIs, class_fixture=False):
4949
class TestFoo(HPyTest):
5050
hpy_abi = make_hpy_abi_fixture('with hybrid', class_fixture=True)
5151
"""
52-
if ABIs == 'default':
53-
ABIs = ['cpython', 'universal', 'debug']
54-
elif ABIs == 'with hybrid':
55-
ABIs = ['cpython', 'hybrid', 'hybrid+debug']
56-
elif isinstance(ABIs, list):
52+
is_cpython = not hasattr(sys, "implementation") or sys.implementation.name == 'cpython'
53+
if isinstance(ABIs, list):
5754
pass
5855
else:
59-
raise ValueError("ABIs must be 'default', 'with hybrid' "
60-
"or a list of strings. Got: %s" % ABIs)
61-
56+
if ABIs == 'default':
57+
ABIs = ['universal', 'debug']
58+
elif ABIs == 'with hybrid':
59+
ABIs = ['hybrid', 'hybrid+debug']
60+
else:
61+
raise ValueError("ABIs must be 'default', 'with hybrid' "
62+
"or a list of strings. Got: %s" % ABIs)
63+
if is_cpython:
64+
ABIs.append('cpython')
6265
if class_fixture:
6366
@pytest.fixture(params=ABIs)
6467
def hpy_abi(self, request):
@@ -495,15 +498,6 @@ def supports_ordinary_make_module_imports(self):
495498
"""
496499
return True
497500

498-
def supports_refcounts(self):
499-
""" Returns True if the underlying Python implementation supports
500-
the vectorcall protocol.
501-
502-
By default, this returns True for Python version 3.8+ on all
503-
implementations.
504-
"""
505-
return sys.version_info >= (3, 8)
506-
507501

508502
class HPyDebugCapture:
509503
"""

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"""
99
from .support import HPyTest
1010
from hpy.devel.abitag import HPY_ABI_VERSION, HPY_ABI_VERSION_MINOR
11-
import shutil
1211

1312

1413
class TestBasic(HPyTest):
@@ -48,6 +47,7 @@ def test_abi_version_check(self):
4847
assert False, "Expected exception"
4948

5049
def test_abi_tag_check(self):
50+
import shutil
5151
if self.compiler.hpy_abi != 'universal':
5252
return
5353

@@ -262,6 +262,7 @@ def test_builtin_handles(self):
262262
case 20: h = ctx->h_MemoryViewType; break;
263263
case 21: h = ctx->h_SliceType; break;
264264
case 22: h = ctx->h_Builtins; break;
265+
case 23: h = ctx->h_DictType; break;
265266
case 2048: h = ctx->h_CapsuleType; break;
266267
default:
267268
HPyErr_SetString(ctx, ctx->h_ValueError, "invalid choice");
@@ -278,7 +279,7 @@ def test_builtin_handles(self):
278279
'<NULL>', None, False, True, ValueError, TypeError, IndexError,
279280
SystemError, object, type, bool, int, float, str, tuple, list,
280281
NotImplemented, Ellipsis, complex, bytes, memoryview, slice,
281-
builtins.__dict__
282+
builtins.__dict__, dict
282283
)
283284
for i, obj in enumerate(builtin_objs):
284285
if i == 0:
@@ -560,3 +561,20 @@ def test_leave_python(self):
560561
@INIT
561562
""")
562563
assert mod.f("abraka") == 3
564+
565+
def test_dup_null(self):
566+
mod = self.make_module("""
567+
HPyDef_METH(f, "f", HPyFunc_NOARGS)
568+
static HPy f_impl(HPyContext *ctx, HPy self)
569+
{
570+
HPy h = HPy_Dup(ctx, HPy_NULL);
571+
if (HPy_IsNull(h)) {
572+
return HPyLong_FromSize_t(ctx, 0);
573+
}
574+
HPy_Close(ctx, h);
575+
return HPyLong_FromSize_t(ctx, -1);
576+
}
577+
@EXPORT(f)
578+
@INIT
579+
""")
580+
assert mod.f() == 0

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def test_s(self):
7575
"function a str is required"
7676
)
7777

78-
def test_B(self):
78+
def test_upper_b(self):
7979
mod = self.make_parse_item("B", "char", "char_to_hpybytes")
8080
assert mod.f(0) == b"\x00"
8181
assert mod.f(1) == b"\x01"
@@ -102,7 +102,7 @@ def test_h(self):
102102
"function signed short integer is less than minimum"
103103
)
104104

105-
def test_H_short(self):
105+
def test_upper_h_short(self):
106106
mod = self.make_parse_item("H", "short", "HPyLong_FromLong")
107107
assert mod.f(0) == 0
108108
assert mod.f(1) == 1
@@ -114,7 +114,7 @@ def test_H_short(self):
114114
assert mod.f(2**16) == 0
115115
assert mod.f(-2**16) == 0
116116

117-
def test_H_unsigned_short(self):
117+
def test_upper_h_unsigned_short(self):
118118
mod = self.make_parse_item(
119119
"H", "unsigned short", "HPyLong_FromUnsignedLong"
120120
)
@@ -147,7 +147,7 @@ def test_i(self):
147147
"Python int too large to convert to C long", # where sizeof(long) == 4
148148
)
149149

150-
def test_I_signed(self):
150+
def test_upper_i_signed(self):
151151
mod = self.make_parse_item("I", "int", "HPyLong_FromLong")
152152
assert mod.f(0) == 0
153153
assert mod.f(1) == 1
@@ -159,7 +159,7 @@ def test_I_signed(self):
159159
assert mod.f(2**32) == 0
160160
assert mod.f(-2**32) == 0
161161

162-
def test_I_unsigned(self):
162+
def test_upper_i_unsigned(self):
163163
mod = self.make_parse_item(
164164
"I", "unsigned int", "HPyLong_FromUnsignedLong"
165165
)
@@ -211,7 +211,7 @@ def test_k_unsigned(self):
211211
assert mod.f(2**ULONG_BITS) == 0
212212
assert mod.f(-2**ULONG_BITS) == 0
213213

214-
def test_L(self):
214+
def test_upper_l(self):
215215
import pytest
216216
mod = self.make_parse_item("L", "long long", "HPyLong_FromLongLong")
217217
assert mod.f(0) == 0
@@ -224,7 +224,7 @@ def test_L(self):
224224
with pytest.raises(OverflowError):
225225
mod.f(-2**63 - 1)
226226

227-
def test_K_signed(self):
227+
def test_upper_k_signed(self):
228228
mod = self.make_parse_item("K", "long long", "HPyLong_FromLongLong")
229229
assert mod.f(0) == 0
230230
assert mod.f(1) == 1
@@ -236,7 +236,7 @@ def test_K_signed(self):
236236
assert mod.f(2**64) == 0
237237
assert mod.f(-2**64) == 0
238238

239-
def test_K_unsigned(self):
239+
def test_upper_k_unsigned(self):
240240
mod = self.make_parse_item(
241241
"K", "unsigned long long", "HPyLong_FromUnsignedLongLong"
242242
)
@@ -277,7 +277,7 @@ def test_d(self):
277277
with pytest.raises(TypeError):
278278
mod.f("x")
279279

280-
def test_O(self):
280+
def test_upper_o(self):
281281
mod = self.make_parse_item("O", "HPy", "HPy_Dup")
282282
assert mod.f("a") == "a"
283283
assert mod.f(5) == 5

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ class TestHPyCapsule(HPyTest):
156156
ExtensionTemplate = CapsuleTemplate
157157

158158
def test_capsule_new(self):
159+
import pytest
159160
mod = self.make_module("""
160161
@DEFINE_SomeObject
161162
@DEFINE_Capsule_New
@@ -178,6 +179,7 @@ def test_capsule_new(self):
178179
mod.capsule_new()
179180

180181
def test_capsule_getter_and_setter(self):
182+
import pytest
181183
mod = self.make_module("""
182184
#include <string.h>
183185
@@ -385,6 +387,7 @@ def test_capsule_getter_and_setter(self):
385387
mod.capsule_freename(p)
386388

387389
def test_capsule_isvalid(self):
390+
import pytest
388391
mod = self.make_module("""
389392
@DEFINE_SomeObject
390393
@DEFINE_Capsule_New
@@ -455,6 +458,7 @@ def test_capsule_new_with_destructor(self):
455458
assert mod.pointer_freed()
456459

457460
def test_capsule_new_with_invalid_destructor(self):
461+
import pytest
458462
mod = self.make_module("""
459463
static HPyCapsule_Destructor mydtor = { NULL, NULL };
460464

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from textwrap import dedent
21
from .support import HPyTest
32

43
class TestEval(HPyTest):
54
def test_compile(self):
65
import pytest
6+
from textwrap import dedent
77
mod = self.make_module("""
88
HPyDef_METH(f, "f", HPyFunc_VARARGS)
99
static HPy f_impl(HPyContext *ctx, HPy self, const HPy *args, size_t nargs)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ def test_tp_finalize(self):
326326
// nicely with pytest, but if the finalizer gets called after the
327327
// test has finished, we have no choice but to abort to signal
328328
// the error
329+
static void on_unexpected_finalize_call(void);
329330
static void on_unexpected_finalize_call() {
330331
if (test_finished)
331332
abort();
@@ -420,4 +421,4 @@ def test_tp_finalize(self):
420421
owner.set_a(42)
421422
from gc import collect
422423
collect()
423-
assert mod.check_finalize_calls()
424+
assert mod.check_finalize_calls()

0 commit comments

Comments
 (0)