Commit 8d1f1650 authored by Boxiang Sun's avatar Boxiang Sun

use PyObject_GetDict instead _PyObject_GetDictPtr

some Pyston class use hidden class to store their attributes,
instead use PyDictObejct. This can get some speedup. But we can't
get a writable dict pointer if a class use hidden class.

So if code want to copy the dict, use PyObject_GetDict, if code want
to add new item to it, use PyObject_SetDict.
parent bca9323e
...@@ -134,7 +134,6 @@ Base_getattro(PyObject *obj, PyObject *name) ...@@ -134,7 +134,6 @@ Base_getattro(PyObject *obj, PyObject *name)
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);
...@@ -144,9 +143,6 @@ Base_getattro(PyObject *obj, PyObject *name) ...@@ -144,9 +143,6 @@ 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) {
......
...@@ -158,9 +158,17 @@ pickle___getstate__(PyObject *self) ...@@ -158,9 +158,17 @@ pickle___getstate__(PyObject *self)
if (slotnames == NULL) if (slotnames == NULL)
return NULL; return NULL;
/* Pyston change: Pyston dont' support _PyObject_GetDictPtr fully
* and will not support it in future, use new PyObject_GetDict API
*/
#if 0
dictp = _PyObject_GetDictPtr(self); dictp = _PyObject_GetDictPtr(self);
if (dictp) if (dictp)
state = pickle_copy_dict(*dictp); state = pickle_copy_dict(*dictp);
#endif
PyObject *dict = PyObject_GetDict(self);
if (dict)
state = pickle_copy_dict(dict);
else else
{ {
state = Py_None; state = Py_None;
...@@ -280,6 +288,7 @@ pickle___setstate__(PyObject *self, PyObject *state) ...@@ -280,6 +288,7 @@ pickle___setstate__(PyObject *self, PyObject *state)
if (state != Py_None) if (state != Py_None)
{ {
#if 0
PyObject **dict; PyObject **dict;
dict = _PyObject_GetDictPtr(self); dict = _PyObject_GetDictPtr(self);
...@@ -301,6 +310,9 @@ pickle___setstate__(PyObject *self, PyObject *state) ...@@ -301,6 +310,9 @@ pickle___setstate__(PyObject *self, PyObject *state)
} }
else if (pickle_setattrs_from_dict(self, state) < 0) else if (pickle_setattrs_from_dict(self, state) < 0)
return NULL; return NULL;
#endif
PyObject_ClearDict((PyObject*)self);
PyObject_SetDict(self, state);
} }
if (slots != NULL && pickle_setattrs_from_dict(self, slots) < 0) if (slots != NULL && pickle_setattrs_from_dict(self, slots) < 0)
......
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