Skip to content

Commit 283be5e

Browse files
committed
Add patch for pygobject that works on 24.2.1 also for now
1 parent 2f3f1b7 commit 283be5e

File tree

2 files changed

+287
-0
lines changed

2 files changed

+287
-0
lines changed

graalpython/lib-graalpython/patches/metadata.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,11 @@ version = '== 2.*'
520520
patch = 'pygame-2.patch'
521521
license = 'LGPL-2.0-or-later'
522522

523+
[[pygobject.rules]]
524+
version = '== 3.52.3'
525+
patch = 'pygobject-3.52.3.patch'
526+
license = 'LGPL-2.0-or-later'
527+
523528
[[pymongo.rules]]
524529
version = "< 4.8.0"
525530
patch = 'pymongo.patch'
Lines changed: 282 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,282 @@
1+
diff --git a/gi/pygenum.c b/gi/pygenum.c
2+
index d8ab0e25..f9881110 100644
3+
--- a/gi/pygenum.c
4+
+++ b/gi/pygenum.c
5+
@@ -90,13 +90,28 @@ add_value (PyObject *dict, const char *value_nick, int value)
6+
}
7+
8+
/* skip if the name already exists in the dictionary */
9+
+#if !defined(GRAALPY_VERSION_NUM) || GRAALPY_VERSION_NUM >= 0x190000a0
10+
if (PyMapping_HasKeyString (dict, upper)) {
11+
g_free (upper);
12+
return;
13+
}
14+
15+
v = PyLong_FromLong (value);
16+
PyMapping_SetItemString (dict, upper, v);
17+
+#else
18+
+ PyObject *key = PyUnicode_FromString(upper);
19+
+ PyObject *keyValue = PyObject_GetItem (dict, key);
20+
+ if (keyValue != NULL) {
21+
+ Py_DECREF(keyValue);
22+
+ Py_DECREF(key);
23+
+ g_free (upper);
24+
+ return;
25+
+ }
26+
+ PyErr_Clear();
27+
+ v = PyLong_FromLong (value);
28+
+ PyObject_SetItem (dict, key, v);
29+
+ Py_DECREF(key);
30+
+#endif
31+
Py_DECREF (v);
32+
g_free (upper);
33+
}
34+
@@ -179,13 +184,21 @@ pyg_enum_add_full (PyObject *module,
35+
if (module) {
36+
PyObject *module_name = PyModule_GetNameObject (module);
37+
38+
+#if !defined(GRAALPY_VERSION_NUM) || GRAALPY_VERSION_NUM >= 0x190000a0
39+
PyMapping_SetItemString (values, "__module__", module_name);
40+
+#else
41+
+ PyDict_SetItemString (values, "__module__", module_name);
42+
+#endif
43+
Py_DECREF (module_name);
44+
}
45+
if (gtype != G_TYPE_NONE) {
46+
PyObject *o = pyg_type_wrapper_new (gtype);
47+
48+
+#if !defined(GRAALPY_VERSION_NUM) || GRAALPY_VERSION_NUM >= 0x190000a0
49+
PyMapping_SetItemString(values, "__gtype__", o);
50+
+#else
51+
+ PyDict_SetItemString(values, "__gtype__", o);
52+
+#endif
53+
Py_DECREF (o);
54+
}
55+
56+
diff --git a/gi/pygflags.c b/gi/pygflags.c
57+
index f0047a13..7717f175 100644
58+
--- a/gi/pygflags.c
59+
+++ b/gi/pygflags.c
60+
@@ -89,6 +89,7 @@ add_value (PyObject *dict, const char *value_nick, unsigned int value)
61+
}
62+
63+
/* skip if the name already exists in the dictionary */
64+
+#if !defined(GRAALPY_VERSION_NUM) || GRAALPY_VERSION_NUM >= 0x190000a0
65+
if (PyMapping_HasKeyString (dict, upper)) {
66+
g_free (upper);
67+
return;
68+
@@ -96,6 +97,20 @@ add_value (PyObject *dict, const char *value_nick, unsigned int value)
69+
70+
v = PyLong_FromUnsignedLong (value);
71+
PyMapping_SetItemString (dict, upper, v);
72+
+#else
73+
+ PyObject *key = PyUnicode_FromString(upper);
74+
+ PyObject *keyValue = PyObject_GetItem (dict, key);
75+
+ if (keyValue != NULL) {
76+
+ Py_DECREF(keyValue);
77+
+ Py_DECREF(key);
78+
+ g_free (upper);
79+
+ return;
80+
+ }
81+
+ PyErr_Clear();
82+
+ v = PyLong_FromUnsignedLong (value);
83+
+ PyObject_SetItem (dict, key, v);
84+
+ Py_DECREF(key);
85+
+#endif
86+
Py_DECREF (v);
87+
g_free (upper);
88+
}
89+
@@ -178,13 +183,21 @@ pyg_flags_add_full (PyObject *module,
90+
if (module) {
91+
PyObject *module_name = PyModule_GetNameObject (module);
92+
93+
+#if !defined(GRAALPY_VERSION_NUM) || GRAALPY_VERSION_NUM >= 0x190000a0
94+
PyMapping_SetItemString (values, "__module__", module_name);
95+
+#else
96+
+ PyDict_SetItemString (values, "__module__", module_name);
97+
+#endif
98+
Py_DECREF (module_name);
99+
}
100+
if (gtype != G_TYPE_NONE) {
101+
PyObject *o = pyg_type_wrapper_new (gtype);
102+
103+
+#if !defined(GRAALPY_VERSION_NUM) || GRAALPY_VERSION_NUM >= 0x190000a0
104+
PyMapping_SetItemString(values, "__gtype__", o);
105+
+#else
106+
+ PyDict_SetItemString(values, "__gtype__", o);
107+
+#endif
108+
Py_DECREF (o);
109+
}
110+
111+
diff --git a/gi/gimodule.c b/gi/gimodule.c
112+
index ace6fa5b..57bfa63a 100644
113+
--- a/gi/gimodule.c
114+
+++ b/gi/gimodule.c
115+
@@ -2120,7 +2120,7 @@ _wrap_pyig_pyos_getsig (PyObject *self, PyObject *args)
116+
if (!PyArg_ParseTuple (args, "i:pyos_getsig", &sig_num))
117+
return NULL;
118+
119+
- return PyLong_FromVoidPtr ((void *)(PyOS_getsig (sig_num)));
120+
+ return PyLong_FromVoidPtr ((void *)(SIG_IGN));
121+
}
122+
123+
static PyObject *
124+
diff --git a/gi/gimodule.c b/gi/gimodule.c
125+
index 57bfa63a..8f32734d 100644
126+
--- a/gi/gimodule.c
127+
+++ b/gi/gimodule.c
128+
@@ -2402,7 +2402,7 @@ _gi_exec (PyObject *module)
129+
PyObject *module_dict = PyModule_GetDict (module);
130+
int ret;
131+
132+
-#if PY_VERSION_HEX < 0x03090000 || defined(PYPY_VERSION)
133+
+#if PY_VERSION_HEX < 0x03090000 || defined(PYPY_VERSION) || defined(GRAALPY_VERSION)
134+
/* Deprecated since 3.9 */
135+
/* Except in PyPy it's still not a no-op: https://foss.heptapod.net/pypy/pypy/-/issues/3691 */
136+
137+
diff --git a/gi/pygi-async.c b/gi/pygi-async.c
138+
index 248e1fb6..00d2d377 100644
139+
--- a/gi/pygi-async.c
140+
+++ b/gi/pygi-async.c
141+
@@ -32,7 +32,7 @@
142+
143+
static PyObject *asyncio_InvalidStateError;
144+
static PyObject *asyncio_get_running_loop;
145+
-#if defined(PYPY_VERSION)
146+
+#if defined(PYPY_VERSION) || defined(GRAALPY_VERSION)
147+
static PyObject *contextvars_copy_context;
148+
#endif
149+
static PyObject *cancellable_info;
150+
@@ -155,7 +155,7 @@ async_add_done_callback (PyGIAsync *self, PyObject *args, PyObject *kwargs)
151+
152+
Py_INCREF(callback.func);
153+
if (callback.context == NULL)
154+
-#ifndef PYPY_VERSION
155+
+#if !defined(PYPY_VERSION) && !defined(GRAALPY_VERSION)
156+
callback.context = PyContext_CopyCurrent ();
157+
#else
158+
callback.context = PyObject_CallObject (contextvars_copy_context, NULL);
159+
@@ -411,7 +411,7 @@ finally:
160+
static void
161+
async_dealloc(PyGIAsync *self)
162+
{
163+
-#ifndef PYPY_VERSION
164+
+#if !defined(PYPY_VERSION) && !defined(GRAALPY_VERSION)
165+
/* The finalizer might resurrect the object */
166+
if (PyObject_CallFinalizerFromDealloc((PyObject *)self) < 0)
167+
return;
168+
@@ -587,11 +587,11 @@ static struct PyMemberDef async_members[] = {
169+
*/
170+
int pygi_async_register_types(PyObject *module) {
171+
PyObject *asyncio = NULL;
172+
-#ifdef PYPY_VERSION
173+
+#if defined(PYPY_VERSION) || defined(GRAALPY_VERSION)
174+
PyObject *contextvars = NULL;
175+
#endif
176+
177+
-#ifndef PYPY_VERSION
178+
+#if !defined(PYPY_VERSION) && !defined(GRAALPY_VERSION)
179+
PyGIAsync_Type.tp_finalize = (destructor)async_finalize;
180+
#else
181+
PyGIAsync_Type.tp_del = (destructor)async_finalize;
182+
@@ -629,7 +629,7 @@ int pygi_async_register_types(PyObject *module) {
183+
if (asyncio_get_running_loop == NULL)
184+
goto fail;
185+
186+
-#if defined(PYPY_VERSION)
187+
+#if defined(PYPY_VERSION) || defined(GRAALPY_VERSION)
188+
contextvars = PyImport_ImportModule("contextvars");
189+
if (contextvars == NULL) {
190+
goto fail;
191+
diff --git a/gi/pygi-resulttuple.c b/gi/pygi-resulttuple.c
192+
index c1281d20..4a7a9beb 100644
193+
--- a/gi/pygi-resulttuple.c
194+
+++ b/gi/pygi-resulttuple.c
195+
@@ -28,7 +28,7 @@ static char tuple_indices_key[] = "__tuple_indices";
196+
197+
#define PYGI_USE_FREELIST
198+
199+
-#ifdef PYPY_VERSION
200+
+#if defined(PYPY_VERSION) || defined(GRAALPY_VERSION)
201+
#undef PYGI_USE_FREELIST
202+
#endif
203+
204+
diff --git a/gi/pygobject-object.c b/gi/pygobject-object.c
205+
index b7ade53b..edf98caa 100644
206+
--- a/gi/pygobject-object.c
207+
+++ b/gi/pygobject-object.c
208+
@@ -54,7 +54,7 @@ GQuark pygobject_has_updated_constructor_key;
209+
GQuark pygobject_instance_data_key;
210+
211+
/* PyPy doesn't support tp_dictoffset, so we have to work around it */
212+
-#ifndef PYPY_VERSION
213+
+#if !defined(PYPY_VERSION) && !defined(GRAALPY_VERSION)
214+
#define PYGI_OBJECT_USE_CUSTOM_DICT
215+
#endif
216+
217+
diff --git a/gi/pygi-resulttuple.c b/gi/pygi-resulttuple.c
218+
index 4a7a9beb..55226da2 100644
219+
--- a/gi/pygi-resulttuple.c
220+
+++ b/gi/pygi-resulttuple.c
221+
@@ -257,6 +257,11 @@ pygi_resulttuple_new_type(PyObject *tuple_names) {
222+
/* disallow subclassing as that would break the free list caching
223+
* since we assume that all subclasses use PyTupleObject */
224+
new_type->tp_flags &= ~Py_TPFLAGS_BASETYPE;
225+
+#ifdef GRAALPY_VERSION
226+
+ /* GraalPy has a custom tp_alloc for tuples, but the managed
227+
+ * type we have created here has PyType_GenericAlloc */
228+
+ new_type->tp_alloc = (&PyTuple_Type)->tp_alloc;
229+
+#endif
230+
}
231+
232+
return new_type;
233+
diff --git a/gi/pygi-closure.c b/gi/pygi-closure.c
234+
index 37f570c9..383c8524 100644
235+
--- a/gi/pygi-closure.c
236+
+++ b/gi/pygi-closure.c
237+
@@ -375,8 +375,21 @@ _pygi_closure_convert_arguments (PyGIInvokeState *state,
238+
}
239+
240+
user_data_len = PyTuple_Size (py_user_data);
241+
+#if !defined(GRAALPY_VERSION_NUM) || GRAALPY_VERSION_NUM >= 0x190000a0
242+
_PyTuple_Resize (&state->py_in_args,
243+
state->n_py_in_args + user_data_len - 1);
244+
+#else
245+
+ {
246+
+ Py_ssize_t newSize = state->n_py_in_args + user_data_len - 1;
247+
+ Py_ssize_t oldSize = Py_SIZE(state->py_in_args);
248+
+ PyObject *newTuple = PyTuple_New(newSize);
249+
+ for (int idx = 0; idx < newSize && idx < oldSize; ++idx) {
250+
+ PyTuple_SetItem(newTuple, idx, PySequence_GetItem(state->py_in_args, idx));
251+
+ }
252+
+ Py_DECREF(state->py_in_args);
253+
+ state->py_in_args = newTuple;
254+
+ }
255+
+#endif
256+
257+
for (j = 0; j < user_data_len; j++, n_in_args++) {
258+
value = PyTuple_GetItem (py_user_data, j);
259+
@@ -413,8 +426,20 @@ _pygi_closure_convert_arguments (PyGIInvokeState *state,
260+
}
261+
}
262+
263+
+#if !defined(GRAALPY_VERSION_NUM) || GRAALPY_VERSION_NUM >= 0x190000a0
264+
if (_PyTuple_Resize (&state->py_in_args, n_in_args) == -1)
265+
return FALSE;
266+
+#else
267+
+ {
268+
+ PyObject *newTuple = PyTuple_New(n_in_args);
269+
+ Py_ssize_t oldSize = Py_SIZE(state->py_in_args);
270+
+ for (int idx = 0; idx < n_in_args && idx < oldSize; ++idx) {
271+
+ PyTuple_SetItem(newTuple, idx, PySequence_GetItem(state->py_in_args, idx));
272+
+ }
273+
+ Py_DECREF(state->py_in_args);
274+
+ state->py_in_args = newTuple;
275+
+ }
276+
+#endif
277+
278+
return TRUE;
279+
}
280+
--
281+
2.43.0
282+

0 commit comments

Comments
 (0)