#3247: get rid of Py_FindMethod · pythoncapi/cpython@1f900f1 · GitHub
Skip to content

Commit 1f900f1

Browse files
committed
python#3247: get rid of Py_FindMethod
Third step: unix-only modules. Really remove the function this time.
1 parent 7c265a1 commit 1f900f1

8 files changed

Lines changed: 105 additions & 96 deletions

File tree

Include/methodobject.h

Lines changed: 0 additions & 10 deletions

Modules/_curses_panel.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,6 @@ static PyMethodDef PyCursesPanel_Methods[] = {
329329
{NULL, NULL} /* sentinel */
330330
};
331331

332-
static PyObject *
333-
PyCursesPanel_GetAttr(PyCursesPanelObject *self, char *name)
334-
{
335-
return Py_FindMethod(PyCursesPanel_Methods, (PyObject *)self, name);
336-
}
337-
338332
/* -------------------------------------------------------*/
339333

340334
PyTypeObject PyCursesPanel_Type = {
@@ -345,14 +339,28 @@ PyTypeObject PyCursesPanel_Type = {
345339
/* methods */
346340
(destructor)PyCursesPanel_Dealloc, /*tp_dealloc*/
347341
0, /*tp_print*/
348-
(getattrfunc)PyCursesPanel_GetAttr, /*tp_getattr*/
349-
(setattrfunc)0, /*tp_setattr*/
342+
0, /*tp_getattr*/
343+
0, /*tp_setattr*/
350344
0, /*tp_compare*/
351345
0, /*tp_repr*/
352346
0, /*tp_as_number*/
353347
0, /*tp_as_sequence*/
354348
0, /*tp_as_mapping*/
355349
0, /*tp_hash*/
350+
0, /*tp_call*/
351+
0, /*tp_str*/
352+
0, /*tp_getattro*/
353+
0, /*tp_setattro*/
354+
0, /*tp_as_buffer*/
355+
Py_TPFLAGS_DEFAULT, /*tp_flags*/
356+
0, /*tp_doc*/
357+
0, /*tp_traverse*/
358+
0, /*tp_clear*/
359+
0, /*tp_richcompare*/
360+
0, /*tp_weaklistoffset*/
361+
0, /*tp_iter*/
362+
0, /*tp_iternext*/
363+
PyCursesPanel_Methods, /*tp_methods*/
356364
};
357365

358366
/* Wrapper for panel_above(NULL). This function returns the bottom
@@ -470,7 +478,8 @@ PyInit__curses_panel(void)
470478
PyObject *m, *d, *v;
471479

472480
/* Initialize object type */
473-
Py_TYPE(&PyCursesPanel_Type) = &PyType_Type;
481+
if (PyType_Ready(&PyCursesPanel_Type) < 0)
482+
return NULL;
474483

475484
import_curses();
476485

Modules/_cursesmodule.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,12 +1650,6 @@ static PyMethodDef PyCursesWindow_Methods[] = {
16501650
{NULL, NULL} /* sentinel */
16511651
};
16521652

1653-
static PyObject *
1654-
PyCursesWindow_GetAttr(PyCursesWindowObject *self, char *name)
1655-
{
1656-
return Py_FindMethod(PyCursesWindow_Methods, (PyObject *)self, name);
1657-
}
1658-
16591653
/* -------------------------------------------------------*/
16601654

16611655
PyTypeObject PyCursesWindow_Type = {
@@ -1666,14 +1660,28 @@ PyTypeObject PyCursesWindow_Type = {
16661660
/* methods */
16671661
(destructor)PyCursesWindow_Dealloc, /*tp_dealloc*/
16681662
0, /*tp_print*/
1669-
(getattrfunc)PyCursesWindow_GetAttr, /*tp_getattr*/
1670-
(setattrfunc)0, /*tp_setattr*/
1663+
(getattrfunc)0, /*tp_getattr*/
1664+
(setattrfunc)0, /*tp_setattr*/
16711665
0, /*tp_compare*/
16721666
0, /*tp_repr*/
16731667
0, /*tp_as_number*/
16741668
0, /*tp_as_sequence*/
16751669
0, /*tp_as_mapping*/
16761670
0, /*tp_hash*/
1671+
0, /*tp_call*/
1672+
0, /*tp_str*/
1673+
0, /*tp_getattro*/
1674+
0, /*tp_setattro*/
1675+
0, /*tp_as_buffer*/
1676+
Py_TPFLAGS_DEFAULT, /*tp_flags*/
1677+
0, /*tp_doc*/
1678+
0, /*tp_traverse*/
1679+
0, /*tp_clear*/
1680+
0, /*tp_richcompare*/
1681+
0, /*tp_weaklistoffset*/
1682+
0, /*tp_iter*/
1683+
0, /*tp_iternext*/
1684+
PyCursesWindow_Methods, /*tp_methods*/
16771685
};
16781686

16791687
/*********************************************************************
@@ -2792,7 +2800,8 @@ PyInit__curses(void)
27922800
static void *PyCurses_API[PyCurses_API_pointers];
27932801

27942802
/* Initialize object type */
2795-
Py_TYPE(&PyCursesWindow_Type) = &PyType_Type;
2803+
if (PyType_Ready(&PyCursesWindow_Type) < 0)
2804+
return NULL;
27962805

27972806
/* Initialize the C API pointer array */
27982807
PyCurses_API[0] = (void *)&PyCursesWindow_Type;

Modules/_dbmmodule.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -324,20 +324,14 @@ static PyMethodDef dbm_methods[] = {
324324
{NULL, NULL} /* sentinel */
325325
};
326326

327-
static PyObject *
328-
dbm_getattr(dbmobject *dp, char *name)
329-
{
330-
return Py_FindMethod(dbm_methods, (PyObject *)dp, name);
331-
}
332-
333327
static PyTypeObject Dbmtype = {
334328
PyVarObject_HEAD_INIT(NULL, 0)
335329
"_dbm.dbm",
336330
sizeof(dbmobject),
337331
0,
338332
(destructor)dbm_dealloc, /*tp_dealloc*/
339333
0, /*tp_print*/
340-
(getattrfunc)dbm_getattr, /*tp_getattr*/
334+
0, /*tp_getattr*/
341335
0, /*tp_setattr*/
342336
0, /*tp_compare*/
343337
0, /*tp_repr*/
@@ -350,7 +344,15 @@ static PyTypeObject Dbmtype = {
350344
0, /*tp_getattro*/
351345
0, /*tp_setattro*/
352346
0, /*tp_as_buffer*/
353-
Py_TPFLAGS_DEFAULT, /*tp_xxx4*/
347+
Py_TPFLAGS_DEFAULT, /*tp_flags*/
348+
0, /*tp_doc*/
349+
0, /*tp_traverse*/
350+
0, /*tp_clear*/
351+
0, /*tp_richcompare*/
352+
0, /*tp_weaklistoffset*/
353+
0, /*tp_iter*/
354+
0, /*tp_iternext*/
355+
dbm_methods, /*tp_methods*/
354356
};
355357

356358
/* ----------------------------------------------------------------- */

Modules/_gdbmmodule.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -381,20 +381,14 @@ static PyMethodDef dbm_methods[] = {
381381
{NULL, NULL} /* sentinel */
382382
};
383383

384-
static PyObject *
385-
dbm_getattr(dbmobject *dp, char *name)
386-
{
387-
return Py_FindMethod(dbm_methods, (PyObject *)dp, name);
388-
}
389-
390384
static PyTypeObject Dbmtype = {
391385
PyVarObject_HEAD_INIT(0, 0)
392386
"_gdbm.gdbm",
393387
sizeof(dbmobject),
394388
0,
395389
(destructor)dbm_dealloc, /*tp_dealloc*/
396390
0, /*tp_print*/
397-
(getattrfunc)dbm_getattr, /*tp_getattr*/
391+
0, /*tp_getattr*/
398392
0, /*tp_setattr*/
399393
0, /*tp_compare*/
400394
0, /*tp_repr*/
@@ -409,6 +403,13 @@ static PyTypeObject Dbmtype = {
409403
0, /*tp_as_buffer*/
410404
Py_TPFLAGS_DEFAULT, /*tp_xxx4*/
411405
gdbm_object__doc__, /*tp_doc*/
406+
0, /*tp_traverse*/
407+
0, /*tp_clear*/
408+
0, /*tp_richcompare*/
409+
0, /*tp_weaklistoffset*/
410+
0, /*tp_iter*/
411+
0, /*tp_iternext*/
412+
dbm_methods, /*tp_methods*/
412413
};
413414

414415
/* ----------------------------------------------------------------- */

Modules/ossaudiodev.c

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -803,9 +803,14 @@ static PyMethodDef oss_mixer_methods[] = {
803803
};
804804

805805
static PyObject *
806-
oss_getattr(oss_audio_t *self, char *name)
806+
oss_getattro(oss_audio_t *self, PyObject *nameobj)
807807
{
808+
char *name = "";
808809
PyObject * rval = NULL;
810+
811+
if (PyUnicode_Check(nameobj))
812+
name = PyUnicode_AsString(nameobj);
813+
809814
if (strcmp(name, "closed") == 0) {
810815
rval = (self->fd == -1) ? Py_True : Py_False;
811816
Py_INCREF(rval);
@@ -829,17 +834,11 @@ oss_getattr(oss_audio_t *self, char *name)
829834
}
830835
}
831836
else {
832-
rval = Py_FindMethod(oss_methods, (PyObject *)self, name);
837+
rval = PyObject_GenericGetAttr((PyObject *)self, nameobj);
833838
}
834839
return rval;
835840
}
836841

837-
static PyObject *
838-
oss_mixer_getattr(oss_mixer_t *self, char *name)
839-
{
840-
return Py_FindMethod(oss_mixer_methods, (PyObject *)self, name);
841-
}
842-
843842
static PyTypeObject OSSAudioType = {
844843
PyVarObject_HEAD_INIT(&PyType_Type, 0)
845844
"ossaudiodev.oss_audio_device", /*tp_name*/
@@ -848,10 +847,28 @@ static PyTypeObject OSSAudioType = {
848847
/* methods */
849848
(destructor)oss_dealloc, /*tp_dealloc*/
850849
0, /*tp_print*/
851-
(getattrfunc)oss_getattr, /*tp_getattr*/
850+
0, /*tp_getattr*/
852851
0, /*tp_setattr*/
853852
0, /*tp_compare*/
854853
0, /*tp_repr*/
854+
0, /*tp_as_number*/
855+
0, /*tp_as_sequence*/
856+
0, /*tp_as_mapping*/
857+
0, /*tp_hash*/
858+
0, /*tp_call*/
859+
0, /*tp_str*/
860+
(getattrofunc)oss_getattro, /*tp_getattro*/
861+
0, /*tp_setattro*/
862+
0, /*tp_as_buffer*/
863+
Py_TPFLAGS_DEFAULT, /*tp_flags*/
864+
0, /*tp_doc*/
865+
0, /*tp_traverse*/
866+
0, /*tp_clear*/
867+
0, /*tp_richcompare*/
868+
0, /*tp_weaklistoffset*/
869+
0, /*tp_iter*/
870+
0, /*tp_iternext*/
871+
oss_methods, /*tp_methods*/
855872
};
856873

857874
static PyTypeObject OSSMixerType = {
@@ -862,10 +879,28 @@ static PyTypeObject OSSMixerType = {
862879
/* methods */
863880
(destructor)oss_mixer_dealloc, /*tp_dealloc*/
864881
0, /*tp_print*/
865-
(getattrfunc)oss_mixer_getattr, /*tp_getattr*/
882+
0, /*tp_getattr*/
866883
0, /*tp_setattr*/
867884
0, /*tp_compare*/
868885
0, /*tp_repr*/
886+
0, /*tp_as_number*/
887+
0, /*tp_as_sequence*/
888+
0, /*tp_as_mapping*/
889+
0, /*tp_hash*/
890+
0, /*tp_call*/
891+
0, /*tp_str*/
892+
0, /*tp_getattro*/
893+
0, /*tp_setattro*/
894+
0, /*tp_as_buffer*/
895+
Py_TPFLAGS_DEFAULT, /*tp_flags*/
896+
0, /*tp_doc*/
897+
0, /*tp_traverse*/
898+
0, /*tp_clear*/
899+
0, /*tp_richcompare*/
900+
0, /*tp_weaklistoffset*/
901+
0, /*tp_iter*/
902+
0, /*tp_iternext*/
903+
oss_mixer_methods, /*tp_methods*/
869904
};
870905

871906

Modules/xxmodule.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@ static PyMethodDef Xxo_methods[] = {
6363
};
6464

6565
static PyObject *
66-
Xxo_getattr(XxoObject *self, char *name)
66+
Xxo_getattro(XxoObject *self, PyObject *name)
6767
{
6868
if (self->x_attr != NULL) {
69-
PyObject *v = PyDict_GetItemString(self->x_attr, name);
69+
PyObject *v = PyDict_GetItem(self->x_attr, name);
7070
if (v != NULL) {
7171
Py_INCREF(v);
7272
return v;
7373
}
7474
}
75-
return Py_FindMethod(Xxo_methods, (PyObject *)self, name);
75+
return PyObject_GenericGetattr((PyObject *)self, name);
7676
}
7777

7878
static int
@@ -104,7 +104,7 @@ static PyTypeObject Xxo_Type = {
104104
/* methods */
105105
(destructor)Xxo_dealloc, /*tp_dealloc*/
106106
0, /*tp_print*/
107-
(getattrfunc)Xxo_getattr, /*tp_getattr*/
107+
(getattrfunc)0, /*tp_getattr*/
108108
(setattrfunc)Xxo_setattr, /*tp_setattr*/
109109
0, /*tp_compare*/
110110
0, /*tp_repr*/
@@ -114,7 +114,7 @@ static PyTypeObject Xxo_Type = {
114114
0, /*tp_hash*/
115115
0, /*tp_call*/
116116
0, /*tp_str*/
117-
0, /*tp_getattro*/
117+
(getattrofunc)Xxo_getattro, /*tp_getattro*/
118118
0, /*tp_setattro*/
119119
0, /*tp_as_buffer*/
120120
Py_TPFLAGS_DEFAULT, /*tp_flags*/
@@ -125,7 +125,7 @@ static PyTypeObject Xxo_Type = {
125125
0, /*tp_weaklistoffset*/
126126
0, /*tp_iter*/
127127
0, /*tp_iternext*/
128-
0, /*tp_methods*/
128+
Xxo_methods, /*tp_methods*/
129129
0, /*tp_members*/
130130
0, /*tp_getset*/
131131
0, /*tp_base*/

Objects/methodobject.c

Lines changed: 0 additions & 37 deletions

0 commit comments

Comments
 (0)