Mercurial > cpython-lru_cache-weakref
annotate Include/bytesobject.h @ 87690:66c1c9f32567 default tip
Add use_weakref option to functools.lru_cache
The use_weakref option makes lru_cache create weak references to the function
arguments when creating the cache key, which prevents them from staying in the
memory forever even after all other references to them are gone.
This is a proof of concept for http://bugs.python.org/issue19859
| author | Radomir Dopieralski <devel@sheep.art.pl> |
|---|---|
| date | Tue, 03 Dec 2013 16:02:48 +0100 |
| parents | e7f6cef7a4cc |
| children |
| 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 |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
65494
diff
changeset
|
30 #ifndef Py_LIMITED_API |
| 6 | 31 typedef struct { |
|
13445
091ca6b9348f
ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents:
13376
diff
changeset
|
32 PyObject_VAR_HEAD |
|
65494
e8969fb822fc
make hashes always the size of pointers; introduce Py_hash_t #9778
Benjamin Peterson <benjamin@python.org>
parents:
53187
diff
changeset
|
33 Py_hash_t ob_shash; |
|
13445
091ca6b9348f
ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents:
13376
diff
changeset
|
34 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
|
35 |
|
60c60dc75c77
Wrote down the invariants of some common objects whose structure is
Armin Rigo <arigo@tunes.org>
parents:
29726
diff
changeset
|
36 /* Invariants: |
|
60c60dc75c77
Wrote down the invariants of some common objects whose structure is
Armin Rigo <arigo@tunes.org>
parents:
29726
diff
changeset
|
37 * 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
|
38 * 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
|
39 * 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
|
40 */ |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
41 } PyBytesObject; |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
65494
diff
changeset
|
42 #endif |
| 6 | 43 |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
44 PyAPI_DATA(PyTypeObject) PyBytes_Type; |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
45 PyAPI_DATA(PyTypeObject) PyBytesIter_Type; |
| 6 | 46 |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
47 #define PyBytes_Check(op) \ |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
48 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_BYTES_SUBCLASS) |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
49 #define PyBytes_CheckExact(op) (Py_TYPE(op) == &PyBytes_Type) |
| 6 | 50 |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
51 PyAPI_FUNC(PyObject *) PyBytes_FromStringAndSize(const char *, Py_ssize_t); |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
52 PyAPI_FUNC(PyObject *) PyBytes_FromString(const char *); |
|
48871
548dccc4008e
make bytes(o) respect __bytes__ #2415
Benjamin Peterson <benjamin@python.org>
parents:
48358
diff
changeset
|
53 PyAPI_FUNC(PyObject *) PyBytes_FromObject(PyObject *); |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
54 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
|
55 Py_GCC_ATTRIBUTE((format(printf, 1, 0))); |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
56 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
|
57 Py_GCC_ATTRIBUTE((format(printf, 1, 2))); |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
58 PyAPI_FUNC(Py_ssize_t) PyBytes_Size(PyObject *); |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
59 PyAPI_FUNC(char *) PyBytes_AsString(PyObject *); |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
60 PyAPI_FUNC(PyObject *) PyBytes_Repr(PyObject *, int); |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
61 PyAPI_FUNC(void) PyBytes_Concat(PyObject **, PyObject *); |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
62 PyAPI_FUNC(void) PyBytes_ConcatAndDel(PyObject **, PyObject *); |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
65494
diff
changeset
|
63 #ifndef Py_LIMITED_API |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
64 PyAPI_FUNC(int) _PyBytes_Resize(PyObject **, Py_ssize_t); |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
65494
diff
changeset
|
65 #endif |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
66 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
|
67 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
|
68 const char *); |
| 6 | 69 |
| 70 /* Macro, trading safety for speed */ | |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
65494
diff
changeset
|
71 #ifndef Py_LIMITED_API |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
72 #define PyBytes_AS_STRING(op) (assert(PyBytes_Check(op)), \ |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
73 (((PyBytesObject *)(op))->ob_sval)) |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
74 #define PyBytes_GET_SIZE(op) (assert(PyBytes_Check(op)),Py_SIZE(op)) |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
65494
diff
changeset
|
75 #endif |
|
1329
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
76 |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
77 /* _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
|
78 x must be an iterable object. */ |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
65494
diff
changeset
|
79 #ifndef Py_LIMITED_API |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
80 PyAPI_FUNC(PyObject *) _PyBytes_Join(PyObject *sep, PyObject *x); |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
65494
diff
changeset
|
81 #endif |
|
18129
9d533ae574d2
SF bug 433228: repr(list) woes when len(list) big.
Tim Peters <tim.peters@gmail.com>
parents:
17964
diff
changeset
|
82 |
|
14696
85038a024b19
This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents:
14375
diff
changeset
|
83 /* 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
|
84 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
|
85 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
|
86 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
|
87 cause an exception). */ |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46909
diff
changeset
|
88 PyAPI_FUNC(int) PyBytes_AsStringAndSize( |
|
85157
e7f6cef7a4cc
Issue #18722: Remove uses of the "register" keyword in C code.
Antoine Pitrou <solipsis@pitrou.net>
parents:
76588
diff
changeset
|
89 PyObject *obj, /* string or Unicode object */ |
|
e7f6cef7a4cc
Issue #18722: Remove uses of the "register" keyword in C code.
Antoine Pitrou <solipsis@pitrou.net>
parents:
76588
diff
changeset
|
90 char **s, /* pointer to buffer variable */ |
|
e7f6cef7a4cc
Issue #18722: Remove uses of the "register" keyword in C code.
Antoine Pitrou <solipsis@pitrou.net>
parents:
76588
diff
changeset
|
91 Py_ssize_t *len /* pointer to length variable or NULL |
|
e7f6cef7a4cc
Issue #18722: Remove uses of the "register" keyword in C code.
Antoine Pitrou <solipsis@pitrou.net>
parents:
76588
diff
changeset
|
92 (only possible for 0-terminated |
|
e7f6cef7a4cc
Issue #18722: Remove uses of the "register" keyword in C code.
Antoine Pitrou <solipsis@pitrou.net>
parents:
76588
diff
changeset
|
93 strings) */ |
|
14696
85038a024b19
This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents:
14375
diff
changeset
|
94 ); |
|
43692
50a3475db466
Kill PyString_Encode(), which isn't used anywhere.
Guido van Rossum <guido@python.org>
parents:
43577
diff
changeset
|
95 |
|
46909
ef4ec968fdb6
Merged revisions 63078 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
44351
diff
changeset
|
96 /* Using the current locale, insert the thousands grouping |
|
ef4ec968fdb6
Merged revisions 63078 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
44351
diff
changeset
|
97 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
|
98 see Objects/stringlib/localeutil.h */ |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
65494
diff
changeset
|
99 #ifndef Py_LIMITED_API |
|
53187
b653eab13b73
The other half of Issue #1580: use short float repr where possible.
Eric Smith <eric@trueblade.com>
parents:
52773
diff
changeset
|
100 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
|
101 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
|
102 char *digits, |
|
b653eab13b73
The other half of Issue #1580: use short float repr where possible.
Eric Smith <eric@trueblade.com>
parents:
52773
diff
changeset
|
103 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
|
104 Py_ssize_t min_width); |
|
46909
ef4ec968fdb6
Merged revisions 63078 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
44351
diff
changeset
|
105 |
|
52773
28096ed73153
Added ',' thousands grouping to int.__format__. See PEP 378.
Eric Smith <eric@trueblade.com>
parents:
48871
diff
changeset
|
106 /* 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
|
107 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
|
108 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
|
109 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
|
110 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
|
111 char *digits, |
|
b653eab13b73
The other half of Issue #1580: use short float repr where possible.
Eric Smith <eric@trueblade.com>
parents:
52773
diff
changeset
|
112 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
|
113 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
|
114 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
|
115 const char *thousands_sep); |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
65494
diff
changeset
|
116 #endif |
|
52773
28096ed73153
Added ',' thousands grouping to int.__format__. See PEP 378.
Eric Smith <eric@trueblade.com>
parents:
48871
diff
changeset
|
117 |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43692
diff
changeset
|
118 /* 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
|
119 #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
|
120 #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
|
121 #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
|
122 #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
|
123 #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
|
124 |
|
1329
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
125 #ifdef __cplusplus |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
126 } |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
127 #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
|
128 #endif /* !Py_BYTESOBJECT_H */ |
