Added all documentation.
[python/dscho.git] / Include / stringobject.h
blob7b9b53fed37a5710771abc70c2e8fc9775a24d80
1 #ifndef Py_STRINGOBJECT_H
2 #define Py_STRINGOBJECT_H
3 #ifdef __cplusplus
4 extern "C" {
5 #endif
7 /***********************************************************
8 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
9 The Netherlands.
11 All Rights Reserved
13 Permission to use, copy, modify, and distribute this software and its
14 documentation for any purpose and without fee is hereby granted,
15 provided that the above copyright notice appear in all copies and that
16 both that copyright notice and this permission notice appear in
17 supporting documentation, and that the names of Stichting Mathematisch
18 Centrum or CWI or Corporation for National Research Initiatives or
19 CNRI not be used in advertising or publicity pertaining to
20 distribution of the software without specific, written prior
21 permission.
23 While CWI is the initial source for this software, a modified version
24 is made available by the Corporation for National Research Initiatives
25 (CNRI) at the Internet address ftp://ftp.python.org.
27 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
28 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
29 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
30 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
31 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
32 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
33 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
34 PERFORMANCE OF THIS SOFTWARE.
36 ******************************************************************/
38 /* String object interface */
41 Type PyStringObject represents a character string. An extra zero byte is
42 reserved at the end to ensure it is zero-terminated, but a size is
43 present so strings with null bytes in them can be represented. This
44 is an immutable object type.
46 There are functions to create new string objects, to test
47 an object for string-ness, and to get the
48 string value. The latter function returns a null pointer
49 if the object is not of the proper type.
50 There is a variant that takes an explicit size as well as a
51 variant that assumes a zero-terminated string. Note that none of the
52 functions should be applied to nil objects.
55 /* Two speedup hacks. Caching the hash saves recalculation of a
56 string's hash value. Interning strings (which requires hash
57 caching) tries to ensure that only one string object with a given
58 value exists, so equality tests are one pointer comparison.
59 Together, these can speed the interpreter up by as much as 20%.
60 Each costs the size of a long or pointer per string object. In
61 addition, interned strings live until the end of times. If you are
62 concerned about memory footprint, simply comment the #define out
63 here (and rebuild everything!). */
64 #define CACHE_HASH
65 #ifdef CACHE_HASH
66 #define INTERN_STRINGS
67 #endif
69 typedef struct {
70 PyObject_VAR_HEAD
71 #ifdef CACHE_HASH
72 long ob_shash;
73 #endif
74 #ifdef INTERN_STRINGS
75 PyObject *ob_sinterned;
76 #endif
77 char ob_sval[1];
78 } PyStringObject;
80 extern DL_IMPORT(PyTypeObject) PyString_Type;
82 #define PyString_Check(op) ((op)->ob_type == &PyString_Type)
84 extern DL_IMPORT(PyObject *) PyString_FromStringAndSize Py_PROTO((const char *, int));
85 extern DL_IMPORT(PyObject *) PyString_FromString Py_PROTO((const char *));
86 extern DL_IMPORT(int) PyString_Size Py_PROTO((PyObject *));
87 extern DL_IMPORT(char *) PyString_AsString Py_PROTO((PyObject *));
88 extern DL_IMPORT(void) PyString_Concat Py_PROTO((PyObject **, PyObject *));
89 extern DL_IMPORT(void) PyString_ConcatAndDel Py_PROTO((PyObject **, PyObject *));
90 extern DL_IMPORT(int) _PyString_Resize Py_PROTO((PyObject **, int));
91 extern DL_IMPORT(PyObject *) PyString_Format Py_PROTO((PyObject *, PyObject *));
93 #ifdef INTERN_STRINGS
94 extern DL_IMPORT(void) PyString_InternInPlace Py_PROTO((PyObject **));
95 extern DL_IMPORT(PyObject *) PyString_InternFromString Py_PROTO((const char *));
96 #else
97 #define PyString_InternInPlace(p)
98 #define PyString_InternFromString(cp) PyString_FromString(cp)
99 #endif
101 /* Macro, trading safety for speed */
102 #define PyString_AS_STRING(op) (((PyStringObject *)(op))->ob_sval)
103 #define PyString_GET_SIZE(op) (((PyStringObject *)(op))->ob_size)
105 #ifdef __cplusplus
107 #endif
108 #endif /* !Py_STRINGOBJECT_H */