mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-09-05 05:01:36 +00:00
sharedarea can be mapped to generic objects
This commit is contained in:
@@ -164,6 +164,10 @@ struct uwsgi_option uwsgi_python_options[] = {
|
||||
|
||||
{"python-raw", required_argument, 0, "load a python file for managing raw requests", uwsgi_opt_set_str, &up.raw, 0},
|
||||
|
||||
#if defined(PYTHREE) || defined(Py_TPFLAGS_HAVE_NEWBUFFER)
|
||||
{"py-sharedarea", required_argument, 0, "create a sharedarea from a python bytearray object of the specified size", uwsgi_opt_add_string_list, &up.sharedarea, 0},
|
||||
#endif
|
||||
|
||||
{0, 0, 0, 0, 0, 0, 0},
|
||||
};
|
||||
|
||||
@@ -263,6 +267,17 @@ pep405:
|
||||
up.swap_ts = simple_swap_ts;
|
||||
up.reset_ts = simple_reset_ts;
|
||||
|
||||
#if defined(PYTHREE) || defined(Py_TPFLAGS_HAVE_NEWBUFFER)
|
||||
struct uwsgi_string_list *usl = NULL;
|
||||
uwsgi_foreach(usl, up.sharedarea) {
|
||||
uint64_t len = uwsgi_n64(usl->value);
|
||||
PyObject *obj = PyByteArray_FromStringAndSize(NULL, len);
|
||||
char *storage = PyByteArray_AsString(obj);
|
||||
Py_INCREF(obj);
|
||||
struct uwsgi_sharedarea *sa = uwsgi_sharedarea_init_ptr(storage, len);
|
||||
sa->obj = obj;
|
||||
}
|
||||
#endif
|
||||
|
||||
uwsgi_log_initial("Python main interpreter initialized at %p\n", up.main_thread);
|
||||
|
||||
|
||||
@@ -1708,6 +1708,18 @@ PyObject *py_uwsgi_sharedarea_memoryview(PyObject * self, PyObject * args) {
|
||||
return PyErr_Format(PyExc_ValueError, "cannot get a memoryview object from sharedarea %d", id);
|
||||
return PyMemoryView_FromBuffer(&info);
|
||||
}
|
||||
|
||||
PyObject *py_uwsgi_sharedarea_object(PyObject * self, PyObject * args) {
|
||||
int id;
|
||||
if (!PyArg_ParseTuple(args, "i:sharedarea_object", &id)) {
|
||||
return NULL;
|
||||
}
|
||||
struct uwsgi_sharedarea *sa = uwsgi_sharedarea_get_by_id(id, 0);
|
||||
if (!sa) {
|
||||
return PyErr_Format(PyExc_ValueError, "cannot get an object from sharedarea %d", id);
|
||||
}
|
||||
return (PyObject *) sa->obj;
|
||||
}
|
||||
#endif
|
||||
|
||||
PyObject *py_uwsgi_spooler_freq(PyObject * self, PyObject * args) {
|
||||
@@ -2599,6 +2611,7 @@ static PyMethodDef uwsgi_sa_methods[] = {
|
||||
{"sharedarea_unlock", py_uwsgi_sharedarea_unlock, METH_VARARGS, ""},
|
||||
#if defined(PYTHREE) || defined(Py_TPFLAGS_HAVE_NEWBUFFER)
|
||||
{"sharedarea_memoryview", py_uwsgi_sharedarea_memoryview, METH_VARARGS, ""},
|
||||
{"sharedarea_object", py_uwsgi_sharedarea_object, METH_VARARGS, ""},
|
||||
#endif
|
||||
{NULL, NULL},
|
||||
};
|
||||
|
||||
@@ -191,6 +191,8 @@ struct uwsgi_python {
|
||||
|
||||
char *raw;
|
||||
PyObject *raw_callable;
|
||||
|
||||
struct uwsgi_string_list *sharedarea;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user