pygobject r781 - in branches/pygobject-2-14: . gobject tests



Author: johan
Date: Fri May 23 16:54:58 2008
New Revision: 781
URL: http://svn.gnome.org/viewvc/pygobject?rev=781&view=rev

Log:
2008-05-23  Johan Dahlin  <jdahlin async com br>

    Merge from trunk:

    * gobject/__init__.py:
    * tests/test_properties.py:
    Allow gobject.property work with subclasses. Add tests.
    (#523352, Tomeu Vizoso)

    * gobject/pygsource.c:
    * tests/test_source.py:
    Unbreak Source.prepare
    (#523075, Bryan Silverthorn)

    * gobject/gobjectmodule.c (REGISTER_TYPE): Never override customly
    set 'tp_new' and 'tp_alloc'.

    * configure.ac: Don't link against libffi if we cannot find libffi
    on the system.
    (#496006, Ed Catmur)

    * Makefile.am: Dist .m4 files.
    (#496011, Ed Catmur)

    * gobject/pygenum.c (pyg_enum_richcompare): Don't return NULL
    after warning; more useful warning message (bug #519631).



Modified:
   branches/pygobject-2-14/ChangeLog
   branches/pygobject-2-14/Makefile.am
   branches/pygobject-2-14/configure.ac
   branches/pygobject-2-14/gobject/__init__.py
   branches/pygobject-2-14/gobject/gobjectmodule.c
   branches/pygobject-2-14/gobject/pygenum.c
   branches/pygobject-2-14/gobject/pygsource.c
   branches/pygobject-2-14/tests/test_properties.py
   branches/pygobject-2-14/tests/test_source.py

Modified: branches/pygobject-2-14/Makefile.am
==============================================================================
--- branches/pygobject-2-14/Makefile.am	(original)
+++ branches/pygobject-2-14/Makefile.am	Fri May 23 16:54:58 2008
@@ -13,7 +13,10 @@
 	setup.py			\
 	pygobject_postinstall.py	\
 	pygtk.py			\
-	dsextras.py
+	dsextras.py			\
+	m4/as-ac-expand.m4		\
+	m4/jhflags.m4			\
+	m4/python.m4
 
 INCLUDES = $(PYTHON_INCLUDES) $(GLIB_CFLAGS) -I$(top_srcdir)/gobject
 

Modified: branches/pygobject-2-14/configure.ac
==============================================================================
--- branches/pygobject-2-14/configure.ac	(original)
+++ branches/pygobject-2-14/configure.ac	Fri May 23 16:54:58 2008
@@ -145,10 +145,33 @@
 
 dnl libffi
 AC_MSG_CHECKING(for ffi.h)
-AC_TRY_CPP([#include <ffi.h>], pygobject_ffi_h=yes, pygobject_ffi_h=no)
-if test $pygobject_ffi_h = yes; then
-   AC_DEFINE(HAVE_FFI_H,1,[Have ffi.h include file])
-   FFI_LIBS="-lffi"
+AC_ARG_WITH(libffi,
+  AC_HELP_STRING([--without-ffi], [Disable libffi support]),
+  with_ffi=$withval,
+  with_ffi=auto)
+if test x"$with_ffi" = xno ; then
+  pygobject_ffi_h=disabled
+else
+  AC_TRY_CPP([#include <ffi.h>], pygobject_ffi_h=yes, pygobject_ffi_h=no)
+  if test $pygobject_ffi_h = yes; then
+    AC_DEFINE(HAVE_FFI_H,1,[Have ffi.h include file])
+    save_LIBS=$LIBS
+    if test x"$with_ffi" = xyes || test x"$with_ffi" = xauto; then
+      other_LIBS=
+    else
+      other_LIBS=$with_ffi
+    fi
+    AC_SEARCH_LIBS(ffi_call,ffi,,AC_MSG_ERROR([libffi not found]),$other_LIBS)
+    if test x$"ac_cv_search_ffi_call" = x"none required" ; then
+      FFI_LIBS=$other_LIBS
+    else
+      FFI_LIBS="$ac_cv_search_ffi_call $other_LIBS"
+    fi
+    LIBS=$save_LIBS
+  fi
+fi
+if test x"$with_ffi" != xauto && test x"$pygobject_ffi_h" != xyes ; then
+  AC_MSG_ERROR([libffi requested, but ffi.h not found])
 fi
 AC_MSG_RESULT([$pygobject_ffi_h])
 AM_CONDITIONAL(HAVE_LIBFFI, test "$pygobject_ffi_h" = "yes")

Modified: branches/pygobject-2-14/gobject/__init__.py
==============================================================================
--- branches/pygobject-2-14/gobject/__init__.py	(original)
+++ branches/pygobject-2-14/gobject/__init__.py	Fri May 23 16:54:58 2008
@@ -57,15 +57,16 @@
 
         cls.__gproperties__ = gproperties
 
-        if (hasattr(cls, 'do_get_property') or
-            hasattr(cls, 'do_set_property')):
+        if ('do_get_property' in cls.__dict__ or
+            'do_set_property' in cls.__dict__):
             for prop in props:
                 if (prop.getter != prop._default_getter or
                     prop.setter != prop._default_setter):
                     raise TypeError(
                         "GObject subclass %r defines do_get/set_property"
                         " and it also uses a property which a custom setter"
-                        " or getter. This is not allowed" % (cls,))
+                        " or getter. This is not allowed" % (
+                        cls.__name__,))
 
         def obj_get_property(self, pspec):
             name = pspec.name.replace('-', '_')
@@ -92,7 +93,6 @@
             return
 
         type_register(cls, namespace.get('__gtype_name__'))
-
 _gobject._install_metaclass(GObjectMeta)
 
 del _gobject

Modified: branches/pygobject-2-14/gobject/gobjectmodule.c
==============================================================================
--- branches/pygobject-2-14/gobject/gobjectmodule.c	(original)
+++ branches/pygobject-2-14/gobject/gobjectmodule.c	Fri May 23 16:54:58 2008
@@ -3506,8 +3506,10 @@
 
 #define REGISTER_TYPE(d, type, name) \
     type.ob_type = &PyType_Type; \
-    type.tp_alloc = PyType_GenericAlloc; \
-    type.tp_new = PyType_GenericNew; \
+    if (!type.tp_alloc) \
+	type.tp_alloc = PyType_GenericAlloc; \
+    if (!type.tp_new) \
+	type.tp_new = PyType_GenericNew; \
     if (PyType_Ready(&type)) \
 	return; \
     PyDict_SetItemString(d, name, (PyObject *)&type);

Modified: branches/pygobject-2-14/gobject/pygenum.c
==============================================================================
--- branches/pygobject-2-14/gobject/pygenum.c	(original)
+++ branches/pygobject-2-14/gobject/pygenum.c	Fri May 23 16:54:58 2008
@@ -30,14 +30,17 @@
 static PyObject *
 pyg_enum_richcompare(PyGEnum *self, PyObject *other, int op)
 {
+    static char warning[256];
+
     if (!PyInt_Check(other)) {
 	Py_INCREF(Py_NotImplemented);
 	return Py_NotImplemented;
     }
 
     if (PyObject_TypeCheck(other, &PyGEnum_Type) && ((PyGEnum*)other)->gtype != self->gtype) {
-	PyErr_Warn(PyExc_Warning, "comparing different enum types");
-	return NULL;
+	g_snprintf(warning, sizeof(warning), "comparing different enum types: %s and %s",
+		   g_type_name(self->gtype), g_type_name(((PyGEnum*)other)->gtype));
+	PyErr_Warn(PyExc_Warning, warning);
     }
 
     return pyg_integer_richcompare((PyObject *)self, other, op);

Modified: branches/pygobject-2-14/gobject/pygsource.c
==============================================================================
--- branches/pygobject-2-14/gobject/pygsource.c	(original)
+++ branches/pygobject-2-14/gobject/pygsource.c	Fri May 23 16:54:58 2008
@@ -418,14 +418,12 @@
     }
 
     ret = PyObject_IsTrue(PyTuple_GET_ITEM(t, 0));
-
-    if (ret) {
 	*timeout = PyInt_AsLong(PyTuple_GET_ITEM(t, 1));
+
 	if (*timeout == -1 && PyErr_Occurred()) {
 	    ret = FALSE;
 	    goto bail;
 	}
-    }
 
     got_err = FALSE;
 

Modified: branches/pygobject-2-14/tests/test_properties.py
==============================================================================
--- branches/pygobject-2-14/tests/test_properties.py	(original)
+++ branches/pygobject-2-14/tests/test_properties.py	Fri May 23 16:54:58 2008
@@ -327,6 +327,41 @@
         b.prop1 = 20
         self.assertEquals(b.prop1, 20)
 
+    def testPropertySubclassCustomSetter(self):
+        # test for #523352
+        class A(GObject):
+            def get_first(self):
+                return 'first'
+            first = gobject.property(type=str, getter=get_first)
+
+        class B(A):
+            def get_second(self):
+                return 'second'
+            second = gobject.property(type=str, getter=get_second)
+
+        a = A()
+        self.assertEquals(a.first, 'first')
+        self.assertRaises(TypeError, setattr, a, 'first', 'foo')
+
+        b = B()
+        self.assertEquals(b.first, 'first')
+        self.assertRaises(TypeError, setattr, b, 'first', 'foo')
+        self.assertEquals(b.second, 'second')
+        self.assertRaises(TypeError, setattr, b, 'second', 'foo')
+
+    def testPropertySubclassCustomSetterError(self):
+        try:
+            class A(GObject):
+                def get_first(self):
+                    return 'first'
+                first = gobject.property(type=str, getter=get_first)
+
+                def do_get_property(self, pspec):
+                    pass
+        except TypeError:
+            pass
+        else:
+            raise AssertionError
 
 if __name__ == '__main__':
     unittest.main()

Modified: branches/pygobject-2-14/tests/test_source.py
==============================================================================
--- branches/pygobject-2-14/tests/test_source.py	(original)
+++ branches/pygobject-2-14/tests/test_source.py	Fri May 23 16:54:58 2008
@@ -62,5 +62,33 @@
 
         assert self.pos >= 0 and idle.count >= 0
 
+    def testSourcePrepare(self):
+        # this test may not terminate if prepare() is wrapped incorrectly
+        dispatched = [False]
+        loop = gobject.MainLoop()
+
+        class CustomTimeout(gobject.Source):
+            def prepare(self):
+                return (False, 10)
+
+            def check(self):
+                return True
+
+            def dispatch(self, callback, args):
+                dispatched[0] = True
+
+                loop.quit()
+
+                return False
+
+        source = CustomTimeout()
+
+        source.attach()
+        source.set_callback(dir)
+
+        loop.run()
+
+        assert dispatched[0]
+
 if __name__ == '__main__':
     unittest.main()



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