Skip to content

Commit a113d90

Browse files
authored
Fix asyncpg with Py_DEBUG mode (#719)
If Py_DEBUG enabled, then newly allocated memory is filled with the byte 0xCD (CLEANBYTE) https://docs.python.org/3/c-api/memory.html#c.PyMem_SetupDebugHooks This breaks checks for `pointer == NULL` and results in crash. From documentation PyObject_GC_Track https://docs.python.org/3/c-api/gcsupport.html#c.PyObject_GC_Track: > This should be called once all the fields followed by the tp_traverse > handler become valid, usually near the end of the constructor.
1 parent fa2c1e5 commit a113d90

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

asyncpg/protocol/record/recordobj.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ ApgRecord_New(PyTypeObject *type, PyObject *desc, Py_ssize_t size)
3131
{
3232
ApgRecordObject *o;
3333
Py_ssize_t i;
34+
int need_gc_track = 0;
3435

3536
if (size < 0 || desc == NULL || !ApgRecordDesc_CheckExact(desc)) {
3637
PyErr_BadInternalCall();
@@ -54,7 +55,7 @@ ApgRecord_New(PyTypeObject *type, PyObject *desc, Py_ssize_t size)
5455
}
5556
}
5657

57-
PyObject_GC_Track(o);
58+
need_gc_track = 1;
5859
} else {
5960
assert(PyType_IsSubtype(type, &ApgRecord_Type));
6061

@@ -78,6 +79,9 @@ ApgRecord_New(PyTypeObject *type, PyObject *desc, Py_ssize_t size)
7879
Py_INCREF(desc);
7980
o->desc = (ApgRecordDescObject*)desc;
8081
o->self_hash = -1;
82+
if (need_gc_track) {
83+
PyObject_GC_Track(o);
84+
}
8185
return (PyObject *) o;
8286
}
8387

0 commit comments

Comments
 (0)