Py_Object* Py_BuildValue, Py_INCREF necessary?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Torsten Mohr

    #1

    Py_Object* Py_BuildValue, Py_INCREF necessary?

    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.

  • Tim Peters

    #2
    Re: Py_Object* Py_BuildValue, Py_INCREF necessary?

    [Torsten Mohr][color=blue]
    > 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?[/color]

    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).

    Comment

    • nszabolcs

      #3
      Re: Py_Object* Py_BuildValue, Py_INCREF necessary?

      no

      The official home of the Python Programming Language


      nsz

      Comment

      Working...