mirror of
https://github.com/python/cpython.git
synced 2025-10-06 15:11:58 +00:00
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.
This commit is contained in:
parent
063e1e846d
commit
89a39461bf
12 changed files with 98 additions and 25 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue