LCOV - code coverage report
Current view: top level - Modules/clinic - _codecsmodule.c.h (source / functions) Hit Total Coverage
Test: CPython 3.12 LCOV report [commit 5e6661bce9] Lines: 32 1152 2.8 %
Date: 2023-03-20 08:15:36 Functions: 2 37 5.4 %
Branches: 15 832 1.8 %

           Branch data     Line data    Source code
       1                 :            : /*[clinic input]
       2                 :            : preserve
       3                 :            : [clinic start generated code]*/
       4                 :            : 
       5                 :            : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
       6                 :            : #  include "pycore_gc.h"            // PyGC_Head
       7                 :            : #  include "pycore_runtime.h"       // _Py_ID()
       8                 :            : #endif
       9                 :            : 
      10                 :            : 
      11                 :            : PyDoc_STRVAR(_codecs_register__doc__,
      12                 :            : "register($module, search_function, /)\n"
      13                 :            : "--\n"
      14                 :            : "\n"
      15                 :            : "Register a codec search function.\n"
      16                 :            : "\n"
      17                 :            : "Search functions are expected to take one argument, the encoding name in\n"
      18                 :            : "all lower case letters, and either return None, or a tuple of functions\n"
      19                 :            : "(encoder, decoder, stream_reader, stream_writer) (or a CodecInfo object).");
      20                 :            : 
      21                 :            : #define _CODECS_REGISTER_METHODDEF    \
      22                 :            :     {"register", (PyCFunction)_codecs_register, METH_O, _codecs_register__doc__},
      23                 :            : 
      24                 :            : PyDoc_STRVAR(_codecs_unregister__doc__,
      25                 :            : "unregister($module, search_function, /)\n"
      26                 :            : "--\n"
      27                 :            : "\n"
      28                 :            : "Unregister a codec search function and clear the registry\'s cache.\n"
      29                 :            : "\n"
      30                 :            : "If the search function is not registered, do nothing.");
      31                 :            : 
      32                 :            : #define _CODECS_UNREGISTER_METHODDEF    \
      33                 :            :     {"unregister", (PyCFunction)_codecs_unregister, METH_O, _codecs_unregister__doc__},
      34                 :            : 
      35                 :            : PyDoc_STRVAR(_codecs_lookup__doc__,
      36                 :            : "lookup($module, encoding, /)\n"
      37                 :            : "--\n"
      38                 :            : "\n"
      39                 :            : "Looks up a codec tuple in the Python codec registry and returns a CodecInfo object.");
      40                 :            : 
      41                 :            : #define _CODECS_LOOKUP_METHODDEF    \
      42                 :            :     {"lookup", (PyCFunction)_codecs_lookup, METH_O, _codecs_lookup__doc__},
      43                 :            : 
      44                 :            : static PyObject *
      45                 :            : _codecs_lookup_impl(PyObject *module, const char *encoding);
      46                 :            : 
      47                 :            : static PyObject *
      48                 :          0 : _codecs_lookup(PyObject *module, PyObject *arg)
      49                 :            : {
      50                 :          0 :     PyObject *return_value = NULL;
      51                 :            :     const char *encoding;
      52                 :            : 
      53         [ #  # ]:          0 :     if (!PyUnicode_Check(arg)) {
      54                 :          0 :         _PyArg_BadArgument("lookup", "argument", "str", arg);
      55                 :          0 :         goto exit;
      56                 :            :     }
      57                 :            :     Py_ssize_t encoding_length;
      58                 :          0 :     encoding = PyUnicode_AsUTF8AndSize(arg, &encoding_length);
      59         [ #  # ]:          0 :     if (encoding == NULL) {
      60                 :          0 :         goto exit;
      61                 :            :     }
      62         [ #  # ]:          0 :     if (strlen(encoding) != (size_t)encoding_length) {
      63                 :          0 :         PyErr_SetString(PyExc_ValueError, "embedded null character");
      64                 :          0 :         goto exit;
      65                 :            :     }
      66                 :          0 :     return_value = _codecs_lookup_impl(module, encoding);
      67                 :            : 
      68                 :          0 : exit:
      69                 :          0 :     return return_value;
      70                 :            : }
      71                 :            : 
      72                 :            : PyDoc_STRVAR(_codecs_encode__doc__,
      73                 :            : "encode($module, /, obj, encoding=\'utf-8\', errors=\'strict\')\n"
      74                 :            : "--\n"
      75                 :            : "\n"
      76                 :            : "Encodes obj using the codec registered for encoding.\n"
      77                 :            : "\n"
      78                 :            : "The default encoding is \'utf-8\'.  errors may be given to set a\n"
      79                 :            : "different error handling scheme.  Default is \'strict\' meaning that encoding\n"
      80                 :            : "errors raise a ValueError.  Other possible values are \'ignore\', \'replace\'\n"
      81                 :            : "and \'backslashreplace\' as well as any other name registered with\n"
      82                 :            : "codecs.register_error that can handle ValueErrors.");
      83                 :            : 
      84                 :            : #define _CODECS_ENCODE_METHODDEF    \
      85                 :            :     {"encode", _PyCFunction_CAST(_codecs_encode), METH_FASTCALL|METH_KEYWORDS, _codecs_encode__doc__},
      86                 :            : 
      87                 :            : static PyObject *
      88                 :            : _codecs_encode_impl(PyObject *module, PyObject *obj, const char *encoding,
      89                 :            :                     const char *errors);
      90                 :            : 
      91                 :            : static PyObject *
      92                 :          0 : _codecs_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
      93                 :            : {
      94                 :          0 :     PyObject *return_value = NULL;
      95                 :            :     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
      96                 :            : 
      97                 :            :     #define NUM_KEYWORDS 3
      98                 :            :     static struct {
      99                 :            :         PyGC_Head _this_is_not_used;
     100                 :            :         PyObject_VAR_HEAD
     101                 :            :         PyObject *ob_item[NUM_KEYWORDS];
     102                 :            :     } _kwtuple = {
     103                 :            :         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
     104                 :            :         .ob_item = { &_Py_ID(obj), &_Py_ID(encoding), &_Py_ID(errors), },
     105                 :            :     };
     106                 :            :     #undef NUM_KEYWORDS
     107                 :            :     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
     108                 :            : 
     109                 :            :     #else  // !Py_BUILD_CORE
     110                 :            :     #  define KWTUPLE NULL
     111                 :            :     #endif  // !Py_BUILD_CORE
     112                 :            : 
     113                 :            :     static const char * const _keywords[] = {"obj", "encoding", "errors", NULL};
     114                 :            :     static _PyArg_Parser _parser = {
     115                 :            :         .keywords = _keywords,
     116                 :            :         .fname = "encode",
     117                 :            :         .kwtuple = KWTUPLE,
     118                 :            :     };
     119                 :            :     #undef KWTUPLE
     120                 :            :     PyObject *argsbuf[3];
     121         [ #  # ]:          0 :     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
     122                 :            :     PyObject *obj;
     123                 :          0 :     const char *encoding = NULL;
     124                 :          0 :     const char *errors = NULL;
     125                 :            : 
     126   [ #  #  #  #  :          0 :     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
             #  #  #  # ]
     127         [ #  # ]:          0 :     if (!args) {
     128                 :          0 :         goto exit;
     129                 :            :     }
     130                 :          0 :     obj = args[0];
     131         [ #  # ]:          0 :     if (!noptargs) {
     132                 :          0 :         goto skip_optional_pos;
     133                 :            :     }
     134         [ #  # ]:          0 :     if (args[1]) {
     135         [ #  # ]:          0 :         if (!PyUnicode_Check(args[1])) {
     136                 :          0 :             _PyArg_BadArgument("encode", "argument 'encoding'", "str", args[1]);
     137                 :          0 :             goto exit;
     138                 :            :         }
     139                 :            :         Py_ssize_t encoding_length;
     140                 :          0 :         encoding = PyUnicode_AsUTF8AndSize(args[1], &encoding_length);
     141         [ #  # ]:          0 :         if (encoding == NULL) {
     142                 :          0 :             goto exit;
     143                 :            :         }
     144         [ #  # ]:          0 :         if (strlen(encoding) != (size_t)encoding_length) {
     145                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
     146                 :          0 :             goto exit;
     147                 :            :         }
     148         [ #  # ]:          0 :         if (!--noptargs) {
     149                 :          0 :             goto skip_optional_pos;
     150                 :            :         }
     151                 :            :     }
     152         [ #  # ]:          0 :     if (!PyUnicode_Check(args[2])) {
     153                 :          0 :         _PyArg_BadArgument("encode", "argument 'errors'", "str", args[2]);
     154                 :          0 :         goto exit;
     155                 :            :     }
     156                 :            :     Py_ssize_t errors_length;
     157                 :          0 :     errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length);
     158         [ #  # ]:          0 :     if (errors == NULL) {
     159                 :          0 :         goto exit;
     160                 :            :     }
     161         [ #  # ]:          0 :     if (strlen(errors) != (size_t)errors_length) {
     162                 :          0 :         PyErr_SetString(PyExc_ValueError, "embedded null character");
     163                 :          0 :         goto exit;
     164                 :            :     }
     165                 :          0 : skip_optional_pos:
     166                 :          0 :     return_value = _codecs_encode_impl(module, obj, encoding, errors);
     167                 :            : 
     168                 :          0 : exit:
     169                 :          0 :     return return_value;
     170                 :            : }
     171                 :            : 
     172                 :            : PyDoc_STRVAR(_codecs_decode__doc__,
     173                 :            : "decode($module, /, obj, encoding=\'utf-8\', errors=\'strict\')\n"
     174                 :            : "--\n"
     175                 :            : "\n"
     176                 :            : "Decodes obj using the codec registered for encoding.\n"
     177                 :            : "\n"
     178                 :            : "Default encoding is \'utf-8\'.  errors may be given to set a\n"
     179                 :            : "different error handling scheme.  Default is \'strict\' meaning that encoding\n"
     180                 :            : "errors raise a ValueError.  Other possible values are \'ignore\', \'replace\'\n"
     181                 :            : "and \'backslashreplace\' as well as any other name registered with\n"
     182                 :            : "codecs.register_error that can handle ValueErrors.");
     183                 :            : 
     184                 :            : #define _CODECS_DECODE_METHODDEF    \
     185                 :            :     {"decode", _PyCFunction_CAST(_codecs_decode), METH_FASTCALL|METH_KEYWORDS, _codecs_decode__doc__},
     186                 :            : 
     187                 :            : static PyObject *
     188                 :            : _codecs_decode_impl(PyObject *module, PyObject *obj, const char *encoding,
     189                 :            :                     const char *errors);
     190                 :            : 
     191                 :            : static PyObject *
     192                 :          0 : _codecs_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     193                 :            : {
     194                 :          0 :     PyObject *return_value = NULL;
     195                 :            :     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     196                 :            : 
     197                 :            :     #define NUM_KEYWORDS 3
     198                 :            :     static struct {
     199                 :            :         PyGC_Head _this_is_not_used;
     200                 :            :         PyObject_VAR_HEAD
     201                 :            :         PyObject *ob_item[NUM_KEYWORDS];
     202                 :            :     } _kwtuple = {
     203                 :            :         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
     204                 :            :         .ob_item = { &_Py_ID(obj), &_Py_ID(encoding), &_Py_ID(errors), },
     205                 :            :     };
     206                 :            :     #undef NUM_KEYWORDS
     207                 :            :     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
     208                 :            : 
     209                 :            :     #else  // !Py_BUILD_CORE
     210                 :            :     #  define KWTUPLE NULL
     211                 :            :     #endif  // !Py_BUILD_CORE
     212                 :            : 
     213                 :            :     static const char * const _keywords[] = {"obj", "encoding", "errors", NULL};
     214                 :            :     static _PyArg_Parser _parser = {
     215                 :            :         .keywords = _keywords,
     216                 :            :         .fname = "decode",
     217                 :            :         .kwtuple = KWTUPLE,
     218                 :            :     };
     219                 :            :     #undef KWTUPLE
     220                 :            :     PyObject *argsbuf[3];
     221         [ #  # ]:          0 :     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
     222                 :            :     PyObject *obj;
     223                 :          0 :     const char *encoding = NULL;
     224                 :          0 :     const char *errors = NULL;
     225                 :            : 
     226   [ #  #  #  #  :          0 :     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
             #  #  #  # ]
     227         [ #  # ]:          0 :     if (!args) {
     228                 :          0 :         goto exit;
     229                 :            :     }
     230                 :          0 :     obj = args[0];
     231         [ #  # ]:          0 :     if (!noptargs) {
     232                 :          0 :         goto skip_optional_pos;
     233                 :            :     }
     234         [ #  # ]:          0 :     if (args[1]) {
     235         [ #  # ]:          0 :         if (!PyUnicode_Check(args[1])) {
     236                 :          0 :             _PyArg_BadArgument("decode", "argument 'encoding'", "str", args[1]);
     237                 :          0 :             goto exit;
     238                 :            :         }
     239                 :            :         Py_ssize_t encoding_length;
     240                 :          0 :         encoding = PyUnicode_AsUTF8AndSize(args[1], &encoding_length);
     241         [ #  # ]:          0 :         if (encoding == NULL) {
     242                 :          0 :             goto exit;
     243                 :            :         }
     244         [ #  # ]:          0 :         if (strlen(encoding) != (size_t)encoding_length) {
     245                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
     246                 :          0 :             goto exit;
     247                 :            :         }
     248         [ #  # ]:          0 :         if (!--noptargs) {
     249                 :          0 :             goto skip_optional_pos;
     250                 :            :         }
     251                 :            :     }
     252         [ #  # ]:          0 :     if (!PyUnicode_Check(args[2])) {
     253                 :          0 :         _PyArg_BadArgument("decode", "argument 'errors'", "str", args[2]);
     254                 :          0 :         goto exit;
     255                 :            :     }
     256                 :            :     Py_ssize_t errors_length;
     257                 :          0 :     errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length);
     258         [ #  # ]:          0 :     if (errors == NULL) {
     259                 :          0 :         goto exit;
     260                 :            :     }
     261         [ #  # ]:          0 :     if (strlen(errors) != (size_t)errors_length) {
     262                 :          0 :         PyErr_SetString(PyExc_ValueError, "embedded null character");
     263                 :          0 :         goto exit;
     264                 :            :     }
     265                 :          0 : skip_optional_pos:
     266                 :          0 :     return_value = _codecs_decode_impl(module, obj, encoding, errors);
     267                 :            : 
     268                 :          0 : exit:
     269                 :          0 :     return return_value;
     270                 :            : }
     271                 :            : 
     272                 :            : PyDoc_STRVAR(_codecs_escape_decode__doc__,
     273                 :            : "escape_decode($module, data, errors=None, /)\n"
     274                 :            : "--\n"
     275                 :            : "\n");
     276                 :            : 
     277                 :            : #define _CODECS_ESCAPE_DECODE_METHODDEF    \
     278                 :            :     {"escape_decode", _PyCFunction_CAST(_codecs_escape_decode), METH_FASTCALL, _codecs_escape_decode__doc__},
     279                 :            : 
     280                 :            : static PyObject *
     281                 :            : _codecs_escape_decode_impl(PyObject *module, Py_buffer *data,
     282                 :            :                            const char *errors);
     283                 :            : 
     284                 :            : static PyObject *
     285                 :          0 : _codecs_escape_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     286                 :            : {
     287                 :          0 :     PyObject *return_value = NULL;
     288                 :          0 :     Py_buffer data = {NULL, NULL};
     289                 :          0 :     const char *errors = NULL;
     290                 :            : 
     291   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("escape_decode", nargs, 1, 2)) {
                   #  # ]
     292                 :          0 :         goto exit;
     293                 :            :     }
     294         [ #  # ]:          0 :     if (PyUnicode_Check(args[0])) {
     295                 :            :         Py_ssize_t len;
     296                 :          0 :         const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
     297         [ #  # ]:          0 :         if (ptr == NULL) {
     298                 :          0 :             goto exit;
     299                 :            :         }
     300                 :          0 :         PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, 0);
     301                 :            :     }
     302                 :            :     else { /* any bytes-like object */
     303         [ #  # ]:          0 :         if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
     304                 :          0 :             goto exit;
     305                 :            :         }
     306         [ #  # ]:          0 :         if (!PyBuffer_IsContiguous(&data, 'C')) {
     307                 :          0 :             _PyArg_BadArgument("escape_decode", "argument 1", "contiguous buffer", args[0]);
     308                 :          0 :             goto exit;
     309                 :            :         }
     310                 :            :     }
     311         [ #  # ]:          0 :     if (nargs < 2) {
     312                 :          0 :         goto skip_optional;
     313                 :            :     }
     314         [ #  # ]:          0 :     if (args[1] == Py_None) {
     315                 :          0 :         errors = NULL;
     316                 :            :     }
     317         [ #  # ]:          0 :     else if (PyUnicode_Check(args[1])) {
     318                 :            :         Py_ssize_t errors_length;
     319                 :          0 :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
     320         [ #  # ]:          0 :         if (errors == NULL) {
     321                 :          0 :             goto exit;
     322                 :            :         }
     323         [ #  # ]:          0 :         if (strlen(errors) != (size_t)errors_length) {
     324                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
     325                 :          0 :             goto exit;
     326                 :            :         }
     327                 :            :     }
     328                 :            :     else {
     329                 :          0 :         _PyArg_BadArgument("escape_decode", "argument 2", "str or None", args[1]);
     330                 :          0 :         goto exit;
     331                 :            :     }
     332                 :          0 : skip_optional:
     333                 :          0 :     return_value = _codecs_escape_decode_impl(module, &data, errors);
     334                 :            : 
     335                 :          0 : exit:
     336                 :            :     /* Cleanup for data */
     337         [ #  # ]:          0 :     if (data.obj) {
     338                 :          0 :        PyBuffer_Release(&data);
     339                 :            :     }
     340                 :            : 
     341                 :          0 :     return return_value;
     342                 :            : }
     343                 :            : 
     344                 :            : PyDoc_STRVAR(_codecs_escape_encode__doc__,
     345                 :            : "escape_encode($module, data, errors=None, /)\n"
     346                 :            : "--\n"
     347                 :            : "\n");
     348                 :            : 
     349                 :            : #define _CODECS_ESCAPE_ENCODE_METHODDEF    \
     350                 :            :     {"escape_encode", _PyCFunction_CAST(_codecs_escape_encode), METH_FASTCALL, _codecs_escape_encode__doc__},
     351                 :            : 
     352                 :            : static PyObject *
     353                 :            : _codecs_escape_encode_impl(PyObject *module, PyObject *data,
     354                 :            :                            const char *errors);
     355                 :            : 
     356                 :            : static PyObject *
     357                 :          0 : _codecs_escape_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     358                 :            : {
     359                 :          0 :     PyObject *return_value = NULL;
     360                 :            :     PyObject *data;
     361                 :          0 :     const char *errors = NULL;
     362                 :            : 
     363   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("escape_encode", nargs, 1, 2)) {
                   #  # ]
     364                 :          0 :         goto exit;
     365                 :            :     }
     366         [ #  # ]:          0 :     if (!PyBytes_Check(args[0])) {
     367                 :          0 :         _PyArg_BadArgument("escape_encode", "argument 1", "bytes", args[0]);
     368                 :          0 :         goto exit;
     369                 :            :     }
     370                 :          0 :     data = args[0];
     371         [ #  # ]:          0 :     if (nargs < 2) {
     372                 :          0 :         goto skip_optional;
     373                 :            :     }
     374         [ #  # ]:          0 :     if (args[1] == Py_None) {
     375                 :          0 :         errors = NULL;
     376                 :            :     }
     377         [ #  # ]:          0 :     else if (PyUnicode_Check(args[1])) {
     378                 :            :         Py_ssize_t errors_length;
     379                 :          0 :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
     380         [ #  # ]:          0 :         if (errors == NULL) {
     381                 :          0 :             goto exit;
     382                 :            :         }
     383         [ #  # ]:          0 :         if (strlen(errors) != (size_t)errors_length) {
     384                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
     385                 :          0 :             goto exit;
     386                 :            :         }
     387                 :            :     }
     388                 :            :     else {
     389                 :          0 :         _PyArg_BadArgument("escape_encode", "argument 2", "str or None", args[1]);
     390                 :          0 :         goto exit;
     391                 :            :     }
     392                 :          0 : skip_optional:
     393                 :          0 :     return_value = _codecs_escape_encode_impl(module, data, errors);
     394                 :            : 
     395                 :          0 : exit:
     396                 :          0 :     return return_value;
     397                 :            : }
     398                 :            : 
     399                 :            : PyDoc_STRVAR(_codecs_utf_7_decode__doc__,
     400                 :            : "utf_7_decode($module, data, errors=None, final=False, /)\n"
     401                 :            : "--\n"
     402                 :            : "\n");
     403                 :            : 
     404                 :            : #define _CODECS_UTF_7_DECODE_METHODDEF    \
     405                 :            :     {"utf_7_decode", _PyCFunction_CAST(_codecs_utf_7_decode), METH_FASTCALL, _codecs_utf_7_decode__doc__},
     406                 :            : 
     407                 :            : static PyObject *
     408                 :            : _codecs_utf_7_decode_impl(PyObject *module, Py_buffer *data,
     409                 :            :                           const char *errors, int final);
     410                 :            : 
     411                 :            : static PyObject *
     412                 :          0 : _codecs_utf_7_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     413                 :            : {
     414                 :          0 :     PyObject *return_value = NULL;
     415                 :          0 :     Py_buffer data = {NULL, NULL};
     416                 :          0 :     const char *errors = NULL;
     417                 :          0 :     int final = 0;
     418                 :            : 
     419   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("utf_7_decode", nargs, 1, 3)) {
                   #  # ]
     420                 :          0 :         goto exit;
     421                 :            :     }
     422         [ #  # ]:          0 :     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
     423                 :          0 :         goto exit;
     424                 :            :     }
     425         [ #  # ]:          0 :     if (!PyBuffer_IsContiguous(&data, 'C')) {
     426                 :          0 :         _PyArg_BadArgument("utf_7_decode", "argument 1", "contiguous buffer", args[0]);
     427                 :          0 :         goto exit;
     428                 :            :     }
     429         [ #  # ]:          0 :     if (nargs < 2) {
     430                 :          0 :         goto skip_optional;
     431                 :            :     }
     432         [ #  # ]:          0 :     if (args[1] == Py_None) {
     433                 :          0 :         errors = NULL;
     434                 :            :     }
     435         [ #  # ]:          0 :     else if (PyUnicode_Check(args[1])) {
     436                 :            :         Py_ssize_t errors_length;
     437                 :          0 :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
     438         [ #  # ]:          0 :         if (errors == NULL) {
     439                 :          0 :             goto exit;
     440                 :            :         }
     441         [ #  # ]:          0 :         if (strlen(errors) != (size_t)errors_length) {
     442                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
     443                 :          0 :             goto exit;
     444                 :            :         }
     445                 :            :     }
     446                 :            :     else {
     447                 :          0 :         _PyArg_BadArgument("utf_7_decode", "argument 2", "str or None", args[1]);
     448                 :          0 :         goto exit;
     449                 :            :     }
     450         [ #  # ]:          0 :     if (nargs < 3) {
     451                 :          0 :         goto skip_optional;
     452                 :            :     }
     453                 :          0 :     final = PyObject_IsTrue(args[2]);
     454         [ #  # ]:          0 :     if (final < 0) {
     455                 :          0 :         goto exit;
     456                 :            :     }
     457                 :          0 : skip_optional:
     458                 :          0 :     return_value = _codecs_utf_7_decode_impl(module, &data, errors, final);
     459                 :            : 
     460                 :          0 : exit:
     461                 :            :     /* Cleanup for data */
     462         [ #  # ]:          0 :     if (data.obj) {
     463                 :          0 :        PyBuffer_Release(&data);
     464                 :            :     }
     465                 :            : 
     466                 :          0 :     return return_value;
     467                 :            : }
     468                 :            : 
     469                 :            : PyDoc_STRVAR(_codecs_utf_8_decode__doc__,
     470                 :            : "utf_8_decode($module, data, errors=None, final=False, /)\n"
     471                 :            : "--\n"
     472                 :            : "\n");
     473                 :            : 
     474                 :            : #define _CODECS_UTF_8_DECODE_METHODDEF    \
     475                 :            :     {"utf_8_decode", _PyCFunction_CAST(_codecs_utf_8_decode), METH_FASTCALL, _codecs_utf_8_decode__doc__},
     476                 :            : 
     477                 :            : static PyObject *
     478                 :            : _codecs_utf_8_decode_impl(PyObject *module, Py_buffer *data,
     479                 :            :                           const char *errors, int final);
     480                 :            : 
     481                 :            : static PyObject *
     482                 :       4094 : _codecs_utf_8_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     483                 :            : {
     484                 :       4094 :     PyObject *return_value = NULL;
     485                 :       4094 :     Py_buffer data = {NULL, NULL};
     486                 :       4094 :     const char *errors = NULL;
     487                 :       4094 :     int final = 0;
     488                 :            : 
     489   [ +  -  -  +  :       4094 :     if (!_PyArg_CheckPositional("utf_8_decode", nargs, 1, 3)) {
                   -  - ]
     490                 :          0 :         goto exit;
     491                 :            :     }
     492         [ -  + ]:       4094 :     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
     493                 :          0 :         goto exit;
     494                 :            :     }
     495         [ -  + ]:       4094 :     if (!PyBuffer_IsContiguous(&data, 'C')) {
     496                 :          0 :         _PyArg_BadArgument("utf_8_decode", "argument 1", "contiguous buffer", args[0]);
     497                 :          0 :         goto exit;
     498                 :            :     }
     499         [ -  + ]:       4094 :     if (nargs < 2) {
     500                 :          0 :         goto skip_optional;
     501                 :            :     }
     502         [ -  + ]:       4094 :     if (args[1] == Py_None) {
     503                 :          0 :         errors = NULL;
     504                 :            :     }
     505         [ +  - ]:       4094 :     else if (PyUnicode_Check(args[1])) {
     506                 :            :         Py_ssize_t errors_length;
     507                 :       4094 :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
     508         [ -  + ]:       4094 :         if (errors == NULL) {
     509                 :          0 :             goto exit;
     510                 :            :         }
     511         [ -  + ]:       4094 :         if (strlen(errors) != (size_t)errors_length) {
     512                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
     513                 :          0 :             goto exit;
     514                 :            :         }
     515                 :            :     }
     516                 :            :     else {
     517                 :          0 :         _PyArg_BadArgument("utf_8_decode", "argument 2", "str or None", args[1]);
     518                 :          0 :         goto exit;
     519                 :            :     }
     520         [ -  + ]:       4094 :     if (nargs < 3) {
     521                 :          0 :         goto skip_optional;
     522                 :            :     }
     523                 :       4094 :     final = PyObject_IsTrue(args[2]);
     524         [ -  + ]:       4094 :     if (final < 0) {
     525                 :          0 :         goto exit;
     526                 :            :     }
     527                 :       4094 : skip_optional:
     528                 :       4094 :     return_value = _codecs_utf_8_decode_impl(module, &data, errors, final);
     529                 :            : 
     530                 :       4094 : exit:
     531                 :            :     /* Cleanup for data */
     532         [ +  - ]:       4094 :     if (data.obj) {
     533                 :       4094 :        PyBuffer_Release(&data);
     534                 :            :     }
     535                 :            : 
     536                 :       4094 :     return return_value;
     537                 :            : }
     538                 :            : 
     539                 :            : PyDoc_STRVAR(_codecs_utf_16_decode__doc__,
     540                 :            : "utf_16_decode($module, data, errors=None, final=False, /)\n"
     541                 :            : "--\n"
     542                 :            : "\n");
     543                 :            : 
     544                 :            : #define _CODECS_UTF_16_DECODE_METHODDEF    \
     545                 :            :     {"utf_16_decode", _PyCFunction_CAST(_codecs_utf_16_decode), METH_FASTCALL, _codecs_utf_16_decode__doc__},
     546                 :            : 
     547                 :            : static PyObject *
     548                 :            : _codecs_utf_16_decode_impl(PyObject *module, Py_buffer *data,
     549                 :            :                            const char *errors, int final);
     550                 :            : 
     551                 :            : static PyObject *
     552                 :          0 : _codecs_utf_16_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     553                 :            : {
     554                 :          0 :     PyObject *return_value = NULL;
     555                 :          0 :     Py_buffer data = {NULL, NULL};
     556                 :          0 :     const char *errors = NULL;
     557                 :          0 :     int final = 0;
     558                 :            : 
     559   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("utf_16_decode", nargs, 1, 3)) {
                   #  # ]
     560                 :          0 :         goto exit;
     561                 :            :     }
     562         [ #  # ]:          0 :     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
     563                 :          0 :         goto exit;
     564                 :            :     }
     565         [ #  # ]:          0 :     if (!PyBuffer_IsContiguous(&data, 'C')) {
     566                 :          0 :         _PyArg_BadArgument("utf_16_decode", "argument 1", "contiguous buffer", args[0]);
     567                 :          0 :         goto exit;
     568                 :            :     }
     569         [ #  # ]:          0 :     if (nargs < 2) {
     570                 :          0 :         goto skip_optional;
     571                 :            :     }
     572         [ #  # ]:          0 :     if (args[1] == Py_None) {
     573                 :          0 :         errors = NULL;
     574                 :            :     }
     575         [ #  # ]:          0 :     else if (PyUnicode_Check(args[1])) {
     576                 :            :         Py_ssize_t errors_length;
     577                 :          0 :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
     578         [ #  # ]:          0 :         if (errors == NULL) {
     579                 :          0 :             goto exit;
     580                 :            :         }
     581         [ #  # ]:          0 :         if (strlen(errors) != (size_t)errors_length) {
     582                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
     583                 :          0 :             goto exit;
     584                 :            :         }
     585                 :            :     }
     586                 :            :     else {
     587                 :          0 :         _PyArg_BadArgument("utf_16_decode", "argument 2", "str or None", args[1]);
     588                 :          0 :         goto exit;
     589                 :            :     }
     590         [ #  # ]:          0 :     if (nargs < 3) {
     591                 :          0 :         goto skip_optional;
     592                 :            :     }
     593                 :          0 :     final = PyObject_IsTrue(args[2]);
     594         [ #  # ]:          0 :     if (final < 0) {
     595                 :          0 :         goto exit;
     596                 :            :     }
     597                 :          0 : skip_optional:
     598                 :          0 :     return_value = _codecs_utf_16_decode_impl(module, &data, errors, final);
     599                 :            : 
     600                 :          0 : exit:
     601                 :            :     /* Cleanup for data */
     602         [ #  # ]:          0 :     if (data.obj) {
     603                 :          0 :        PyBuffer_Release(&data);
     604                 :            :     }
     605                 :            : 
     606                 :          0 :     return return_value;
     607                 :            : }
     608                 :            : 
     609                 :            : PyDoc_STRVAR(_codecs_utf_16_le_decode__doc__,
     610                 :            : "utf_16_le_decode($module, data, errors=None, final=False, /)\n"
     611                 :            : "--\n"
     612                 :            : "\n");
     613                 :            : 
     614                 :            : #define _CODECS_UTF_16_LE_DECODE_METHODDEF    \
     615                 :            :     {"utf_16_le_decode", _PyCFunction_CAST(_codecs_utf_16_le_decode), METH_FASTCALL, _codecs_utf_16_le_decode__doc__},
     616                 :            : 
     617                 :            : static PyObject *
     618                 :            : _codecs_utf_16_le_decode_impl(PyObject *module, Py_buffer *data,
     619                 :            :                               const char *errors, int final);
     620                 :            : 
     621                 :            : static PyObject *
     622                 :          0 : _codecs_utf_16_le_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     623                 :            : {
     624                 :          0 :     PyObject *return_value = NULL;
     625                 :          0 :     Py_buffer data = {NULL, NULL};
     626                 :          0 :     const char *errors = NULL;
     627                 :          0 :     int final = 0;
     628                 :            : 
     629   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("utf_16_le_decode", nargs, 1, 3)) {
                   #  # ]
     630                 :          0 :         goto exit;
     631                 :            :     }
     632         [ #  # ]:          0 :     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
     633                 :          0 :         goto exit;
     634                 :            :     }
     635         [ #  # ]:          0 :     if (!PyBuffer_IsContiguous(&data, 'C')) {
     636                 :          0 :         _PyArg_BadArgument("utf_16_le_decode", "argument 1", "contiguous buffer", args[0]);
     637                 :          0 :         goto exit;
     638                 :            :     }
     639         [ #  # ]:          0 :     if (nargs < 2) {
     640                 :          0 :         goto skip_optional;
     641                 :            :     }
     642         [ #  # ]:          0 :     if (args[1] == Py_None) {
     643                 :          0 :         errors = NULL;
     644                 :            :     }
     645         [ #  # ]:          0 :     else if (PyUnicode_Check(args[1])) {
     646                 :            :         Py_ssize_t errors_length;
     647                 :          0 :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
     648         [ #  # ]:          0 :         if (errors == NULL) {
     649                 :          0 :             goto exit;
     650                 :            :         }
     651         [ #  # ]:          0 :         if (strlen(errors) != (size_t)errors_length) {
     652                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
     653                 :          0 :             goto exit;
     654                 :            :         }
     655                 :            :     }
     656                 :            :     else {
     657                 :          0 :         _PyArg_BadArgument("utf_16_le_decode", "argument 2", "str or None", args[1]);
     658                 :          0 :         goto exit;
     659                 :            :     }
     660         [ #  # ]:          0 :     if (nargs < 3) {
     661                 :          0 :         goto skip_optional;
     662                 :            :     }
     663                 :          0 :     final = PyObject_IsTrue(args[2]);
     664         [ #  # ]:          0 :     if (final < 0) {
     665                 :          0 :         goto exit;
     666                 :            :     }
     667                 :          0 : skip_optional:
     668                 :          0 :     return_value = _codecs_utf_16_le_decode_impl(module, &data, errors, final);
     669                 :            : 
     670                 :          0 : exit:
     671                 :            :     /* Cleanup for data */
     672         [ #  # ]:          0 :     if (data.obj) {
     673                 :          0 :        PyBuffer_Release(&data);
     674                 :            :     }
     675                 :            : 
     676                 :          0 :     return return_value;
     677                 :            : }
     678                 :            : 
     679                 :            : PyDoc_STRVAR(_codecs_utf_16_be_decode__doc__,
     680                 :            : "utf_16_be_decode($module, data, errors=None, final=False, /)\n"
     681                 :            : "--\n"
     682                 :            : "\n");
     683                 :            : 
     684                 :            : #define _CODECS_UTF_16_BE_DECODE_METHODDEF    \
     685                 :            :     {"utf_16_be_decode", _PyCFunction_CAST(_codecs_utf_16_be_decode), METH_FASTCALL, _codecs_utf_16_be_decode__doc__},
     686                 :            : 
     687                 :            : static PyObject *
     688                 :            : _codecs_utf_16_be_decode_impl(PyObject *module, Py_buffer *data,
     689                 :            :                               const char *errors, int final);
     690                 :            : 
     691                 :            : static PyObject *
     692                 :          0 : _codecs_utf_16_be_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     693                 :            : {
     694                 :          0 :     PyObject *return_value = NULL;
     695                 :          0 :     Py_buffer data = {NULL, NULL};
     696                 :          0 :     const char *errors = NULL;
     697                 :          0 :     int final = 0;
     698                 :            : 
     699   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("utf_16_be_decode", nargs, 1, 3)) {
                   #  # ]
     700                 :          0 :         goto exit;
     701                 :            :     }
     702         [ #  # ]:          0 :     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
     703                 :          0 :         goto exit;
     704                 :            :     }
     705         [ #  # ]:          0 :     if (!PyBuffer_IsContiguous(&data, 'C')) {
     706                 :          0 :         _PyArg_BadArgument("utf_16_be_decode", "argument 1", "contiguous buffer", args[0]);
     707                 :          0 :         goto exit;
     708                 :            :     }
     709         [ #  # ]:          0 :     if (nargs < 2) {
     710                 :          0 :         goto skip_optional;
     711                 :            :     }
     712         [ #  # ]:          0 :     if (args[1] == Py_None) {
     713                 :          0 :         errors = NULL;
     714                 :            :     }
     715         [ #  # ]:          0 :     else if (PyUnicode_Check(args[1])) {
     716                 :            :         Py_ssize_t errors_length;
     717                 :          0 :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
     718         [ #  # ]:          0 :         if (errors == NULL) {
     719                 :          0 :             goto exit;
     720                 :            :         }
     721         [ #  # ]:          0 :         if (strlen(errors) != (size_t)errors_length) {
     722                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
     723                 :          0 :             goto exit;
     724                 :            :         }
     725                 :            :     }
     726                 :            :     else {
     727                 :          0 :         _PyArg_BadArgument("utf_16_be_decode", "argument 2", "str or None", args[1]);
     728                 :          0 :         goto exit;
     729                 :            :     }
     730         [ #  # ]:          0 :     if (nargs < 3) {
     731                 :          0 :         goto skip_optional;
     732                 :            :     }
     733                 :          0 :     final = PyObject_IsTrue(args[2]);
     734         [ #  # ]:          0 :     if (final < 0) {
     735                 :          0 :         goto exit;
     736                 :            :     }
     737                 :          0 : skip_optional:
     738                 :          0 :     return_value = _codecs_utf_16_be_decode_impl(module, &data, errors, final);
     739                 :            : 
     740                 :          0 : exit:
     741                 :            :     /* Cleanup for data */
     742         [ #  # ]:          0 :     if (data.obj) {
     743                 :          0 :        PyBuffer_Release(&data);
     744                 :            :     }
     745                 :            : 
     746                 :          0 :     return return_value;
     747                 :            : }
     748                 :            : 
     749                 :            : PyDoc_STRVAR(_codecs_utf_16_ex_decode__doc__,
     750                 :            : "utf_16_ex_decode($module, data, errors=None, byteorder=0, final=False,\n"
     751                 :            : "                 /)\n"
     752                 :            : "--\n"
     753                 :            : "\n");
     754                 :            : 
     755                 :            : #define _CODECS_UTF_16_EX_DECODE_METHODDEF    \
     756                 :            :     {"utf_16_ex_decode", _PyCFunction_CAST(_codecs_utf_16_ex_decode), METH_FASTCALL, _codecs_utf_16_ex_decode__doc__},
     757                 :            : 
     758                 :            : static PyObject *
     759                 :            : _codecs_utf_16_ex_decode_impl(PyObject *module, Py_buffer *data,
     760                 :            :                               const char *errors, int byteorder, int final);
     761                 :            : 
     762                 :            : static PyObject *
     763                 :          0 : _codecs_utf_16_ex_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     764                 :            : {
     765                 :          0 :     PyObject *return_value = NULL;
     766                 :          0 :     Py_buffer data = {NULL, NULL};
     767                 :          0 :     const char *errors = NULL;
     768                 :          0 :     int byteorder = 0;
     769                 :          0 :     int final = 0;
     770                 :            : 
     771   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("utf_16_ex_decode", nargs, 1, 4)) {
                   #  # ]
     772                 :          0 :         goto exit;
     773                 :            :     }
     774         [ #  # ]:          0 :     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
     775                 :          0 :         goto exit;
     776                 :            :     }
     777         [ #  # ]:          0 :     if (!PyBuffer_IsContiguous(&data, 'C')) {
     778                 :          0 :         _PyArg_BadArgument("utf_16_ex_decode", "argument 1", "contiguous buffer", args[0]);
     779                 :          0 :         goto exit;
     780                 :            :     }
     781         [ #  # ]:          0 :     if (nargs < 2) {
     782                 :          0 :         goto skip_optional;
     783                 :            :     }
     784         [ #  # ]:          0 :     if (args[1] == Py_None) {
     785                 :          0 :         errors = NULL;
     786                 :            :     }
     787         [ #  # ]:          0 :     else if (PyUnicode_Check(args[1])) {
     788                 :            :         Py_ssize_t errors_length;
     789                 :          0 :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
     790         [ #  # ]:          0 :         if (errors == NULL) {
     791                 :          0 :             goto exit;
     792                 :            :         }
     793         [ #  # ]:          0 :         if (strlen(errors) != (size_t)errors_length) {
     794                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
     795                 :          0 :             goto exit;
     796                 :            :         }
     797                 :            :     }
     798                 :            :     else {
     799                 :          0 :         _PyArg_BadArgument("utf_16_ex_decode", "argument 2", "str or None", args[1]);
     800                 :          0 :         goto exit;
     801                 :            :     }
     802         [ #  # ]:          0 :     if (nargs < 3) {
     803                 :          0 :         goto skip_optional;
     804                 :            :     }
     805                 :          0 :     byteorder = _PyLong_AsInt(args[2]);
     806   [ #  #  #  # ]:          0 :     if (byteorder == -1 && PyErr_Occurred()) {
     807                 :          0 :         goto exit;
     808                 :            :     }
     809         [ #  # ]:          0 :     if (nargs < 4) {
     810                 :          0 :         goto skip_optional;
     811                 :            :     }
     812                 :          0 :     final = PyObject_IsTrue(args[3]);
     813         [ #  # ]:          0 :     if (final < 0) {
     814                 :          0 :         goto exit;
     815                 :            :     }
     816                 :          0 : skip_optional:
     817                 :          0 :     return_value = _codecs_utf_16_ex_decode_impl(module, &data, errors, byteorder, final);
     818                 :            : 
     819                 :          0 : exit:
     820                 :            :     /* Cleanup for data */
     821         [ #  # ]:          0 :     if (data.obj) {
     822                 :          0 :        PyBuffer_Release(&data);
     823                 :            :     }
     824                 :            : 
     825                 :          0 :     return return_value;
     826                 :            : }
     827                 :            : 
     828                 :            : PyDoc_STRVAR(_codecs_utf_32_decode__doc__,
     829                 :            : "utf_32_decode($module, data, errors=None, final=False, /)\n"
     830                 :            : "--\n"
     831                 :            : "\n");
     832                 :            : 
     833                 :            : #define _CODECS_UTF_32_DECODE_METHODDEF    \
     834                 :            :     {"utf_32_decode", _PyCFunction_CAST(_codecs_utf_32_decode), METH_FASTCALL, _codecs_utf_32_decode__doc__},
     835                 :            : 
     836                 :            : static PyObject *
     837                 :            : _codecs_utf_32_decode_impl(PyObject *module, Py_buffer *data,
     838                 :            :                            const char *errors, int final);
     839                 :            : 
     840                 :            : static PyObject *
     841                 :          0 : _codecs_utf_32_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     842                 :            : {
     843                 :          0 :     PyObject *return_value = NULL;
     844                 :          0 :     Py_buffer data = {NULL, NULL};
     845                 :          0 :     const char *errors = NULL;
     846                 :          0 :     int final = 0;
     847                 :            : 
     848   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("utf_32_decode", nargs, 1, 3)) {
                   #  # ]
     849                 :          0 :         goto exit;
     850                 :            :     }
     851         [ #  # ]:          0 :     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
     852                 :          0 :         goto exit;
     853                 :            :     }
     854         [ #  # ]:          0 :     if (!PyBuffer_IsContiguous(&data, 'C')) {
     855                 :          0 :         _PyArg_BadArgument("utf_32_decode", "argument 1", "contiguous buffer", args[0]);
     856                 :          0 :         goto exit;
     857                 :            :     }
     858         [ #  # ]:          0 :     if (nargs < 2) {
     859                 :          0 :         goto skip_optional;
     860                 :            :     }
     861         [ #  # ]:          0 :     if (args[1] == Py_None) {
     862                 :          0 :         errors = NULL;
     863                 :            :     }
     864         [ #  # ]:          0 :     else if (PyUnicode_Check(args[1])) {
     865                 :            :         Py_ssize_t errors_length;
     866                 :          0 :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
     867         [ #  # ]:          0 :         if (errors == NULL) {
     868                 :          0 :             goto exit;
     869                 :            :         }
     870         [ #  # ]:          0 :         if (strlen(errors) != (size_t)errors_length) {
     871                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
     872                 :          0 :             goto exit;
     873                 :            :         }
     874                 :            :     }
     875                 :            :     else {
     876                 :          0 :         _PyArg_BadArgument("utf_32_decode", "argument 2", "str or None", args[1]);
     877                 :          0 :         goto exit;
     878                 :            :     }
     879         [ #  # ]:          0 :     if (nargs < 3) {
     880                 :          0 :         goto skip_optional;
     881                 :            :     }
     882                 :          0 :     final = PyObject_IsTrue(args[2]);
     883         [ #  # ]:          0 :     if (final < 0) {
     884                 :          0 :         goto exit;
     885                 :            :     }
     886                 :          0 : skip_optional:
     887                 :          0 :     return_value = _codecs_utf_32_decode_impl(module, &data, errors, final);
     888                 :            : 
     889                 :          0 : exit:
     890                 :            :     /* Cleanup for data */
     891         [ #  # ]:          0 :     if (data.obj) {
     892                 :          0 :        PyBuffer_Release(&data);
     893                 :            :     }
     894                 :            : 
     895                 :          0 :     return return_value;
     896                 :            : }
     897                 :            : 
     898                 :            : PyDoc_STRVAR(_codecs_utf_32_le_decode__doc__,
     899                 :            : "utf_32_le_decode($module, data, errors=None, final=False, /)\n"
     900                 :            : "--\n"
     901                 :            : "\n");
     902                 :            : 
     903                 :            : #define _CODECS_UTF_32_LE_DECODE_METHODDEF    \
     904                 :            :     {"utf_32_le_decode", _PyCFunction_CAST(_codecs_utf_32_le_decode), METH_FASTCALL, _codecs_utf_32_le_decode__doc__},
     905                 :            : 
     906                 :            : static PyObject *
     907                 :            : _codecs_utf_32_le_decode_impl(PyObject *module, Py_buffer *data,
     908                 :            :                               const char *errors, int final);
     909                 :            : 
     910                 :            : static PyObject *
     911                 :          0 : _codecs_utf_32_le_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     912                 :            : {
     913                 :          0 :     PyObject *return_value = NULL;
     914                 :          0 :     Py_buffer data = {NULL, NULL};
     915                 :          0 :     const char *errors = NULL;
     916                 :          0 :     int final = 0;
     917                 :            : 
     918   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("utf_32_le_decode", nargs, 1, 3)) {
                   #  # ]
     919                 :          0 :         goto exit;
     920                 :            :     }
     921         [ #  # ]:          0 :     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
     922                 :          0 :         goto exit;
     923                 :            :     }
     924         [ #  # ]:          0 :     if (!PyBuffer_IsContiguous(&data, 'C')) {
     925                 :          0 :         _PyArg_BadArgument("utf_32_le_decode", "argument 1", "contiguous buffer", args[0]);
     926                 :          0 :         goto exit;
     927                 :            :     }
     928         [ #  # ]:          0 :     if (nargs < 2) {
     929                 :          0 :         goto skip_optional;
     930                 :            :     }
     931         [ #  # ]:          0 :     if (args[1] == Py_None) {
     932                 :          0 :         errors = NULL;
     933                 :            :     }
     934         [ #  # ]:          0 :     else if (PyUnicode_Check(args[1])) {
     935                 :            :         Py_ssize_t errors_length;
     936                 :          0 :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
     937         [ #  # ]:          0 :         if (errors == NULL) {
     938                 :          0 :             goto exit;
     939                 :            :         }
     940         [ #  # ]:          0 :         if (strlen(errors) != (size_t)errors_length) {
     941                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
     942                 :          0 :             goto exit;
     943                 :            :         }
     944                 :            :     }
     945                 :            :     else {
     946                 :          0 :         _PyArg_BadArgument("utf_32_le_decode", "argument 2", "str or None", args[1]);
     947                 :          0 :         goto exit;
     948                 :            :     }
     949         [ #  # ]:          0 :     if (nargs < 3) {
     950                 :          0 :         goto skip_optional;
     951                 :            :     }
     952                 :          0 :     final = PyObject_IsTrue(args[2]);
     953         [ #  # ]:          0 :     if (final < 0) {
     954                 :          0 :         goto exit;
     955                 :            :     }
     956                 :          0 : skip_optional:
     957                 :          0 :     return_value = _codecs_utf_32_le_decode_impl(module, &data, errors, final);
     958                 :            : 
     959                 :          0 : exit:
     960                 :            :     /* Cleanup for data */
     961         [ #  # ]:          0 :     if (data.obj) {
     962                 :          0 :        PyBuffer_Release(&data);
     963                 :            :     }
     964                 :            : 
     965                 :          0 :     return return_value;
     966                 :            : }
     967                 :            : 
     968                 :            : PyDoc_STRVAR(_codecs_utf_32_be_decode__doc__,
     969                 :            : "utf_32_be_decode($module, data, errors=None, final=False, /)\n"
     970                 :            : "--\n"
     971                 :            : "\n");
     972                 :            : 
     973                 :            : #define _CODECS_UTF_32_BE_DECODE_METHODDEF    \
     974                 :            :     {"utf_32_be_decode", _PyCFunction_CAST(_codecs_utf_32_be_decode), METH_FASTCALL, _codecs_utf_32_be_decode__doc__},
     975                 :            : 
     976                 :            : static PyObject *
     977                 :            : _codecs_utf_32_be_decode_impl(PyObject *module, Py_buffer *data,
     978                 :            :                               const char *errors, int final);
     979                 :            : 
     980                 :            : static PyObject *
     981                 :          0 : _codecs_utf_32_be_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     982                 :            : {
     983                 :          0 :     PyObject *return_value = NULL;
     984                 :          0 :     Py_buffer data = {NULL, NULL};
     985                 :          0 :     const char *errors = NULL;
     986                 :          0 :     int final = 0;
     987                 :            : 
     988   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("utf_32_be_decode", nargs, 1, 3)) {
                   #  # ]
     989                 :          0 :         goto exit;
     990                 :            :     }
     991         [ #  # ]:          0 :     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
     992                 :          0 :         goto exit;
     993                 :            :     }
     994         [ #  # ]:          0 :     if (!PyBuffer_IsContiguous(&data, 'C')) {
     995                 :          0 :         _PyArg_BadArgument("utf_32_be_decode", "argument 1", "contiguous buffer", args[0]);
     996                 :          0 :         goto exit;
     997                 :            :     }
     998         [ #  # ]:          0 :     if (nargs < 2) {
     999                 :          0 :         goto skip_optional;
    1000                 :            :     }
    1001         [ #  # ]:          0 :     if (args[1] == Py_None) {
    1002                 :          0 :         errors = NULL;
    1003                 :            :     }
    1004         [ #  # ]:          0 :     else if (PyUnicode_Check(args[1])) {
    1005                 :            :         Py_ssize_t errors_length;
    1006                 :          0 :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
    1007         [ #  # ]:          0 :         if (errors == NULL) {
    1008                 :          0 :             goto exit;
    1009                 :            :         }
    1010         [ #  # ]:          0 :         if (strlen(errors) != (size_t)errors_length) {
    1011                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
    1012                 :          0 :             goto exit;
    1013                 :            :         }
    1014                 :            :     }
    1015                 :            :     else {
    1016                 :          0 :         _PyArg_BadArgument("utf_32_be_decode", "argument 2", "str or None", args[1]);
    1017                 :          0 :         goto exit;
    1018                 :            :     }
    1019         [ #  # ]:          0 :     if (nargs < 3) {
    1020                 :          0 :         goto skip_optional;
    1021                 :            :     }
    1022                 :          0 :     final = PyObject_IsTrue(args[2]);
    1023         [ #  # ]:          0 :     if (final < 0) {
    1024                 :          0 :         goto exit;
    1025                 :            :     }
    1026                 :          0 : skip_optional:
    1027                 :          0 :     return_value = _codecs_utf_32_be_decode_impl(module, &data, errors, final);
    1028                 :            : 
    1029                 :          0 : exit:
    1030                 :            :     /* Cleanup for data */
    1031         [ #  # ]:          0 :     if (data.obj) {
    1032                 :          0 :        PyBuffer_Release(&data);
    1033                 :            :     }
    1034                 :            : 
    1035                 :          0 :     return return_value;
    1036                 :            : }
    1037                 :            : 
    1038                 :            : PyDoc_STRVAR(_codecs_utf_32_ex_decode__doc__,
    1039                 :            : "utf_32_ex_decode($module, data, errors=None, byteorder=0, final=False,\n"
    1040                 :            : "                 /)\n"
    1041                 :            : "--\n"
    1042                 :            : "\n");
    1043                 :            : 
    1044                 :            : #define _CODECS_UTF_32_EX_DECODE_METHODDEF    \
    1045                 :            :     {"utf_32_ex_decode", _PyCFunction_CAST(_codecs_utf_32_ex_decode), METH_FASTCALL, _codecs_utf_32_ex_decode__doc__},
    1046                 :            : 
    1047                 :            : static PyObject *
    1048                 :            : _codecs_utf_32_ex_decode_impl(PyObject *module, Py_buffer *data,
    1049                 :            :                               const char *errors, int byteorder, int final);
    1050                 :            : 
    1051                 :            : static PyObject *
    1052                 :          0 : _codecs_utf_32_ex_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
    1053                 :            : {
    1054                 :          0 :     PyObject *return_value = NULL;
    1055                 :          0 :     Py_buffer data = {NULL, NULL};
    1056                 :          0 :     const char *errors = NULL;
    1057                 :          0 :     int byteorder = 0;
    1058                 :          0 :     int final = 0;
    1059                 :            : 
    1060   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("utf_32_ex_decode", nargs, 1, 4)) {
                   #  # ]
    1061                 :          0 :         goto exit;
    1062                 :            :     }
    1063         [ #  # ]:          0 :     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
    1064                 :          0 :         goto exit;
    1065                 :            :     }
    1066         [ #  # ]:          0 :     if (!PyBuffer_IsContiguous(&data, 'C')) {
    1067                 :          0 :         _PyArg_BadArgument("utf_32_ex_decode", "argument 1", "contiguous buffer", args[0]);
    1068                 :          0 :         goto exit;
    1069                 :            :     }
    1070         [ #  # ]:          0 :     if (nargs < 2) {
    1071                 :          0 :         goto skip_optional;
    1072                 :            :     }
    1073         [ #  # ]:          0 :     if (args[1] == Py_None) {
    1074                 :          0 :         errors = NULL;
    1075                 :            :     }
    1076         [ #  # ]:          0 :     else if (PyUnicode_Check(args[1])) {
    1077                 :            :         Py_ssize_t errors_length;
    1078                 :          0 :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
    1079         [ #  # ]:          0 :         if (errors == NULL) {
    1080                 :          0 :             goto exit;
    1081                 :            :         }
    1082         [ #  # ]:          0 :         if (strlen(errors) != (size_t)errors_length) {
    1083                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
    1084                 :          0 :             goto exit;
    1085                 :            :         }
    1086                 :            :     }
    1087                 :            :     else {
    1088                 :          0 :         _PyArg_BadArgument("utf_32_ex_decode", "argument 2", "str or None", args[1]);
    1089                 :          0 :         goto exit;
    1090                 :            :     }
    1091         [ #  # ]:          0 :     if (nargs < 3) {
    1092                 :          0 :         goto skip_optional;
    1093                 :            :     }
    1094                 :          0 :     byteorder = _PyLong_AsInt(args[2]);
    1095   [ #  #  #  # ]:          0 :     if (byteorder == -1 && PyErr_Occurred()) {
    1096                 :          0 :         goto exit;
    1097                 :            :     }
    1098         [ #  # ]:          0 :     if (nargs < 4) {
    1099                 :          0 :         goto skip_optional;
    1100                 :            :     }
    1101                 :          0 :     final = PyObject_IsTrue(args[3]);
    1102         [ #  # ]:          0 :     if (final < 0) {
    1103                 :          0 :         goto exit;
    1104                 :            :     }
    1105                 :          0 : skip_optional:
    1106                 :          0 :     return_value = _codecs_utf_32_ex_decode_impl(module, &data, errors, byteorder, final);
    1107                 :            : 
    1108                 :          0 : exit:
    1109                 :            :     /* Cleanup for data */
    1110         [ #  # ]:          0 :     if (data.obj) {
    1111                 :          0 :        PyBuffer_Release(&data);
    1112                 :            :     }
    1113                 :            : 
    1114                 :          0 :     return return_value;
    1115                 :            : }
    1116                 :            : 
    1117                 :            : PyDoc_STRVAR(_codecs_unicode_escape_decode__doc__,
    1118                 :            : "unicode_escape_decode($module, data, errors=None, final=True, /)\n"
    1119                 :            : "--\n"
    1120                 :            : "\n");
    1121                 :            : 
    1122                 :            : #define _CODECS_UNICODE_ESCAPE_DECODE_METHODDEF    \
    1123                 :            :     {"unicode_escape_decode", _PyCFunction_CAST(_codecs_unicode_escape_decode), METH_FASTCALL, _codecs_unicode_escape_decode__doc__},
    1124                 :            : 
    1125                 :            : static PyObject *
    1126                 :            : _codecs_unicode_escape_decode_impl(PyObject *module, Py_buffer *data,
    1127                 :            :                                    const char *errors, int final);
    1128                 :            : 
    1129                 :            : static PyObject *
    1130                 :          0 : _codecs_unicode_escape_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
    1131                 :            : {
    1132                 :          0 :     PyObject *return_value = NULL;
    1133                 :          0 :     Py_buffer data = {NULL, NULL};
    1134                 :          0 :     const char *errors = NULL;
    1135                 :          0 :     int final = 1;
    1136                 :            : 
    1137   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("unicode_escape_decode", nargs, 1, 3)) {
                   #  # ]
    1138                 :          0 :         goto exit;
    1139                 :            :     }
    1140         [ #  # ]:          0 :     if (PyUnicode_Check(args[0])) {
    1141                 :            :         Py_ssize_t len;
    1142                 :          0 :         const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
    1143         [ #  # ]:          0 :         if (ptr == NULL) {
    1144                 :          0 :             goto exit;
    1145                 :            :         }
    1146                 :          0 :         PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, 0);
    1147                 :            :     }
    1148                 :            :     else { /* any bytes-like object */
    1149         [ #  # ]:          0 :         if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
    1150                 :          0 :             goto exit;
    1151                 :            :         }
    1152         [ #  # ]:          0 :         if (!PyBuffer_IsContiguous(&data, 'C')) {
    1153                 :          0 :             _PyArg_BadArgument("unicode_escape_decode", "argument 1", "contiguous buffer", args[0]);
    1154                 :          0 :             goto exit;
    1155                 :            :         }
    1156                 :            :     }
    1157         [ #  # ]:          0 :     if (nargs < 2) {
    1158                 :          0 :         goto skip_optional;
    1159                 :            :     }
    1160         [ #  # ]:          0 :     if (args[1] == Py_None) {
    1161                 :          0 :         errors = NULL;
    1162                 :            :     }
    1163         [ #  # ]:          0 :     else if (PyUnicode_Check(args[1])) {
    1164                 :            :         Py_ssize_t errors_length;
    1165                 :          0 :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
    1166         [ #  # ]:          0 :         if (errors == NULL) {
    1167                 :          0 :             goto exit;
    1168                 :            :         }
    1169         [ #  # ]:          0 :         if (strlen(errors) != (size_t)errors_length) {
    1170                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
    1171                 :          0 :             goto exit;
    1172                 :            :         }
    1173                 :            :     }
    1174                 :            :     else {
    1175                 :          0 :         _PyArg_BadArgument("unicode_escape_decode", "argument 2", "str or None", args[1]);
    1176                 :          0 :         goto exit;
    1177                 :            :     }
    1178         [ #  # ]:          0 :     if (nargs < 3) {
    1179                 :          0 :         goto skip_optional;
    1180                 :            :     }
    1181                 :          0 :     final = PyObject_IsTrue(args[2]);
    1182         [ #  # ]:          0 :     if (final < 0) {
    1183                 :          0 :         goto exit;
    1184                 :            :     }
    1185                 :          0 : skip_optional:
    1186                 :          0 :     return_value = _codecs_unicode_escape_decode_impl(module, &data, errors, final);
    1187                 :            : 
    1188                 :          0 : exit:
    1189                 :            :     /* Cleanup for data */
    1190         [ #  # ]:          0 :     if (data.obj) {
    1191                 :          0 :        PyBuffer_Release(&data);
    1192                 :            :     }
    1193                 :            : 
    1194                 :          0 :     return return_value;
    1195                 :            : }
    1196                 :            : 
    1197                 :            : PyDoc_STRVAR(_codecs_raw_unicode_escape_decode__doc__,
    1198                 :            : "raw_unicode_escape_decode($module, data, errors=None, final=True, /)\n"
    1199                 :            : "--\n"
    1200                 :            : "\n");
    1201                 :            : 
    1202                 :            : #define _CODECS_RAW_UNICODE_ESCAPE_DECODE_METHODDEF    \
    1203                 :            :     {"raw_unicode_escape_decode", _PyCFunction_CAST(_codecs_raw_unicode_escape_decode), METH_FASTCALL, _codecs_raw_unicode_escape_decode__doc__},
    1204                 :            : 
    1205                 :            : static PyObject *
    1206                 :            : _codecs_raw_unicode_escape_decode_impl(PyObject *module, Py_buffer *data,
    1207                 :            :                                        const char *errors, int final);
    1208                 :            : 
    1209                 :            : static PyObject *
    1210                 :          0 : _codecs_raw_unicode_escape_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
    1211                 :            : {
    1212                 :          0 :     PyObject *return_value = NULL;
    1213                 :          0 :     Py_buffer data = {NULL, NULL};
    1214                 :          0 :     const char *errors = NULL;
    1215                 :          0 :     int final = 1;
    1216                 :            : 
    1217   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("raw_unicode_escape_decode", nargs, 1, 3)) {
                   #  # ]
    1218                 :          0 :         goto exit;
    1219                 :            :     }
    1220         [ #  # ]:          0 :     if (PyUnicode_Check(args[0])) {
    1221                 :            :         Py_ssize_t len;
    1222                 :          0 :         const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
    1223         [ #  # ]:          0 :         if (ptr == NULL) {
    1224                 :          0 :             goto exit;
    1225                 :            :         }
    1226                 :          0 :         PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, 0);
    1227                 :            :     }
    1228                 :            :     else { /* any bytes-like object */
    1229         [ #  # ]:          0 :         if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
    1230                 :          0 :             goto exit;
    1231                 :            :         }
    1232         [ #  # ]:          0 :         if (!PyBuffer_IsContiguous(&data, 'C')) {
    1233                 :          0 :             _PyArg_BadArgument("raw_unicode_escape_decode", "argument 1", "contiguous buffer", args[0]);
    1234                 :          0 :             goto exit;
    1235                 :            :         }
    1236                 :            :     }
    1237         [ #  # ]:          0 :     if (nargs < 2) {
    1238                 :          0 :         goto skip_optional;
    1239                 :            :     }
    1240         [ #  # ]:          0 :     if (args[1] == Py_None) {
    1241                 :          0 :         errors = NULL;
    1242                 :            :     }
    1243         [ #  # ]:          0 :     else if (PyUnicode_Check(args[1])) {
    1244                 :            :         Py_ssize_t errors_length;
    1245                 :          0 :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
    1246         [ #  # ]:          0 :         if (errors == NULL) {
    1247                 :          0 :             goto exit;
    1248                 :            :         }
    1249         [ #  # ]:          0 :         if (strlen(errors) != (size_t)errors_length) {
    1250                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
    1251                 :          0 :             goto exit;
    1252                 :            :         }
    1253                 :            :     }
    1254                 :            :     else {
    1255                 :          0 :         _PyArg_BadArgument("raw_unicode_escape_decode", "argument 2", "str or None", args[1]);
    1256                 :          0 :         goto exit;
    1257                 :            :     }
    1258         [ #  # ]:          0 :     if (nargs < 3) {
    1259                 :          0 :         goto skip_optional;
    1260                 :            :     }
    1261                 :          0 :     final = PyObject_IsTrue(args[2]);
    1262         [ #  # ]:          0 :     if (final < 0) {
    1263                 :          0 :         goto exit;
    1264                 :            :     }
    1265                 :          0 : skip_optional:
    1266                 :          0 :     return_value = _codecs_raw_unicode_escape_decode_impl(module, &data, errors, final);
    1267                 :            : 
    1268                 :          0 : exit:
    1269                 :            :     /* Cleanup for data */
    1270         [ #  # ]:          0 :     if (data.obj) {
    1271                 :          0 :        PyBuffer_Release(&data);
    1272                 :            :     }
    1273                 :            : 
    1274                 :          0 :     return return_value;
    1275                 :            : }
    1276                 :            : 
    1277                 :            : PyDoc_STRVAR(_codecs_latin_1_decode__doc__,
    1278                 :            : "latin_1_decode($module, data, errors=None, /)\n"
    1279                 :            : "--\n"
    1280                 :            : "\n");
    1281                 :            : 
    1282                 :            : #define _CODECS_LATIN_1_DECODE_METHODDEF    \
    1283                 :            :     {"latin_1_decode", _PyCFunction_CAST(_codecs_latin_1_decode), METH_FASTCALL, _codecs_latin_1_decode__doc__},
    1284                 :            : 
    1285                 :            : static PyObject *
    1286                 :            : _codecs_latin_1_decode_impl(PyObject *module, Py_buffer *data,
    1287                 :            :                             const char *errors);
    1288                 :            : 
    1289                 :            : static PyObject *
    1290                 :          0 : _codecs_latin_1_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
    1291                 :            : {
    1292                 :          0 :     PyObject *return_value = NULL;
    1293                 :          0 :     Py_buffer data = {NULL, NULL};
    1294                 :          0 :     const char *errors = NULL;
    1295                 :            : 
    1296   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("latin_1_decode", nargs, 1, 2)) {
                   #  # ]
    1297                 :          0 :         goto exit;
    1298                 :            :     }
    1299         [ #  # ]:          0 :     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
    1300                 :          0 :         goto exit;
    1301                 :            :     }
    1302         [ #  # ]:          0 :     if (!PyBuffer_IsContiguous(&data, 'C')) {
    1303                 :          0 :         _PyArg_BadArgument("latin_1_decode", "argument 1", "contiguous buffer", args[0]);
    1304                 :          0 :         goto exit;
    1305                 :            :     }
    1306         [ #  # ]:          0 :     if (nargs < 2) {
    1307                 :          0 :         goto skip_optional;
    1308                 :            :     }
    1309         [ #  # ]:          0 :     if (args[1] == Py_None) {
    1310                 :          0 :         errors = NULL;
    1311                 :            :     }
    1312         [ #  # ]:          0 :     else if (PyUnicode_Check(args[1])) {
    1313                 :            :         Py_ssize_t errors_length;
    1314                 :          0 :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
    1315         [ #  # ]:          0 :         if (errors == NULL) {
    1316                 :          0 :             goto exit;
    1317                 :            :         }
    1318         [ #  # ]:          0 :         if (strlen(errors) != (size_t)errors_length) {
    1319                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
    1320                 :          0 :             goto exit;
    1321                 :            :         }
    1322                 :            :     }
    1323                 :            :     else {
    1324                 :          0 :         _PyArg_BadArgument("latin_1_decode", "argument 2", "str or None", args[1]);
    1325                 :          0 :         goto exit;
    1326                 :            :     }
    1327                 :          0 : skip_optional:
    1328                 :          0 :     return_value = _codecs_latin_1_decode_impl(module, &data, errors);
    1329                 :            : 
    1330                 :          0 : exit:
    1331                 :            :     /* Cleanup for data */
    1332         [ #  # ]:          0 :     if (data.obj) {
    1333                 :          0 :        PyBuffer_Release(&data);
    1334                 :            :     }
    1335                 :            : 
    1336                 :          0 :     return return_value;
    1337                 :            : }
    1338                 :            : 
    1339                 :            : PyDoc_STRVAR(_codecs_ascii_decode__doc__,
    1340                 :            : "ascii_decode($module, data, errors=None, /)\n"
    1341                 :            : "--\n"
    1342                 :            : "\n");
    1343                 :            : 
    1344                 :            : #define _CODECS_ASCII_DECODE_METHODDEF    \
    1345                 :            :     {"ascii_decode", _PyCFunction_CAST(_codecs_ascii_decode), METH_FASTCALL, _codecs_ascii_decode__doc__},
    1346                 :            : 
    1347                 :            : static PyObject *
    1348                 :            : _codecs_ascii_decode_impl(PyObject *module, Py_buffer *data,
    1349                 :            :                           const char *errors);
    1350                 :            : 
    1351                 :            : static PyObject *
    1352                 :          0 : _codecs_ascii_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
    1353                 :            : {
    1354                 :          0 :     PyObject *return_value = NULL;
    1355                 :          0 :     Py_buffer data = {NULL, NULL};
    1356                 :          0 :     const char *errors = NULL;
    1357                 :            : 
    1358   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("ascii_decode", nargs, 1, 2)) {
                   #  # ]
    1359                 :          0 :         goto exit;
    1360                 :            :     }
    1361         [ #  # ]:          0 :     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
    1362                 :          0 :         goto exit;
    1363                 :            :     }
    1364         [ #  # ]:          0 :     if (!PyBuffer_IsContiguous(&data, 'C')) {
    1365                 :          0 :         _PyArg_BadArgument("ascii_decode", "argument 1", "contiguous buffer", args[0]);
    1366                 :          0 :         goto exit;
    1367                 :            :     }
    1368         [ #  # ]:          0 :     if (nargs < 2) {
    1369                 :          0 :         goto skip_optional;
    1370                 :            :     }
    1371         [ #  # ]:          0 :     if (args[1] == Py_None) {
    1372                 :          0 :         errors = NULL;
    1373                 :            :     }
    1374         [ #  # ]:          0 :     else if (PyUnicode_Check(args[1])) {
    1375                 :            :         Py_ssize_t errors_length;
    1376                 :          0 :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
    1377         [ #  # ]:          0 :         if (errors == NULL) {
    1378                 :          0 :             goto exit;
    1379                 :            :         }
    1380         [ #  # ]:          0 :         if (strlen(errors) != (size_t)errors_length) {
    1381                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
    1382                 :          0 :             goto exit;
    1383                 :            :         }
    1384                 :            :     }
    1385                 :            :     else {
    1386                 :          0 :         _PyArg_BadArgument("ascii_decode", "argument 2", "str or None", args[1]);
    1387                 :          0 :         goto exit;
    1388                 :            :     }
    1389                 :          0 : skip_optional:
    1390                 :          0 :     return_value = _codecs_ascii_decode_impl(module, &data, errors);
    1391                 :            : 
    1392                 :          0 : exit:
    1393                 :            :     /* Cleanup for data */
    1394         [ #  # ]:          0 :     if (data.obj) {
    1395                 :          0 :        PyBuffer_Release(&data);
    1396                 :            :     }
    1397                 :            : 
    1398                 :          0 :     return return_value;
    1399                 :            : }
    1400                 :            : 
    1401                 :            : PyDoc_STRVAR(_codecs_charmap_decode__doc__,
    1402                 :            : "charmap_decode($module, data, errors=None, mapping=None, /)\n"
    1403                 :            : "--\n"
    1404                 :            : "\n");
    1405                 :            : 
    1406                 :            : #define _CODECS_CHARMAP_DECODE_METHODDEF    \
    1407                 :            :     {"charmap_decode", _PyCFunction_CAST(_codecs_charmap_decode), METH_FASTCALL, _codecs_charmap_decode__doc__},
    1408                 :            : 
    1409                 :            : static PyObject *
    1410                 :            : _codecs_charmap_decode_impl(PyObject *module, Py_buffer *data,
    1411                 :            :                             const char *errors, PyObject *mapping);
    1412                 :            : 
    1413                 :            : static PyObject *
    1414                 :          0 : _codecs_charmap_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
    1415                 :            : {
    1416                 :          0 :     PyObject *return_value = NULL;
    1417                 :          0 :     Py_buffer data = {NULL, NULL};
    1418                 :          0 :     const char *errors = NULL;
    1419                 :          0 :     PyObject *mapping = Py_None;
    1420                 :            : 
    1421   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("charmap_decode", nargs, 1, 3)) {
                   #  # ]
    1422                 :          0 :         goto exit;
    1423                 :            :     }
    1424         [ #  # ]:          0 :     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
    1425                 :          0 :         goto exit;
    1426                 :            :     }
    1427         [ #  # ]:          0 :     if (!PyBuffer_IsContiguous(&data, 'C')) {
    1428                 :          0 :         _PyArg_BadArgument("charmap_decode", "argument 1", "contiguous buffer", args[0]);
    1429                 :          0 :         goto exit;
    1430                 :            :     }
    1431         [ #  # ]:          0 :     if (nargs < 2) {
    1432                 :          0 :         goto skip_optional;
    1433                 :            :     }
    1434         [ #  # ]:          0 :     if (args[1] == Py_None) {
    1435                 :          0 :         errors = NULL;
    1436                 :            :     }
    1437         [ #  # ]:          0 :     else if (PyUnicode_Check(args[1])) {
    1438                 :            :         Py_ssize_t errors_length;
    1439                 :          0 :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
    1440         [ #  # ]:          0 :         if (errors == NULL) {
    1441                 :          0 :             goto exit;
    1442                 :            :         }
    1443         [ #  # ]:          0 :         if (strlen(errors) != (size_t)errors_length) {
    1444                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
    1445                 :          0 :             goto exit;
    1446                 :            :         }
    1447                 :            :     }
    1448                 :            :     else {
    1449                 :          0 :         _PyArg_BadArgument("charmap_decode", "argument 2", "str or None", args[1]);
    1450                 :          0 :         goto exit;
    1451                 :            :     }
    1452         [ #  # ]:          0 :     if (nargs < 3) {
    1453                 :          0 :         goto skip_optional;
    1454                 :            :     }
    1455                 :          0 :     mapping = args[2];
    1456                 :          0 : skip_optional:
    1457                 :          0 :     return_value = _codecs_charmap_decode_impl(module, &data, errors, mapping);
    1458                 :            : 
    1459                 :          0 : exit:
    1460                 :            :     /* Cleanup for data */
    1461         [ #  # ]:          0 :     if (data.obj) {
    1462                 :          0 :        PyBuffer_Release(&data);
    1463                 :            :     }
    1464                 :            : 
    1465                 :          0 :     return return_value;
    1466                 :            : }
    1467                 :            : 
    1468                 :            : #if defined(MS_WINDOWS)
    1469                 :            : 
    1470                 :            : PyDoc_STRVAR(_codecs_mbcs_decode__doc__,
    1471                 :            : "mbcs_decode($module, data, errors=None, final=False, /)\n"
    1472                 :            : "--\n"
    1473                 :            : "\n");
    1474                 :            : 
    1475                 :            : #define _CODECS_MBCS_DECODE_METHODDEF    \
    1476                 :            :     {"mbcs_decode", _PyCFunction_CAST(_codecs_mbcs_decode), METH_FASTCALL, _codecs_mbcs_decode__doc__},
    1477                 :            : 
    1478                 :            : static PyObject *
    1479                 :            : _codecs_mbcs_decode_impl(PyObject *module, Py_buffer *data,
    1480                 :            :                          const char *errors, int final);
    1481                 :            : 
    1482                 :            : static PyObject *
    1483                 :            : _codecs_mbcs_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
    1484                 :            : {
    1485                 :            :     PyObject *return_value = NULL;
    1486                 :            :     Py_buffer data = {NULL, NULL};
    1487                 :            :     const char *errors = NULL;
    1488                 :            :     int final = 0;
    1489                 :            : 
    1490                 :            :     if (!_PyArg_CheckPositional("mbcs_decode", nargs, 1, 3)) {
    1491                 :            :         goto exit;
    1492                 :            :     }
    1493                 :            :     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
    1494                 :            :         goto exit;
    1495                 :            :     }
    1496                 :            :     if (!PyBuffer_IsContiguous(&data, 'C')) {
    1497                 :            :         _PyArg_BadArgument("mbcs_decode", "argument 1", "contiguous buffer", args[0]);
    1498                 :            :         goto exit;
    1499                 :            :     }
    1500                 :            :     if (nargs < 2) {
    1501                 :            :         goto skip_optional;
    1502                 :            :     }
    1503                 :            :     if (args[1] == Py_None) {
    1504                 :            :         errors = NULL;
    1505                 :            :     }
    1506                 :            :     else if (PyUnicode_Check(args[1])) {
    1507                 :            :         Py_ssize_t errors_length;
    1508                 :            :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
    1509                 :            :         if (errors == NULL) {
    1510                 :            :             goto exit;
    1511                 :            :         }
    1512                 :            :         if (strlen(errors) != (size_t)errors_length) {
    1513                 :            :             PyErr_SetString(PyExc_ValueError, "embedded null character");
    1514                 :            :             goto exit;
    1515                 :            :         }
    1516                 :            :     }
    1517                 :            :     else {
    1518                 :            :         _PyArg_BadArgument("mbcs_decode", "argument 2", "str or None", args[1]);
    1519                 :            :         goto exit;
    1520                 :            :     }
    1521                 :            :     if (nargs < 3) {
    1522                 :            :         goto skip_optional;
    1523                 :            :     }
    1524                 :            :     final = PyObject_IsTrue(args[2]);
    1525                 :            :     if (final < 0) {
    1526                 :            :         goto exit;
    1527                 :            :     }
    1528                 :            : skip_optional:
    1529                 :            :     return_value = _codecs_mbcs_decode_impl(module, &data, errors, final);
    1530                 :            : 
    1531                 :            : exit:
    1532                 :            :     /* Cleanup for data */
    1533                 :            :     if (data.obj) {
    1534                 :            :        PyBuffer_Release(&data);
    1535                 :            :     }
    1536                 :            : 
    1537                 :            :     return return_value;
    1538                 :            : }
    1539                 :            : 
    1540                 :            : #endif /* defined(MS_WINDOWS) */
    1541                 :            : 
    1542                 :            : #if defined(MS_WINDOWS)
    1543                 :            : 
    1544                 :            : PyDoc_STRVAR(_codecs_oem_decode__doc__,
    1545                 :            : "oem_decode($module, data, errors=None, final=False, /)\n"
    1546                 :            : "--\n"
    1547                 :            : "\n");
    1548                 :            : 
    1549                 :            : #define _CODECS_OEM_DECODE_METHODDEF    \
    1550                 :            :     {"oem_decode", _PyCFunction_CAST(_codecs_oem_decode), METH_FASTCALL, _codecs_oem_decode__doc__},
    1551                 :            : 
    1552                 :            : static PyObject *
    1553                 :            : _codecs_oem_decode_impl(PyObject *module, Py_buffer *data,
    1554                 :            :                         const char *errors, int final);
    1555                 :            : 
    1556                 :            : static PyObject *
    1557                 :            : _codecs_oem_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
    1558                 :            : {
    1559                 :            :     PyObject *return_value = NULL;
    1560                 :            :     Py_buffer data = {NULL, NULL};
    1561                 :            :     const char *errors = NULL;
    1562                 :            :     int final = 0;
    1563                 :            : 
    1564                 :            :     if (!_PyArg_CheckPositional("oem_decode", nargs, 1, 3)) {
    1565                 :            :         goto exit;
    1566                 :            :     }
    1567                 :            :     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
    1568                 :            :         goto exit;
    1569                 :            :     }
    1570                 :            :     if (!PyBuffer_IsContiguous(&data, 'C')) {
    1571                 :            :         _PyArg_BadArgument("oem_decode", "argument 1", "contiguous buffer", args[0]);
    1572                 :            :         goto exit;
    1573                 :            :     }
    1574                 :            :     if (nargs < 2) {
    1575                 :            :         goto skip_optional;
    1576                 :            :     }
    1577                 :            :     if (args[1] == Py_None) {
    1578                 :            :         errors = NULL;
    1579                 :            :     }
    1580                 :            :     else if (PyUnicode_Check(args[1])) {
    1581                 :            :         Py_ssize_t errors_length;
    1582                 :            :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
    1583                 :            :         if (errors == NULL) {
    1584                 :            :             goto exit;
    1585                 :            :         }
    1586                 :            :         if (strlen(errors) != (size_t)errors_length) {
    1587                 :            :             PyErr_SetString(PyExc_ValueError, "embedded null character");
    1588                 :            :             goto exit;
    1589                 :            :         }
    1590                 :            :     }
    1591                 :            :     else {
    1592                 :            :         _PyArg_BadArgument("oem_decode", "argument 2", "str or None", args[1]);
    1593                 :            :         goto exit;
    1594                 :            :     }
    1595                 :            :     if (nargs < 3) {
    1596                 :            :         goto skip_optional;
    1597                 :            :     }
    1598                 :            :     final = PyObject_IsTrue(args[2]);
    1599                 :            :     if (final < 0) {
    1600                 :            :         goto exit;
    1601                 :            :     }
    1602                 :            : skip_optional:
    1603                 :            :     return_value = _codecs_oem_decode_impl(module, &data, errors, final);
    1604                 :            : 
    1605                 :            : exit:
    1606                 :            :     /* Cleanup for data */
    1607                 :            :     if (data.obj) {
    1608                 :            :        PyBuffer_Release(&data);
    1609                 :            :     }
    1610                 :            : 
    1611                 :            :     return return_value;
    1612                 :            : }
    1613                 :            : 
    1614                 :            : #endif /* defined(MS_WINDOWS) */
    1615                 :            : 
    1616                 :            : #if defined(MS_WINDOWS)
    1617                 :            : 
    1618                 :            : PyDoc_STRVAR(_codecs_code_page_decode__doc__,
    1619                 :            : "code_page_decode($module, codepage, data, errors=None, final=False, /)\n"
    1620                 :            : "--\n"
    1621                 :            : "\n");
    1622                 :            : 
    1623                 :            : #define _CODECS_CODE_PAGE_DECODE_METHODDEF    \
    1624                 :            :     {"code_page_decode", _PyCFunction_CAST(_codecs_code_page_decode), METH_FASTCALL, _codecs_code_page_decode__doc__},
    1625                 :            : 
    1626                 :            : static PyObject *
    1627                 :            : _codecs_code_page_decode_impl(PyObject *module, int codepage,
    1628                 :            :                               Py_buffer *data, const char *errors, int final);
    1629                 :            : 
    1630                 :            : static PyObject *
    1631                 :            : _codecs_code_page_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
    1632                 :            : {
    1633                 :            :     PyObject *return_value = NULL;
    1634                 :            :     int codepage;
    1635                 :            :     Py_buffer data = {NULL, NULL};
    1636                 :            :     const char *errors = NULL;
    1637                 :            :     int final = 0;
    1638                 :            : 
    1639                 :            :     if (!_PyArg_CheckPositional("code_page_decode", nargs, 2, 4)) {
    1640                 :            :         goto exit;
    1641                 :            :     }
    1642                 :            :     codepage = _PyLong_AsInt(args[0]);
    1643                 :            :     if (codepage == -1 && PyErr_Occurred()) {
    1644                 :            :         goto exit;
    1645                 :            :     }
    1646                 :            :     if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) {
    1647                 :            :         goto exit;
    1648                 :            :     }
    1649                 :            :     if (!PyBuffer_IsContiguous(&data, 'C')) {
    1650                 :            :         _PyArg_BadArgument("code_page_decode", "argument 2", "contiguous buffer", args[1]);
    1651                 :            :         goto exit;
    1652                 :            :     }
    1653                 :            :     if (nargs < 3) {
    1654                 :            :         goto skip_optional;
    1655                 :            :     }
    1656                 :            :     if (args[2] == Py_None) {
    1657                 :            :         errors = NULL;
    1658                 :            :     }
    1659                 :            :     else if (PyUnicode_Check(args[2])) {
    1660                 :            :         Py_ssize_t errors_length;
    1661                 :            :         errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length);
    1662                 :            :         if (errors == NULL) {
    1663                 :            :             goto exit;
    1664                 :            :         }
    1665                 :            :         if (strlen(errors) != (size_t)errors_length) {
    1666                 :            :             PyErr_SetString(PyExc_ValueError, "embedded null character");
    1667                 :            :             goto exit;
    1668                 :            :         }
    1669                 :            :     }
    1670                 :            :     else {
    1671                 :            :         _PyArg_BadArgument("code_page_decode", "argument 3", "str or None", args[2]);
    1672                 :            :         goto exit;
    1673                 :            :     }
    1674                 :            :     if (nargs < 4) {
    1675                 :            :         goto skip_optional;
    1676                 :            :     }
    1677                 :            :     final = PyObject_IsTrue(args[3]);
    1678                 :            :     if (final < 0) {
    1679                 :            :         goto exit;
    1680                 :            :     }
    1681                 :            : skip_optional:
    1682                 :            :     return_value = _codecs_code_page_decode_impl(module, codepage, &data, errors, final);
    1683                 :            : 
    1684                 :            : exit:
    1685                 :            :     /* Cleanup for data */
    1686                 :            :     if (data.obj) {
    1687                 :            :        PyBuffer_Release(&data);
    1688                 :            :     }
    1689                 :            : 
    1690                 :            :     return return_value;
    1691                 :            : }
    1692                 :            : 
    1693                 :            : #endif /* defined(MS_WINDOWS) */
    1694                 :            : 
    1695                 :            : PyDoc_STRVAR(_codecs_readbuffer_encode__doc__,
    1696                 :            : "readbuffer_encode($module, data, errors=None, /)\n"
    1697                 :            : "--\n"
    1698                 :            : "\n");
    1699                 :            : 
    1700                 :            : #define _CODECS_READBUFFER_ENCODE_METHODDEF    \
    1701                 :            :     {"readbuffer_encode", _PyCFunction_CAST(_codecs_readbuffer_encode), METH_FASTCALL, _codecs_readbuffer_encode__doc__},
    1702                 :            : 
    1703                 :            : static PyObject *
    1704                 :            : _codecs_readbuffer_encode_impl(PyObject *module, Py_buffer *data,
    1705                 :            :                                const char *errors);
    1706                 :            : 
    1707                 :            : static PyObject *
    1708                 :          0 : _codecs_readbuffer_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
    1709                 :            : {
    1710                 :          0 :     PyObject *return_value = NULL;
    1711                 :          0 :     Py_buffer data = {NULL, NULL};
    1712                 :          0 :     const char *errors = NULL;
    1713                 :            : 
    1714   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("readbuffer_encode", nargs, 1, 2)) {
                   #  # ]
    1715                 :          0 :         goto exit;
    1716                 :            :     }
    1717         [ #  # ]:          0 :     if (PyUnicode_Check(args[0])) {
    1718                 :            :         Py_ssize_t len;
    1719                 :          0 :         const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
    1720         [ #  # ]:          0 :         if (ptr == NULL) {
    1721                 :          0 :             goto exit;
    1722                 :            :         }
    1723                 :          0 :         PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, 0);
    1724                 :            :     }
    1725                 :            :     else { /* any bytes-like object */
    1726         [ #  # ]:          0 :         if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
    1727                 :          0 :             goto exit;
    1728                 :            :         }
    1729         [ #  # ]:          0 :         if (!PyBuffer_IsContiguous(&data, 'C')) {
    1730                 :          0 :             _PyArg_BadArgument("readbuffer_encode", "argument 1", "contiguous buffer", args[0]);
    1731                 :          0 :             goto exit;
    1732                 :            :         }
    1733                 :            :     }
    1734         [ #  # ]:          0 :     if (nargs < 2) {
    1735                 :          0 :         goto skip_optional;
    1736                 :            :     }
    1737         [ #  # ]:          0 :     if (args[1] == Py_None) {
    1738                 :          0 :         errors = NULL;
    1739                 :            :     }
    1740         [ #  # ]:          0 :     else if (PyUnicode_Check(args[1])) {
    1741                 :            :         Py_ssize_t errors_length;
    1742                 :          0 :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
    1743         [ #  # ]:          0 :         if (errors == NULL) {
    1744                 :          0 :             goto exit;
    1745                 :            :         }
    1746         [ #  # ]:          0 :         if (strlen(errors) != (size_t)errors_length) {
    1747                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
    1748                 :          0 :             goto exit;
    1749                 :            :         }
    1750                 :            :     }
    1751                 :            :     else {
    1752                 :          0 :         _PyArg_BadArgument("readbuffer_encode", "argument 2", "str or None", args[1]);
    1753                 :          0 :         goto exit;
    1754                 :            :     }
    1755                 :          0 : skip_optional:
    1756                 :          0 :     return_value = _codecs_readbuffer_encode_impl(module, &data, errors);
    1757                 :            : 
    1758                 :          0 : exit:
    1759                 :            :     /* Cleanup for data */
    1760         [ #  # ]:          0 :     if (data.obj) {
    1761                 :          0 :        PyBuffer_Release(&data);
    1762                 :            :     }
    1763                 :            : 
    1764                 :          0 :     return return_value;
    1765                 :            : }
    1766                 :            : 
    1767                 :            : PyDoc_STRVAR(_codecs_utf_7_encode__doc__,
    1768                 :            : "utf_7_encode($module, str, errors=None, /)\n"
    1769                 :            : "--\n"
    1770                 :            : "\n");
    1771                 :            : 
    1772                 :            : #define _CODECS_UTF_7_ENCODE_METHODDEF    \
    1773                 :            :     {"utf_7_encode", _PyCFunction_CAST(_codecs_utf_7_encode), METH_FASTCALL, _codecs_utf_7_encode__doc__},
    1774                 :            : 
    1775                 :            : static PyObject *
    1776                 :            : _codecs_utf_7_encode_impl(PyObject *module, PyObject *str,
    1777                 :            :                           const char *errors);
    1778                 :            : 
    1779                 :            : static PyObject *
    1780                 :          0 : _codecs_utf_7_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
    1781                 :            : {
    1782                 :          0 :     PyObject *return_value = NULL;
    1783                 :            :     PyObject *str;
    1784                 :          0 :     const char *errors = NULL;
    1785                 :            : 
    1786   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("utf_7_encode", nargs, 1, 2)) {
                   #  # ]
    1787                 :          0 :         goto exit;
    1788                 :            :     }
    1789         [ #  # ]:          0 :     if (!PyUnicode_Check(args[0])) {
    1790                 :          0 :         _PyArg_BadArgument("utf_7_encode", "argument 1", "str", args[0]);
    1791                 :          0 :         goto exit;
    1792                 :            :     }
    1793         [ #  # ]:          0 :     if (PyUnicode_READY(args[0]) == -1) {
    1794                 :          0 :         goto exit;
    1795                 :            :     }
    1796                 :          0 :     str = args[0];
    1797         [ #  # ]:          0 :     if (nargs < 2) {
    1798                 :          0 :         goto skip_optional;
    1799                 :            :     }
    1800         [ #  # ]:          0 :     if (args[1] == Py_None) {
    1801                 :          0 :         errors = NULL;
    1802                 :            :     }
    1803         [ #  # ]:          0 :     else if (PyUnicode_Check(args[1])) {
    1804                 :            :         Py_ssize_t errors_length;
    1805                 :          0 :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
    1806         [ #  # ]:          0 :         if (errors == NULL) {
    1807                 :          0 :             goto exit;
    1808                 :            :         }
    1809         [ #  # ]:          0 :         if (strlen(errors) != (size_t)errors_length) {
    1810                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
    1811                 :          0 :             goto exit;
    1812                 :            :         }
    1813                 :            :     }
    1814                 :            :     else {
    1815                 :          0 :         _PyArg_BadArgument("utf_7_encode", "argument 2", "str or None", args[1]);
    1816                 :          0 :         goto exit;
    1817                 :            :     }
    1818                 :          0 : skip_optional:
    1819                 :          0 :     return_value = _codecs_utf_7_encode_impl(module, str, errors);
    1820                 :            : 
    1821                 :          0 : exit:
    1822                 :          0 :     return return_value;
    1823                 :            : }
    1824                 :            : 
    1825                 :            : PyDoc_STRVAR(_codecs_utf_8_encode__doc__,
    1826                 :            : "utf_8_encode($module, str, errors=None, /)\n"
    1827                 :            : "--\n"
    1828                 :            : "\n");
    1829                 :            : 
    1830                 :            : #define _CODECS_UTF_8_ENCODE_METHODDEF    \
    1831                 :            :     {"utf_8_encode", _PyCFunction_CAST(_codecs_utf_8_encode), METH_FASTCALL, _codecs_utf_8_encode__doc__},
    1832                 :            : 
    1833                 :            : static PyObject *
    1834                 :            : _codecs_utf_8_encode_impl(PyObject *module, PyObject *str,
    1835                 :            :                           const char *errors);
    1836                 :            : 
    1837                 :            : static PyObject *
    1838                 :          0 : _codecs_utf_8_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
    1839                 :            : {
    1840                 :          0 :     PyObject *return_value = NULL;
    1841                 :            :     PyObject *str;
    1842                 :          0 :     const char *errors = NULL;
    1843                 :            : 
    1844   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("utf_8_encode", nargs, 1, 2)) {
                   #  # ]
    1845                 :          0 :         goto exit;
    1846                 :            :     }
    1847         [ #  # ]:          0 :     if (!PyUnicode_Check(args[0])) {
    1848                 :          0 :         _PyArg_BadArgument("utf_8_encode", "argument 1", "str", args[0]);
    1849                 :          0 :         goto exit;
    1850                 :            :     }
    1851         [ #  # ]:          0 :     if (PyUnicode_READY(args[0]) == -1) {
    1852                 :          0 :         goto exit;
    1853                 :            :     }
    1854                 :          0 :     str = args[0];
    1855         [ #  # ]:          0 :     if (nargs < 2) {
    1856                 :          0 :         goto skip_optional;
    1857                 :            :     }
    1858         [ #  # ]:          0 :     if (args[1] == Py_None) {
    1859                 :          0 :         errors = NULL;
    1860                 :            :     }
    1861         [ #  # ]:          0 :     else if (PyUnicode_Check(args[1])) {
    1862                 :            :         Py_ssize_t errors_length;
    1863                 :          0 :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
    1864         [ #  # ]:          0 :         if (errors == NULL) {
    1865                 :          0 :             goto exit;
    1866                 :            :         }
    1867         [ #  # ]:          0 :         if (strlen(errors) != (size_t)errors_length) {
    1868                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
    1869                 :          0 :             goto exit;
    1870                 :            :         }
    1871                 :            :     }
    1872                 :            :     else {
    1873                 :          0 :         _PyArg_BadArgument("utf_8_encode", "argument 2", "str or None", args[1]);
    1874                 :          0 :         goto exit;
    1875                 :            :     }
    1876                 :          0 : skip_optional:
    1877                 :          0 :     return_value = _codecs_utf_8_encode_impl(module, str, errors);
    1878                 :            : 
    1879                 :          0 : exit:
    1880                 :          0 :     return return_value;
    1881                 :            : }
    1882                 :            : 
    1883                 :            : PyDoc_STRVAR(_codecs_utf_16_encode__doc__,
    1884                 :            : "utf_16_encode($module, str, errors=None, byteorder=0, /)\n"
    1885                 :            : "--\n"
    1886                 :            : "\n");
    1887                 :            : 
    1888                 :            : #define _CODECS_UTF_16_ENCODE_METHODDEF    \
    1889                 :            :     {"utf_16_encode", _PyCFunction_CAST(_codecs_utf_16_encode), METH_FASTCALL, _codecs_utf_16_encode__doc__},
    1890                 :            : 
    1891                 :            : static PyObject *
    1892                 :            : _codecs_utf_16_encode_impl(PyObject *module, PyObject *str,
    1893                 :            :                            const char *errors, int byteorder);
    1894                 :            : 
    1895                 :            : static PyObject *
    1896                 :          0 : _codecs_utf_16_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
    1897                 :            : {
    1898                 :          0 :     PyObject *return_value = NULL;
    1899                 :            :     PyObject *str;
    1900                 :          0 :     const char *errors = NULL;
    1901                 :          0 :     int byteorder = 0;
    1902                 :            : 
    1903   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("utf_16_encode", nargs, 1, 3)) {
                   #  # ]
    1904                 :          0 :         goto exit;
    1905                 :            :     }
    1906         [ #  # ]:          0 :     if (!PyUnicode_Check(args[0])) {
    1907                 :          0 :         _PyArg_BadArgument("utf_16_encode", "argument 1", "str", args[0]);
    1908                 :          0 :         goto exit;
    1909                 :            :     }
    1910         [ #  # ]:          0 :     if (PyUnicode_READY(args[0]) == -1) {
    1911                 :          0 :         goto exit;
    1912                 :            :     }
    1913                 :          0 :     str = args[0];
    1914         [ #  # ]:          0 :     if (nargs < 2) {
    1915                 :          0 :         goto skip_optional;
    1916                 :            :     }
    1917         [ #  # ]:          0 :     if (args[1] == Py_None) {
    1918                 :          0 :         errors = NULL;
    1919                 :            :     }
    1920         [ #  # ]:          0 :     else if (PyUnicode_Check(args[1])) {
    1921                 :            :         Py_ssize_t errors_length;
    1922                 :          0 :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
    1923         [ #  # ]:          0 :         if (errors == NULL) {
    1924                 :          0 :             goto exit;
    1925                 :            :         }
    1926         [ #  # ]:          0 :         if (strlen(errors) != (size_t)errors_length) {
    1927                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
    1928                 :          0 :             goto exit;
    1929                 :            :         }
    1930                 :            :     }
    1931                 :            :     else {
    1932                 :          0 :         _PyArg_BadArgument("utf_16_encode", "argument 2", "str or None", args[1]);
    1933                 :          0 :         goto exit;
    1934                 :            :     }
    1935         [ #  # ]:          0 :     if (nargs < 3) {
    1936                 :          0 :         goto skip_optional;
    1937                 :            :     }
    1938                 :          0 :     byteorder = _PyLong_AsInt(args[2]);
    1939   [ #  #  #  # ]:          0 :     if (byteorder == -1 && PyErr_Occurred()) {
    1940                 :          0 :         goto exit;
    1941                 :            :     }
    1942                 :          0 : skip_optional:
    1943                 :          0 :     return_value = _codecs_utf_16_encode_impl(module, str, errors, byteorder);
    1944                 :            : 
    1945                 :          0 : exit:
    1946                 :          0 :     return return_value;
    1947                 :            : }
    1948                 :            : 
    1949                 :            : PyDoc_STRVAR(_codecs_utf_16_le_encode__doc__,
    1950                 :            : "utf_16_le_encode($module, str, errors=None, /)\n"
    1951                 :            : "--\n"
    1952                 :            : "\n");
    1953                 :            : 
    1954                 :            : #define _CODECS_UTF_16_LE_ENCODE_METHODDEF    \
    1955                 :            :     {"utf_16_le_encode", _PyCFunction_CAST(_codecs_utf_16_le_encode), METH_FASTCALL, _codecs_utf_16_le_encode__doc__},
    1956                 :            : 
    1957                 :            : static PyObject *
    1958                 :            : _codecs_utf_16_le_encode_impl(PyObject *module, PyObject *str,
    1959                 :            :                               const char *errors);
    1960                 :            : 
    1961                 :            : static PyObject *
    1962                 :          0 : _codecs_utf_16_le_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
    1963                 :            : {
    1964                 :          0 :     PyObject *return_value = NULL;
    1965                 :            :     PyObject *str;
    1966                 :          0 :     const char *errors = NULL;
    1967                 :            : 
    1968   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("utf_16_le_encode", nargs, 1, 2)) {
                   #  # ]
    1969                 :          0 :         goto exit;
    1970                 :            :     }
    1971         [ #  # ]:          0 :     if (!PyUnicode_Check(args[0])) {
    1972                 :          0 :         _PyArg_BadArgument("utf_16_le_encode", "argument 1", "str", args[0]);
    1973                 :          0 :         goto exit;
    1974                 :            :     }
    1975         [ #  # ]:          0 :     if (PyUnicode_READY(args[0]) == -1) {
    1976                 :          0 :         goto exit;
    1977                 :            :     }
    1978                 :          0 :     str = args[0];
    1979         [ #  # ]:          0 :     if (nargs < 2) {
    1980                 :          0 :         goto skip_optional;
    1981                 :            :     }
    1982         [ #  # ]:          0 :     if (args[1] == Py_None) {
    1983                 :          0 :         errors = NULL;
    1984                 :            :     }
    1985         [ #  # ]:          0 :     else if (PyUnicode_Check(args[1])) {
    1986                 :            :         Py_ssize_t errors_length;
    1987                 :          0 :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
    1988         [ #  # ]:          0 :         if (errors == NULL) {
    1989                 :          0 :             goto exit;
    1990                 :            :         }
    1991         [ #  # ]:          0 :         if (strlen(errors) != (size_t)errors_length) {
    1992                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
    1993                 :          0 :             goto exit;
    1994                 :            :         }
    1995                 :            :     }
    1996                 :            :     else {
    1997                 :          0 :         _PyArg_BadArgument("utf_16_le_encode", "argument 2", "str or None", args[1]);
    1998                 :          0 :         goto exit;
    1999                 :            :     }
    2000                 :          0 : skip_optional:
    2001                 :          0 :     return_value = _codecs_utf_16_le_encode_impl(module, str, errors);
    2002                 :            : 
    2003                 :          0 : exit:
    2004                 :          0 :     return return_value;
    2005                 :            : }
    2006                 :            : 
    2007                 :            : PyDoc_STRVAR(_codecs_utf_16_be_encode__doc__,
    2008                 :            : "utf_16_be_encode($module, str, errors=None, /)\n"
    2009                 :            : "--\n"
    2010                 :            : "\n");
    2011                 :            : 
    2012                 :            : #define _CODECS_UTF_16_BE_ENCODE_METHODDEF    \
    2013                 :            :     {"utf_16_be_encode", _PyCFunction_CAST(_codecs_utf_16_be_encode), METH_FASTCALL, _codecs_utf_16_be_encode__doc__},
    2014                 :            : 
    2015                 :            : static PyObject *
    2016                 :            : _codecs_utf_16_be_encode_impl(PyObject *module, PyObject *str,
    2017                 :            :                               const char *errors);
    2018                 :            : 
    2019                 :            : static PyObject *
    2020                 :          0 : _codecs_utf_16_be_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
    2021                 :            : {
    2022                 :          0 :     PyObject *return_value = NULL;
    2023                 :            :     PyObject *str;
    2024                 :          0 :     const char *errors = NULL;
    2025                 :            : 
    2026   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("utf_16_be_encode", nargs, 1, 2)) {
                   #  # ]
    2027                 :          0 :         goto exit;
    2028                 :            :     }
    2029         [ #  # ]:          0 :     if (!PyUnicode_Check(args[0])) {
    2030                 :          0 :         _PyArg_BadArgument("utf_16_be_encode", "argument 1", "str", args[0]);
    2031                 :          0 :         goto exit;
    2032                 :            :     }
    2033         [ #  # ]:          0 :     if (PyUnicode_READY(args[0]) == -1) {
    2034                 :          0 :         goto exit;
    2035                 :            :     }
    2036                 :          0 :     str = args[0];
    2037         [ #  # ]:          0 :     if (nargs < 2) {
    2038                 :          0 :         goto skip_optional;
    2039                 :            :     }
    2040         [ #  # ]:          0 :     if (args[1] == Py_None) {
    2041                 :          0 :         errors = NULL;
    2042                 :            :     }
    2043         [ #  # ]:          0 :     else if (PyUnicode_Check(args[1])) {
    2044                 :            :         Py_ssize_t errors_length;
    2045                 :          0 :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
    2046         [ #  # ]:          0 :         if (errors == NULL) {
    2047                 :          0 :             goto exit;
    2048                 :            :         }
    2049         [ #  # ]:          0 :         if (strlen(errors) != (size_t)errors_length) {
    2050                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
    2051                 :          0 :             goto exit;
    2052                 :            :         }
    2053                 :            :     }
    2054                 :            :     else {
    2055                 :          0 :         _PyArg_BadArgument("utf_16_be_encode", "argument 2", "str or None", args[1]);
    2056                 :          0 :         goto exit;
    2057                 :            :     }
    2058                 :          0 : skip_optional:
    2059                 :          0 :     return_value = _codecs_utf_16_be_encode_impl(module, str, errors);
    2060                 :            : 
    2061                 :          0 : exit:
    2062                 :          0 :     return return_value;
    2063                 :            : }
    2064                 :            : 
    2065                 :            : PyDoc_STRVAR(_codecs_utf_32_encode__doc__,
    2066                 :            : "utf_32_encode($module, str, errors=None, byteorder=0, /)\n"
    2067                 :            : "--\n"
    2068                 :            : "\n");
    2069                 :            : 
    2070                 :            : #define _CODECS_UTF_32_ENCODE_METHODDEF    \
    2071                 :            :     {"utf_32_encode", _PyCFunction_CAST(_codecs_utf_32_encode), METH_FASTCALL, _codecs_utf_32_encode__doc__},
    2072                 :            : 
    2073                 :            : static PyObject *
    2074                 :            : _codecs_utf_32_encode_impl(PyObject *module, PyObject *str,
    2075                 :            :                            const char *errors, int byteorder);
    2076                 :            : 
    2077                 :            : static PyObject *
    2078                 :          0 : _codecs_utf_32_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
    2079                 :            : {
    2080                 :          0 :     PyObject *return_value = NULL;
    2081                 :            :     PyObject *str;
    2082                 :          0 :     const char *errors = NULL;
    2083                 :          0 :     int byteorder = 0;
    2084                 :            : 
    2085   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("utf_32_encode", nargs, 1, 3)) {
                   #  # ]
    2086                 :          0 :         goto exit;
    2087                 :            :     }
    2088         [ #  # ]:          0 :     if (!PyUnicode_Check(args[0])) {
    2089                 :          0 :         _PyArg_BadArgument("utf_32_encode", "argument 1", "str", args[0]);
    2090                 :          0 :         goto exit;
    2091                 :            :     }
    2092         [ #  # ]:          0 :     if (PyUnicode_READY(args[0]) == -1) {
    2093                 :          0 :         goto exit;
    2094                 :            :     }
    2095                 :          0 :     str = args[0];
    2096         [ #  # ]:          0 :     if (nargs < 2) {
    2097                 :          0 :         goto skip_optional;
    2098                 :            :     }
    2099         [ #  # ]:          0 :     if (args[1] == Py_None) {
    2100                 :          0 :         errors = NULL;
    2101                 :            :     }
    2102         [ #  # ]:          0 :     else if (PyUnicode_Check(args[1])) {
    2103                 :            :         Py_ssize_t errors_length;
    2104                 :          0 :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
    2105         [ #  # ]:          0 :         if (errors == NULL) {
    2106                 :          0 :             goto exit;
    2107                 :            :         }
    2108         [ #  # ]:          0 :         if (strlen(errors) != (size_t)errors_length) {
    2109                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
    2110                 :          0 :             goto exit;
    2111                 :            :         }
    2112                 :            :     }
    2113                 :            :     else {
    2114                 :          0 :         _PyArg_BadArgument("utf_32_encode", "argument 2", "str or None", args[1]);
    2115                 :          0 :         goto exit;
    2116                 :            :     }
    2117         [ #  # ]:          0 :     if (nargs < 3) {
    2118                 :          0 :         goto skip_optional;
    2119                 :            :     }
    2120                 :          0 :     byteorder = _PyLong_AsInt(args[2]);
    2121   [ #  #  #  # ]:          0 :     if (byteorder == -1 && PyErr_Occurred()) {
    2122                 :          0 :         goto exit;
    2123                 :            :     }
    2124                 :          0 : skip_optional:
    2125                 :          0 :     return_value = _codecs_utf_32_encode_impl(module, str, errors, byteorder);
    2126                 :            : 
    2127                 :          0 : exit:
    2128                 :          0 :     return return_value;
    2129                 :            : }
    2130                 :            : 
    2131                 :            : PyDoc_STRVAR(_codecs_utf_32_le_encode__doc__,
    2132                 :            : "utf_32_le_encode($module, str, errors=None, /)\n"
    2133                 :            : "--\n"
    2134                 :            : "\n");
    2135                 :            : 
    2136                 :            : #define _CODECS_UTF_32_LE_ENCODE_METHODDEF    \
    2137                 :            :     {"utf_32_le_encode", _PyCFunction_CAST(_codecs_utf_32_le_encode), METH_FASTCALL, _codecs_utf_32_le_encode__doc__},
    2138                 :            : 
    2139                 :            : static PyObject *
    2140                 :            : _codecs_utf_32_le_encode_impl(PyObject *module, PyObject *str,
    2141                 :            :                               const char *errors);
    2142                 :            : 
    2143                 :            : static PyObject *
    2144                 :          0 : _codecs_utf_32_le_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
    2145                 :            : {
    2146                 :          0 :     PyObject *return_value = NULL;
    2147                 :            :     PyObject *str;
    2148                 :          0 :     const char *errors = NULL;
    2149                 :            : 
    2150   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("utf_32_le_encode", nargs, 1, 2)) {
                   #  # ]
    2151                 :          0 :         goto exit;
    2152                 :            :     }
    2153         [ #  # ]:          0 :     if (!PyUnicode_Check(args[0])) {
    2154                 :          0 :         _PyArg_BadArgument("utf_32_le_encode", "argument 1", "str", args[0]);
    2155                 :          0 :         goto exit;
    2156                 :            :     }
    2157         [ #  # ]:          0 :     if (PyUnicode_READY(args[0]) == -1) {
    2158                 :          0 :         goto exit;
    2159                 :            :     }
    2160                 :          0 :     str = args[0];
    2161         [ #  # ]:          0 :     if (nargs < 2) {
    2162                 :          0 :         goto skip_optional;
    2163                 :            :     }
    2164         [ #  # ]:          0 :     if (args[1] == Py_None) {
    2165                 :          0 :         errors = NULL;
    2166                 :            :     }
    2167         [ #  # ]:          0 :     else if (PyUnicode_Check(args[1])) {
    2168                 :            :         Py_ssize_t errors_length;
    2169                 :          0 :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
    2170         [ #  # ]:          0 :         if (errors == NULL) {
    2171                 :          0 :             goto exit;
    2172                 :            :         }
    2173         [ #  # ]:          0 :         if (strlen(errors) != (size_t)errors_length) {
    2174                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
    2175                 :          0 :             goto exit;
    2176                 :            :         }
    2177                 :            :     }
    2178                 :            :     else {
    2179                 :          0 :         _PyArg_BadArgument("utf_32_le_encode", "argument 2", "str or None", args[1]);
    2180                 :          0 :         goto exit;
    2181                 :            :     }
    2182                 :          0 : skip_optional:
    2183                 :          0 :     return_value = _codecs_utf_32_le_encode_impl(module, str, errors);
    2184                 :            : 
    2185                 :          0 : exit:
    2186                 :          0 :     return return_value;
    2187                 :            : }
    2188                 :            : 
    2189                 :            : PyDoc_STRVAR(_codecs_utf_32_be_encode__doc__,
    2190                 :            : "utf_32_be_encode($module, str, errors=None, /)\n"
    2191                 :            : "--\n"
    2192                 :            : "\n");
    2193                 :            : 
    2194                 :            : #define _CODECS_UTF_32_BE_ENCODE_METHODDEF    \
    2195                 :            :     {"utf_32_be_encode", _PyCFunction_CAST(_codecs_utf_32_be_encode), METH_FASTCALL, _codecs_utf_32_be_encode__doc__},
    2196                 :            : 
    2197                 :            : static PyObject *
    2198                 :            : _codecs_utf_32_be_encode_impl(PyObject *module, PyObject *str,
    2199                 :            :                               const char *errors);
    2200                 :            : 
    2201                 :            : static PyObject *
    2202                 :          0 : _codecs_utf_32_be_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
    2203                 :            : {
    2204                 :          0 :     PyObject *return_value = NULL;
    2205                 :            :     PyObject *str;
    2206                 :          0 :     const char *errors = NULL;
    2207                 :            : 
    2208   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("utf_32_be_encode", nargs, 1, 2)) {
                   #  # ]
    2209                 :          0 :         goto exit;
    2210                 :            :     }
    2211         [ #  # ]:          0 :     if (!PyUnicode_Check(args[0])) {
    2212                 :          0 :         _PyArg_BadArgument("utf_32_be_encode", "argument 1", "str", args[0]);
    2213                 :          0 :         goto exit;
    2214                 :            :     }
    2215         [ #  # ]:          0 :     if (PyUnicode_READY(args[0]) == -1) {
    2216                 :          0 :         goto exit;
    2217                 :            :     }
    2218                 :          0 :     str = args[0];
    2219         [ #  # ]:          0 :     if (nargs < 2) {
    2220                 :          0 :         goto skip_optional;
    2221                 :            :     }
    2222         [ #  # ]:          0 :     if (args[1] == Py_None) {
    2223                 :          0 :         errors = NULL;
    2224                 :            :     }
    2225         [ #  # ]:          0 :     else if (PyUnicode_Check(args[1])) {
    2226                 :            :         Py_ssize_t errors_length;
    2227                 :          0 :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
    2228         [ #  # ]:          0 :         if (errors == NULL) {
    2229                 :          0 :             goto exit;
    2230                 :            :         }
    2231         [ #  # ]:          0 :         if (strlen(errors) != (size_t)errors_length) {
    2232                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
    2233                 :          0 :             goto exit;
    2234                 :            :         }
    2235                 :            :     }
    2236                 :            :     else {
    2237                 :          0 :         _PyArg_BadArgument("utf_32_be_encode", "argument 2", "str or None", args[1]);
    2238                 :          0 :         goto exit;
    2239                 :            :     }
    2240                 :          0 : skip_optional:
    2241                 :          0 :     return_value = _codecs_utf_32_be_encode_impl(module, str, errors);
    2242                 :            : 
    2243                 :          0 : exit:
    2244                 :          0 :     return return_value;
    2245                 :            : }
    2246                 :            : 
    2247                 :            : PyDoc_STRVAR(_codecs_unicode_escape_encode__doc__,
    2248                 :            : "unicode_escape_encode($module, str, errors=None, /)\n"
    2249                 :            : "--\n"
    2250                 :            : "\n");
    2251                 :            : 
    2252                 :            : #define _CODECS_UNICODE_ESCAPE_ENCODE_METHODDEF    \
    2253                 :            :     {"unicode_escape_encode", _PyCFunction_CAST(_codecs_unicode_escape_encode), METH_FASTCALL, _codecs_unicode_escape_encode__doc__},
    2254                 :            : 
    2255                 :            : static PyObject *
    2256                 :            : _codecs_unicode_escape_encode_impl(PyObject *module, PyObject *str,
    2257                 :            :                                    const char *errors);
    2258                 :            : 
    2259                 :            : static PyObject *
    2260                 :          0 : _codecs_unicode_escape_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
    2261                 :            : {
    2262                 :          0 :     PyObject *return_value = NULL;
    2263                 :            :     PyObject *str;
    2264                 :          0 :     const char *errors = NULL;
    2265                 :            : 
    2266   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("unicode_escape_encode", nargs, 1, 2)) {
                   #  # ]
    2267                 :          0 :         goto exit;
    2268                 :            :     }
    2269         [ #  # ]:          0 :     if (!PyUnicode_Check(args[0])) {
    2270                 :          0 :         _PyArg_BadArgument("unicode_escape_encode", "argument 1", "str", args[0]);
    2271                 :          0 :         goto exit;
    2272                 :            :     }
    2273         [ #  # ]:          0 :     if (PyUnicode_READY(args[0]) == -1) {
    2274                 :          0 :         goto exit;
    2275                 :            :     }
    2276                 :          0 :     str = args[0];
    2277         [ #  # ]:          0 :     if (nargs < 2) {
    2278                 :          0 :         goto skip_optional;
    2279                 :            :     }
    2280         [ #  # ]:          0 :     if (args[1] == Py_None) {
    2281                 :          0 :         errors = NULL;
    2282                 :            :     }
    2283         [ #  # ]:          0 :     else if (PyUnicode_Check(args[1])) {
    2284                 :            :         Py_ssize_t errors_length;
    2285                 :          0 :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
    2286         [ #  # ]:          0 :         if (errors == NULL) {
    2287                 :          0 :             goto exit;
    2288                 :            :         }
    2289         [ #  # ]:          0 :         if (strlen(errors) != (size_t)errors_length) {
    2290                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
    2291                 :          0 :             goto exit;
    2292                 :            :         }
    2293                 :            :     }
    2294                 :            :     else {
    2295                 :          0 :         _PyArg_BadArgument("unicode_escape_encode", "argument 2", "str or None", args[1]);
    2296                 :          0 :         goto exit;
    2297                 :            :     }
    2298                 :          0 : skip_optional:
    2299                 :          0 :     return_value = _codecs_unicode_escape_encode_impl(module, str, errors);
    2300                 :            : 
    2301                 :          0 : exit:
    2302                 :          0 :     return return_value;
    2303                 :            : }
    2304                 :            : 
    2305                 :            : PyDoc_STRVAR(_codecs_raw_unicode_escape_encode__doc__,
    2306                 :            : "raw_unicode_escape_encode($module, str, errors=None, /)\n"
    2307                 :            : "--\n"
    2308                 :            : "\n");
    2309                 :            : 
    2310                 :            : #define _CODECS_RAW_UNICODE_ESCAPE_ENCODE_METHODDEF    \
    2311                 :            :     {"raw_unicode_escape_encode", _PyCFunction_CAST(_codecs_raw_unicode_escape_encode), METH_FASTCALL, _codecs_raw_unicode_escape_encode__doc__},
    2312                 :            : 
    2313                 :            : static PyObject *
    2314                 :            : _codecs_raw_unicode_escape_encode_impl(PyObject *module, PyObject *str,
    2315                 :            :                                        const char *errors);
    2316                 :            : 
    2317                 :            : static PyObject *
    2318                 :          0 : _codecs_raw_unicode_escape_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
    2319                 :            : {
    2320                 :          0 :     PyObject *return_value = NULL;
    2321                 :            :     PyObject *str;
    2322                 :          0 :     const char *errors = NULL;
    2323                 :            : 
    2324   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("raw_unicode_escape_encode", nargs, 1, 2)) {
                   #  # ]
    2325                 :          0 :         goto exit;
    2326                 :            :     }
    2327         [ #  # ]:          0 :     if (!PyUnicode_Check(args[0])) {
    2328                 :          0 :         _PyArg_BadArgument("raw_unicode_escape_encode", "argument 1", "str", args[0]);
    2329                 :          0 :         goto exit;
    2330                 :            :     }
    2331         [ #  # ]:          0 :     if (PyUnicode_READY(args[0]) == -1) {
    2332                 :          0 :         goto exit;
    2333                 :            :     }
    2334                 :          0 :     str = args[0];
    2335         [ #  # ]:          0 :     if (nargs < 2) {
    2336                 :          0 :         goto skip_optional;
    2337                 :            :     }
    2338         [ #  # ]:          0 :     if (args[1] == Py_None) {
    2339                 :          0 :         errors = NULL;
    2340                 :            :     }
    2341         [ #  # ]:          0 :     else if (PyUnicode_Check(args[1])) {
    2342                 :            :         Py_ssize_t errors_length;
    2343                 :          0 :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
    2344         [ #  # ]:          0 :         if (errors == NULL) {
    2345                 :          0 :             goto exit;
    2346                 :            :         }
    2347         [ #  # ]:          0 :         if (strlen(errors) != (size_t)errors_length) {
    2348                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
    2349                 :          0 :             goto exit;
    2350                 :            :         }
    2351                 :            :     }
    2352                 :            :     else {
    2353                 :          0 :         _PyArg_BadArgument("raw_unicode_escape_encode", "argument 2", "str or None", args[1]);
    2354                 :          0 :         goto exit;
    2355                 :            :     }
    2356                 :          0 : skip_optional:
    2357                 :          0 :     return_value = _codecs_raw_unicode_escape_encode_impl(module, str, errors);
    2358                 :            : 
    2359                 :          0 : exit:
    2360                 :          0 :     return return_value;
    2361                 :            : }
    2362                 :            : 
    2363                 :            : PyDoc_STRVAR(_codecs_latin_1_encode__doc__,
    2364                 :            : "latin_1_encode($module, str, errors=None, /)\n"
    2365                 :            : "--\n"
    2366                 :            : "\n");
    2367                 :            : 
    2368                 :            : #define _CODECS_LATIN_1_ENCODE_METHODDEF    \
    2369                 :            :     {"latin_1_encode", _PyCFunction_CAST(_codecs_latin_1_encode), METH_FASTCALL, _codecs_latin_1_encode__doc__},
    2370                 :            : 
    2371                 :            : static PyObject *
    2372                 :            : _codecs_latin_1_encode_impl(PyObject *module, PyObject *str,
    2373                 :            :                             const char *errors);
    2374                 :            : 
    2375                 :            : static PyObject *
    2376                 :          0 : _codecs_latin_1_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
    2377                 :            : {
    2378                 :          0 :     PyObject *return_value = NULL;
    2379                 :            :     PyObject *str;
    2380                 :          0 :     const char *errors = NULL;
    2381                 :            : 
    2382   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("latin_1_encode", nargs, 1, 2)) {
                   #  # ]
    2383                 :          0 :         goto exit;
    2384                 :            :     }
    2385         [ #  # ]:          0 :     if (!PyUnicode_Check(args[0])) {
    2386                 :          0 :         _PyArg_BadArgument("latin_1_encode", "argument 1", "str", args[0]);
    2387                 :          0 :         goto exit;
    2388                 :            :     }
    2389         [ #  # ]:          0 :     if (PyUnicode_READY(args[0]) == -1) {
    2390                 :          0 :         goto exit;
    2391                 :            :     }
    2392                 :          0 :     str = args[0];
    2393         [ #  # ]:          0 :     if (nargs < 2) {
    2394                 :          0 :         goto skip_optional;
    2395                 :            :     }
    2396         [ #  # ]:          0 :     if (args[1] == Py_None) {
    2397                 :          0 :         errors = NULL;
    2398                 :            :     }
    2399         [ #  # ]:          0 :     else if (PyUnicode_Check(args[1])) {
    2400                 :            :         Py_ssize_t errors_length;
    2401                 :          0 :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
    2402         [ #  # ]:          0 :         if (errors == NULL) {
    2403                 :          0 :             goto exit;
    2404                 :            :         }
    2405         [ #  # ]:          0 :         if (strlen(errors) != (size_t)errors_length) {
    2406                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
    2407                 :          0 :             goto exit;
    2408                 :            :         }
    2409                 :            :     }
    2410                 :            :     else {
    2411                 :          0 :         _PyArg_BadArgument("latin_1_encode", "argument 2", "str or None", args[1]);
    2412                 :          0 :         goto exit;
    2413                 :            :     }
    2414                 :          0 : skip_optional:
    2415                 :          0 :     return_value = _codecs_latin_1_encode_impl(module, str, errors);
    2416                 :            : 
    2417                 :          0 : exit:
    2418                 :          0 :     return return_value;
    2419                 :            : }
    2420                 :            : 
    2421                 :            : PyDoc_STRVAR(_codecs_ascii_encode__doc__,
    2422                 :            : "ascii_encode($module, str, errors=None, /)\n"
    2423                 :            : "--\n"
    2424                 :            : "\n");
    2425                 :            : 
    2426                 :            : #define _CODECS_ASCII_ENCODE_METHODDEF    \
    2427                 :            :     {"ascii_encode", _PyCFunction_CAST(_codecs_ascii_encode), METH_FASTCALL, _codecs_ascii_encode__doc__},
    2428                 :            : 
    2429                 :            : static PyObject *
    2430                 :            : _codecs_ascii_encode_impl(PyObject *module, PyObject *str,
    2431                 :            :                           const char *errors);
    2432                 :            : 
    2433                 :            : static PyObject *
    2434                 :          0 : _codecs_ascii_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
    2435                 :            : {
    2436                 :          0 :     PyObject *return_value = NULL;
    2437                 :            :     PyObject *str;
    2438                 :          0 :     const char *errors = NULL;
    2439                 :            : 
    2440   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("ascii_encode", nargs, 1, 2)) {
                   #  # ]
    2441                 :          0 :         goto exit;
    2442                 :            :     }
    2443         [ #  # ]:          0 :     if (!PyUnicode_Check(args[0])) {
    2444                 :          0 :         _PyArg_BadArgument("ascii_encode", "argument 1", "str", args[0]);
    2445                 :          0 :         goto exit;
    2446                 :            :     }
    2447         [ #  # ]:          0 :     if (PyUnicode_READY(args[0]) == -1) {
    2448                 :          0 :         goto exit;
    2449                 :            :     }
    2450                 :          0 :     str = args[0];
    2451         [ #  # ]:          0 :     if (nargs < 2) {
    2452                 :          0 :         goto skip_optional;
    2453                 :            :     }
    2454         [ #  # ]:          0 :     if (args[1] == Py_None) {
    2455                 :          0 :         errors = NULL;
    2456                 :            :     }
    2457         [ #  # ]:          0 :     else if (PyUnicode_Check(args[1])) {
    2458                 :            :         Py_ssize_t errors_length;
    2459                 :          0 :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
    2460         [ #  # ]:          0 :         if (errors == NULL) {
    2461                 :          0 :             goto exit;
    2462                 :            :         }
    2463         [ #  # ]:          0 :         if (strlen(errors) != (size_t)errors_length) {
    2464                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
    2465                 :          0 :             goto exit;
    2466                 :            :         }
    2467                 :            :     }
    2468                 :            :     else {
    2469                 :          0 :         _PyArg_BadArgument("ascii_encode", "argument 2", "str or None", args[1]);
    2470                 :          0 :         goto exit;
    2471                 :            :     }
    2472                 :          0 : skip_optional:
    2473                 :          0 :     return_value = _codecs_ascii_encode_impl(module, str, errors);
    2474                 :            : 
    2475                 :          0 : exit:
    2476                 :          0 :     return return_value;
    2477                 :            : }
    2478                 :            : 
    2479                 :            : PyDoc_STRVAR(_codecs_charmap_encode__doc__,
    2480                 :            : "charmap_encode($module, str, errors=None, mapping=None, /)\n"
    2481                 :            : "--\n"
    2482                 :            : "\n");
    2483                 :            : 
    2484                 :            : #define _CODECS_CHARMAP_ENCODE_METHODDEF    \
    2485                 :            :     {"charmap_encode", _PyCFunction_CAST(_codecs_charmap_encode), METH_FASTCALL, _codecs_charmap_encode__doc__},
    2486                 :            : 
    2487                 :            : static PyObject *
    2488                 :            : _codecs_charmap_encode_impl(PyObject *module, PyObject *str,
    2489                 :            :                             const char *errors, PyObject *mapping);
    2490                 :            : 
    2491                 :            : static PyObject *
    2492                 :          0 : _codecs_charmap_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
    2493                 :            : {
    2494                 :          0 :     PyObject *return_value = NULL;
    2495                 :            :     PyObject *str;
    2496                 :          0 :     const char *errors = NULL;
    2497                 :          0 :     PyObject *mapping = Py_None;
    2498                 :            : 
    2499   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("charmap_encode", nargs, 1, 3)) {
                   #  # ]
    2500                 :          0 :         goto exit;
    2501                 :            :     }
    2502         [ #  # ]:          0 :     if (!PyUnicode_Check(args[0])) {
    2503                 :          0 :         _PyArg_BadArgument("charmap_encode", "argument 1", "str", args[0]);
    2504                 :          0 :         goto exit;
    2505                 :            :     }
    2506         [ #  # ]:          0 :     if (PyUnicode_READY(args[0]) == -1) {
    2507                 :          0 :         goto exit;
    2508                 :            :     }
    2509                 :          0 :     str = args[0];
    2510         [ #  # ]:          0 :     if (nargs < 2) {
    2511                 :          0 :         goto skip_optional;
    2512                 :            :     }
    2513         [ #  # ]:          0 :     if (args[1] == Py_None) {
    2514                 :          0 :         errors = NULL;
    2515                 :            :     }
    2516         [ #  # ]:          0 :     else if (PyUnicode_Check(args[1])) {
    2517                 :            :         Py_ssize_t errors_length;
    2518                 :          0 :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
    2519         [ #  # ]:          0 :         if (errors == NULL) {
    2520                 :          0 :             goto exit;
    2521                 :            :         }
    2522         [ #  # ]:          0 :         if (strlen(errors) != (size_t)errors_length) {
    2523                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
    2524                 :          0 :             goto exit;
    2525                 :            :         }
    2526                 :            :     }
    2527                 :            :     else {
    2528                 :          0 :         _PyArg_BadArgument("charmap_encode", "argument 2", "str or None", args[1]);
    2529                 :          0 :         goto exit;
    2530                 :            :     }
    2531         [ #  # ]:          0 :     if (nargs < 3) {
    2532                 :          0 :         goto skip_optional;
    2533                 :            :     }
    2534                 :          0 :     mapping = args[2];
    2535                 :          0 : skip_optional:
    2536                 :          0 :     return_value = _codecs_charmap_encode_impl(module, str, errors, mapping);
    2537                 :            : 
    2538                 :          0 : exit:
    2539                 :          0 :     return return_value;
    2540                 :            : }
    2541                 :            : 
    2542                 :            : PyDoc_STRVAR(_codecs_charmap_build__doc__,
    2543                 :            : "charmap_build($module, map, /)\n"
    2544                 :            : "--\n"
    2545                 :            : "\n");
    2546                 :            : 
    2547                 :            : #define _CODECS_CHARMAP_BUILD_METHODDEF    \
    2548                 :            :     {"charmap_build", (PyCFunction)_codecs_charmap_build, METH_O, _codecs_charmap_build__doc__},
    2549                 :            : 
    2550                 :            : static PyObject *
    2551                 :            : _codecs_charmap_build_impl(PyObject *module, PyObject *map);
    2552                 :            : 
    2553                 :            : static PyObject *
    2554                 :          0 : _codecs_charmap_build(PyObject *module, PyObject *arg)
    2555                 :            : {
    2556                 :          0 :     PyObject *return_value = NULL;
    2557                 :            :     PyObject *map;
    2558                 :            : 
    2559         [ #  # ]:          0 :     if (!PyUnicode_Check(arg)) {
    2560                 :          0 :         _PyArg_BadArgument("charmap_build", "argument", "str", arg);
    2561                 :          0 :         goto exit;
    2562                 :            :     }
    2563         [ #  # ]:          0 :     if (PyUnicode_READY(arg) == -1) {
    2564                 :          0 :         goto exit;
    2565                 :            :     }
    2566                 :          0 :     map = arg;
    2567                 :          0 :     return_value = _codecs_charmap_build_impl(module, map);
    2568                 :            : 
    2569                 :          0 : exit:
    2570                 :          0 :     return return_value;
    2571                 :            : }
    2572                 :            : 
    2573                 :            : #if defined(MS_WINDOWS)
    2574                 :            : 
    2575                 :            : PyDoc_STRVAR(_codecs_mbcs_encode__doc__,
    2576                 :            : "mbcs_encode($module, str, errors=None, /)\n"
    2577                 :            : "--\n"
    2578                 :            : "\n");
    2579                 :            : 
    2580                 :            : #define _CODECS_MBCS_ENCODE_METHODDEF    \
    2581                 :            :     {"mbcs_encode", _PyCFunction_CAST(_codecs_mbcs_encode), METH_FASTCALL, _codecs_mbcs_encode__doc__},
    2582                 :            : 
    2583                 :            : static PyObject *
    2584                 :            : _codecs_mbcs_encode_impl(PyObject *module, PyObject *str, const char *errors);
    2585                 :            : 
    2586                 :            : static PyObject *
    2587                 :            : _codecs_mbcs_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
    2588                 :            : {
    2589                 :            :     PyObject *return_value = NULL;
    2590                 :            :     PyObject *str;
    2591                 :            :     const char *errors = NULL;
    2592                 :            : 
    2593                 :            :     if (!_PyArg_CheckPositional("mbcs_encode", nargs, 1, 2)) {
    2594                 :            :         goto exit;
    2595                 :            :     }
    2596                 :            :     if (!PyUnicode_Check(args[0])) {
    2597                 :            :         _PyArg_BadArgument("mbcs_encode", "argument 1", "str", args[0]);
    2598                 :            :         goto exit;
    2599                 :            :     }
    2600                 :            :     if (PyUnicode_READY(args[0]) == -1) {
    2601                 :            :         goto exit;
    2602                 :            :     }
    2603                 :            :     str = args[0];
    2604                 :            :     if (nargs < 2) {
    2605                 :            :         goto skip_optional;
    2606                 :            :     }
    2607                 :            :     if (args[1] == Py_None) {
    2608                 :            :         errors = NULL;
    2609                 :            :     }
    2610                 :            :     else if (PyUnicode_Check(args[1])) {
    2611                 :            :         Py_ssize_t errors_length;
    2612                 :            :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
    2613                 :            :         if (errors == NULL) {
    2614                 :            :             goto exit;
    2615                 :            :         }
    2616                 :            :         if (strlen(errors) != (size_t)errors_length) {
    2617                 :            :             PyErr_SetString(PyExc_ValueError, "embedded null character");
    2618                 :            :             goto exit;
    2619                 :            :         }
    2620                 :            :     }
    2621                 :            :     else {
    2622                 :            :         _PyArg_BadArgument("mbcs_encode", "argument 2", "str or None", args[1]);
    2623                 :            :         goto exit;
    2624                 :            :     }
    2625                 :            : skip_optional:
    2626                 :            :     return_value = _codecs_mbcs_encode_impl(module, str, errors);
    2627                 :            : 
    2628                 :            : exit:
    2629                 :            :     return return_value;
    2630                 :            : }
    2631                 :            : 
    2632                 :            : #endif /* defined(MS_WINDOWS) */
    2633                 :            : 
    2634                 :            : #if defined(MS_WINDOWS)
    2635                 :            : 
    2636                 :            : PyDoc_STRVAR(_codecs_oem_encode__doc__,
    2637                 :            : "oem_encode($module, str, errors=None, /)\n"
    2638                 :            : "--\n"
    2639                 :            : "\n");
    2640                 :            : 
    2641                 :            : #define _CODECS_OEM_ENCODE_METHODDEF    \
    2642                 :            :     {"oem_encode", _PyCFunction_CAST(_codecs_oem_encode), METH_FASTCALL, _codecs_oem_encode__doc__},
    2643                 :            : 
    2644                 :            : static PyObject *
    2645                 :            : _codecs_oem_encode_impl(PyObject *module, PyObject *str, const char *errors);
    2646                 :            : 
    2647                 :            : static PyObject *
    2648                 :            : _codecs_oem_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
    2649                 :            : {
    2650                 :            :     PyObject *return_value = NULL;
    2651                 :            :     PyObject *str;
    2652                 :            :     const char *errors = NULL;
    2653                 :            : 
    2654                 :            :     if (!_PyArg_CheckPositional("oem_encode", nargs, 1, 2)) {
    2655                 :            :         goto exit;
    2656                 :            :     }
    2657                 :            :     if (!PyUnicode_Check(args[0])) {
    2658                 :            :         _PyArg_BadArgument("oem_encode", "argument 1", "str", args[0]);
    2659                 :            :         goto exit;
    2660                 :            :     }
    2661                 :            :     if (PyUnicode_READY(args[0]) == -1) {
    2662                 :            :         goto exit;
    2663                 :            :     }
    2664                 :            :     str = args[0];
    2665                 :            :     if (nargs < 2) {
    2666                 :            :         goto skip_optional;
    2667                 :            :     }
    2668                 :            :     if (args[1] == Py_None) {
    2669                 :            :         errors = NULL;
    2670                 :            :     }
    2671                 :            :     else if (PyUnicode_Check(args[1])) {
    2672                 :            :         Py_ssize_t errors_length;
    2673                 :            :         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
    2674                 :            :         if (errors == NULL) {
    2675                 :            :             goto exit;
    2676                 :            :         }
    2677                 :            :         if (strlen(errors) != (size_t)errors_length) {
    2678                 :            :             PyErr_SetString(PyExc_ValueError, "embedded null character");
    2679                 :            :             goto exit;
    2680                 :            :         }
    2681                 :            :     }
    2682                 :            :     else {
    2683                 :            :         _PyArg_BadArgument("oem_encode", "argument 2", "str or None", args[1]);
    2684                 :            :         goto exit;
    2685                 :            :     }
    2686                 :            : skip_optional:
    2687                 :            :     return_value = _codecs_oem_encode_impl(module, str, errors);
    2688                 :            : 
    2689                 :            : exit:
    2690                 :            :     return return_value;
    2691                 :            : }
    2692                 :            : 
    2693                 :            : #endif /* defined(MS_WINDOWS) */
    2694                 :            : 
    2695                 :            : #if defined(MS_WINDOWS)
    2696                 :            : 
    2697                 :            : PyDoc_STRVAR(_codecs_code_page_encode__doc__,
    2698                 :            : "code_page_encode($module, code_page, str, errors=None, /)\n"
    2699                 :            : "--\n"
    2700                 :            : "\n");
    2701                 :            : 
    2702                 :            : #define _CODECS_CODE_PAGE_ENCODE_METHODDEF    \
    2703                 :            :     {"code_page_encode", _PyCFunction_CAST(_codecs_code_page_encode), METH_FASTCALL, _codecs_code_page_encode__doc__},
    2704                 :            : 
    2705                 :            : static PyObject *
    2706                 :            : _codecs_code_page_encode_impl(PyObject *module, int code_page, PyObject *str,
    2707                 :            :                               const char *errors);
    2708                 :            : 
    2709                 :            : static PyObject *
    2710                 :            : _codecs_code_page_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
    2711                 :            : {
    2712                 :            :     PyObject *return_value = NULL;
    2713                 :            :     int code_page;
    2714                 :            :     PyObject *str;
    2715                 :            :     const char *errors = NULL;
    2716                 :            : 
    2717                 :            :     if (!_PyArg_CheckPositional("code_page_encode", nargs, 2, 3)) {
    2718                 :            :         goto exit;
    2719                 :            :     }
    2720                 :            :     code_page = _PyLong_AsInt(args[0]);
    2721                 :            :     if (code_page == -1 && PyErr_Occurred()) {
    2722                 :            :         goto exit;
    2723                 :            :     }
    2724                 :            :     if (!PyUnicode_Check(args[1])) {
    2725                 :            :         _PyArg_BadArgument("code_page_encode", "argument 2", "str", args[1]);
    2726                 :            :         goto exit;
    2727                 :            :     }
    2728                 :            :     if (PyUnicode_READY(args[1]) == -1) {
    2729                 :            :         goto exit;
    2730                 :            :     }
    2731                 :            :     str = args[1];
    2732                 :            :     if (nargs < 3) {
    2733                 :            :         goto skip_optional;
    2734                 :            :     }
    2735                 :            :     if (args[2] == Py_None) {
    2736                 :            :         errors = NULL;
    2737                 :            :     }
    2738                 :            :     else if (PyUnicode_Check(args[2])) {
    2739                 :            :         Py_ssize_t errors_length;
    2740                 :            :         errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length);
    2741                 :            :         if (errors == NULL) {
    2742                 :            :             goto exit;
    2743                 :            :         }
    2744                 :            :         if (strlen(errors) != (size_t)errors_length) {
    2745                 :            :             PyErr_SetString(PyExc_ValueError, "embedded null character");
    2746                 :            :             goto exit;
    2747                 :            :         }
    2748                 :            :     }
    2749                 :            :     else {
    2750                 :            :         _PyArg_BadArgument("code_page_encode", "argument 3", "str or None", args[2]);
    2751                 :            :         goto exit;
    2752                 :            :     }
    2753                 :            : skip_optional:
    2754                 :            :     return_value = _codecs_code_page_encode_impl(module, code_page, str, errors);
    2755                 :            : 
    2756                 :            : exit:
    2757                 :            :     return return_value;
    2758                 :            : }
    2759                 :            : 
    2760                 :            : #endif /* defined(MS_WINDOWS) */
    2761                 :            : 
    2762                 :            : PyDoc_STRVAR(_codecs_register_error__doc__,
    2763                 :            : "register_error($module, errors, handler, /)\n"
    2764                 :            : "--\n"
    2765                 :            : "\n"
    2766                 :            : "Register the specified error handler under the name errors.\n"
    2767                 :            : "\n"
    2768                 :            : "handler must be a callable object, that will be called with an exception\n"
    2769                 :            : "instance containing information about the location of the encoding/decoding\n"
    2770                 :            : "error and must return a (replacement, new position) tuple.");
    2771                 :            : 
    2772                 :            : #define _CODECS_REGISTER_ERROR_METHODDEF    \
    2773                 :            :     {"register_error", _PyCFunction_CAST(_codecs_register_error), METH_FASTCALL, _codecs_register_error__doc__},
    2774                 :            : 
    2775                 :            : static PyObject *
    2776                 :            : _codecs_register_error_impl(PyObject *module, const char *errors,
    2777                 :            :                             PyObject *handler);
    2778                 :            : 
    2779                 :            : static PyObject *
    2780                 :          0 : _codecs_register_error(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
    2781                 :            : {
    2782                 :          0 :     PyObject *return_value = NULL;
    2783                 :            :     const char *errors;
    2784                 :            :     PyObject *handler;
    2785                 :            : 
    2786   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("register_error", nargs, 2, 2)) {
                   #  # ]
    2787                 :          0 :         goto exit;
    2788                 :            :     }
    2789         [ #  # ]:          0 :     if (!PyUnicode_Check(args[0])) {
    2790                 :          0 :         _PyArg_BadArgument("register_error", "argument 1", "str", args[0]);
    2791                 :          0 :         goto exit;
    2792                 :            :     }
    2793                 :            :     Py_ssize_t errors_length;
    2794                 :          0 :     errors = PyUnicode_AsUTF8AndSize(args[0], &errors_length);
    2795         [ #  # ]:          0 :     if (errors == NULL) {
    2796                 :          0 :         goto exit;
    2797                 :            :     }
    2798         [ #  # ]:          0 :     if (strlen(errors) != (size_t)errors_length) {
    2799                 :          0 :         PyErr_SetString(PyExc_ValueError, "embedded null character");
    2800                 :          0 :         goto exit;
    2801                 :            :     }
    2802                 :          0 :     handler = args[1];
    2803                 :          0 :     return_value = _codecs_register_error_impl(module, errors, handler);
    2804                 :            : 
    2805                 :          0 : exit:
    2806                 :          0 :     return return_value;
    2807                 :            : }
    2808                 :            : 
    2809                 :            : PyDoc_STRVAR(_codecs_lookup_error__doc__,
    2810                 :            : "lookup_error($module, name, /)\n"
    2811                 :            : "--\n"
    2812                 :            : "\n"
    2813                 :            : "lookup_error(errors) -> handler\n"
    2814                 :            : "\n"
    2815                 :            : "Return the error handler for the specified error handling name or raise a\n"
    2816                 :            : "LookupError, if no handler exists under this name.");
    2817                 :            : 
    2818                 :            : #define _CODECS_LOOKUP_ERROR_METHODDEF    \
    2819                 :            :     {"lookup_error", (PyCFunction)_codecs_lookup_error, METH_O, _codecs_lookup_error__doc__},
    2820                 :            : 
    2821                 :            : static PyObject *
    2822                 :            : _codecs_lookup_error_impl(PyObject *module, const char *name);
    2823                 :            : 
    2824                 :            : static PyObject *
    2825                 :        150 : _codecs_lookup_error(PyObject *module, PyObject *arg)
    2826                 :            : {
    2827                 :        150 :     PyObject *return_value = NULL;
    2828                 :            :     const char *name;
    2829                 :            : 
    2830         [ -  + ]:        150 :     if (!PyUnicode_Check(arg)) {
    2831                 :          0 :         _PyArg_BadArgument("lookup_error", "argument", "str", arg);
    2832                 :          0 :         goto exit;
    2833                 :            :     }
    2834                 :            :     Py_ssize_t name_length;
    2835                 :        150 :     name = PyUnicode_AsUTF8AndSize(arg, &name_length);
    2836         [ -  + ]:        150 :     if (name == NULL) {
    2837                 :          0 :         goto exit;
    2838                 :            :     }
    2839         [ -  + ]:        150 :     if (strlen(name) != (size_t)name_length) {
    2840                 :          0 :         PyErr_SetString(PyExc_ValueError, "embedded null character");
    2841                 :          0 :         goto exit;
    2842                 :            :     }
    2843                 :        150 :     return_value = _codecs_lookup_error_impl(module, name);
    2844                 :            : 
    2845                 :        150 : exit:
    2846                 :        150 :     return return_value;
    2847                 :            : }
    2848                 :            : 
    2849                 :            : #ifndef _CODECS_MBCS_DECODE_METHODDEF
    2850                 :            :     #define _CODECS_MBCS_DECODE_METHODDEF
    2851                 :            : #endif /* !defined(_CODECS_MBCS_DECODE_METHODDEF) */
    2852                 :            : 
    2853                 :            : #ifndef _CODECS_OEM_DECODE_METHODDEF
    2854                 :            :     #define _CODECS_OEM_DECODE_METHODDEF
    2855                 :            : #endif /* !defined(_CODECS_OEM_DECODE_METHODDEF) */
    2856                 :            : 
    2857                 :            : #ifndef _CODECS_CODE_PAGE_DECODE_METHODDEF
    2858                 :            :     #define _CODECS_CODE_PAGE_DECODE_METHODDEF
    2859                 :            : #endif /* !defined(_CODECS_CODE_PAGE_DECODE_METHODDEF) */
    2860                 :            : 
    2861                 :            : #ifndef _CODECS_MBCS_ENCODE_METHODDEF
    2862                 :            :     #define _CODECS_MBCS_ENCODE_METHODDEF
    2863                 :            : #endif /* !defined(_CODECS_MBCS_ENCODE_METHODDEF) */
    2864                 :            : 
    2865                 :            : #ifndef _CODECS_OEM_ENCODE_METHODDEF
    2866                 :            :     #define _CODECS_OEM_ENCODE_METHODDEF
    2867                 :            : #endif /* !defined(_CODECS_OEM_ENCODE_METHODDEF) */
    2868                 :            : 
    2869                 :            : #ifndef _CODECS_CODE_PAGE_ENCODE_METHODDEF
    2870                 :            :     #define _CODECS_CODE_PAGE_ENCODE_METHODDEF
    2871                 :            : #endif /* !defined(_CODECS_CODE_PAGE_ENCODE_METHODDEF) */
    2872                 :            : /*[clinic end generated code: output=603da07cf8dfeb4b input=a9049054013a1b77]*/

Generated by: LCOV version 1.14