Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch to compile on Python 3 #21

Closed
manugarg opened this issue Sep 26, 2014 · 1 comment
Closed

Patch to compile on Python 3 #21

manugarg opened this issue Sep 26, 2014 · 1 comment

Comments

@manugarg
Copy link
Owner

From [email protected] on October 17, 2012 09:02:27

--- 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: http://code.google.com/p/pacparser/issues/detail?id=21

@manugarg
Copy link
Owner Author

From manugarg on April 14, 2013 23:00:02

Thanks a lot Paweł for the patch. I have committed it: https://code.google.com/p/pacparser/source/detail?r=2777fc745a8223886ddd9c017a6e5f6e681369ce

Status: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant