diff --git a/plugins/psgi/psgi.h b/plugins/psgi/psgi.h index d3809ae9..38830f0f 100644 --- a/plugins/psgi/psgi.h +++ b/plugins/psgi/psgi.h @@ -19,7 +19,7 @@ struct uwsgi_perl { }; -#define LONG_ARGS_PERL_BASE 17000 + (5 * 100) +#define LONG_ARGS_PERL_BASE 17000 + ((5 + 1) * 100) #define LONG_ARGS_PSGI LONG_ARGS_PERL_BASE + 1 void init_perl_embedded_module(void); diff --git a/plugins/python/pyloader.c b/plugins/python/pyloader.c index 1e317d60..d97a6955 100644 --- a/plugins/python/pyloader.c +++ b/plugins/python/pyloader.c @@ -410,41 +410,11 @@ PyObject *uwsgi_dyn_loader(void *arg1) { PyObject *uwsgi_file_loader(void *arg1) { char *filename = (char *) arg1; - FILE *wsgifile; - struct _node *wsgi_file_node = NULL; - PyObject *wsgi_compiled_node, *wsgi_file_module, *wsgi_file_dict; + PyObject *wsgi_file_module, *wsgi_file_dict; PyObject *wsgi_file_callable; - wsgifile = fopen(filename, "r"); - if (!wsgifile) { - uwsgi_error("fopen()"); - exit(1); - } - - wsgi_file_node = PyParser_SimpleParseFile(wsgifile, filename, Py_file_input); - if (!wsgi_file_node) { - PyErr_Print(); - uwsgi_log( "failed to parse file %s\n", filename); - exit(1); - } - - fclose(wsgifile); - - wsgi_compiled_node = (PyObject *) PyNode_Compile(wsgi_file_node, filename); - - if (!wsgi_compiled_node) { - PyErr_Print(); - uwsgi_log( "failed to compile wsgi file %s\n", filename); - exit(1); - } - - wsgi_file_module = PyImport_ExecCodeModule("uwsgi_wsgi_file", wsgi_compiled_node); - if (!wsgi_file_module) { - PyErr_Print(); - exit(1); - } - - Py_DECREF(wsgi_compiled_node); + wsgi_file_module = uwsgi_pyimport_by_filename("uwsgi_wsgi_file", filename); + // no need to check here for module import as it is already done by uwsgi_pyimport_by_file wsgi_file_dict = PyModule_GetDict(wsgi_file_module); if (!wsgi_file_dict) { @@ -452,7 +422,6 @@ PyObject *uwsgi_file_loader(void *arg1) { exit(1); } - wsgi_file_callable = PyDict_GetItemString(wsgi_file_dict, "application"); if (!wsgi_file_callable) { PyErr_Print(); @@ -465,7 +434,6 @@ PyObject *uwsgi_file_loader(void *arg1) { exit(1); } - return wsgi_file_callable; } diff --git a/plugins/python/python_plugin.c b/plugins/python/python_plugin.c index 60d74bdd..f5a90b6e 100644 --- a/plugins/python/python_plugin.c +++ b/plugins/python/python_plugin.c @@ -13,6 +13,7 @@ struct option uwsgi_python_options[] = { {"home", required_argument, 0, 'H'}, {"pythonpath", required_argument, 0, LONG_ARGS_PYTHONPATH}, {"python-path", required_argument, 0, LONG_ARGS_PYTHONPATH}, + {"pymodule-alias", required_argument, 0, LONG_ARGS_PYMODULE_ALIAS}, {"pp", required_argument, 0, LONG_ARGS_PYTHONPATH}, {"pyargv", required_argument, 0, LONG_ARGS_PYARGV}, {"optimize", required_argument, 0, 'O'}, @@ -164,11 +165,56 @@ void uwsgi_python_post_fork() { } +PyObject *uwsgi_pyimport_by_filename(char *name, char *filename) { + + FILE *pyfile; + struct _node *py_file_node = NULL; + PyObject *py_compiled_node, *py_file_module; + + pyfile = fopen(filename, "r"); + if (!pyfile) { + uwsgi_error("fopen()"); + exit(1); + } + + py_file_node = PyParser_SimpleParseFile(pyfile, filename, Py_file_input); + if (!py_file_node) { + PyErr_Print(); + uwsgi_log( "failed to parse file %s\n", filename); + exit(1); + } + + fclose(pyfile); + + py_compiled_node = (PyObject *) PyNode_Compile(py_file_node, filename); + + if (!py_compiled_node) { + PyErr_Print(); + uwsgi_log( "failed to compile python file %s\n", filename); + exit(1); + } + + py_file_module = PyImport_ExecCodeModule(name, py_compiled_node); + if (!py_file_module) { + PyErr_Print(); + exit(1); + } + + Py_DECREF(py_compiled_node); + + return py_file_module; + +} + + void init_uwsgi_vars() { int i; PyObject *pysys, *pysys_dict, *pypath; + PyObject *modules = PyImport_GetModuleDict(); + PyObject *tmp_module; + #ifdef UWSGI_MINTERPRETERS char venv_version[15]; PyObject *site_module; @@ -233,6 +279,33 @@ void init_uwsgi_vars() { } } + for(i=0;i @@ -100,6 +108,9 @@ struct uwsgi_python { PyObject *embedded_dict; PyObject *embedded_args; PyObject *fastfuncslist; + + char *pymodule_alias[MAX_PYMODULE_ALIAS]; + int pymodule_alias_cnt; }; @@ -184,3 +195,5 @@ void gil_fake_release(void); void init_uwsgi_module_advanced(PyObject *); void init_uwsgi_module_spooler(PyObject *); void init_uwsgi_module_sharedarea(PyObject *); + +PyObject *uwsgi_pyimport_by_filename(char *, char *); diff --git a/plugins/rack/uwsgi_rack.h b/plugins/rack/uwsgi_rack.h index 1dc70b56..96a95028 100644 --- a/plugins/rack/uwsgi_rack.h +++ b/plugins/rack/uwsgi_rack.h @@ -2,7 +2,7 @@ #include -#define LONG_ARGS_RACK_BASE 17000 + (7 * 100) +#define LONG_ARGS_RACK_BASE 17000 + ((7 + 1) * 100) #define LONG_ARGS_RAILS LONG_ARGS_RACK_BASE + 1 #define LONG_ARGS_RUBY_GC_FREQ LONG_ARGS_RACK_BASE + 2 #define LONG_ARGS_RACK LONG_ARGS_RACK_BASE + 3 diff --git a/uwsgi.h b/uwsgi.h index a38d1758..e644a39f 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -186,10 +186,7 @@ struct uwsgi_opt { #define LONG_ARGS_CHROOT 17002 #define LONG_ARGS_GID 17003 #define LONG_ARGS_UID 17004 -#define LONG_ARGS_PYTHONPATH 17005 -#define LONG_ARGS_PASTE 17006 #define LONG_ARGS_CHECK_INTERVAL 17007 -#define LONG_ARGS_PYARGV 17008 #define LONG_ARGS_LIMIT_AS 17009 #define LONG_ARGS_UDP 17010 #define LONG_ARGS_WSGI_FILE 17011