|
Graham Dumpleton
grahamd at dscpl.com.au
Sun Aug 20 05:44:53 EDT 2006
On 20/08/2006, at 6:25 PM, Graham Dumpleton wrote:
>
> On 20/08/2006, at 6:08 PM, Graham Dumpleton wrote:
>
>> Have been busy and have added minimal set of functions to mod_python
>> and exporting them for use in other modules. This code is now checked
>> into subversion trunk for 3.3.
>>
>> As an example, here is how it could be used:
>
> And here is a replacement example that fixes up some stupid mistakes
> with cleaning up data.
>
> optfn_mp_acquire_interpreter("main_interpreter");
>
> request_obj = optfn_mp_get_request_object(r);
>
> m = PyImport_ImportModule("mod_python.testhandler");
> if (m) {
> d = PyModule_GetDict(m);
> o = PyDict_GetItemString(d, "handler");
>
> if (o) {
> PyObject *a = NULL;
> PyObject *r = NULL;
>
> a = Py_BuildValue("(O)", request_obj);
> r = PyEval_CallObject(o, a);
>
> Py_DECREF(a);
>
> if (r == NULL)
> result = HTTP_INTERNAL_SERVER_ERROR;
> else if (!PyInt_Check(r))
> result = HTTP_INTERNAL_SERVER_ERROR;
> else
> result = PyInt_AsLong(r);
>
> Py_XDECREF(r);
> }
> else {
> result = HTTP_INTERNAL_SERVER_ERROR;
> }
> }
> else {
> result = HTTP_INTERNAL_SERVER_ERROR;
> }
>
> Py_XDECREF(m);
> Py_XDECREF(o);
>
> Py_XDECREF(request_obj);
Whoops (AGAIN).
Neither 'o' or 'request_obj' should be DECREF'd. This is because 'o' is
a borrowed reference, and 'request_obj' is destroyed automatically when
the cleanup handler runs.
I'll fix attachment to issue after a bit more testing. Works like a
charm now,
problem only showed up when mixing requests against this code with
requests against standard mod_python handlers. :-(
> optfn_mp_release_interpreter();
>
> return result;
>
> I ended up replacing the attachment to the JIRA issue a couple of
> times,
> so watch out for moving targets. :-)
>
> Graham
|