annotate Include/stringobject.h @ 44252:444da08f78a4

Fixed issue #1564: The set implementation should special-case PyUnicode instead of PyString I moved the unicode_eq to stringlib/eq.h to keep the function static and possible inline for setobject.c and dictobject.h. I also removed the unused _PyString_Eq method. If it's required in the future it can be added to eq.h
author Christian Heimes <christian@cheimes.de>
date Mon, 10 Dec 2007 15:50:56 +0000
parents 0cc552ab76bd
children 86a2679dca46
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
1
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 /* String object interface */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
13445
091ca6b9348f ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13376
diff changeset
4 #ifndef Py_STRINGOBJECT_H
091ca6b9348f ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13376
diff changeset
5 #define Py_STRINGOBJECT_H
091ca6b9348f ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13376
diff changeset
6 #ifdef __cplusplus
091ca6b9348f ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13376
diff changeset
7 extern "C" {
091ca6b9348f ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13376
diff changeset
8 #endif
091ca6b9348f ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13376
diff changeset
9
19475
bc63afc701ef PyString_FromFormat() and PyString_FromFormatV(): Largely ripped from
Barry Warsaw <barry@python.org>
parents: 18129
diff changeset
10 #include <stdarg.h>
bc63afc701ef PyString_FromFormat() and PyString_FromFormatV(): Largely ripped from
Barry Warsaw <barry@python.org>
parents: 18129
diff changeset
11
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 /*
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2058
diff changeset
13 Type PyStringObject represents a character string. An extra zero byte is
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 reserved at the end to ensure it is zero-terminated, but a size is
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 present so strings with null bytes in them can be represented. This
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 is an immutable object type.
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
17
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 There are functions to create new string objects, to test
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 an object for string-ness, and to get the
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 string value. The latter function returns a null pointer
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 if the object is not of the proper type.
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 There is a variant that takes an explicit size as well as a
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 variant that assumes a zero-terminated string. Note that none of the
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 functions should be applied to nil objects.
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
26
22651
f3a416b178c4 Remove the CACHE_HASH and INTERN_STRINGS preprocessor symbols.
Tim Peters <tim.peters@gmail.com>
parents: 20626
diff changeset
27 /* Caching the hash (ob_shash) saves recalculation of a string's hash value.
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43692
diff changeset
28 This significantly speeds up dict lookups. */
3833
f0efff28a24d Turn on CACHE_HASH, for 2% speedier dict lookups
Guido van Rossum <guido@python.org>
parents: 2436
diff changeset
29
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 typedef struct {
13445
091ca6b9348f ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13376
diff changeset
31 PyObject_VAR_HEAD
091ca6b9348f ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13376
diff changeset
32 long ob_shash;
091ca6b9348f ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13376
diff changeset
33 char ob_sval[1];
33856
60c60dc75c77 Wrote down the invariants of some common objects whose structure is
Armin Rigo <arigo@tunes.org>
parents: 29726
diff changeset
34
60c60dc75c77 Wrote down the invariants of some common objects whose structure is
Armin Rigo <arigo@tunes.org>
parents: 29726
diff changeset
35 /* Invariants:
60c60dc75c77 Wrote down the invariants of some common objects whose structure is
Armin Rigo <arigo@tunes.org>
parents: 29726
diff changeset
36 * ob_sval contains space for 'ob_size+1' elements.
60c60dc75c77 Wrote down the invariants of some common objects whose structure is
Armin Rigo <arigo@tunes.org>
parents: 29726
diff changeset
37 * ob_sval[ob_size] == 0.
60c60dc75c77 Wrote down the invariants of some common objects whose structure is
Armin Rigo <arigo@tunes.org>
parents: 29726
diff changeset
38 * ob_shash is the hash of the string or -1 if not computed yet.
60c60dc75c77 Wrote down the invariants of some common objects whose structure is
Armin Rigo <arigo@tunes.org>
parents: 29726
diff changeset
39 */
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2058
diff changeset
40 } PyStringObject;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
41
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 23542
diff changeset
42 PyAPI_DATA(PyTypeObject) PyString_Type;
44061
0cc552ab76bd Added all PyTypeObjects to the appropriate header files.
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
43 PyAPI_DATA(PyTypeObject) PyStringIter_Type;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
44
40909
f2f0b41f270d Merged revisions 53875-53911 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40484
diff changeset
45 #define PyString_Check(op) \
42334
e70cdce0e8b2 Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 42013
diff changeset
46 PyType_FastSubclass(Py_Type(op), Py_TPFLAGS_STRING_SUBCLASS)
e70cdce0e8b2 Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 42013
diff changeset
47 #define PyString_CheckExact(op) (Py_Type(op) == &PyString_Type)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
48
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 33856
diff changeset
49 PyAPI_FUNC(PyObject *) PyString_FromStringAndSize(const char *, Py_ssize_t);
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 23542
diff changeset
50 PyAPI_FUNC(PyObject *) PyString_FromString(const char *);
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 23542
diff changeset
51 PyAPI_FUNC(PyObject *) PyString_FromFormatV(const char*, va_list)
25276
6c21e95a4881 Use Py_GCC_ATTRIBUTE instead of __attribute__. Compilers other than GCC
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 24901
diff changeset
52 Py_GCC_ATTRIBUTE((format(printf, 1, 0)));
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 23542
diff changeset
53 PyAPI_FUNC(PyObject *) PyString_FromFormat(const char*, ...)
25276
6c21e95a4881 Use Py_GCC_ATTRIBUTE instead of __attribute__. Compilers other than GCC
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 24901
diff changeset
54 Py_GCC_ATTRIBUTE((format(printf, 1, 2)));
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 33856
diff changeset
55 PyAPI_FUNC(Py_ssize_t) PyString_Size(PyObject *);
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 23542
diff changeset
56 PyAPI_FUNC(char *) PyString_AsString(PyObject *);
24808
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24752
diff changeset
57 PyAPI_FUNC(PyObject *) PyString_Repr(PyObject *, int);
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 23542
diff changeset
58 PyAPI_FUNC(void) PyString_Concat(PyObject **, PyObject *);
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 23542
diff changeset
59 PyAPI_FUNC(void) PyString_ConcatAndDel(PyObject **, PyObject *);
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 33856
diff changeset
60 PyAPI_FUNC(int) _PyString_Resize(PyObject **, Py_ssize_t);
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 23542
diff changeset
61 PyAPI_FUNC(PyObject *) PyString_Format(PyObject *, PyObject *);
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 23542
diff changeset
62 PyAPI_FUNC(PyObject *) _PyString_FormatLong(PyObject*, int, int,
14713
58b832b8745e Derived from Martin's SF patch 110609: support unbounded ints in %d,i,u,x,X,o formats.
Tim Peters <tim.peters@gmail.com>
parents: 14696
diff changeset
63 int, char**, int*);
43692
50a3475db466 Kill PyString_Encode(), which isn't used anywhere.
Guido van Rossum <guido@python.org>
parents: 43577
diff changeset
64 PyAPI_FUNC(PyObject *) PyString_DecodeEscape(const char *, Py_ssize_t,
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 33856
diff changeset
65 const char *, Py_ssize_t,
24808
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24752
diff changeset
66 const char *);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
67
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 /* Macro, trading safety for speed */
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43692
diff changeset
69 #define PyString_AS_STRING(op) (assert(PyString_Check(op)), \
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43692
diff changeset
70 (((PyStringObject *)(op))->ob_sval))
42335
c8b850b5a066 Fix merge breakage.
Martin v. Löwis <martin@v.loewis.de>
parents: 42334
diff changeset
71 #define PyString_GET_SIZE(op) (assert(PyString_Check(op)),Py_Size(op))
1329
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
72
18129
9d533ae574d2 SF bug 433228: repr(list) woes when len(list) big.
Tim Peters <tim.peters@gmail.com>
parents: 17964
diff changeset
73 /* _PyString_Join(sep, x) is like sep.join(x). sep must be PyStringObject*,
9d533ae574d2 SF bug 433228: repr(list) woes when len(list) big.
Tim Peters <tim.peters@gmail.com>
parents: 17964
diff changeset
74 x must be an iterable object. */
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 23542
diff changeset
75 PyAPI_FUNC(PyObject *) _PyString_Join(PyObject *sep, PyObject *x);
18129
9d533ae574d2 SF bug 433228: repr(list) woes when len(list) big.
Tim Peters <tim.peters@gmail.com>
parents: 17964
diff changeset
76
14696
85038a024b19 This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents: 14375
diff changeset
77 /* Provides access to the internal data buffer and size of a string
85038a024b19 This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents: 14375
diff changeset
78 object or the default encoded version of an Unicode object. Passing
85038a024b19 This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents: 14375
diff changeset
79 NULL as *len parameter will force the string buffer to be
85038a024b19 This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents: 14375
diff changeset
80 0-terminated (passing a string with embedded NULL characters will
85038a024b19 This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents: 14375
diff changeset
81 cause an exception). */
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 23542
diff changeset
82 PyAPI_FUNC(int) PyString_AsStringAndSize(
14696
85038a024b19 This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents: 14375
diff changeset
83 register PyObject *obj, /* string or Unicode object */
85038a024b19 This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents: 14375
diff changeset
84 register char **s, /* pointer to buffer variable */
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 33856
diff changeset
85 register Py_ssize_t *len /* pointer to length variable or NULL
14696
85038a024b19 This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents: 14375
diff changeset
86 (only possible for 0-terminated
85038a024b19 This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents: 14375
diff changeset
87 strings) */
85038a024b19 This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents: 14375
diff changeset
88 );
43692
50a3475db466 Kill PyString_Encode(), which isn't used anywhere.
Guido van Rossum <guido@python.org>
parents: 43577
diff changeset
89
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43692
diff changeset
90 /* Flags used by string formatting */
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43692
diff changeset
91 #define F_LJUST (1<<0)
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43692
diff changeset
92 #define F_SIGN (1<<1)
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43692
diff changeset
93 #define F_BLANK (1<<2)
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43692
diff changeset
94 #define F_ALT (1<<3)
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43692
diff changeset
95 #define F_ZERO (1<<4)
14696
85038a024b19 This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents: 14375
diff changeset
96
1329
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
97 #ifdef __cplusplus
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
98 }
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
99 #endif
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
100 #endif /* !Py_STRINGOBJECT_H */