Mercurial > cpython-lru_cache-weakref
annotate Include/codecs.h @ 25838:8540887bcec6 2.2
Backport of 2.183:
Fix memory leak in add_subclass() found by NealN with valgrind.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 18 Oct 2002 13:42:21 +0000 |
| parents | 254f8b7c4a83 |
| children | c1eb668525e1 |
| rev | line source |
|---|---|
|
11961
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 #ifndef Py_CODECREGISTRY_H |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 #define Py_CODECREGISTRY_H |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 #ifdef __cplusplus |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 extern "C" { |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 #endif |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
7 /* ------------------------------------------------------------------------ |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 Python Codec Registry and support functions |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 Written by Marc-Andre Lemburg (mal@lemburg.com). |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 |
|
13828
254f8b7c4a83
Changing the CNRI copyright notice according to CNRI's instructions.
Guido van Rossum <guido@python.org>
parents:
12642
diff
changeset
|
14 Copyright (c) Corporation for National Research Initiatives. |
|
11961
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 ------------------------------------------------------------------------ */ |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
17 |
|
12642
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
18 /* Register a new codec search function. |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
19 |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
20 As side effect, this tries to load the encodings package, if not |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
21 yet done, to make sure that it is always first in the list of |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
22 search functions. |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
23 |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
24 The search_function's refcount is incremented by this function. */ |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
25 |
|
11961
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
26 extern DL_IMPORT(int) PyCodec_Register( |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
27 PyObject *search_function |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
28 ); |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 |
|
12642
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
30 /* Codec register lookup API. |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
31 |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
32 Looks up the given encoding and returns a tuple (encoder, decoder, |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
33 stream reader, stream writer) of functions which implement the |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
34 different aspects of processing the encoding. |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
35 |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
36 The encoding string is looked up converted to all lower-case |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
37 characters. This makes encodings looked up through this mechanism |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
38 effectively case-insensitive. |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
39 |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
40 If no codec is found, a KeyError is set and NULL returned. |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
41 |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
42 As side effect, this tries to load the encodings package, if not |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
43 yet done. This is part of the lazy load strategy for the encodings |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
44 package. |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
45 |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
46 */ |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
47 |
|
11961
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
48 extern DL_IMPORT(PyObject *) _PyCodec_Lookup( |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
49 const char *encoding |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
50 ); |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
51 |
|
12642
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
52 /* Generic codec based encoding API. |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
53 |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
54 object is passed through the encoder function found for the given |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
55 encoding using the error handling method defined by errors. errors |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
56 may be NULL to use the default method defined for the codec. |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
57 |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
58 Raises a LookupError in case no encoder can be found. |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
59 |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
60 */ |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
61 |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
62 extern DL_IMPORT(PyObject *) PyCodec_Encode( |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
63 PyObject *object, |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
64 const char *encoding, |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
65 const char *errors |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
66 ); |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
67 |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
68 /* Generic codec based decoding API. |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
69 |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
70 object is passed through the decoder function found for the given |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
71 encoding using the error handling method defined by errors. errors |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
72 may be NULL to use the default method defined for the codec. |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
73 |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
74 Raises a LookupError in case no encoder can be found. |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
75 |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
76 */ |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
77 |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
78 extern DL_IMPORT(PyObject *) PyCodec_Decode( |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
79 PyObject *object, |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
80 const char *encoding, |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
81 const char *errors |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
82 ); |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
83 |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
84 /* --- Codec Lookup APIs -------------------------------------------------- |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
85 |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
86 All APIs return a codec object with incremented refcount and are |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
87 based on _PyCodec_Lookup(). The same comments w/r to the encoding |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
88 name also apply to these APIs. |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
89 |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
90 */ |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
91 |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
92 /* Get an encoder function for the given encoding. */ |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
93 |
|
11961
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
94 extern DL_IMPORT(PyObject *) PyCodec_Encoder( |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
95 const char *encoding |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
96 ); |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
97 |
|
12642
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
98 /* Get a decoder function for the given encoding. */ |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
99 |
|
11961
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
100 extern DL_IMPORT(PyObject *) PyCodec_Decoder( |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
101 const char *encoding |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
102 ); |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
103 |
|
12642
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
104 /* Get a StreamReader factory function for the given encoding. */ |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
105 |
|
11961
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
106 extern DL_IMPORT(PyObject *) PyCodec_StreamReader( |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
107 const char *encoding, |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
108 PyObject *stream, |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
109 const char *errors |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
110 ); |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
111 |
|
12642
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
112 /* Get a StreamWriter factory function for the given encoding. */ |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
113 |
|
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
114 extern DL_IMPORT(PyObject *) PyCodec_StreamWriter( |
|
11961
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
115 const char *encoding, |
|
12642
91b2ec207633
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
11961
diff
changeset
|
116 PyObject *stream, |
|
11961
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
117 const char *errors |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
118 ); |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
119 |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
120 #ifdef __cplusplus |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
121 } |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
122 #endif |
|
9d53fc8043ba
Python Codec Registry and support functions, by Marc-Andre Lemburg.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
123 #endif /* !Py_CODECREGISTRY_H */ |
