jeffreywugz / pyev

Automatically exported from code.google.com/p/pyev
0 stars 0 forks source link

Python 2.x support #3

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I wanted to try the latest pyev with eventlet, but apparently Python 3.1 is
required.

Are there any plans to add support for Python 2.x?

Original issue reported on code.google.com by Denis.Bi...@gmail.com on 15 Jun 2009 at 11:52

GoogleCodeExporter commented 9 years ago
I use it in python 2.6.2
http://stan-noname.blogspot.com/2009/07/pyev-0.html

Original comment by s.suhopa...@gmail.com on 30 Jul 2009 at 11:01

GoogleCodeExporter commented 9 years ago
The difference doesn't seem to be too big, it would be good to incorporate it 
into
the mainstream source...

Original comment by nagy.att...@gmail.com on 3 Aug 2009 at 2:29

GoogleCodeExporter commented 9 years ago
Yes, you can place it in the new branch, for python 2.6.2

Original comment by s.suhopa...@gmail.com on 5 Aug 2009 at 12:42

GoogleCodeExporter commented 9 years ago
i just saw this and will try to add it to the next release

Original comment by lekma...@gmail.com on 2 Sep 2009 at 8:13

GoogleCodeExporter commented 9 years ago

Original comment by lekma...@gmail.com on 2 Sep 2009 at 8:14

GoogleCodeExporter commented 9 years ago
Here are the changes I made to get the thing to compile on Snow Leopard (Mac OS 
X
10.6) with Python 2.6.1:

diff --git a/pyev/setup.py b/pyev/setup.py
index 8f5d52a..8a9f010 100644
--- a/pyev/setup.py
+++ b/pyev/setup.py
@@ -52,7 +52,7 @@ from re import findall, search
 from distutils.core import setup, Extension

-python_version = (3, 1, 0)
+python_version = (2, 5, 0)
 if python_version_tuple() < python_version:
     raise SystemExit("Aborted: Python >= {0}.{1}.{2} "
                      "is required".format(*python_version))
diff --git a/pyev/src/pyev.c b/pyev/src/pyev.c
index 8755d86..b76aef2 100644
--- a/pyev/src/pyev.c
+++ b/pyev/src/pyev.c
@@ -4131,6 +4131,7 @@ static PyMethodDef pyev_methods[] = {
     {NULL} /* Sentinel */
 };

+#if PY_MAJOR_VERSION >= 3

 /* pyev_module */
 static PyModuleDef pyev_module = {
@@ -4141,10 +4142,18 @@ static PyModuleDef pyev_module = {
     pyev_methods,                             /*m_methods*/
 };

+#define INITERROR return NULL

 /* pyev_module initialization */
 PyMODINIT_FUNC
 PyInit_pyev(void)
+#else
+
+#define INITERROR return
+
+void
+initpyev(void)
+#endif
 {
     PyObject *pyev, *version;

@@ -4181,25 +4190,30 @@ PyInit_pyev(void)
         PyType_Ready(&ForkType) ||
         PyType_Ready(&AsyncType)
        ) {
-        return NULL;
+        INITERROR;
     }

     /* pyev.__version__ */
     version = PyUnicode_FromFormat("%s-%s", PYEV_VERSION, LIBEV_VERSION);
     if (!version) {
-        return NULL;
+        INITERROR;
     }

     /* pyev.Error object */
     Pyev_Error = PyErr_NewException("pyev.Error", NULL, NULL);
     if (!Pyev_Error) {
-        return NULL;
+        INITERROR;
     }

     /* pyev */
+#if PY_MAJOR_VERSION >= 3
     pyev = PyModule_Create(&pyev_module);
+#else
+    pyev = Py_InitModule("pyev", pyev_methods);
+#endif
+
     if (!pyev) {
-        return NULL;
+        INITERROR;
     }

     /* adding objects and constants */
@@ -4264,12 +4278,14 @@ PyInit_pyev(void)
         Py_DECREF(version);
         Py_DECREF(Pyev_Error);
         Py_DECREF(pyev);
-        return NULL;
+        INITERROR;
     }

     /* setup libev */
     ev_set_allocator(pyev_realloc);
     ev_set_syserr_cb(Py_FatalError);

+#if PY_MAJOR_VERSION >= 3
     return pyev;
+#endif
 }

Original comment by jnor...@gmail.com on 7 Sep 2009 at 8:17

GoogleCodeExporter commented 9 years ago
support for Python 2.6.2 is in trunk, please test

Original comment by lekma...@gmail.com on 21 Oct 2009 at 9:01