summaryrefslogtreecommitdiff
path: root/Include/tupleobject.h
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2004-10-28 16:32:00 +0000
committerArmin Rigo <arigo@tunes.org>2004-10-28 16:32:00 +0000
commite0962fc1c68294f36200f849d1fe6e509c211ca2 (patch)
treefc9a2ee7726154a27872a254a103a23cd466a444 /Include/tupleobject.h
parent81c24608179bd058dfbfa3736e3b5deb01bf6432 (diff)
downloadcpython-e0962fc1c68294f36200f849d1fe6e509c211ca2.tar.gz
Wrote down the invariants of some common objects whose structure is
exposed in header files. Fixed a few comments in these headers. As we might have expected, writing down invariants systematically exposed a (minor) bug. In this case, function objects have a writeable func_code attribute, which could be set to code objects with the wrong number of free variables. Calling the resulting function segfaulted the interpreter. Added a corresponding test.
Diffstat (limited to 'Include/tupleobject.h')
-rw-r--r--Include/tupleobject.h13
1 files changed, 10 insertions, 3 deletions
diff --git a/Include/tupleobject.h b/Include/tupleobject.h
index f1839fe98c..6b60d62da8 100644
--- a/Include/tupleobject.h
+++ b/Include/tupleobject.h
@@ -8,9 +8,11 @@ extern "C" {
#endif
/*
-Another generally useful object type is an tuple of object pointers.
-This is a mutable type: the tuple items can be changed (but not their
-number). Out-of-range indices or non-tuple objects are ignored.
+Another generally useful object type is a tuple of object pointers.
+For Python, this is an immutable type. C code can change the tuple items
+(but not their number), and even use tuples are general-purpose arrays of
+object references, but in general only brand new tuples should be mutated,
+not ones that might already have been exposed to Python code.
*** WARNING *** PyTuple_SetItem does not increment the new item's reference
count, but does decrement the reference count of the item it replaces,
@@ -22,6 +24,11 @@ returned item's reference count.
typedef struct {
PyObject_VAR_HEAD
PyObject *ob_item[1];
+
+ /* ob_item contains space for 'ob_size' elements.
+ * Items must normally not be NULL, except during construction when
+ * the tuple is not yet visible outside the function that builds it.
+ */
} PyTupleObject;
PyAPI_DATA(PyTypeObject) PyTuple_Type;