[Python-checkins] python/dist/src/Modules datetimemodule.c,1.59,1.60

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Mon, 14 Apr 2003 15:02:00 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv28774/Modules

Modified Files:
	datetimemodule.c 
Log Message:
The date class is now properly subclassable.  (SF bug #720908)

(This is only the tip of the iceberg; the time and datetime classes
need the same treatment.)


Index: datetimemodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/datetimemodule.c,v
retrieving revision 1.59
retrieving revision 1.60
diff -C2 -d -r1.59 -r1.60
*** datetimemodule.c	8 Feb 2003 03:28:59 -0000	1.59
--- datetimemodule.c	14 Apr 2003 22:01:57 -0000	1.60
***************
*** 1292,1300 ****
  /* Create a date instance with no range checking. */
  static PyObject *
! new_date(int year, int month, int day)
  {
  	PyDateTime_Date *self;
  
! 	self = PyObject_New(PyDateTime_Date, &PyDateTime_DateType);
  	if (self != NULL)
  		set_date_fields(self, year, month, day);
--- 1292,1300 ----
  /* Create a date instance with no range checking. */
  static PyObject *
! new_date_ex(int year, int month, int day, PyTypeObject *type)
  {
  	PyDateTime_Date *self;
  
! 	self = (PyDateTime_Date *) (type->tp_alloc(type, 0));
  	if (self != NULL)
  		set_date_fields(self, year, month, day);
***************
*** 1302,1305 ****
--- 1302,1308 ----
  }
  
+ #define new_date(year, month, day) \
+ 	(new_date_ex(year, month, day, &PyDateTime_DateType))
+ 
  /* Create a datetime instance with no range checking. */
  static PyObject *
***************
*** 2169,2173 ****
  	    	PyDateTime_Date *me;
  
! 		me = PyObject_New(PyDateTime_Date, &PyDateTime_DateType);
  		if (me != NULL) {
  			char *pdata = PyString_AS_STRING(state);
--- 2172,2176 ----
  	    	PyDateTime_Date *me;
  
! 		me = PyObject_New(PyDateTime_Date, type);
  		if (me != NULL) {
  			char *pdata = PyString_AS_STRING(state);
***************
*** 2182,2186 ****
  		if (check_date_args(year, month, day) < 0)
  			return NULL;
! 		self = new_date(year, month, day);
  	}
  	return self;
--- 2185,2189 ----
  		if (check_date_args(year, month, day) < 0)
  			return NULL;
! 		self = new_date_ex(year, month, day, type);
  	}
  	return self;
***************
*** 2633,2637 ****
  	sizeof(PyDateTime_Date),			/* tp_basicsize */
  	0,						/* tp_itemsize */
! 	(destructor)PyObject_Del,			/* tp_dealloc */
  	0,						/* tp_print */
  	0,						/* tp_getattr */
--- 2636,2640 ----
  	sizeof(PyDateTime_Date),			/* tp_basicsize */
  	0,						/* tp_itemsize */
! 	0,						/* tp_dealloc */
  	0,						/* tp_print */
  	0,						/* tp_getattr */