mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
Guido suggests, and I agree, to insist that SIZEOF_VOID_P be a power of 2.
This simplifies the rounding in _PyObject_VAR_SIZE, allows to restore the pre-rounding calling sequence, and allows some nice little simplifications in its callers. I'm still making it return a size_t, though.
This commit is contained in:
parent
0a1fc4e389
commit
f2a67daca2
4 changed files with 31 additions and 47 deletions
|
|
@ -801,14 +801,10 @@ PyObject *
|
|||
_PyObject_GC_Malloc(PyTypeObject *tp, int nitems)
|
||||
{
|
||||
PyObject *op;
|
||||
size_t basicsize;
|
||||
const size_t basicsize = _PyObject_VAR_SIZE(tp, nitems);
|
||||
#ifdef WITH_CYCLE_GC
|
||||
size_t nbytes;
|
||||
PyGC_Head *g;
|
||||
|
||||
_PyObject_VAR_SIZE(basicsize, tp, nitems);
|
||||
nbytes = sizeof(PyGC_Head) + basicsize;
|
||||
g = PyObject_MALLOC(nbytes);
|
||||
const size_t nbytes = sizeof(PyGC_Head) + basicsize;
|
||||
PyGC_Head *g = PyObject_MALLOC(nbytes);
|
||||
if (g == NULL)
|
||||
return (PyObject *)PyErr_NoMemory();
|
||||
g->gc_next = NULL;
|
||||
|
|
@ -824,7 +820,6 @@ _PyObject_GC_Malloc(PyTypeObject *tp, int nitems)
|
|||
}
|
||||
op = FROM_GC(g);
|
||||
#else
|
||||
_PyObject_VAR_SIZE(basicsize, tp, nitems);
|
||||
op = PyObject_MALLOC(basicsize);
|
||||
if (op == NULL)
|
||||
return (PyObject *)PyErr_NoMemory();
|
||||
|
|
@ -850,17 +845,14 @@ _PyObject_GC_NewVar(PyTypeObject *tp, int nitems)
|
|||
PyVarObject *
|
||||
_PyObject_GC_Resize(PyVarObject *op, int nitems)
|
||||
{
|
||||
size_t basicsize;
|
||||
const size_t basicsize = _PyObject_VAR_SIZE(op->ob_type, nitems);
|
||||
#ifdef WITH_CYCLE_GC
|
||||
PyGC_Head *g = AS_GC(op);
|
||||
|
||||
_PyObject_VAR_SIZE(basicsize, op->ob_type, nitems);
|
||||
g = PyObject_REALLOC(g, sizeof(PyGC_Head) + basicsize);
|
||||
if (g == NULL)
|
||||
return (PyVarObject *)PyErr_NoMemory();
|
||||
op = (PyVarObject *) FROM_GC(g);
|
||||
#else
|
||||
_PyObject_VAR_SIZE(basicsize, op->ob_type, nitems);
|
||||
op = PyObject_REALLOC(op, basicsize);
|
||||
if (op == NULL)
|
||||
return (PyVarObject *)PyErr_NoMemory();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue