File tree 2 files changed +9
-6
lines changed 2 files changed +9
-6
lines changed Original file line number Diff line number Diff line change
1
+ :c:func: `PyObject_GC_Resize ` should calculate preheader size if needed.
2
+ Patch by Dong-hee Na.
Original file line number Diff line number Diff line change @@ -2361,16 +2361,17 @@ PyVarObject *
2361
2361
_PyObject_GC_Resize (PyVarObject * op , Py_ssize_t nitems )
2362
2362
{
2363
2363
const size_t basicsize = _PyObject_VAR_SIZE (Py_TYPE (op ), nitems );
2364
+ const size_t presize = _PyType_PreHeaderSize (((PyObject * )op )-> ob_type );
2364
2365
_PyObject_ASSERT ((PyObject * )op , !_PyObject_GC_IS_TRACKED (op ));
2365
- if (basicsize > (size_t )PY_SSIZE_T_MAX - sizeof ( PyGC_Head ) ) {
2366
+ if (basicsize > (size_t )PY_SSIZE_T_MAX - presize ) {
2366
2367
return (PyVarObject * )PyErr_NoMemory ();
2367
2368
}
2368
-
2369
- PyGC_Head * g = AS_GC (op );
2370
- g = (PyGC_Head * )PyObject_Realloc (g , sizeof (PyGC_Head ) + basicsize );
2371
- if (g == NULL )
2369
+ char * mem = (char * )op - presize ;
2370
+ mem = (char * )PyObject_Realloc (mem , presize + basicsize );
2371
+ if (mem == NULL ) {
2372
2372
return (PyVarObject * )PyErr_NoMemory ();
2373
- op = (PyVarObject * ) FROM_GC (g );
2373
+ }
2374
+ op = (PyVarObject * ) (mem + presize );
2374
2375
Py_SET_SIZE (op , nitems );
2375
2376
return op ;
2376
2377
}
You can’t perform that action at this time.
0 commit comments