Skip to content

Commit

Permalink
WIP: Do not inline _PyObject_GetDictPtr.
Browse files Browse the repository at this point in the history
Use as much API from python as possible (even if its declared private).
Its better than copy&paste, which breaks if the internal implementation
of python changes.
  • Loading branch information
stephan-hof committed Jan 24, 2017
1 parent db6a6e0 commit 6617fe1
Showing 1 changed file with 7 additions and 27 deletions.
34 changes: 7 additions & 27 deletions src/ExtensionClass/_ExtensionClass.c
Expand Up @@ -48,7 +48,6 @@ Base_getattro(PyObject *obj, PyObject *name)
PyObject *descr = NULL;
PyObject *res = NULL;
descrgetfunc f;
Py_ssize_t dictoffset;
PyObject **dictptr;

if (!PyString_Check(name)){
Expand Down Expand Up @@ -92,37 +91,18 @@ Base_getattro(PyObject *obj, PyObject *name)
}
}

if (dict == NULL) {
/* Inline _PyObject_GetDictPtr */
dictoffset = tp->tp_dictoffset;
if (dictoffset != 0) {
if (dictoffset < 0) {
Py_ssize_t 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;
}
}
if (dict != NULL) {
Py_INCREF(dict);
res = PyDict_GetItem(dict, name);
dictptr = _PyObject_GetDictPtr(obj);

if (dictptr && *dictptr) {
Py_INCREF(*dictptr);
res = PyDict_GetItem(*dictptr, name);
if (res != NULL) {
Py_INCREF(res);
Py_XDECREF(descr);
Py_DECREF(dict);
Py_DECREF(*dictptr);
goto done;
}
Py_DECREF(dict);
Py_DECREF(*dictptr);
}

if (f != NULL) {
Expand Down

0 comments on commit 6617fe1

Please sign in to comment.