[Python-checkins] CVS: python/dist/src/Objects typeobject.c,2.16.8.40,2.16.8.41
Guido van Rossum
gvanrossum@users.sourceforge.net
Sat, 16 Jun 2001 07:41:42 -0700
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv11001/Objects
Modified Files:
Tag: descr-branch
typeobject.c
Log Message:
I think I've got the right solution for tp_alloc: it's a lower-level
function that really should only allocate the memory and initialize
the type and refcount. The new signature gets the number of items (in
case it's a VarObject). The smarts have to be put in tp_new().
Thies does away wih my fear that tp_alloc() and tp_new() would have to
be merged -- they are both needed.
Index: typeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/typeobject.c,v
retrieving revision 2.16.8.40
retrieving revision 2.16.8.41
diff -C2 -r2.16.8.40 -r2.16.8.41
*** typeobject.c 2001/06/14 14:13:46 2.16.8.40
--- typeobject.c 2001/06/16 14:41:40 2.16.8.41
***************
*** 78,82 ****
PyObject *
! PyType_GenericAlloc(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
int size;
--- 78,82 ----
PyObject *
! PyType_GenericAlloc(PyTypeObject *type, int nitems)
{
int size;
***************
*** 85,89 ****
/* Inline PyObject_New() so we can zero the memory */
! size = _PyObject_SIZE(type);
mem = PyObject_MALLOC(size);
if (mem == NULL)
--- 85,89 ----
/* Inline PyObject_New() so we can zero the memory */
! size = _PyObject_VAR_SIZE(type, nitems);
mem = PyObject_MALLOC(size);
if (mem == NULL)
***************
*** 96,100 ****
if (type->tp_flags & Py_TPFLAGS_HEAPTYPE)
Py_INCREF(type);
! PyObject_INIT(obj, type);
if (PyType_IS_GC(type))
PyObject_GC_Init(obj);
--- 96,103 ----
if (type->tp_flags & Py_TPFLAGS_HEAPTYPE)
Py_INCREF(type);
! if (type->tp_itemsize == 0)
! PyObject_INIT(obj, type);
! else
! (void) PyObject_INIT_VAR((PyVarObject *)obj, type, nitems);
if (PyType_IS_GC(type))
PyObject_GC_Init(obj);
***************
*** 107,111 ****
PyObject *self;
! self = type->tp_alloc(type, args, kwds);
if (self == NULL)
return NULL;
--- 110,114 ----
PyObject *self;
! self = type->tp_alloc(type, 0);
if (self == NULL)
return NULL;
***************
*** 527,541 ****
static PyObject *
! type_alloc(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
{
PyTypeObject *type;
- PyObject *name, *bases, *dict;
- static char *kwlist[] = {"name", "bases", "dict", 0};
! /* Check arguments (again?!?! yes, alas -- we need the dict!) */
! if (!PyArg_ParseTupleAndKeywords(args, kwds, "SOO:type", kwlist,
! &name, &bases, &dict))
! return NULL;
! type = (PyTypeObject *)PyType_GenericAlloc(metatype, args, kwds);
if (type != NULL)
type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE;
--- 530,538 ----
static PyObject *
! type_alloc(PyTypeObject *metatype, int nitems)
{
PyTypeObject *type;
! type = (PyTypeObject *)PyType_GenericAlloc(metatype, nitems);
if (type != NULL)
type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE;