Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-91102: Use Argument Clinic for EncodingMap #31725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use Argument Clinic for :class:`EncodingMap`. Patch by Oleg Iarygin.
20 changes: 19 additions & 1 deletion Objects/clinic/unicodeobject.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 23 additions & 47 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ static const unsigned char ascii_linebreak[] = {

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

struct encoding_map;
#include "clinic/unicodeobject.c.h"

_Py_error_handler
Expand Down Expand Up @@ -8331,69 +8332,44 @@ PyUnicode_DecodeCharmap(const char *s,

/* Charmap encoding: the lookup table */

/*[clinic input]
class EncodingMap "struct encoding_map *" "&EncodingMapType"
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=14e46bbb6c522d22]*/

struct encoding_map {
PyObject_HEAD
unsigned char level1[32];
int count2, count3;
unsigned char level23[1];
};

static PyObject*
encoding_map_size(PyObject *obj, PyObject* args)
/*[clinic input]
EncodingMap.size

Return the size (in bytes) of this object.
[clinic start generated code]*/

static PyObject *
EncodingMap_size_impl(struct encoding_map *self)
/*[clinic end generated code: output=c4c969e4c99342a4 input=004ff13f26bb5366]*/
{
struct encoding_map *map = (struct encoding_map*)obj;
return PyLong_FromLong(sizeof(*map) - 1 + 16*map->count2 +
128*map->count3);
return PyLong_FromLong((sizeof(*self) - 1) + 16*self->count2 +
128*self->count3);
}

static PyMethodDef encoding_map_methods[] = {
{"size", encoding_map_size, METH_NOARGS,
PyDoc_STR("Return the size (in bytes) of this object") },
{ 0 }
ENCODINGMAP_SIZE_METHODDEF
{NULL, NULL}
};

static PyTypeObject EncodingMapType = {
PyVarObject_HEAD_INIT(NULL, 0)
"EncodingMap", /*tp_name*/
sizeof(struct encoding_map), /*tp_basicsize*/
0, /*tp_itemsize*/
.tp_name = "EncodingMap",
.tp_basicsize = sizeof(struct encoding_map),
/* methods */
0, /*tp_dealloc*/
0, /*tp_vectorcall_offset*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_as_async*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash*/
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT, /*tp_flags*/
0, /*tp_doc*/
0, /*tp_traverse*/
0, /*tp_clear*/
0, /*tp_richcompare*/
0, /*tp_weaklistoffset*/
0, /*tp_iter*/
0, /*tp_iternext*/
encoding_map_methods, /*tp_methods*/
0, /*tp_members*/
0, /*tp_getset*/
0, /*tp_base*/
0, /*tp_dict*/
0, /*tp_descr_get*/
0, /*tp_descr_set*/
0, /*tp_dictoffset*/
0, /*tp_init*/
0, /*tp_alloc*/
0, /*tp_new*/
0, /*tp_free*/
0, /*tp_is_gc*/
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_methods = encoding_map_methods,
};

PyObject*
Expand Down