There was an error while loading. Please reload this page.
1 parent cb8ed53 commit df875b9Copy full SHA for df875b9
2 files changed
Include/classobject.h
@@ -51,6 +51,18 @@ PyAPI_FUNC(PyObject *) PyMethod_Function(PyObject *);
51
PyAPI_FUNC(PyObject *) PyMethod_Self(PyObject *);
52
PyAPI_FUNC(PyObject *) PyMethod_Class(PyObject *);
53
54
+/* Look up attribute with name (a string) on instance object pinst, using
55
+ * only the instance and base class dicts. If a descriptor is found in
56
+ * a class dict, the descriptor is returned without calling it.
57
+ * Returns NULL if nothing found, else a borrowed reference to the
58
+ * value associated with name in the dict in which name was found.
59
+ * The point of this routine is that it never calls arbitrary Python
60
+ * code, so is always "safe": all it does is dict lookups. The function
61
+ * can't fail, never sets an exceptionm, and NULL is not an error (it just
62
+ * means "not found").
63
+ */
64
+PyAPI_FUNC(PyObject *)_PyInstance_Lookup(PyObject *pinst, PyObject *name);
65
+
66
/* Macros for direct access to these values. Type checks are *not*
67
done, so use with care. */
68
#define PyMethod_GET_FUNCTION(meth) \
Objects/classobject.c
@@ -759,6 +759,27 @@ instance_getattr(register PyInstanceObject *inst, PyObject *name)
759
return res;
760
}
761
762
+/* See classobject.h comments: this only does dict lookups, and is always
763
+ * safe to call.
764
765
+PyObject *
766
+_PyInstance_Lookup(PyObject *pinst, PyObject *name)
767
+{
768
+ PyObject *v;
769
+ PyClassObject *class;
770
+ PyInstanceObject *inst; /* pinst cast to the right type */
771
772
+ assert(PyInstance_Check(pinst));
773
+ inst = (PyInstanceObject *)pinst;
774
775
+ assert(PyString_Check(name));
776
777
+ v = PyDict_GetItem(inst->in_dict, name);
778
+ if (v == NULL)
779
+ v = class_lookup(inst->in_class, name, &class);
780
+ return v;
781
+}
782
783
static int
784
instance_setattr1(PyInstanceObject *inst, PyObject *name, PyObject *v)
785
{
0 commit comments