changeset 139:a09bdbffbdec

Regenerate all patches and add forgotten patch files
author Franz Glasner <fzglas.hg@dom66.de>
date Sun, 25 Sep 2022 18:33:32 +0200
parents 0591ef28d649
children bbc009daf3c0
files uwsginl/files/patch-core-logging.c uwsginl/files/patch-plugins_coroae_uwsgiplugin.py uwsginl/files/patch-plugins_pypy_pypy__plugin.c uwsginl/files/patch-plugins_pypy_pypy__setup.py uwsginl/files/patch-uwsgiconfig.py
diffstat 5 files changed, 439 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/uwsginl/files/patch-core-logging.c	Sun Sep 25 18:04:55 2022 +0200
+++ b/uwsginl/files/patch-core-logging.c	Sun Sep 25 18:33:32 2022 +0200
@@ -1,6 +1,6 @@
---- core/logging.c.orig	2020-11-06 10:12:49.865752000 +0100
-+++ core/logging.c	2020-11-06 10:17:57.825745000 +0100
-@@ -536,13 +536,23 @@
+--- core/logging.c.orig	2022-09-21 14:46:45 UTC
++++ core/logging.c
+@@ -549,13 +549,23 @@ void uwsgi_log_do_rotate(char *logfile, char *rotatedf
  			uwsgi_error_open(logfile);
  			exit(1);
  		}
--- a/uwsginl/files/patch-plugins_coroae_uwsgiplugin.py	Sun Sep 25 18:04:55 2022 +0200
+++ b/uwsginl/files/patch-plugins_coroae_uwsgiplugin.py	Sun Sep 25 18:33:32 2022 +0200
@@ -1,6 +1,6 @@
---- plugins/coroae/uwsgiplugin.py.orig	2020-06-17 09:03:34 UTC
+--- plugins/coroae/uwsgiplugin.py.orig	2022-09-21 14:46:45 UTC
 +++ plugins/coroae/uwsgiplugin.py
-@@ -9,7 +9,7 @@ for p in search_paths:
+@@ -11,7 +11,7 @@ for p in search_paths:
          coroapi = p
  
  if not coroapi:
@@ -8,4 +8,4 @@
 +    print("unable to find the Coro perl module !!!")
      sys.exit(1)
  
- NAME='coroae'
+ CFLAGS = os.popen('perl -MExtUtils::Embed -e ccopts').read().rstrip().split()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/uwsginl/files/patch-plugins_pypy_pypy__plugin.c	Sun Sep 25 18:33:32 2022 +0200
@@ -0,0 +1,211 @@
+--- plugins/pypy/pypy_plugin.c.orig	2022-09-21 14:46:45 UTC
++++ plugins/pypy/pypy_plugin.c
+@@ -42,9 +42,10 @@ void (*uwsgi_pypy_hook_paste_loader)(char *);
+ void (*uwsgi_pypy_hook_pythonpath)(char *);
+ void (*uwsgi_pypy_hook_request)(void *, int);
+ void (*uwsgi_pypy_post_fork_hook)(void);
++void (*uwsgi_pypy_hook_atexit)(void);
+ 
+ extern struct uwsgi_server uwsgi;
+-struct uwsgi_plugin pypy_plugin;
++struct uwsgi_plugin pypy3_plugin;
+ 
+ static int uwsgi_pypy_init() {
+ 
+@@ -68,26 +69,26 @@ static int uwsgi_pypy_init() {
+ 		if (upypy.home) {
+ 			// first try with /bin way:
+ #ifdef __CYGWIN__
+-                        char *libpath = uwsgi_concat2(upypy.home, "/bin/libpypy-c.dll");
++			char *libpath = uwsgi_concat2(upypy.home, "/bin/libpypy3-c.so");
+ #elif defined(__APPLE__)
+-                        char *libpath = uwsgi_concat2(upypy.home, "/bin/libpypy-c.dylib");
++			char *libpath = uwsgi_concat2(upypy.home, "/bin/libpypy3-c.so");
+ #else
+-                        char *libpath = uwsgi_concat2(upypy.home, "/bin/libpypy-c.so");
++			char *libpath = uwsgi_concat2(upypy.home, "/bin/libpypy3-c.so");
+ #endif
+ 			if (uwsgi_file_exists(libpath)) {
+-                                upypy.handler = dlopen(libpath, RTLD_NOW | RTLD_GLOBAL);
+-                        }
+-                        free(libpath);
++				upypy.handler = dlopen(libpath, RTLD_NOW | RTLD_GLOBAL);
++			}
++			free(libpath);
+ 
+ 			// fallback to old-style way
+ 			if (!upypy.handler) {
+ 			
+ #ifdef __CYGWIN__
+-                        	char *libpath = uwsgi_concat2(upypy.home, "/libpypy-c.dll");
++				char *libpath = uwsgi_concat2(upypy.home, "/libpypy3-c.so");
+ #elif defined(__APPLE__)
+-                        	char *libpath = uwsgi_concat2(upypy.home, "/libpypy-c.dylib");
++				char *libpath = uwsgi_concat2(upypy.home, "/libpypy3-c.dylib");
+ #else
+-                        	char *libpath = uwsgi_concat2(upypy.home, "/libpypy-c.so");
++				char *libpath = uwsgi_concat2(upypy.home, "/libpypy3-c.so");
+ #endif
+ 				if (uwsgi_file_exists(libpath)) {
+ 					upypy.handler = dlopen(libpath, RTLD_NOW | RTLD_GLOBAL);
+@@ -98,11 +99,11 @@ static int uwsgi_pypy_init() {
+ 		// fallback to standard library search path
+ 		if (!upypy.handler) {
+ #ifdef __CYGWIN__
+-			upypy.handler = dlopen("libpypy-c.dll", RTLD_NOW | RTLD_GLOBAL);
++			upypy.handler = dlopen("libpypy3-c.dll", RTLD_NOW | RTLD_GLOBAL);
+ #elif defined(__APPLE__)
+-			upypy.handler = dlopen("libpypy-c.dylib", RTLD_NOW | RTLD_GLOBAL);
++			upypy.handler = dlopen("libpypy3-c.dylib", RTLD_NOW | RTLD_GLOBAL);
+ #else
+-			upypy.handler = dlopen("libpypy-c.so", RTLD_NOW | RTLD_GLOBAL);
++			upypy.handler = dlopen("libpypy3-c.so", RTLD_NOW | RTLD_GLOBAL);
+ #endif
+ 		}
+ 	}
+@@ -125,9 +126,9 @@ static int uwsgi_pypy_init() {
+ 	}
+ 
+ 	u_pypy_init_threads = dlsym(upypy.handler, "pypy_init_threads");
+-        if (!u_pypy_init_threads) {
+-                uwsgi_log("!!! WARNING your libpypy-c does not export pypy_init_threads, multithreading will not work !!!\n");
+-        }
++	if (!u_pypy_init_threads) {
++		uwsgi_log("!!! WARNING your libpypy-c does not export pypy_init_threads, multithreading will not work !!!\n");
++	}
+ 	
+ 	u_rpython_startup_code();
+ 
+@@ -148,9 +149,9 @@ static int uwsgi_pypy_init() {
+ 				goto ready;
+ 			}
+ 		}
+-                uwsgi_log("unable to set pypy home to \"%s\"\n", upypy.home);
++		uwsgi_log("unable to set pypy home to \"%s\"\n", upypy.home);
+ 		exit(1);
+-        }
++	}
+ 
+ ready:
+ 	u_pypy_execute_source = dlsym(upypy.handler, "pypy_execute_source");
+@@ -160,9 +161,9 @@ ready:
+ 	}
+ 
+ 	u_pypy_thread_attach = dlsym(upypy.handler, "pypy_thread_attach");
+-        if (!u_pypy_thread_attach) {
+-                uwsgi_log("!!! WARNING your libpypy-c does not export pypy_thread_attach, multithreading will not work !!!\n");
+-        }
++	if (!u_pypy_thread_attach) {
++		uwsgi_log("!!! WARNING your libpypy-c does not export pypy_thread_attach, multithreading will not work !!!\n");
++	}
+ 
+ 	if (upypy.setup) {
+ 		buffer = uwsgi_open_and_read(upypy.setup, &rlen, 1, NULL);
+@@ -233,14 +234,14 @@ static void uwsgi_pypy_preinit_apps() {
+ 
+ static int uwsgi_pypy_request(struct wsgi_request *wsgi_req) {
+ 	/* Standard WSGI request */
+-        if (!wsgi_req->len) {
+-                uwsgi_log( "Empty pypy request. skip.\n");
+-                return -1;
+-        }
++	if (!wsgi_req->len) {
++		uwsgi_log( "Empty pypy request. skip.\n");
++		return -1;
++	}
+ 
+-        if (uwsgi_parse_vars(wsgi_req)) {
+-                return -1;
+-        }
++	if (uwsgi_parse_vars(wsgi_req)) {
++		return -1;
++	}
+ 
+ 	if (uwsgi_pypy_hook_request) {
+ 		uwsgi_pypy_hook_request(wsgi_req, wsgi_req->async_id);
+@@ -266,16 +267,20 @@ static void uwsgi_pypy_init_apps() {
+ 	}
+ }
+ 
+-/*
++
+ static void uwsgi_pypy_atexit() {
+-	if (pypy_debug_file)
+-		fflush(pypy_debug_file);
++	/* NOTE: this function is NOT called when "skip-atexit = true" is configured */
++	if (!uwsgi_pypy_hook_atexit) {
++		uwsgi_log("!!! Your pypy setup does not define a uwsgi_pypy_atexit !!!\n");	       
++		return;
++	}	     
++	uwsgi_pypy_hook_atexit();
+ }
+-*/
+ 
++
+ static void uwsgi_opt_pypy_ini_paste(char *opt, char *value, void *foobar) {
+-        uwsgi_opt_load_ini(opt, value, NULL);
+-        upypy.paste = value;
++	uwsgi_opt_load_ini(opt, value, NULL);
++	upypy.paste = value;
+ }
+ 
+ 
+@@ -332,14 +337,14 @@ static void uwsgi_pypy_post_fork() {
+ 	pthread_mutex_init(&upypy.attach_thread_lock, NULL);
+ 	struct uwsgi_string_list *usl = NULL;
+ 	uwsgi_foreach(usl, upypy.eval_post_fork) {
+-                uwsgi_pypy_hook_execute_source(usl->value);
+-        }
++		uwsgi_pypy_hook_execute_source(usl->value);
++	}
+ 	uwsgi_foreach(usl, upypy.exec_post_fork) {
+-                size_t rlen = 0;
+-                char *buffer = uwsgi_open_and_read(usl->value, &rlen, 1, NULL);
+-                uwsgi_pypy_hook_execute_source(buffer);
+-                free(buffer);
+-        }
++		size_t rlen = 0;
++		char *buffer = uwsgi_open_and_read(usl->value, &rlen, 1, NULL);
++		uwsgi_pypy_hook_execute_source(buffer);
++		free(buffer);
++	}
+ 
+ 	if (uwsgi_pypy_post_fork_hook) {
+ 		uwsgi_pypy_post_fork_hook();
+@@ -360,20 +365,20 @@ static int uwsgi_pypy_mule(char *opt) {
+ 		exit(1);
+ 	}
+ 
+-        if (uwsgi_endswith(opt, ".py")) {
+-                size_t rlen = 0;
+-                char *buffer = uwsgi_open_and_read(opt, &rlen, 1, NULL);
+-                uwsgi_pypy_hook_execute_source(buffer);
++	if (uwsgi_endswith(opt, ".py")) {
++		size_t rlen = 0;
++		char *buffer = uwsgi_open_and_read(opt, &rlen, 1, NULL);
++		uwsgi_pypy_hook_execute_source(buffer);
+ 		free(buffer);
+-                return 1;
+-        }
+-        return 0;
++		return 1;
++	}
++	return 0;
+ 
+ }
+ 
+ 
+-struct uwsgi_plugin pypy_plugin = {
+-	.name = "pypy",
++struct uwsgi_plugin pypy3_plugin = {
++	.name = "pypy3",
+ 	.modifier1 = 0,
+ 	.on_load = uwsgi_pypy_onload,
+ 	.init = uwsgi_pypy_init,
+@@ -388,4 +393,6 @@ struct uwsgi_plugin pypy_plugin = {
+ 	.rpc = uwsgi_pypy_rpc,
+ 	.post_fork = uwsgi_pypy_post_fork,
+ 	.mule = uwsgi_pypy_mule,
++
++	.atexit = uwsgi_pypy_atexit,
+ };
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/uwsginl/files/patch-plugins_pypy_pypy__setup.py	Sun Sep 25 18:33:32 2022 +0200
@@ -0,0 +1,218 @@
+--- plugins/pypy/pypy_setup.py.orig	2022-09-21 14:46:45 UTC
++++ plugins/pypy/pypy_setup.py
+@@ -31,8 +31,15 @@ extern void (*uwsgi_pypy_hook_paste_loader)(char *);
+ extern void (*uwsgi_pypy_hook_pythonpath)(char *);
+ extern void (*uwsgi_pypy_hook_request)(struct wsgi_request *);
+ extern void (*uwsgi_pypy_post_fork_hook)(void);
++extern void (*uwsgi_pypy_hook_atexit)(void);
+ '''
+ 
++
++# Convert a byte string to a native string using the default encoding
++def n(b):
++    return b.decode()
++
++
+ # here we load CFLAGS and uwsgi.h from the binary
+ defines0 = '''
+ char *uwsgi_get_cflags();
+@@ -46,7 +53,7 @@ lib0 = ffi.verify(defines0)
+ # basically it build a list of #define from binary CFLAGS
+ uwsgi_cdef = []
+ uwsgi_defines = []
+-uwsgi_cflags = ffi.string(lib0.uwsgi_get_cflags()).split()
++uwsgi_cflags = n(ffi.string(lib0.uwsgi_get_cflags())).split()
+ for cflag in uwsgi_cflags:
+     if cflag.startswith('-D'):
+         line = cflag[2:]
+@@ -57,8 +64,14 @@ for cflag in uwsgi_cflags:
+         else:
+             uwsgi_cdef.append('#define %s ...' % line)
+             uwsgi_defines.append('#define %s 1' % line)
+-uwsgi_dot_h = ffi.string(lib0.uwsgi_get_dot_h())
++uwsgi_dot_h = n(ffi.string(lib0.uwsgi_get_dot_h()))
+ 
++#
++# Replace #include <pcre.h> on FreeBSD because it is found on a non-standard
++# location for cffi.
++#
++uwsgi_dot_h = uwsgi_dot_h.replace('#include <pcre.h>', '#include "/usr/local/include/pcre.h"')
++
+ # uwsgi definitions
+ cdefines = '''
+ %s
+@@ -110,6 +123,8 @@ struct uwsgi_worker {
+         uint64_t running_time;
+         uint64_t avg_response_time;
+         uint64_t tx;
++
++        int hijacked;
+         ...;
+ };
+ 
+@@ -164,11 +179,14 @@ struct uwsgi_server {
+         struct wsgi_request *wsgi_req;
+ 
+         struct uwsgi_plugin *p[];
++
++        int skip_atexit_teardown;
++
+         ...;
+ };
+ struct uwsgi_server uwsgi;
+ 
+-struct uwsgi_plugin pypy_plugin;
++struct uwsgi_plugin pypy3_plugin;
+ 
+ const char *uwsgi_pypy_version;
+ 
+@@ -269,7 +287,7 @@ const char *uwsgi_pypy_version = UWSGI_VERSION;
+ %s
+ 
+ extern struct uwsgi_server uwsgi;
+-extern struct uwsgi_plugin pypy_plugin;
++extern struct uwsgi_plugin pypy3_plugin;
+ %s
+ ''' % ('\n'.join(uwsgi_defines), uwsgi_dot_h, hooks)
+ 
+@@ -286,7 +304,7 @@ wsgi_application = None
+ 
+ # fix argv if needed
+ if len(sys.argv) == 0:
+-    sys.argv.insert(0, ffi.string(lib.uwsgi_binary_path()))
++    sys.argv.insert(0, n(ffi.string(lib.uwsgi_binary_path())))
+ 
+ 
+ @ffi.callback("void(char *)")
+@@ -305,7 +323,7 @@ def uwsgi_pypy_loader(module):
+     load a wsgi module
+     """
+     global wsgi_application
+-    m = ffi.string(module)
++    m = n(ffi.string(module))
+     c = 'application'
+     if ':' in m:
+         m, c = m.split(':')
+@@ -322,7 +340,7 @@ def uwsgi_pypy_file_loader(filename):
+     load a mod_wsgi compliant .wsgi file
+     """
+     global wsgi_application
+-    w = ffi.string(filename)
++    w = n(ffi.string(filename))
+     c = 'application'
+     mod = imp.load_source('uwsgi_file_wsgi', w)
+     wsgi_application = getattr(mod, c)
+@@ -334,7 +352,7 @@ def uwsgi_pypy_paste_loader(config):
+     load a .ini paste app
+     """
+     global wsgi_application
+-    c = ffi.string(config)
++    c = n(ffi.string(config))
+     if c.startswith('config:'):
+         c = c[7:]
+     if c[0] != '/':
+@@ -358,12 +376,47 @@ def uwsgi_pypy_post_fork_hook():
+         uwsgi.post_fork_hook()
+ 
+ 
++@ffi.callback("void()")
++def uwsgi_pypy_atexit():
++    """
++    .atexit handler implementation
++
++    Modelled after python_plugin.c
++    """
++    mywid = lib.uwsgi.mywid
++    if mywid > 0:
++        # if hijacked do not run atexit hooks
++        if lib.uwsgi.workers[mywid].hijacked:
++            return
++        # if busy do not run atexit hooks
++        if lib.uwsgi_worker_is_busy(mywid):
++            return
++        # managing atexit in async mode is a real pain...skip it for now
++        if lib.uwsgi.async > 0:
++            return
++
++    import uwsgi
++    uahandler = getattr(uwsgi, "atexit", None)
++    if callable(uahandler):
++        uahandler()
++
++    if lib.uwsgi.skip_atexit_teardown:
++        return
++
++    import atexit
++    aefn = getattr(atexit, "_run_exitfuncs", None)
++    if callable(aefn):
++        aefn()
++    else:
++        print("!!! atexit._run_exitfuncs() not found !!!")
++
++
+ @ffi.callback("void(char *)")
+ def uwsgi_pypy_pythonpath(item):
+     """
+     add an item to the pythonpath
+     """
+-    path = ffi.string(item)
++    path = n(ffi.string(item))
+     sys.path.append(path)
+     print("added %s to pythonpath" % path)
+ 
+@@ -470,15 +523,17 @@ def uwsgi_pypy_wsgi_handler(wsgi_req):
+     def start_response(status, headers, exc_info=None):
+         if exc_info:
+             traceback.print_exception(*exc_info)
++        status = status.encode("latin1")
+         lib.uwsgi_response_prepare_headers(wsgi_req, ffi.new("char[]", status), len(status))
+         for hh in headers:
++            hh = (hh[0].encode("latin1"), hh[1].encode("latin1"))
+             lib.uwsgi_response_add_header(wsgi_req, ffi.new("char[]", hh[0]), len(hh[0]), ffi.new("char[]", hh[1]), len(hh[1]))
+         return writer
+ 
+     environ = {}
+     iov = wsgi_req.hvec
+     for i in range(0, wsgi_req.var_cnt, 2):
+-        environ[ffi.string(ffi.cast("char*", iov[i].iov_base), iov[i].iov_len)] = ffi.string(ffi.cast("char*", iov[i+1].iov_base), iov[i+1].iov_len)
++        environ[ffi.string(ffi.cast("char*", iov[i].iov_base), iov[i].iov_len).decode("latin1")] = ffi.string(ffi.cast("char*", iov[i+1].iov_base), iov[i+1].iov_len).decode("latin1")
+ 
+     environ['wsgi.version'] = (1, 0)
+     scheme = 'http'
+@@ -523,6 +578,7 @@ lib.uwsgi_pypy_hook_paste_loader = uwsgi_pypy_paste_lo
+ lib.uwsgi_pypy_hook_pythonpath = uwsgi_pypy_pythonpath
+ lib.uwsgi_pypy_hook_request = uwsgi_pypy_wsgi_handler
+ lib.uwsgi_pypy_post_fork_hook = uwsgi_pypy_post_fork_hook
++lib.uwsgi_pypy_hook_atexit = uwsgi_pypy_atexit
+ 
+ """
+ Here we define the "uwsgi" virtual module
+@@ -537,7 +593,7 @@ uwsgi.hostname = ffi.string(lib.uwsgi.hostname)
+ def uwsgi_pypy_uwsgi_register_signal(signum, kind, handler):
+     cb = ffi.callback('void(int)', handler)
+     uwsgi_gc.append(cb)
+-    if lib.uwsgi_register_signal(signum, ffi.new("char[]", kind), cb, lib.pypy_plugin.modifier1) < 0:
++    if lib.uwsgi_register_signal(signum, ffi.new("char[]", kind), cb, lib.pypy3_plugin.modifier1) < 0:
+         raise Exception("unable to register signal %d" % signum)
+ uwsgi.register_signal = uwsgi_pypy_uwsgi_register_signal
+ 
+@@ -562,7 +618,7 @@ def uwsgi_pypy_uwsgi_register_rpc(name, func, argc=0):
+     rpc_func = uwsgi_pypy_RPC(func)
+     cb = ffi.callback("int(int, char*[], int[], char**)", rpc_func)
+     uwsgi_gc.append(cb)
+-    if lib.uwsgi_register_rpc(ffi.new("char[]", name), ffi.addressof(lib.pypy_plugin), argc, cb) < 0:
++    if lib.uwsgi_register_rpc(ffi.new("char[]", name), ffi.addressof(lib.pypy3_plugin), argc, cb) < 0:
+         raise Exception("unable to register rpc func %s" % name)
+ uwsgi.register_rpc = uwsgi_pypy_uwsgi_register_rpc
+ 
+@@ -598,8 +654,8 @@ uwsgi.rpc = uwsgi_pypy_rpc
+ 
+ def uwsgi_pypy_call(func, *args):
+     node = None
+-    if '@' in func:
+-        (func, node) = func.split('@')
++    if b'@' in func:
++        (func, node) = func.split(b'@')
+     return uwsgi_pypy_rpc(node, func, *args)
+ uwsgi.call = uwsgi_pypy_call
+ 
--- a/uwsginl/files/patch-uwsgiconfig.py	Sun Sep 25 18:04:55 2022 +0200
+++ b/uwsginl/files/patch-uwsgiconfig.py	Sun Sep 25 18:33:32 2022 +0200
@@ -1,6 +1,6 @@
---- uwsgiconfig.py.orig	2020-06-14 09:50:00 UTC
+--- uwsgiconfig.py.orig	2022-09-21 14:46:45 UTC
 +++ uwsgiconfig.py
-@@ -1494,7 +1494,8 @@ def build_plugin(path, uc, cflags, ldflags, libs, name
+@@ -1495,7 +1495,8 @@ def build_plugin(path, uc, cflags, ldflags, libs, name
              gcc_list.append(path + '/' + cfile)
      for bfile in up.get('BINARY_LIST', []):
          try:
@@ -8,9 +8,9 @@
 +            # See https://svnweb.freebsd.org/base/vendor/lld/dist-release_80/ELF/Driver.cpp?revision=344173&view=markup
 +            binary_link_cmd = "ld -r -b binary %s -o %s/%s.o %s/%s" % (get_default_target_emulation(), path, bfile[1], path, bfile[1])
              print(binary_link_cmd)
-             if os.system(binary_link_cmd) != 0:
+             if subprocess.call(binary_link_cmd, shell=True) != 0:
                  raise Exception('unable to link binary file')
-@@ -1590,6 +1591,17 @@ def build_plugin(path, uc, cflags, ldflags, libs, name
+@@ -1591,6 +1592,17 @@ def build_plugin(path, uc, cflags, ldflags, libs, name
  
      print("build time: %d seconds" % (time.time() - plugin_started_at))
      print("*** %s plugin built and available in %s ***" % (name, plugin_dest + '.so'))