pygobject r874 - in trunk: . glib



Author: johan
Date: Sat Jul 26 14:04:48 2008
New Revision: 874
URL: http://svn.gnome.org/viewvc/pygobject?rev=874&view=rev

Log:
2008-07-26  Johan Dahlin  <johan gnome org>

    * glib/Makefile.am:
    Also export PyInit_glib
    * glib/__init__.py:
    import glib._glib instead of just _glib
    * glib/pyglib-python-compat.h:
    * glib/pygoptioncontext.c (pyg_option_context_parse):
    * glib/pygsource.c (source_repr), (pyg_source_attach),
    (pyg_source_get_priority), (pyg_source_set_priority),
    (pyg_source_get_id), (pyg_source_prepare), (pyg_poll_fd_repr):
    * glib/pygspawn.c (pyg_pid_close), (pyg_pid_free), (pyg_pid_new),
    (pyglib_spawn_async), (pyglib_spawn_register_types):
    Go over the rest and replace missing symbols on python3.
    the glib module successfully compiles and runs now.



Modified:
   trunk/ChangeLog
   trunk/glib/Makefile.am
   trunk/glib/__init__.py
   trunk/glib/pyglib-python-compat.h
   trunk/glib/pygoptioncontext.c
   trunk/glib/pygsource.c
   trunk/glib/pygspawn.c

Modified: trunk/glib/Makefile.am
==============================================================================
--- trunk/glib/Makefile.am	(original)
+++ trunk/glib/Makefile.am	Sat Jul 26 14:04:48 2008
@@ -28,7 +28,7 @@
 	pyglib-python-compat.h
 
 _glib_la_CFLAGS = $(GLIB_CFLAGS)
-_glib_la_LDFLAGS = $(common_ldflags) -export-symbols-regex init_glib
+_glib_la_LDFLAGS = $(common_ldflags) -export-symbols-regex "_glib|PyInit__glib"
 _glib_la_LIBADD = $(GLIB_LIBS) libpyglib-2.0.la
 _glib_la_SOURCES = 	 	\
 	glibmodule.c	 	\

Modified: trunk/glib/__init__.py
==============================================================================
--- trunk/glib/__init__.py	(original)
+++ trunk/glib/__init__.py	Sat Jul 26 14:04:48 2008
@@ -27,7 +27,7 @@
 except ImportError:
     pass
 
-from _glib import *
+from glib._glib import *
 _PyGLib_API = _glib._PyGLib_API
 
 del _glib

Modified: trunk/glib/pyglib-python-compat.h
==============================================================================
--- trunk/glib/pyglib-python-compat.h	(original)
+++ trunk/glib/pyglib-python-compat.h	Sat Jul 26 14:04:48 2008
@@ -55,12 +55,16 @@
 #define _PyUnicode_AsStringAndSize PyString_AsStringAndSize
 #define _PyUnicode_FromString PyString_FromString 
 #define _PyUnicode_FromStringAndSize PyString_FromStringAndSize 
+#define _PyUnicode_FromFormat PyString_FromFormat
 #define _PyUnicode_AS_STRING PyString_AS_STRING
 #define _PyUnicode_GET_SIZE PyString_GET_SIZE
 #define _PyUnicode_Resize _PyString_Resize
 #define _PyLong_Check PyInt_Check
 #define _PyLong_FromLong PyInt_FromLong
 #define _PyLong_AsLong  PyInt_AsLong
+#define RO READONLY
+#define _PyLongObject PyIntObject
+#define _PyLong_Type PyInt_Type
 #else
 #define PYGLIB_MODULE_START(symbol, modname)	        \
     static struct PyModuleDef _##symbol##module = {     \
@@ -99,12 +103,15 @@
 #define _PyUnicode_AsStringAndSize(obj, buf, size) PyUnicode_AsStringAndSize(obj, size)
 #define _PyUnicode_FromString PyUnicode_FromString
 #define _PyUnicode_FromStringAndSize PyUnicode_FromStringAndSize
+#define _PyUnicode_FromFormat PyUnicode_FromFormat
 #define _PyUnicode_AS_STRING _PyUnicode_AsString
 #define _PyUnicode_GET_SIZE PyUnicode_GET_SIZE
 #define _PyUnicode_Resize PyUnicode_Resize
 #define _PyLong_Check PyLong_Check
 #define _PyLong_FromLong PyLong_FromLong
 #define _PyLong_AsLong PyLong_AsLong
+#define _PyLongObject PyLongObject
+#define _PyLong_Type PyLong_Type
 #endif
 
 #endif /* __PYGLIB_PYTHON_COMPAT_H__ */

Modified: trunk/glib/pygoptioncontext.c
==============================================================================
--- trunk/glib/pygoptioncontext.c	(original)
+++ trunk/glib/pygoptioncontext.c	Sat Jul 26 14:04:48 2008
@@ -97,7 +97,7 @@
     for (pos = 0; pos < argv_length; pos++)
     {
         arg = PyList_GetItem(argv, pos);
-        argv_content[pos] = g_strdup(PyString_AsString(arg));
+        argv_content[pos] = g_strdup(_PyUnicode_AsString(arg));
         if (argv_content[pos] == NULL)
         {
             g_strfreev(argv_content);
@@ -125,7 +125,7 @@
     new_argv = PyList_New(g_strv_length(argv_content));
     for (pos = 0; pos < argv_length; pos++)
     {
-        arg = PyString_FromString(argv_content[pos]);
+        arg = _PyUnicode_FromString(argv_content[pos]);
         PyList_SetItem(new_argv, pos, arg);
     }
     

Modified: trunk/glib/pygsource.c
==============================================================================
--- trunk/glib/pygsource.c	(original)
+++ trunk/glib/pygsource.c	Sat Jul 26 14:04:48 2008
@@ -82,7 +82,7 @@
 	g_snprintf(buf, sizeof(buf), "<%s glib source at 0x%lx>",
 		   desc, (long) self);
 
-    return PyString_FromString(buf);
+    return _PyUnicode_FromString(buf);
 }
 
 static PyObject *
@@ -109,7 +109,7 @@
     }
 
     id = g_source_attach(self->source, context);
-    return PyInt_FromLong(id);
+    return _PyLong_FromLong(id);
 }
 
 static PyObject *
@@ -283,7 +283,7 @@
 {
     CHECK_DESTROYED(self, NULL);
 
-    return PyInt_FromLong(g_source_get_priority(self->source));
+    return _PyLong_FromLong(g_source_get_priority(self->source));
 }
 
 static int
@@ -296,12 +296,12 @@
 	return -1;
     }
 
-    if (!PyInt_Check(value)) {
+    if (!_PyLong_Check(value)) {
 	PyErr_SetString(PyExc_TypeError, "type mismatch");
 	return -1;
     }
 
-    g_source_set_priority(self->source, PyInt_AsLong(value));
+    g_source_set_priority(self->source, _PyLong_AsLong(value));
 
     return 0;
 }
@@ -339,7 +339,7 @@
 	return NULL;
     }
 
-    return PyInt_FromLong(g_source_get_id(self->source));
+    return _PyLong_FromLong(g_source_get_id(self->source));
 }
 
 static PyGetSetDef pyg_source_getsets[] = {
@@ -426,7 +426,7 @@
     }
 
     ret = PyObject_IsTrue(PyTuple_GET_ITEM(t, 0));
-	*timeout = PyInt_AsLong(PyTuple_GET_ITEM(t, 1));
+	*timeout = _PyLong_AsLong(PyTuple_GET_ITEM(t, 1));
 
 	if (*timeout == -1 && PyErr_Occurred()) {
 	    ret = FALSE;
@@ -636,9 +636,9 @@
 PYGLIB_DEFINE_TYPE("glib.PollFD", PyGPollFD_Type, PyGPollFD)
 
 static PyMemberDef pyg_poll_fd_members[] = {
-    { "fd",      T_INT,    offsetof(PyGPollFD, pollfd.fd),      RO },
-    { "events",  T_USHORT, offsetof(PyGPollFD, pollfd.events),  RO },
-    { "revents", T_USHORT, offsetof(PyGPollFD, pollfd.revents), RO },
+    { "fd",      T_INT,    offsetof(PyGPollFD, pollfd.fd),      READONLY },
+    { "events",  T_USHORT, offsetof(PyGPollFD, pollfd.events),  READONLY },
+    { "revents", T_USHORT, offsetof(PyGPollFD, pollfd.revents), READONLY },
     { NULL, 0, 0, 0 }
 };
 
@@ -652,9 +652,9 @@
 static PyObject *
 pyg_poll_fd_repr(PyGPollFD *self)
 {
-    return PyString_FromFormat("<GPollFD %d (%d) at 0x%lx>",
-			       self->pollfd.fd, self->pollfd.events,
-			       (long)self);
+    return _PyUnicode_FromFormat("<GPollFD %d (%d) at 0x%lx>",
+				 self->pollfd.fd, self->pollfd.events,
+				 (long)self);
 }
 
 static int

Modified: trunk/glib/pygspawn.c
==============================================================================
--- trunk/glib/pygspawn.c	(original)
+++ trunk/glib/pygspawn.c	Sat Jul 26 14:04:48 2008
@@ -32,12 +32,12 @@
     PyObject *data;
 };
 
-PYGLIB_DEFINE_TYPE("glib.Pid", PyGPid_Type, PyIntObject)
+PYGLIB_DEFINE_TYPE("glib.Pid", PyGPid_Type, _PyLongObject)
 
 static PyObject *
-pyg_pid_close(PyIntObject *self, PyObject *args, PyObject *kwargs)
+pyg_pid_close(PyObject *self, PyObject *args, PyObject *kwargs)
 {
-    g_spawn_close_pid((GPid) self->ob_ival);
+    g_spawn_close_pid(_PyLong_AsLong(self));
     Py_INCREF(Py_None);
     return Py_None;
 }
@@ -48,10 +48,10 @@
 };
 
 static void
-pyg_pid_free(PyIntObject *gpid)
+pyg_pid_free(PyObject *gpid)
 {
-    g_spawn_close_pid((GPid) gpid->ob_ival);
-    PyInt_Type.tp_free((void *) gpid);
+    g_spawn_close_pid((GPid) _PyLong_AsLong(gpid));
+    _PyLong_Type.tp_free((void *) gpid);
 }
 
 static int
@@ -64,10 +64,14 @@
 PyObject *
 pyg_pid_new(GPid pid)
 {
-    PyIntObject *pygpid;
-    pygpid = PyObject_NEW(PyIntObject, &PyGPid_Type);
+    _PyLongObject *pygpid;
+    pygpid = PyObject_NEW(_PyLongObject, &PyGPid_Type);
 
+#if PY_VERSION_HEX >= 0x03000000
+#   warning "FIXME: figure out how to subclass long"    
+#else
     pygpid->ob_ival = pid;
+#endif    
     return (PyObject *) pygpid;
 }
 
@@ -145,7 +149,7 @@
     argv = g_new0(char *, len + 1);
     for (i = 0; i < len; ++i) {
         PyObject *tmp = PySequence_ITEM(pyargv, i);
-        if (!PyString_Check(tmp)) {
+        if (!_PyUnicode_Check(tmp)) {
             PyErr_SetString(PyExc_TypeError,
                             "glib.spawn_async: "
 			    "first argument must be a sequence of strings");
@@ -153,7 +157,7 @@
             Py_XDECREF(tmp);
             return NULL;
         }
-        argv[i] = PyString_AsString(tmp);
+        argv[i] = _PyUnicode_AsString(tmp);
         Py_DECREF(tmp);
     }
 
@@ -170,7 +174,7 @@
         envp = g_new0(char *, len + 1);
         for (i = 0; i < len; ++i) {
             PyObject *tmp = PySequence_ITEM(pyenvp, i);
-            if (!PyString_Check(tmp)) {
+            if (!_PyUnicode_Check(tmp)) {
                 PyErr_SetString(PyExc_TypeError,
                                 "glib.spawn_async: "
 				"second argument must be a sequence of strings");
@@ -179,7 +183,7 @@
 		g_free(argv);
                 return NULL;
             }
-            envp[i] = PyString_AsString(tmp);
+            envp[i] = _PyUnicode_AsString(tmp);
             Py_DECREF(tmp);
         }
     }
@@ -224,21 +228,21 @@
     if (envp) g_free(envp);
 
     if (standard_input)
-        pystdin = PyInt_FromLong(*standard_input);
+        pystdin = _PyLong_FromLong(*standard_input);
     else {
         Py_INCREF(Py_None);
         pystdin = Py_None;
     }
 
     if (standard_output)
-        pystdout = PyInt_FromLong(*standard_output);
+        pystdout = _PyLong_FromLong(*standard_output);
     else {
         Py_INCREF(Py_None);
         pystdout = Py_None;
     }
 
     if (standard_error)
-        pystderr = PyInt_FromLong(*standard_error);
+        pystderr = _PyLong_FromLong(*standard_error);
     else {
         Py_INCREF(Py_None);
         pystderr = Py_None;
@@ -250,7 +254,7 @@
 void
 pyglib_spawn_register_types(PyObject *d)
 {
-    PyGPid_Type.tp_base = &PyInt_Type;
+    PyGPid_Type.tp_base = &_PyLong_Type;
     PyGPid_Type.tp_flags = Py_TPFLAGS_DEFAULT;
     PyGPid_Type.tp_methods = pyg_pid_methods;
     PyGPid_Type.tp_init = pyg_pid_tp_init;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]