summaryrefslogtreecommitdiff
path: root/dev-libs/tre/files/tre-python3.patch
blob: b3068519e1dd410354958b91c70410748e0c2e73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
--- a/python/example.py
+++ b/python/example.py
@@ -1,7 +1,7 @@
 import tre
 
 fz = tre.Fuzzyness(maxerr = 3)
-print fz
+print (fz)
 
 pt = tre.compile("Don(ald( Ervin)?)? Knuth", tre.EXTENDED)
 data = """
@@ -16,5 +16,5 @@ typefaces.
 m = pt.search(data, fz)
 
 if m:
-    print m.groups()
-    print m[0]
+    print (m.groups())
+    print (m[0])
--- a/python/tre-python.c
+++ b/python/tre-python.c
@@ -86,9 +86,9 @@ TreFuzzyness_repr(PyObject *obj)
   TreFuzzynessObject *self = (TreFuzzynessObject*)obj;
   PyObject *o;
 
-  o = PyString_FromFormat("%s(delcost=%d,inscost=%d,maxcost=%d,subcost=%d,"
+  o = PyUnicode_FromFormat("%s(delcost=%d,inscost=%d,maxcost=%d,subcost=%d,"
 			  "maxdel=%d,maxerr=%d,maxins=%d,maxsub=%d)",
-			  self->ob_type->tp_name, self->ap.cost_del,
+			  Py_TYPE(self)->tp_name, self->ap.cost_del,
 			  self->ap.cost_ins, self->ap.max_cost,
 			  self->ap.cost_subst, self->ap.max_del,
 			  self->ap.max_err, self->ap.max_ins,
@@ -118,8 +118,7 @@ static PyMemberDef TreFuzzyness_members[
 };
 
 static PyTypeObject TreFuzzynessType = {
-  PyObject_HEAD_INIT(NULL)
-  0,			        /* ob_size */
+  PyVarObject_HEAD_INIT(NULL, 0)
   TRE_MODULE ".Fuzzyness",	/* tp_name */
   sizeof(TreFuzzynessObject),	/* tp_basicsize */
   0,			        /* tp_itemsize */
@@ -193,7 +192,7 @@ PyTreMatch_groups(TreMatchObject *self,
 }
 
 static PyObject *
-PyTreMatch_groupi(PyObject *obj, int gn)
+PyTreMatch_groupi(PyObject *obj, Py_ssize_t gn)
 {
   TreMatchObject *self = (TreMatchObject*)obj;
   PyObject *result;
@@ -220,7 +219,7 @@ PyTreMatch_group(TreMatchObject *self, P
   PyObject *result;
   long gn;
 
-  gn = PyInt_AsLong(grpno);
+  gn = PyLong_AsLong(grpno);
 
   if (PyErr_Occurred())
     return NULL;
@@ -277,8 +276,7 @@ static PySequenceMethods TreMatch_as_seq
 };
 
 static PyTypeObject TreMatchType = {
-  PyObject_HEAD_INIT(NULL)
-  0,			        /* ob_size */
+  PyVarObject_HEAD_INIT(NULL, 0)
   TRE_MODULE ".Match",		/* tp_name */
   sizeof(TreMatchObject),	/* tp_basicsize */
   0,			        /* tp_itemsize */
@@ -380,8 +378,8 @@ PyTrePattern_search(TrePatternObject *se
     }
   else
     {
-      targ = PyString_AsString(pstring);
-      tlen = PyString_Size(pstring);
+      targ = PyBytes_AsString(pstring);
+      tlen = PyBytes_Size(pstring);
 
       rc = tre_reganexec(&self->rgx, targ, tlen, &mo->am, fz->ap, eflags);
     }
@@ -433,8 +431,7 @@ PyTrePattern_dealloc(TrePatternObject *s
 }
 
 static PyTypeObject TrePatternType = {
-  PyObject_HEAD_INIT(NULL)
-  0,			        /* ob_size */
+  PyVarObject_HEAD_INIT(NULL, 0)
   TRE_MODULE ".Pattern",	/* tp_name */
   sizeof(TrePatternObject),	/* tp_basicsize */
   0,			        /* tp_itemsize */
@@ -467,7 +464,7 @@ static PyTypeObject TrePatternType = {
 };
 
 static TrePatternObject *
-newTrePatternObject()
+newTrePatternObject(void)
 {
   TrePatternObject *self;
 
@@ -482,7 +479,7 @@ static PyObject *
 PyTre_ncompile(PyObject *self, PyObject *args)
 {
   TrePatternObject *rv;
-  PyUnicodeObject *upattern = NULL;
+  PyObject *upattern = NULL;
   char *pattern = NULL;
   int pattlen;
   int cflags = 0;
@@ -537,9 +534,8 @@ static PyMethodDef tre_methods[] = {
   { NULL, NULL }
 };
 
-static char *tre_doc =
-"Python module for TRE library\n\nModule exports "
-"the only function: compile";
+
+#define tre_doc "Python module for TRE library\n\nModule exports the only function: compile"
 
 static struct _tre_flags {
   char *name;
@@ -556,40 +552,57 @@ static struct _tre_flags {
   { NULL, 0 }
 };
 
+
+static struct PyModuleDef moduledef = {
+  PyModuleDef_HEAD_INIT,
+  TRE_MODULE ".Module",   /* m_name */
+  tre_doc,             /* m_doc */
+  -1,                  /* m_size */
+  tre_methods,         /* m_methods */
+  NULL,                /* m_reload */
+  NULL,                /* m_traverse */
+  NULL,                /* m_clear */
+  NULL,                /* m_free */
+};
+
+
 PyMODINIT_FUNC
-inittre(void)
+PyInit_tre(void)
 {
   PyObject *m;
   struct _tre_flags *fp;
 
   if (PyType_Ready(&TreFuzzynessType) < 0)
-    return;
+    return NULL;
   if (PyType_Ready(&TreMatchType) < 0)
-    return;
+    return NULL;
   if (PyType_Ready(&TrePatternType) < 0)
-    return;
+    return NULL;
 
   /* Create the module and add the functions */
-  m = Py_InitModule3(TRE_MODULE, tre_methods, tre_doc);
+
+  m = PyModule_Create (&moduledef);
+
   if (m == NULL)
-    return;
+    return NULL;
 
   Py_INCREF(&TreFuzzynessType);
   if (PyModule_AddObject(m, "Fuzzyness", (PyObject*)&TreFuzzynessType) < 0)
-    return;
+    return NULL;
   Py_INCREF(&TreMatchType);
   if (PyModule_AddObject(m, "Match", (PyObject*)&TreMatchType) < 0)
-    return;
+    return NULL;
   Py_INCREF(&TrePatternType);
   if (PyModule_AddObject(m, "Pattern", (PyObject*)&TrePatternType) < 0)
-    return;
+    return NULL;
   ErrorObject = PyErr_NewException(TRE_MODULE ".Error", NULL, NULL);
   Py_INCREF(ErrorObject);
   if (PyModule_AddObject(m, "Error", ErrorObject) < 0)
-    return;
+    return NULL;
 
   /* Insert the flags */
   for (fp = tre_flags; fp->name != NULL; fp++)
     if (PyModule_AddIntConstant(m, fp->name, fp->val) < 0)
-      return;
+      return NULL;
+  return m;
 }