diff Modules/gcmodule.c @ 20293:b285decf0421 legacy-trunk

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>.
author Tim Peters <tim.peters@gmail.com>
date Sat, 06 Oct 2001 19:04:01 +0000
parents 178ba33f67e4
children 426b379a138b
line wrap: on
line diff
--- a/Modules/gcmodule.c	Sat Oct 06 17:45:17 2001 +0000
+++ b/Modules/gcmodule.c	Sat Oct 06 19:04:01 2001 +0000
@@ -798,13 +798,14 @@
 }
 
 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 @@
 	}
 	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 *
 _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);
 }