annotate Include/stringobject.h @ 20737:00a581bdedeb legacy-trunk

When overriding __str__ or __repr__, set the tp_print slot to NULL.
author Guido van Rossum <guido@python.org>
date Mon, 29 Oct 2001 14:33:44 +0000
parents 3d299b156511
children f3a416b178c4
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
5003
65aace2012e5 Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents: 4897
diff changeset
27 /* Two speedup hacks. Caching the hash saves recalculation of a
65aace2012e5 Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents: 4897
diff changeset
28 string's hash value. Interning strings (which requires hash
65aace2012e5 Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents: 4897
diff changeset
29 caching) tries to ensure that only one string object with a given
65aace2012e5 Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents: 4897
diff changeset
30 value exists, so equality tests are one pointer comparison.
65aace2012e5 Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents: 4897
diff changeset
31 Together, these can speed the interpreter up by as much as 20%.
65aace2012e5 Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents: 4897
diff changeset
32 Each costs the size of a long or pointer per string object. In
65aace2012e5 Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents: 4897
diff changeset
33 addition, interned strings live until the end of times. If you are
65aace2012e5 Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents: 4897
diff changeset
34 concerned about memory footprint, simply comment the #define out
65aace2012e5 Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents: 4897
diff changeset
35 here (and rebuild everything!). */
3833
f0efff28a24d Turn on CACHE_HASH, for 2% speedier dict lookups
Guido van Rossum <guido@python.org>
parents: 2436
diff changeset
36 #define CACHE_HASH
5003
65aace2012e5 Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents: 4897
diff changeset
37 #ifdef CACHE_HASH
65aace2012e5 Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents: 4897
diff changeset
38 #define INTERN_STRINGS
65aace2012e5 Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents: 4897
diff changeset
39 #endif
3833
f0efff28a24d Turn on CACHE_HASH, for 2% speedier dict lookups
Guido van Rossum <guido@python.org>
parents: 2436
diff changeset
40
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 typedef struct {
13445
091ca6b9348f ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13376
diff changeset
42 PyObject_VAR_HEAD
1356
043da19302ef Several optimizations and speed improvements.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1329
diff changeset
43 #ifdef CACHE_HASH
13445
091ca6b9348f ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13376
diff changeset
44 long ob_shash;
1356
043da19302ef Several optimizations and speed improvements.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1329
diff changeset
45 #endif
5003
65aace2012e5 Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents: 4897
diff changeset
46 #ifdef INTERN_STRINGS
13445
091ca6b9348f ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13376
diff changeset
47 PyObject *ob_sinterned;
5003
65aace2012e5 Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents: 4897
diff changeset
48 #endif
13445
091ca6b9348f ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13376
diff changeset
49 char ob_sval[1];
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2058
diff changeset
50 } PyStringObject;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
51
2436
fa98dda07877 make the type a parameter of the DL_IMPORT macro, for Borland C
Guido van Rossum <guido@python.org>
parents: 2146
diff changeset
52 extern DL_IMPORT(PyTypeObject) PyString_Type;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
53
19589
844553473fa4 Make the Py<type>_Check() macro use PyObject_TypeCheck().
Guido van Rossum <guido@python.org>
parents: 19475
diff changeset
54 #define PyString_Check(op) PyObject_TypeCheck(op, &PyString_Type)
19846
662e22f99639 More on SF bug [#460020] bug or feature: unicode() and subclasses.
Tim Peters <tim.peters@gmail.com>
parents: 19589
diff changeset
55 #define PyString_CheckExact(op) ((op)->ob_type == &PyString_Type)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
56
13445
091ca6b9348f ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13376
diff changeset
57 extern DL_IMPORT(PyObject *) PyString_FromStringAndSize(const char *, int);
091ca6b9348f ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13376
diff changeset
58 extern DL_IMPORT(PyObject *) PyString_FromString(const char *);
20626
3d299b156511 Add function attributes that allow GCC to check the arguments of printf-like
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19846
diff changeset
59 extern DL_IMPORT(PyObject *) PyString_FromFormatV(const char*, va_list)
3d299b156511 Add function attributes that allow GCC to check the arguments of printf-like
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19846
diff changeset
60 __attribute__((format(printf, 1, 0)));
3d299b156511 Add function attributes that allow GCC to check the arguments of printf-like
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19846
diff changeset
61 extern DL_IMPORT(PyObject *) PyString_FromFormat(const char*, ...)
3d299b156511 Add function attributes that allow GCC to check the arguments of printf-like
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19846
diff changeset
62 __attribute__((format(printf, 1, 2)));
13445
091ca6b9348f ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13376
diff changeset
63 extern DL_IMPORT(int) PyString_Size(PyObject *);
091ca6b9348f ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13376
diff changeset
64 extern DL_IMPORT(char *) PyString_AsString(PyObject *);
091ca6b9348f ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13376
diff changeset
65 extern DL_IMPORT(void) PyString_Concat(PyObject **, PyObject *);
091ca6b9348f ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13376
diff changeset
66 extern DL_IMPORT(void) PyString_ConcatAndDel(PyObject **, PyObject *);
091ca6b9348f ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13376
diff changeset
67 extern DL_IMPORT(int) _PyString_Resize(PyObject **, int);
17964
5e1141157d53 Patch #424335: Implement string_richcompare, remove string_compare.
Martin v. Löwis <martin@v.loewis.de>
parents: 17835
diff changeset
68 extern DL_IMPORT(int) _PyString_Eq(PyObject *, PyObject*);
13445
091ca6b9348f ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13376
diff changeset
69 extern DL_IMPORT(PyObject *) PyString_Format(PyObject *, PyObject *);
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
70 extern DL_IMPORT(PyObject *) _PyString_FormatLong(PyObject*, int, int,
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
71 int, char**, int*);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
72
5003
65aace2012e5 Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents: 4897
diff changeset
73 #ifdef INTERN_STRINGS
13445
091ca6b9348f ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13376
diff changeset
74 extern DL_IMPORT(void) PyString_InternInPlace(PyObject **);
091ca6b9348f ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13376
diff changeset
75 extern DL_IMPORT(PyObject *) PyString_InternFromString(const char *);
16751
ca1be7d00413 _Py_ReleaseInternedStrings(): Private API function to decref and
Barry Warsaw <barry@python.org>
parents: 14713
diff changeset
76 extern DL_IMPORT(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
77 #else
65aace2012e5 Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents: 4897
diff changeset
78 #define PyString_InternInPlace(p)
65aace2012e5 Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents: 4897
diff changeset
79 #define PyString_InternFromString(cp) PyString_FromString(cp)
16751
ca1be7d00413 _Py_ReleaseInternedStrings(): Private API function to decref and
Barry Warsaw <barry@python.org>
parents: 14713
diff changeset
80 #define _Py_ReleaseInternedStrings()
5003
65aace2012e5 Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents: 4897
diff changeset
81 #endif
65aace2012e5 Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents: 4897
diff changeset
82
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
83 /* Macro, trading safety for speed */
4897
90c21dde4284 added PyString_GET_SIZE macro
Barry Warsaw <barry@python.org>
parents: 4654
diff changeset
84 #define PyString_AS_STRING(op) (((PyStringObject *)(op))->ob_sval)
90c21dde4284 added PyString_GET_SIZE macro
Barry Warsaw <barry@python.org>
parents: 4654
diff changeset
85 #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
86
18129
9d533ae574d2 SF bug 433228: repr(list) woes when len(list) big.
Tim Peters <tim.peters@gmail.com>
parents: 17964
diff changeset
87 /* _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
88 x must be an iterable object. */
9d533ae574d2 SF bug 433228: repr(list) woes when len(list) big.
Tim Peters <tim.peters@gmail.com>
parents: 17964
diff changeset
89 extern DL_IMPORT(PyObject *) _PyString_Join(PyObject *sep, PyObject *x);
9d533ae574d2 SF bug 433228: repr(list) woes when len(list) big.
Tim Peters <tim.peters@gmail.com>
parents: 17964
diff changeset
90
13376
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
91 /* --- Generic Codecs ----------------------------------------------------- */
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
92
17835
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
93 /* 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
94 given size. */
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
95
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
96 extern DL_IMPORT(PyObject*) PyString_Decode(
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
97 const char *s, /* encoded string */
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
98 int size, /* size of buffer */
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
99 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
100 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
101 );
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
102
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
103 /* 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
104 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
105
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
106 extern DL_IMPORT(PyObject*) PyString_Encode(
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 *s, /* string char buffer */
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
108 int size, /* number of chars to encode */
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
109 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
110 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
111 );
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
112
17835
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
113 /* 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
114 object. */
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
115
17835
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
116 extern DL_IMPORT(PyObject*) PyString_AsEncodedObject(
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
117 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
118 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
119 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
120 );
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
121
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
122 /* 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
123 object.
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
124
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
125 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
126 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
127
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
128 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
129
13376
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
130 extern DL_IMPORT(PyObject*) PyString_AsEncodedString(
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
131 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
132 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
133 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
134 );
bfe22cf6e770 Added prototypes for the new codec APIs for strings. These APIs
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
135
17835
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
136 /* 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
137 object. */
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
138
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
139 extern DL_IMPORT(PyObject*) PyString_AsDecodedObject(
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
140 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
141 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
142 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
143 );
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
144
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
145 /* 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
146 object.
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
147
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
148 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
149 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
150
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
151 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
152
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
153 extern DL_IMPORT(PyObject*) PyString_AsDecodedString(
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
154 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
155 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
156 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
157 );
9ea87c0a7c04 This patch changes the way the string .encode() method works slightly
Marc-André Lemburg <mal@egenix.com>
parents: 16751
diff changeset
158
14696
85038a024b19 This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents: 14375
diff changeset
159 /* 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
160 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
161 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
162 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
163 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
164
85038a024b19 This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents: 14375
diff changeset
165 extern DL_IMPORT(int) PyString_AsStringAndSize(
85038a024b19 This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents: 14375
diff changeset
166 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
167 register char **s, /* pointer to buffer variable */
85038a024b19 This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents: 14375
diff changeset
168 register int *len /* pointer to length variable or NULL
85038a024b19 This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents: 14375
diff changeset
169 (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
170 strings) */
85038a024b19 This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents: 14375
diff changeset
171 );
85038a024b19 This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents: 14375
diff changeset
172
85038a024b19 This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents: 14375
diff changeset
173
1329
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
174 #ifdef __cplusplus
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
175 }
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
176 #endif
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
177 #endif /* !Py_STRINGOBJECT_H */