By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,095 Members | 1,586 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,095 IT Pros & Developers. It's quick & easy.

Py_Object* Py_BuildValue, Py_INCREF necessary?

P: n/a
Hi,

when i write an extension module in C and return a Py_Object*
that i've built with Py_BuildValue, do i need to use Py_INCREF
on that before i return it to python from my extension module
or not?
Thanks for hints,
Torsten.

Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
[Torsten Mohr]
when i write an extension module in C and return a Py_Object*
that i've built with Py_BuildValue, do i need to use Py_INCREF
on that before i return it to python from my extension module
or not?


The docs for Py_BuildValue() say it returns a new reference (and it
does). So the caller owns the reference, and is responsible for
either passing its reference on to someone else, or for giving up its
reference (via Py_DECREF). If you pass the result on to your
extension module's caller, then you're also transferring ownership of
the reference to your extension module's caller (and should not do
Py_INCREF -- which would create yet another reference).
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.