Skip to content

Commit 30080aa

Browse files
committed
Merge branch 'master' into mq/GR-57401_1
2 parents 705b478 + 70da40f commit 30080aa

File tree

82 files changed

+2514
-861
lines changed

Some content is hidden

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

82 files changed

+2514
-861
lines changed

ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "overlay": "135a012d8317556124e728eea5f638747e21aef2" }
1+
{ "overlay": "a74e2e4ae250150f0f974c20c80ac212a9116ea1" }

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,6 @@ PyTypeObject PyTuple_Type = {
942942
};
943943

944944

945-
#if 0 // GraalPy change
946945
/* The following function breaks the notion that tuples are immutable:
947946
it changes the size of a tuple. We get away with this only if there
948947
is only one module referencing the object. You can also think of it
@@ -960,7 +959,8 @@ _PyTuple_Resize(PyObject **pv, Py_ssize_t newsize)
960959

961960
v = (PyTupleObject *) *pv;
962961
if (v == NULL || !Py_IS_TYPE(v, &PyTuple_Type) ||
963-
(Py_SIZE(v) != 0 && Py_REFCNT(v) != 1)) {
962+
// GraalPy change: ignore refcnt
963+
/* (Py_SIZE(v) != 0 && Py_REFCNT(v) != 1) */ 0) {
964964
*pv = 0;
965965
Py_XDECREF(v);
966966
PyErr_BadInternalCall();
@@ -973,7 +973,9 @@ _PyTuple_Resize(PyObject **pv, Py_ssize_t newsize)
973973
}
974974
if (newsize == 0) {
975975
Py_DECREF(v);
976-
*pv = tuple_get_empty();
976+
// GraalPy change: no empty tuple singleton
977+
// *pv = tuple_get_empty();
978+
*pv = PyTuple_New(0);
977979
return 0;
978980
}
979981
if (oldsize == 0) {
@@ -987,6 +989,19 @@ _PyTuple_Resize(PyObject **pv, Py_ssize_t newsize)
987989
return *pv == NULL ? -1 : 0;
988990
}
989991

992+
// Begin GraalPy change
993+
if (points_to_py_handle_space(v)) {
994+
GraalPyVarObject *o = (GraalPyVarObject *)pointer_to_stub(v);
995+
PyObject** new_items = GraalPyTruffleTuple_Resize((PyObject *)v, newsize, o->ob_item);
996+
if (new_items == NULL && o->ob_item != NULL) {
997+
*pv = NULL;
998+
return -1;
999+
}
1000+
o->ob_size = newsize;
1001+
o->ob_item = new_items;
1002+
return 0;
1003+
}
1004+
// End GraalPy change
9901005
if (_PyObject_GC_IS_TRACKED(v)) {
9911006
_PyObject_GC_UNTRACK(v);
9921007
}
@@ -1016,6 +1031,7 @@ _PyTuple_Resize(PyObject **pv, Py_ssize_t newsize)
10161031
return 0;
10171032
}
10181033

1034+
#if 0 // GraalPy change
10191035

10201036
static void maybe_freelist_clear(PyInterpreterState *, int);
10211037

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import ctypes
4040
import os.path
4141
import struct
42+
import sys
4243

4344
from tests.cpyext import CPyExtTestCase, CPyExtType
4445

@@ -225,3 +226,27 @@ class MyLargeStruct(ctypes.Structure):
225226
assert result.num7 == 42
226227
finally:
227228
os.chdir(original_cwd)
229+
230+
231+
def test_void_p():
232+
assert ctypes.c_void_p(True).value == ctypes.c_void_p(1).value
233+
assert ctypes.c_void_p(False).value == ctypes.c_void_p(0).value
234+
assert ctypes.c_void_p(2**128 - 1).value == ctypes.c_void_p(2**64 - 1).value
235+
try:
236+
ctypes.c_void_p(2**128 - 1)
237+
except TypeError as e:
238+
assert "cannot be converted to pointer" in str(e)
239+
240+
241+
def test_meson_windows_detect_native_arch() -> str:
242+
if sys.platform != 'win32':
243+
return
244+
process_arch = ctypes.c_ushort()
245+
native_arch = ctypes.c_ushort()
246+
kernel32 = ctypes.windll.kernel32
247+
process = ctypes.c_void_p(kernel32.GetCurrentProcess())
248+
try:
249+
if kernel32.IsWow64Process2(process, ctypes.byref(process_arch), ctypes.byref(native_arch)):
250+
assert native_arch.value == 0x8664, "only amd64 supported by GraalPy on Windows"
251+
except AttributeError as e:
252+
assert "Unknown identifier: IsWow64Process2" in str(e)

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ def _reference_setitem(args):
6767
return tuple(t)
6868

6969

70+
def _reference_resize(args):
71+
original = args[0]
72+
newsize = args[1]
73+
return original[:newsize] + (None,) * (newsize - len(original))
74+
return tuple(result)
75+
76+
7077
class MyStr(str):
7178

7279
def __init__(self, s):
@@ -259,6 +266,35 @@ class TestPyTuple(CPyExtTestCase):
259266
cmpfunc=unhandled_error_compare
260267
)
261268

269+
# _PyTuple_Resize
270+
test_PyTuple_Resize = CPyExtFunction(
271+
_reference_resize,
272+
lambda: (
273+
((1, 2, 3), 1),
274+
((), 1),
275+
((1, 2, 3), 5),
276+
),
277+
code="""
278+
PyObject* wrap_PyTuple_Resize(PyObject* original, int newsize) {
279+
int size = PyTuple_Size(original);
280+
PyObject *freshTuple = PyTuple_New(size);
281+
for (int i = 0; i < size; ++i) {
282+
PyTuple_SET_ITEM(freshTuple, i, Py_NewRef(PyTuple_GetItem(original, i)));
283+
}
284+
_PyTuple_Resize(&freshTuple, newsize);
285+
for (int i = size; i < newsize; i++) {
286+
PyTuple_SET_ITEM(freshTuple, i, Py_NewRef(Py_None));
287+
}
288+
return freshTuple;
289+
}
290+
""",
291+
resultspec="O",
292+
argspec='Oi',
293+
arguments=["PyObject* original", "Py_ssize_t newsize"],
294+
callfunction="wrap_PyTuple_Resize",
295+
cmpfunc=unhandled_error_compare,
296+
)
297+
262298

263299
class TestNativeSubclass(unittest.TestCase):
264300
def _verify(self, t):

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

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -37,10 +37,12 @@
3737
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3838
# SOFTWARE.
3939

40+
import gc
41+
import time
4042
import unittest
4143
import weakref
4244

43-
from . import CPyExtType, assert_raises
45+
from . import CPyExtFunction, CPyExtType, assert_raises
4446

4547
TestWeakRefHelper = CPyExtType(
4648
'TestWeakRefHelper',
@@ -95,3 +97,47 @@ class Bar(clazz):
9597
x = Bar()
9698
y = weakref.ref(x)
9799
assert type(y) == weakref.ReferenceType
100+
101+
def clear_ref_arguments():
102+
class Foo():
103+
pass
104+
f = Foo()
105+
log = []
106+
wr = weakref.ref(f, lambda wr: log.append("cb called"))
107+
return ((f, wr, log),)
108+
109+
def clear_ref_equivalent(args):
110+
# Ignore args. There is no clearref in python, so
111+
# the equivalent is a weakref that never had a callback
112+
# in the first place
113+
class Foo():
114+
pass
115+
f = Foo()
116+
return weakref.ref(f), []
117+
118+
def compare_cleared_weakref(cresult, presult):
119+
cwr, clog = cresult
120+
pwr, plog = presult
121+
for i in range(3):
122+
gc.collect()
123+
time.sleep(1)
124+
assert cwr() is None
125+
assert pwr() is None
126+
assert not clog
127+
assert not plog
128+
return True
129+
130+
test_PyWeakref_ClearRef = CPyExtFunction(
131+
clear_ref_equivalent,
132+
clear_ref_arguments,
133+
code="""
134+
PyObject* wrap_PyWeakref_ClearRef(PyObject *o, PyObject* weakref, PyObject* log) {
135+
_PyWeakref_ClearRef((PyWeakReference *)weakref);
136+
return Py_BuildValue("OO", weakref, log);
137+
}
138+
""",
139+
argspec='OOO',
140+
arguments=["PyObject* o", "PyObject* weakref", "PyObject* log"],
141+
callfunction="wrap_PyWeakref_ClearRef",
142+
cmpfunc=compare_cleared_weakref,
143+
)

graalpython/com.oracle.graal.python.test/src/tests/standalone/util.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ def print_missing_graalpy_msg(graalpy_home=None):
258258
sep="\n")
259259

260260
def get_graalvm_version():
261-
graalvmVersion, _ = run_cmd([get_gp(), "-c", "print(__graalpython__.get_graalvm_version(), end='')"], os.environ.copy())
261+
if not (graalvmVersion := os.environ.get("GRAAL_VERSION")):
262+
graalvmVersion, _ = run_cmd([get_gp(), "-c", "print(__graalpython__.get_graalvm_version(), end='')"], os.environ.copy())
262263
# when JLine is cannot detect a terminal, it prints logging info
263264
graalvmVersion = graalvmVersion.split("\n")[-1]
264265
# we never test -dev versions here, we always pretend to use release versions

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ def foo(**kwargs):
172172

173173
assert foo(a=5, b=6) == {'a': 1, 'b': 1}
174174

175+
d = dict.fromkeys({'a': 1, 'b': 2, 'c': 3})
176+
assert len(d) == 3
177+
assert set(d.keys()) == {'a', 'b', 'c'}
178+
assert set(d.values()) == {None}
179+
175180

176181
def test_init():
177182
d = dict(a=1, b=2, c=3)

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -876,7 +876,6 @@ def test_sysconf_names(self):
876876
self.assertIn('SC_CLK_TCK', os.sysconf_names)
877877

878878
def test_sysconf(self):
879-
self.assertGreaterEqual(os.sysconf('SC_CLK_TCK'), 0)
880879
with self.assertRaisesRegex(TypeError, 'strings or integers'):
881880
os.sysconf(object())
882881
with self.assertRaisesRegex(ValueError, 'unrecognized'):
@@ -889,6 +888,17 @@ def test_sysconf(self):
889888
else:
890889
assert False
891890

891+
# constants taken from POSIX where defined
892+
self.assertGreaterEqual(os.sysconf('SC_ARG_MAX'), 4096)
893+
self.assertGreaterEqual(os.sysconf('SC_CHILD_MAX'), 25)
894+
self.assertGreaterEqual(os.sysconf('SC_LOGIN_NAME_MAX'), 9)
895+
self.assertGreaterEqual(os.sysconf('SC_CLK_TCK'), 0)
896+
self.assertGreaterEqual(os.sysconf('SC_OPEN_MAX'), 20)
897+
self.assertGreaterEqual(os.sysconf('SC_PAGESIZE'), 1)
898+
os.sysconf('SC_SEM_NSEMS_MAX') # returns -1 on my linux box, just check it's there
899+
self.assertGreaterEqual(os.sysconf('SC_PHYS_PAGES'), 1)
900+
self.assertGreaterEqual(os.sysconf('SC_NPROCESSORS_CONF'), 1)
901+
892902

893903
if __name__ == '__main__':
894904
unittest.main()

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,23 @@
5050
import termios
5151
from textwrap import dedent
5252

53+
# The terminal tests can be flaky
54+
def autoretry(fn):
55+
def decorated(*args, **kwargs):
56+
retries = 3
57+
while retries:
58+
try:
59+
fn(*args, **kwargs)
60+
return
61+
except Exception:
62+
retries -= 1
63+
print("Retrying test")
64+
continue
65+
fn(*args, **kwargs)
66+
return decorated
5367

68+
69+
@autoretry
5470
def validate_repl(stdin, python_args=(), ignore_preamble=True):
5571
env = os.environ.copy()
5672
env['TERM'] = 'ansi'

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_cmd_line.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ test.test_cmd_line.CmdLineTest.test_unbuffered_input @ darwin-arm64,darwin-x86_6
2121
test.test_cmd_line.CmdLineTest.test_unbuffered_output @ darwin-arm64,darwin-x86_64,linux-aarch64,linux-x86_64,win32-AMD64
2222
test.test_cmd_line.CmdLineTest.test_unmached_quote @ darwin-arm64,darwin-x86_64,linux-aarch64,linux-x86_64,win32-AMD64
2323
test.test_cmd_line.CmdLineTest.test_verbose @ darwin-arm64,darwin-x86_64,linux-aarch64,linux-x86_64,win32-AMD64
24-
test.test_cmd_line.CmdLineTest.test_version @ linux-x86_64
24+
test.test_cmd_line.CmdLineTest.test_version @ darwin-arm64,darwin-x86_64,linux-aarch64,linux-x86_64,win32-AMD64
2525
test.test_cmd_line.IgnoreEnvironmentTest.test_ignore_PYTHONPATH @ darwin-arm64,darwin-x86_64,linux-aarch64,linux-x86_64,win32-AMD64

0 commit comments

Comments
 (0)