diff options
author | Johan Dahlin <jdahlin@async.com.br> | 2008-05-23 16:54:58 +0000 |
---|---|---|
committer | Johan Dahlin <johan@src.gnome.org> | 2008-05-23 16:54:58 +0000 |
commit | a1c2bc60bd137b0faecb75a22f8c96c952c4ada4 (patch) | |
tree | 9c89705e7632e3579bbc68890da086a493f0e810 | |
parent | 4689542d67328249508d78bc463866cd2a20fe34 (diff) | |
download | pygobject-a1c2bc60bd137b0faecb75a22f8c96c952c4ada4.tar.gz |
Merge from trunk:
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).
svn path=/branches/pygobject-2-14/; revision=781
-rw-r--r-- | ChangeLog | 29 | ||||
-rw-r--r-- | Makefile.am | 5 | ||||
-rw-r--r-- | configure.ac | 31 | ||||
-rw-r--r-- | gobject/__init__.py | 8 | ||||
-rw-r--r-- | gobject/gobjectmodule.c | 6 | ||||
-rw-r--r-- | gobject/pygenum.c | 7 | ||||
-rw-r--r-- | gobject/pygsource.c | 4 | ||||
-rw-r--r-- | tests/test_properties.py | 35 | ||||
-rw-r--r-- | tests/test_source.py | 28 |
9 files changed, 136 insertions, 17 deletions
@@ -1,3 +1,30 @@ +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). + 2008-01-03 Johan Dahlin <johan@gnome.org> * configure.ac: Post release version bump @@ -43,7 +70,7 @@ 2007-08-27 Johan Dahlin <jdahlin@async.com.br> * gobject/propertyhelper.py (property.__metaclass__.__repr__): Avoid - exporting the metaclass, just define it in the class. + exporting the metaclass, just define it where it will be used. * gobject/__init__.py (GObjectMeta._install_properties): Refactor a bit to make sure that it is possible to use in subclasses, diff --git a/Makefile.am b/Makefile.am index 965f1d9d..824027fe 100644 --- a/Makefile.am +++ b/Makefile.am @@ -13,7 +13,10 @@ EXTRA_DIST = \ 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 diff --git a/configure.ac b/configure.ac index f0906aba..bdbd54b3 100644 --- a/configure.ac +++ b/configure.ac @@ -145,10 +145,33 @@ AS_AC_EXPAND(DATADIR, $datadir) 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") diff --git a/gobject/__init__.py b/gobject/__init__.py index c1404f91..488d87ed 100644 --- a/gobject/__init__.py +++ b/gobject/__init__.py @@ -57,15 +57,16 @@ class GObjectMeta(type): 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 @@ class GObjectMeta(type): return type_register(cls, namespace.get('__gtype_name__')) - _gobject._install_metaclass(GObjectMeta) del _gobject diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c index 4881120a..9d304493 100644 --- a/gobject/gobjectmodule.c +++ b/gobject/gobjectmodule.c @@ -3506,8 +3506,10 @@ struct _PyGObject_Functions pygobject_api_functions = { #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); diff --git a/gobject/pygenum.c b/gobject/pygenum.c index 543bc49d..876e4644 100644 --- a/gobject/pygenum.c +++ b/gobject/pygenum.c @@ -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); diff --git a/gobject/pygsource.c b/gobject/pygsource.c index 900bd4f9..9e831e5a 100644 --- a/gobject/pygsource.c +++ b/gobject/pygsource.c @@ -418,14 +418,12 @@ pyg_source_prepare(GSource *source, gint *timeout) } 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; diff --git a/tests/test_properties.py b/tests/test_properties.py index de93f624..a691b329 100644 --- a/tests/test_properties.py +++ b/tests/test_properties.py @@ -327,6 +327,41 @@ class TestProperty(unittest.TestCase): 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() diff --git a/tests/test_source.py b/tests/test_source.py index 5e0f01b7..fd5f310e 100644 --- a/tests/test_source.py +++ b/tests/test_source.py @@ -62,5 +62,33 @@ class TestSource(unittest.TestCase): 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() |