diff options
author | Hugo Parente Lima <hugo.pl@gmail.com> | 2010-12-29 10:55:43 -0200 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:12:51 -0300 |
commit | cbd6c033ab05df82613a98df8d90a6e2fcc0b597 (patch) | |
tree | 71c95f230f1993068bc9808d31fb64d5db9d18b9 /libshiboken | |
parent | 3cafad161b8688693a91b5fc31137a16dc9626a6 (diff) |
Put __file__ on argv only when a empty list is given.
Reviewer: Marcelo Lira <marcelo.lira@openbossa.org>
Renato Araújo <renato.filho@openbossa.org>
Diffstat (limited to 'libshiboken')
-rw-r--r-- | libshiboken/helper.cpp | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/libshiboken/helper.cpp b/libshiboken/helper.cpp index 50bf6941c..7359acf01 100644 --- a/libshiboken/helper.cpp +++ b/libshiboken/helper.cpp @@ -42,24 +42,32 @@ bool sequenceToArgcArgv(PyObject* argList, int* argc, char*** argv, const char* return false; } - *argc = numArgs + 1; + bool hasEmptyArgList = numArgs == 0; + if (hasEmptyArgList) + numArgs = 1; + + *argc = numArgs; *argv = new char*[*argc]; - for (int i = 0; i < numArgs; ++i) { - PyObject* item = PySequence_Fast_GET_ITEM(args.object(), i); - char* string; - if (PyUnicode_Check(item)) { - Shiboken::AutoDecRef utf8(PyUnicode_AsUTF8String(item)); - string = strdup(PyString_AS_STRING(utf8.object())); - } else { - string = strdup(PyString_AS_STRING(item)); + + if (hasEmptyArgList) { + // Try to get the script name + PyObject* globals = PyEval_GetGlobals(); + PyObject* appName = PyDict_GetItemString(globals, "__file__"); + (*argv)[0] = strdup(appName ? PyString_AS_STRING(appName) : defaultAppName); + } else { + for (int i = 0; i < numArgs; ++i) { + PyObject* item = PySequence_Fast_GET_ITEM(args.object(), i); + char* string; + if (PyUnicode_Check(item)) { + Shiboken::AutoDecRef utf8(PyUnicode_AsUTF8String(item)); + string = strdup(PyString_AS_STRING(utf8.object())); + } else { + string = strdup(PyString_AS_STRING(item)); + } + (*argv)[i] = string; } - (*argv)[i+1] = string; } - // Try to get the script name - PyObject* globals = PyEval_GetGlobals(); - PyObject* appName = PyDict_GetItemString(globals, "__file__"); - (*argv)[0] = strdup(appName ? PyString_AS_STRING(appName) : defaultAppName); return true; } |