diff --git a/plugins/python/uwsgi_pymodule.c b/plugins/python/uwsgi_pymodule.c index 32eda062..e0ba2faf 100644 --- a/plugins/python/uwsgi_pymodule.c +++ b/plugins/python/uwsgi_pymodule.c @@ -1479,8 +1479,7 @@ clear: } static PyTypeObject uwsgi_IterType = { - PyObject_HEAD_INIT(NULL) - 0, /*ob_size*/ + PyVarObject_HEAD_INIT(NULL, 0) "uwsgi._Iter", /*tp_name*/ sizeof(uwsgi_Iter), /*tp_basicsize*/ 0, /*tp_itemsize*/ @@ -1499,7 +1498,11 @@ static PyTypeObject uwsgi_IterType = { 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ +#if defined(Py_TPFLAGS_HAVE_ITER) Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER, +#else + Py_TPFLAGS_DEFAULT, +#endif "uwsgi response iterator object.", /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ diff --git a/plugins/python/wsgi_headers.c b/plugins/python/wsgi_headers.c index 524066dd..0c552678 100644 --- a/plugins/python/wsgi_headers.c +++ b/plugins/python/wsgi_headers.c @@ -34,7 +34,11 @@ PyObject *py_uwsgi_spit(PyObject * self, PyObject * args) { goto clear; } +#ifdef PYTHREE + if (!PyUnicode_Check(head)) { +#else if (!PyString_Check(head)) { +#endif uwsgi_log( "http status must be a string !\n"); goto clear; } diff --git a/uwsgi.c b/uwsgi.c index 046e141e..8bd38509 100644 --- a/uwsgi.c +++ b/uwsgi.c @@ -714,9 +714,8 @@ int uwsgi_start(void *v_argv) { pid_t pid; int i, j; - struct sockaddr_un usa; - struct sockaddr *gsa; - struct sockaddr_in *isa; + union uwsgi_sockaddr usa; + union uwsgi_sockaddr_ptr gsa, isa; socklen_t socket_type_len; FILE *pidfile; @@ -1070,10 +1069,10 @@ int uwsgi_start(void *v_argv) { for (j = 3; j < sysconf(_SC_OPEN_MAX); j++) { socket_type_len = sizeof(struct sockaddr_un); - gsa = (struct sockaddr *) &usa; - if (!getsockname(j, gsa, &socket_type_len)) { - if (gsa->sa_family == AF_UNIX) { - if (!strcmp(usa.sun_path, uwsgi.sockets[i].name)) { + gsa.sa = &usa.sa; + if (!getsockname(j, gsa.sa, &socket_type_len)) { + if (gsa.sa->sa_family == AF_UNIX) { + if (!strcmp(usa.sa_un.sun_path, uwsgi.sockets[i].name)) { uwsgi.sockets[i].fd = j; uwsgi.sockets[i].family = AF_UNIX; uwsgi.sockets[i].bound = 1; @@ -1081,17 +1080,17 @@ int uwsgi_start(void *v_argv) { uwsgi.sockets_poll[i].events = POLLIN; uwsgi_log("uwsgi socket %d inherited UNIX address %s fd %d\n", i, uwsgi.sockets[i].name, uwsgi.sockets[i].fd); } - } else if (gsa->sa_family == AF_INET) { + } else if (gsa.sa->sa_family == AF_INET) { char *computed_addr; char computed_port[6]; - isa = (struct sockaddr_in *) &usa; + isa.sa_in = (struct sockaddr_in *) &usa; char ipv4a[INET_ADDRSTRLEN + 1]; memset(ipv4a, 0, INET_ADDRSTRLEN + 1); memset(computed_port, 0, 6); - if (snprintf(computed_port, 6, "%d", ntohs(isa->sin_port)) > 0) { - if (inet_ntop(AF_INET, (const void *) &isa->sin_addr.s_addr, ipv4a, INET_ADDRSTRLEN)) { + if (snprintf(computed_port, 6, "%d", ntohs(isa.sa_in->sin_port)) > 0) { + if (inet_ntop(AF_INET, (const void *) &isa.sa_in->sin_addr.s_addr, ipv4a, INET_ADDRSTRLEN)) { if (!strcmp("0.0.0.0", ipv4a)) { computed_addr = uwsgi_concat2(":", computed_port); @@ -1132,8 +1131,8 @@ int uwsgi_start(void *v_argv) { if (j == uwsgi.cluster_fd) continue; #endif socket_type_len = sizeof(struct sockaddr_un); - gsa = (struct sockaddr *) & usa; - if (!getsockname(j, gsa, &socket_type_len)) { + gsa.sa = (struct sockaddr *) & usa; + if (!getsockname(j, gsa.sa, &socket_type_len)) { for (i = 0; i < uwsgi.sockets_cnt; i++) { if (uwsgi.sockets[i].fd == j && uwsgi.sockets[i].bound) { useless = 0; @@ -1179,13 +1178,13 @@ int uwsgi_start(void *v_argv) { if (!zero_used) { socket_type_len = sizeof(struct sockaddr_un); - gsa = (struct sockaddr *) & usa; - if (!getsockname(0, gsa, &socket_type_len)) { + gsa.sa = (struct sockaddr *) & usa; + if (!getsockname(0, gsa.sa, &socket_type_len)) { if (uwsgi.sockets_cnt < 8) { uwsgi.sockets_cnt++; uwsgi.sockets[uwsgi.sockets_cnt - 1].fd = 0; uwsgi.sockets[uwsgi.sockets_cnt - 1].bound = 1; - uwsgi.sockets[uwsgi.sockets_cnt - 1].family = gsa->sa_family; + uwsgi.sockets[uwsgi.sockets_cnt - 1].family = gsa.sa->sa_family; //uwsgi.sockets[uwsgi.sockets_cnt - 1].name = uwsgi_get_socket_name(gsa->sa_family, gsa); uwsgi.sockets_poll[uwsgi.sockets_cnt - 1].fd = 0; uwsgi.sockets_poll[uwsgi.sockets_cnt - 1].events = POLLIN; diff --git a/uwsgi.h b/uwsgi.h index 858a9f23..aeb22109 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -85,6 +85,7 @@ #include + #ifdef __linux #include #include @@ -185,6 +186,18 @@ extern int pivot_root(const char * new_root, const char * put_old); #define UWSGI_CACHE_MAX_KEY_SIZE 4071 +union uwsgi_sockaddr { + struct sockaddr sa; + struct sockaddr_in sa_in; + struct sockaddr_un sa_un; +}; + +union uwsgi_sockaddr_ptr { + struct sockaddr *sa; + struct sockaddr_in *sa_in; + struct sockaddr_un *sa_un; +}; + // Gateways are processes (managed by the master) that extends the // server core features // -- Gateways can prefork -- diff --git a/uwsgiconfig.py b/uwsgiconfig.py index c1efa712..75bb156c 100644 --- a/uwsgiconfig.py +++ b/uwsgiconfig.py @@ -12,7 +12,11 @@ import subprocess from distutils import sysconfig -import ConfigParser +try: + import ConfigParser +except: + import configparser as ConfigParser + from imp import reload GCC = os.environ.get('CC', sysconfig.get_config_var('CC')) if not GCC: @@ -29,6 +33,7 @@ def spcall(cmd): else: return None + def spcall2(cmd): p = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE) @@ -46,6 +51,7 @@ def add_o(x): x = x + '.o' return x + def compile(file, objfile, cflags): cmdline = "%s -c %s -o %s %s" % (GCC, cflags, objfile, file) print(cmdline) @@ -53,6 +59,7 @@ def compile(file, objfile, cflags): if ret != 0: sys.exit(1) + def build_uwsgi(uc): gcc_list, cflags, ldflags, libs = uc.get_gcll() @@ -71,7 +78,6 @@ def build_uwsgi(uc): cflags.append(epc) cflags.append(eplc) - print("*** uWSGI compiling server core ***") for file in gcc_list: objfile = file @@ -97,7 +103,8 @@ def build_uwsgi(uc): p_cflags += up.CFLAGS for cfile in up.GCC_LIST: - compile(' '.join(p_cflags), path + '/' + cfile + '.o', path + '/' + cfile + '.c') + compile(' '.join(p_cflags), + path + '/' + cfile + '.o', path + '/' + cfile + '.c') gcc_list.append('%s/%s' % (path, cfile)) libs += up.LIBS @@ -122,7 +129,8 @@ def build_uwsgi(uc): bin_name = uc.get('bin_name') print("*** uWSGI linking ***") - ldline = "%s -o %s %s %s %s" % (GCC, bin_name, ' '.join(ldflags), ' '.join(map(add_o, gcc_list)), ' '.join(libs)) + ldline = "%s -o %s %s %s %s" % (GCC, bin_name, ' '.join(ldflags), + ' '.join(map(add_o, gcc_list)), ' '.join(libs)) print(ldline) ret = os.system(ldline) if ret != 0: @@ -133,13 +141,15 @@ def build_uwsgi(uc): bin_name = './' + bin_name print("*** uWSGI is ready, launch it with %s ***" % bin_name) + class uConf(object): def __init__(self, filename): self.config = ConfigParser.ConfigParser() print("using profile: %s" % filename) self.config.read(filename) - self.gcc_list = ['utils', 'protocol', 'socket', 'logging', 'master', 'plugins', 'lock', 'cache', 'event', 'signal', 'rpc', 'gateway', 'loop', 'uwsgi'] + self.gcc_list = ['utils', 'protocol', 'socket', 'logging', 'master', + 'plugins', 'lock', 'cache', 'event', 'signal', 'rpc', 'gateway', 'loop', 'uwsgi'] self.cflags = ['-O2', '-Wall', '-Werror', '-D_LARGEFILE_SOURCE', '-D_FILE_OFFSET_BITS=64'] + os.environ.get("CFLAGS", "").split() try: gcc_version = str(spcall2("%s -v" % GCC)).split('\n')[-1].split()[2] @@ -171,10 +181,10 @@ class uConf(object): for opt in iconfig.options('uwsgi'): if not self.get(opt): self.set(opt, iconfig.get('uwsgi', opt)) - elif self.get(opt).startswith('+'): + elif self.get(opt).startswith('+'): self.set(opt, iconfig.get('uwsgi', opt) + self.get(opt)[1:]) - elif self.get(opt) == 'null': - self.config.remove_option('uwsgi', opt) + elif self.get(opt) == 'null': + self.config.remove_option('uwsgi', opt) def set(self, key, value):