Mercurial > cpython-lru_cache-weakref
annotate Include/bytesobject.h @ 58689:514b56efd89a 3.1
Merged revisions 77962 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r77962 | r.david.murray | 2010-02-04 11:41:57 -0500 (Thu, 04 Feb 2010) | 17 lines
Merged revisions 77943,77959-77960 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77943 | r.david.murray | 2010-02-03 08:36:23 -0500 (Wed, 03 Feb 2010) | 2 lines
Explicitly mention the default value for formatdate's usegmt parameter.
........
r77959 | nick.coghlan | 2010-02-04 07:43:58 -0500 (Thu, 04 Feb 2010) | 1 line
Issue 6760: Clarify args handling for subprocess.Popen. Patch by Chris Rebert
........
r77960 | r.david.murray | 2010-02-04 11:33:31 -0500 (Thu, 04 Feb 2010) | 2 lines
Add Chris Rebert to ACKS for issue 6760 Popen doc improvements.
........
................
| author | R. David Murray <rdmurray@bitdance.com> |
|---|---|
| date | Thu, 04 Feb 2010 16:44:31 +0000 |
| parents | b653eab13b73 |
| children | e8969fb822fc |
| rev | line source |
|---|---|
| 145 | 1 |
|
47555
7d824fd131ad
Merged revisions 63829-63831,63858,63865,63879,63882,63948,63970-63972,63976,63989,64014-64015,64021-64022,64063-64065,64067 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47313
diff
changeset
|
2 /* Bytes (String) object interface */ |
| 6 | 3 |
|
47555
7d824fd131ad
Merged revisions 63829-63831,63858,63865,63879,63882,63948,63970-63972,63976,63989,64014-64015,64021-64022,64063-64065,64067 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47313
diff
changeset
|
4 #ifndef Py_BYTESOBJECT_H |
|
7d824fd131ad
Merged revisions 63829-63831,63858,63865,63879,63882,63948,63970-63972,63976,63989,64014-64015,64021-64022,64063-64065,64067 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47313
diff
changeset
|
5 #define Py_BYTESOBJECT_H |
|
13445
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 | 12 /* |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
13 Type PyBytesObject represents a character string. An extra zero byte is |
| 6 | 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 | |
|
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 | 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 */ |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
40 } PyBytesObject; |
| 6 | 41 |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
42 PyAPI_DATA(PyTypeObject) PyBytes_Type; |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
43 PyAPI_DATA(PyTypeObject) PyBytesIter_Type; |
| 6 | 44 |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
45 #define PyBytes_Check(op) \ |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
46 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_BYTES_SUBCLASS) |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
47 #define PyBytes_CheckExact(op) (Py_TYPE(op) == &PyBytes_Type) |
| 6 | 48 |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
49 PyAPI_FUNC(PyObject *) PyBytes_FromStringAndSize(const char *, Py_ssize_t); |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
50 PyAPI_FUNC(PyObject *) PyBytes_FromString(const char *); |
|
48871
548dccc4008e
make bytes(o) respect __bytes__ #2415
Benjamin Peterson <benjamin@python.org>
parents:
48358
diff
changeset
|
51 PyAPI_FUNC(PyObject *) PyBytes_FromObject(PyObject *); |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
52 PyAPI_FUNC(PyObject *) PyBytes_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
|
53 Py_GCC_ATTRIBUTE((format(printf, 1, 0))); |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
54 PyAPI_FUNC(PyObject *) PyBytes_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
|
55 Py_GCC_ATTRIBUTE((format(printf, 1, 2))); |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
56 PyAPI_FUNC(Py_ssize_t) PyBytes_Size(PyObject *); |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
57 PyAPI_FUNC(char *) PyBytes_AsString(PyObject *); |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
58 PyAPI_FUNC(PyObject *) PyBytes_Repr(PyObject *, int); |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
59 PyAPI_FUNC(void) PyBytes_Concat(PyObject **, PyObject *); |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
60 PyAPI_FUNC(void) PyBytes_ConcatAndDel(PyObject **, PyObject *); |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
61 PyAPI_FUNC(int) _PyBytes_Resize(PyObject **, Py_ssize_t); |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
62 PyAPI_FUNC(PyObject *) _PyBytes_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*); |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
64 PyAPI_FUNC(PyObject *) PyBytes_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 | 67 |
| 68 /* Macro, trading safety for speed */ | |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
69 #define PyBytes_AS_STRING(op) (assert(PyBytes_Check(op)), \ |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
70 (((PyBytesObject *)(op))->ob_sval)) |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
71 #define PyBytes_GET_SIZE(op) (assert(PyBytes_Check(op)),Py_SIZE(op)) |
|
1329
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
72 |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
73 /* _PyBytes_Join(sep, x) is like sep.join(x). sep must be PyBytesObject*, |
|
18129
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. */ |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
75 PyAPI_FUNC(PyObject *) _PyBytes_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). */ |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
82 PyAPI_FUNC(int) PyBytes_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 |
|
46909
ef4ec968fdb6
Merged revisions 63078 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
44351
diff
changeset
|
90 /* Using the current locale, insert the thousands grouping |
|
ef4ec968fdb6
Merged revisions 63078 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
44351
diff
changeset
|
91 into the string pointed to by buffer. For the argument descriptions, |
|
ef4ec968fdb6
Merged revisions 63078 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
44351
diff
changeset
|
92 see Objects/stringlib/localeutil.h */ |
|
ef4ec968fdb6
Merged revisions 63078 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
44351
diff
changeset
|
93 |
|
53187
b653eab13b73
The other half of Issue #1580: use short float repr where possible.
Eric Smith <eric@trueblade.com>
parents:
52773
diff
changeset
|
94 PyAPI_FUNC(Py_ssize_t) _PyBytes_InsertThousandsGroupingLocale(char *buffer, |
|
b653eab13b73
The other half of Issue #1580: use short float repr where possible.
Eric Smith <eric@trueblade.com>
parents:
52773
diff
changeset
|
95 Py_ssize_t n_buffer, |
|
b653eab13b73
The other half of Issue #1580: use short float repr where possible.
Eric Smith <eric@trueblade.com>
parents:
52773
diff
changeset
|
96 char *digits, |
|
b653eab13b73
The other half of Issue #1580: use short float repr where possible.
Eric Smith <eric@trueblade.com>
parents:
52773
diff
changeset
|
97 Py_ssize_t n_digits, |
|
b653eab13b73
The other half of Issue #1580: use short float repr where possible.
Eric Smith <eric@trueblade.com>
parents:
52773
diff
changeset
|
98 Py_ssize_t min_width); |
|
46909
ef4ec968fdb6
Merged revisions 63078 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
44351
diff
changeset
|
99 |
|
52773
28096ed73153
Added ',' thousands grouping to int.__format__. See PEP 378.
Eric Smith <eric@trueblade.com>
parents:
48871
diff
changeset
|
100 /* Using explicit passed-in values, insert the thousands grouping |
|
28096ed73153
Added ',' thousands grouping to int.__format__. See PEP 378.
Eric Smith <eric@trueblade.com>
parents:
48871
diff
changeset
|
101 into the string pointed to by buffer. For the argument descriptions, |
|
28096ed73153
Added ',' thousands grouping to int.__format__. See PEP 378.
Eric Smith <eric@trueblade.com>
parents:
48871
diff
changeset
|
102 see Objects/stringlib/localeutil.h */ |
|
53187
b653eab13b73
The other half of Issue #1580: use short float repr where possible.
Eric Smith <eric@trueblade.com>
parents:
52773
diff
changeset
|
103 PyAPI_FUNC(Py_ssize_t) _PyBytes_InsertThousandsGrouping(char *buffer, |
|
b653eab13b73
The other half of Issue #1580: use short float repr where possible.
Eric Smith <eric@trueblade.com>
parents:
52773
diff
changeset
|
104 Py_ssize_t n_buffer, |
|
b653eab13b73
The other half of Issue #1580: use short float repr where possible.
Eric Smith <eric@trueblade.com>
parents:
52773
diff
changeset
|
105 char *digits, |
|
b653eab13b73
The other half of Issue #1580: use short float repr where possible.
Eric Smith <eric@trueblade.com>
parents:
52773
diff
changeset
|
106 Py_ssize_t n_digits, |
|
b653eab13b73
The other half of Issue #1580: use short float repr where possible.
Eric Smith <eric@trueblade.com>
parents:
52773
diff
changeset
|
107 Py_ssize_t min_width, |
|
b653eab13b73
The other half of Issue #1580: use short float repr where possible.
Eric Smith <eric@trueblade.com>
parents:
52773
diff
changeset
|
108 const char *grouping, |
|
b653eab13b73
The other half of Issue #1580: use short float repr where possible.
Eric Smith <eric@trueblade.com>
parents:
52773
diff
changeset
|
109 const char *thousands_sep); |
|
52773
28096ed73153
Added ',' thousands grouping to int.__format__. See PEP 378.
Eric Smith <eric@trueblade.com>
parents:
48871
diff
changeset
|
110 |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43692
diff
changeset
|
111 /* 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
|
112 #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
|
113 #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
|
114 #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
|
115 #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
|
116 #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
|
117 |
|
1329
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
118 #ifdef __cplusplus |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
119 } |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
120 #endif |
|
47555
7d824fd131ad
Merged revisions 63829-63831,63858,63865,63879,63882,63948,63970-63972,63976,63989,64014-64015,64021-64022,64063-64065,64067 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47313
diff
changeset
|
121 #endif /* !Py_BYTESOBJECT_H */ |
