removed matheval flag, added generic matheval plugin and startin 1.9.20 development cycle

This commit is contained in:
Unbit
2013-11-10 02:53:08 +01:00
parent 79c702278a
commit 50a8ec8a19
11 changed files with 59 additions and 95 deletions
-1
View File
@@ -6,7 +6,6 @@ zeromq = auto
ssl = auto
pcre = auto
routing = auto
matheval = auto
debug = false
unbit = false
xml_implementation = libxml2
-1
View File
@@ -1,4 +1,3 @@
[uwsgi]
main_plugin = glusterfs
inherit = base
matheval = false
-1
View File
@@ -6,7 +6,6 @@ zeromq = false
ssl = false
pcre = false
routing = false
matheval = false
debug = false
unbit = false
xml_implementation = none
-46
View File
@@ -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;
-20
View File
@@ -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;
-5
View File
@@ -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();
-4
View File
@@ -1,10 +1,6 @@
#include <uwsgi.h>
#include <api/glfs.h>
#ifdef UWSGI_MATHEVAL
#error currently the glusterfs plugins is not compatible with uWSGI built with matheval support
#endif
extern struct uwsgi_server uwsgi;
/*
+52
View File
@@ -0,0 +1,52 @@
#include <uwsgi.h>
#include <matheval.h>
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,
};
+6
View File
@@ -0,0 +1,6 @@
NAME='matheval'
CFLAGS = []
LDFLAGS = []
LIBS = ['-lmatheval']
GCC_LIST = ['math']
-9
View File
@@ -438,10 +438,6 @@ struct uwsgi_lock_ops {
#include <pcre.h>
#endif
#ifdef UWSGI_MATHEVAL
#include <matheval.h>
#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);
+1 -8
View File
@@ -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