Commit 9d2ae85b authored by Stefan Behnel's avatar Stefan Behnel

Add more visible warnings to C-API functions that steal references of their arguments.

parent 84b6c4a3
...@@ -42,17 +42,19 @@ cdef extern from "Python.h": ...@@ -42,17 +42,19 @@ cdef extern from "Python.h":
int PyList_SetItem(object list, Py_ssize_t index, object item) except -1 int PyList_SetItem(object list, Py_ssize_t index, object item) except -1
# Set the item at index index in list to item. Return 0 on success # Set the item at index index in list to item. Return 0 on success
# or -1 on failure. Note: This function ``steals'' a reference to # or -1 on failure.
# item and discards a reference to an item already in the list at #
# the affected position. # WARNING: This function _steals_ a reference to item and discards a
# reference to an item already in the list at the affected position.
void PyList_SET_ITEM(object list, Py_ssize_t i, object o) void PyList_SET_ITEM(object list, Py_ssize_t i, object o)
# Macro form of PyList_SetItem() without error checking. This is # Macro form of PyList_SetItem() without error checking. This is
# normally only used to fill in new lists where there is no # normally only used to fill in new lists where there is no
# previous content. Note: This function ``steals'' a reference to # previous content.
# item, and, unlike PyList_SetItem(), does not discard a reference #
# to any item that it being replaced; any reference in list at # WARNING: This function _steals_ a reference to item, and, unlike
# position i will be *leaked*. # PyList_SetItem(), does not discard a reference to any item that
# it being replaced; any reference in list at position i will be *leaked*.
int PyList_Insert(object list, Py_ssize_t index, object item) except -1 int PyList_Insert(object list, Py_ssize_t index, object item) except -1
# Insert the item item into list list in front of index # Insert the item item into list list in front of index
......
...@@ -191,9 +191,10 @@ cdef extern from "Python.h": ...@@ -191,9 +191,10 @@ cdef extern from "Python.h":
int PyModule_AddObject(object module, const char *name, object value) except -1 int PyModule_AddObject(object module, const char *name, object value) except -1
# Add an object to module as name. This is a convenience function # Add an object to module as name. This is a convenience function
# which can be used from the module's initialization # which can be used from the module's initialization function.
# function. This steals a reference to value. Return -1 on error, # Return -1 on error, 0 on success.
# 0 on success. #
# WARNING: This _steals_ a reference to value.
int PyModule_AddIntConstant(object module, const char *name, long value) except -1 int PyModule_AddIntConstant(object module, const char *name, long value) except -1
# Add an integer constant to module as name. This convenience # Add an integer constant to module as name. This convenience
......
...@@ -47,13 +47,15 @@ cdef extern from "Python.h": ...@@ -47,13 +47,15 @@ cdef extern from "Python.h":
int PyTuple_SetItem(object p, Py_ssize_t pos, object o) except -1 int PyTuple_SetItem(object p, Py_ssize_t pos, object o) except -1
# Insert a reference to object o at position pos of the tuple # Insert a reference to object o at position pos of the tuple
# pointed to by p. Return 0 on success. Note: This function # pointed to by p. Return 0 on success.
# ``steals'' a reference to o. #
# WARNING: This function _steals_ a reference to o.
void PyTuple_SET_ITEM(object p, Py_ssize_t pos, object o) void PyTuple_SET_ITEM(object p, Py_ssize_t pos, object o)
# Like PyTuple_SetItem(), but does no error checking, and should # Like PyTuple_SetItem(), but does no error checking, and should
# only be used to fill in brand new tuples. Note: This function # only be used to fill in brand new tuples.
# ``steals'' a reference to o. #
# WARNING: This function _steals_ a reference to o.
int _PyTuple_Resize(PyObject **p, Py_ssize_t newsize) except -1 int _PyTuple_Resize(PyObject **p, Py_ssize_t newsize) except -1
# Can be used to resize a tuple. newsize will be the new length of # Can be used to resize a tuple. newsize will be the new length of
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment