sunzhenguo / pacparser

Automatically exported from code.google.com/p/pacparser
GNU Lesser General Public License v3.0
0 stars 0 forks source link

Patch to compile on Python 3 #21

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
--- pacparser_py.c      2012-10-17 17:56:25.038235264 +0200
+++ pacparser_py.c.new  2012-10-17 17:51:57.648909350 +0200
@@ -31,6 +31,22 @@
 #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
 #endif

+#if PY_MAJOR_VERSION >= 3
+  #define MOD_ERROR_VAL NULL
+  #define MOD_SUCCESS_VAL(val) val
+  #define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void)
+  #define MOD_DEF(ob, name, doc, methods) \
+              static struct PyModuleDef moduledef = { \
+                              PyModuleDef_HEAD_INIT, name, doc, -1, methods, 
}; \
+                  ob = PyModule_Create(&moduledef);
+#else
+  #define MOD_ERROR_VAL
+  #define MOD_SUCCESS_VAL(val)
+  #define MOD_INIT(name) void init##name(void)
+  #define MOD_DEF(ob, name, doc, methods) \
+              ob = Py_InitModule3(name, methods, doc);
+#endif
+
 static PyObject *PacparserError;
 // Initialize PAC parser.
 //
@@ -137,12 +153,14 @@
   {NULL, NULL, 0, NULL}
 };

-PyMODINIT_FUNC
-init_pacparser(void)
+MOD_INIT(_pacparser)
 {
   PyObject *m;
-  m = Py_InitModule("_pacparser", PpMethods);
+  MOD_DEF(m, "_pacparser", NULL, PpMethods)
+  if(m == NULL)
+      return MOD_ERROR_VAL;
   PacparserError = PyErr_NewException("pacparser.error", NULL, NULL);
   Py_INCREF(PacparserError);
   PyModule_AddObject(m, "error", PacparserError);
+  return MOD_SUCCESS_VAL(m);
 }

Original issue reported on code.google.com by pawel.kr...@hush.com on 17 Oct 2012 at 4:02

GoogleCodeExporter commented 9 years ago
Thanks a lot Paweł for the patch. I have committed it:

https://code.google.com/p/pacparser/source/detail?r=2777fc745a8223886ddd9c017a6e
5f6e681369ce

Original comment by manugarg on 15 Apr 2013 at 6:00