mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
Support for tp_getattro, tp_setattro (Sjoerd)
This commit is contained in:
parent
929f1b83ea
commit
d8eb1b340f
3 changed files with 33 additions and 0 deletions
|
|
@ -326,6 +326,16 @@ getattr(v, name)
|
|||
object *v;
|
||||
char *name;
|
||||
{
|
||||
if (v->ob_type->tp_getattro != NULL) {
|
||||
object *w, *res;
|
||||
w = newstringobject(name);
|
||||
if (w == NULL)
|
||||
return NULL;
|
||||
res = (*v->ob_type->tp_getattro)(v, w);
|
||||
XDECREF(w);
|
||||
return res;
|
||||
}
|
||||
|
||||
if (v->ob_type->tp_getattr == NULL) {
|
||||
err_setstr(AttributeError, "attribute-less object");
|
||||
return NULL;
|
||||
|
|
@ -355,6 +365,17 @@ setattr(v, name, w)
|
|||
char *name;
|
||||
object *w;
|
||||
{
|
||||
if (v->ob_type->tp_setattro != NULL) {
|
||||
object *s;
|
||||
int res;
|
||||
s = newstringobject(name);
|
||||
if (s == NULL)
|
||||
return NULL;
|
||||
res = (*v->ob_type->tp_setattro)(v, s, w);
|
||||
XDECREF(s);
|
||||
return res;
|
||||
}
|
||||
|
||||
if (v->ob_type->tp_setattr == NULL) {
|
||||
if (v->ob_type->tp_getattr == NULL)
|
||||
err_setstr(TypeError,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue