fix Parser.__module__ for 2.7 py33
authorrobin
Mon, 18 Nov 2013 10:48:33 +0000
branchpy33
changeset 20 825aedf5dd22
parent 19 9d3d2132b307
child 21 0e2e76932beb
fix Parser.__module__ for 2.7
src/pyRXP.c
--- a/src/pyRXP.c	Thu Nov 14 17:49:56 2013 +0000
+++ b/src/pyRXP.c	Mon Nov 18 10:48:33 2013 +0000
@@ -73,6 +73,7 @@
 #	define Py_FindMethod RLPy_FindMethod
 #	define KEY2STR(key) PyUnicode_AsUTF8(key)
 #else
+	static	PyObject *g_module;
 	static struct module_state _state;
 #	define GETSTATE(m) (&_state)
 #	define MSTATE(m,n) GETSTATE(m)->n
@@ -1157,7 +1158,11 @@
 	if(!PyArg_ParseTuple(args, ":Parser")) return NULL;
 	if(!(self = PyObject_NEW(pyRXPParserObject, &pyRXPParserType))) return NULL;
 	self->warnCB = self->eoCB = self->ucrCB = self->fourth = self->srcName = NULL;
+#ifdef isPy3
 	self->__module__ = module;
+#else
+	self->__module__ = g_module;
+#endif
 	if(!(self->srcName=PyBytes_FromString("[unknown]"))){
 		PyErr_SetString(MSTATE(module,moduleError),"Internal error, memory limit reached!");
 Lfree:	pyRXPParserFree(self);
@@ -1252,14 +1257,17 @@
 #endif
 
 #ifndef isPy3
-	/*set up the types by hand*/
-	pyRXPParserType.ob_type = &PyType_Type;
+	if(PyType_Ready(&pyRXPParserType)<0)goto err;	/*set up the types by hand*/
 #endif
 
 	/* Create the module and add the functions */
 	m = CREATE_MODULE();
     if(!m)goto err;
 
+#ifndef isPy3
+	g_module = m;
+#endif
+
 	/* Add some symbolic constants to the module */
 	moduleVersion = PyBytes_FromString(VERSION);
 	if(!moduleVersion)goto err;