Skip to content

Viper bug: integers > 0x3fffffff appear as python objects #9114

@rkompass

Description

@rkompass

The bug presumably is a result of the same logic as the now closed #8956 (perhaps the fix is also as simple).

Integers outside the mpy small int range ( > 0x3fffffff) are handled as python objects in viper.
This rather should happen with integers > 0xffffffff.

Code to illustrate the issue:

# @micropython.viper
# def largeint(a) -> int:
#     b = a & 0xfffffffe
#     return b                   #  ->  ViperTypeError: return expected 'int' but got 'object'

# print(largeint(3))

@micropython.viper
def largeint2(a):
    b = a & 0xfffffffe           #      works, but b is now a python object rather than a viper integer
    return b

print(largeint2(3))


gv = b'\x03\x00\x00\x00'

@micropython.viper
def and32(p:ptr32):
    p[0] = p[0] & 0xfffffffe              # -> ViperTypeError: can't do binary op between 'int' and 'object'
                                          # but  works with 0x3ffffffe and with int(0xfffffffe)

print('Before: ', int.from_bytes(gv, 'little'))   #  -> 3
and32(gv) 
print('After: ', int.from_bytes(gv, 'little'))    # should be 2, but does not work

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy