[issue28959] Add a macro for dict size

STINNER Victor report at bugs.python.org
Wed Dec 14 11:08:41 EST 2016


STINNER Victor added the comment:

Ignore my previous comment, PyDict_GET_SIZE-3.patch LGTM.


> I don't think the changes in _datetimemodule.c and typeobject.c change the behavior.

Oh wait, it seems like I misunderstood the new code.

Modules/_datetimemodule.c:

         dictptr = _PyObject_GetDictPtr(self);
-        if (dictptr && *dictptr && PyDict_Size(*dictptr)) {
+        if (dictptr && *dictptr &&
+            (!PyDict_Check(*dictptr) || PyDict_GET_SIZE(*dictptr))) {
             state = *dictptr;

If *dictptr is set and is not a dict, the test is true for the old and new code. Hum, I misunderstood the new code: I understood that (!PyDict_Check(*dictptr) || PyDict_GET_SIZE(*dictptr)) is false is *dictptr is not a dict, but it's true.

Hum, the only difference is that the old code raises an exception (SystemError), the new code doesn't raise an exception.

Since I'm not able to create an object with a __dict__ attribute which is not a dict, I don't really case of the small behaviour change.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28959>
_______________________________________


More information about the Python-bugs-list mailing list