Skip to content

Commit 2f0fc52

Browse files
gh-91102: Use Argument Clinic for EncodingMap (#31725)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
1 parent dbd9d75 commit 2f0fc52

File tree

3 files changed

+43
-48
lines changed

3 files changed

+43
-48
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use Argument Clinic for :class:`EncodingMap`. Patch by Oleg Iarygin.

Objects/clinic/unicodeobject.c.h

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Objects/unicodeobject.c

Lines changed: 23 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ static const unsigned char ascii_linebreak[] = {
397397

398398
static int convert_uc(PyObject *obj, void *addr);
399399

400+
struct encoding_map;
400401
#include "clinic/unicodeobject.c.h"
401402

402403
_Py_error_handler
@@ -8331,69 +8332,44 @@ PyUnicode_DecodeCharmap(const char *s,
83318332

83328333
/* Charmap encoding: the lookup table */
83338334

8335+
/*[clinic input]
8336+
class EncodingMap "struct encoding_map *" "&EncodingMapType"
8337+
[clinic start generated code]*/
8338+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=14e46bbb6c522d22]*/
8339+
83348340
struct encoding_map {
83358341
PyObject_HEAD
83368342
unsigned char level1[32];
83378343
int count2, count3;
83388344
unsigned char level23[1];
83398345
};
83408346

8341-
static PyObject*
8342-
encoding_map_size(PyObject *obj, PyObject* args)
8347+
/*[clinic input]
8348+
EncodingMap.size
8349+
8350+
Return the size (in bytes) of this object.
8351+
[clinic start generated code]*/
8352+
8353+
static PyObject *
8354+
EncodingMap_size_impl(struct encoding_map *self)
8355+
/*[clinic end generated code: output=c4c969e4c99342a4 input=004ff13f26bb5366]*/
83438356
{
8344-
struct encoding_map *map = (struct encoding_map*)obj;
8345-
return PyLong_FromLong(sizeof(*map) - 1 + 16*map->count2 +
8346-
128*map->count3);
8357+
return PyLong_FromLong((sizeof(*self) - 1) + 16*self->count2 +
8358+
128*self->count3);
83478359
}
83488360

83498361
static PyMethodDef encoding_map_methods[] = {
8350-
{"size", encoding_map_size, METH_NOARGS,
8351-
PyDoc_STR("Return the size (in bytes) of this object") },
8352-
{ 0 }
8362+
ENCODINGMAP_SIZE_METHODDEF
8363+
{NULL, NULL}
83538364
};
83548365

83558366
static PyTypeObject EncodingMapType = {
83568367
PyVarObject_HEAD_INIT(NULL, 0)
8357-
"EncodingMap", /*tp_name*/
8358-
sizeof(struct encoding_map), /*tp_basicsize*/
8359-
0, /*tp_itemsize*/
8368+
.tp_name = "EncodingMap",
8369+
.tp_basicsize = sizeof(struct encoding_map),
83608370
/* methods */
8361-
0, /*tp_dealloc*/
8362-
0, /*tp_vectorcall_offset*/
8363-
0, /*tp_getattr*/
8364-
0, /*tp_setattr*/
8365-
0, /*tp_as_async*/
8366-
0, /*tp_repr*/
8367-
0, /*tp_as_number*/
8368-
0, /*tp_as_sequence*/
8369-
0, /*tp_as_mapping*/
8370-
0, /*tp_hash*/
8371-
0, /*tp_call*/
8372-
0, /*tp_str*/
8373-
0, /*tp_getattro*/
8374-
0, /*tp_setattro*/
8375-
0, /*tp_as_buffer*/
8376-
Py_TPFLAGS_DEFAULT, /*tp_flags*/
8377-
0, /*tp_doc*/
8378-
0, /*tp_traverse*/
8379-
0, /*tp_clear*/
8380-
0, /*tp_richcompare*/
8381-
0, /*tp_weaklistoffset*/
8382-
0, /*tp_iter*/
8383-
0, /*tp_iternext*/
8384-
encoding_map_methods, /*tp_methods*/
8385-
0, /*tp_members*/
8386-
0, /*tp_getset*/
8387-
0, /*tp_base*/
8388-
0, /*tp_dict*/
8389-
0, /*tp_descr_get*/
8390-
0, /*tp_descr_set*/
8391-
0, /*tp_dictoffset*/
8392-
0, /*tp_init*/
8393-
0, /*tp_alloc*/
8394-
0, /*tp_new*/
8395-
0, /*tp_free*/
8396-
0, /*tp_is_gc*/
8371+
.tp_flags = Py_TPFLAGS_DEFAULT,
8372+
.tp_methods = encoding_map_methods,
83978373
};
83988374

83998375
PyObject*

0 commit comments

Comments
 (0)