diff options
author | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2008-07-02 20:50:16 (GMT) |
---|---|---|
committer | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2008-07-02 20:50:16 (GMT) |
commit | e43d33a4db0c0c9afcb70a26f682abfe889e845b (patch) | |
tree | 47197bd06fa88bf96cef5f673018d20887fa301c /Modules/parsermodule.c | |
parent | 4118174315f4cba03208886af868fe31f1cd5b9d (diff) | |
download | cpython-e43d33a4db0c0c9afcb70a26f682abfe889e845b.zip cpython-e43d33a4db0c0c9afcb70a26f682abfe889e845b.tar.gz cpython-e43d33a4db0c0c9afcb70a26f682abfe889e845b.tar.bz2 |
#3247 Get rid of Py_FindMethod; use tp_members instead.
Otherwise dir(_sre.SRE_Match) returns an empty list.
First step: handle most occurrences, remove tp_getattr and fill the tp_methods and tp_members slots.
Add some test about attribute access.
Diffstat (limited to 'Modules/parsermodule.c')
-rw-r--r-- | Modules/parsermodule.c | 62 |
1 files changed, 32 insertions, 30 deletions
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c index cd7a3b2..ab41aaf 100644 --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -161,8 +161,28 @@ typedef struct { static void parser_free(PyST_Object *st); static int parser_compare(PyST_Object *left, PyST_Object *right); -static PyObject *parser_getattr(PyObject *self, char *name); +static PyObject* parser_compilest(PyST_Object *, PyObject *, PyObject *); +static PyObject* parser_isexpr(PyST_Object *, PyObject *, PyObject *); +static PyObject* parser_issuite(PyST_Object *, PyObject *, PyObject *); +static PyObject* parser_st2list(PyST_Object *, PyObject *, PyObject *); +static PyObject* parser_st2tuple(PyST_Object *, PyObject *, PyObject *); +#define PUBLIC_METHOD_TYPE (METH_VARARGS|METH_KEYWORDS) + +static PyMethodDef parser_methods[] = { + {"compile", (PyCFunction)parser_compilest, PUBLIC_METHOD_TYPE, + PyDoc_STR("Compile this ST object into a code object.")}, + {"isexpr", (PyCFunction)parser_isexpr, PUBLIC_METHOD_TYPE, + PyDoc_STR("Determines if this ST object was created from an expression.")}, + {"issuite", (PyCFunction)parser_issuite, PUBLIC_METHOD_TYPE, + PyDoc_STR("Determines if this ST object was created from a suite.")}, + {"tolist", (PyCFunction)parser_st2list, PUBLIC_METHOD_TYPE, + PyDoc_STR("Creates a list-tree representation of this ST.")}, + {"totuple", (PyCFunction)parser_st2tuple, PUBLIC_METHOD_TYPE, + PyDoc_STR("Creates a tuple-tree representation of this ST.")}, + + {NULL, NULL, 0, NULL} +}; static PyTypeObject PyST_Type = { @@ -172,7 +192,7 @@ PyTypeObject PyST_Type = { 0, /* tp_itemsize */ (destructor)parser_free, /* tp_dealloc */ 0, /* tp_print */ - parser_getattr, /* tp_getattr */ + 0, /* tp_getattr */ 0, /* tp_setattr */ (cmpfunc)parser_compare, /* tp_compare */ 0, /* tp_repr */ @@ -191,7 +211,14 @@ PyTypeObject PyST_Type = { Py_TPFLAGS_DEFAULT, /* tp_flags */ /* __doc__ */ - "Intermediate representation of a Python parse tree." + "Intermediate representation of a Python parse tree.", + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + parser_methods, /* tp_methods */ }; /* PyST_Type */ @@ -450,32 +477,6 @@ parser_issuite(PyST_Object *self, PyObject *args, PyObject *kw) } -#define PUBLIC_METHOD_TYPE (METH_VARARGS|METH_KEYWORDS) - -static PyMethodDef -parser_methods[] = { - {"compile", (PyCFunction)parser_compilest, PUBLIC_METHOD_TYPE, - PyDoc_STR("Compile this ST object into a code object.")}, - {"isexpr", (PyCFunction)parser_isexpr, PUBLIC_METHOD_TYPE, - PyDoc_STR("Determines if this ST object was created from an expression.")}, - {"issuite", (PyCFunction)parser_issuite, PUBLIC_METHOD_TYPE, - PyDoc_STR("Determines if this ST object was created from a suite.")}, - {"tolist", (PyCFunction)parser_st2list, PUBLIC_METHOD_TYPE, - PyDoc_STR("Creates a list-tree representation of this ST.")}, - {"totuple", (PyCFunction)parser_st2tuple, PUBLIC_METHOD_TYPE, - PyDoc_STR("Creates a tuple-tree representation of this ST.")}, - - {NULL, NULL, 0, NULL} -}; - - -static PyObject* -parser_getattr(PyObject *self, char *name) -{ - return (Py_FindMethod(parser_methods, self, name)); -} - - /* err_string(char* message) * * Sets the error string for an exception of type ParserError. @@ -3067,7 +3068,8 @@ PyInit_parser(void) { PyObject *module, *copyreg; - Py_TYPE(&PyST_Type) = &PyType_Type; + if (PyType_Ready(&PyST_Type) < 0) + return NULL; module = PyModule_Create(&parsermodule); if (module == NULL) return NULL; |