annotate Include/stringobject.h @ 40909:f2f0b41f270d

Merged revisions 53875-53911 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r53899 | neal.norwitz | 2007-02-25 16:52:27 +0100 (Sun, 25 Feb 2007) | 1 line Add more details when releasing interned strings ........ r53900 | neal.norwitz | 2007-02-25 16:53:36 +0100 (Sun, 25 Feb 2007) | 1 line Whitespace only changes ........ r53901 | jeremy.hylton | 2007-02-25 16:57:45 +0100 (Sun, 25 Feb 2007) | 8 lines Fix crash in exec when unicode filename can't be decoded. I can't think of an easy way to test this behavior. It only occurs when the file system default encoding and the interpreter default encoding are different, such that you can open the file but not decode its name. ........ r53902 | jeremy.hylton | 2007-02-25 17:01:58 +0100 (Sun, 25 Feb 2007) | 2 lines Put declarations before code. ........ r53910 | fred.drake | 2007-02-25 18:56:27 +0100 (Sun, 25 Feb 2007) | 3 lines - SF patch #1657613: add documentation for the Element interface - clean up bogus use of the {datadescni} environment everywhere ........ r53911 | neal.norwitz | 2007-02-25 20:44:48 +0100 (Sun, 25 Feb 2007) | 17 lines Variation of patch # 1624059 to speed up checking if an object is a subclass of some of the common builtin types. Use a bit in tp_flags for each common builtin type. Check the bit to determine if any instance is a subclass of these common types. The check avoids a function call and O(n) search of the base classes. The check is done in the various Py*_Check macros rather than calling PyType_IsSubtype(). All the bits are set in tp_flags when the type is declared in the Objects/*object.c files because PyType_Ready() is not called for all the types. Should PyType_Ready() be called for all types? If so and the change is made, the changes to the Objects/*object.c files can be reverted (remove setting the tp_flags). Objects/typeobject.c would also have to be modified to add conditions for Py*_CheckExact() in addition to each the PyType_IsSubtype check. ........
author Thomas Wouters <thomas@python.org>
date Sun, 25 Feb 2007 20:39:11 +0000
parents 8565e3fea9b6
children dcb43f40390b
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.
24901
bc660f73795c SF patch 576101, by Oren Tirosh: alternative implementation of
Guido van Rossum <guido@python.org>
parents: 24808
diff changeset
28 Interning strings (ob_sstate) tries to ensure that only one string
22651
f3a416b178c4 Remove the CACHE_HASH and INTERN_STRINGS preprocessor symbols.
Tim Peters <tim.peters@gmail.com>
parents: 20626
diff changeset
29 object with a given value exists, so equality tests can be one pointer
f3a416b178c4 Remove the CACHE_HASH and INTERN_STRINGS preprocessor symbols.
Tim Peters <tim.peters@gmail.com>
parents: 20626
diff changeset
30 comparison. This is generally restricted to strings that "look like"
40484
8565e3fea9b6 Patch #1601678: move intern() to sys.intern().
Georg Brandl <georg@python.org>
parents: 36501
diff changeset
31 Python identifiers, although the sys.intern() function can be used to force
22651
f3a416b178c4 Remove the CACHE_HASH and INTERN_STRINGS preprocessor symbols.
Tim Peters <tim.peters@gmail.com>
parents: 20626
diff changeset
32 interning of any string.
f3a416b178c4 Remove the CACHE_HASH and INTERN_STRINGS preprocessor symbols.
Tim Peters <tim.peters@gmail.com>
parents: 20626
diff changeset
33 Together, these sped the interpreter by up to 20%. */
3833
f0efff28a24d Turn on CACHE_HASH, for 2% speedier dict lookups
Guido van Rossum <guido@python.org>
parents: 2436
diff changeset
34
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 typedef struct {
13445
091ca6b9348f ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13376
diff changeset
36 PyObject_VAR_HEAD
091ca6b9348f ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13376
diff changeset
37 long ob_shash;
24901
bc660f73795c SF patch 576101, by Oren Tirosh: alternative implementation of
Guido van Rossum <guido@python.org>
parents: 24808
diff changeset
38 int ob_sstate;
13445
091ca6b9348f ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13376
diff changeset
39 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
40
60c60dc75c77 Wrote down the invariants of some common objects whose structure is
Armin Rigo <arigo@tunes.org>
parents: 29726
diff changeset
41 /* Invariants:
60c60dc75c77 Wrote down the invariants of some common objects whose structure is
Armin Rigo <arigo@tunes.org>
parents: 29726
diff changeset
42 * 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
43 * 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
44 * 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
45 * ob_sstate != 0 iff the string object is in stringobject.c's
60c60dc75c77 Wrote down the invariants of some common objects whose structure is
Armin Rigo <arigo@tunes.org>
parents: 29726
diff changeset
46 * 'interned' dictionary; in this case the two references
60c60dc75c77 Wrote down the invariants of some common objects whose structure is
Armin Rigo <arigo@tunes.org>
parents: 29726
diff changeset
47 * from 'interned' to this object are *not counted* in ob_refcnt.
60c60dc75c77 Wrote down the invariants of some common objects whose structure is
Armin Rigo <arigo@tunes.org>
parents: 29726
diff changeset
48 */
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2058
diff changeset
49 } PyStringObject;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
50
24901
bc660f73795c SF patch 576101, by Oren Tirosh: alternative implementation of
Guido van Rossum <guido@python.org>
parents: 24808
diff changeset
51 #define SSTATE_NOT_INTERNED 0
bc660f73795c SF patch 576101, by Oren Tirosh: alternative implementation of
Guido van Rossum <guido@python.org>
parents: 24808
diff changeset
52 #define SSTATE_INTERNED_MORTAL 1
bc660f73795c SF patch 576101, by Oren Tirosh: alternative implementation of
Guido van Rossum <guido@python.org>
parents: 24808
diff changeset
53 #define SSTATE_INTERNED_IMMORTAL 2
bc660f73795c SF patch 576101, by Oren Tirosh: alternative implementation of
Guido van Rossum <guido@python.org>
parents: 24808
diff changeset
54
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 23542
diff changeset
55 PyAPI_DATA(PyTypeObject) PyBaseString_Type;
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 23542
diff changeset
56 PyAPI_DATA(PyTypeObject) PyString_Type;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
57
40909
f2f0b41f270d Merged revisions 53875-53911 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40484
diff changeset
58 #define PyString_Check(op) \
f2f0b41f270d Merged revisions 53875-53911 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40484
diff changeset
59 PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_STRING_SUBCLASS)
19846
662e22f99639 More on SF bug [#460020] bug or feature: unicode() and subclasses.
Tim Peters <tim.peters@gmail.com>
parents: 19589
diff changeset
60 #define PyString_CheckExact(op) ((op)->ob_type == &PyString_Type)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
61
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 33856
diff changeset
62 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
63 PyAPI_FUNC(PyObject *) PyString_FromString(const char *);
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 23542
diff changeset
64 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
65 Py_GCC_ATTRIBUTE((format(printf, 1, 0)));
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 23542
diff changeset
66 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
67 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
68 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
69 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
70 PyAPI_FUNC(PyObject *) PyString_Repr(PyObject *, int);
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 23542
diff changeset
71 PyAPI_FUNC(void) PyString_Concat(PyObject **, PyObject *);
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 23542
diff changeset
72 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
73 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
74 PyAPI_FUNC(int) _PyString_Eq(PyObject *, PyObject*);
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 23542
diff changeset
75 PyAPI_FUNC(PyObject *) PyString_Format(PyObject *, PyObject *);
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 23542
diff changeset
76 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
77 int, char**, int*);
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 33856
diff changeset
78 PyAPI_FUNC(PyObject *) PyString_DecodeEscape(const char *, Py_ssize_t,
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 33856
diff changeset
79 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
80 const char *);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
81
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 23542
diff changeset
82 PyAPI_FUNC(void) PyString_InternInPlace(PyObject **);
24901
bc660f73795c SF patch 576101, by Oren Tirosh: alternative implementation of
Guido van Rossum <guido@python.org>
parents: 24808
diff changeset
83 PyAPI_FUNC(void) PyString_InternImmortal(PyObject **);
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 23542
diff changeset
84 PyAPI_FUNC(PyObject *) PyString_InternFromString(const char *);
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 23542
diff changeset
85 PyAPI_FUNC(void) _Py_ReleaseInternedStrings(void);
5003
65aace2012e5 Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents: 4897
diff changeset
86
24901
bc660f73795c SF patch 576101, by Oren Tirosh: alternative implementation of
Guido van Rossum <guido@python.org>
parents: 24808
diff changeset
87 /* Use only if you know it's a string */
bc660f73795c SF patch 576101, by Oren Tirosh: alternative implementation of
Guido van Rossum <guido@python.org>
parents: 24808
diff changeset
88 #define PyString_CHECK_INTERNED(op) (((PyStringObject *)(op))->ob_sstate)
bc660f73795c SF patch 576101, by Oren Tirosh: alternative implementation of
Guido van Rossum <guido@python.org>
parents: 24808
diff changeset
89
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 /* Macro, trading safety for speed */
4897
90c21dde4284 added PyString_GET_SIZE macro
Barry Warsaw <barry@python.org>
parents: 4654
diff changeset
91 #define PyString_AS_STRING(op) (((PyStringObject *)(op))->ob_sval)
90c21dde4284 added PyString_GET_SIZE macro
Barry Warsaw <barry@python.org>
parents: 4654
diff changeset
92 #define PyString_GET_SIZE(op) (((PyStringObject *)(op))->ob_size)
1329
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
93
18129
9d533ae574d2 SF bug 433228: repr(list) woes when len(list) big.
Tim Peters <tim.peters@gmail.com>
parents: 17964
diff changeset
94 /* _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
95 x must be an iterable object. */
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 23542
diff changeset
96 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
97
13376
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
98 /* --- Generic Codecs ----------------------------------------------------- */
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
99
17835
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
100 /* Create an object by decoding the encoded string s of the
13376
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
101 given size. */
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
102
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 23542
diff changeset
103 PyAPI_FUNC(PyObject*) PyString_Decode(
13376
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
104 const char *s, /* encoded string */
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 33856
diff changeset
105 Py_ssize_t size, /* size of buffer */
13376
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
106 const char *encoding, /* encoding */
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
107 const char *errors /* error handling */
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
108 );
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
109
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
110 /* Encodes a char buffer of the given size and returns a
17835
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
111 Python object. */
13376
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
112
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 23542
diff changeset
113 PyAPI_FUNC(PyObject*) PyString_Encode(
13376
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
114 const char *s, /* string char buffer */
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 33856
diff changeset
115 Py_ssize_t size, /* number of chars to encode */
13376
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
116 const char *encoding, /* encoding */
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
117 const char *errors /* error handling */
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
118 );
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
119
17835
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
120 /* Encodes a string object and returns the result as Python
13376
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
121 object. */
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
122
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 23542
diff changeset
123 PyAPI_FUNC(PyObject*) PyString_AsEncodedObject(
17835
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
124 PyObject *str, /* string object */
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
125 const char *encoding, /* encoding */
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
126 const char *errors /* error handling */
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
127 );
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
128
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
129 /* Encodes a string object and returns the result as Python string
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
130 object.
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
131
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
132 If the codec returns an Unicode object, the object is converted
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
133 back to a string using the default encoding.
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
134
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
135 DEPRECATED - use PyString_AsEncodedObject() instead. */
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
136
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 23542
diff changeset
137 PyAPI_FUNC(PyObject*) PyString_AsEncodedString(
13376
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
138 PyObject *str, /* string object */
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
139 const char *encoding, /* encoding */
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
140 const char *errors /* error handling */
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
141 );
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
142
17835
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
143 /* Decodes a string object and returns the result as Python
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
144 object. */
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
145
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 23542
diff changeset
146 PyAPI_FUNC(PyObject*) PyString_AsDecodedObject(
17835
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
147 PyObject *str, /* string object */
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
148 const char *encoding, /* encoding */
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
149 const char *errors /* error handling */
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
150 );
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
151
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
152 /* Decodes a string object and returns the result as Python string
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
153 object.
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
154
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
155 If the codec returns an Unicode object, the object is converted
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
156 back to a string using the default encoding.
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
157
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
158 DEPRECATED - use PyString_AsDecodedObject() instead. */
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
159
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 23542
diff changeset
160 PyAPI_FUNC(PyObject*) PyString_AsDecodedString(
17835
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
161 PyObject *str, /* string object */
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
162 const char *encoding, /* encoding */
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
163 const char *errors /* error handling */
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
164 );
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
165
14696
85038a024b19 This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents: 14375
diff changeset
166 /* 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
167 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
168 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
169 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
170 cause an exception). */
85038a024b19 This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents: 14375
diff changeset
171
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 23542
diff changeset
172 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
173 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
174 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
175 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
176 (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
177 strings) */
85038a024b19 This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents: 14375
diff changeset
178 );
85038a024b19 This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents: 14375
diff changeset
179
85038a024b19 This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents: 14375
diff changeset
180
1329
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
181 #ifdef __cplusplus
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
182 }
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
183 #endif
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
184 #endif /* !Py_STRINGOBJECT_H */