From c5b2a96bc9bf8332dc9026de7713e448df75e987 Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Thu, 26 Aug 2010 12:09:31 +0200 Subject: plugin: refactor the initialization code. Remove references to global python objects from the initialization code. This makes it possible to avoid linking to libpython. --- plugin/gstpythonplugin.c | 60 +++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/plugin/gstpythonplugin.c b/plugin/gstpythonplugin.c index f8b0d0d..0134f19 100644 --- a/plugin/gstpythonplugin.c +++ b/plugin/gstpythonplugin.c @@ -25,6 +25,7 @@ /* include this first, before NO_IMPORT_PYGOBJECT is defined */ #include #include +#include PyTypeObject *_PyGstElement_Type; #define PyGstElement_Type (*_PyGstElement_Type) @@ -40,35 +41,46 @@ static PyObject *element; static inline gboolean np_init_pygobject (void) { - PyObject *gobject = PyImport_ImportModule ("gobject"); - gboolean res = TRUE; - - if (gobject != NULL) { - PyObject *mdict = PyModule_GetDict (gobject); - PyObject *cobject = PyDict_GetItemString (mdict, "_PyGObject_API"); - if (PyCObject_Check (cobject)) { - _PyGObject_API = - (struct _PyGObject_Functions *) PyCObject_AsVoidPtr (cobject); - } else { - PyErr_SetString (PyExc_RuntimeError, - "could not find _PyGObject_API object"); - PyErr_Print (); - res = FALSE; - goto beach; - } - if (!(PyObject_CallMethod (gobject, "threads_init", NULL, NULL))) { - PyErr_SetString (PyExc_RuntimeError, "Could not initialize threads"); - PyErr_Print (); - res = FALSE; - goto beach; - } - } else { + gboolean res = FALSE; + PyObject *gobject = NULL; + PyObject *main_module = NULL; + PyObject *mdict = NULL; + + gobject = PyImport_ImportModule ("gobject"); + if (gobject == NULL) { PyErr_Print (); GST_WARNING ("could not import gobject"); - res = FALSE; + goto beach; + } + + main_module = PyImport_AddModule ("__main__"); + mdict = PyModule_GetDict (gobject); + + PyObject *cobject = PyDict_GetItemString (mdict, "_PyGObject_API"); + if (cobject == NULL) { + GST_WARNING ("could not find _PyGObject_API"); + goto beach; } + _PyGObject_API = + (struct _PyGObject_Functions *) PyCObject_AsVoidPtr (cobject); + if (_PyGObject_API == NULL) { + PyErr_Print (); + GST_WARNING ("_PyGObject_API is not a valid CObject"); + goto beach; + } + + if (!(PyObject_CallMethod (gobject, "threads_init", NULL, NULL))) { + PyErr_Print (); + GST_WARNING ("could not initialize threads"); + goto beach; + } + + res = TRUE; + beach: + Py_XDECREF (gobject); + return res; } -- cgit v1.2.3 From 9ee33ad3014b751ead5a1b0aa44b9c74458dac6d Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Thu, 26 Aug 2010 12:13:34 +0200 Subject: acinclude.m4: use a better way to find the correct PYTHON_LIB_LOC. --- acinclude.m4 | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index 4b9972c..25f27e6 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -73,8 +73,15 @@ AC_DEFUN([AM_CHECK_PYTHON_LIBS], AC_MSG_CHECKING(for libraries required to embed python) dnl deduce PYTHON_LIBS py_exec_prefix=`$PYTHON -c "import sys; print sys.exec_prefix"` -PYTHON_LIBS="-L${py_prefix}/lib -lpython${PYTHON_VERSION}" -PYTHON_LIB_LOC="${py_prefix}/lib" +if $PYTHON-config --help 2>/dev/null; then + PYTHON_LIBS=`$PYTHON-config --ldflags 2>/dev/null` + PYTHON_LIB=`$PYTHON -c "import distutils.sysconfig as s; print s.get_python_lib(standard_lib=1)"` + PYTHON_LIB_LOC=$PYTHON_LIB/config +else + asd + PYTHON_LIBS="-L${py_prefix}/lib -lpython${PYTHON_VERSION}" + PYTHON_LIB_LOC="${py_prefix}/lib" +fi AC_SUBST(PYTHON_LIBS) AC_SUBST(PYTHON_LIB_LOC) dnl check if the headers exist: -- cgit v1.2.3 From 53e5a77f527f40e4a16e1a00d574fb9f4f1c3c9e Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Thu, 26 Aug 2010 12:14:33 +0200 Subject: plugin: don't link to libpython --- plugin/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/Makefile.am b/plugin/Makefile.am index a8b6342..fc961a0 100644 --- a/plugin/Makefile.am +++ b/plugin/Makefile.am @@ -7,4 +7,4 @@ INCLUDES = $(PYGOBJECT_CFLAGS) $(GST_CFLAGS)\ libgstpython_la_SOURCES = gstpythonplugin.c libgstpython_la_LDFLAGS = -module -avoid-version -libgstpython_la_LIBADD = $(GST_LIBS) $(PYTHON_LIBS) +libgstpython_la_LIBADD = $(GST_LIBS) -- cgit v1.2.3