summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-10-06 21:27:34 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-10-06 21:27:34 (GMT)
commit6d483d3477c37d7dfe3113ef6fd02ba02c78fde6 (patch)
treea411a61b3fa22b4ddc912b5c4b4dc3196a377355 /Modules
parent406fe3b1c029e2526f4aeab070cc93177512f164 (diff)
downloadcpython-6d483d3477c37d7dfe3113ef6fd02ba02c78fde6.zip
cpython-6d483d3477c37d7dfe3113ef6fd02ba02c78fde6.tar.gz
cpython-6d483d3477c37d7dfe3113ef6fd02ba02c78fde6.tar.bz2
_PyObject_VAR_SIZE: always round up to a multiple-of-pointer-size value.
As Guido suggested, this makes the new subclassing code substantially simpler. But the mechanics of doing it w/ C macro semantics are a mess, and _PyObject_VAR_SIZE has a new calling sequence now. Question: The PyObject_NEW_VAR macro appears to be part of the public API. Regardless of what it expands to, the notion that it has to round up the memory it allocates is new, and extensions containing the old PyObject_NEW_VAR macro expansion (which was embedded in the PyObject_NEW_VAR expansion) won't do this rounding. But the rounding isn't actually *needed* except for new-style instances with dict pointers after a variable-length blob of embedded data. So my guess is that we do not need to bump the API version for this (as the rounding isn't needed for anything an extension can do unless it's recompiled anyway). What's your guess?
Diffstat (limited to 'Modules')
-rw-r--r--Modules/gcmodule.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index 349ba6a..63a2370 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -798,14 +798,17 @@ _PyObject_GC_UnTrack(PyObject *op)
}
PyObject *
-_PyObject_GC_Malloc(PyTypeObject *tp, int nitems, size_t padding)
+_PyObject_GC_Malloc(PyTypeObject *tp, int nitems)
{
PyObject *op;
+ size_t basicsize;
#ifdef WITH_CYCLE_GC
- const size_t basic = (size_t)_PyObject_VAR_SIZE(tp, nitems);
- const size_t nbytes = sizeof(PyGC_Head) + basic + padding;
+ size_t nbytes;
+ PyGC_Head *g;
- PyGC_Head *g = PyObject_MALLOC(nbytes);
+ _PyObject_VAR_SIZE(basicsize, tp, nitems);
+ nbytes = sizeof(PyGC_Head) + basicsize;
+ g = PyObject_MALLOC(nbytes);
if (g == NULL)
return (PyObject *)PyErr_NoMemory();
g->gc_next = NULL;
@@ -821,7 +824,8 @@ _PyObject_GC_Malloc(PyTypeObject *tp, int nitems, size_t padding)
}
op = FROM_GC(g);
#else
- op = PyObject_MALLOC(_PyObject_VAR_SIZE(tp, nitems) + padding);
+ _PyObject_VAR_SIZE(basicsize, tp, nitems);
+ op = PyObject_MALLOC(basicsize);
if (op == NULL)
return (PyObject *)PyErr_NoMemory();
@@ -832,33 +836,36 @@ _PyObject_GC_Malloc(PyTypeObject *tp, int nitems, size_t padding)
PyObject *
_PyObject_GC_New(PyTypeObject *tp)
{
- PyObject *op = _PyObject_GC_Malloc(tp, 0, 0);
+ PyObject *op = _PyObject_GC_Malloc(tp, 0);
return PyObject_INIT(op, tp);
}
PyVarObject *
-_PyObject_GC_NewVar(PyTypeObject *tp, int size)
+_PyObject_GC_NewVar(PyTypeObject *tp, int nitems)
{
- PyVarObject *op = (PyVarObject *) _PyObject_GC_Malloc(tp, size, 0);
- return PyObject_INIT_VAR(op, tp, size);
+ PyVarObject *op = (PyVarObject *) _PyObject_GC_Malloc(tp, nitems);
+ return PyObject_INIT_VAR(op, tp, nitems);
}
PyVarObject *
-_PyObject_GC_Resize(PyVarObject *op, int size)
+_PyObject_GC_Resize(PyVarObject *op, int nitems)
{
+ size_t basicsize;
#ifdef WITH_CYCLE_GC
PyGC_Head *g = AS_GC(op);
- g = PyObject_REALLOC(g, _PyObject_VAR_SIZE(op->ob_type, size) +
- sizeof(PyGC_Head));
+
+ _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
- op = PyObject_REALLOC(op, _PyObject_VAR_SIZE(op->ob_type, size));
+ _PyObject_VAR_SIZE(basicsize, op->ob_type, nitems);
+ op = PyObject_REALLOC(op, basicsize);
if (op == NULL)
return (PyVarObject *)PyErr_NoMemory();
#endif
- op->ob_size = size;
+ op->ob_size = nitems;
return op;
}