Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 98ff96a

Browse files
committed
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
1 parent 9678394 commit 98ff96a

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

Objects/object.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,49 @@ PyObject_SetAttrString(v, name, w)
398398
}
399399
}
400400

401+
PyObject *
402+
PyObject_GetAttr(v, name)
403+
PyObject *v;
404+
PyObject *name;
405+
{
406+
if (v->ob_type->tp_getattro != NULL)
407+
return (*v->ob_type->tp_getattro)(v, name);
408+
else
409+
return PyObject_GetAttrString(v, PyString_AsString(name));
410+
}
411+
412+
int
413+
PyObject_HasAttr(v, name)
414+
PyObject *v;
415+
PyObject *name;
416+
{
417+
PyObject *res = PyObject_GetAttr(v, name);
418+
if (res != NULL) {
419+
Py_DECREF(res);
420+
return 1;
421+
}
422+
PyErr_Clear();
423+
return 0;
424+
}
425+
426+
int
427+
PyObject_SetAttr(v, name, value)
428+
PyObject *v;
429+
PyObject *name;
430+
PyObject *value;
431+
{
432+
int err;
433+
Py_INCREF(name);
434+
PyString_InternInPlace(&name);
435+
if (v->ob_type->tp_setattro != NULL)
436+
err = (*v->ob_type->tp_setattro)(v, name, value);
437+
else
438+
err = PyObject_SetAttrString(
439+
v, PyString_AsString(name), value);
440+
Py_DECREF(name);
441+
return err;
442+
}
443+
401444
/* Test a value used as condition, e.g., in a for or if statement.
402445
Return -1 if an error occurred */
403446

0 commit comments

Comments
 (0)