summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-05-20 18:34:44 (GMT)
committerGuido van Rossum <guido@python.org>1997-05-20 18:34:44 (GMT)
commit98ff96adbadb88f2ff05ffa0388d1568aa45ebf1 (patch)
treeba5b1511a4509e49881ea5c53cc63f208906a965
parent967839473aadea9b3e3d9e50abdc862e3090fb99 (diff)
downloadcpython-98ff96adbadb88f2ff05ffa0388d1568aa45ebf1.zip
cpython-98ff96adbadb88f2ff05ffa0388d1568aa45ebf1.tar.gz
cpython-98ff96adbadb88f2ff05ffa0388d1568aa45ebf1.tar.bz2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
-rw-r--r--Objects/object.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/Objects/object.c b/Objects/object.c
index c4adf9a..29269d0 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -398,6 +398,49 @@ PyObject_SetAttrString(v, name, w)
}
}
+PyObject *
+PyObject_GetAttr(v, name)
+ PyObject *v;
+ PyObject *name;
+{
+ if (v->ob_type->tp_getattro != NULL)
+ return (*v->ob_type->tp_getattro)(v, name);
+ else
+ return PyObject_GetAttrString(v, PyString_AsString(name));
+}
+
+int
+PyObject_HasAttr(v, name)
+ PyObject *v;
+ PyObject *name;
+{
+ PyObject *res = PyObject_GetAttr(v, name);
+ if (res != NULL) {
+ Py_DECREF(res);
+ return 1;
+ }
+ PyErr_Clear();
+ return 0;
+}
+
+int
+PyObject_SetAttr(v, name, value)
+ PyObject *v;
+ PyObject *name;
+ PyObject *value;
+{
+ int err;
+ Py_INCREF(name);
+ PyString_InternInPlace(&name);
+ if (v->ob_type->tp_setattro != NULL)
+ err = (*v->ob_type->tp_setattro)(v, name, value);
+ else
+ err = PyObject_SetAttrString(
+ v, PyString_AsString(name), value);
+ Py_DECREF(name);
+ return err;
+}
+
/* Test a value used as condition, e.g., in a for or if statement.
Return -1 if an error occurred */