OT: Python C API and reference counting
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Web Servers reviews > Apache Server configuration support > Apache Mod-Python > OT: Python C API and reference counting




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    OT: Python C API and reference counting  
Dan Eloff


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-13-06 01:13 PM

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






[ Post a follow-up to this message ]



    Re: OT: Python C API and reference counting  
Graham Dumpleton


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-13-06 01:13 PM

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






[ Post a follow-up to this message ]



    Re: OT: Python C API and reference counting  
Dan Eloff


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-13-06 01:13 PM

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






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 04:00 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register