diff options
author | Tim Peters <tim.peters@gmail.com> | 2001-10-06 19:04:01 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2001-10-06 19:04:01 (GMT) |
commit | 406fe3b1c029e2526f4aeab070cc93177512f164 (patch) | |
tree | ff9400cc654378fbf1c57fadc34a32c5d05533c9 /Modules/gcmodule.c | |
parent | 7254e5a3edd85563d333ba5aa2978d7cd7daa96a (diff) | |
download | cpython-406fe3b1c029e2526f4aeab070cc93177512f164.zip cpython-406fe3b1c029e2526f4aeab070cc93177512f164.tar.gz cpython-406fe3b1c029e2526f4aeab070cc93177512f164.tar.bz2 |
Repaired the debug Windows deaths in test_descr, by allocating enough
pad memory to properly align the __dict__ pointer in all cases.
gcmodule.c/objimpl.h, _PyObject_GC_Malloc:
+ Added a "padding" argument so that this flavor of malloc can allocate
enough bytes for alignment padding (it can't know this is needed, but
its callers do).
typeobject.c, PyType_GenericAlloc:
+ Allocated enough bytes to align the __dict__ pointer.
+ Sped and simplified the round-up-to-PTRSIZE logic.
+ Added blank lines so I could parse the if/else blocks <0.7 wink>.
Diffstat (limited to 'Modules/gcmodule.c')
-rw-r--r-- | Modules/gcmodule.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c index 43a7bf1..349ba6a 100644 --- a/Modules/gcmodule.c +++ b/Modules/gcmodule.c @@ -798,13 +798,14 @@ _PyObject_GC_UnTrack(PyObject *op) } PyObject * -_PyObject_GC_Malloc(PyTypeObject *tp, int size) +_PyObject_GC_Malloc(PyTypeObject *tp, int nitems, size_t padding) { PyObject *op; #ifdef WITH_CYCLE_GC - const size_t nbytes = sizeof(PyGC_Head) + - (size_t)_PyObject_VAR_SIZE(tp, size); - PyGC_Head *g = PyObject_MALLOC(nbytes); + const size_t basic = (size_t)_PyObject_VAR_SIZE(tp, nitems); + const size_t nbytes = sizeof(PyGC_Head) + basic + padding; + + PyGC_Head *g = PyObject_MALLOC(nbytes); if (g == NULL) return (PyObject *)PyErr_NoMemory(); g->gc_next = NULL; @@ -820,7 +821,7 @@ _PyObject_GC_Malloc(PyTypeObject *tp, int size) } op = FROM_GC(g); #else - op = PyObject_MALLOC(_PyObject_VAR_SIZE(tp, size)); + op = PyObject_MALLOC(_PyObject_VAR_SIZE(tp, nitems) + padding); if (op == NULL) return (PyObject *)PyErr_NoMemory(); @@ -831,14 +832,14 @@ _PyObject_GC_Malloc(PyTypeObject *tp, int size) PyObject * _PyObject_GC_New(PyTypeObject *tp) { - PyObject *op = _PyObject_GC_Malloc(tp, 0); + PyObject *op = _PyObject_GC_Malloc(tp, 0, 0); return PyObject_INIT(op, tp); } PyVarObject * _PyObject_GC_NewVar(PyTypeObject *tp, int size) { - PyVarObject *op = (PyVarObject *) _PyObject_GC_Malloc(tp, size); + PyVarObject *op = (PyVarObject *) _PyObject_GC_Malloc(tp, size, 0); return PyObject_INIT_VAR(op, tp, size); } |