diff options
author | Armin Rigo <arigo@tunes.org> | 2004-10-28 16:32:00 (GMT) |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2004-10-28 16:32:00 (GMT) |
commit | 89a39461bff04b80bb4857790350e1ab30ff2df9 (patch) | |
tree | 54bc00a9ad30e8e49849874cfbca8543de62fa58 /Include/tupleobject.h | |
parent | 063e1e846dc5c3fe593cef5b14cc429369dcd2c2 (diff) | |
download | cpython-89a39461bff04b80bb4857790350e1ab30ff2df9.zip cpython-89a39461bff04b80bb4857790350e1ab30ff2df9.tar.gz cpython-89a39461bff04b80bb4857790350e1ab30ff2df9.tar.bz2 |
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.h | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/Include/tupleobject.h b/Include/tupleobject.h index f1839fe..6b60d62 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; |