[Python-checkins] CVS: python/dist/src/Objects typeobject.c,2.16.8.45,2.16.8.46

Guido van Rossum gvanrossum@users.sourceforge.net
Mon, 18 Jun 2001 15:21:44 -0700


Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv8469

Modified Files:
      Tag: descr-branch
	typeobject.c 
Log Message:
Experimental policy change:

- the call to tp_init is now made in type_call, not in type_new

- tp_new is only called with sequential arguments

- PyType_GenericNew is now super-simple: only calls tp_alloc

This makes it easier for subclassable types to do the right thing --
no need to call tp_init in their tp_new implementation.

We'll see if this works out alright.


Index: typeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/typeobject.c,v
retrieving revision 2.16.8.45
retrieving revision 2.16.8.46
diff -C2 -r2.16.8.45 -r2.16.8.46
*** typeobject.c	2001/06/18 20:17:36	2.16.8.45
--- typeobject.c	2001/06/18 22:21:42	2.16.8.46
***************
*** 67,70 ****
--- 67,72 ----
  type_call(PyTypeObject *type, PyObject *args, PyObject *kwds)
  {
+ 	PyObject *obj;
+ 
  	if (type->tp_new == NULL) {
  		PyErr_Format(PyExc_TypeError,
***************
*** 74,78 ****
  	}
  
! 	return type->tp_new(type, args, kwds);
  }
  
--- 76,87 ----
  	}
  
! 	obj = type->tp_new(type, args, NULL);
! 	if (obj != NULL && type->tp_init != NULL) {
! 		if (type->tp_init(obj, args, kwds) < 0) {
! 			Py_DECREF(obj);
! 			obj = NULL;
! 		}
! 	}
! 	return obj;
  }
  
***************
*** 108,121 ****
  PyType_GenericNew(PyTypeObject *type, PyObject *args, PyObject *kwds)
  {
! 	PyObject *self;
! 
! 	self = type->tp_alloc(type, 0);
! 	if (self == NULL)
! 		return NULL;
! 	if (type->tp_init != NULL && type->tp_init(self, args, kwds) < 0) {
! 		Py_DECREF(self);
! 		return NULL;
! 	}
! 	return self;
  }
  
--- 117,121 ----
  PyType_GenericNew(PyTypeObject *type, PyObject *args, PyObject *kwds)
  {
! 	return type->tp_alloc(type, 0);
  }