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) ...@@ -122,28 +122,19 @@ Base_getattro(PyObject *obj, PyObject *name)
} }
} }
/* Inline _PyObject_GetDictPtr */ // Pyston change:
dictoffset = tp->tp_dictoffset; // The code below basically did these things:
if (dictoffset != 0) { // get the dict of the obj
PyObject *dict; // get the item in the dict by name
if (dictoffset < 0) { // if the item type is ExtensionClassType
int tsize; // then do something
size_t size; PyObject *dict= PyObject_GetDict(obj); // New API added in Pyston
if (dict) {
tsize = ((PyVarObject *)obj)->ob_size; res = PyDict_GetItem(dict, name);
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;
if (dict != NULL) { if (dict != NULL) {
Py_INCREF(dict); Py_INCREF(dict);
res = PyDict_GetItem(dict, name); res = PyDict_GetItem(dict, name);
// get the dict item through the name
if (res != NULL) { if (res != NULL) {
Py_INCREF(res); Py_INCREF(res);
Py_XDECREF(descr); Py_XDECREF(descr);
...@@ -153,6 +144,9 @@ Base_getattro(PyObject *obj, PyObject *name) ...@@ -153,6 +144,9 @@ Base_getattro(PyObject *obj, PyObject *name)
If the tp_descr_get of res is of_get, If the tp_descr_get of res is of_get,
then call it. */ 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, if (PyObject_TypeCheck(res->ob_type,
&ExtensionClassType) &ExtensionClassType)
&& res->ob_type->tp_descr_get != NULL) { && res->ob_type->tp_descr_get != NULL) {
...@@ -167,7 +161,58 @@ Base_getattro(PyObject *obj, PyObject *name) ...@@ -167,7 +161,58 @@ Base_getattro(PyObject *obj, PyObject *name)
} }
Py_DECREF(dict); 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) { if (f != NULL) {
res = f(descr, obj, (PyObject *)obj->ob_type); 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