This is an archive of the discontinued LLVM Phabricator instance.

[Python] Allow PyLong values in integer lists (when converting to C lists)
ClosedPublic

Authored by sivachandra on Jun 29 2015, 4:17 PM.

Diff Detail

Event Timeline

sivachandra retitled this revision from to [Python] Allow PyLong values in integer lists (when converting to C lists).
sivachandra updated this object.
sivachandra edited the test plan for this revision. (Show Details)
sivachandra added a subscriber: Unknown Object (MLST).
clayborg accepted this revision.Jun 29 2015, 4:36 PM
clayborg edited edge metadata.

Looks good. Not sure if we also want to handle booleans? Should be easy to add support for bools.

This revision is now accepted and ready to land.Jun 29 2015, 4:36 PM
sivachandra retitled this revision from [Python] Allow PyLong values in integer lists (when converting to C lists) to [Python] Allow PyLong & PyBool values in integer list typemaps..Jun 30 2015, 11:32 AM
sivachandra edited edge metadata.

Allowing PyBool lists as well.
OK?

granata.enrico accepted this revision.Jun 30 2015, 11:48 AM
granata.enrico edited edge metadata.

At a glance, it looks like you might be able to use PyLong_AsUnsignedLongLong() also for bool values.
If so, that might be a nicer code flow instead of the exact pointer equality check

if (PyLong || PyBool) { PyLong_AsUnsigned.... }

But if that actually doesn't work, looks good to me

sivachandra retitled this revision from [Python] Allow PyLong & PyBool values in integer list typemaps. to [Python] Allow PyLong values in integer lists (when converting to C lists).Jun 30 2015, 12:05 PM
sivachandra edited edge metadata.

Enrico prompted me to do this experiment:

>>> isinstance(True, long)
False
>>> isinstance(False, long)
False
>>> isinstance(False, int)
True
>>> isinstance(True, int)
True

So, bools were allowed even before this patch! I have taken out the additional
PyBool check and reverted to the original version of the patch. Will put it in
shortly.

sivachandra closed this revision.Jul 1 2015, 4:27 PM