Skip to content

Commit 5cf3962

Browse files
authored
Merge pull request unbit#2720 from xrmx/backports-1143fix
plugins/python: fix reload-os-env=true
2 parents 6d1a043 + 1686a2f commit 5cf3962

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

plugins/python/pyloader.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,21 +129,33 @@ int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, PyThre
129129
p = strchr(*e, '=');
130130
if (p == NULL) continue;
131131

132+
#ifdef PYTHREE
133+
k = PyUnicode_FromStringAndSize(*e, (int)(p-*e));
134+
#else
132135
k = PyString_FromStringAndSize(*e, (int)(p-*e));
136+
#endif
133137
if (k == NULL) {
134138
PyErr_Print();
135139
continue;
136140
}
137141

138-
env_value = PyString_FromString(p+1);
142+
#ifdef PYTHREE
143+
env_value = PyUnicode_FromString(p+1);
144+
#else
145+
env_value = PyString_FromString(p+1);
146+
#endif
139147
if (env_value == NULL) {
140148
PyErr_Print();
141149
Py_DECREF(k);
142150
continue;
143151
}
144-
152+
145153
#ifdef UWSGI_DEBUG
154+
#ifdef PYTHREE
155+
uwsgi_log("%s = %s\n", PyUnicode_AsUTF8(k), PyUnicode_AsUTF8(env_value));
156+
#else
146157
uwsgi_log("%s = %s\n", PyString_AsString(k), PyString_AsString(env_value));
158+
#endif
147159
#endif
148160

149161
if (PyObject_SetItem(py_environ, k, env_value)) {
@@ -209,7 +221,7 @@ int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, PyThre
209221
if (multiapp < 1) {
210222
uwsgi_log("you have to define at least one app in the applications dictionary\n");
211223
goto doh;
212-
}
224+
}
213225

214226
PyObject *app_mnt = PyList_GetItem(app_list, 0);
215227
if (!PyString_Check(app_mnt)) {
@@ -228,7 +240,7 @@ int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, PyThre
228240
if (PyString_Check((PyObject *) wi->callable)) {
229241
PyObject *callables_dict = get_uwsgi_pydict((char *)arg1);
230242
if (callables_dict) {
231-
wi->callable = PyDict_GetItem(callables_dict, (PyObject *)wi->callable);
243+
wi->callable = PyDict_GetItem(callables_dict, (PyObject *)wi->callable);
232244
if (!wi->callable) {
233245
uwsgi_log("skipping broken app %s\n", wsgi_req->appid);
234246
goto multiapp;
@@ -377,7 +389,7 @@ int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, PyThre
377389
multiapp:
378390
if (multiapp > 1) {
379391
for(i=1;i<multiapp;i++) {
380-
PyObject *app_mnt = PyList_GetItem(app_list, i);
392+
PyObject *app_mnt = PyList_GetItem(app_list, i);
381393
if (!PyString_Check(app_mnt)) {
382394
uwsgi_log("applications dictionary key must be a string, skipping.\n");
383395
continue;
@@ -770,7 +782,7 @@ PyObject *uwsgi_eval_loader(void *arg1) {
770782
wsgi_eval_callable = PyDict_GetItemString(up.loader_dict, up.callable);
771783
}
772784
else {
773-
785+
774786
wsgi_eval_callable = PyDict_GetItemString(up.loader_dict, "application");
775787
}
776788

0 commit comments

Comments
 (0)