You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mod_python-commits@quetz.apache.org by gr...@apache.org on 2006/08/20 09:52:38 UTC
svn commit: r432952 - in /httpd/mod_python/trunk: Doc/appendixc.tex
src/include/mod_python.h src/include/mod_python.h.in src/mod_python.c
Author: grahamd
Date: Sun Aug 20 00:52:36 2006
New Revision: 432952
URL: http://svn.apache.org/viewvc?rev=432952&view=rev
Log:
(MODPYTHON-165) Exported functions from mod_python module to be used in
other third party modules for Apache. The purpose of these functions is to
allow those other modules to access the mechanics of how mod_python creates
interpreters, thereby allowing other modules to also embed Python and for
there not to be a conflict with mod_python.
Modified:
httpd/mod_python/trunk/Doc/appendixc.tex
httpd/mod_python/trunk/src/include/mod_python.h
httpd/mod_python/trunk/src/include/mod_python.h.in
httpd/mod_python/trunk/src/mod_python.c
Modified: httpd/mod_python/trunk/Doc/appendixc.tex
URL: http://svn.apache.org/viewvc/httpd/mod_python/trunk/Doc/appendixc.tex?rev=432952&r1=432951&r2=432952&view=diff
==============================================================================
--- httpd/mod_python/trunk/Doc/appendixc.tex (original)
+++ httpd/mod_python/trunk/Doc/appendixc.tex Sun Aug 20 00:52:36 2006
@@ -68,6 +68,13 @@
\code{req.register_output_filter()} methods can now take a direct
reference to a callable object as well a string which refers to a
module or module::function combination by name.
+ \item
+ (\citetitle[http://issues.apache.org/jira/browse/MODPYTHON-165]{MODPYTHON-165})
+ Exported functions from mod_python module to be used in other third
+ party modules for Apache. The purpose of these functions is to allow
+ those other modules to access the mechanics of how mod_python creates
+ interpreters, thereby allowing other modules to also embed Python
+ and for there not to be a conflict with mod_python.
\end{itemize}
Improvements
Modified: httpd/mod_python/trunk/src/include/mod_python.h
URL: http://svn.apache.org/viewvc/httpd/mod_python/trunk/src/include/mod_python.h?rev=432952&r1=432951&r2=432952&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/include/mod_python.h (original)
+++ httpd/mod_python/trunk/src/include/mod_python.h Sun Aug 20 00:52:36 2006
@@ -207,6 +207,12 @@
PyObject* python_interpreter_name(void);
requestobject *python_get_request_object(request_rec *req, const char *phase);
+APR_DECLARE_OPTIONAL_FN(PyInterpreterState *, mp_acquire_interpreter, (const char *));
+APR_DECLARE_OPTIONAL_FN(void *, mp_release_interpreter, ());
+APR_DECLARE_OPTIONAL_FN(PyObject *, mp_get_request_object, (request_rec *));
+APR_DECLARE_OPTIONAL_FN(PyObject *, mp_get_server_object, (server_rec *));
+APR_DECLARE_OPTIONAL_FN(PyObject *, mp_get_connection_object, (conn_rec *));
+
#endif /* !Mp_MOD_PYTHON_H */
/*
Modified: httpd/mod_python/trunk/src/include/mod_python.h.in
URL: http://svn.apache.org/viewvc/httpd/mod_python/trunk/src/include/mod_python.h.in?rev=432952&r1=432951&r2=432952&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/include/mod_python.h.in (original)
+++ httpd/mod_python/trunk/src/include/mod_python.h.in Sun Aug 20 00:52:36 2006
@@ -207,6 +207,12 @@
PyObject* python_interpreter_name(void);
requestobject *python_get_request_object(request_rec *req, const char *phase);
+APR_DECLARE_OPTIONAL_FN(PyInterpreterState *, mp_acquire_interpreter, (const char *));
+APR_DECLARE_OPTIONAL_FN(void *, mp_release_interpreter, ());
+APR_DECLARE_OPTIONAL_FN(PyObject *, mp_get_request_object, (request_rec *));
+APR_DECLARE_OPTIONAL_FN(PyObject *, mp_get_server_object, (server_rec *));
+APR_DECLARE_OPTIONAL_FN(PyObject *, mp_get_connection_object, (conn_rec *));
+
#endif /* !Mp_MOD_PYTHON_H */
/*
Modified: httpd/mod_python/trunk/src/mod_python.c
URL: http://svn.apache.org/viewvc/httpd/mod_python/trunk/src/mod_python.c?rev=432952&r1=432951&r2=432952&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/mod_python.c (original)
+++ httpd/mod_python/trunk/src/mod_python.c Sun Aug 20 00:52:36 2006
@@ -51,7 +51,7 @@
* Creates a new Python interpreter.
*/
-static PyInterpreterState *make_interpreter(const char *name, server_rec *srv)
+static PyInterpreterState *make_interpreter(const char *name)
{
PyThreadState *tstate;
@@ -60,7 +60,7 @@
if (! tstate) {
/* couldn't create an interpreter, this is bad */
- ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, srv,
+ ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, main_server,
"make_interpreter: Py_NewInterpreter() returned NULL. No more memory?");
return NULL;
}
@@ -85,7 +85,7 @@
* the reference to obCallBack.
*/
-static PyObject * make_obcallback(char *name, server_rec *s)
+static PyObject * make_obcallback(char *name)
{
PyObject *m = NULL;
@@ -107,7 +107,7 @@
if (! ((m = PyImport_ImportModule(MODULENAME)))) {
PyObject *path;
- ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, s,
+ ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, main_server,
"make_obcallback: could not import %s.\n",
(!MODULENAME) ? "<null>" : MODULENAME);
@@ -116,7 +116,7 @@
path = PyObject_Repr(PySys_GetObject("path"));
- ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, s,
+ ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, main_server,
"make_obcallback: Python path being used \"%s\".",
PyString_AsString(path));
@@ -134,7 +134,7 @@
PyObject *d = NULL;
PyObject *f = NULL;
- ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, s,
+ ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, main_server,
"make_obcallback: could not call %s.\n",
(!INITFUNC) ? "<null>" : INITFUNC);
@@ -153,10 +153,10 @@
}
if (strcmp(mp_compile_version, mp_dynamic_version) != 0) {
- ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, s,
+ ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, main_server,
"make_obcallback: mod_python version mismatch, expected '%s', found '%s'.",
mp_compile_version, mp_dynamic_version);
- ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, s,
+ ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, main_server,
"make_obcallback: mod_python modules location '%s'.",
PyString_AsString(f));
}
@@ -227,7 +227,7 @@
* NOTE: This function will acquire lock
*/
-static interpreterdata *get_interpreter(const char *name, server_rec *srv)
+static interpreterdata *get_interpreter(const char *name)
{
PyObject *p;
PyThreadState *tstate;
@@ -244,7 +244,7 @@
#endif
if (!interpreters) {
- ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, srv,
+ ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, main_server,
"get_interpreter: interpreters dictionary not initialised.");
return NULL;
}
@@ -252,7 +252,7 @@
p = PyDict_GetItemString(interpreters, (char *)name);
if (!p)
{
- PyInterpreterState *istate = make_interpreter(name, srv);
+ PyInterpreterState *istate = make_interpreter(name);
if (istate)
idata = save_interpreter(name, istate);
@@ -266,7 +266,7 @@
#endif
if (! idata) {
- ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, srv,
+ ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, main_server,
"get_interpreter: cannot get interpreter data (no more memory?)");
#if APR_HAS_THREADS
apr_thread_mutex_unlock(interpreters_lock);
@@ -284,7 +284,7 @@
if (!idata->obcallback) {
- idata->obcallback = make_obcallback((char*)name,srv);
+ idata->obcallback = make_obcallback((char*)name);
if (!idata->obcallback)
{
@@ -294,7 +294,7 @@
PyThreadState_Swap(NULL);
#endif
PyThreadState_Delete(tstate);
- ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, srv,
+ ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, main_server,
"get_interpreter: no interpreter callback found.");
#if APR_HAS_THREADS
apr_thread_mutex_unlock(interpreters_lock);
@@ -345,10 +345,7 @@
cleanup_info *ci = (cleanup_info *)data;
/* get/create interpreter */
- if (ci->request_rec)
- idata = get_interpreter(ci->interpreter, ci->request_rec->server);
- else
- idata = get_interpreter(ci->interpreter, ci->server_rec);
+ idata = get_interpreter(ci->interpreter);
if (!idata) {
Py_DECREF(ci->handler);
@@ -639,6 +636,73 @@
return glb;
}
+/*
+ * mp_acquire_interpreter()
+ *
+ * Exported function for acquiring named interpreter.
+ */
+
+PyInterpreterState *mp_acquire_interpreter(const char *name)
+{
+ interpreterdata *idata;
+
+ idata = get_interpreter(name);
+
+ return idata->istate;
+}
+
+/*
+ * mp_release_interpreter()
+ *
+ * Exported function for releasing acquired interpreter.
+ *
+ */
+
+void mp_release_interpreter(void)
+{
+ release_interpreter();
+}
+
+/*
+ * mp_get_request_object(request_rec *req)
+ *
+ * Exported function for obtaining wrapper for request object.
+ *
+ */
+
+PyObject *mp_get_request_object(request_rec *req)
+{
+ requestobject *request_obj;
+
+ request_obj = python_get_request_object(req, 0);
+
+ return (PyObject *)request_obj;
+}
+
+/*
+ * mp_get_server_object(server_rec *srv)
+ *
+ * Exported function for obtaining wrapper for server object.
+ *
+ */
+
+PyObject *mp_get_server_object(server_rec *srv)
+{
+ return (PyObject *)MpServer_FromServer(srv);
+}
+
+/*
+ * mp_get_connection_object(conn_rec *conn)
+ *
+ * Exported function for obtaining wrapper for connection object.
+ *
+ */
+
+PyObject *mp_get_connection_object(conn_rec *conn)
+{
+ return (PyObject *)MpConn_FromConn(conn);
+}
+
/**
** python_init()
**
@@ -738,6 +802,13 @@
PyEval_ReleaseLock();
#endif
}
+
+ APR_REGISTER_OPTIONAL_FN(mp_acquire_interpreter);
+ APR_REGISTER_OPTIONAL_FN(mp_release_interpreter);
+ APR_REGISTER_OPTIONAL_FN(mp_get_request_object);
+ APR_REGISTER_OPTIONAL_FN(mp_get_server_object);
+ APR_REGISTER_OPTIONAL_FN(mp_get_connection_object);
+
return OK;
}
@@ -1436,7 +1507,7 @@
interp_name = select_interp_name(req, NULL, conf, hlohle, NULL);
/* get/create interpreter */
- idata = get_interpreter(interp_name, req->server);
+ idata = get_interpreter(interp_name);
if (!idata) {
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, req,
@@ -1575,7 +1646,7 @@
requestobject *request_obj = req_config->request_obj;
/* get interpreter */
- idata = get_interpreter(NULL, req->server);
+ idata = get_interpreter(NULL);
if (!idata)
return APR_SUCCESS; /* this return code is ignored by httpd anyway */
@@ -1623,7 +1694,7 @@
interp_name = select_interp_name(NULL, con, conf, hle, NULL);
/* get/create interpreter */
- idata = get_interpreter(interp_name, con->base_server);
+ idata = get_interpreter(interp_name);
if (!idata) {
ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, con->base_server,
@@ -1745,7 +1816,7 @@
interp_name = select_interp_name(req, NULL, conf, NULL, fh);
/* get/create interpreter */
- idata = get_interpreter(interp_name, req->server);
+ idata = get_interpreter(interp_name);
if (!idata) {
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, req,
@@ -1920,7 +1991,7 @@
interp_name = select_interp_name(req, NULL, conf, NULL, NULL);
/* get/create interpreter */
- idata = get_interpreter(interp_name, req->server);
+ idata = get_interpreter(interp_name);
if (!idata) {
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, req,
@@ -2061,7 +2132,7 @@
interp_name = select_interp_name(req, NULL, conf, NULL, NULL);
/* get/create interpreter */
- idata = get_interpreter(interp_name, req->server);
+ idata = get_interpreter(interp_name);
if (!idata) {
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, req,
@@ -2491,7 +2562,7 @@
{
interpreterdata *idata;
- idata = get_interpreter(NULL, NULL);
+ idata = get_interpreter(NULL);
if (idata) {
@@ -2605,7 +2676,7 @@
const char *ppath;
/* get interpreter */
- idata = get_interpreter(interp_name, s);
+ idata = get_interpreter(interp_name);
if (!idata)
return;