summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_python_wsgi.c
diff options
context:
space:
mode:
authorAndrei Belov <defan@nginx.com>2018-12-20 20:25:50 +0300
committerAndrei Belov <defan@nginx.com>2018-12-20 20:25:50 +0300
commit82e12d0cdeeb707ad4b1aef91c5e90b4347b0831 (patch)
tree19ef4cf3dea340fa365af022c76543f92d1e2e0a /src/nxt_python_wsgi.c
parentb140ac29e5571e9abaafce006932f15d86b78803 (diff)
parent4195a29fabfe65f5a28baf2405c2077e2ba3c09a (diff)
downloadunit-82e12d0cdeeb707ad4b1aef91c5e90b4347b0831.tar.gz
unit-82e12d0cdeeb707ad4b1aef91c5e90b4347b0831.tar.bz2
Merged with the default branch.
Diffstat (limited to 'src/nxt_python_wsgi.c')
-rw-r--r--src/nxt_python_wsgi.c44
1 files changed, 18 insertions, 26 deletions
diff --git a/src/nxt_python_wsgi.c b/src/nxt_python_wsgi.c
index 3a5f1913..bd3a2cb2 100644
--- a/src/nxt_python_wsgi.c
+++ b/src/nxt_python_wsgi.c
@@ -276,7 +276,6 @@ nxt_python_init(nxt_task_t *task, nxt_common_app_conf_t *conf)
Py_InitializeEx(0);
- obj = NULL;
module = NULL;
if (c->path.length > 0) {
@@ -284,7 +283,7 @@ nxt_python_init(nxt_task_t *task, nxt_common_app_conf_t *conf)
c->path.length);
if (nxt_slow_path(obj == NULL)) {
- nxt_alert(task, "Python failed create string object \"%V\"",
+ nxt_alert(task, "Python failed to create string object \"%V\"",
&c->path);
goto fail;
}
@@ -303,11 +302,9 @@ nxt_python_init(nxt_task_t *task, nxt_common_app_conf_t *conf)
}
Py_DECREF(obj);
- obj = NULL;
}
obj = PyCFunction_New(nxt_py_start_resp_method, NULL);
-
if (nxt_slow_path(obj == NULL)) {
nxt_alert(task,
"Python failed to initialize the \"start_response\" function");
@@ -317,7 +314,6 @@ nxt_python_init(nxt_task_t *task, nxt_common_app_conf_t *conf)
nxt_py_start_resp_obj = obj;
obj = PyCFunction_New(nxt_py_write_method, NULL);
-
if (nxt_slow_path(obj == NULL)) {
nxt_alert(task, "Python failed to initialize the \"write\" function");
goto fail;
@@ -326,40 +322,37 @@ nxt_python_init(nxt_task_t *task, nxt_common_app_conf_t *conf)
nxt_py_write_obj = obj;
obj = nxt_python_create_environ(task);
-
- if (obj == NULL) {
+ if (nxt_slow_path(obj == NULL)) {
goto fail;
}
nxt_py_environ_ptyp = obj;
obj = Py_BuildValue("[s]", "unit");
- if (obj == NULL) {
+ if (nxt_slow_path(obj == NULL)) {
nxt_alert(task, "Python failed to create the \"sys.argv\" list");
goto fail;
}
- if (PySys_SetObject((char *) "argv", obj) != 0) {
+ if (nxt_slow_path(PySys_SetObject((char *) "argv", obj) != 0)) {
nxt_alert(task, "Python failed to set the \"sys.argv\" list");
goto fail;
}
- Py_DECREF(obj);
+ Py_CLEAR(obj);
nxt_py_module = nxt_alloca(c->module.length + 1);
nxt_memcpy(nxt_py_module, c->module.start, c->module.length);
nxt_py_module[c->module.length] = '\0';
module = PyImport_ImportModule(nxt_py_module);
-
if (nxt_slow_path(module == NULL)) {
nxt_alert(task, "Python failed to import module \"%s\"", nxt_py_module);
- PyErr_PrintEx(1);
- return NXT_ERROR;
+ PyErr_Print();
+ goto fail;
}
obj = PyDict_GetItemString(PyModule_GetDict(module), "application");
-
if (nxt_slow_path(obj == NULL)) {
nxt_alert(task, "Python failed to get \"application\" "
"from module \"%s\"", nxt_py_module);
@@ -369,14 +362,15 @@ nxt_python_init(nxt_task_t *task, nxt_common_app_conf_t *conf)
if (nxt_slow_path(PyCallable_Check(obj) == 0)) {
nxt_alert(task, "\"application\" in module \"%s\" "
"is not a callable object", nxt_py_module);
- PyErr_PrintEx(1);
+ PyErr_Print();
goto fail;
}
Py_INCREF(obj);
- Py_DECREF(module);
+ Py_CLEAR(module);
nxt_py_application = obj;
+ obj = NULL;
nxt_unit_default_init(task, &python_init);
@@ -384,7 +378,7 @@ nxt_python_init(nxt_task_t *task, nxt_common_app_conf_t *conf)
unit_ctx = nxt_unit_init(&python_init);
if (nxt_slow_path(unit_ctx == NULL)) {
- return NXT_ERROR;
+ goto fail;
}
rc = nxt_unit_run(unit_ctx);
@@ -402,9 +396,7 @@ fail:
Py_XDECREF(obj);
Py_XDECREF(module);
- if (nxt_py_home != NULL) {
- nxt_free(nxt_py_home);
- }
+ nxt_python_atexit();
return NXT_ERROR;
}
@@ -536,10 +528,10 @@ fail:
static void
nxt_python_atexit(void)
{
- Py_DECREF(nxt_py_application);
- Py_DECREF(nxt_py_start_resp_obj);
- Py_DECREF(nxt_py_write_obj);
- Py_DECREF(nxt_py_environ_ptyp);
+ Py_XDECREF(nxt_py_application);
+ Py_XDECREF(nxt_py_start_resp_obj);
+ Py_XDECREF(nxt_py_write_obj);
+ Py_XDECREF(nxt_py_environ_ptyp);
Py_Finalize();
@@ -804,7 +796,7 @@ nxt_python_add_sptr(nxt_python_run_ctx_t *ctx, const char *name,
nxt_unit_req_error(ctx->req,
"Python failed to create value string \"%.*s\"",
(int) size, src);
- PyErr_PrintEx(1);
+ PyErr_Print();
return NXT_UNIT_ERROR;
}
@@ -839,7 +831,7 @@ nxt_python_add_str(nxt_python_run_ctx_t *ctx, const char *name,
nxt_unit_req_error(ctx->req,
"Python failed to create value string \"%.*s\"",
(int) size, str);
- PyErr_PrintEx(1);
+ PyErr_Print();
return NXT_UNIT_ERROR;
}