From 9d1891d51968b7c5ac7928df0207c1b1e7800728 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Fri, 23 Mar 2018 14:33:07 +0100 Subject: [PATCH] Rename pyglib-python-compat.h to pygi-python-compat.h There is no pyglib anymore --- gi/Makefile.am | 3 +- gi/gimodule.c | 3 +- gi/pygenum.c | 2 +- gi/pygenum.h | 2 +- gi/pygi-argument.c | 2 +- gi/pygi-array.c | 2 +- gi/pygi-basictype.c | 3 +- gi/pygi-boxed.c | 2 +- gi/pygi-cache.c | 2 +- gi/pygi-ccallback.c | 2 +- gi/pygi-enum-marshal.c | 2 +- gi/pygi-error.c | 2 +- gi/pygi-foreign-cairo.c | 2 +- gi/pygi-info.c | 4 +-- gi/pygi-object.c | 2 +- gi/pygi-python-compat.c | 33 ++++++++++++++++++++++ ...pyglib-python-compat.h => pygi-python-compat.h} | 18 +----------- gi/pygi-repository.c | 3 +- gi/pygi-resulttuple.c | 2 +- gi/pygi-source.c | 2 +- gi/pygi-struct-marshal.c | 2 +- gi/pygi-struct.c | 2 +- gi/pygi-type.c | 3 +- gi/pygi-util.h | 2 +- gi/pygi-value.c | 2 +- gi/pyginterface.c | 2 +- gi/pygobject-object.h | 2 +- gi/pygspawn.c | 2 +- tests/testhelpermodule.c | 2 +- 29 files changed, 62 insertions(+), 50 deletions(-) create mode 100644 gi/pygi-python-compat.c rename gi/{pyglib-python-compat.h => pygi-python-compat.h} (94%) diff --git a/gi/Makefile.am b/gi/Makefile.am index 53dcd433..404f429d 100644 --- a/gi/Makefile.am +++ b/gi/Makefile.am @@ -58,7 +58,8 @@ _gi_la_SOURCES = \ pygoptiongroup.h \ pygspawn.c \ pygspawn.h \ - pyglib-python-compat.h \ + pygi-python-compat.c \ + pygi-python-compat.h \ gimodule.c \ pygi-repository.c \ pygi-repository.h \ diff --git a/gi/gimodule.c b/gi/gimodule.c index 85b61b9e..0a8316cc 100644 --- a/gi/gimodule.c +++ b/gi/gimodule.c @@ -52,8 +52,7 @@ #include "pygi-property.h" #include "pygi-util.h" #include "gimodule.h" - -#include +#include "pygi-python-compat.h" PyObject *PyGIWarning; PyObject *PyGIDeprecationWarning; diff --git a/gi/pygenum.c b/gi/pygenum.c index 2438d86e..127e1bea 100644 --- a/gi/pygenum.c +++ b/gi/pygenum.c @@ -21,7 +21,7 @@ #include -#include "pyglib-python-compat.h" +#include "pygi-python-compat.h" #include "pygi-type.h" #include "pygi-util.h" diff --git a/gi/pygenum.h b/gi/pygenum.h index ca1fd79a..35d23118 100644 --- a/gi/pygenum.h +++ b/gi/pygenum.h @@ -20,7 +20,7 @@ #ifndef __PYGOBJECT_ENUM_H__ #define __PYGOBJECT_ENUM_H__ -#include "pyglib-python-compat.h" +#include "pygi-python-compat.h" extern GQuark pygenum_class_key; diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c index 040c1e76..4fa970c6 100644 --- a/gi/pygi-argument.c +++ b/gi/pygi-argument.c @@ -26,10 +26,10 @@ #include "pygobject-internal.h" -#include #include #include +#include "pygi-python-compat.h" #include "pygi-argument.h" #include "pygi-info.h" #include "pygi-value.h" diff --git a/gi/pygi-array.c b/gi/pygi-array.c index 7cd3689a..9982acaf 100644 --- a/gi/pygi-array.c +++ b/gi/pygi-array.c @@ -20,8 +20,8 @@ #include #include -#include +#include "pygi-python-compat.h" #include "pygi-array.h" #include "pygi-info.h" #include "pygi-marshal-cleanup.h" diff --git a/gi/pygi-basictype.c b/gi/pygi-basictype.c index cc4899ec..fd8e4974 100644 --- a/gi/pygi-basictype.c +++ b/gi/pygi-basictype.c @@ -19,8 +19,7 @@ */ #include -#include - +#include "pygi-python-compat.h" #include "pygtype.h" #include "pygi-basictype.h" #include "pygi-argument.h" diff --git a/gi/pygi-boxed.c b/gi/pygi-boxed.c index 599d6d3e..6832a7b6 100644 --- a/gi/pygi-boxed.c +++ b/gi/pygi-boxed.c @@ -23,9 +23,9 @@ #include "pygi-info.h" #include "pygboxed.h" #include "pygtype.h" +#include "pygi-python-compat.h" #include -#include static void _boxed_dealloc (PyGIBoxed *self) diff --git a/gi/pygi-cache.c b/gi/pygi-cache.c index 4bdee1b3..e51a7563 100644 --- a/gi/pygi-cache.c +++ b/gi/pygi-cache.c @@ -21,7 +21,7 @@ #include #include -#include "pyglib-python-compat.h" +#include "pygi-python-compat.h" #include "pygtype.h" #include "pygi-info.h" #include "pygi-cache.h" diff --git a/gi/pygi-ccallback.c b/gi/pygi-ccallback.c index 3fe5366a..5c0823a7 100644 --- a/gi/pygi-ccallback.c +++ b/gi/pygi-ccallback.c @@ -19,10 +19,10 @@ * License along with this library; if not, see . */ +#include "pygi-python-compat.h" #include "pygi-ccallback.h" #include -#include static PyObject * diff --git a/gi/pygi-enum-marshal.c b/gi/pygi-enum-marshal.c index fe6c7d72..dc36dfe3 100644 --- a/gi/pygi-enum-marshal.c +++ b/gi/pygi-enum-marshal.c @@ -20,8 +20,8 @@ #include #include -#include +#include "pygi-python-compat.h" #include "pygi-enum-marshal.h" #include "pygi-type.h" #include "pygenum.h" diff --git a/gi/pygi-error.c b/gi/pygi-error.c index 862cf527..eb35991b 100644 --- a/gi/pygi-error.c +++ b/gi/pygi-error.c @@ -22,7 +22,7 @@ #include "pygi-error.h" #include "pygtype.h" -#include +#include "pygi-python-compat.h" PyObject *PyGError = NULL; diff --git a/gi/pygi-foreign-cairo.c b/gi/pygi-foreign-cairo.c index b2ec9fc5..03ee05a5 100644 --- a/gi/pygi-foreign-cairo.c +++ b/gi/pygi-foreign-cairo.c @@ -38,7 +38,7 @@ static Pycairo_CAPI_t *Pycairo_CAPI; * shared library that interacts with PyGI through a PyCapsule API at runtime. */ #include -#include +#include "pygi-python-compat.h" /* * cairo_t marshaling diff --git a/gi/pygi-info.c b/gi/pygi-info.c index e46f6007..d7338f43 100644 --- a/gi/pygi-info.c +++ b/gi/pygi-info.c @@ -20,6 +20,7 @@ * License along with this library; if not, see . */ +#include "pygi-python-compat.h" #include "pygi-info.h" #include "pygi-cache.h" #include "pygi-invoke.h" @@ -28,9 +29,6 @@ #include "pygi-util.h" #include "pygtype.h" -#include - - /* _generate_doc_string * * C wrapper to call Python implemented "gi.docstring.generate_doc_string" diff --git a/gi/pygi-object.c b/gi/pygi-object.c index 80c90555..07fd5995 100644 --- a/gi/pygi-object.c +++ b/gi/pygi-object.c @@ -20,8 +20,8 @@ #include #include -#include +#include "pygi-python-compat.h" #include "pygi-object.h" #include "pygobject-object.h" #include "pygparamspec.h" diff --git a/gi/pygi-python-compat.c b/gi/pygi-python-compat.c new file mode 100644 index 00000000..4a7b8b7f --- /dev/null +++ b/gi/pygi-python-compat.c @@ -0,0 +1,33 @@ +/* + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#include "pygi-python-compat.h" + +/* Better alternative to PyImport_ImportModule which tries to import from + * sys.modules first */ +PyObject * +PYGLIB_PyImport_ImportModule(const char *name) +{ +#if PY_VERSION_HEX < 0x03000000 + /* see PyImport_ImportModuleNoBlock + * https://github.com/python/cpython/blob/2.7/Python/import.c#L2166-L2206 */ + PyObject *result = PyImport_ImportModuleNoBlock(name); + if (result) + return result; + + PyErr_Clear(); +#endif + return PyImport_ImportModule(name); +} diff --git a/gi/pyglib-python-compat.h b/gi/pygi-python-compat.h similarity index 94% rename from gi/pyglib-python-compat.h rename to gi/pygi-python-compat.h index cf0ebb4e..1e8e6979 100644 --- a/gi/pyglib-python-compat.h +++ b/gi/pygi-python-compat.h @@ -33,6 +33,7 @@ # define PYGLIB_CPointer_Import(module, symbol) \ PyCapsule_Import(##module##.##symbol##, FALSE) +PyObject * PYGLIB_PyImport_ImportModule(const char *name); #define PYGLIB_MODULE_ERROR_RETURN NULL @@ -121,21 +122,6 @@ PyTypeObject symbol = { \ return; \ PyDict_SetItemString(d, name, (PyObject *)&type); -/* Better alternative to PyImport_ImportModule which tries to import from - * sys.modules first */ -static inline PyObject * -PYGLIB_PyImport_ImportModule(const char *name) -{ - /* see PyImport_ImportModuleNoBlock - * https://github.com/python/cpython/blob/2.7/Python/import.c#L2166-L2206 */ - PyObject *result = PyImport_ImportModuleNoBlock(name); - if (result) - return result; - - PyErr_Clear(); - return PyImport_ImportModule(name); -} - #else #define PYGLIB_MODULE_START(symbol, modname) \ @@ -178,8 +164,6 @@ PyTypeObject symbol = { \ return; \ PyDict_SetItemString(d, name, (PyObject *)&type); -#define PYGLIB_PyImport_ImportModule PyImport_ImportModule - #define PYGLIB_PyBaseString_Check PyUnicode_Check #define PYGLIB_PyUnicode_Check PyUnicode_Check diff --git a/gi/pygi-repository.c b/gi/pygi-repository.c index 62ef3b60..e9e0068b 100644 --- a/gi/pygi-repository.c +++ b/gi/pygi-repository.c @@ -21,8 +21,7 @@ #include "pygi-repository.h" #include "pygi-info.h" - -#include +#include "pygi-python-compat.h" PyObject *PyGIRepositoryError; diff --git a/gi/pygi-resulttuple.c b/gi/pygi-resulttuple.c index a8c20325..98590896 100644 --- a/gi/pygi-resulttuple.c +++ b/gi/pygi-resulttuple.c @@ -19,7 +19,7 @@ #include #include "pygi-resulttuple.h" -#include "pyglib-python-compat.h" +#include "pygi-python-compat.h" static char repr_format_key[] = "__repr_format"; static char tuple_indices_key[] = "__tuple_indices"; diff --git a/gi/pygi-source.c b/gi/pygi-source.c index 23082788..67729bec 100644 --- a/gi/pygi-source.c +++ b/gi/pygi-source.c @@ -23,7 +23,7 @@ * IN THE SOFTWARE. */ -#include "pyglib-python-compat.h" +#include "pygi-python-compat.h" #include "pygi-info.h" #include "pygi-boxed.h" #include "pygi-type.h" diff --git a/gi/pygi-struct-marshal.c b/gi/pygi-struct-marshal.c index 75896a86..3c3bdfc6 100644 --- a/gi/pygi-struct-marshal.c +++ b/gi/pygi-struct-marshal.c @@ -20,8 +20,8 @@ #include #include -#include +#include "pygi-python-compat.h" #include "pygi-struct-marshal.h" #include "pygi-struct.h" #include "pygi-foreign.h" diff --git a/gi/pygi-struct.c b/gi/pygi-struct.c index e2906e0a..8de342c3 100644 --- a/gi/pygi-struct.c +++ b/gi/pygi-struct.c @@ -25,9 +25,9 @@ #include "pygi-type.h" #include "pygtype.h" #include "pygpointer.h" +#include "pygi-python-compat.h" #include -#include static GIBaseInfo * diff --git a/gi/pygi-type.c b/gi/pygi-type.c index 9561c432..338fcc1f 100644 --- a/gi/pygi-type.c +++ b/gi/pygi-type.c @@ -21,8 +21,7 @@ #include "pygtype.h" #include "pygi-type.h" - -#include +#include "pygi-python-compat.h" PyObject * diff --git a/gi/pygi-util.h b/gi/pygi-util.h index c9cdb77b..2c00ce42 100644 --- a/gi/pygi-util.h +++ b/gi/pygi-util.h @@ -4,7 +4,7 @@ #include #include #include "pygobject-internal.h" -#include +#include "pygi-python-compat.h" G_BEGIN_DECLS diff --git a/gi/pygi-value.c b/gi/pygi-value.c index 2a40aaa2..bfeadf31 100644 --- a/gi/pygi-value.c +++ b/gi/pygi-value.c @@ -19,7 +19,7 @@ #include #include "pygi-value.h" #include "pygi-struct.h" -#include "pyglib-python-compat.h" +#include "pygi-python-compat.h" #include "pygobject-object.h" #include "pygtype.h" #include "pygenum.h" diff --git a/gi/pyginterface.c b/gi/pyginterface.c index 87c6e4ce..c9df2e47 100644 --- a/gi/pyginterface.c +++ b/gi/pyginterface.c @@ -22,8 +22,8 @@ #include #include -#include "pyglib-python-compat.h" +#include "pygi-python-compat.h" #include "pyginterface.h" #include "pygtype.h" diff --git a/gi/pygobject-object.h b/gi/pygobject-object.h index 70315289..d38837e4 100644 --- a/gi/pygobject-object.h +++ b/gi/pygobject-object.h @@ -3,7 +3,7 @@ #include #include -#include "pyglib-python-compat.h" +#include "pygi-python-compat.h" #include "pygobject-internal.h" /* Data that belongs to the GObject instance, not the Python wrapper */ diff --git a/gi/pygspawn.c b/gi/pygspawn.c index 1c70b362..9405571a 100644 --- a/gi/pygspawn.c +++ b/gi/pygspawn.c @@ -22,7 +22,7 @@ #include #include -#include "pyglib-python-compat.h" +#include "pygi-python-compat.h" #include "pygspawn.h" #include "pygi-error.h" diff --git a/tests/testhelpermodule.c b/tests/testhelpermodule.c index c5dfd4e9..0975bc44 100644 --- a/tests/testhelpermodule.c +++ b/tests/testhelpermodule.c @@ -5,7 +5,7 @@ #include "test-unknown.h" #include "test-floating.h" -#include +#include "pygi-python-compat.h" static PyObject * _wrap_TestInterface__do_iface_method(PyObject *cls, PyObject *args, -- 2.11.4.GIT