From f04aa843ffdc66b681603270b03ffa45bee51774 Mon Sep 17 00:00:00 2001 From: "roberto@mrspurr" Date: Sat, 18 Sep 2010 08:41:16 +0200 Subject: [PATCH] fix argument count check --- uwsgi.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/uwsgi.c b/uwsgi.c index 81c68e01..a50e3db0 100644 --- a/uwsgi.c +++ b/uwsgi.c @@ -2293,10 +2293,26 @@ int init_uwsgi_app(PyObject * force_wsgi_dict, PyObject * my_callable) { #endif #ifdef UWSGI_WEB3 - // heck function args + + + // check function args + // by defaut is a WSGI app + wi->argc = 2; zero = PyObject_GetAttrString(wi->wsgi_callable, "__code__"); - zero = PyObject_GetAttrString(zero, "co_argcount"); - wi->argc = (int) PyInt_AsLong(zero); + if (!zero) { + zero = PyObject_GetAttrString(wi->wsgi_callable, "__call__"); + if (zero) { + zero = PyObject_GetAttrString(wi->wsgi_callable, "__code__"); + } + else { + uwsgi_log("WARNING: unable to get the number of callable args. Fallback to WSGI\n"); + } + } + + if (zero) { + zero = PyObject_GetAttrString(zero, "co_argcount"); + wi->argc = (int) PyInt_AsLong(zero); + } if (wi->argc == 1) { uwsgi_log("-- Web3 callable detected --\n"); @@ -2387,8 +2403,6 @@ int init_uwsgi_app(PyObject * force_wsgi_dict, PyObject * my_callable) { uwsgi_log( "application %d (%.*s) ready\n", id, wi->mountpoint_len, wi->mountpoint); - Py_DECREF(zero); - if (id == 0) { uwsgi_log( "setting default application to 0\n"); uwsgi.default_app = 0;