qulogic/gplugin

Require python >= 3.5.0 and replace mbstowcs with Py_DecodeLocale
feature/python-fixes
2020-02-03, Gary Kramlich
3deb288f68f6
Parents 541abadf58b2
Children c7744f9017bd
Require python >= 3.5.0 and replace mbstowcs with Py_DecodeLocale
--- a/python/gplugin-python-loader.c Mon Feb 03 20:31:14 2020 -0600
+++ b/python/gplugin-python-loader.c Mon Feb 03 20:47:58 2020 -0600
@@ -311,43 +311,23 @@
static gboolean
gplugin_python_loader_init_python(void) {
- const gchar *program = NULL;
wchar_t *argv[] = { NULL, NULL };
- size_t len;
/* Initializes Python */
if(!Py_IsInitialized())
Py_InitializeEx(FALSE);
- program = g_get_prgname();
- program = program ? program : "";
- len = mbstowcs(NULL, program, 0);
- if(len == (size_t)-1) {
+ argv[0] = Py_DecodeLocale(g_get_prgname(), NULL);
+ if(argv[0] == NULL) {
g_warning("Could not convert program name to wchar_t string.");
return FALSE;
}
- argv[0] = g_new(wchar_t, len + 1);
- len = mbstowcs(argv[0], program, len + 1);
- if(len == (size_t)-1) {
- g_warning("Could not convert program name to wchar_t string.");
-
- g_free(argv[0]);
-
- return FALSE;
- }
-
/* setup sys.path according to
* https://docs.python.org/3/c-api/init.html#PySys_SetArgvEx
*/
-#if PY_VERSION_HEX < 0x03010300
- PySys_SetArgv(1, argv);
- PyRun_SimpleString("import sys; sys.path.pop(0)\n");
- g_free(argv[0]);
-#else
PySys_SetArgvEx(1, argv, 0);
- g_free(argv[0]);
-#endif
+ PyMem_RawFree(argv[0]);
/* initialize pygobject */
if(gplugin_python_loader_init_pygobject()) {
--- a/python/meson.build Mon Feb 03 20:31:14 2020 -0600
+++ b/python/meson.build Mon Feb 03 20:47:58 2020 -0600
@@ -16,12 +16,12 @@
'gplugin-python-utils.h',
]
- PYTHON3 = dependency('python3-embed', required: false)
+ PYTHON3 = dependency('python3-embed', version: '>=3.5.0', required: false)
if not PYTHON3.found()
- PYTHON3 = dependency('python3')
+ PYTHON3 = dependency('python3', version: '>=3.5.0')
endif
- PYGOBJECT = dependency('pygobject-3.0', version : '>=3.0.0')
+ PYGOBJECT = dependency('pygobject-3.0', version: '>=3.0.0')
# Compile and run our python-gi test program
python_gi_test = compiler.run(files('gplugin-python-test-pygobject.c'),