Skip to content

uctypes does not support values larger than 31 bits despite listing uint64 support #2269

Description

@ryannathans
>>> struct = uctypes.struct(uctypes.addressof(buffer), {"bug": uctypes.UINT32 | 0, "bug64": uctypes.UINT64 | 4})
>>> struct.bug = 2147483647
>>> struct.bug = 2147483648
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: overflow converting long int to machine word
>>> struct.bug64 = 2147483647
>>> struct.bug64 = 2147483648
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: overflow converting long int to machine word

Seems pretty funny how ctypes can't support UINT32 and UINT64s?

Activity

  1. pfalcon commented on Aug 25, 2016

    @pfalcon
    Contributor

    To fix this, we need getters for getting Python int object as: int32, uint32, int64, uint64, each apparently "truncated" and "range checking" version. That's many getters, so apparently there should be one new function, taking flags for the above, deprecating previously available mp_obj_int_get_truncated() & mp_obj_int_get_checked().

  2. dpgeorge commented on Aug 26, 2016

    @dpgeorge
    Member

    Just using mp_obj_int_get_truncated should fix the 32 bit case. Then there are already some functions to handle wider values, eg int_to_bytes() and mp_obj_int_to_bytes_impl().

  3. pfalcon commented on Apr 20, 2017

    @pfalcon
    Contributor

    Ok, I have fixes for these working on 32-bit little-endian, now the most boring part is writing tests...

  4. pfalcon commented on Apr 21, 2017

    @pfalcon
    Contributor

    Fixed by 9e8f316

  5. added a commit that references this issue on Nov 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions