Skip to content

Commit 3ee474f

Browse files
authored
gh-111178: Fix function signatures in codeobject.c (#125180)
1 parent eb18574 commit 3ee474f

File tree

1 file changed

+48
-32
lines changed

1 file changed

+48
-32
lines changed

Objects/codeobject.c

+48-32
Original file line numberDiff line numberDiff line change
@@ -1278,8 +1278,9 @@ typedef struct {
12781278

12791279

12801280
static void
1281-
lineiter_dealloc(lineiterator *li)
1281+
lineiter_dealloc(PyObject *self)
12821282
{
1283+
lineiterator *li = (lineiterator*)self;
12831284
Py_DECREF(li->li_code);
12841285
Py_TYPE(li)->tp_free(li);
12851286
}
@@ -1293,8 +1294,9 @@ _source_offset_converter(int *value) {
12931294
}
12941295

12951296
static PyObject *
1296-
lineiter_next(lineiterator *li)
1297+
lineiter_next(PyObject *self)
12971298
{
1299+
lineiterator *li = (lineiterator*)self;
12981300
PyCodeAddressRange *bounds = &li->li_line;
12991301
if (!_PyLineTable_NextAddressRange(bounds)) {
13001302
return NULL;
@@ -1318,7 +1320,7 @@ PyTypeObject _PyLineIterator = {
13181320
sizeof(lineiterator), /* tp_basicsize */
13191321
0, /* tp_itemsize */
13201322
/* methods */
1321-
(destructor)lineiter_dealloc, /* tp_dealloc */
1323+
lineiter_dealloc, /* tp_dealloc */
13221324
0, /* tp_vectorcall_offset */
13231325
0, /* tp_getattr */
13241326
0, /* tp_setattr */
@@ -1340,7 +1342,7 @@ PyTypeObject _PyLineIterator = {
13401342
0, /* tp_richcompare */
13411343
0, /* tp_weaklistoffset */
13421344
PyObject_SelfIter, /* tp_iter */
1343-
(iternextfunc)lineiter_next, /* tp_iternext */
1345+
lineiter_next, /* tp_iternext */
13441346
0, /* tp_methods */
13451347
0, /* tp_members */
13461348
0, /* tp_getset */
@@ -1379,15 +1381,17 @@ typedef struct {
13791381
} positionsiterator;
13801382

13811383
static void
1382-
positionsiter_dealloc(positionsiterator* pi)
1384+
positionsiter_dealloc(PyObject *self)
13831385
{
1386+
positionsiterator *pi = (positionsiterator*)self;
13841387
Py_DECREF(pi->pi_code);
13851388
Py_TYPE(pi)->tp_free(pi);
13861389
}
13871390

13881391
static PyObject*
1389-
positionsiter_next(positionsiterator* pi)
1392+
positionsiter_next(PyObject *self)
13901393
{
1394+
positionsiterator *pi = (positionsiterator*)self;
13911395
if (pi->pi_offset >= pi->pi_range.ar_end) {
13921396
assert(pi->pi_offset == pi->pi_range.ar_end);
13931397
if (at_end(&pi->pi_range)) {
@@ -1409,7 +1413,7 @@ PyTypeObject _PyPositionsIterator = {
14091413
sizeof(positionsiterator), /* tp_basicsize */
14101414
0, /* tp_itemsize */
14111415
/* methods */
1412-
(destructor)positionsiter_dealloc, /* tp_dealloc */
1416+
positionsiter_dealloc, /* tp_dealloc */
14131417
0, /* tp_vectorcall_offset */
14141418
0, /* tp_getattr */
14151419
0, /* tp_setattr */
@@ -1431,7 +1435,7 @@ PyTypeObject _PyPositionsIterator = {
14311435
0, /* tp_richcompare */
14321436
0, /* tp_weaklistoffset */
14331437
PyObject_SelfIter, /* tp_iter */
1434-
(iternextfunc)positionsiter_next, /* tp_iternext */
1438+
positionsiter_next, /* tp_iternext */
14351439
0, /* tp_methods */
14361440
0, /* tp_members */
14371441
0, /* tp_getset */
@@ -1447,8 +1451,9 @@ PyTypeObject _PyPositionsIterator = {
14471451
};
14481452

14491453
static PyObject*
1450-
code_positionsiterator(PyCodeObject* code, PyObject* Py_UNUSED(args))
1454+
code_positionsiterator(PyObject *self, PyObject* Py_UNUSED(args))
14511455
{
1456+
PyCodeObject *code = (PyCodeObject*)self;
14521457
positionsiterator* pi = (positionsiterator*)PyType_GenericAlloc(&_PyPositionsIterator, 0);
14531458
if (pi == NULL) {
14541459
return NULL;
@@ -1875,16 +1880,18 @@ code_dealloc(PyCodeObject *co)
18751880

18761881
#ifdef Py_GIL_DISABLED
18771882
static int
1878-
code_traverse(PyCodeObject *co, visitproc visit, void *arg)
1883+
code_traverse(PyObject *self, visitproc visit, void *arg)
18791884
{
1885+
PyCodeObject *co = (PyCodeObject*)self;
18801886
Py_VISIT(co->co_consts);
18811887
return 0;
18821888
}
18831889
#endif
18841890

18851891
static PyObject *
1886-
code_repr(PyCodeObject *co)
1892+
code_repr(PyObject *self)
18871893
{
1894+
PyCodeObject *co = (PyCodeObject*)self;
18881895
int lineno;
18891896
if (co->co_firstlineno != 0)
18901897
lineno = co->co_firstlineno;
@@ -1991,8 +1998,9 @@ code_richcompare(PyObject *self, PyObject *other, int op)
19911998
}
19921999

19932000
static Py_hash_t
1994-
code_hash(PyCodeObject *co)
2001+
code_hash(PyObject *self)
19952002
{
2003+
PyCodeObject *co = (PyCodeObject*)self;
19962004
Py_uhash_t uhash = 20221211;
19972005
#define SCRAMBLE_IN(H) do { \
19982006
uhash ^= (Py_uhash_t)(H); \
@@ -2053,8 +2061,9 @@ static PyMemberDef code_memberlist[] = {
20532061

20542062

20552063
static PyObject *
2056-
code_getlnotab(PyCodeObject *code, void *closure)
2064+
code_getlnotab(PyObject *self, void *closure)
20572065
{
2066+
PyCodeObject *code = (PyCodeObject*)self;
20582067
if (PyErr_WarnEx(PyExc_DeprecationWarning,
20592068
"co_lnotab is deprecated, use co_lines instead.",
20602069
1) < 0) {
@@ -2064,51 +2073,57 @@ code_getlnotab(PyCodeObject *code, void *closure)
20642073
}
20652074

20662075
static PyObject *
2067-
code_getvarnames(PyCodeObject *code, void *closure)
2076+
code_getvarnames(PyObject *self, void *closure)
20682077
{
2078+
PyCodeObject *code = (PyCodeObject*)self;
20692079
return _PyCode_GetVarnames(code);
20702080
}
20712081

20722082
static PyObject *
2073-
code_getcellvars(PyCodeObject *code, void *closure)
2083+
code_getcellvars(PyObject *self, void *closure)
20742084
{
2085+
PyCodeObject *code = (PyCodeObject*)self;
20752086
return _PyCode_GetCellvars(code);
20762087
}
20772088

20782089
static PyObject *
2079-
code_getfreevars(PyCodeObject *code, void *closure)
2090+
code_getfreevars(PyObject *self, void *closure)
20802091
{
2092+
PyCodeObject *code = (PyCodeObject*)self;
20812093
return _PyCode_GetFreevars(code);
20822094
}
20832095

20842096
static PyObject *
2085-
code_getcodeadaptive(PyCodeObject *code, void *closure)
2097+
code_getcodeadaptive(PyObject *self, void *closure)
20862098
{
2099+
PyCodeObject *code = (PyCodeObject*)self;
20872100
return PyBytes_FromStringAndSize(code->co_code_adaptive,
20882101
_PyCode_NBYTES(code));
20892102
}
20902103

20912104
static PyObject *
2092-
code_getcode(PyCodeObject *code, void *closure)
2105+
code_getcode(PyObject *self, void *closure)
20932106
{
2107+
PyCodeObject *code = (PyCodeObject*)self;
20942108
return _PyCode_GetCode(code);
20952109
}
20962110

20972111
static PyGetSetDef code_getsetlist[] = {
2098-
{"co_lnotab", (getter)code_getlnotab, NULL, NULL},
2099-
{"_co_code_adaptive", (getter)code_getcodeadaptive, NULL, NULL},
2112+
{"co_lnotab", code_getlnotab, NULL, NULL},
2113+
{"_co_code_adaptive", code_getcodeadaptive, NULL, NULL},
21002114
// The following old names are kept for backward compatibility.
2101-
{"co_varnames", (getter)code_getvarnames, NULL, NULL},
2102-
{"co_cellvars", (getter)code_getcellvars, NULL, NULL},
2103-
{"co_freevars", (getter)code_getfreevars, NULL, NULL},
2104-
{"co_code", (getter)code_getcode, NULL, NULL},
2115+
{"co_varnames", code_getvarnames, NULL, NULL},
2116+
{"co_cellvars", code_getcellvars, NULL, NULL},
2117+
{"co_freevars", code_getfreevars, NULL, NULL},
2118+
{"co_code", code_getcode, NULL, NULL},
21052119
{0}
21062120
};
21072121

21082122

21092123
static PyObject *
2110-
code_sizeof(PyCodeObject *co, PyObject *Py_UNUSED(args))
2124+
code_sizeof(PyObject *self, PyObject *Py_UNUSED(args))
21112125
{
2126+
PyCodeObject *co = (PyCodeObject*)self;
21122127
size_t res = _PyObject_VAR_SIZE(Py_TYPE(co), Py_SIZE(co));
21132128
_PyCodeObjectExtra *co_extra = (_PyCodeObjectExtra*) co->co_extra;
21142129
if (co_extra != NULL) {
@@ -2119,8 +2134,9 @@ code_sizeof(PyCodeObject *co, PyObject *Py_UNUSED(args))
21192134
}
21202135

21212136
static PyObject *
2122-
code_linesiterator(PyCodeObject *code, PyObject *Py_UNUSED(args))
2137+
code_linesiterator(PyObject *self, PyObject *Py_UNUSED(args))
21232138
{
2139+
PyCodeObject *code = (PyCodeObject*)self;
21242140
return (PyObject *)new_linesiterator(code);
21252141
}
21262142

@@ -2262,9 +2278,9 @@ code__varname_from_oparg_impl(PyCodeObject *self, int oparg)
22622278
/* XXX code objects need to participate in GC? */
22632279

22642280
static struct PyMethodDef code_methods[] = {
2265-
{"__sizeof__", (PyCFunction)code_sizeof, METH_NOARGS},
2266-
{"co_lines", (PyCFunction)code_linesiterator, METH_NOARGS},
2267-
{"co_positions", (PyCFunction)code_positionsiterator, METH_NOARGS},
2281+
{"__sizeof__", code_sizeof, METH_NOARGS},
2282+
{"co_lines", code_linesiterator, METH_NOARGS},
2283+
{"co_positions", code_positionsiterator, METH_NOARGS},
22682284
CODE_REPLACE_METHODDEF
22692285
CODE__VARNAME_FROM_OPARG_METHODDEF
22702286
{"__replace__", _PyCFunction_CAST(code_replace), METH_FASTCALL|METH_KEYWORDS,
@@ -2283,11 +2299,11 @@ PyTypeObject PyCode_Type = {
22832299
0, /* tp_getattr */
22842300
0, /* tp_setattr */
22852301
0, /* tp_as_async */
2286-
(reprfunc)code_repr, /* tp_repr */
2302+
code_repr, /* tp_repr */
22872303
0, /* tp_as_number */
22882304
0, /* tp_as_sequence */
22892305
0, /* tp_as_mapping */
2290-
(hashfunc)code_hash, /* tp_hash */
2306+
code_hash, /* tp_hash */
22912307
0, /* tp_call */
22922308
0, /* tp_str */
22932309
PyObject_GenericGetAttr, /* tp_getattro */
@@ -2300,7 +2316,7 @@ PyTypeObject PyCode_Type = {
23002316
#endif
23012317
code_new__doc__, /* tp_doc */
23022318
#ifdef Py_GIL_DISABLED
2303-
(traverseproc)code_traverse, /* tp_traverse */
2319+
code_traverse, /* tp_traverse */
23042320
#else
23052321
0, /* tp_traverse */
23062322
#endif

0 commit comments

Comments
 (0)