[Checkins] SVN: persistent/trunk/ All extensions building w/ tests passing under Python 3.2.

Tres Seaver cvs-admin at zope.org
Wed Dec 12 02:26:58 UTC 2012


Log message for revision 128593:
  All extensions building w/ tests passing under Python 3.2.

Changed:
  U   persistent/trunk/persistent/_timestamp.c
  U   persistent/trunk/persistent/cPersistence.c
  U   persistent/trunk/persistent/cPickleCache.c
  U   persistent/trunk/setup.py

-=-
Modified: persistent/trunk/persistent/_timestamp.c
===================================================================
--- persistent/trunk/persistent/_timestamp.c	2012-12-12 02:26:23 UTC (rev 128592)
+++ persistent/trunk/persistent/_timestamp.c	2012-12-12 02:26:58 UTC (rev 128593)
@@ -13,8 +13,20 @@
  ****************************************************************************/
 
 #include "Python.h"
+#include "bytesobject.h"
 #include <time.h>
 
+#if PY_MAJOR_VERSION >= 3
+#define PY3K
+#define Py_TPFLAGS_HAVE_RICHCOMPARE 0
+#endif
+
+#ifdef PY3K
+#define INT_FROM_LONG(x) PyLong_FromLong(x)
+#else
+#define INT_FROM_LONG(x) PyInt_FromLong(x)
+#endif
+
 PyObject *TimeStamp_FromDate(int, int, int, int, int, double);
 PyObject *TimeStamp_FromString(const char *);
 
@@ -106,13 +118,41 @@
     PyObject_Del(ts);
 }
 
-static int
-TimeStamp_compare(TimeStamp *v, TimeStamp *w)
+static PyObject*
+TimeStamp_richcompare(TimeStamp *self, TimeStamp *other, int op)
 {
-    int cmp = memcmp(v->data, w->data, 8);
-    if (cmp < 0) return -1;
-    if (cmp > 0) return 1;
-    return 0;
+    PyObject *result = NULL;
+    int cmp;
+
+    if (Py_TYPE(other) != Py_TYPE(self)) {
+        result = Py_NotImplemented;
+    }
+    else {
+        cmp = memcmp(self->data, other->data, 8);
+        switch (op) {
+        case Py_LT:
+            result = (cmp < 0) ? Py_True : Py_False;
+            break;
+        case Py_LE:
+            result = (cmp <= 0) ? Py_True : Py_False;
+            break;
+        case Py_EQ:
+            result = (cmp == 0) ? Py_True : Py_False;
+            break;
+        case Py_NE:
+            result = (cmp != 0) ? Py_True : Py_False;
+            break;
+        case Py_GT:
+            result = (cmp > 0) ? Py_True : Py_False;
+            break;
+        case Py_GE:
+            result = (cmp >= 0) ? Py_True : Py_False;
+            break;
+        }
+    }
+
+    Py_XINCREF(result);
+    return result;
 }
 
 static long
@@ -165,7 +205,7 @@
 {
     TimeStampParts p;
     TimeStamp_unpack(self, &p);
-    return PyInt_FromLong(p.y);
+    return INT_FROM_LONG(p.y);
 }
 
 static PyObject *
@@ -173,7 +213,7 @@
 {
     TimeStampParts p;
     TimeStamp_unpack(self, &p);
-    return PyInt_FromLong(p.m);
+    return INT_FROM_LONG(p.m);
 }
 
 static PyObject *
@@ -181,7 +221,7 @@
 {
     TimeStampParts p;
     TimeStamp_unpack(self, &p);
-    return PyInt_FromLong(p.d);
+    return INT_FROM_LONG(p.d);
 }
 
 static PyObject *
@@ -189,7 +229,7 @@
 {
     TimeStampParts p;
     TimeStamp_unpack(self, &p);
-    return PyInt_FromLong(p.mi / 60);
+    return INT_FROM_LONG(p.mi / 60);
 }
 
 static PyObject *
@@ -197,7 +237,7 @@
 {
     TimeStampParts p;
     TimeStamp_unpack(self, &p);
-    return PyInt_FromLong(p.mi % 60);
+    return INT_FROM_LONG(p.mi % 60);
 }
 
 static PyObject *
@@ -218,7 +258,7 @@
 static PyObject *
 TimeStamp_raw(TimeStamp *self)
 {
-    return PyString_FromStringAndSize((const char*)self->data, 8);
+    return PyBytes_FromStringAndSize((const char*)self->data, 8);
 }
 
 static PyObject *
@@ -233,7 +273,7 @@
 	         p.y, p.m, p.d, p.mi / 60, p.mi % 60,
 	         TimeStamp_sec(self));
 
-    return PyString_FromStringAndSize(buf, len);
+    return PyBytes_FromStringAndSize(buf, len);
 }
 
 
@@ -245,7 +285,7 @@
     unsigned char new[8];
     int i;
 
-    if (obj->ob_type != self->ob_type) {
+    if (Py_TYPE(obj) != Py_TYPE(self)) {
 	PyErr_SetString(PyExc_TypeError, "expected TimeStamp object");
 	return NULL;
     }
@@ -298,42 +338,45 @@
     {NULL,	NULL},
 };
 
+#define DEFERRED_ADDRESS(ADDR) 0
+
 static PyTypeObject TimeStamp_type = {
-    PyObject_HEAD_INIT(NULL)
-    0,
+    PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(NULL), 0)
     "persistent.TimeStamp",
-    sizeof(TimeStamp),
-    0,
-    (destructor)TimeStamp_dealloc,	/* tp_dealloc */
-    0,					/* tp_print */
-    0,					/* tp_getattr */
-    0,					/* tp_setattr */
-    (cmpfunc)TimeStamp_compare,		/* tp_compare */
-    (reprfunc)TimeStamp_raw,		/* tp_repr */
-    0,					/* tp_as_number */
-    0,					/* tp_as_sequence */
-    0,					/* tp_as_mapping */
-    (hashfunc)TimeStamp_hash,		/* tp_hash */
-    0,					/* tp_call */
-    (reprfunc)TimeStamp_str,		/* tp_str */
-    0,					/* tp_getattro */
-    0,					/* tp_setattro */
-    0,					/* tp_as_buffer */
-    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
-    0,					/* tp_doc */
-    0,					/* tp_traverse */
-    0,					/* tp_clear */
-    0,					/* tp_richcompare */
-    0,					/* tp_weaklistoffset */
-    0,					/* tp_iter */
-    0,					/* tp_iternext */
-    TimeStamp_methods,			/* tp_methods */
-    0,					/* tp_members */
-    0,					/* tp_getset */
-    0,					/* tp_base */
-    0,					/* tp_dict */
-    0,					/* tp_descr_get */
-    0,					/* tp_descr_set */
+    sizeof(TimeStamp),                      /* tp_basicsize */
+    0,                                      /* tp_itemsize */
+    (destructor)TimeStamp_dealloc,	        /* tp_dealloc */
+    0,					                    /* tp_print */
+    0,					                    /* tp_getattr */
+    0,					                    /* tp_setattr */
+    0,		                                /* tp_compare */
+    (reprfunc)TimeStamp_raw,		        /* tp_repr */
+    0,					                    /* tp_as_number */
+    0,					                    /* tp_as_sequence */
+    0,					                    /* tp_as_mapping */
+    (hashfunc)TimeStamp_hash,		        /* tp_hash */
+    0,					                    /* tp_call */
+    (reprfunc)TimeStamp_str,		        /* tp_str */
+    0,					                    /* tp_getattro */
+    0,					                    /* tp_setattro */
+    0,					                    /* tp_as_buffer */
+    Py_TPFLAGS_DEFAULT |
+    Py_TPFLAGS_BASETYPE |
+    Py_TPFLAGS_HAVE_RICHCOMPARE,            /* tp_flags */
+    0,					                    /* tp_doc */
+    0,					                    /* tp_traverse */
+    0,					                    /* tp_clear */
+    (richcmpfunc)&TimeStamp_richcompare,    /* tp_richcompare */
+    0,					                    /* tp_weaklistoffset */
+    0,					                    /* tp_iter */
+    0,					                    /* tp_iternext */
+    TimeStamp_methods,			            /* tp_methods */
+    0,					                    /* tp_members */
+    0,					                    /* tp_getset */
+    0,					                    /* tp_base */
+    0,					                    /* tp_dict */
+    0,					                    /* tp_descr_get */
+    0,					                    /* tp_descr_set */
 };
 
 PyObject *
@@ -418,7 +461,21 @@
     {NULL,		NULL},
 };
 
+#ifdef PY3K
+static struct PyModuleDef moduledef = {
+        PyModuleDef_HEAD_INIT,
+        "_timestamp",               /* m_name */
+        TimeStampModule_doc,        /* m_doc */
+        -1,                         /* m_size */
+        TimeStampModule_functions,  /* m_methods */
+        NULL,                       /* m_reload */
+        NULL,                       /* m_traverse */
+        NULL,                       /* m_clear */
+        NULL,                       /* m_free */
+    };
+#endif
 
+
 void
 init_timestamp(void)
 {
@@ -427,11 +484,19 @@
     if (TimeStamp_init_gmoff() < 0)
 	return;
 
+#ifdef PY3K
+    m = PyModule_Create(&moduledef);
+#else
     m = Py_InitModule4("_timestamp", TimeStampModule_functions,
 		       TimeStampModule_doc, NULL, PYTHON_API_VERSION);
+#endif
     if (m == NULL)
 	return;
 
+#ifdef PY3K
+  ((PyObject*)&TimeStamp_type)->ob_type = &PyType_Type;
+#else
     TimeStamp_type.ob_type = &PyType_Type;
+#endif
     TimeStamp_type.tp_getattro = PyObject_GenericGetAttr;
 }

Modified: persistent/trunk/persistent/cPersistence.c
===================================================================
--- persistent/trunk/persistent/cPersistence.c	2012-12-12 02:26:23 UTC (rev 128592)
+++ persistent/trunk/persistent/cPersistence.c	2012-12-12 02:26:58 UTC (rev 128593)
@@ -1272,37 +1272,38 @@
 #define DEFERRED_ADDRESS(ADDR) 0
 
 static PyTypeObject Pertype = {
-  PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyPersist_MetaType), 0)
-  "persistent.Persistent",		/* tp_name */
+  PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0)
+  "persistent.Persistent",		    /* tp_name */
   sizeof(cPersistentObject),		/* tp_basicsize */
-  0,					/* tp_itemsize */
-  (destructor)Per_dealloc,		/* tp_dealloc */
-  0,					/* tp_print */
-  0,					/* tp_getattr */
-  0,					/* tp_setattr */
-  0,					/* tp_compare */
-  0,					/* tp_repr */
-  0,					/* tp_as_number */
-  0,					/* tp_as_sequence */
-  0,					/* tp_as_mapping */
-  0,					/* tp_hash */
-  0,					/* tp_call */
-  0,					/* tp_str */
+  0,					            /* tp_itemsize */
+  (destructor)Per_dealloc,		    /* tp_dealloc */
+  0,					            /* tp_print */
+  0,					            /* tp_getattr */
+  0,					            /* tp_setattr */
+  0,					            /* tp_compare */
+  0,					            /* tp_repr */
+  0,					            /* tp_as_number */
+  0,					            /* tp_as_sequence */
+  0,					            /* tp_as_mapping */
+  0,					            /* tp_hash */
+  0,					            /* tp_call */
+  0,					            /* tp_str */
   (getattrofunc)Per_getattro,		/* tp_getattro */
   (setattrofunc)Per_setattro,		/* tp_setattro */
-  0,					/* tp_as_buffer */
-  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
-  /* tp_flags */
-  0,					/* tp_doc */
+  0,					            /* tp_as_buffer */
+  Py_TPFLAGS_DEFAULT |
+  Py_TPFLAGS_BASETYPE |
+  Py_TPFLAGS_HAVE_GC,               /* tp_flags */
+  0,					            /* tp_doc */
   (traverseproc)Per_traverse,		/* tp_traverse */
-  0,					/* tp_clear */
-  0,					/* tp_richcompare */
-  0,					/* tp_weaklistoffset */
-  0,					/* tp_iter */
-  0,					/* tp_iternext */
-  Per_methods,			/* tp_methods */
-  0,					/* tp_members */
-  Per_getsets,			/* tp_getset */
+  0,					            /* tp_clear */
+  0,					            /* tp_richcompare */
+  0,					            /* tp_weaklistoffset */
+  0,					            /* tp_iter */
+  0,					            /* tp_iternext */
+  Per_methods,			            /* tp_methods */
+  0,					            /* tp_members */
+  Per_getsets,			            /* tp_getset */
 };
 
 /* End of code for Persistent objects */

Modified: persistent/trunk/persistent/cPickleCache.c
===================================================================
--- persistent/trunk/persistent/cPickleCache.c	2012-12-12 02:26:23 UTC (rev 128592)
+++ persistent/trunk/persistent/cPickleCache.c	2012-12-12 02:26:58 UTC (rev 128593)
@@ -1254,41 +1254,42 @@
 
 static PyTypeObject Cctype = {
   PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0)
-  "persistent.PickleCache",		/* tp_name */
-  sizeof(ccobject),			/* tp_basicsize */
-  0,					/* tp_itemsize */
-  (destructor)cc_dealloc,		/* tp_dealloc */
-  0,					/* tp_print */
-  0,					/* tp_getattr */
-  0,					/* tp_setattr */
-  0,					/* tp_compare */
-  0,					/* tp_repr */
-  0,					/* tp_as_number */
-  0,					/* tp_as_sequence */
-  &cc_as_mapping,			/* tp_as_mapping */
-  0,					/* tp_hash */
-  0,					/* tp_call */
-  0,					/* tp_str */
-  0,					/* tp_getattro */
-  0,					/* tp_setattro */
-  0,					/* tp_as_buffer */
-  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
-  /* tp_flags */
-  0,					/* tp_doc */
-  (traverseproc)cc_traverse,		/* tp_traverse */
+  "persistent.PickleCache",	    /* tp_name */
+  sizeof(ccobject),			    /* tp_basicsize */
+  0,					        /* tp_itemsize */
+  (destructor)cc_dealloc,	    /* tp_dealloc */
+  0,					        /* tp_print */
+  0,					        /* tp_getattr */
+  0,					        /* tp_setattr */
+  0,					        /* tp_compare */
+  0,					        /* tp_repr */
+  0,					        /* tp_as_number */
+  0,					        /* tp_as_sequence */
+  &cc_as_mapping,			    /* tp_as_mapping */
+  0,					        /* tp_hash */
+  0,					        /* tp_call */
+  0,					        /* tp_str */
+  0,					        /* tp_getattro */
+  0,					        /* tp_setattro */
+  0,					        /* tp_as_buffer */
+  Py_TPFLAGS_DEFAULT |
+  Py_TPFLAGS_BASETYPE |
+  Py_TPFLAGS_HAVE_GC,           /* tp_flags */
+  0,					        /* tp_doc */
+  (traverseproc)cc_traverse,    /* tp_traverse */
   (inquiry)cc_clear,			/* tp_clear */
-  0,					/* tp_richcompare */
-  0,					/* tp_weaklistoffset */
-  0,					/* tp_iter */
-  0,					/* tp_iternext */
-  cc_methods,				/* tp_methods */
-  cc_members,				/* tp_members */
-  cc_getsets,				/* tp_getset */
-  0,					/* tp_base */
-  0,					/* tp_dict */
-  0,					/* tp_descr_get */
-  0,					/* tp_descr_set */
-  0,					/* tp_dictoffset */
+  0,					        /* tp_richcompare */
+  0,					        /* tp_weaklistoffset */
+  0,					        /* tp_iter */
+  0,					        /* tp_iternext */
+  cc_methods,				    /* tp_methods */
+  cc_members,				    /* tp_members */
+  cc_getsets,				    /* tp_getset */
+  0,					        /* tp_base */
+  0,					        /* tp_dict */
+  0,					        /* tp_descr_get */
+  0,					        /* tp_descr_set */
+  0,					        /* tp_dictoffset */
   (initproc)cc_init,			/* tp_init */
 };
 

Modified: persistent/trunk/setup.py
===================================================================
--- persistent/trunk/setup.py	2012-12-12 02:26:23 UTC (rev 128592)
+++ persistent/trunk/setup.py	2012-12-12 02:26:58 UTC (rev 128593)
@@ -35,7 +35,7 @@
 # Jython cannot build the C optimizations, while on PyPy they are
 # anti-optimizations (the C extension compatibility layer is known-slow,
 # and defeats JIT opportunities).
-if is_pypy or is_jython or sys.version_info[0] > 2:
+if is_pypy or is_jython:
     ext_modules = headers = []
 else:
     ext_modules = [Extension(name = 'persistent.cPersistence',



More information about the checkins mailing list