Permalink
Browse files

preliminary pypy support

  • Loading branch information...
1 parent 1446e3f commit 1989099cc5dd341b3671fe2fe0455380959d23eb roberto@debian32 committed Aug 31, 2011
View
@@ -3,6 +3,11 @@
extern struct uwsgi_server uwsgi;
extern struct uwsgi_python up;
+#ifdef UWSGI_PYPY
+void gil_real_get() {}
+void gil_real_release() {}
+#else
+
void gil_real_get() {
//uwsgi_log("LOCK %d\n", uwsgi.mywid);
#ifndef PYTHREE
@@ -26,5 +31,7 @@ void gil_real_release() {
#endif
}
+#endif
+
void gil_fake_get() {}
void gil_fake_release() {}
@@ -15,6 +15,7 @@ int PyFrame_GetLineNumber(PyFrameObject *frame) {
int uwsgi_python_profiler_call(PyObject *obj, PyFrameObject *frame, int what, PyObject *arg) {
+#ifndef UWSGI_PYPY
switch(what) {
case PyTrace_CALL:
uwsgi_log("[uWSGI Python profiler] CALL: %s (line %d) -> %s %d args, stacksize %d\n",
@@ -29,6 +30,7 @@ int uwsgi_python_profiler_call(PyObject *obj, PyFrameObject *frame, int what, Py
PyEval_GetFuncName(arg), frame->f_code->co_argcount, frame->f_code->co_stacksize);
break;
}
+#endif
return 0;
}
View
@@ -160,6 +160,7 @@ int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, PyThre
}
}
+#ifdef UWSGI_MINTERPRETERS
if (interpreter == NULL && id) {
wi->interpreter = Py_NewInterpreter();
@@ -184,10 +185,11 @@ int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, PyThre
wi->interpreter = up.main_thread;
}
-#ifdef UWSGI_MINTERPRETERS
if (wsgi_req->pyhome_len) {
set_dyn_pyhome(wsgi_req->pyhome, wsgi_req->pyhome_len);
}
+#else
+ wi->interpreter = up.main_thread;
#endif
if (wsgi_req->touch_reload_len) {
@@ -424,6 +426,7 @@ int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, PyThre
doh:
free(mountpoint);
PyErr_Print();
+#ifdef UWSGI_MINTERPRETERS
if (interpreter == NULL && id) {
Py_EndInterpreter(wi->interpreter);
if (uwsgi.threads > 1) {
@@ -433,6 +436,7 @@ int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, PyThre
PyThreadState_Swap(up.main_thread);
}
}
+#endif
return -1;
}
@@ -477,7 +481,9 @@ PyObject *uwsgi_uwsgi_loader(void *arg1) {
PyObject *tmp_callable;
PyObject *applications;
+#ifndef UWSGI_PYPY
PyObject *uwsgi_dict = get_uwsgi_pydict("uwsgi");
+#endif
char *module = (char *) arg1;
@@ -500,8 +506,10 @@ PyObject *uwsgi_uwsgi_loader(void *arg1) {
return NULL;
}
+#ifndef UWSGI_PYPY
applications = PyDict_GetItemString(uwsgi_dict, "applications");
if (applications && PyDict_Check(applications)) return applications;
+#endif
applications = PyDict_GetItemString(wsgi_dict, "applications");
@@ -672,6 +680,8 @@ PyObject *uwsgi_paste_loader(void *arg1) {
PyObject *uwsgi_eval_loader(void *arg1) {
+#ifndef UWSGI_PYPY
+
char *code = (char *) arg1;
PyObject *wsgi_eval_module, *wsgi_eval_callable = NULL;
@@ -727,6 +737,9 @@ PyObject *uwsgi_eval_loader(void *arg1) {
}
return wsgi_eval_callable;
+#else
+ return NULL;
+#endif
}
@@ -47,7 +47,9 @@ struct option uwsgi_python_options[] = {
{"ignore-script-name", no_argument, &up.ignore_script_name, 1},
{"pep3333-input", no_argument, &up.pep3333_input, 1},
{"reload-os-env", no_argument, &up.reload_os_env, 1},
+#ifndef UWSGI_PYPY
{"no-site", no_argument, &Py_NoSiteFlag, 1},
+#endif
{"pyshell", no_argument, 0, LONG_ARGS_PYSHELL},
{0, 0, 0, 0},
@@ -100,9 +102,14 @@ PyMethodDef uwsgi_write_method[] = { {"uwsgi_write", py_uwsgi_write, METH_VARARG
int uwsgi_python_init() {
+#ifndef UWSGI_PYPY
char *pyversion = strchr(Py_GetVersion(), '\n');
uwsgi_log("Python version: %.*s %s\n", pyversion-Py_GetVersion(), Py_GetVersion(), Py_GetCompiler()+1);
+#else
+ uwsgi_log("PyPy version: %s\n", PYPY_VERSION);
+#endif
+#ifndef UWSGI_PYPY
if (up.home != NULL) {
#ifdef PYTHREE
wchar_t *wpyhome;
@@ -135,6 +142,8 @@ int uwsgi_python_init() {
Py_OptimizeFlag = up.optimize;
+#endif
+
up.wsgi_spitout = PyCFunction_New(uwsgi_spit_method, NULL);
up.wsgi_writeout = PyCFunction_New(uwsgi_write_method, NULL);
@@ -156,6 +165,7 @@ int uwsgi_python_init() {
void uwsgi_python_reset_random_seed() {
+#ifndef UWSGI_PYPY
PyObject *random_module, *random_dict, *random_seed;
// reinitialize the random seed (thanks Jonas Borgström)
@@ -175,6 +185,7 @@ void uwsgi_python_reset_random_seed() {
}
}
}
+#endif
}
void uwsgi_python_post_fork() {
@@ -189,6 +200,7 @@ void uwsgi_python_post_fork() {
uwsgi_python_reset_random_seed();
+#ifndef UWSGI_PYPY
#ifdef UWSGI_EMBEDDED
// call the post_fork_hook
PyObject *uwsgi_dict = get_uwsgi_pydict("uwsgi");
@@ -200,13 +212,15 @@ void uwsgi_python_post_fork() {
}
PyErr_Clear();
#endif
+#endif
UWSGI_RELEASE_GIL
}
PyObject *uwsgi_pyimport_by_filename(char *name, char *filename) {
+#ifndef UWSGI_PYPY
FILE *pyfile;
struct _node *py_file_node = NULL;
PyObject *py_compiled_node, *py_file_module;
@@ -292,6 +306,9 @@ PyObject *uwsgi_pyimport_by_filename(char *name, char *filename) {
}
return py_file_module;
+#else
+ return NULL;
+#endif
}
@@ -859,7 +876,9 @@ void uwsgi_python_init_apps() {
if (uwsgi.async > 1) {
up.current_recursion_depth = uwsgi_malloc(sizeof(int)*uwsgi.async);
+#ifndef UWSGI_PYPY
up.current_frame = uwsgi_malloc(sizeof(struct _frame)*uwsgi.async);
+#endif
}
init_pyargv();
@@ -869,7 +888,7 @@ void uwsgi_python_init_apps() {
#endif
#ifdef __linux__
-#ifndef PYTHREE
+#if !defined(PYTHREE) && !defined(UWSGI_PYPY)
uwsgi_init_symbol_import();
#endif
#endif
@@ -974,9 +993,11 @@ void uwsgi_python_init_apps() {
}
if (uwsgi.profiler) {
+#ifndef UWSGI_PYPY
if (!strcmp(uwsgi.profiler, "pycall")) {
PyEval_SetProfile(uwsgi_python_profiler_call, NULL);
}
+#endif
}
}
@@ -1091,6 +1112,7 @@ int uwsgi_python_xml(char *node, char *content) {
return 0;
}
+#ifndef UWSGI_PYPY
void uwsgi_python_suspend(struct wsgi_request *wsgi_req) {
PyThreadState *tstate = PyThreadState_GET();
@@ -1105,6 +1127,7 @@ void uwsgi_python_suspend(struct wsgi_request *wsgi_req) {
}
}
+#endif
char *uwsgi_python_code_string(char *id, char *code, char *function, char *key, uint16_t keylen) {
@@ -1293,6 +1316,7 @@ int uwsgi_python_spooler(char *filename, char *buf, uint16_t len, char *body, si
return -1;
}
+#ifndef UWSGI_PYPY
void uwsgi_python_resume(struct wsgi_request *wsgi_req) {
PyThreadState *tstate = PyThreadState_GET();
@@ -1307,6 +1331,7 @@ void uwsgi_python_resume(struct wsgi_request *wsgi_req) {
}
}
+#endif
void uwsgi_python_fixup() {
// set hacky modifier 30
@@ -1316,12 +1341,14 @@ void uwsgi_python_fixup() {
void uwsgi_python_hijack(void) {
// the pyshell will be execute only in the first worker
+#ifndef UWSGI_PYPY
if (up.pyshell && uwsgi.mywid == 1) {
UWSGI_GET_GIL;
PyImport_ImportModule("readline");
PyRun_InteractiveLoop(stdin, "uwsgi");
exit(0);
}
+#endif
}
struct uwsgi_plugin python_plugin = {
@@ -1349,8 +1376,10 @@ struct uwsgi_plugin python_plugin = {
.magic = uwsgi_python_magic,
+#ifndef UWSGI_PYPY
.suspend = uwsgi_python_suspend,
.resume = uwsgi_python_resume,
+#endif
.hijack_worker = uwsgi_python_hijack,
.spooler_init = uwsgi_python_spooler_init,
View
@@ -105,7 +105,9 @@ void init_pyargv() {
}
}
+#ifndef UWSGI_PYPY
PySys_SetArgv(up.argc, up.py_argv);
+#endif
PyObject *sys_dict = get_uwsgi_pydict("sys");
if (!sys_dict) {
@@ -1,6 +1,6 @@
#include "uwsgi_python.h"
-#ifndef PYTHREE
+#if !defined(PYTHREE) && !defined(UWSGI_PYPY)
extern struct uwsgi_server uwsgi;
extern struct uwsgi_python up;
@@ -1499,7 +1499,6 @@ PyObject *py_uwsgi_send_multi_message(PyObject * self, PyObject * args) {
PyObject *arg_modifier1, *arg_modifier2, *arg_timeout;
- PyObject *marshalled;
PyObject *retobject;
@@ -1568,6 +1567,8 @@ PyObject *py_uwsgi_send_multi_message(PyObject * self, PyObject * args) {
}
+#ifndef UWSGI_PYPY
+ PyObject *marshalled;
switch (PyInt_AsLong(arg_modifier1)) {
case UWSGI_MODIFIER_MESSAGE_MARSHAL:
marshalled = PyMarshal_WriteObjectToString(arg_message, 1);
@@ -1582,6 +1583,7 @@ PyObject *py_uwsgi_send_multi_message(PyObject * self, PyObject * args) {
}
break;
}
+#endif
}
@@ -1909,7 +1911,7 @@ PyObject *py_uwsgi_async_connect(PyObject * self, PyObject * args) {
PyObject *py_uwsgi_async_send_message(PyObject * self, PyObject * args) {
- PyObject *pyobj = NULL, *marshalled = NULL;
+ PyObject *pyobj = NULL;
int uwsgi_fd;
int modifier1 = 0;
@@ -1938,8 +1940,9 @@ PyObject *py_uwsgi_async_send_message(PyObject * self, PyObject * args) {
esize = PyString_Size(pyobj);
UWSGI_RELEASE_GIL uwsgi_send_message(uwsgi_fd, (uint8_t) modifier1, (uint8_t) modifier2, encoded, esize, -1, 0, 0);
}
+#ifndef UWSGI_PYPY
else {
- marshalled = PyMarshal_WriteObjectToString(pyobj, 1);
+ PyObject *marshalled = PyMarshal_WriteObjectToString(pyobj, 1);
if (!marshalled) {
PyErr_Print();
goto clear;
@@ -1949,6 +1952,7 @@ PyObject *py_uwsgi_async_send_message(PyObject * self, PyObject * args) {
esize = PyString_Size(marshalled);
UWSGI_RELEASE_GIL uwsgi_send_message(uwsgi_fd, (uint8_t) modifier1, (uint8_t) modifier2, encoded, esize, -1, 0, 0);
}
+#endif
UWSGI_GET_GIL clear:
@@ -2049,7 +2053,7 @@ PyObject *py_uwsgi_fcgi(PyObject * self, PyObject * args) {
PyObject *py_uwsgi_send_message(PyObject * self, PyObject * args) {
- PyObject *destination = NULL, *pyobj = NULL, *marshalled = NULL;
+ PyObject *destination = NULL, *pyobj = NULL;
int modifier1 = 0;
int modifier2 = 0;
@@ -2094,8 +2098,9 @@ PyObject *py_uwsgi_send_message(PyObject * self, PyObject * args) {
esize = PyString_Size(pyobj);
UWSGI_RELEASE_GIL uwsgi_send_message(uwsgi_fd, (uint8_t) modifier1, (uint8_t) modifier2, encoded, esize, fd, cl, timeout);
}
+#ifndef UWSGI_PYPY
else {
- marshalled = PyMarshal_WriteObjectToString(pyobj, 1);
+ PyObject *marshalled = PyMarshal_WriteObjectToString(pyobj, 1);
if (!marshalled) {
PyErr_Print();
goto clear;
@@ -2105,6 +2110,7 @@ PyObject *py_uwsgi_send_message(PyObject * self, PyObject * args) {
esize = PyString_Size(marshalled);
UWSGI_RELEASE_GIL uwsgi_send_message(uwsgi_fd, (uint8_t) modifier1, (uint8_t) modifier2, encoded, esize, fd, cl, timeout);
}
+#endif
UWSGI_GET_GIL
@@ -264,6 +264,10 @@ void uwsgi_python_reset_random_seed(void);
char *uwsgi_pythonize(char *);
+#ifdef UWSGI_PYPY
+#undef UWSGI_MINTERPRETERS
+#endif
+
#define uwsgi_pyexit {PyErr_Print();exit(1);}
#ifdef __linux__
Oops, something went wrong.

0 comments on commit 1989099

Please sign in to comment.