Remove support for __members__ and __methods__. There still might be

some cleanup to do on this.  Particularly in Python/traceback.c with
getting rid of the getattr if possible and Demo/*metaclasses/Enum.py.
This commit is contained in:
Neal Norwitz 2007-08-11 06:39:53 +00:00
parent 32ca442b13
commit 8dfc4a9bac
14 changed files with 83 additions and 195 deletions

View file

@ -5,51 +5,6 @@
#include "structmember.h"
static PyObject *
listmembers(struct memberlist *mlist)
{
int i, n;
PyObject *v;
for (n = 0; mlist[n].name != NULL; n++)
;
v = PyList_New(n);
if (v != NULL) {
for (i = 0; i < n; i++)
PyList_SetItem(v, i,
PyString_FromString(mlist[i].name));
if (PyErr_Occurred()) {
Py_DECREF(v);
v = NULL;
}
else {
PyList_Sort(v);
}
}
return v;
}
PyObject *
PyMember_Get(const char *addr, struct memberlist *mlist, const char *name)
{
struct memberlist *l;
if (strcmp(name, "__members__") == 0)
return listmembers(mlist);
for (l = mlist; l->name != NULL; l++) {
if (strcmp(l->name, name) == 0) {
PyMemberDef copy;
copy.name = l->name;
copy.type = l->type;
copy.offset = l->offset;
copy.flags = l->flags;
copy.doc = NULL;
return PyMember_GetOne(addr, &copy);
}
}
PyErr_SetString(PyExc_AttributeError, name);
return NULL;
}
PyObject *
PyMember_GetOne(const char *addr, PyMemberDef *l)
{
@ -135,27 +90,6 @@ PyMember_GetOne(const char *addr, PyMemberDef *l)
return v;
}
int
PyMember_Set(char *addr, struct memberlist *mlist, const char *name, PyObject *v)
{
struct memberlist *l;
for (l = mlist; l->name != NULL; l++) {
if (strcmp(l->name, name) == 0) {
PyMemberDef copy;
copy.name = l->name;
copy.type = l->type;
copy.offset = l->offset;
copy.flags = l->flags;
copy.doc = NULL;
return PyMember_SetOne(addr, &copy, v);
}
}
PyErr_SetString(PyExc_AttributeError, name);
return -1;
}
#define WARN(msg) \
do { \
if (PyErr_Warn(PyExc_RuntimeWarning, msg) < 0) \

View file

@ -11,18 +11,28 @@
#define OFF(x) offsetof(PyTracebackObject, x)
static struct memberlist tb_memberlist[] = {
{"tb_next", T_OBJECT, OFF(tb_next)},
{"tb_frame", T_OBJECT, OFF(tb_frame)},
{"tb_lasti", T_INT, OFF(tb_lasti)},
{"tb_lineno", T_INT, OFF(tb_lineno)},
static PyMemberDef tb_memberlist[] = {
{"tb_next", T_OBJECT, OFF(tb_next), READONLY},
{"tb_frame", T_OBJECT, OFF(tb_frame), READONLY},
{"tb_lasti", T_INT, OFF(tb_lasti), READONLY},
{"tb_lineno", T_INT, OFF(tb_lineno), READONLY},
{NULL} /* Sentinel */
};
/* XXX(nnorwitz): can we get rid of tb_getattr and use tp_members? */
static PyObject *
tb_getattr(PyTracebackObject *tb, char *name)
{
return PyMember_Get((char *)tb, tb_memberlist, name);
int i;
for (i = 0; tb_memberlist[i].name != NULL; i++) {
if (strcmp(name, tb_memberlist[i].name) == 0)
return PyMember_GetOne((const char *)tb,
tb_memberlist + i);
}
PyErr_Format(PyExc_AttributeError,
"'%.50s' object has no attribute '%.400s'",
Py_Type(tb)->tp_name, name);
return NULL;
}
static void
@ -80,8 +90,8 @@ PyTypeObject PyTraceBack_Type = {
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
};