|
Home > Archive > Apache Mod-Python > November 2006 > OT: Python C API and reference counting
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
OT: Python C API and reference counting
|
|
| Dan Eloff 2006-11-13, 8:13 am |
| I know this isn't about mod_python, but I can think of nobody better
qualified to answer this question than mod_python developers.
If in a C function you release the GIl using begin/end allow threads,
does it change your responsibilites with regard to the reference
counts on the input parameters?
unsigned char * str;
int len;
PyArg_Parse(args, "s#", &str, &len)
Now if you do a Py_BEGIN_ALLOW_THREADS, and do something time
consuming without any Python calls, can you count on str not being
deallocated somehow while you work?
Thanks,
-Dan
| |
| Graham Dumpleton 2006-11-13, 8:13 am |
| Dan Eloff wrote ..
> I know this isn't about mod_python, but I can think of nobody better
> qualified to answer this question than mod_python developers.
>
> If in a C function you release the GIl using begin/end allow threads,
> does it change your responsibilites with regard to the reference
> counts on the input parameters?
>
> unsigned char * str;
> int len;
>
> PyArg_Parse(args, "s#", &str, &len)
>
> Now if you do a Py_BEGIN_ALLOW_THREADS, and do something time
> consuming without any Python calls, can you count on str not being
> deallocated somehow while you work?
I would have assumed that the code is safe as the calling Python stack
frame still holds a reference count on any objects passed to you and
since it is waiting for you to finish, even if in an allow threads state,
there shouldn't be anyway that its reference count could be undone.
Graham
| |
| Dan Eloff 2006-11-13, 8:13 am |
| On 11/9/06, Graham Dumpleton <grahamd@dscpl.com.au> wrote:
> I would have assumed that the code is safe as the calling Python stack
> frame still holds a reference count on any objects passed to you and
> since it is waiting for you to finish, even if in an allow threads state,
> there shouldn't be anyway that its reference count could be undone.
>
That makes sense, thanks Graham.
-Dan
|
|
|
|
|