[issue16086] tp_flags: Undefined behaviour with 32 bits long

Mark Dickinson report at bugs.python.org
Sat Sep 29 19:14:01 CEST 2012


Mark Dickinson added the comment:

Actually, I think it'll be messy to make this work:  PyType_GetFlags is part of the stable ABI, so that's got to continue to return a long rather than an unsigned long.  And then we've got, in object.h:

#ifdef Py_LIMITED_API
#define PyType_HasFeature(t,f)  ((PyType_GetFlags(t) & (f)) != 0)
#else
#define PyType_HasFeature(t,f)  (((t)->tp_flags & (f)) != 0)
#endif

So we'd need an extra cast from long to unsigned long in the first branch.

I suggest instead just replacing that one occurrence of (1L << 31) with (long)(1UL << 31) to get around the undefined behaviour.


P.S. The docs would also need to be updated in these two files:

   Doc/c-api/typeobj.rst
   Doc/includes/typestruct.h

----------

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


More information about the Python-bugs-list mailing list