From 89a39461bff04b80bb4857790350e1ab30ff2df9 Mon Sep 17 00:00:00 2001 From: Armin Rigo Date: Thu, 28 Oct 2004 16:32:00 +0000 Subject: 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. --- Include/setobject.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'Include/setobject.h') diff --git a/Include/setobject.h b/Include/setobject.h index abbd8477ad..cc2d6832bc 100644 --- a/Include/setobject.h +++ b/Include/setobject.h @@ -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; -- cgit v1.2.1