Skip to content

Commit ee85b47

Browse files
committed
Fix compilation errors in py_loader_port.c
- Replace Py_XDecRef with Py_DecRef using explicit NULL checks (Py_XDecRef is not available on all platforms) - Implement PyExc_MemoryErrorPtr in py_loader_symbol_fallback.c following the existing pattern for other exception types
1 parent bd96b78 commit ee85b47

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

source/loaders/py_loader/source/py_loader_port.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,10 @@ static void *py_loader_port_await_resolve(void *result, void *data)
602602
PyObject *args = PyTuple_Pack(3, asyncio_loop, ctx->future, py_result);
603603
PyObject *call_result = PyObject_Call(future_resolve_func, args, NULL);
604604

605-
Py_XDecRef(call_result);
605+
if (call_result != NULL)
606+
{
607+
Py_DecRef(call_result);
608+
}
606609
Py_DecRef(args);
607610
Py_DecRef(future_resolve_func);
608611
}
@@ -660,7 +663,10 @@ static void *py_loader_port_await_reject(void *result, void *data)
660663
PyObject *args = PyTuple_Pack(3, asyncio_loop, ctx->future, py_exception);
661664
PyObject *call_result = PyObject_Call(future_reject_func, args, NULL);
662665

663-
Py_XDecRef(call_result);
666+
if (call_result != NULL)
667+
{
668+
Py_DecRef(call_result);
669+
}
664670
Py_DecRef(args);
665671
Py_DecRef(future_reject_func);
666672
}
@@ -761,7 +767,10 @@ static PyObject *py_loader_port_await(PyObject *self, PyObject *var_args)
761767
if (future_create_func == NULL || !PyCallable_Check(future_create_func))
762768
{
763769
PyErr_SetString(PyExc_RuntimeErrorPtr(), "Failed to get future_create function");
764-
Py_XDecRef(future_create_func);
770+
if (future_create_func != NULL)
771+
{
772+
Py_DecRef(future_create_func);
773+
}
765774
goto cleanup_args;
766775
}
767776

source/loaders/py_loader/source/py_loader_symbol_fallback.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ static PyObject **PyExc_FileNotFoundErrorStructPtr = NULL;
4141
static PyObject **PyExc_TypeErrorStructPtr = NULL;
4242
static PyObject **PyExc_ValueErrorStructPtr = NULL;
4343
static PyObject **PyExc_RuntimeErrorStructPtr = NULL;
44+
static PyObject **PyExc_MemoryErrorStructPtr = NULL;
4445
static PyObject *Py_FalseStructPtr = NULL;
4546
static PyObject *Py_TrueStructPtr = NULL;
4647
#endif
@@ -183,6 +184,14 @@ int py_loader_symbol_fallback_initialize(dynlink py_library)
183184

184185
dynlink_symbol_uncast_type(address, PyObject **, PyExc_RuntimeErrorStructPtr);
185186

187+
/* PyExc_MemoryError */
188+
if (dynlink_symbol(py_library, "PyExc_MemoryError", &address) != 0)
189+
{
190+
return 1;
191+
}
192+
193+
dynlink_symbol_uncast_type(address, PyObject **, PyExc_MemoryErrorStructPtr);
194+
186195
/* Py_False */
187196
if (dynlink_symbol(py_library, "_Py_FalseStruct", &address) != 0)
188197
{
@@ -337,6 +346,15 @@ PyObject *PyExc_RuntimeErrorPtr(void)
337346
#endif
338347
}
339348

349+
PyObject *PyExc_MemoryErrorPtr(void)
350+
{
351+
#if defined(_WIN32) && defined(_MSC_VER)
352+
return *PyExc_MemoryErrorStructPtr;
353+
#else
354+
return PyExc_MemoryError;
355+
#endif
356+
}
357+
340358
PyObject *Py_ReturnNone(void)
341359
{
342360
#if defined(_WIN32) && defined(_MSC_VER)

0 commit comments

Comments
 (0)