blob: a8223ad0a1d320e101463b19afeb4f45c6204490 [file] [log] [blame]
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03005PyDoc_STRVAR(_codecs_register__doc__,
6"register($module, search_function, /)\n"
7"--\n"
8"\n"
9"Register a codec search function.\n"
10"\n"
11"Search functions are expected to take one argument, the encoding name in\n"
12"all lower case letters, and either return None, or a tuple of functions\n"
13"(encoder, decoder, stream_reader, stream_writer) (or a CodecInfo object).");
14
15#define _CODECS_REGISTER_METHODDEF \
16 {"register", (PyCFunction)_codecs_register, METH_O, _codecs_register__doc__},
17
18PyDoc_STRVAR(_codecs_lookup__doc__,
19"lookup($module, encoding, /)\n"
20"--\n"
21"\n"
22"Looks up a codec tuple in the Python codec registry and returns a CodecInfo object.");
23
24#define _CODECS_LOOKUP_METHODDEF \
25 {"lookup", (PyCFunction)_codecs_lookup, METH_O, _codecs_lookup__doc__},
26
27static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030028_codecs_lookup_impl(PyObject *module, const char *encoding);
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030029
30static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030031_codecs_lookup(PyObject *module, PyObject *arg)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030032{
33 PyObject *return_value = NULL;
34 const char *encoding;
35
Serhiy Storchaka32d96a22018-12-25 13:23:47 +020036 if (!PyUnicode_Check(arg)) {
Serhiy Storchaka4fa95912019-01-11 16:01:14 +020037 _PyArg_BadArgument("lookup", 0, "str", arg);
Serhiy Storchaka32d96a22018-12-25 13:23:47 +020038 goto exit;
39 }
40 Py_ssize_t encoding_length;
41 encoding = PyUnicode_AsUTF8AndSize(arg, &encoding_length);
42 if (encoding == NULL) {
43 goto exit;
44 }
45 if (strlen(encoding) != (size_t)encoding_length) {
46 PyErr_SetString(PyExc_ValueError, "embedded null character");
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030047 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030048 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030049 return_value = _codecs_lookup_impl(module, encoding);
50
51exit:
52 return return_value;
53}
54
55PyDoc_STRVAR(_codecs_encode__doc__,
Serhiy Storchakac97a9622015-08-09 12:23:08 +030056"encode($module, /, obj, encoding=\'utf-8\', errors=\'strict\')\n"
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030057"--\n"
58"\n"
59"Encodes obj using the codec registered for encoding.\n"
60"\n"
Serhiy Storchakac97a9622015-08-09 12:23:08 +030061"The default encoding is \'utf-8\'. errors may be given to set a\n"
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030062"different error handling scheme. Default is \'strict\' meaning that encoding\n"
63"errors raise a ValueError. Other possible values are \'ignore\', \'replace\'\n"
64"and \'backslashreplace\' as well as any other name registered with\n"
65"codecs.register_error that can handle ValueErrors.");
66
67#define _CODECS_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +020068 {"encode", (PyCFunction)(void(*)(void))_codecs_encode, METH_FASTCALL|METH_KEYWORDS, _codecs_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030069
70static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030071_codecs_encode_impl(PyObject *module, PyObject *obj, const char *encoding,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030072 const char *errors);
73
74static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +020075_codecs_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030076{
77 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +030078 static const char * const _keywords[] = {"obj", "encoding", "errors", NULL};
79 static _PyArg_Parser _parser = {"O|ss:encode", _keywords, 0};
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030080 PyObject *obj;
81 const char *encoding = NULL;
82 const char *errors = NULL;
83
Victor Stinner3e1fad62017-01-17 01:29:01 +010084 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030085 &obj, &encoding, &errors)) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030086 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030087 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030088 return_value = _codecs_encode_impl(module, obj, encoding, errors);
89
90exit:
91 return return_value;
92}
93
94PyDoc_STRVAR(_codecs_decode__doc__,
Serhiy Storchakac97a9622015-08-09 12:23:08 +030095"decode($module, /, obj, encoding=\'utf-8\', errors=\'strict\')\n"
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030096"--\n"
97"\n"
98"Decodes obj using the codec registered for encoding.\n"
99"\n"
Serhiy Storchakac97a9622015-08-09 12:23:08 +0300100"Default encoding is \'utf-8\'. errors may be given to set a\n"
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300101"different error handling scheme. Default is \'strict\' meaning that encoding\n"
102"errors raise a ValueError. Other possible values are \'ignore\', \'replace\'\n"
103"and \'backslashreplace\' as well as any other name registered with\n"
104"codecs.register_error that can handle ValueErrors.");
105
106#define _CODECS_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200107 {"decode", (PyCFunction)(void(*)(void))_codecs_decode, METH_FASTCALL|METH_KEYWORDS, _codecs_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300108
109static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300110_codecs_decode_impl(PyObject *module, PyObject *obj, const char *encoding,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300111 const char *errors);
112
113static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200114_codecs_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300115{
116 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300117 static const char * const _keywords[] = {"obj", "encoding", "errors", NULL};
118 static _PyArg_Parser _parser = {"O|ss:decode", _keywords, 0};
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300119 PyObject *obj;
120 const char *encoding = NULL;
121 const char *errors = NULL;
122
Victor Stinner3e1fad62017-01-17 01:29:01 +0100123 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300124 &obj, &encoding, &errors)) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300125 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300126 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300127 return_value = _codecs_decode_impl(module, obj, encoding, errors);
128
129exit:
130 return return_value;
131}
132
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300133PyDoc_STRVAR(_codecs__forget_codec__doc__,
134"_forget_codec($module, encoding, /)\n"
135"--\n"
136"\n"
137"Purge the named codec from the internal codec lookup cache");
138
139#define _CODECS__FORGET_CODEC_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300140 {"_forget_codec", (PyCFunction)_codecs__forget_codec, METH_O, _codecs__forget_codec__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300141
142static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300143_codecs__forget_codec_impl(PyObject *module, const char *encoding);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300144
145static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300146_codecs__forget_codec(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300147{
148 PyObject *return_value = NULL;
149 const char *encoding;
150
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200151 if (!PyUnicode_Check(arg)) {
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200152 _PyArg_BadArgument("_forget_codec", 0, "str", arg);
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200153 goto exit;
154 }
155 Py_ssize_t encoding_length;
156 encoding = PyUnicode_AsUTF8AndSize(arg, &encoding_length);
157 if (encoding == NULL) {
158 goto exit;
159 }
160 if (strlen(encoding) != (size_t)encoding_length) {
161 PyErr_SetString(PyExc_ValueError, "embedded null character");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300162 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300163 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300164 return_value = _codecs__forget_codec_impl(module, encoding);
165
166exit:
167 return return_value;
168}
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300169
170PyDoc_STRVAR(_codecs_escape_decode__doc__,
171"escape_decode($module, data, errors=None, /)\n"
172"--\n"
173"\n");
174
175#define _CODECS_ESCAPE_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200176 {"escape_decode", (PyCFunction)(void(*)(void))_codecs_escape_decode, METH_FASTCALL, _codecs_escape_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300177
178static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300179_codecs_escape_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300180 const char *errors);
181
182static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200183_codecs_escape_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300184{
185 PyObject *return_value = NULL;
186 Py_buffer data = {NULL, NULL};
187 const char *errors = NULL;
188
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200189 if (!_PyArg_CheckPositional("escape_decode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100190 goto exit;
191 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200192 if (PyUnicode_Check(args[0])) {
193 Py_ssize_t len;
194 const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
195 if (ptr == NULL) {
196 goto exit;
197 }
198 PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, 0);
199 }
200 else { /* any bytes-like object */
201 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
202 goto exit;
203 }
204 if (!PyBuffer_IsContiguous(&data, 'C')) {
205 _PyArg_BadArgument("escape_decode", 1, "contiguous buffer", args[0]);
206 goto exit;
207 }
208 }
209 if (nargs < 2) {
210 goto skip_optional;
211 }
212 if (args[1] == Py_None) {
213 errors = NULL;
214 }
215 else if (PyUnicode_Check(args[1])) {
216 Py_ssize_t errors_length;
217 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
218 if (errors == NULL) {
219 goto exit;
220 }
221 if (strlen(errors) != (size_t)errors_length) {
222 PyErr_SetString(PyExc_ValueError, "embedded null character");
223 goto exit;
224 }
225 }
226 else {
227 _PyArg_BadArgument("escape_decode", 2, "str or None", args[1]);
228 goto exit;
229 }
230skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300231 return_value = _codecs_escape_decode_impl(module, &data, errors);
232
233exit:
234 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300235 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300236 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300237 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300238
239 return return_value;
240}
241
242PyDoc_STRVAR(_codecs_escape_encode__doc__,
243"escape_encode($module, data, errors=None, /)\n"
244"--\n"
245"\n");
246
247#define _CODECS_ESCAPE_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200248 {"escape_encode", (PyCFunction)(void(*)(void))_codecs_escape_encode, METH_FASTCALL, _codecs_escape_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300249
250static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300251_codecs_escape_encode_impl(PyObject *module, PyObject *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300252 const char *errors);
253
254static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200255_codecs_escape_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300256{
257 PyObject *return_value = NULL;
258 PyObject *data;
259 const char *errors = NULL;
260
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200261 if (!_PyArg_CheckPositional("escape_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100262 goto exit;
263 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200264 if (!PyBytes_Check(args[0])) {
265 _PyArg_BadArgument("escape_encode", 1, "bytes", args[0]);
266 goto exit;
267 }
268 data = args[0];
269 if (nargs < 2) {
270 goto skip_optional;
271 }
272 if (args[1] == Py_None) {
273 errors = NULL;
274 }
275 else if (PyUnicode_Check(args[1])) {
276 Py_ssize_t errors_length;
277 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
278 if (errors == NULL) {
279 goto exit;
280 }
281 if (strlen(errors) != (size_t)errors_length) {
282 PyErr_SetString(PyExc_ValueError, "embedded null character");
283 goto exit;
284 }
285 }
286 else {
287 _PyArg_BadArgument("escape_encode", 2, "str or None", args[1]);
288 goto exit;
289 }
290skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300291 return_value = _codecs_escape_encode_impl(module, data, errors);
292
293exit:
294 return return_value;
295}
296
297PyDoc_STRVAR(_codecs_unicode_internal_decode__doc__,
298"unicode_internal_decode($module, obj, errors=None, /)\n"
299"--\n"
300"\n");
301
302#define _CODECS_UNICODE_INTERNAL_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200303 {"unicode_internal_decode", (PyCFunction)(void(*)(void))_codecs_unicode_internal_decode, METH_FASTCALL, _codecs_unicode_internal_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300304
305static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300306_codecs_unicode_internal_decode_impl(PyObject *module, PyObject *obj,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300307 const char *errors);
308
309static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200310_codecs_unicode_internal_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300311{
312 PyObject *return_value = NULL;
313 PyObject *obj;
314 const char *errors = NULL;
315
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200316 if (!_PyArg_CheckPositional("unicode_internal_decode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100317 goto exit;
318 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200319 obj = args[0];
320 if (nargs < 2) {
321 goto skip_optional;
322 }
323 if (args[1] == Py_None) {
324 errors = NULL;
325 }
326 else if (PyUnicode_Check(args[1])) {
327 Py_ssize_t errors_length;
328 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
329 if (errors == NULL) {
330 goto exit;
331 }
332 if (strlen(errors) != (size_t)errors_length) {
333 PyErr_SetString(PyExc_ValueError, "embedded null character");
334 goto exit;
335 }
336 }
337 else {
338 _PyArg_BadArgument("unicode_internal_decode", 2, "str or None", args[1]);
339 goto exit;
340 }
341skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300342 return_value = _codecs_unicode_internal_decode_impl(module, obj, errors);
343
344exit:
345 return return_value;
346}
347
348PyDoc_STRVAR(_codecs_utf_7_decode__doc__,
349"utf_7_decode($module, data, errors=None, final=False, /)\n"
350"--\n"
351"\n");
352
353#define _CODECS_UTF_7_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200354 {"utf_7_decode", (PyCFunction)(void(*)(void))_codecs_utf_7_decode, METH_FASTCALL, _codecs_utf_7_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300355
356static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300357_codecs_utf_7_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300358 const char *errors, int final);
359
360static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200361_codecs_utf_7_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300362{
363 PyObject *return_value = NULL;
364 Py_buffer data = {NULL, NULL};
365 const char *errors = NULL;
366 int final = 0;
367
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200368 if (!_PyArg_CheckPositional("utf_7_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100369 goto exit;
370 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200371 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
372 goto exit;
373 }
374 if (!PyBuffer_IsContiguous(&data, 'C')) {
375 _PyArg_BadArgument("utf_7_decode", 1, "contiguous buffer", args[0]);
376 goto exit;
377 }
378 if (nargs < 2) {
379 goto skip_optional;
380 }
381 if (args[1] == Py_None) {
382 errors = NULL;
383 }
384 else if (PyUnicode_Check(args[1])) {
385 Py_ssize_t errors_length;
386 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
387 if (errors == NULL) {
388 goto exit;
389 }
390 if (strlen(errors) != (size_t)errors_length) {
391 PyErr_SetString(PyExc_ValueError, "embedded null character");
392 goto exit;
393 }
394 }
395 else {
396 _PyArg_BadArgument("utf_7_decode", 2, "str or None", args[1]);
397 goto exit;
398 }
399 if (nargs < 3) {
400 goto skip_optional;
401 }
402 if (PyFloat_Check(args[2])) {
403 PyErr_SetString(PyExc_TypeError,
404 "integer argument expected, got float" );
405 goto exit;
406 }
407 final = _PyLong_AsInt(args[2]);
408 if (final == -1 && PyErr_Occurred()) {
409 goto exit;
410 }
411skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300412 return_value = _codecs_utf_7_decode_impl(module, &data, errors, final);
413
414exit:
415 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300416 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300417 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300418 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300419
420 return return_value;
421}
422
423PyDoc_STRVAR(_codecs_utf_8_decode__doc__,
424"utf_8_decode($module, data, errors=None, final=False, /)\n"
425"--\n"
426"\n");
427
428#define _CODECS_UTF_8_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200429 {"utf_8_decode", (PyCFunction)(void(*)(void))_codecs_utf_8_decode, METH_FASTCALL, _codecs_utf_8_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300430
431static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300432_codecs_utf_8_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300433 const char *errors, int final);
434
435static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200436_codecs_utf_8_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300437{
438 PyObject *return_value = NULL;
439 Py_buffer data = {NULL, NULL};
440 const char *errors = NULL;
441 int final = 0;
442
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200443 if (!_PyArg_CheckPositional("utf_8_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100444 goto exit;
445 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200446 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
447 goto exit;
448 }
449 if (!PyBuffer_IsContiguous(&data, 'C')) {
450 _PyArg_BadArgument("utf_8_decode", 1, "contiguous buffer", args[0]);
451 goto exit;
452 }
453 if (nargs < 2) {
454 goto skip_optional;
455 }
456 if (args[1] == Py_None) {
457 errors = NULL;
458 }
459 else if (PyUnicode_Check(args[1])) {
460 Py_ssize_t errors_length;
461 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
462 if (errors == NULL) {
463 goto exit;
464 }
465 if (strlen(errors) != (size_t)errors_length) {
466 PyErr_SetString(PyExc_ValueError, "embedded null character");
467 goto exit;
468 }
469 }
470 else {
471 _PyArg_BadArgument("utf_8_decode", 2, "str or None", args[1]);
472 goto exit;
473 }
474 if (nargs < 3) {
475 goto skip_optional;
476 }
477 if (PyFloat_Check(args[2])) {
478 PyErr_SetString(PyExc_TypeError,
479 "integer argument expected, got float" );
480 goto exit;
481 }
482 final = _PyLong_AsInt(args[2]);
483 if (final == -1 && PyErr_Occurred()) {
484 goto exit;
485 }
486skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300487 return_value = _codecs_utf_8_decode_impl(module, &data, errors, final);
488
489exit:
490 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300491 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300492 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300493 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300494
495 return return_value;
496}
497
498PyDoc_STRVAR(_codecs_utf_16_decode__doc__,
499"utf_16_decode($module, data, errors=None, final=False, /)\n"
500"--\n"
501"\n");
502
503#define _CODECS_UTF_16_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200504 {"utf_16_decode", (PyCFunction)(void(*)(void))_codecs_utf_16_decode, METH_FASTCALL, _codecs_utf_16_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300505
506static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300507_codecs_utf_16_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300508 const char *errors, int final);
509
510static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200511_codecs_utf_16_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300512{
513 PyObject *return_value = NULL;
514 Py_buffer data = {NULL, NULL};
515 const char *errors = NULL;
516 int final = 0;
517
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200518 if (!_PyArg_CheckPositional("utf_16_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100519 goto exit;
520 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200521 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
522 goto exit;
523 }
524 if (!PyBuffer_IsContiguous(&data, 'C')) {
525 _PyArg_BadArgument("utf_16_decode", 1, "contiguous buffer", args[0]);
526 goto exit;
527 }
528 if (nargs < 2) {
529 goto skip_optional;
530 }
531 if (args[1] == Py_None) {
532 errors = NULL;
533 }
534 else if (PyUnicode_Check(args[1])) {
535 Py_ssize_t errors_length;
536 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
537 if (errors == NULL) {
538 goto exit;
539 }
540 if (strlen(errors) != (size_t)errors_length) {
541 PyErr_SetString(PyExc_ValueError, "embedded null character");
542 goto exit;
543 }
544 }
545 else {
546 _PyArg_BadArgument("utf_16_decode", 2, "str or None", args[1]);
547 goto exit;
548 }
549 if (nargs < 3) {
550 goto skip_optional;
551 }
552 if (PyFloat_Check(args[2])) {
553 PyErr_SetString(PyExc_TypeError,
554 "integer argument expected, got float" );
555 goto exit;
556 }
557 final = _PyLong_AsInt(args[2]);
558 if (final == -1 && PyErr_Occurred()) {
559 goto exit;
560 }
561skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300562 return_value = _codecs_utf_16_decode_impl(module, &data, errors, final);
563
564exit:
565 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300566 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300567 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300568 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300569
570 return return_value;
571}
572
573PyDoc_STRVAR(_codecs_utf_16_le_decode__doc__,
574"utf_16_le_decode($module, data, errors=None, final=False, /)\n"
575"--\n"
576"\n");
577
578#define _CODECS_UTF_16_LE_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200579 {"utf_16_le_decode", (PyCFunction)(void(*)(void))_codecs_utf_16_le_decode, METH_FASTCALL, _codecs_utf_16_le_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300580
581static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300582_codecs_utf_16_le_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300583 const char *errors, int final);
584
585static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200586_codecs_utf_16_le_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300587{
588 PyObject *return_value = NULL;
589 Py_buffer data = {NULL, NULL};
590 const char *errors = NULL;
591 int final = 0;
592
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200593 if (!_PyArg_CheckPositional("utf_16_le_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100594 goto exit;
595 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200596 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
597 goto exit;
598 }
599 if (!PyBuffer_IsContiguous(&data, 'C')) {
600 _PyArg_BadArgument("utf_16_le_decode", 1, "contiguous buffer", args[0]);
601 goto exit;
602 }
603 if (nargs < 2) {
604 goto skip_optional;
605 }
606 if (args[1] == Py_None) {
607 errors = NULL;
608 }
609 else if (PyUnicode_Check(args[1])) {
610 Py_ssize_t errors_length;
611 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
612 if (errors == NULL) {
613 goto exit;
614 }
615 if (strlen(errors) != (size_t)errors_length) {
616 PyErr_SetString(PyExc_ValueError, "embedded null character");
617 goto exit;
618 }
619 }
620 else {
621 _PyArg_BadArgument("utf_16_le_decode", 2, "str or None", args[1]);
622 goto exit;
623 }
624 if (nargs < 3) {
625 goto skip_optional;
626 }
627 if (PyFloat_Check(args[2])) {
628 PyErr_SetString(PyExc_TypeError,
629 "integer argument expected, got float" );
630 goto exit;
631 }
632 final = _PyLong_AsInt(args[2]);
633 if (final == -1 && PyErr_Occurred()) {
634 goto exit;
635 }
636skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300637 return_value = _codecs_utf_16_le_decode_impl(module, &data, errors, final);
638
639exit:
640 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300641 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300642 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300643 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300644
645 return return_value;
646}
647
648PyDoc_STRVAR(_codecs_utf_16_be_decode__doc__,
649"utf_16_be_decode($module, data, errors=None, final=False, /)\n"
650"--\n"
651"\n");
652
653#define _CODECS_UTF_16_BE_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200654 {"utf_16_be_decode", (PyCFunction)(void(*)(void))_codecs_utf_16_be_decode, METH_FASTCALL, _codecs_utf_16_be_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300655
656static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300657_codecs_utf_16_be_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300658 const char *errors, int final);
659
660static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200661_codecs_utf_16_be_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300662{
663 PyObject *return_value = NULL;
664 Py_buffer data = {NULL, NULL};
665 const char *errors = NULL;
666 int final = 0;
667
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200668 if (!_PyArg_CheckPositional("utf_16_be_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100669 goto exit;
670 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200671 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
672 goto exit;
673 }
674 if (!PyBuffer_IsContiguous(&data, 'C')) {
675 _PyArg_BadArgument("utf_16_be_decode", 1, "contiguous buffer", args[0]);
676 goto exit;
677 }
678 if (nargs < 2) {
679 goto skip_optional;
680 }
681 if (args[1] == Py_None) {
682 errors = NULL;
683 }
684 else if (PyUnicode_Check(args[1])) {
685 Py_ssize_t errors_length;
686 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
687 if (errors == NULL) {
688 goto exit;
689 }
690 if (strlen(errors) != (size_t)errors_length) {
691 PyErr_SetString(PyExc_ValueError, "embedded null character");
692 goto exit;
693 }
694 }
695 else {
696 _PyArg_BadArgument("utf_16_be_decode", 2, "str or None", args[1]);
697 goto exit;
698 }
699 if (nargs < 3) {
700 goto skip_optional;
701 }
702 if (PyFloat_Check(args[2])) {
703 PyErr_SetString(PyExc_TypeError,
704 "integer argument expected, got float" );
705 goto exit;
706 }
707 final = _PyLong_AsInt(args[2]);
708 if (final == -1 && PyErr_Occurred()) {
709 goto exit;
710 }
711skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300712 return_value = _codecs_utf_16_be_decode_impl(module, &data, errors, final);
713
714exit:
715 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300716 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300717 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300718 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300719
720 return return_value;
721}
722
723PyDoc_STRVAR(_codecs_utf_16_ex_decode__doc__,
724"utf_16_ex_decode($module, data, errors=None, byteorder=0, final=False,\n"
725" /)\n"
726"--\n"
727"\n");
728
729#define _CODECS_UTF_16_EX_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200730 {"utf_16_ex_decode", (PyCFunction)(void(*)(void))_codecs_utf_16_ex_decode, METH_FASTCALL, _codecs_utf_16_ex_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300731
732static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300733_codecs_utf_16_ex_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300734 const char *errors, int byteorder, int final);
735
736static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200737_codecs_utf_16_ex_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300738{
739 PyObject *return_value = NULL;
740 Py_buffer data = {NULL, NULL};
741 const char *errors = NULL;
742 int byteorder = 0;
743 int final = 0;
744
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200745 if (!_PyArg_CheckPositional("utf_16_ex_decode", nargs, 1, 4)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100746 goto exit;
747 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200748 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
749 goto exit;
750 }
751 if (!PyBuffer_IsContiguous(&data, 'C')) {
752 _PyArg_BadArgument("utf_16_ex_decode", 1, "contiguous buffer", args[0]);
753 goto exit;
754 }
755 if (nargs < 2) {
756 goto skip_optional;
757 }
758 if (args[1] == Py_None) {
759 errors = NULL;
760 }
761 else if (PyUnicode_Check(args[1])) {
762 Py_ssize_t errors_length;
763 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
764 if (errors == NULL) {
765 goto exit;
766 }
767 if (strlen(errors) != (size_t)errors_length) {
768 PyErr_SetString(PyExc_ValueError, "embedded null character");
769 goto exit;
770 }
771 }
772 else {
773 _PyArg_BadArgument("utf_16_ex_decode", 2, "str or None", args[1]);
774 goto exit;
775 }
776 if (nargs < 3) {
777 goto skip_optional;
778 }
779 if (PyFloat_Check(args[2])) {
780 PyErr_SetString(PyExc_TypeError,
781 "integer argument expected, got float" );
782 goto exit;
783 }
784 byteorder = _PyLong_AsInt(args[2]);
785 if (byteorder == -1 && PyErr_Occurred()) {
786 goto exit;
787 }
788 if (nargs < 4) {
789 goto skip_optional;
790 }
791 if (PyFloat_Check(args[3])) {
792 PyErr_SetString(PyExc_TypeError,
793 "integer argument expected, got float" );
794 goto exit;
795 }
796 final = _PyLong_AsInt(args[3]);
797 if (final == -1 && PyErr_Occurred()) {
798 goto exit;
799 }
800skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300801 return_value = _codecs_utf_16_ex_decode_impl(module, &data, errors, byteorder, final);
802
803exit:
804 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300805 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300806 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300807 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300808
809 return return_value;
810}
811
812PyDoc_STRVAR(_codecs_utf_32_decode__doc__,
813"utf_32_decode($module, data, errors=None, final=False, /)\n"
814"--\n"
815"\n");
816
817#define _CODECS_UTF_32_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200818 {"utf_32_decode", (PyCFunction)(void(*)(void))_codecs_utf_32_decode, METH_FASTCALL, _codecs_utf_32_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300819
820static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300821_codecs_utf_32_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300822 const char *errors, int final);
823
824static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200825_codecs_utf_32_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300826{
827 PyObject *return_value = NULL;
828 Py_buffer data = {NULL, NULL};
829 const char *errors = NULL;
830 int final = 0;
831
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200832 if (!_PyArg_CheckPositional("utf_32_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100833 goto exit;
834 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200835 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
836 goto exit;
837 }
838 if (!PyBuffer_IsContiguous(&data, 'C')) {
839 _PyArg_BadArgument("utf_32_decode", 1, "contiguous buffer", args[0]);
840 goto exit;
841 }
842 if (nargs < 2) {
843 goto skip_optional;
844 }
845 if (args[1] == Py_None) {
846 errors = NULL;
847 }
848 else if (PyUnicode_Check(args[1])) {
849 Py_ssize_t errors_length;
850 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
851 if (errors == NULL) {
852 goto exit;
853 }
854 if (strlen(errors) != (size_t)errors_length) {
855 PyErr_SetString(PyExc_ValueError, "embedded null character");
856 goto exit;
857 }
858 }
859 else {
860 _PyArg_BadArgument("utf_32_decode", 2, "str or None", args[1]);
861 goto exit;
862 }
863 if (nargs < 3) {
864 goto skip_optional;
865 }
866 if (PyFloat_Check(args[2])) {
867 PyErr_SetString(PyExc_TypeError,
868 "integer argument expected, got float" );
869 goto exit;
870 }
871 final = _PyLong_AsInt(args[2]);
872 if (final == -1 && PyErr_Occurred()) {
873 goto exit;
874 }
875skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300876 return_value = _codecs_utf_32_decode_impl(module, &data, errors, final);
877
878exit:
879 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300880 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300881 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300882 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300883
884 return return_value;
885}
886
887PyDoc_STRVAR(_codecs_utf_32_le_decode__doc__,
888"utf_32_le_decode($module, data, errors=None, final=False, /)\n"
889"--\n"
890"\n");
891
892#define _CODECS_UTF_32_LE_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200893 {"utf_32_le_decode", (PyCFunction)(void(*)(void))_codecs_utf_32_le_decode, METH_FASTCALL, _codecs_utf_32_le_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300894
895static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300896_codecs_utf_32_le_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300897 const char *errors, int final);
898
899static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200900_codecs_utf_32_le_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300901{
902 PyObject *return_value = NULL;
903 Py_buffer data = {NULL, NULL};
904 const char *errors = NULL;
905 int final = 0;
906
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200907 if (!_PyArg_CheckPositional("utf_32_le_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100908 goto exit;
909 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200910 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
911 goto exit;
912 }
913 if (!PyBuffer_IsContiguous(&data, 'C')) {
914 _PyArg_BadArgument("utf_32_le_decode", 1, "contiguous buffer", args[0]);
915 goto exit;
916 }
917 if (nargs < 2) {
918 goto skip_optional;
919 }
920 if (args[1] == Py_None) {
921 errors = NULL;
922 }
923 else if (PyUnicode_Check(args[1])) {
924 Py_ssize_t errors_length;
925 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
926 if (errors == NULL) {
927 goto exit;
928 }
929 if (strlen(errors) != (size_t)errors_length) {
930 PyErr_SetString(PyExc_ValueError, "embedded null character");
931 goto exit;
932 }
933 }
934 else {
935 _PyArg_BadArgument("utf_32_le_decode", 2, "str or None", args[1]);
936 goto exit;
937 }
938 if (nargs < 3) {
939 goto skip_optional;
940 }
941 if (PyFloat_Check(args[2])) {
942 PyErr_SetString(PyExc_TypeError,
943 "integer argument expected, got float" );
944 goto exit;
945 }
946 final = _PyLong_AsInt(args[2]);
947 if (final == -1 && PyErr_Occurred()) {
948 goto exit;
949 }
950skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300951 return_value = _codecs_utf_32_le_decode_impl(module, &data, errors, final);
952
953exit:
954 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300955 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300956 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300957 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300958
959 return return_value;
960}
961
962PyDoc_STRVAR(_codecs_utf_32_be_decode__doc__,
963"utf_32_be_decode($module, data, errors=None, final=False, /)\n"
964"--\n"
965"\n");
966
967#define _CODECS_UTF_32_BE_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200968 {"utf_32_be_decode", (PyCFunction)(void(*)(void))_codecs_utf_32_be_decode, METH_FASTCALL, _codecs_utf_32_be_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300969
970static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300971_codecs_utf_32_be_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300972 const char *errors, int final);
973
974static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200975_codecs_utf_32_be_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300976{
977 PyObject *return_value = NULL;
978 Py_buffer data = {NULL, NULL};
979 const char *errors = NULL;
980 int final = 0;
981
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200982 if (!_PyArg_CheckPositional("utf_32_be_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100983 goto exit;
984 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200985 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
986 goto exit;
987 }
988 if (!PyBuffer_IsContiguous(&data, 'C')) {
989 _PyArg_BadArgument("utf_32_be_decode", 1, "contiguous buffer", args[0]);
990 goto exit;
991 }
992 if (nargs < 2) {
993 goto skip_optional;
994 }
995 if (args[1] == Py_None) {
996 errors = NULL;
997 }
998 else if (PyUnicode_Check(args[1])) {
999 Py_ssize_t errors_length;
1000 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1001 if (errors == NULL) {
1002 goto exit;
1003 }
1004 if (strlen(errors) != (size_t)errors_length) {
1005 PyErr_SetString(PyExc_ValueError, "embedded null character");
1006 goto exit;
1007 }
1008 }
1009 else {
1010 _PyArg_BadArgument("utf_32_be_decode", 2, "str or None", args[1]);
1011 goto exit;
1012 }
1013 if (nargs < 3) {
1014 goto skip_optional;
1015 }
1016 if (PyFloat_Check(args[2])) {
1017 PyErr_SetString(PyExc_TypeError,
1018 "integer argument expected, got float" );
1019 goto exit;
1020 }
1021 final = _PyLong_AsInt(args[2]);
1022 if (final == -1 && PyErr_Occurred()) {
1023 goto exit;
1024 }
1025skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001026 return_value = _codecs_utf_32_be_decode_impl(module, &data, errors, final);
1027
1028exit:
1029 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001030 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001031 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001032 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001033
1034 return return_value;
1035}
1036
1037PyDoc_STRVAR(_codecs_utf_32_ex_decode__doc__,
1038"utf_32_ex_decode($module, data, errors=None, byteorder=0, final=False,\n"
1039" /)\n"
1040"--\n"
1041"\n");
1042
1043#define _CODECS_UTF_32_EX_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001044 {"utf_32_ex_decode", (PyCFunction)(void(*)(void))_codecs_utf_32_ex_decode, METH_FASTCALL, _codecs_utf_32_ex_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001045
1046static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001047_codecs_utf_32_ex_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001048 const char *errors, int byteorder, int final);
1049
1050static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001051_codecs_utf_32_ex_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001052{
1053 PyObject *return_value = NULL;
1054 Py_buffer data = {NULL, NULL};
1055 const char *errors = NULL;
1056 int byteorder = 0;
1057 int final = 0;
1058
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001059 if (!_PyArg_CheckPositional("utf_32_ex_decode", nargs, 1, 4)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001060 goto exit;
1061 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001062 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1063 goto exit;
1064 }
1065 if (!PyBuffer_IsContiguous(&data, 'C')) {
1066 _PyArg_BadArgument("utf_32_ex_decode", 1, "contiguous buffer", args[0]);
1067 goto exit;
1068 }
1069 if (nargs < 2) {
1070 goto skip_optional;
1071 }
1072 if (args[1] == Py_None) {
1073 errors = NULL;
1074 }
1075 else if (PyUnicode_Check(args[1])) {
1076 Py_ssize_t errors_length;
1077 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1078 if (errors == NULL) {
1079 goto exit;
1080 }
1081 if (strlen(errors) != (size_t)errors_length) {
1082 PyErr_SetString(PyExc_ValueError, "embedded null character");
1083 goto exit;
1084 }
1085 }
1086 else {
1087 _PyArg_BadArgument("utf_32_ex_decode", 2, "str or None", args[1]);
1088 goto exit;
1089 }
1090 if (nargs < 3) {
1091 goto skip_optional;
1092 }
1093 if (PyFloat_Check(args[2])) {
1094 PyErr_SetString(PyExc_TypeError,
1095 "integer argument expected, got float" );
1096 goto exit;
1097 }
1098 byteorder = _PyLong_AsInt(args[2]);
1099 if (byteorder == -1 && PyErr_Occurred()) {
1100 goto exit;
1101 }
1102 if (nargs < 4) {
1103 goto skip_optional;
1104 }
1105 if (PyFloat_Check(args[3])) {
1106 PyErr_SetString(PyExc_TypeError,
1107 "integer argument expected, got float" );
1108 goto exit;
1109 }
1110 final = _PyLong_AsInt(args[3]);
1111 if (final == -1 && PyErr_Occurred()) {
1112 goto exit;
1113 }
1114skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001115 return_value = _codecs_utf_32_ex_decode_impl(module, &data, errors, byteorder, final);
1116
1117exit:
1118 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001119 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001120 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001121 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001122
1123 return return_value;
1124}
1125
1126PyDoc_STRVAR(_codecs_unicode_escape_decode__doc__,
1127"unicode_escape_decode($module, data, errors=None, /)\n"
1128"--\n"
1129"\n");
1130
1131#define _CODECS_UNICODE_ESCAPE_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001132 {"unicode_escape_decode", (PyCFunction)(void(*)(void))_codecs_unicode_escape_decode, METH_FASTCALL, _codecs_unicode_escape_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001133
1134static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001135_codecs_unicode_escape_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001136 const char *errors);
1137
1138static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001139_codecs_unicode_escape_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001140{
1141 PyObject *return_value = NULL;
1142 Py_buffer data = {NULL, NULL};
1143 const char *errors = NULL;
1144
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001145 if (!_PyArg_CheckPositional("unicode_escape_decode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001146 goto exit;
1147 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001148 if (PyUnicode_Check(args[0])) {
1149 Py_ssize_t len;
1150 const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
1151 if (ptr == NULL) {
1152 goto exit;
1153 }
1154 PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, 0);
1155 }
1156 else { /* any bytes-like object */
1157 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1158 goto exit;
1159 }
1160 if (!PyBuffer_IsContiguous(&data, 'C')) {
1161 _PyArg_BadArgument("unicode_escape_decode", 1, "contiguous buffer", args[0]);
1162 goto exit;
1163 }
1164 }
1165 if (nargs < 2) {
1166 goto skip_optional;
1167 }
1168 if (args[1] == Py_None) {
1169 errors = NULL;
1170 }
1171 else if (PyUnicode_Check(args[1])) {
1172 Py_ssize_t errors_length;
1173 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1174 if (errors == NULL) {
1175 goto exit;
1176 }
1177 if (strlen(errors) != (size_t)errors_length) {
1178 PyErr_SetString(PyExc_ValueError, "embedded null character");
1179 goto exit;
1180 }
1181 }
1182 else {
1183 _PyArg_BadArgument("unicode_escape_decode", 2, "str or None", args[1]);
1184 goto exit;
1185 }
1186skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001187 return_value = _codecs_unicode_escape_decode_impl(module, &data, errors);
1188
1189exit:
1190 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001191 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001192 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001193 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001194
1195 return return_value;
1196}
1197
1198PyDoc_STRVAR(_codecs_raw_unicode_escape_decode__doc__,
1199"raw_unicode_escape_decode($module, data, errors=None, /)\n"
1200"--\n"
1201"\n");
1202
1203#define _CODECS_RAW_UNICODE_ESCAPE_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001204 {"raw_unicode_escape_decode", (PyCFunction)(void(*)(void))_codecs_raw_unicode_escape_decode, METH_FASTCALL, _codecs_raw_unicode_escape_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001205
1206static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001207_codecs_raw_unicode_escape_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001208 const char *errors);
1209
1210static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001211_codecs_raw_unicode_escape_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001212{
1213 PyObject *return_value = NULL;
1214 Py_buffer data = {NULL, NULL};
1215 const char *errors = NULL;
1216
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001217 if (!_PyArg_CheckPositional("raw_unicode_escape_decode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001218 goto exit;
1219 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001220 if (PyUnicode_Check(args[0])) {
1221 Py_ssize_t len;
1222 const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
1223 if (ptr == NULL) {
1224 goto exit;
1225 }
1226 PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, 0);
1227 }
1228 else { /* any bytes-like object */
1229 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1230 goto exit;
1231 }
1232 if (!PyBuffer_IsContiguous(&data, 'C')) {
1233 _PyArg_BadArgument("raw_unicode_escape_decode", 1, "contiguous buffer", args[0]);
1234 goto exit;
1235 }
1236 }
1237 if (nargs < 2) {
1238 goto skip_optional;
1239 }
1240 if (args[1] == Py_None) {
1241 errors = NULL;
1242 }
1243 else if (PyUnicode_Check(args[1])) {
1244 Py_ssize_t errors_length;
1245 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1246 if (errors == NULL) {
1247 goto exit;
1248 }
1249 if (strlen(errors) != (size_t)errors_length) {
1250 PyErr_SetString(PyExc_ValueError, "embedded null character");
1251 goto exit;
1252 }
1253 }
1254 else {
1255 _PyArg_BadArgument("raw_unicode_escape_decode", 2, "str or None", args[1]);
1256 goto exit;
1257 }
1258skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001259 return_value = _codecs_raw_unicode_escape_decode_impl(module, &data, errors);
1260
1261exit:
1262 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001263 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001264 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001265 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001266
1267 return return_value;
1268}
1269
1270PyDoc_STRVAR(_codecs_latin_1_decode__doc__,
1271"latin_1_decode($module, data, errors=None, /)\n"
1272"--\n"
1273"\n");
1274
1275#define _CODECS_LATIN_1_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001276 {"latin_1_decode", (PyCFunction)(void(*)(void))_codecs_latin_1_decode, METH_FASTCALL, _codecs_latin_1_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001277
1278static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001279_codecs_latin_1_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001280 const char *errors);
1281
1282static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001283_codecs_latin_1_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001284{
1285 PyObject *return_value = NULL;
1286 Py_buffer data = {NULL, NULL};
1287 const char *errors = NULL;
1288
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001289 if (!_PyArg_CheckPositional("latin_1_decode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001290 goto exit;
1291 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001292 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1293 goto exit;
1294 }
1295 if (!PyBuffer_IsContiguous(&data, 'C')) {
1296 _PyArg_BadArgument("latin_1_decode", 1, "contiguous buffer", args[0]);
1297 goto exit;
1298 }
1299 if (nargs < 2) {
1300 goto skip_optional;
1301 }
1302 if (args[1] == Py_None) {
1303 errors = NULL;
1304 }
1305 else if (PyUnicode_Check(args[1])) {
1306 Py_ssize_t errors_length;
1307 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1308 if (errors == NULL) {
1309 goto exit;
1310 }
1311 if (strlen(errors) != (size_t)errors_length) {
1312 PyErr_SetString(PyExc_ValueError, "embedded null character");
1313 goto exit;
1314 }
1315 }
1316 else {
1317 _PyArg_BadArgument("latin_1_decode", 2, "str or None", args[1]);
1318 goto exit;
1319 }
1320skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001321 return_value = _codecs_latin_1_decode_impl(module, &data, errors);
1322
1323exit:
1324 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001325 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001326 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001327 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001328
1329 return return_value;
1330}
1331
1332PyDoc_STRVAR(_codecs_ascii_decode__doc__,
1333"ascii_decode($module, data, errors=None, /)\n"
1334"--\n"
1335"\n");
1336
1337#define _CODECS_ASCII_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001338 {"ascii_decode", (PyCFunction)(void(*)(void))_codecs_ascii_decode, METH_FASTCALL, _codecs_ascii_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001339
1340static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001341_codecs_ascii_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001342 const char *errors);
1343
1344static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001345_codecs_ascii_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001346{
1347 PyObject *return_value = NULL;
1348 Py_buffer data = {NULL, NULL};
1349 const char *errors = NULL;
1350
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001351 if (!_PyArg_CheckPositional("ascii_decode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001352 goto exit;
1353 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001354 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1355 goto exit;
1356 }
1357 if (!PyBuffer_IsContiguous(&data, 'C')) {
1358 _PyArg_BadArgument("ascii_decode", 1, "contiguous buffer", args[0]);
1359 goto exit;
1360 }
1361 if (nargs < 2) {
1362 goto skip_optional;
1363 }
1364 if (args[1] == Py_None) {
1365 errors = NULL;
1366 }
1367 else if (PyUnicode_Check(args[1])) {
1368 Py_ssize_t errors_length;
1369 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1370 if (errors == NULL) {
1371 goto exit;
1372 }
1373 if (strlen(errors) != (size_t)errors_length) {
1374 PyErr_SetString(PyExc_ValueError, "embedded null character");
1375 goto exit;
1376 }
1377 }
1378 else {
1379 _PyArg_BadArgument("ascii_decode", 2, "str or None", args[1]);
1380 goto exit;
1381 }
1382skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001383 return_value = _codecs_ascii_decode_impl(module, &data, errors);
1384
1385exit:
1386 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001387 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001388 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001389 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001390
1391 return return_value;
1392}
1393
1394PyDoc_STRVAR(_codecs_charmap_decode__doc__,
1395"charmap_decode($module, data, errors=None, mapping=None, /)\n"
1396"--\n"
1397"\n");
1398
1399#define _CODECS_CHARMAP_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001400 {"charmap_decode", (PyCFunction)(void(*)(void))_codecs_charmap_decode, METH_FASTCALL, _codecs_charmap_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001401
1402static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001403_codecs_charmap_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001404 const char *errors, PyObject *mapping);
1405
1406static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001407_codecs_charmap_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001408{
1409 PyObject *return_value = NULL;
1410 Py_buffer data = {NULL, NULL};
1411 const char *errors = NULL;
1412 PyObject *mapping = NULL;
1413
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001414 if (!_PyArg_CheckPositional("charmap_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001415 goto exit;
1416 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001417 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1418 goto exit;
1419 }
1420 if (!PyBuffer_IsContiguous(&data, 'C')) {
1421 _PyArg_BadArgument("charmap_decode", 1, "contiguous buffer", args[0]);
1422 goto exit;
1423 }
1424 if (nargs < 2) {
1425 goto skip_optional;
1426 }
1427 if (args[1] == Py_None) {
1428 errors = NULL;
1429 }
1430 else if (PyUnicode_Check(args[1])) {
1431 Py_ssize_t errors_length;
1432 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1433 if (errors == NULL) {
1434 goto exit;
1435 }
1436 if (strlen(errors) != (size_t)errors_length) {
1437 PyErr_SetString(PyExc_ValueError, "embedded null character");
1438 goto exit;
1439 }
1440 }
1441 else {
1442 _PyArg_BadArgument("charmap_decode", 2, "str or None", args[1]);
1443 goto exit;
1444 }
1445 if (nargs < 3) {
1446 goto skip_optional;
1447 }
1448 mapping = args[2];
1449skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001450 return_value = _codecs_charmap_decode_impl(module, &data, errors, mapping);
1451
1452exit:
1453 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001454 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001455 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001456 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001457
1458 return return_value;
1459}
1460
Steve Dowercc16be82016-09-08 10:35:16 -07001461#if defined(MS_WINDOWS)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001462
1463PyDoc_STRVAR(_codecs_mbcs_decode__doc__,
1464"mbcs_decode($module, data, errors=None, final=False, /)\n"
1465"--\n"
1466"\n");
1467
1468#define _CODECS_MBCS_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001469 {"mbcs_decode", (PyCFunction)(void(*)(void))_codecs_mbcs_decode, METH_FASTCALL, _codecs_mbcs_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001470
1471static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001472_codecs_mbcs_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001473 const char *errors, int final);
1474
1475static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001476_codecs_mbcs_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001477{
1478 PyObject *return_value = NULL;
1479 Py_buffer data = {NULL, NULL};
1480 const char *errors = NULL;
1481 int final = 0;
1482
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001483 if (!_PyArg_CheckPositional("mbcs_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001484 goto exit;
1485 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001486 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1487 goto exit;
1488 }
1489 if (!PyBuffer_IsContiguous(&data, 'C')) {
1490 _PyArg_BadArgument("mbcs_decode", 1, "contiguous buffer", args[0]);
1491 goto exit;
1492 }
1493 if (nargs < 2) {
1494 goto skip_optional;
1495 }
1496 if (args[1] == Py_None) {
1497 errors = NULL;
1498 }
1499 else if (PyUnicode_Check(args[1])) {
1500 Py_ssize_t errors_length;
1501 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1502 if (errors == NULL) {
1503 goto exit;
1504 }
1505 if (strlen(errors) != (size_t)errors_length) {
1506 PyErr_SetString(PyExc_ValueError, "embedded null character");
1507 goto exit;
1508 }
1509 }
1510 else {
1511 _PyArg_BadArgument("mbcs_decode", 2, "str or None", args[1]);
1512 goto exit;
1513 }
1514 if (nargs < 3) {
1515 goto skip_optional;
1516 }
1517 if (PyFloat_Check(args[2])) {
1518 PyErr_SetString(PyExc_TypeError,
1519 "integer argument expected, got float" );
1520 goto exit;
1521 }
1522 final = _PyLong_AsInt(args[2]);
1523 if (final == -1 && PyErr_Occurred()) {
1524 goto exit;
1525 }
1526skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001527 return_value = _codecs_mbcs_decode_impl(module, &data, errors, final);
1528
1529exit:
1530 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001531 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001532 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001533 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001534
1535 return return_value;
1536}
1537
Steve Dowercc16be82016-09-08 10:35:16 -07001538#endif /* defined(MS_WINDOWS) */
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001539
Steve Dowercc16be82016-09-08 10:35:16 -07001540#if defined(MS_WINDOWS)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001541
Steve Dowerf5aba582016-09-06 19:42:27 -07001542PyDoc_STRVAR(_codecs_oem_decode__doc__,
1543"oem_decode($module, data, errors=None, final=False, /)\n"
1544"--\n"
1545"\n");
1546
1547#define _CODECS_OEM_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001548 {"oem_decode", (PyCFunction)(void(*)(void))_codecs_oem_decode, METH_FASTCALL, _codecs_oem_decode__doc__},
Steve Dowerf5aba582016-09-06 19:42:27 -07001549
1550static PyObject *
1551_codecs_oem_decode_impl(PyObject *module, Py_buffer *data,
1552 const char *errors, int final);
1553
1554static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001555_codecs_oem_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Steve Dowerf5aba582016-09-06 19:42:27 -07001556{
1557 PyObject *return_value = NULL;
1558 Py_buffer data = {NULL, NULL};
1559 const char *errors = NULL;
1560 int final = 0;
1561
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001562 if (!_PyArg_CheckPositional("oem_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001563 goto exit;
1564 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001565 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1566 goto exit;
1567 }
1568 if (!PyBuffer_IsContiguous(&data, 'C')) {
1569 _PyArg_BadArgument("oem_decode", 1, "contiguous buffer", args[0]);
1570 goto exit;
1571 }
1572 if (nargs < 2) {
1573 goto skip_optional;
1574 }
1575 if (args[1] == Py_None) {
1576 errors = NULL;
1577 }
1578 else if (PyUnicode_Check(args[1])) {
1579 Py_ssize_t errors_length;
1580 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1581 if (errors == NULL) {
1582 goto exit;
1583 }
1584 if (strlen(errors) != (size_t)errors_length) {
1585 PyErr_SetString(PyExc_ValueError, "embedded null character");
1586 goto exit;
1587 }
1588 }
1589 else {
1590 _PyArg_BadArgument("oem_decode", 2, "str or None", args[1]);
1591 goto exit;
1592 }
1593 if (nargs < 3) {
1594 goto skip_optional;
1595 }
1596 if (PyFloat_Check(args[2])) {
1597 PyErr_SetString(PyExc_TypeError,
1598 "integer argument expected, got float" );
1599 goto exit;
1600 }
1601 final = _PyLong_AsInt(args[2]);
1602 if (final == -1 && PyErr_Occurred()) {
1603 goto exit;
1604 }
1605skip_optional:
Steve Dowerf5aba582016-09-06 19:42:27 -07001606 return_value = _codecs_oem_decode_impl(module, &data, errors, final);
1607
1608exit:
1609 /* Cleanup for data */
1610 if (data.obj) {
1611 PyBuffer_Release(&data);
1612 }
1613
1614 return return_value;
1615}
1616
Steve Dowercc16be82016-09-08 10:35:16 -07001617#endif /* defined(MS_WINDOWS) */
Steve Dowerf5aba582016-09-06 19:42:27 -07001618
Steve Dowercc16be82016-09-08 10:35:16 -07001619#if defined(MS_WINDOWS)
Steve Dowerf5aba582016-09-06 19:42:27 -07001620
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001621PyDoc_STRVAR(_codecs_code_page_decode__doc__,
1622"code_page_decode($module, codepage, data, errors=None, final=False, /)\n"
1623"--\n"
1624"\n");
1625
1626#define _CODECS_CODE_PAGE_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001627 {"code_page_decode", (PyCFunction)(void(*)(void))_codecs_code_page_decode, METH_FASTCALL, _codecs_code_page_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001628
1629static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001630_codecs_code_page_decode_impl(PyObject *module, int codepage,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001631 Py_buffer *data, const char *errors, int final);
1632
1633static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001634_codecs_code_page_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001635{
1636 PyObject *return_value = NULL;
1637 int codepage;
1638 Py_buffer data = {NULL, NULL};
1639 const char *errors = NULL;
1640 int final = 0;
1641
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001642 if (!_PyArg_CheckPositional("code_page_decode", nargs, 2, 4)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001643 goto exit;
1644 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001645 if (PyFloat_Check(args[0])) {
1646 PyErr_SetString(PyExc_TypeError,
1647 "integer argument expected, got float" );
1648 goto exit;
1649 }
1650 codepage = _PyLong_AsInt(args[0]);
1651 if (codepage == -1 && PyErr_Occurred()) {
1652 goto exit;
1653 }
1654 if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) {
1655 goto exit;
1656 }
1657 if (!PyBuffer_IsContiguous(&data, 'C')) {
1658 _PyArg_BadArgument("code_page_decode", 2, "contiguous buffer", args[1]);
1659 goto exit;
1660 }
1661 if (nargs < 3) {
1662 goto skip_optional;
1663 }
1664 if (args[2] == Py_None) {
1665 errors = NULL;
1666 }
1667 else if (PyUnicode_Check(args[2])) {
1668 Py_ssize_t errors_length;
1669 errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length);
1670 if (errors == NULL) {
1671 goto exit;
1672 }
1673 if (strlen(errors) != (size_t)errors_length) {
1674 PyErr_SetString(PyExc_ValueError, "embedded null character");
1675 goto exit;
1676 }
1677 }
1678 else {
1679 _PyArg_BadArgument("code_page_decode", 3, "str or None", args[2]);
1680 goto exit;
1681 }
1682 if (nargs < 4) {
1683 goto skip_optional;
1684 }
1685 if (PyFloat_Check(args[3])) {
1686 PyErr_SetString(PyExc_TypeError,
1687 "integer argument expected, got float" );
1688 goto exit;
1689 }
1690 final = _PyLong_AsInt(args[3]);
1691 if (final == -1 && PyErr_Occurred()) {
1692 goto exit;
1693 }
1694skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001695 return_value = _codecs_code_page_decode_impl(module, codepage, &data, errors, final);
1696
1697exit:
1698 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001699 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001700 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001701 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001702
1703 return return_value;
1704}
1705
Steve Dowercc16be82016-09-08 10:35:16 -07001706#endif /* defined(MS_WINDOWS) */
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001707
1708PyDoc_STRVAR(_codecs_readbuffer_encode__doc__,
1709"readbuffer_encode($module, data, errors=None, /)\n"
1710"--\n"
1711"\n");
1712
1713#define _CODECS_READBUFFER_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001714 {"readbuffer_encode", (PyCFunction)(void(*)(void))_codecs_readbuffer_encode, METH_FASTCALL, _codecs_readbuffer_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001715
1716static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001717_codecs_readbuffer_encode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001718 const char *errors);
1719
1720static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001721_codecs_readbuffer_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001722{
1723 PyObject *return_value = NULL;
1724 Py_buffer data = {NULL, NULL};
1725 const char *errors = NULL;
1726
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001727 if (!_PyArg_CheckPositional("readbuffer_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001728 goto exit;
1729 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001730 if (PyUnicode_Check(args[0])) {
1731 Py_ssize_t len;
1732 const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
1733 if (ptr == NULL) {
1734 goto exit;
1735 }
1736 PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, 0);
1737 }
1738 else { /* any bytes-like object */
1739 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1740 goto exit;
1741 }
1742 if (!PyBuffer_IsContiguous(&data, 'C')) {
1743 _PyArg_BadArgument("readbuffer_encode", 1, "contiguous buffer", args[0]);
1744 goto exit;
1745 }
1746 }
1747 if (nargs < 2) {
1748 goto skip_optional;
1749 }
1750 if (args[1] == Py_None) {
1751 errors = NULL;
1752 }
1753 else if (PyUnicode_Check(args[1])) {
1754 Py_ssize_t errors_length;
1755 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1756 if (errors == NULL) {
1757 goto exit;
1758 }
1759 if (strlen(errors) != (size_t)errors_length) {
1760 PyErr_SetString(PyExc_ValueError, "embedded null character");
1761 goto exit;
1762 }
1763 }
1764 else {
1765 _PyArg_BadArgument("readbuffer_encode", 2, "str or None", args[1]);
1766 goto exit;
1767 }
1768skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001769 return_value = _codecs_readbuffer_encode_impl(module, &data, errors);
1770
1771exit:
1772 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001773 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001774 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001775 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001776
1777 return return_value;
1778}
1779
1780PyDoc_STRVAR(_codecs_unicode_internal_encode__doc__,
1781"unicode_internal_encode($module, obj, errors=None, /)\n"
1782"--\n"
1783"\n");
1784
1785#define _CODECS_UNICODE_INTERNAL_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001786 {"unicode_internal_encode", (PyCFunction)(void(*)(void))_codecs_unicode_internal_encode, METH_FASTCALL, _codecs_unicode_internal_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001787
1788static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001789_codecs_unicode_internal_encode_impl(PyObject *module, PyObject *obj,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001790 const char *errors);
1791
1792static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001793_codecs_unicode_internal_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001794{
1795 PyObject *return_value = NULL;
1796 PyObject *obj;
1797 const char *errors = NULL;
1798
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001799 if (!_PyArg_CheckPositional("unicode_internal_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001800 goto exit;
1801 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001802 obj = args[0];
1803 if (nargs < 2) {
1804 goto skip_optional;
1805 }
1806 if (args[1] == Py_None) {
1807 errors = NULL;
1808 }
1809 else if (PyUnicode_Check(args[1])) {
1810 Py_ssize_t errors_length;
1811 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1812 if (errors == NULL) {
1813 goto exit;
1814 }
1815 if (strlen(errors) != (size_t)errors_length) {
1816 PyErr_SetString(PyExc_ValueError, "embedded null character");
1817 goto exit;
1818 }
1819 }
1820 else {
1821 _PyArg_BadArgument("unicode_internal_encode", 2, "str or None", args[1]);
1822 goto exit;
1823 }
1824skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001825 return_value = _codecs_unicode_internal_encode_impl(module, obj, errors);
1826
1827exit:
1828 return return_value;
1829}
1830
1831PyDoc_STRVAR(_codecs_utf_7_encode__doc__,
1832"utf_7_encode($module, str, errors=None, /)\n"
1833"--\n"
1834"\n");
1835
1836#define _CODECS_UTF_7_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001837 {"utf_7_encode", (PyCFunction)(void(*)(void))_codecs_utf_7_encode, METH_FASTCALL, _codecs_utf_7_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001838
1839static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001840_codecs_utf_7_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001841 const char *errors);
1842
1843static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001844_codecs_utf_7_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001845{
1846 PyObject *return_value = NULL;
1847 PyObject *str;
1848 const char *errors = NULL;
1849
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001850 if (!_PyArg_CheckPositional("utf_7_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001851 goto exit;
1852 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001853 if (!PyUnicode_Check(args[0])) {
1854 _PyArg_BadArgument("utf_7_encode", 1, "str", args[0]);
1855 goto exit;
1856 }
1857 if (PyUnicode_READY(args[0]) == -1) {
1858 goto exit;
1859 }
1860 str = args[0];
1861 if (nargs < 2) {
1862 goto skip_optional;
1863 }
1864 if (args[1] == Py_None) {
1865 errors = NULL;
1866 }
1867 else if (PyUnicode_Check(args[1])) {
1868 Py_ssize_t errors_length;
1869 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1870 if (errors == NULL) {
1871 goto exit;
1872 }
1873 if (strlen(errors) != (size_t)errors_length) {
1874 PyErr_SetString(PyExc_ValueError, "embedded null character");
1875 goto exit;
1876 }
1877 }
1878 else {
1879 _PyArg_BadArgument("utf_7_encode", 2, "str or None", args[1]);
1880 goto exit;
1881 }
1882skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001883 return_value = _codecs_utf_7_encode_impl(module, str, errors);
1884
1885exit:
1886 return return_value;
1887}
1888
1889PyDoc_STRVAR(_codecs_utf_8_encode__doc__,
1890"utf_8_encode($module, str, errors=None, /)\n"
1891"--\n"
1892"\n");
1893
1894#define _CODECS_UTF_8_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001895 {"utf_8_encode", (PyCFunction)(void(*)(void))_codecs_utf_8_encode, METH_FASTCALL, _codecs_utf_8_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001896
1897static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001898_codecs_utf_8_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001899 const char *errors);
1900
1901static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001902_codecs_utf_8_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001903{
1904 PyObject *return_value = NULL;
1905 PyObject *str;
1906 const char *errors = NULL;
1907
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001908 if (!_PyArg_CheckPositional("utf_8_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001909 goto exit;
1910 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001911 if (!PyUnicode_Check(args[0])) {
1912 _PyArg_BadArgument("utf_8_encode", 1, "str", args[0]);
1913 goto exit;
1914 }
1915 if (PyUnicode_READY(args[0]) == -1) {
1916 goto exit;
1917 }
1918 str = args[0];
1919 if (nargs < 2) {
1920 goto skip_optional;
1921 }
1922 if (args[1] == Py_None) {
1923 errors = NULL;
1924 }
1925 else if (PyUnicode_Check(args[1])) {
1926 Py_ssize_t errors_length;
1927 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1928 if (errors == NULL) {
1929 goto exit;
1930 }
1931 if (strlen(errors) != (size_t)errors_length) {
1932 PyErr_SetString(PyExc_ValueError, "embedded null character");
1933 goto exit;
1934 }
1935 }
1936 else {
1937 _PyArg_BadArgument("utf_8_encode", 2, "str or None", args[1]);
1938 goto exit;
1939 }
1940skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001941 return_value = _codecs_utf_8_encode_impl(module, str, errors);
1942
1943exit:
1944 return return_value;
1945}
1946
1947PyDoc_STRVAR(_codecs_utf_16_encode__doc__,
1948"utf_16_encode($module, str, errors=None, byteorder=0, /)\n"
1949"--\n"
1950"\n");
1951
1952#define _CODECS_UTF_16_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001953 {"utf_16_encode", (PyCFunction)(void(*)(void))_codecs_utf_16_encode, METH_FASTCALL, _codecs_utf_16_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001954
1955static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001956_codecs_utf_16_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001957 const char *errors, int byteorder);
1958
1959static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001960_codecs_utf_16_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001961{
1962 PyObject *return_value = NULL;
1963 PyObject *str;
1964 const char *errors = NULL;
1965 int byteorder = 0;
1966
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001967 if (!_PyArg_CheckPositional("utf_16_encode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001968 goto exit;
1969 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001970 if (!PyUnicode_Check(args[0])) {
1971 _PyArg_BadArgument("utf_16_encode", 1, "str", args[0]);
1972 goto exit;
1973 }
1974 if (PyUnicode_READY(args[0]) == -1) {
1975 goto exit;
1976 }
1977 str = args[0];
1978 if (nargs < 2) {
1979 goto skip_optional;
1980 }
1981 if (args[1] == Py_None) {
1982 errors = NULL;
1983 }
1984 else if (PyUnicode_Check(args[1])) {
1985 Py_ssize_t errors_length;
1986 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1987 if (errors == NULL) {
1988 goto exit;
1989 }
1990 if (strlen(errors) != (size_t)errors_length) {
1991 PyErr_SetString(PyExc_ValueError, "embedded null character");
1992 goto exit;
1993 }
1994 }
1995 else {
1996 _PyArg_BadArgument("utf_16_encode", 2, "str or None", args[1]);
1997 goto exit;
1998 }
1999 if (nargs < 3) {
2000 goto skip_optional;
2001 }
2002 if (PyFloat_Check(args[2])) {
2003 PyErr_SetString(PyExc_TypeError,
2004 "integer argument expected, got float" );
2005 goto exit;
2006 }
2007 byteorder = _PyLong_AsInt(args[2]);
2008 if (byteorder == -1 && PyErr_Occurred()) {
2009 goto exit;
2010 }
2011skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002012 return_value = _codecs_utf_16_encode_impl(module, str, errors, byteorder);
2013
2014exit:
2015 return return_value;
2016}
2017
2018PyDoc_STRVAR(_codecs_utf_16_le_encode__doc__,
2019"utf_16_le_encode($module, str, errors=None, /)\n"
2020"--\n"
2021"\n");
2022
2023#define _CODECS_UTF_16_LE_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002024 {"utf_16_le_encode", (PyCFunction)(void(*)(void))_codecs_utf_16_le_encode, METH_FASTCALL, _codecs_utf_16_le_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002025
2026static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002027_codecs_utf_16_le_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002028 const char *errors);
2029
2030static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002031_codecs_utf_16_le_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002032{
2033 PyObject *return_value = NULL;
2034 PyObject *str;
2035 const char *errors = NULL;
2036
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002037 if (!_PyArg_CheckPositional("utf_16_le_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002038 goto exit;
2039 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002040 if (!PyUnicode_Check(args[0])) {
2041 _PyArg_BadArgument("utf_16_le_encode", 1, "str", args[0]);
2042 goto exit;
2043 }
2044 if (PyUnicode_READY(args[0]) == -1) {
2045 goto exit;
2046 }
2047 str = args[0];
2048 if (nargs < 2) {
2049 goto skip_optional;
2050 }
2051 if (args[1] == Py_None) {
2052 errors = NULL;
2053 }
2054 else if (PyUnicode_Check(args[1])) {
2055 Py_ssize_t errors_length;
2056 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2057 if (errors == NULL) {
2058 goto exit;
2059 }
2060 if (strlen(errors) != (size_t)errors_length) {
2061 PyErr_SetString(PyExc_ValueError, "embedded null character");
2062 goto exit;
2063 }
2064 }
2065 else {
2066 _PyArg_BadArgument("utf_16_le_encode", 2, "str or None", args[1]);
2067 goto exit;
2068 }
2069skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002070 return_value = _codecs_utf_16_le_encode_impl(module, str, errors);
2071
2072exit:
2073 return return_value;
2074}
2075
2076PyDoc_STRVAR(_codecs_utf_16_be_encode__doc__,
2077"utf_16_be_encode($module, str, errors=None, /)\n"
2078"--\n"
2079"\n");
2080
2081#define _CODECS_UTF_16_BE_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002082 {"utf_16_be_encode", (PyCFunction)(void(*)(void))_codecs_utf_16_be_encode, METH_FASTCALL, _codecs_utf_16_be_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002083
2084static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002085_codecs_utf_16_be_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002086 const char *errors);
2087
2088static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002089_codecs_utf_16_be_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002090{
2091 PyObject *return_value = NULL;
2092 PyObject *str;
2093 const char *errors = NULL;
2094
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002095 if (!_PyArg_CheckPositional("utf_16_be_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002096 goto exit;
2097 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002098 if (!PyUnicode_Check(args[0])) {
2099 _PyArg_BadArgument("utf_16_be_encode", 1, "str", args[0]);
2100 goto exit;
2101 }
2102 if (PyUnicode_READY(args[0]) == -1) {
2103 goto exit;
2104 }
2105 str = args[0];
2106 if (nargs < 2) {
2107 goto skip_optional;
2108 }
2109 if (args[1] == Py_None) {
2110 errors = NULL;
2111 }
2112 else if (PyUnicode_Check(args[1])) {
2113 Py_ssize_t errors_length;
2114 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2115 if (errors == NULL) {
2116 goto exit;
2117 }
2118 if (strlen(errors) != (size_t)errors_length) {
2119 PyErr_SetString(PyExc_ValueError, "embedded null character");
2120 goto exit;
2121 }
2122 }
2123 else {
2124 _PyArg_BadArgument("utf_16_be_encode", 2, "str or None", args[1]);
2125 goto exit;
2126 }
2127skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002128 return_value = _codecs_utf_16_be_encode_impl(module, str, errors);
2129
2130exit:
2131 return return_value;
2132}
2133
2134PyDoc_STRVAR(_codecs_utf_32_encode__doc__,
2135"utf_32_encode($module, str, errors=None, byteorder=0, /)\n"
2136"--\n"
2137"\n");
2138
2139#define _CODECS_UTF_32_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002140 {"utf_32_encode", (PyCFunction)(void(*)(void))_codecs_utf_32_encode, METH_FASTCALL, _codecs_utf_32_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002141
2142static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002143_codecs_utf_32_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002144 const char *errors, int byteorder);
2145
2146static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002147_codecs_utf_32_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002148{
2149 PyObject *return_value = NULL;
2150 PyObject *str;
2151 const char *errors = NULL;
2152 int byteorder = 0;
2153
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002154 if (!_PyArg_CheckPositional("utf_32_encode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002155 goto exit;
2156 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002157 if (!PyUnicode_Check(args[0])) {
2158 _PyArg_BadArgument("utf_32_encode", 1, "str", args[0]);
2159 goto exit;
2160 }
2161 if (PyUnicode_READY(args[0]) == -1) {
2162 goto exit;
2163 }
2164 str = args[0];
2165 if (nargs < 2) {
2166 goto skip_optional;
2167 }
2168 if (args[1] == Py_None) {
2169 errors = NULL;
2170 }
2171 else if (PyUnicode_Check(args[1])) {
2172 Py_ssize_t errors_length;
2173 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2174 if (errors == NULL) {
2175 goto exit;
2176 }
2177 if (strlen(errors) != (size_t)errors_length) {
2178 PyErr_SetString(PyExc_ValueError, "embedded null character");
2179 goto exit;
2180 }
2181 }
2182 else {
2183 _PyArg_BadArgument("utf_32_encode", 2, "str or None", args[1]);
2184 goto exit;
2185 }
2186 if (nargs < 3) {
2187 goto skip_optional;
2188 }
2189 if (PyFloat_Check(args[2])) {
2190 PyErr_SetString(PyExc_TypeError,
2191 "integer argument expected, got float" );
2192 goto exit;
2193 }
2194 byteorder = _PyLong_AsInt(args[2]);
2195 if (byteorder == -1 && PyErr_Occurred()) {
2196 goto exit;
2197 }
2198skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002199 return_value = _codecs_utf_32_encode_impl(module, str, errors, byteorder);
2200
2201exit:
2202 return return_value;
2203}
2204
2205PyDoc_STRVAR(_codecs_utf_32_le_encode__doc__,
2206"utf_32_le_encode($module, str, errors=None, /)\n"
2207"--\n"
2208"\n");
2209
2210#define _CODECS_UTF_32_LE_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002211 {"utf_32_le_encode", (PyCFunction)(void(*)(void))_codecs_utf_32_le_encode, METH_FASTCALL, _codecs_utf_32_le_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002212
2213static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002214_codecs_utf_32_le_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002215 const char *errors);
2216
2217static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002218_codecs_utf_32_le_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002219{
2220 PyObject *return_value = NULL;
2221 PyObject *str;
2222 const char *errors = NULL;
2223
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002224 if (!_PyArg_CheckPositional("utf_32_le_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002225 goto exit;
2226 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002227 if (!PyUnicode_Check(args[0])) {
2228 _PyArg_BadArgument("utf_32_le_encode", 1, "str", args[0]);
2229 goto exit;
2230 }
2231 if (PyUnicode_READY(args[0]) == -1) {
2232 goto exit;
2233 }
2234 str = args[0];
2235 if (nargs < 2) {
2236 goto skip_optional;
2237 }
2238 if (args[1] == Py_None) {
2239 errors = NULL;
2240 }
2241 else if (PyUnicode_Check(args[1])) {
2242 Py_ssize_t errors_length;
2243 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2244 if (errors == NULL) {
2245 goto exit;
2246 }
2247 if (strlen(errors) != (size_t)errors_length) {
2248 PyErr_SetString(PyExc_ValueError, "embedded null character");
2249 goto exit;
2250 }
2251 }
2252 else {
2253 _PyArg_BadArgument("utf_32_le_encode", 2, "str or None", args[1]);
2254 goto exit;
2255 }
2256skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002257 return_value = _codecs_utf_32_le_encode_impl(module, str, errors);
2258
2259exit:
2260 return return_value;
2261}
2262
2263PyDoc_STRVAR(_codecs_utf_32_be_encode__doc__,
2264"utf_32_be_encode($module, str, errors=None, /)\n"
2265"--\n"
2266"\n");
2267
2268#define _CODECS_UTF_32_BE_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002269 {"utf_32_be_encode", (PyCFunction)(void(*)(void))_codecs_utf_32_be_encode, METH_FASTCALL, _codecs_utf_32_be_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002270
2271static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002272_codecs_utf_32_be_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002273 const char *errors);
2274
2275static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002276_codecs_utf_32_be_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002277{
2278 PyObject *return_value = NULL;
2279 PyObject *str;
2280 const char *errors = NULL;
2281
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002282 if (!_PyArg_CheckPositional("utf_32_be_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002283 goto exit;
2284 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002285 if (!PyUnicode_Check(args[0])) {
2286 _PyArg_BadArgument("utf_32_be_encode", 1, "str", args[0]);
2287 goto exit;
2288 }
2289 if (PyUnicode_READY(args[0]) == -1) {
2290 goto exit;
2291 }
2292 str = args[0];
2293 if (nargs < 2) {
2294 goto skip_optional;
2295 }
2296 if (args[1] == Py_None) {
2297 errors = NULL;
2298 }
2299 else if (PyUnicode_Check(args[1])) {
2300 Py_ssize_t errors_length;
2301 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2302 if (errors == NULL) {
2303 goto exit;
2304 }
2305 if (strlen(errors) != (size_t)errors_length) {
2306 PyErr_SetString(PyExc_ValueError, "embedded null character");
2307 goto exit;
2308 }
2309 }
2310 else {
2311 _PyArg_BadArgument("utf_32_be_encode", 2, "str or None", args[1]);
2312 goto exit;
2313 }
2314skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002315 return_value = _codecs_utf_32_be_encode_impl(module, str, errors);
2316
2317exit:
2318 return return_value;
2319}
2320
2321PyDoc_STRVAR(_codecs_unicode_escape_encode__doc__,
2322"unicode_escape_encode($module, str, errors=None, /)\n"
2323"--\n"
2324"\n");
2325
2326#define _CODECS_UNICODE_ESCAPE_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002327 {"unicode_escape_encode", (PyCFunction)(void(*)(void))_codecs_unicode_escape_encode, METH_FASTCALL, _codecs_unicode_escape_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002328
2329static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002330_codecs_unicode_escape_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002331 const char *errors);
2332
2333static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002334_codecs_unicode_escape_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002335{
2336 PyObject *return_value = NULL;
2337 PyObject *str;
2338 const char *errors = NULL;
2339
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002340 if (!_PyArg_CheckPositional("unicode_escape_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002341 goto exit;
2342 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002343 if (!PyUnicode_Check(args[0])) {
2344 _PyArg_BadArgument("unicode_escape_encode", 1, "str", args[0]);
2345 goto exit;
2346 }
2347 if (PyUnicode_READY(args[0]) == -1) {
2348 goto exit;
2349 }
2350 str = args[0];
2351 if (nargs < 2) {
2352 goto skip_optional;
2353 }
2354 if (args[1] == Py_None) {
2355 errors = NULL;
2356 }
2357 else if (PyUnicode_Check(args[1])) {
2358 Py_ssize_t errors_length;
2359 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2360 if (errors == NULL) {
2361 goto exit;
2362 }
2363 if (strlen(errors) != (size_t)errors_length) {
2364 PyErr_SetString(PyExc_ValueError, "embedded null character");
2365 goto exit;
2366 }
2367 }
2368 else {
2369 _PyArg_BadArgument("unicode_escape_encode", 2, "str or None", args[1]);
2370 goto exit;
2371 }
2372skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002373 return_value = _codecs_unicode_escape_encode_impl(module, str, errors);
2374
2375exit:
2376 return return_value;
2377}
2378
2379PyDoc_STRVAR(_codecs_raw_unicode_escape_encode__doc__,
2380"raw_unicode_escape_encode($module, str, errors=None, /)\n"
2381"--\n"
2382"\n");
2383
2384#define _CODECS_RAW_UNICODE_ESCAPE_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002385 {"raw_unicode_escape_encode", (PyCFunction)(void(*)(void))_codecs_raw_unicode_escape_encode, METH_FASTCALL, _codecs_raw_unicode_escape_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002386
2387static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002388_codecs_raw_unicode_escape_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002389 const char *errors);
2390
2391static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002392_codecs_raw_unicode_escape_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002393{
2394 PyObject *return_value = NULL;
2395 PyObject *str;
2396 const char *errors = NULL;
2397
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002398 if (!_PyArg_CheckPositional("raw_unicode_escape_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002399 goto exit;
2400 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002401 if (!PyUnicode_Check(args[0])) {
2402 _PyArg_BadArgument("raw_unicode_escape_encode", 1, "str", args[0]);
2403 goto exit;
2404 }
2405 if (PyUnicode_READY(args[0]) == -1) {
2406 goto exit;
2407 }
2408 str = args[0];
2409 if (nargs < 2) {
2410 goto skip_optional;
2411 }
2412 if (args[1] == Py_None) {
2413 errors = NULL;
2414 }
2415 else if (PyUnicode_Check(args[1])) {
2416 Py_ssize_t errors_length;
2417 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2418 if (errors == NULL) {
2419 goto exit;
2420 }
2421 if (strlen(errors) != (size_t)errors_length) {
2422 PyErr_SetString(PyExc_ValueError, "embedded null character");
2423 goto exit;
2424 }
2425 }
2426 else {
2427 _PyArg_BadArgument("raw_unicode_escape_encode", 2, "str or None", args[1]);
2428 goto exit;
2429 }
2430skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002431 return_value = _codecs_raw_unicode_escape_encode_impl(module, str, errors);
2432
2433exit:
2434 return return_value;
2435}
2436
2437PyDoc_STRVAR(_codecs_latin_1_encode__doc__,
2438"latin_1_encode($module, str, errors=None, /)\n"
2439"--\n"
2440"\n");
2441
2442#define _CODECS_LATIN_1_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002443 {"latin_1_encode", (PyCFunction)(void(*)(void))_codecs_latin_1_encode, METH_FASTCALL, _codecs_latin_1_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002444
2445static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002446_codecs_latin_1_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002447 const char *errors);
2448
2449static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002450_codecs_latin_1_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002451{
2452 PyObject *return_value = NULL;
2453 PyObject *str;
2454 const char *errors = NULL;
2455
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002456 if (!_PyArg_CheckPositional("latin_1_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002457 goto exit;
2458 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002459 if (!PyUnicode_Check(args[0])) {
2460 _PyArg_BadArgument("latin_1_encode", 1, "str", args[0]);
2461 goto exit;
2462 }
2463 if (PyUnicode_READY(args[0]) == -1) {
2464 goto exit;
2465 }
2466 str = args[0];
2467 if (nargs < 2) {
2468 goto skip_optional;
2469 }
2470 if (args[1] == Py_None) {
2471 errors = NULL;
2472 }
2473 else if (PyUnicode_Check(args[1])) {
2474 Py_ssize_t errors_length;
2475 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2476 if (errors == NULL) {
2477 goto exit;
2478 }
2479 if (strlen(errors) != (size_t)errors_length) {
2480 PyErr_SetString(PyExc_ValueError, "embedded null character");
2481 goto exit;
2482 }
2483 }
2484 else {
2485 _PyArg_BadArgument("latin_1_encode", 2, "str or None", args[1]);
2486 goto exit;
2487 }
2488skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002489 return_value = _codecs_latin_1_encode_impl(module, str, errors);
2490
2491exit:
2492 return return_value;
2493}
2494
2495PyDoc_STRVAR(_codecs_ascii_encode__doc__,
2496"ascii_encode($module, str, errors=None, /)\n"
2497"--\n"
2498"\n");
2499
2500#define _CODECS_ASCII_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002501 {"ascii_encode", (PyCFunction)(void(*)(void))_codecs_ascii_encode, METH_FASTCALL, _codecs_ascii_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002502
2503static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002504_codecs_ascii_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002505 const char *errors);
2506
2507static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002508_codecs_ascii_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002509{
2510 PyObject *return_value = NULL;
2511 PyObject *str;
2512 const char *errors = NULL;
2513
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002514 if (!_PyArg_CheckPositional("ascii_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002515 goto exit;
2516 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002517 if (!PyUnicode_Check(args[0])) {
2518 _PyArg_BadArgument("ascii_encode", 1, "str", args[0]);
2519 goto exit;
2520 }
2521 if (PyUnicode_READY(args[0]) == -1) {
2522 goto exit;
2523 }
2524 str = args[0];
2525 if (nargs < 2) {
2526 goto skip_optional;
2527 }
2528 if (args[1] == Py_None) {
2529 errors = NULL;
2530 }
2531 else if (PyUnicode_Check(args[1])) {
2532 Py_ssize_t errors_length;
2533 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2534 if (errors == NULL) {
2535 goto exit;
2536 }
2537 if (strlen(errors) != (size_t)errors_length) {
2538 PyErr_SetString(PyExc_ValueError, "embedded null character");
2539 goto exit;
2540 }
2541 }
2542 else {
2543 _PyArg_BadArgument("ascii_encode", 2, "str or None", args[1]);
2544 goto exit;
2545 }
2546skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002547 return_value = _codecs_ascii_encode_impl(module, str, errors);
2548
2549exit:
2550 return return_value;
2551}
2552
2553PyDoc_STRVAR(_codecs_charmap_encode__doc__,
2554"charmap_encode($module, str, errors=None, mapping=None, /)\n"
2555"--\n"
2556"\n");
2557
2558#define _CODECS_CHARMAP_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002559 {"charmap_encode", (PyCFunction)(void(*)(void))_codecs_charmap_encode, METH_FASTCALL, _codecs_charmap_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002560
2561static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002562_codecs_charmap_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002563 const char *errors, PyObject *mapping);
2564
2565static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002566_codecs_charmap_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002567{
2568 PyObject *return_value = NULL;
2569 PyObject *str;
2570 const char *errors = NULL;
2571 PyObject *mapping = NULL;
2572
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002573 if (!_PyArg_CheckPositional("charmap_encode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002574 goto exit;
2575 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002576 if (!PyUnicode_Check(args[0])) {
2577 _PyArg_BadArgument("charmap_encode", 1, "str", args[0]);
2578 goto exit;
2579 }
2580 if (PyUnicode_READY(args[0]) == -1) {
2581 goto exit;
2582 }
2583 str = args[0];
2584 if (nargs < 2) {
2585 goto skip_optional;
2586 }
2587 if (args[1] == Py_None) {
2588 errors = NULL;
2589 }
2590 else if (PyUnicode_Check(args[1])) {
2591 Py_ssize_t errors_length;
2592 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2593 if (errors == NULL) {
2594 goto exit;
2595 }
2596 if (strlen(errors) != (size_t)errors_length) {
2597 PyErr_SetString(PyExc_ValueError, "embedded null character");
2598 goto exit;
2599 }
2600 }
2601 else {
2602 _PyArg_BadArgument("charmap_encode", 2, "str or None", args[1]);
2603 goto exit;
2604 }
2605 if (nargs < 3) {
2606 goto skip_optional;
2607 }
2608 mapping = args[2];
2609skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002610 return_value = _codecs_charmap_encode_impl(module, str, errors, mapping);
2611
2612exit:
2613 return return_value;
2614}
2615
2616PyDoc_STRVAR(_codecs_charmap_build__doc__,
2617"charmap_build($module, map, /)\n"
2618"--\n"
2619"\n");
2620
2621#define _CODECS_CHARMAP_BUILD_METHODDEF \
2622 {"charmap_build", (PyCFunction)_codecs_charmap_build, METH_O, _codecs_charmap_build__doc__},
2623
2624static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002625_codecs_charmap_build_impl(PyObject *module, PyObject *map);
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002626
2627static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002628_codecs_charmap_build(PyObject *module, PyObject *arg)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002629{
2630 PyObject *return_value = NULL;
2631 PyObject *map;
2632
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002633 if (!PyUnicode_Check(arg)) {
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002634 _PyArg_BadArgument("charmap_build", 0, "str", arg);
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002635 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002636 }
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002637 if (PyUnicode_READY(arg) == -1) {
2638 goto exit;
2639 }
2640 map = arg;
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002641 return_value = _codecs_charmap_build_impl(module, map);
2642
2643exit:
2644 return return_value;
2645}
2646
Steve Dowercc16be82016-09-08 10:35:16 -07002647#if defined(MS_WINDOWS)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002648
2649PyDoc_STRVAR(_codecs_mbcs_encode__doc__,
2650"mbcs_encode($module, str, errors=None, /)\n"
2651"--\n"
2652"\n");
2653
2654#define _CODECS_MBCS_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002655 {"mbcs_encode", (PyCFunction)(void(*)(void))_codecs_mbcs_encode, METH_FASTCALL, _codecs_mbcs_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002656
2657static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002658_codecs_mbcs_encode_impl(PyObject *module, PyObject *str, const char *errors);
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002659
2660static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002661_codecs_mbcs_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002662{
2663 PyObject *return_value = NULL;
2664 PyObject *str;
2665 const char *errors = NULL;
2666
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002667 if (!_PyArg_CheckPositional("mbcs_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002668 goto exit;
2669 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002670 if (!PyUnicode_Check(args[0])) {
2671 _PyArg_BadArgument("mbcs_encode", 1, "str", args[0]);
2672 goto exit;
2673 }
2674 if (PyUnicode_READY(args[0]) == -1) {
2675 goto exit;
2676 }
2677 str = args[0];
2678 if (nargs < 2) {
2679 goto skip_optional;
2680 }
2681 if (args[1] == Py_None) {
2682 errors = NULL;
2683 }
2684 else if (PyUnicode_Check(args[1])) {
2685 Py_ssize_t errors_length;
2686 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2687 if (errors == NULL) {
2688 goto exit;
2689 }
2690 if (strlen(errors) != (size_t)errors_length) {
2691 PyErr_SetString(PyExc_ValueError, "embedded null character");
2692 goto exit;
2693 }
2694 }
2695 else {
2696 _PyArg_BadArgument("mbcs_encode", 2, "str or None", args[1]);
2697 goto exit;
2698 }
2699skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002700 return_value = _codecs_mbcs_encode_impl(module, str, errors);
2701
2702exit:
2703 return return_value;
2704}
2705
Steve Dowercc16be82016-09-08 10:35:16 -07002706#endif /* defined(MS_WINDOWS) */
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002707
Steve Dowercc16be82016-09-08 10:35:16 -07002708#if defined(MS_WINDOWS)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002709
Steve Dowerf5aba582016-09-06 19:42:27 -07002710PyDoc_STRVAR(_codecs_oem_encode__doc__,
2711"oem_encode($module, str, errors=None, /)\n"
2712"--\n"
2713"\n");
2714
2715#define _CODECS_OEM_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002716 {"oem_encode", (PyCFunction)(void(*)(void))_codecs_oem_encode, METH_FASTCALL, _codecs_oem_encode__doc__},
Steve Dowerf5aba582016-09-06 19:42:27 -07002717
2718static PyObject *
2719_codecs_oem_encode_impl(PyObject *module, PyObject *str, const char *errors);
2720
2721static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002722_codecs_oem_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Steve Dowerf5aba582016-09-06 19:42:27 -07002723{
2724 PyObject *return_value = NULL;
2725 PyObject *str;
2726 const char *errors = NULL;
2727
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002728 if (!_PyArg_CheckPositional("oem_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002729 goto exit;
2730 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002731 if (!PyUnicode_Check(args[0])) {
2732 _PyArg_BadArgument("oem_encode", 1, "str", args[0]);
2733 goto exit;
2734 }
2735 if (PyUnicode_READY(args[0]) == -1) {
2736 goto exit;
2737 }
2738 str = args[0];
2739 if (nargs < 2) {
2740 goto skip_optional;
2741 }
2742 if (args[1] == Py_None) {
2743 errors = NULL;
2744 }
2745 else if (PyUnicode_Check(args[1])) {
2746 Py_ssize_t errors_length;
2747 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2748 if (errors == NULL) {
2749 goto exit;
2750 }
2751 if (strlen(errors) != (size_t)errors_length) {
2752 PyErr_SetString(PyExc_ValueError, "embedded null character");
2753 goto exit;
2754 }
2755 }
2756 else {
2757 _PyArg_BadArgument("oem_encode", 2, "str or None", args[1]);
2758 goto exit;
2759 }
2760skip_optional:
Steve Dowerf5aba582016-09-06 19:42:27 -07002761 return_value = _codecs_oem_encode_impl(module, str, errors);
2762
2763exit:
2764 return return_value;
2765}
2766
Steve Dowercc16be82016-09-08 10:35:16 -07002767#endif /* defined(MS_WINDOWS) */
Steve Dowerf5aba582016-09-06 19:42:27 -07002768
Steve Dowercc16be82016-09-08 10:35:16 -07002769#if defined(MS_WINDOWS)
Steve Dowerf5aba582016-09-06 19:42:27 -07002770
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002771PyDoc_STRVAR(_codecs_code_page_encode__doc__,
2772"code_page_encode($module, code_page, str, errors=None, /)\n"
2773"--\n"
2774"\n");
2775
2776#define _CODECS_CODE_PAGE_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002777 {"code_page_encode", (PyCFunction)(void(*)(void))_codecs_code_page_encode, METH_FASTCALL, _codecs_code_page_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002778
2779static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002780_codecs_code_page_encode_impl(PyObject *module, int code_page, PyObject *str,
2781 const char *errors);
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002782
2783static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002784_codecs_code_page_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002785{
2786 PyObject *return_value = NULL;
2787 int code_page;
2788 PyObject *str;
2789 const char *errors = NULL;
2790
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002791 if (!_PyArg_CheckPositional("code_page_encode", nargs, 2, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002792 goto exit;
2793 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002794 if (PyFloat_Check(args[0])) {
2795 PyErr_SetString(PyExc_TypeError,
2796 "integer argument expected, got float" );
2797 goto exit;
2798 }
2799 code_page = _PyLong_AsInt(args[0]);
2800 if (code_page == -1 && PyErr_Occurred()) {
2801 goto exit;
2802 }
2803 if (!PyUnicode_Check(args[1])) {
2804 _PyArg_BadArgument("code_page_encode", 2, "str", args[1]);
2805 goto exit;
2806 }
2807 if (PyUnicode_READY(args[1]) == -1) {
2808 goto exit;
2809 }
2810 str = args[1];
2811 if (nargs < 3) {
2812 goto skip_optional;
2813 }
2814 if (args[2] == Py_None) {
2815 errors = NULL;
2816 }
2817 else if (PyUnicode_Check(args[2])) {
2818 Py_ssize_t errors_length;
2819 errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length);
2820 if (errors == NULL) {
2821 goto exit;
2822 }
2823 if (strlen(errors) != (size_t)errors_length) {
2824 PyErr_SetString(PyExc_ValueError, "embedded null character");
2825 goto exit;
2826 }
2827 }
2828 else {
2829 _PyArg_BadArgument("code_page_encode", 3, "str or None", args[2]);
2830 goto exit;
2831 }
2832skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002833 return_value = _codecs_code_page_encode_impl(module, code_page, str, errors);
2834
2835exit:
2836 return return_value;
2837}
2838
Steve Dowercc16be82016-09-08 10:35:16 -07002839#endif /* defined(MS_WINDOWS) */
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002840
2841PyDoc_STRVAR(_codecs_register_error__doc__,
2842"register_error($module, errors, handler, /)\n"
2843"--\n"
2844"\n"
2845"Register the specified error handler under the name errors.\n"
2846"\n"
2847"handler must be a callable object, that will be called with an exception\n"
2848"instance containing information about the location of the encoding/decoding\n"
2849"error and must return a (replacement, new position) tuple.");
2850
2851#define _CODECS_REGISTER_ERROR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002852 {"register_error", (PyCFunction)(void(*)(void))_codecs_register_error, METH_FASTCALL, _codecs_register_error__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002853
2854static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002855_codecs_register_error_impl(PyObject *module, const char *errors,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002856 PyObject *handler);
2857
2858static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002859_codecs_register_error(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002860{
2861 PyObject *return_value = NULL;
2862 const char *errors;
2863 PyObject *handler;
2864
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002865 if (!_PyArg_CheckPositional("register_error", nargs, 2, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002866 goto exit;
2867 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002868 if (!PyUnicode_Check(args[0])) {
2869 _PyArg_BadArgument("register_error", 1, "str", args[0]);
2870 goto exit;
2871 }
2872 Py_ssize_t errors_length;
2873 errors = PyUnicode_AsUTF8AndSize(args[0], &errors_length);
2874 if (errors == NULL) {
2875 goto exit;
2876 }
2877 if (strlen(errors) != (size_t)errors_length) {
2878 PyErr_SetString(PyExc_ValueError, "embedded null character");
2879 goto exit;
2880 }
2881 handler = args[1];
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002882 return_value = _codecs_register_error_impl(module, errors, handler);
2883
2884exit:
2885 return return_value;
2886}
2887
2888PyDoc_STRVAR(_codecs_lookup_error__doc__,
2889"lookup_error($module, name, /)\n"
2890"--\n"
2891"\n"
2892"lookup_error(errors) -> handler\n"
2893"\n"
2894"Return the error handler for the specified error handling name or raise a\n"
2895"LookupError, if no handler exists under this name.");
2896
2897#define _CODECS_LOOKUP_ERROR_METHODDEF \
2898 {"lookup_error", (PyCFunction)_codecs_lookup_error, METH_O, _codecs_lookup_error__doc__},
2899
2900static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002901_codecs_lookup_error_impl(PyObject *module, const char *name);
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002902
2903static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002904_codecs_lookup_error(PyObject *module, PyObject *arg)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002905{
2906 PyObject *return_value = NULL;
2907 const char *name;
2908
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002909 if (!PyUnicode_Check(arg)) {
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002910 _PyArg_BadArgument("lookup_error", 0, "str", arg);
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002911 goto exit;
2912 }
2913 Py_ssize_t name_length;
2914 name = PyUnicode_AsUTF8AndSize(arg, &name_length);
2915 if (name == NULL) {
2916 goto exit;
2917 }
2918 if (strlen(name) != (size_t)name_length) {
2919 PyErr_SetString(PyExc_ValueError, "embedded null character");
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002920 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002921 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002922 return_value = _codecs_lookup_error_impl(module, name);
2923
2924exit:
2925 return return_value;
2926}
2927
2928#ifndef _CODECS_MBCS_DECODE_METHODDEF
2929 #define _CODECS_MBCS_DECODE_METHODDEF
2930#endif /* !defined(_CODECS_MBCS_DECODE_METHODDEF) */
2931
Steve Dowerf5aba582016-09-06 19:42:27 -07002932#ifndef _CODECS_OEM_DECODE_METHODDEF
2933 #define _CODECS_OEM_DECODE_METHODDEF
2934#endif /* !defined(_CODECS_OEM_DECODE_METHODDEF) */
2935
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002936#ifndef _CODECS_CODE_PAGE_DECODE_METHODDEF
2937 #define _CODECS_CODE_PAGE_DECODE_METHODDEF
2938#endif /* !defined(_CODECS_CODE_PAGE_DECODE_METHODDEF) */
2939
2940#ifndef _CODECS_MBCS_ENCODE_METHODDEF
2941 #define _CODECS_MBCS_ENCODE_METHODDEF
2942#endif /* !defined(_CODECS_MBCS_ENCODE_METHODDEF) */
2943
Steve Dowerf5aba582016-09-06 19:42:27 -07002944#ifndef _CODECS_OEM_ENCODE_METHODDEF
2945 #define _CODECS_OEM_ENCODE_METHODDEF
2946#endif /* !defined(_CODECS_OEM_ENCODE_METHODDEF) */
2947
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002948#ifndef _CODECS_CODE_PAGE_ENCODE_METHODDEF
2949 #define _CODECS_CODE_PAGE_ENCODE_METHODDEF
2950#endif /* !defined(_CODECS_CODE_PAGE_ENCODE_METHODDEF) */
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002951/*[clinic end generated code: output=85ea29db163ee74c input=a9049054013a1b77]*/