diff --git a/buildconf/base.ini b/buildconf/base.ini index 3bddf66e..31b26814 100644 --- a/buildconf/base.ini +++ b/buildconf/base.ini @@ -6,7 +6,6 @@ zeromq = auto ssl = auto pcre = auto routing = auto -matheval = auto debug = false unbit = false xml_implementation = libxml2 diff --git a/buildconf/glusterfs.ini b/buildconf/glusterfs.ini index 23ffc707..4b4af1b8 100644 --- a/buildconf/glusterfs.ini +++ b/buildconf/glusterfs.ini @@ -1,4 +1,3 @@ [uwsgi] main_plugin = glusterfs inherit = base -matheval = false diff --git a/buildconf/minimal.ini b/buildconf/minimal.ini index 30f54921..99be3ac2 100644 --- a/buildconf/minimal.ini +++ b/buildconf/minimal.ini @@ -6,7 +6,6 @@ zeromq = false ssl = false pcre = false routing = false -matheval = false debug = false unbit = false xml_implementation = none diff --git a/core/routing.c b/core/routing.c index 9719da60..2b88b4a2 100644 --- a/core/routing.c +++ b/core/routing.c @@ -1639,48 +1639,6 @@ static char *uwsgi_route_var_hex(struct wsgi_request *wsgi_req, char *key, uint1 return ret; } -#ifdef UWSGI_MATHEVAL -static char *uwsgi_route_var_math(struct wsgi_request *wsgi_req, char *key, uint16_t keylen, uint16_t *vallen) { - char *ret = NULL; - // avoid crash - if (!wsgi_req->var_cnt) return NULL; - // we make a bit of fun here, we do a copy of the vars buffer (+1 byte for final zero) and zeor-pad all of the strings - char *vars_buf = uwsgi_malloc(wsgi_req->uh->pktsize + keylen + 1); - char **names = uwsgi_malloc(sizeof(char *) * (wsgi_req->var_cnt/2)); - double *values = uwsgi_calloc(sizeof(double) * (wsgi_req->var_cnt/2)); - int i,j = 0; - char *ptr = vars_buf; - for (i = wsgi_req->var_cnt-1; i > 0; i -= 2) { - memcpy(ptr, wsgi_req->hvec[i-1].iov_base, wsgi_req->hvec[i-1].iov_len); - names[j] = ptr; - ptr += wsgi_req->hvec[i-1].iov_len; - *ptr++=0; - char *num = ptr; - memcpy(ptr, wsgi_req->hvec[i].iov_base, wsgi_req->hvec[i].iov_len); - ptr += wsgi_req->hvec[i].iov_len; - *ptr++=0; - values[j] = strtod(num, NULL); - j++; - } - - char *expr = ptr; - memcpy(ptr, key, keylen); ptr += keylen; - *ptr++=0; - - void *e = evaluator_create(expr); - if (!e) goto end; - double n = evaluator_evaluate(e, j, names, values); - evaluator_destroy(e); - ret = uwsgi_num2str((int)n); - *vallen = strlen(ret); -end: - free(vars_buf); - free(names); - free(values); - return ret; -} -#endif - // register embedded routers void uwsgi_register_embedded_routers() { uwsgi_register_router("continue", uwsgi_router_continue); @@ -1756,10 +1714,6 @@ void uwsgi_register_embedded_routers() { urv->need_free = 1; urv = uwsgi_register_route_var("httptime", uwsgi_route_var_httptime); urv->need_free = 1; -#ifdef UWSGI_MATHEVAL - urv = uwsgi_register_route_var("math", uwsgi_route_var_math); - urv->need_free = 1; -#endif urv = uwsgi_register_route_var("base64", uwsgi_route_var_base64); urv->need_free = 1; diff --git a/core/utils.c b/core/utils.c index ebffbe13..2d3fb361 100644 --- a/core/utils.c +++ b/core/utils.c @@ -3779,26 +3779,6 @@ error: return NULL; } -// evaluate a math expression -#ifdef UWSGI_MATHEVAL -double uwsgi_matheval(char *expr) { -#ifdef UWSGI_DEBUG - uwsgi_log("matheval expr = %s\n", expr); -#endif - double ret = 0.0; - void *e = evaluator_create(expr); - if (!e) - return ret; - ret = evaluator_evaluate(e, 0, NULL, NULL); - evaluator_destroy(e); - return ret; -} -char *uwsgi_matheval_str(char *expr) { - double ret = uwsgi_matheval(expr); - return uwsgi_num2str((int) ret); -} -#endif - int uwsgi_kvlist_parse(char *src, size_t len, char list_separator, char kv_separator, ...) { size_t i; va_list ap; diff --git a/core/uwsgi.c b/core/uwsgi.c index d9de819c..2595fa7c 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -2069,11 +2069,6 @@ int main(int argc, char *argv[], char *envp[]) { // last pass: REFERENCEs uwsgi_apply_config_pass('%', uwsgi_get_exported_opt); -#ifdef UWSGI_MATHEVAL - // optional pass: MATH - uwsgi_apply_config_pass('=', uwsgi_matheval_str); -#endif - // ok, the options dictionary is available, lets manage it uwsgi_configure(); diff --git a/plugins/glusterfs/glusterfs.c b/plugins/glusterfs/glusterfs.c index 248b62d7..afa0461d 100644 --- a/plugins/glusterfs/glusterfs.c +++ b/plugins/glusterfs/glusterfs.c @@ -1,10 +1,6 @@ #include #include -#ifdef UWSGI_MATHEVAL -#error currently the glusterfs plugins is not compatible with uWSGI built with matheval support -#endif - extern struct uwsgi_server uwsgi; /* diff --git a/plugins/matheval/math.c b/plugins/matheval/math.c new file mode 100644 index 00000000..7d41575a --- /dev/null +++ b/plugins/matheval/math.c @@ -0,0 +1,52 @@ +#include +#include + +static char *uwsgi_route_var_math(struct wsgi_request *wsgi_req, char *key, uint16_t keylen, uint16_t *vallen) { + char *ret = NULL; + // avoid crash + if (!wsgi_req->var_cnt) return NULL; + // we make a bit of fun here, we do a copy of the vars buffer (+1 byte for final zero) and zeor-pad all of the strings + char *vars_buf = uwsgi_malloc(wsgi_req->uh->pktsize + keylen + 1); + char **names = uwsgi_malloc(sizeof(char *) * (wsgi_req->var_cnt/2)); + double *values = uwsgi_calloc(sizeof(double) * (wsgi_req->var_cnt/2)); + int i,j = 0; + char *ptr = vars_buf; + for (i = wsgi_req->var_cnt-1; i > 0; i -= 2) { + memcpy(ptr, wsgi_req->hvec[i-1].iov_base, wsgi_req->hvec[i-1].iov_len); + names[j] = ptr; + ptr += wsgi_req->hvec[i-1].iov_len; + *ptr++=0; + char *num = ptr; + memcpy(ptr, wsgi_req->hvec[i].iov_base, wsgi_req->hvec[i].iov_len); + ptr += wsgi_req->hvec[i].iov_len; + *ptr++=0; + values[j] = strtod(num, NULL); + j++; + } + + char *expr = ptr; + memcpy(ptr, key, keylen); ptr += keylen; + *ptr++=0; + + void *e = evaluator_create(expr); + if (!e) goto end; + double n = evaluator_evaluate(e, j, names, values); + evaluator_destroy(e); + ret = uwsgi_num2str((int)n); + *vallen = strlen(ret); +end: + free(vars_buf); + free(names); + free(values); + return ret; +} + +static void router_matheval_register() { + struct uwsgi_route_var *urv = uwsgi_register_route_var("math", uwsgi_route_var_math); + urv->need_free = 1; +} + +struct uwsgi_plugin matheval_plugin = { + .name = "matheval", + .on_load = router_matheval_register, +}; diff --git a/plugins/matheval/uwsgiplugin.py b/plugins/matheval/uwsgiplugin.py new file mode 100644 index 00000000..f5c66adf --- /dev/null +++ b/plugins/matheval/uwsgiplugin.py @@ -0,0 +1,6 @@ +NAME='matheval' + +CFLAGS = [] +LDFLAGS = [] +LIBS = ['-lmatheval'] +GCC_LIST = ['math'] diff --git a/uwsgi.h b/uwsgi.h index f1af4828..e294c0a6 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -438,10 +438,6 @@ struct uwsgi_lock_ops { #include #endif -#ifdef UWSGI_MATHEVAL -#include -#endif - struct uwsgi_dyn_dict { char *key; @@ -4082,11 +4078,6 @@ void uwsgi_daemons_smart_check(); void uwsgi_setup_thread_req(long, struct wsgi_request *); void uwsgi_loop_cores_run(void *(*)(void *)); -#ifdef UWSGI_MATHEVAL -double uwsgi_matheval(char *); -char *uwsgi_matheval_str(char *); -#endif - int uwsgi_kvlist_parse(char *, size_t, char, char, ...); int uwsgi_send_http_stats(int); diff --git a/uwsgiconfig.py b/uwsgiconfig.py index 5a0c84c0..3fef89d2 100644 --- a/uwsgiconfig.py +++ b/uwsgiconfig.py @@ -1,6 +1,6 @@ # uWSGI build system -uwsgi_version = '1.9.19' +uwsgi_version = '1.9.20-dev' import os import re @@ -66,7 +66,6 @@ report = { 'timer': False, 'filemonitor': False, 'pcre': False, - 'matheval': False, 'routing': False, 'capabilities': False, 'yaml': False, @@ -972,12 +971,6 @@ class uConf(object): self.libs.append('-lcap') report['capabilities'] = True - if self.get('matheval'): - if (self.get('matheval') == 'auto' and self.has_include('matheval.h')) or self.get('matheval') == 'true': - self.cflags.append("-DUWSGI_MATHEVAL") - self.libs.append('-lmatheval') - report['matheval'] = True - has_json = False has_uuid = False