Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c297b5b

Browse files
committed
FIX: guard second usage of PyWeakref_GetObject
This function was deprecated in 3.13 and will be removed in 3.15. There are two usages in pycurl, one in easy.c was already correctly guarded, the other in share.c was not.
1 parent 2aff67c commit c297b5b

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/share.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,19 @@ share_cleanup_and_count_live_easies(CurlShareObject *self)
262262

263263
if (it && to_remove) {
264264
PyObject *wr;
265+
PyObject *obj = NULL;
265266

266267
while ((wr = PyIter_Next(it))) {
267-
PyObject *obj = PyWeakref_GetObject(wr);
268+
#if PY_VERSION_HEX >= 0x030D0000 /* Python 3.13+ */
269+
int rc = PyWeakref_GetRef(wr, &obj);
270+
if (rc < 0) {
271+
// NOT CORRECTLY HANDLING THIS
272+
}
273+
274+
#else
275+
obj = PyWeakref_GetObject(wr);
276+
Py_INCREF(obj);
277+
#endif
268278
if (obj != Py_None) {
269279
CurlObject *easy = (CurlObject *)obj;
270280

@@ -286,6 +296,7 @@ share_cleanup_and_count_live_easies(CurlShareObject *self)
286296

287297
Py_DECREF(wr);
288298
}
299+
Py_DECREF(obj);
289300

290301
Py_ssize_t i, n = PyList_GET_SIZE(to_remove);
291302
for (i = 0; i < n; i++) {

0 commit comments

Comments
 (0)