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:
Armin Rigo 2004-10-28 16:32:00 +00:00
parent 063e1e846d
commit 89a39461bf
12 changed files with 98 additions and 25 deletions

View file

@ -16,6 +16,14 @@ typedef struct {
PyObject *data;
long hash; /* only used by frozenset objects */
PyObject *weakreflist; /* List of weak references */
/* Invariants:
* data is a dictionary whose values are all True.
* data points to the same dict for the whole life of the set.
* For frozensets only:
* data is immutable.
* hash is the hash of the frozenset or -1 if not computed yet.
*/
} PySetObject;
PyAPI_DATA(PyTypeObject) PySet_Type;