Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions _prctlmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,8 @@ prctl_prctl(PyObject *self, PyObject *args)
* encoded copy of it. We try to find the real one by going back from the start
* of environ.
*/
static char * encode(wchar_t *wstr) {
static PyObject * encode(wchar_t *wstr) {
PyObject *unicodestr = NULL, *bytesstr = NULL;
char *str = NULL;

unicodestr = PyUnicode_FromWideChar(wstr, -1);
if(!unicodestr) {
Expand All @@ -443,16 +442,15 @@ static char * encode(wchar_t *wstr) {
return NULL;
}

str = PyBytes_AsString(bytesstr);
Py_XDECREF(unicodestr);
Py_XDECREF(bytesstr);
return str;
return bytesstr;
}

static int _Py_GetArgcArgv(int* argc, char ***argv) {
int i = 0;
wchar_t **argv_w;
char **buf = NULL , *arg0 = NULL, *ptr = 0, *limit = NULL;
PyObject *bytesstr = NULL;

Py_GetArgcArgv(argc, &argv_w);
if (*argc < 1 || argv_w == NULL) {
Expand All @@ -476,17 +474,20 @@ static int _Py_GetArgcArgv(int* argc, char ***argv) {
}

/* Now try to find argv[0] */
arg0 = encode(argv_w[0]);
bytesstr = encode(argv_w[0]);
arg0 = PyBytes_AsString(bytesstr);
if(!arg0) {
free(buf);
return 0;
}
ptr -= strlen(arg0);
if(strcmp(ptr, arg0)) {
Py_XDECREF(bytesstr);
free(buf);
return 0;
}

Py_XDECREF(bytesstr);
buf[0] = ptr;
*argv = buf;
return 1;
Expand Down