Skip to content

Commit

Permalink
Merge pull request #2575 from xrmx/2.0.23-backports
Browse files Browse the repository at this point in the history
2.0.23 backports
  • Loading branch information
xrmx authored Nov 1, 2023
2 parents e7d3eda + ed4da62 commit f9e4f0e
Show file tree
Hide file tree
Showing 19 changed files with 227 additions and 80 deletions.
21 changes: 15 additions & 6 deletions .github/workflows/compile-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,31 @@ on:

jobs:
build:
strategy:
matrix:
include:
- os: ubuntu-20.04
php: "php7.4"
php-config: "php-config7.4"
- os: ubuntu-22.04
php: "php8.1"
php-config: "php-config8.1"

runs-on: ubuntu-20.04
runs-on: ${{ matrix.os }}

steps:
- name: remove sury php ppa that does not ship libphpX.Y-embed
run: |
sudo add-apt-repository --remove ppa:ondrej/php
sudo apt remove php7.4-dev php7.4 php7.4-common
sudo apt remove ${{ matrix.php }}-dev ${{ matrix.php }} ${{ matrix.php }}-common
- name: Install dependencies
run: |
sudo apt update -qq
sudo apt install --no-install-recommends -qqyf python3.8-dev \
sudo apt install --no-install-recommends -qqyf python3-dev \
libxml2-dev libpcre3-dev libcap2-dev \
libargon2-0-dev libsodium-dev \
php7.4-dev libphp7.4-embed \
liblua5.1-0-dev ruby2.7-dev \
${{ matrix.php }}-dev lib${{ matrix.php }}-embed \
liblua5.1-0-dev ruby-dev \
libjansson-dev libldap2-dev libpq-dev \
libpam0g-dev libsqlite3-dev libyaml-dev \
libzmq3-dev libmatheval-dev libperl-dev \
Expand All @@ -37,7 +46,7 @@ jobs:
curl check
- uses: actions/checkout@v2
- name: Build kitchensink uWSGI binary
run: UWSGICONFIG_PHPPATH=php-config7.4 /usr/bin/python3 uwsgiconfig.py --build travis
run: UWSGICONFIG_PHPPATH=${{ matrix.php-config }} /usr/bin/python3 uwsgiconfig.py --build travis
- name: Build uWSGI binary
run: |
/usr/bin/python3 uwsgiconfig.py --build base
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: ["2.7", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["2.7", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
test-suite: [unittest, python, deadlocks]
steps:
- name: Add deadnakes ppa
Expand All @@ -24,7 +24,7 @@ jobs:
libpcre3-dev libjansson-dev libcap2-dev \
curl check
- name: Install distutils
if: contains(fromJson('["3.6","3.7","3.8","3.9","3.10","3.11"]'), matrix.python-version)
if: contains(fromJson('["3.6","3.7","3.8","3.9","3.10","3.11","3.12"]'), matrix.python-version)
run: |
sudo apt install --no-install-recommends -qqyf python${{ matrix.python-version }}-distutils \
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 1.0
Name: uWSGI
Version: 2.0.22
Version: 2.0.23
Summary: The uWSGI server
Home-page: https://uwsgi-docs.readthedocs.io/en/latest/
Author: Unbit
Expand Down
5 changes: 0 additions & 5 deletions core/lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ struct uwsgi_lock_item *uwsgi_lock_fast_init(char *id) {
}

#ifdef EOWNERDEAD
#ifndef PTHREAD_MUTEX_ROBUST
#define PTHREAD_MUTEX_ROBUST PTHREAD_MUTEX_ROBUST_NP
#define pthread_mutexattr_setrobust pthread_mutexattr_setrobust_np
#define pthread_mutex_consistent pthread_mutex_consistent_np
#endif
if (uwsgi_pthread_robust_mutexes_enabled) {
int ret;
if ((ret = pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT)) != 0) {
Expand Down
18 changes: 15 additions & 3 deletions plugins/asyncio/uwsgiplugin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
from distutils import sysconfig
try:
from distutils import sysconfig
paths = [
sysconfig.get_python_inc(),
sysconfig.get_python_inc(plat_specific=True),
]
except ImportError:
import sysconfig
paths = [
sysconfig.get_path('include'),
sysconfig.get_path('platinclude'),
]

NAME='asyncio'
CFLAGS = ['-I' + sysconfig.get_python_inc(), '-I' + sysconfig.get_python_inc(plat_specific=True)]
NAME = 'asyncio'

CFLAGS = ['-I' + path for path in paths]
LDFLAGS = []
LIBS = []

Expand Down
18 changes: 15 additions & 3 deletions plugins/gevent/uwsgiplugin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
from distutils import sysconfig
try:
from distutils import sysconfig
paths = [
sysconfig.get_python_inc(),
sysconfig.get_python_inc(plat_specific=True),
]
except ImportError:
import sysconfig
paths = [
sysconfig.get_path('include'),
sysconfig.get_path('platinclude'),
]

NAME='gevent'
CFLAGS = ['-I' + sysconfig.get_python_inc(), '-I' + sysconfig.get_python_inc(plat_specific=True)]
NAME = 'gevent'

CFLAGS = ['-I' + path for path in paths]
LDFLAGS = []
LIBS = []

Expand Down
18 changes: 15 additions & 3 deletions plugins/greenlet/uwsgiplugin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
from distutils import sysconfig
try:
from distutils import sysconfig
paths = [
sysconfig.get_python_inc(),
sysconfig.get_python_inc(plat_specific=True),
]
except ImportError:
import sysconfig
paths = [
sysconfig.get_path('include'),
sysconfig.get_path('platinclude'),
]

NAME='greenlet'
CFLAGS = ['-I' + sysconfig.get_python_inc(), '-I' + sysconfig.get_python_inc(plat_specific=True)]
NAME = 'greenlet'

CFLAGS = ['-I' + path for path in paths]
LDFLAGS = []
LIBS = []

Expand Down
2 changes: 1 addition & 1 deletion plugins/jvm/uwsgiplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
for jvm in known_jvms:
if os.path.exists(jvm + '/include'):
JVM_INCPATH = ["-I%s/include/" % jvm, "-I%s/include/%s" % (jvm, operating_system)]
if os.path.exists("%s/jre"):
if os.path.exists("%s/jre" % jvm):
JVM_LIBPATH = ["-L%s/jre/lib/%s/server" % (jvm, arch)]
else:
JVM_LIBPATH = ["-L%s/lib/server" % (jvm,)]
Expand Down
18 changes: 10 additions & 8 deletions plugins/php/php_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct uwsgi_php {
char *fallback;
char *fallback2;
char *fallback_qs;
char *ini_entries;
size_t ini_size;
int dump_config;
char *server_software;
Expand Down Expand Up @@ -222,21 +223,22 @@ static sapi_module_struct uwsgi_sapi_module;

void uwsgi_php_append_config(char *filename) {
size_t file_size = 0;
char *file_content = uwsgi_open_and_read(filename, &file_size, 1, NULL);
uwsgi_sapi_module.ini_entries = realloc(uwsgi_sapi_module.ini_entries, uphp.ini_size + file_size);
memcpy(uwsgi_sapi_module.ini_entries + uphp.ini_size, file_content, file_size);
char *file_content = uwsgi_open_and_read(filename, &file_size, 1, NULL);
uphp.ini_entries = realloc(uphp.ini_entries, uphp.ini_size + file_size);
memcpy(uphp.ini_entries + uphp.ini_size, file_content, file_size);
uphp.ini_size += file_size-1;
free(file_content);
uwsgi_sapi_module.ini_entries = uphp.ini_entries;
}

void uwsgi_php_set(char *opt) {

uwsgi_sapi_module.ini_entries = realloc(uwsgi_sapi_module.ini_entries, uphp.ini_size + strlen(opt)+2);
memcpy(uwsgi_sapi_module.ini_entries + uphp.ini_size, opt, strlen(opt));

uphp.ini_entries = realloc(uphp.ini_entries, uphp.ini_size + strlen(opt)+2);
memcpy(uphp.ini_entries + uphp.ini_size, opt, strlen(opt));
uphp.ini_size += strlen(opt)+1;
uwsgi_sapi_module.ini_entries[uphp.ini_size-1] = '\n';
uwsgi_sapi_module.ini_entries[uphp.ini_size] = 0;
uphp.ini_entries[uphp.ini_size-1] = '\n';
uphp.ini_entries[uphp.ini_size] = 0;
uwsgi_sapi_module.ini_entries = uphp.ini_entries;
}

extern ps_module ps_mod_uwsgi;
Expand Down
74 changes: 54 additions & 20 deletions plugins/python/python_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,21 @@ void uwsgi_python_pthread_child(void) {
PyMethodDef uwsgi_spit_method[] = { {"uwsgi_spit", py_uwsgi_spit, METH_VARARGS, ""} };
PyMethodDef uwsgi_write_method[] = { {"uwsgi_write", py_uwsgi_write, METH_VARARGS, ""} };

PyDoc_STRVAR(uwsgi_py_doc, "uWSGI api module.");

#ifdef PYTHREE
static PyModuleDef uwsgi_module3 = {
PyModuleDef_HEAD_INIT,
"uwsgi",
uwsgi_py_doc,
-1,
NULL,
};
PyObject *init_uwsgi3(void) {
return PyModule_Create(&uwsgi_module3);
}
#endif

int uwsgi_python_init() {

char *pyversion = strchr(Py_GetVersion(), '\n');
Expand Down Expand Up @@ -261,6 +276,9 @@ int uwsgi_python_init() {
wchar_t *pname = uwsgi_calloc(sizeof(wchar_t) * (strlen(program_name)+1));
mbstowcs(pname, program_name, strlen(program_name)+1);
Py_SetProgramName(pname);
#ifdef UWSGI_PY312
PyImport_AppendInittab("uwsgi", init_uwsgi3);
#endif
#else
Py_SetProgramName(program_name);
#endif
Expand Down Expand Up @@ -623,21 +641,6 @@ void init_uwsgi_vars() {



PyDoc_STRVAR(uwsgi_py_doc, "uWSGI api module.");

#ifdef PYTHREE
static PyModuleDef uwsgi_module3 = {
PyModuleDef_HEAD_INIT,
"uwsgi",
uwsgi_py_doc,
-1,
NULL,
};
PyObject *init_uwsgi3(void) {
return PyModule_Create(&uwsgi_module3);
}
#endif

void init_uwsgi_embedded_module() {
PyObject *new_uwsgi_module, *zero;
int i;
Expand All @@ -658,7 +661,9 @@ void init_uwsgi_embedded_module() {


#ifdef PYTHREE
#ifndef UWSGI_PY312
PyImport_AppendInittab("uwsgi", init_uwsgi3);
#endif
new_uwsgi_module = PyImport_AddModule("uwsgi");
#else
new_uwsgi_module = Py_InitModule3("uwsgi", NULL, uwsgi_py_doc);
Expand Down Expand Up @@ -1161,7 +1166,10 @@ void uwsgi_python_init_apps() {

// prepare for stack suspend/resume
if (uwsgi.async > 1) {
#ifdef UWSGI_PY311
#ifdef UWSGI_PY312
up.current_c_recursion_remaining = uwsgi_malloc(sizeof(int)*uwsgi.async);
up.current_py_recursion_remaining = uwsgi_malloc(sizeof(int)*uwsgi.async);
#elif defined UWSGI_PY311
up.current_recursion_remaining = uwsgi_malloc(sizeof(int)*uwsgi.async);
#else
up.current_recursion_depth = uwsgi_malloc(sizeof(int)*uwsgi.async);
Expand Down Expand Up @@ -1324,7 +1332,12 @@ void uwsgi_python_pre_uwsgi_fork() {
// Acquire the gil and import lock before forking in order to avoid
// deadlocks in workers
UWSGI_GET_GIL
#if defined UWSGI_PY312
PyInterpreterState *interp = PyInterpreterState_Get();
_PyImport_AcquireLock(interp);
#else
_PyImport_AcquireLock();
#endif
}
}

Expand All @@ -1336,7 +1349,12 @@ void uwsgi_python_post_uwsgi_fork(int step) {
if (uwsgi.has_threads) {
if (step == 0) {
// Release locks within master process
#if defined UWSGI_PY312
PyInterpreterState *interp = PyInterpreterState_Get();
_PyImport_ReleaseLock(interp);
#else
_PyImport_ReleaseLock();
#endif
UWSGI_RELEASE_GIL
}
else {
Expand Down Expand Up @@ -1592,7 +1610,11 @@ void uwsgi_python_suspend(struct wsgi_request *wsgi_req) {
PyGILState_Release(pgst);

if (wsgi_req) {
#ifdef UWSGI_PY311
#ifdef UWSGI_PY312
up.current_c_recursion_remaining[wsgi_req->async_id] = tstate->c_recursion_remaining;
up.current_py_recursion_remaining[wsgi_req->async_id] = tstate->py_recursion_remaining;
up.current_frame[wsgi_req->async_id] = tstate->cframe;
#elif defined UWSGI_PY311
up.current_recursion_remaining[wsgi_req->async_id] = tstate->recursion_remaining;
up.current_frame[wsgi_req->async_id] = tstate->cframe;
#else
Expand All @@ -1601,7 +1623,11 @@ void uwsgi_python_suspend(struct wsgi_request *wsgi_req) {
#endif
}
else {
#ifdef UWSGI_PY311
#ifdef UWSGI_PY312
up.current_main_c_recursion_remaining = tstate->c_recursion_remaining;
up.current_main_py_recursion_remaining = tstate->py_recursion_remaining;
up.current_main_frame = tstate->cframe;
#elif defined UWSGI_PY311
up.current_main_recursion_remaining = tstate->recursion_remaining;
up.current_main_frame = tstate->cframe;
#else
Expand Down Expand Up @@ -1835,7 +1861,11 @@ void uwsgi_python_resume(struct wsgi_request *wsgi_req) {
PyGILState_Release(pgst);

if (wsgi_req) {
#ifdef UWSGI_PY311
#ifdef UWSGI_PY312
tstate->c_recursion_remaining = up.current_c_recursion_remaining[wsgi_req->async_id];
tstate->py_recursion_remaining = up.current_py_recursion_remaining[wsgi_req->async_id];
tstate->cframe = up.current_frame[wsgi_req->async_id];
#elif defined UWSGI_PY311
tstate->recursion_remaining = up.current_recursion_remaining[wsgi_req->async_id];
tstate->cframe = up.current_frame[wsgi_req->async_id];
#else
Expand All @@ -1844,7 +1874,11 @@ void uwsgi_python_resume(struct wsgi_request *wsgi_req) {
#endif
}
else {
#ifdef UWSGI_PY311
#ifdef UWSGI_PY312
tstate->c_recursion_remaining = up.current_main_c_recursion_remaining;
tstate->py_recursion_remaining = up.current_main_py_recursion_remaining;
tstate->cframe = up.current_main_frame;
#elif defined UWSGI_PY311
tstate->recursion_remaining = up.current_main_recursion_remaining;
tstate->cframe = up.current_main_frame;
#else
Expand Down
14 changes: 13 additions & 1 deletion plugins/python/uwsgi_python.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
# define UWSGI_PY311
#endif

#if (PY_VERSION_HEX >= 0x030c0000)
# define UWSGI_PY312
#endif

#if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 7
#define HAS_NOT_PyMemoryView_FromBuffer
#endif
Expand Down Expand Up @@ -168,7 +172,15 @@ struct uwsgi_python {

char *callable;

#ifdef UWSGI_PY311
#ifdef UWSGI_PY312
int *current_c_recursion_remaining;
int *current_py_recursion_remaining;
_PyCFrame **current_frame;

int current_main_c_recursion_remaining;
int current_main_py_recursion_remaining;
_PyCFrame *current_main_frame;
#elif defined UWSGI_PY311
int *current_recursion_remaining;
_PyCFrame **current_frame;

Expand Down
Loading

0 comments on commit f9e4f0e

Please sign in to comment.