diff options
author | Simon van der Linden <svdlinden@src.gnome.org> | 2009-11-08 13:06:54 +0100 |
---|---|---|
committer | Simon van der Linden <svdlinden@src.gnome.org> | 2009-11-08 13:06:54 +0100 |
commit | ce673b9027868e6add4eeb438bc707eb40bfd046 (patch) | |
tree | 1668088a8c244591ebfd9384fb726f42dbd22a5e | |
parent | b24fd9633cabe1d95cde173a04e9a49833b06a26 (diff) | |
download | pygi-ce673b9027868e6add4eeb438bc707eb40bfd046.tar.gz pygi-ce673b9027868e6add4eeb438bc707eb40bfd046.tar.xz pygi-ce673b9027868e6add4eeb438bc707eb40bfd046.zip |
Add PyGObject patches
4 files changed, 431 insertions, 0 deletions
diff --git a/patches/0001-Make-GType.pytype-aware-of-the-interface-enum-flags-.patch b/patches/0001-Make-GType.pytype-aware-of-the-interface-enum-flags-.patch new file mode 100644 index 0000000..61bdddb --- /dev/null +++ b/patches/0001-Make-GType.pytype-aware-of-the-interface-enum-flags-.patch @@ -0,0 +1,78 @@ +From 421c03b1c5b69f90c778663df901b45ca3ee8ba5 Mon Sep 17 00:00:00 2001 +From: Simon van der Linden <svdlinden@src.gnome.org> +Date: Fri, 6 Nov 2009 19:17:36 +0100 +Subject: [PATCH 1/4] Make GType.pytype aware of the interface, enum, flags, pointer and boxed wrappers + +--- + gobject/pygtype.c | 39 +++++++++++++++++++++++++++++++++------ + 1 files changed, 33 insertions(+), 6 deletions(-) + +diff --git a/gobject/pygtype.c b/gobject/pygtype.c +index 601ea83..782e998 100644 +--- a/gobject/pygtype.c ++++ b/gobject/pygtype.c +@@ -70,12 +70,36 @@ pyg_type_wrapper_dealloc(PyGTypeWrapper *self) + PyObject_DEL(self); + } + ++static GQuark ++_pyg_type_key(GType type) { ++ GQuark key; ++ ++ if (g_type_is_a(type, G_TYPE_INTERFACE)) { ++ key = pyginterface_type_key; ++ } else if (g_type_is_a(type, G_TYPE_ENUM)) { ++ key = pygenum_class_key; ++ } else if (g_type_is_a(type, G_TYPE_FLAGS)) { ++ key = pygflags_class_key; ++ } else if (g_type_is_a(type, G_TYPE_POINTER)) { ++ key = pygpointer_class_key; ++ } else if (g_type_is_a(type, G_TYPE_BOXED)) { ++ key = pygboxed_type_key; ++ } else { ++ key = pygobject_class_key; ++ } ++ ++ return key; ++} ++ + static PyObject * + _wrap_g_type_wrapper__get_pytype(PyGTypeWrapper *self, void *closure) + { ++ GQuark key; + PyObject *py_type; +- +- py_type = g_type_get_qdata(self->type, pygobject_class_key); ++ ++ key = _pyg_type_key(self->type); ++ ++ py_type = g_type_get_qdata(self->type, key); + if (!py_type) + py_type = Py_None; + +@@ -86,15 +110,18 @@ _wrap_g_type_wrapper__get_pytype(PyGTypeWrapper *self, void *closure) + static int + _wrap_g_type_wrapper__set_pytype(PyGTypeWrapper *self, PyObject* value, void *closure) + { ++ GQuark key; + PyObject *py_type; +- +- py_type = g_type_get_qdata(self->type, pygobject_class_key); ++ ++ key = _pyg_type_key(self->type); ++ ++ py_type = g_type_get_qdata(self->type, key); + Py_CLEAR(py_type); + if (value == Py_None) +- g_type_set_qdata(self->type, pygobject_class_key, NULL); ++ g_type_set_qdata(self->type, key, NULL); + else if (PyType_Check(value)) { + Py_INCREF(value); +- g_type_set_qdata(self->type, pygobject_class_key, value); ++ g_type_set_qdata(self->type, key, value); + } else { + PyErr_SetString(PyExc_TypeError, "Value must be None or a type object"); + return -1; +-- +1.6.3.3 + diff --git a/patches/0002-Fix-girpository-build-setup.patch b/patches/0002-Fix-girpository-build-setup.patch new file mode 100644 index 0000000..9bff664 --- /dev/null +++ b/patches/0002-Fix-girpository-build-setup.patch @@ -0,0 +1,186 @@ +From bfd3100a580b8bea9db25b8bb7443fb8c3dbe1cc Mon Sep 17 00:00:00 2001 +From: Simon van der Linden <svdlinden@src.gnome.org> +Date: Sat, 7 Nov 2009 13:23:53 +0100 +Subject: [PATCH 2/4] Fix girpository build setup + +--- + configure.ac | 21 ++++++---- + girepository/Makefile.am | 13 +++--- + m4/introspection.m4 | 92 ++++++++++++++++++++++++++++++++++++++++++++++ + 3 files changed, 111 insertions(+), 15 deletions(-) + create mode 100644 m4/introspection.m4 + +diff --git a/configure.ac b/configure.ac +index 64aeaa5..0bf7610 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -200,14 +200,19 @@ if test -n "$export_dynamic"; then + GIOUNIX_LIBS=`echo $GIOUNIX_LIBS | sed -e "s/$export_dynamic//"` + fi + +-dnl gobject_introspection +-PKG_CHECK_MODULES(GOBJECT_INTROSPECTION, gobject-introspection-1.0 >= gobject_introspection_required_version, +- have_gobject_introspection=true, have_gobject_introspection=false) +-AC_SUBST(GOBJECT_INTROSPECTION_CFLAGS) +-AC_SUBST(GOBJECT_INTROSPECTION_LIBS) +-AM_CONDITIONAL(BUILD_GOBJECT_INTROSPECTION, $have_gobject_introspection) +-if test -n "$export_dynamic"; then +- GOBJECT_INTROSPECTION_LIBS=`echo $GOBJECT_INTROSPECTION_LIBS | sed -e "s/$export_dynamic//"` ++dnl gi ++AC_ARG_ENABLE(introspection, ++ AC_HELP_STRING([--enable-introspection], [Enable gobject-introspection bindings building]), ++ enable_introspection=$enableval, ++ enable_introspection=no) ++AM_CONDITIONAL(BUILD_GIREPOSITORY, test "$enable_introspection" != no) ++if test "$enable_introspection" != no; then ++ PKG_CHECK_MODULES(GOBJECT_INTROSPECTION, gobject-introspection-1.0 >= gobject_introspection_required_version) ++ AC_SUBST(GOBJECT_INTROSPECTION_CFLAGS) ++ AC_SUBST(GOBJECT_INTROSPECTION_LIBS) ++ if test -n "$export_dynamic"; then ++ GOBJECT_INTROSPECTION_LIBS=`echo $GOBJECT_INTROSPECTION_LIBS | sed -e "s/$export_dynamic//"` ++ fi + fi + + dnl add required cflags ... +diff --git a/girepository/Makefile.am b/girepository/Makefile.am +index c414652..8bdb462 100644 +--- a/girepository/Makefile.am ++++ b/girepository/Makefile.am +@@ -1,17 +1,16 @@ + AUTOMAKE_OPTIONS = 1.7 + PLATFORM_VERSION = 2.0 + ++pkgpyexecdir = $(pyexecdir)/gtk-2.0/girepository ++ ++if BUILD_GIREPOSITORY ++ + INCLUDES = \ + -I$(top_srcdir)/gobject \ + $(PYTHON_INCLUDES) \ + $(PYGOBJECT_CFLAGS) \ + $(GOBJECT_INTROSPECTION_CFLAGS) + +-pkginclude_HEADERS = bank.h +- +-# girepository extension modules +-pkgpyexecdir = $(pyexecdir)/gtk-2.0/girepository +- + # girepository python scripts + pygirepositorydir = $(pkgpyexecdir) + pygirepository_PYTHON = \ +@@ -44,7 +43,6 @@ repo_la_SOURCES = \ + bank.c \ + bank.h + +-if BUILD_GOBJECT_INTROSPECTION + pygirepository_LTLIBRARIES = repo.la + + all: $(pygirepository_LTLIBRARIES:.la=.so) +@@ -52,4 +50,5 @@ clean-local: + rm -f $(pygirepository_LTLIBRARIES:.la=.so) + .la.so: + $(LN_S) .libs/$@ $@ || true +-endif ++ ++endif # BUILD_GIREPOSITORY +diff --git a/m4/introspection.m4 b/m4/introspection.m4 +new file mode 100644 +index 0000000..6e2c565 +--- /dev/null ++++ b/m4/introspection.m4 +@@ -0,0 +1,92 @@ ++dnl -*- mode: autoconf -*- ++dnl Copyright 2009 Johan Dahlin ++dnl ++dnl This file is free software; the author(s) gives unlimited ++dnl permission to copy and/or distribute it, with or without ++dnl modifications, as long as this notice is preserved. ++dnl ++ ++# serial 1 ++ ++m4_define([_GOBJECT_INTROSPECTION_CHECK_INTERNAL], ++[ ++ AC_BEFORE([AC_PROG_LIBTOOL],[$0])dnl setup libtool first ++ AC_BEFORE([AM_PROG_LIBTOOL],[$0])dnl setup libtool first ++ AC_BEFORE([LT_INIT],[$0])dnl setup libtool first ++ ++ dnl enable/disable introspection ++ m4_if([$2], [require], ++ [dnl ++ enable_introspection=yes ++ ],[dnl ++ AC_ARG_ENABLE(introspection, ++ AS_HELP_STRING([--enable-introspection[=@<:@no/auto/yes@:>@]], ++ [Enable introspection for this build]),, ++ [enable_introspection=auto]) ++ ])dnl ++ ++ AC_MSG_CHECKING([for gobject-introspection]) ++ ++ dnl presence/version checking ++ AS_CASE([$enable_introspection], ++ [no], [dnl ++ found_introspection="no (disabled, use --enable-introspection to enable)" ++ ],dnl ++ [yes],[dnl ++ PKG_CHECK_EXISTS([gobject-introspection-1.0],, ++ AC_MSG_ERROR([gobject-introspection-1.0 is not installed])) ++ PKG_CHECK_EXISTS([gobject-introspection-1.0 >= $1], ++ found_introspection=yes, ++ AC_MSG_ERROR([You need to have gobject-introspection >= $1 installed to build AC_PACKAGE_NAME])) ++ ],dnl ++ [auto],[dnl ++ PKG_CHECK_EXISTS([gobject-introspection-1.0 >= $1], found_introspection=yes, found_introspection=no) ++ ],dnl ++ [dnl ++ AC_MSG_ERROR([invalid argument passed to --enable-introspection, should be one of @<:@no/auto/yes@:>@]) ++ ])dnl ++ ++ AC_MSG_RESULT([$found_introspection]) ++ ++ INTROSPECTION_SCANNER= ++ INTROSPECTION_COMPILER= ++ INTROSPECTION_GENERATE= ++ INTROSPECTION_GIRDIR= ++ INTROSPECTION_TYPELIBDIR= ++ if test "x$found_introspection" = "xyes"; then ++ INTROSPECTION_SCANNER=`$PKG_CONFIG --variable=g_ir_scanner gobject-introspection-1.0` ++ INTROSPECTION_COMPILER=`$PKG_CONFIG --variable=g_ir_compiler gobject-introspection-1.0` ++ INTROSPECTION_GENERATE=`$PKG_CONFIG --variable=g_ir_generate gobject-introspection-1.0` ++ INTROSPECTION_GIRDIR=`$PKG_CONFIG --variable=girdir gobject-introspection-1.0` ++ INTROSPECTION_TYPELIBDIR="$($PKG_CONFIG --variable=typelibdir gobject-introspection-1.0)" ++ INTROSPECTION_CFLAGS=`$PKG_CONFIG --cflags gobject-introspection-1.0` ++ INTROSPECTION_LIBS=`$PKG_CONFIG --libs gobject-introspection-1.0` ++ fi ++ AC_SUBST(INTROSPECTION_SCANNER) ++ AC_SUBST(INTROSPECTION_COMPILER) ++ AC_SUBST(INTROSPECTION_GENERATE) ++ AC_SUBST(INTROSPECTION_GIRDIR) ++ AC_SUBST(INTROSPECTION_TYPELIBDIR) ++ AC_SUBST(INTROSPECTION_CFLAGS) ++ AC_SUBST(INTROSPECTION_LIBS) ++ ++ AM_CONDITIONAL(HAVE_INTROSPECTION, test "x$found_introspection" = "xyes") ++]) ++ ++ ++dnl Usage: ++dnl GOBJECT_INTROSPECTION_CHECK([minimum-g-i-version]) ++ ++AC_DEFUN([GOBJECT_INTROSPECTION_CHECK], ++[ ++ _GOBJECT_INTROSPECTION_CHECK_INTERNAL([$1]) ++]) ++ ++dnl Usage: ++dnl GOBJECT_INTROSPECTION_REQUIRE([minimum-g-i-version]) ++ ++ ++AC_DEFUN([GOBJECT_INTROSPECTION_REQUIRE], ++[ ++ _GOBJECT_INTROSPECTION_CHECK_INTERNAL([$1], [require]) ++]) +-- +1.6.3.3 + diff --git a/patches/0003-Add-capabilities-to-import-wrappers-from-pygi.patch b/patches/0003-Add-capabilities-to-import-wrappers-from-pygi.patch new file mode 100644 index 0000000..6268592 --- /dev/null +++ b/patches/0003-Add-capabilities-to-import-wrappers-from-pygi.patch @@ -0,0 +1,138 @@ +From 91da6efa5457a17d94d1cf5c2e4e91da078da214 Mon Sep 17 00:00:00 2001 +From: Simon van der Linden <svdlinden@src.gnome.org> +Date: Sat, 7 Nov 2009 16:43:35 +0100 +Subject: [PATCH 3/4] Add capabilities to import wrappers from pygi + +At instance creation for boxed and pointers, at lookup for objects, +when the gtype has no wrapper yet, a wrapper may be imported from pygi. + +The feature is turned on at configure time by --enable-pygi. + +Because we couldn't create a circular build dependency, PyGI's import function and +API definition had to be copied in this tree. +--- + configure.ac | 8 ++++++++ + gobject/pygboxed.c | 14 ++++++++++++++ + gobject/pygobject.c | 14 ++++++++++++++ + gobject/pygpointer.c | 15 +++++++++++++++ + 4 files changed, 51 insertions(+), 0 deletions(-) + +diff --git a/configure.ac b/configure.ac +index 0bf7610..dc8dea6 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -215,6 +215,14 @@ if test "$enable_introspection" != no; then + fi + fi + ++AC_ARG_ENABLE(pygi, ++ AC_HELP_STRING([--enable-pygi], [Use PyGI to create wrappers for introspection-enabled types]), ++ enable_pygi=$enableval, ++ enable_pygi=no) ++if test "$enable_pygi" != no; then ++ AC_DEFINE(ENABLE_PYGI,1,Use PyGI to create wrappers for introspection-enabled types) ++fi ++ + dnl add required cflags ... + if test "x$GCC" = "xyes"; then + JH_ADD_CFLAG([-Wall]) +diff --git a/gobject/pygboxed.c b/gobject/pygboxed.c +index eb274a2..b9cf6b3 100644 +--- a/gobject/pygboxed.c ++++ b/gobject/pygboxed.c +@@ -28,6 +28,10 @@ + #include "pygobject-private.h" + #include "pygboxed.h" + ++#if ENABLE_PYGI ++# include "pygi-external.h" ++#endif ++ + GQuark pygboxed_type_key; + GQuark pygboxed_marshal_key; + +@@ -182,6 +186,16 @@ pyg_boxed_new(GType boxed_type, gpointer boxed, gboolean copy_boxed, + } + + tp = g_type_get_qdata(boxed_type, pygboxed_type_key); ++ ++#if ENABLE_PYGI ++ if (tp == NULL && _pygi_import() == 0) { ++ tp = (PyTypeObject *)pygi_type_import_by_g_type(boxed_type); ++ if (tp == NULL) { ++ PyErr_Clear(); ++ } ++ } ++#endif /* ENABLE_PYGI */ ++ + if (!tp) + tp = (PyTypeObject *)&PyGBoxed_Type; /* fallback */ + self = PyObject_NEW(PyGBoxed, tp); +diff --git a/gobject/pygobject.c b/gobject/pygobject.c +index b4274e1..19c90ff 100644 +--- a/gobject/pygobject.c ++++ b/gobject/pygobject.c +@@ -29,6 +29,10 @@ + #include "pyginterface.h" + #include "pygparamspec.h" + ++#if ENABLE_PYGI ++# include "pygi-external.h" ++#endif ++ + + static void pygobject_dealloc(PyGObject *self); + static int pygobject_traverse(PyGObject *self, visitproc visit, void *arg); +@@ -871,6 +875,16 @@ pygobject_lookup_class(GType gtype) + py_type = g_type_get_qdata(gtype, pygobject_class_key); + if (py_type == NULL) { + py_type = g_type_get_qdata(gtype, pyginterface_type_key); ++ ++#if ENABLE_PYGI ++ if (py_type == NULL && _pygi_import() == 0) { ++ py_type = (PyTypeObject *)pygi_type_import_by_g_type(gtype); ++ if (py_type == NULL) { ++ PyErr_Clear(); ++ } ++ } ++#endif /* ENABLE_PYGI */ ++ + if (py_type == NULL) { + py_type = pygobject_new_with_interfaces(gtype); + g_type_set_qdata(gtype, pyginterface_type_key, py_type); +diff --git a/gobject/pygpointer.c b/gobject/pygpointer.c +index ee0a8da..cdcb320 100644 +--- a/gobject/pygpointer.c ++++ b/gobject/pygpointer.c +@@ -28,6 +28,11 @@ + #include "pygobject-private.h" + #include "pygpointer.h" + ++#if ENABLE_PYGI ++# include "pygi-external.h" ++#endif ++ ++ + GQuark pygpointer_class_key; + + PYGLIB_DEFINE_TYPE("gobject.GPointer", PyGPointer_Type, PyGPointer); +@@ -155,6 +160,16 @@ pyg_pointer_new(GType pointer_type, gpointer pointer) + } + + tp = g_type_get_qdata(pointer_type, pygpointer_class_key); ++ ++#if ENABLE_PYGI ++ if (tp == NULL && _pygi_import() == 0) { ++ tp = (PyTypeObject *)pygi_type_import_by_g_type(pointer_type); ++ if (tp == NULL) { ++ PyErr_Clear(); ++ } ++ } ++#endif /* ENABLE_PYGI */ ++ + if (!tp) + tp = (PyTypeObject *)&PyGPointer_Type; /* fallback */ + self = PyObject_NEW(PyGPointer, tp); +-- +1.6.3.3 + diff --git a/patches/0004-Create-instances-by-calling-tp_alloc-rather-than-PyO.patch b/patches/0004-Create-instances-by-calling-tp_alloc-rather-than-PyO.patch new file mode 100644 index 0000000..d838e4d --- /dev/null +++ b/patches/0004-Create-instances-by-calling-tp_alloc-rather-than-PyO.patch @@ -0,0 +1,29 @@ +From 55390cf85f4c532a8e281cfd96d601b0ce62fb03 Mon Sep 17 00:00:00 2001 +From: Simon van der Linden <svdlinden@src.gnome.org> +Date: Sat, 7 Nov 2009 23:42:07 +0100 +Subject: [PATCH 4/4] Create instances by calling tp_alloc rather than PyObject_NEW + +PyObject_NEW calls a generic allocator and should only be called by tp_new, knowing +that the type's free function agrees. In pyg_boxed_new, we may allocate +PyGBoxed subtypes, so the subtype's allocation function must be called instead. +--- + gobject/pygboxed.c | 3 ++- + 1 files changed, 2 insertions(+), 1 deletions(-) + +diff --git a/gobject/pygboxed.c b/gobject/pygboxed.c +index b9cf6b3..220bf27 100644 +--- a/gobject/pygboxed.c ++++ b/gobject/pygboxed.c +@@ -198,7 +198,8 @@ pyg_boxed_new(GType boxed_type, gpointer boxed, gboolean copy_boxed, + + if (!tp) + tp = (PyTypeObject *)&PyGBoxed_Type; /* fallback */ +- self = PyObject_NEW(PyGBoxed, tp); ++ ++ self = (PyGBoxed *)tp->tp_alloc(tp, 0); + + if (self == NULL) { + pyglib_gil_state_release(state); +-- +1.6.3.3 + |