8000 Remove private _PyCodec_Lookup() function (#106269) · python/cpython@0b51463 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0b51463

Browse files
authored
Remove private _PyCodec_Lookup() function (#106269)
Remove the following private functions of the C API: * _PyCodecInfo_GetIncrementalDecoder() * _PyCodecInfo_GetIncrementalEncoder() * _PyCodec_DecodeText() * _PyCodec_EncodeText() * _PyCodec_Forget() * _PyCodec_Lookup() * _PyCodec_LookupTextEncoding() Move these functions to a new pycore_codecs.h internal header file. These functions are no longer exported.
1 parent e17420d commit 0b51463

File tree

9 files changed

+87
-97
lines changed

9 files changed

+87
-97
lines changed

Include/codecs.h

Lines changed: 24 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -35,34 +35,6 @@ PyAPI_FUNC(int) PyCodec_Unregister(
3535
PyObject *search_function
3636
);
3737

38-
/* Codec registry lookup API.
39-
40-
Looks up the given encoding and returns a CodecInfo object with
41-
function attributes which implement the different aspects of
42-
processing the encoding.
43-
44-
The encoding string is looked up converted to all lower-case
45-
characters. This makes encodings looked up through this mechanism
46-
effectively case-insensitive.
47-
48-
If no codec is found, a KeyError is set and NULL returned.
49-
50-
As side effect, this tries to load the encodings package, if not
51-
yet done. This is part of the lazy load strategy for the encodings
52-
package.
53-
54-
*/
55-
56-
#ifndef Py_LIMITED_API
57-
PyAPI_FUNC(PyObject *) _PyCodec_Lookup(
58-
const char *encoding
59-
);
60-
61-
PyAPI_FUNC(int) _PyCodec_Forget(
62-
const char *encoding
63-
);
64-
#endif
65-
6638
/* Codec registry encoding check API.
6739
6840
Returns 1/0 depending on whether there is a registered codec for
@@ -106,102 +78,58 @@ PyAPI_FUNC(PyObject *) PyCodec_Decode(
10678
const char *errors
10779
);
10880

109-
#ifndef Py_LIMITED_API
110-
/* Text codec specific encoding and decoding API.
111-
112-
Checks the encoding against a list of codecs which do not
113-
implement a str<->bytes encoding before attempting the
114-
operation.
81+
// --- Codec Lookup APIs --------------------------------------------------
11582

116-
Please note that these APIs are internal and should not
117-
be used in Python C extensions.
118-
119-
XXX (ncoghlan): should we make these, or something like them, public
120-
in Python 3.5+?
83+
/* Codec registry lookup API.
12184
122-
*/
123-
PyAPI_FUNC(PyObject *) _PyCodec_LookupTextEncoding(
124-
const char *encoding,
125-
const char *alternate_command
126-
);
85+
Looks up the given encoding and returns a CodecInfo object with
86+
function attributes which implement the different aspects of
87+
processing the encoding.
12788
128-
PyAPI_FUNC(PyObject *) _PyCodec_EncodeText(
129-
PyObject *object,
130-
const char *encoding,
131-
const char *errors
132-
);
89+
The encoding string is looked up converted to all lower-case
90+
characters. This makes encodings looked up through this mechanism
91+
effectively case-insensitive.
13392
134-
PyAPI_FUNC(PyObject *) _PyCodec_DecodeText(
135-
PyObject *object,
136-
const char *encoding,
137-
const char *errors
138-
);
93+
If no codec is found, a KeyError is set and NULL returned.
13994
140-
/* These two aren't actually text encoding specific, but _io.TextIOWrapper
141-
* is the only current API consumer.
95+
As side effect, this tries to load the encodings package, if not
96+
yet done. This is part of the lazy load strategy for the encodings
97+
package.
14298
*/
143-
PyAPI_FUNC(PyObject *) _PyCodecInfo_GetIncrementalDecoder(
144-
PyObject *codec_info,
145-
const char *errors
146-
);
147-
148-
PyAPI_FUNC(PyObject *) _PyCodecInfo_GetIncrementalEncoder(
149-
PyObject *codec_info,
150-
const char *errors
151-
);
152-
#endif
153-
154-
155-
156-
/* --- Codec Lookup APIs --------------------------------------------------
157-
158-
All APIs return a codec object with incremented refcount and are
159-
based on _PyCodec_Lookup(). The same comments w/r to the encoding
160-
name also apply to these APIs.
161-
162-
*/
16399

164100
/* Get an encoder function for the given encoding. */
165101

166-
PyAPI_FUNC(PyObject *) PyCodec_Encoder(
167-
const char *encoding
168-
);
102+
PyAPI_FUNC(PyObject *) PyCodec_Encoder(const char *encoding);
169103

170104
/* Get a decoder function for the given encoding. */
171105

172-
PyAPI_FUNC(PyObject *) PyCodec_Decoder(
173-
const char *encoding
174-
);
106+
PyAPI_FUNC(PyObject *) PyCodec_Decoder(const char *encoding);
175107

176108
/* Get an IncrementalEncoder object for the given encoding. */
177109

178110
PyAPI_FUNC(PyObject *) PyCodec_IncrementalEncoder(
179-
const char *encoding,
180-
const char *errors
181-
);
111+
const char *encoding,
112+
const char *errors);
182113

183114
/* Get an IncrementalDecoder object function for the given encoding. */
184115

185116
PyAPI_FUNC(PyObject *) PyCodec_IncrementalDecoder(
186-
const char *encoding,
187-
const char *errors
188-
);
117+
const char *encoding,
118+
const char *errors);
189119

190120
/* Get a StreamReader factory function for the given encoding. */
191121

192122
PyAPI_FUNC(PyObject *) PyCodec_StreamReader(
193-
const char *encoding,
194-
PyObject *stream,
195-
const char *errors
196-
);
123+
const char *encoding,
124+
PyObject *stream,
125+
const char *errors);
197126

198127
/* Get a StreamWriter factory function for the given encoding. */
199128

200129
PyAPI_FUNC(PyObject *) PyCodec_StreamWriter(
201-
const char *encoding,
202-
PyObject *stream,
203-
const char *errors
204-
);
130+
const char *encoding,
131+
PyObject *stream,
132+
const char *errors);
205133

206134
/* Unicode encoding error handling callback registry API */
207135

Include/internal/pycore_codecs.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#ifndef Py_INTERNAL_CODECS_H
2+
#define Py_INTERNAL_CODECS_H
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif
6+
7+
extern PyObject* _PyCodec_Lookup(const char *encoding);
8+
9+
extern int _PyCodec_Forget(const char *encoding);
10+
11+
/* Text codec specific encoding and decoding API.
12+
13+
Checks the encoding against a list of codecs which do not
14+
implement a str<->bytes encoding before attempting the
15+
operation.
16+
17+
Please note that these APIs are internal and should not
18+
be used in Python C extensions.
19+
20+
XXX (ncoghlan): should we make these, or something like them, public
21+
in Python 3.5+?
22+
23+
*/
24+
extern PyObject* _PyCodec_LookupTextEncoding(
25+
const char *encoding,
26+
const char *alternate_command);
27+
28+
extern PyObject* _PyCodec_EncodeText(
29+
PyObject *object,
30+
const char *encoding,
31+
const char *errors);
32+
33+
extern PyObject* _PyCodec_DecodeText(
34+
PyObject *object,
35+
const char *encoding,
36+
const char *errors);
37+
38+
/* These two aren't actually text encoding specific, but _io.TextIOWrapper
39+
* is the only current API consumer.
40+
*/
41+
extern PyObject* _PyCodecInfo_GetIncrementalDecoder(
42+
PyObject *codec_info,
43+
const char *errors);
44+
45+
extern PyObject* _PyCodecInfo_GetIncrementalEncoder(
46+
PyObject *codec_info,
47+
const char *errors);
48+
49+
50+
#ifdef __cplusplus
51+
}
52+
#endif
53+
#endif /* !Py_INTERNAL_CODECS_H */

Makefile.pre.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,6 +1732,7 @@ PYTHON_HEADERS= \
17321732
$(srcdir)/Include/internal/pycore_ceval.h \
17331733
$(srcdir)/Include/internal/pycore_ceval_state.h \
17341734
$(srcdir)/Include/internal/pycore_code.h \
1735+
$(srcdir)/Include/internal/pycore_codecs.h \
17351736
$(srcdir)/Include/internal/pycore_compile.h \
17361737
$(srcdir)/Include/internal/pycore_condvar.h \
17371738
$(srcdir)/Include/internal/pycore_context.h \

Modules/_codecsmodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Copyright (c) Corporation for National Research Initiatives.
3232

3333
#define PY_SSIZE_T_CLEAN
3434
#include "Python.h"
35+
#include "pycore_codecs.h" // _PyCodec_Lookup()
3536

3637
#ifdef MS_WINDOWS
3738
#include <windows.h>

Modules/_io/textio.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#define PY_SSIZE_T_CLEAN
1010
#include "Python.h"
1111
#include "pycore_call.h" // _PyObject_CallMethod()
12+
#include "pycore_codecs.h" // _PyCodecInfo_GetIncrementalDecoder()
1213
#include "pycore_interp.h" // PyInterpreterState.fs_codec
1314
#include "pycore_long.h" // _PyLong_GetZero()
1415
#include "pycore_fileutils.h" // _Py_GetLocaleEncoding()

Objects/unicodeobject.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
4242
#include "Python.h"
4343
#include "pycore_abstract.h" // _PyIndex_Check()
4444
#include "pycore_atomic_funcs.h" // _Py_atomic_size_get()
45-
#include "pycore_bytesobject.h" // _PyBytes_Repeat()
4645
#include "pycore_bytes_methods.h" // _Py_bytes_lower()
46+
#include "pycore_bytesobject.h" // _PyBytes_Repeat()
47+
#include "pycore_codecs.h" // _PyCodec_Lookup()
4748
#include "pycore_format.h" // F_LJUST
4849
#include "pycore_initconfig.h" // _PyStatus_OK()
4950
#include "pycore_interp.h" // PyInterpreterState.fs_codec

PCbuild/pythoncore.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@
209209
<ClInclude Include="..\Include\internal\pycore_ceval_state.h" />
210210
<ClInclude Include="..\Include\internal\pycore_cfg.h" />
211211
<ClInclude Include="..\Include\internal\pycore_code.h" />
212+
<ClInclude Include="..\Include\internal\pycore_codecs.h" />
212213
<ClInclude Include="..\Include\internal\pycore_compile.h" />
213214
<ClInclude Include="..\Include\internal\pycore_condvar.h" />
214215
<ClInclude Include="..\Include\internal\pycore_context.h" />

PCbuild/pythoncore.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,9 @@
537537
<ClInclude Include="..\Include\internal\pycore_code.h">
538538
<Filter>Include\internal</Filter>
539539
</ClInclude>
540+
<ClInclude Include="..\Include\internal\pycore_codecs.h">
541+
<Filter>Include\internal</Filter>
542+
</ClInclude>
540543
<ClInclude Include="..\Include\internal\pycore_compile.h">
541544
<Filter>Include\internal</Filter>
542545
</ClInclude>

Python/pylifecycle.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "pycore_call.h" // _PyObject_CallMethod()
66
#include "pycore_ceval.h" // _PyEval_FiniGIL()
7+
#include "pycore_codecs.h" // _PyCodec_Lookup()
78
#include "pycore_context.h" // _PyContext_Init()
89
#include "pycore_dict.h" // _PyDict_Fini()
910
#include "pycore_exceptions.h" // _PyExc_InitTypes()

0 commit comments

Comments
 (0)
0