summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
Diffstat (limited to 'Objects')
-rw-r--r--Objects/object.c29
-rw-r--r--Objects/typeobject.c21
2 files changed, 14 insertions, 36 deletions
diff --git a/Objects/object.c b/Objects/object.c
index ed5f360..0237234 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -127,13 +127,16 @@ _PyObject_New(PyTypeObject *tp)
}
PyVarObject *
-_PyObject_NewVar(PyTypeObject *tp, int size)
+_PyObject_NewVar(PyTypeObject *tp, int nitems)
{
PyVarObject *op;
- op = (PyVarObject *) PyObject_MALLOC(_PyObject_VAR_SIZE(tp, size));
+ size_t size;
+
+ _PyObject_VAR_SIZE(size, tp, nitems);
+ op = (PyVarObject *) PyObject_MALLOC(size);
if (op == NULL)
return (PyVarObject *)PyErr_NoMemory();
- return PyObject_INIT_VAR(op, tp, size);
+ return PyObject_INIT_VAR(op, tp, nitems);
}
void
@@ -1146,8 +1149,6 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value)
PyObject **
_PyObject_GetDictPtr(PyObject *obj)
{
-#define PTRSIZE (sizeof(PyObject *))
-
long dictoffset;
PyTypeObject *tp = obj->ob_type;
@@ -1157,19 +1158,11 @@ _PyObject_GetDictPtr(PyObject *obj)
if (dictoffset == 0)
return NULL;
if (dictoffset < 0) {
- /* dictoffset is positive by the time we're ready to round
- it, and compilers can generate faster rounding code if
- they know that. */
- unsigned long udo; /* unsigned dictoffset */
- const long nitems = ((PyVarObject *)obj)->ob_size;
- const long size = _PyObject_VAR_SIZE(tp, nitems);
-
- dictoffset += size;
- assert(dictoffset > 0); /* Sanity check */
- /* Round up to multiple of PTRSIZE. */
- udo = (unsigned long)dictoffset;
- udo = ((udo + PTRSIZE-1) / PTRSIZE) * PTRSIZE;
- dictoffset = (long)udo;
+ size_t size;
+ _PyObject_VAR_SIZE(size, tp, ((PyVarObject *)obj)->ob_size);
+ dictoffset += (long)size;
+ assert(dictoffset > 0);
+ assert(dictoffset % SIZEOF_VOID_P == 0);
}
return (PyObject **) ((char *)obj + dictoffset);
}
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 59ec588..0342e71 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -190,28 +190,13 @@ type_call(PyTypeObject *type, PyObject *args, PyObject *kwds)
PyObject *
PyType_GenericAlloc(PyTypeObject *type, int nitems)
{
-#define PTRSIZE (sizeof(PyObject *))
-
- size_t size = (size_t)_PyObject_VAR_SIZE(type, nitems);
- size_t padding = 0;
PyObject *obj;
+ size_t size;
- /* Round up size, if necessary, so that the __dict__ pointer
- following the variable part is properly aligned for the platform.
- This is needed only for types with a vrbl number of items
- before the __dict__ pointer == types that record the dict offset
- as a negative offset from the end of the object. If tp_dictoffset
- is 0, there is no __dict__; if positive, tp_dict was declared in a C
- struct so the compiler already took care of aligning it. */
- if (type->tp_dictoffset < 0) {
- padding = PTRSIZE - size % PTRSIZE;
- if (padding == PTRSIZE)
- padding = 0;
- size += padding;
- }
+ _PyObject_VAR_SIZE(size, type, nitems);
if (PyType_IS_GC(type))
- obj = _PyObject_GC_Malloc(type, nitems, padding);
+ obj = _PyObject_GC_Malloc(type, nitems);
else
obj = PyObject_MALLOC(size);