Open GoogleCodeExporter opened 9 years ago
With a great thanks to Thomas Goirand I can write the second part of the patch:
Index: python-esmre/src/esmre.py
===================================================================
--- python-esmre.orig/src/esmre.py 2015-02-19 17:06:52.718795534 +0100
+++ python-esmre/src/esmre.py 2015-02-19 17:06:52.714795526 +0100
@@ -246,7 +246,7 @@
try:
if self.fixed:
- raise TypeError, "enter() cannot be called after query()"
+ raise TypeError("enter() cannot be called after query()")
keywords = shortlist(hints(regex))
Original comment by costamag...@gmail.com
on 19 Feb 2015 at 4:09
with great help from Thomas again I can write the full patch now:
Index: python-esmre/src/esm.c
===================================================================
--- python-esmre.orig/src/esm.c 2015-02-20 13:15:48.597454617 +0100
+++ python-esmre/src/esm.c 2015-02-20 13:15:48.593454596 +0100
@@ -21,6 +21,10 @@
#include "aho_corasick.h"
+#ifndef Py_TYPE
+ #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
+#endif
+
typedef struct {
PyObject_HEAD
ac_index* index;
@@ -35,7 +39,7 @@
static void
esm_Index_dealloc(esm_IndexObject* self) {
ac_index_free(self->index, decref_result_object);
- self->ob_type->tp_free((PyObject*) self);
+ Py_TYPE(self)->tp_free ((PyObject*) self);
}
static PyObject*
@@ -180,10 +184,14 @@
{NULL} /* Sentinel */
};
+// support old python 2.5
+#ifndef PyVarObject_HEAD_INIT
+ #define PyVarObject_HEAD_INIT(type, size) \
+ PyObject_HEAD_INIT(type) size,
+#endif
static PyTypeObject esm_IndexType = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"esm.Index", /*tp_name*/
sizeof(esm_IndexObject), /*tp_basicsize*/
0, /*tp_itemsize*/
@@ -231,21 +239,51 @@
#define PyMODINIT_FUNC void
#endif
PyMODINIT_FUNC
-initesm(void)
+#if PY_MAJOR_VERSION >= 3
+PyInit_esm(void)
+#else
+initesm(void)
+#endif
{
PyObject* m;
if (PyType_Ready(&esm_IndexType) < 0)
+#if PY_MAJOR_VERSION >= 3
+ return NULL;
+#else
return;
+#endif
+#if PY_MAJOR_VERSION >= 3
+ static struct PyModuleDef moduledef = {
+ PyModuleDef_HEAD_INIT,
+ "esm", /* m_name */
+ "Support for efficient string matching.", /* m_doc */
+ -1, /* m_size */
+ esm_methods, /* m_methods */
+ NULL, /* m_reload */
+ NULL, /* m_traverse */
+ NULL, /* m_clear */
+ NULL, /* m_free */
+ };
+ m = PyModule_Create(&moduledef);
+#else
m = Py_InitModule3("esm", esm_methods,
"Support for efficient string matching.");
+#endif
if (m == NULL) {
+#if PY_MAJOR_VERSION >= 3
+ return NULL;
+#else
return;
+#endif
}
Py_INCREF(&esm_IndexType);
PyModule_AddObject(m, "Index", (PyObject *)&esm_IndexType);
+#if PY_MAJOR_VERSION >= 3
+ return m;
+#endif
}
Index: python-esmre/src/esmre.py
===================================================================
--- python-esmre.orig/src/esmre.py 2015-02-20 13:15:48.597454617 +0100
+++ python-esmre/src/esmre.py 2015-02-20 13:15:48.593454596 +0100
@@ -246,7 +246,7 @@
try:
if self.fixed:
- raise TypeError, "enter() cannot be called after query()"
+ raise TypeError("enter() cannot be called after query()")
keywords = shortlist(hints(regex))
Original comment by costamag...@gmail.com
on 20 Feb 2015 at 12:20
Attachments:
Original issue reported on code.google.com by
costamag...@gmail.com
on 19 Feb 2015 at 10:16