diff options
author | Sebastian Dröge <slomo@circular-chaos.org> | 2013-09-30 12:45:59 +0200 |
---|---|---|
committer | Sebastian Dröge <slomo@circular-chaos.org> | 2013-09-30 12:45:59 +0200 |
commit | 46cab502efed860a605120b157e4daf850e19d9f (patch) | |
tree | 6d625e1ef2e106c9c8ed0d853ca32ef916566964 /gi | |
parent | cbc99d041a37fc758461ad9ee9b8e1c6caa7c36b (diff) |
Fix compilation with Python 3.0
Changes partially taken from pygobject.
Diffstat (limited to 'gi')
-rw-r--r-- | gi/overrides/gstmodule.c | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/gi/overrides/gstmodule.c b/gi/overrides/gstmodule.c index 5202a0e..ae4fe49 100644 --- a/gi/overrides/gstmodule.c +++ b/gi/overrides/gstmodule.c @@ -32,12 +32,34 @@ #include <locale.h> +#if PY_MAJOR_VERSION >= 3 +#define PYGLIB_MODULE_START(symbol, modname) \ + static struct PyModuleDef _##symbol##module = { \ + PyModuleDef_HEAD_INIT, \ + modname, \ + NULL, \ + -1, \ + symbol##_functions, \ + NULL, \ + NULL, \ + NULL, \ + NULL \ +}; \ +PyMODINIT_FUNC PyInit_##symbol(void); \ +PyMODINIT_FUNC PyInit_##symbol(void) \ +{ \ + PyObject *module; \ + module = PyModule_Create(&_##symbol##module); +#define PYGLIB_MODULE_END return module; } +#else #define PYGLIB_MODULE_START(symbol, modname) \ +DL_EXPORT(void) init##symbol(void); \ DL_EXPORT(void) init##symbol(void) \ { \ PyObject *module; \ module = Py_InitModule(modname, symbol##_functions); #define PYGLIB_MODULE_END } +#endif GST_DEBUG_CATEGORY_STATIC (python_debug); GST_DEBUG_CATEGORY_STATIC (pygst_debug); @@ -227,15 +249,36 @@ pygst_debug_log (PyObject * pyobject, PyObject * string, GstDebugLevel level, } frame = PyEval_GetFrame (); - function = PyString_AsString (frame->f_code->co_name); +#if PY_MAJOR_VERSION >= 3 + { + PyObject *utf8; + const gchar *utf8_str; + + utf8 = PyUnicode_AsUTF8String (frame->f_code->co_name); + utf8_str = PyBytes_AS_STRING (utf8); + + function = g_strdup (utf8_str); + Py_DECREF (utf8); + + utf8 = PyUnicode_AsUTF8String (frame->f_code->co_filename); + utf8_str = PyBytes_AS_STRING (utf8); + + filename = g_strdup (utf8_str); + Py_DECREF (utf8); + } +#else + function = g_strdup (PyString_AsString (frame->f_code->co_name)); filename = g_path_get_basename (PyString_AsString (frame->f_code->co_filename)); +#endif lineno = PyCode_Addr2Line (frame->f_code, frame->f_lasti); /* gst_debug_log : category, level, file, function, line, object, format, va_list */ if (isgstobject) object = G_OBJECT (pygobject_get (pyobject)); gst_debug_log (python_debug, level, filename, function, lineno, object, "%s", str); + if (function) + g_free (function); if (filename) g_free (filename); #endif |