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

Skip to content

Commit c785f48

Browse files
committed
Supply code objects a new-style tp_members slot and tp_getattr impl.
The chief effects are to make dir() do something useful and supply them with an __class__.
1 parent a8c60f4 commit c785f48

1 file changed

Lines changed: 34 additions & 16 deletions

File tree

Python/compile.c

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,6 @@ static struct memberlist code_memberlist[] = {
9191
{NULL} /* Sentinel */
9292
};
9393

94-
static PyObject *
95-
code_getattr(PyCodeObject *co, char *name)
96-
{
97-
return PyMember_Get((char *)co, code_memberlist, name);
98-
}
99-
10094
static void
10195
code_dealloc(PyCodeObject *co)
10296
{
@@ -189,16 +183,40 @@ PyTypeObject PyCode_Type = {
189183
"code",
190184
sizeof(PyCodeObject),
191185
0,
192-
(destructor)code_dealloc, /*tp_dealloc*/
193-
0, /*tp_print*/
194-
(getattrfunc)code_getattr, /*tp_getattr*/
195-
0, /*tp_setattr*/
196-
(cmpfunc)code_compare, /*tp_compare*/
197-
(reprfunc)code_repr, /*tp_repr*/
198-
0, /*tp_as_number*/
199-
0, /*tp_as_sequence*/
200-
0, /*tp_as_mapping*/
201-
(hashfunc)code_hash, /*tp_hash*/
186+
(destructor)code_dealloc, /* tp_dealloc */
187+
0, /* tp_print */
188+
0, /* tp_getattr */
189+
0, /* tp_setattr */
190+
(cmpfunc)code_compare, /* tp_compare */
191+
(reprfunc)code_repr, /* tp_repr */
192+
0, /* tp_as_number */
193+
0, /* tp_as_sequence */
194+
0, /* tp_as_mapping */
195+
(hashfunc)code_hash, /* tp_hash */
196+
0, /* tp_call */
197+
0, /* tp_str */
198+
PyObject_GenericGetAttr, /* tp_getattro */
199+
0, /* tp_setattro */
200+
0, /* tp_as_buffer */
201+
Py_TPFLAGS_DEFAULT, /* tp_flags */
202+
0, /* tp_doc */
203+
0, /* tp_traverse */
204+
0, /* tp_clear */
205+
0, /* tp_richcompare */
206+
0, /* tp_weaklistoffset */
207+
0, /* tp_iter */
208+
0, /* tp_iternext */
209+
0, /* tp_methods */
210+
code_memberlist, /* tp_members */
211+
0, /* tp_getset */
212+
0, /* tp_base */
213+
0, /* tp_dict */
214+
0, /* tp_descr_get */
215+
0, /* tp_descr_set */
216+
0, /* tp_dictoffset */
217+
0, /* tp_init */
218+
0, /* tp_alloc */
219+
0, /* tp_new */
202220
};
203221

204222
#define NAME_CHARS \

0 commit comments

Comments
 (0)