summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2003-04-14 22:01:58 (GMT)
committerGuido van Rossum <guido@python.org>2003-04-14 22:01:58 (GMT)
commit8b7a9a38c66aff5633255b63be639ee8592f180b (patch)
tree3e385d0dbb502e732aaa613464eef7ad3b51a186 /Modules
parent4dcdb78c6ffd203c9d72ef41638cc4a0e3857adf (diff)
downloadcpython-8b7a9a38c66aff5633255b63be639ee8592f180b.zip
cpython-8b7a9a38c66aff5633255b63be639ee8592f180b.tar.gz
cpython-8b7a9a38c66aff5633255b63be639ee8592f180b.tar.bz2
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.)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/datetimemodule.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/Modules/datetimemodule.c b/Modules/datetimemodule.c
index e514a54..88a076b 100644
--- a/Modules/datetimemodule.c
+++ b/Modules/datetimemodule.c
@@ -1291,16 +1291,19 @@ set_date_fields(PyDateTime_Date *self, int y, int m, int d)
/* Create a date instance with no range checking. */
static PyObject *
-new_date(int year, int month, int day)
+new_date_ex(int year, int month, int day, PyTypeObject *type)
{
PyDateTime_Date *self;
- self = PyObject_New(PyDateTime_Date, &PyDateTime_DateType);
+ self = (PyDateTime_Date *) (type->tp_alloc(type, 0));
if (self != NULL)
set_date_fields(self, year, month, day);
return (PyObject *) self;
}
+#define new_date(year, month, day) \
+ (new_date_ex(year, month, day, &PyDateTime_DateType))
+
/* Create a datetime instance with no range checking. */
static PyObject *
new_datetime(int year, int month, int day, int hour, int minute,
@@ -2168,7 +2171,7 @@ date_new(PyTypeObject *type, PyObject *args, PyObject *kw)
{
PyDateTime_Date *me;
- me = PyObject_New(PyDateTime_Date, &PyDateTime_DateType);
+ me = PyObject_New(PyDateTime_Date, type);
if (me != NULL) {
char *pdata = PyString_AS_STRING(state);
memcpy(me->data, pdata, _PyDateTime_DATE_DATASIZE);
@@ -2181,7 +2184,7 @@ date_new(PyTypeObject *type, PyObject *args, PyObject *kw)
&year, &month, &day)) {
if (check_date_args(year, month, day) < 0)
return NULL;
- self = new_date(year, month, day);
+ self = new_date_ex(year, month, day, type);
}
return self;
}
@@ -2632,7 +2635,7 @@ static PyTypeObject PyDateTime_DateType = {
"datetime.date", /* tp_name */
sizeof(PyDateTime_Date), /* tp_basicsize */
0, /* tp_itemsize */
- (destructor)PyObject_Del, /* tp_dealloc */
+ 0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */