| 1 |
|
|---|
| 2 | /* String object interface */
|
|---|
| 3 |
|
|---|
| 4 | #ifndef Py_STRINGOBJECT_H
|
|---|
| 5 | #define Py_STRINGOBJECT_H
|
|---|
| 6 | #ifdef __cplusplus
|
|---|
| 7 | extern "C" {
|
|---|
| 8 | #endif
|
|---|
| 9 |
|
|---|
| 10 | #include <stdarg.h>
|
|---|
| 11 |
|
|---|
| 12 | /*
|
|---|
| 13 | Type PyStringObject represents a character string. An extra zero byte is
|
|---|
| 14 | reserved at the end to ensure it is zero-terminated, but a size is
|
|---|
| 15 | present so strings with null bytes in them can be represented. This
|
|---|
| 16 | is an immutable object type.
|
|---|
| 17 |
|
|---|
| 18 | There are functions to create new string objects, to test
|
|---|
| 19 | an object for string-ness, and to get the
|
|---|
| 20 | string value. The latter function returns a null pointer
|
|---|
| 21 | if the object is not of the proper type.
|
|---|
| 22 | There is a variant that takes an explicit size as well as a
|
|---|
| 23 | variant that assumes a zero-terminated string. Note that none of the
|
|---|
| 24 | functions should be applied to nil objects.
|
|---|
| 25 | */
|
|---|
| 26 |
|
|---|
| 27 | /* Caching the hash (ob_shash) saves recalculation of a string's hash value.
|
|---|
| 28 | Interning strings (ob_sstate) tries to ensure that only one string
|
|---|
| 29 | object with a given value exists, so equality tests can be one pointer
|
|---|
| 30 | comparison. This is generally restricted to strings that "look like"
|
|---|
| 31 | Python identifiers, although the intern() builtin can be used to force
|
|---|
| 32 | interning of any string.
|
|---|
| 33 | Together, these sped the interpreter by up to 20%. */
|
|---|
| 34 |
|
|---|
| 35 | typedef struct {
|
|---|
| 36 | PyObject_VAR_HEAD
|
|---|
| 37 | long ob_shash;
|
|---|
| 38 | int ob_sstate;
|
|---|
| 39 | char ob_sval[1];
|
|---|
| 40 |
|
|---|
| 41 | /* Invariants:
|
|---|
| 42 | * ob_sval contains space for 'ob_size+1' elements.
|
|---|
| 43 | * ob_sval[ob_size] == 0.
|
|---|
| 44 | * ob_shash is the hash of the string or -1 if not computed yet.
|
|---|
| 45 | * ob_sstate != 0 iff the string object is in stringobject.c's
|
|---|
| 46 | * 'interned' dictionary; in this case the two references
|
|---|
| 47 | * from 'interned' to this object are *not counted* in ob_refcnt.
|
|---|
| 48 | */
|
|---|
|
|---|