diff options
author | Hugo Lima <hugo.lima@openbossa.org> | 2010-01-28 17:19:33 -0200 |
---|---|---|
committer | Hugo Lima <hugo.lima@openbossa.org> | 2010-01-28 17:36:50 -0200 |
commit | 22eb430cecf6ddc10eed04dd67c81485aba84ab6 (patch) | |
tree | 4ebaa0d9d6c99cfe0419cf53859fde63713b852b /libshiboken/helper.cpp | |
parent | 02cdcb7e0e49b22cd10a5146d5a85cec9bfca7bd (diff) |
Changed API for PySequence_to_argc_argv.
It was renamed to PySequenceToArgcArgv and a new argument was added, besides some documentation.
If the sequence is empty and defaultAppName (the new argument) was provided, argc will be 1 and
argv will have a copy of defaultAppName because some libraries, like Qt, need at least one element
in argv (the application name), otherwise it'll crash somewhere inside Qt.
Reviewed by Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'libshiboken/helper.cpp')
-rw-r--r-- | libshiboken/helper.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/libshiboken/helper.cpp b/libshiboken/helper.cpp index e1f23867d..4523a2059 100644 --- a/libshiboken/helper.cpp +++ b/libshiboken/helper.cpp @@ -38,19 +38,22 @@ namespace Shiboken { bool -PySequence_to_argc_argv(PyObject* argList, int* argc, char*** argv) +PySequenceToArgcArgv(PyObject* argList, int* argc, char*** argv, const char* defaultAppName) { if (!PySequence_Check(argList)) return false; + // Check all items int numArgs = PySequence_Size(argList); for (int i = 0; i < numArgs; ++i) if (!PyString_Check(PySequence_GetItem(argList, i))) return false; - *argc = (int) PySequence_Size(argList); + bool addAppName = !numArgs && defaultAppName; + *argc = addAppName ? 1 : numArgs; + *argv = new char*[*argc]; - for (int i = 0; i < *argc; ++i) { + for (int i = 0; i < numArgs; ++i) { PyObject* item = PySequence_GetItem(argList, i); char* string = PyString_AS_STRING(item); int size = strlen(string); @@ -58,6 +61,11 @@ PySequence_to_argc_argv(PyObject* argList, int* argc, char*** argv) (*argv)[i] = strcpy((*argv)[i], string); Py_DECREF(item); } + + if (addAppName) { + (*argv)[0] = new char[strlen(defaultAppName)+1]; + (*argv)[0] = strcpy((*argv)[0], defaultAppName); + } return true; } |