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/stringobject.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'Include/stringobject.h') diff --git a/Include/stringobject.h b/Include/stringobject.h index 3deea8f5d8..0c7e5b6d2c 100644 --- a/Include/stringobject.h +++ b/Include/stringobject.h @@ -37,6 +37,15 @@ typedef struct { long ob_shash; int ob_sstate; char ob_sval[1]; + + /* Invariants: + * ob_sval contains space for 'ob_size+1' elements. + * ob_sval[ob_size] == 0. + * ob_shash is the hash of the string or -1 if not computed yet. + * ob_sstate != 0 iff the string object is in stringobject.c's + * 'interned' dictionary; in this case the two references + * from 'interned' to this object are *not counted* in ob_refcnt. + */ } PyStringObject; #define SSTATE_NOT_INTERNED 0 -- cgit v1.2.1