Commit bca9323e authored by Boxiang Sun's avatar Boxiang Sun

Rewrite part of Base_getattro

parent dc34f2c9
......@@ -122,28 +122,19 @@ Base_getattro(PyObject *obj, PyObject *name)
}
}
/* Inline _PyObject_GetDictPtr */
dictoffset = tp->tp_dictoffset;
if (dictoffset != 0) {
PyObject *dict;
if (dictoffset < 0) {
int tsize;
size_t size;
tsize = ((PyVarObject *)obj)->ob_size;
if (tsize < 0)
tsize = -tsize;
size = _PyObject_VAR_SIZE(tp, tsize);
dictoffset += (long)size;
assert(dictoffset > 0);
assert(dictoffset % SIZEOF_VOID_P == 0);
}
dictptr = (PyObject **) ((char *)obj + dictoffset);
dict = *dictptr;
// Pyston change:
// The code below basically did these things:
// get the dict of the obj
// get the item in the dict by name
// if the item type is ExtensionClassType
// then do something
PyObject *dict= PyObject_GetDict(obj); // New API added in Pyston
if (dict) {
res = PyDict_GetItem(dict, name);
if (dict != NULL) {
Py_INCREF(dict);
res = PyDict_GetItem(dict, name);
// get the dict item through the name
if (res != NULL) {
Py_INCREF(res);
Py_XDECREF(descr);
......@@ -153,6 +144,9 @@ Base_getattro(PyObject *obj, PyObject *name)
If the tp_descr_get of res is of_get,
then call it. */
// if the item type is ExtensionClassType
// and the tp_descr_get is not NULL
// do something
if (PyObject_TypeCheck(res->ob_type,
&ExtensionClassType)
&& res->ob_type->tp_descr_get != NULL) {
......@@ -167,7 +161,58 @@ Base_getattro(PyObject *obj, PyObject *name)
}
Py_DECREF(dict);
}
}
}
/* Inline _PyObject_GetDictPtr */
/* dictoffset = tp->tp_dictoffset; */
/* if (dictoffset != 0) { */
/* PyObject *dict; */
/* if (dictoffset < 0) { */
/* int tsize; */
/* size_t size; */
/* */
/* tsize = ((PyVarObject *)obj)->ob_size; */
/* if (tsize < 0) */
/* tsize = -tsize; */
/* size = _PyObject_VAR_SIZE(tp, tsize); */
/* */
/* dictoffset += (long)size; */
/* assert(dictoffset > 0); */
/* assert(dictoffset % SIZEOF_VOID_P == 0); */
/* } */
/* dictptr = (PyObject **) ((char *)obj + dictoffset); */
/* dict = *dictptr; */
/* // get the dict object */
/* if (dict != NULL) { */
/* Py_INCREF(dict); */
/* res = PyDict_GetItem(dict, name); */
/* // get the dict item through the name */
/* if (res != NULL) { */
/* Py_INCREF(res); */
/* Py_XDECREF(descr); */
/* Py_DECREF(dict); */
/* */
/* #<{(| CHANGED! */
/* If the tp_descr_get of res is of_get, */
/* then call it. |)}># */
/* */
/* // if the item type is ExtensionClassType */
/* // and the tp_descr_get is not NULL */
/* // do something */
/* if (PyObject_TypeCheck(res->ob_type, */
/* &ExtensionClassType) */
/* && res->ob_type->tp_descr_get != NULL) { */
/* PyObject *tres; */
/* tres = res->ob_type->tp_descr_get( */
/* res, obj, */
/* OBJECT(obj->ob_type)); */
/* Py_DECREF(res); */
/* res = tres; */
/* } */
/* goto done; */
/* } */
/* Py_DECREF(dict); */
/* } */
/* } */
if (f != NULL) {
res = f(descr, obj, (PyObject *)obj->ob_type);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment