diff Include/stringobject.h @ 33856:60c60dc75c77 legacy-trunk

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.
author Armin Rigo <arigo@tunes.org>
date Thu, 28 Oct 2004 16:32:00 +0000
parents 85e52ec85629
children 7fdc639bc5b4
line wrap: on
line diff
--- a/Include/stringobject.h	Thu Oct 28 13:04:26 2004 +0000
+++ b/Include/stringobject.h	Thu Oct 28 16:32:00 2004 +0000
@@ -37,6 +37,15 @@
     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