Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

py: Fix handling of large number of *args, and add more tests #8472

Merged
merged 4 commits into from
Apr 1, 2022

Commits on Mar 31, 2022

  1. py/emitbc: Assert that a small int fits its encoding when emitting one.

    Signed-off-by: Damien George <damien@micropython.org>
    dpgeorge committed Mar 31, 2022
    Configuration menu
    Copy the full SHA
    e3de723 View commit details
    Browse the repository at this point in the history
  2. py: Fix compiling and decoding of *args at large arg positions.

    There were two issues with the existing code:
    
    1. "1 << i" is computed as a 32-bit number so would overflow when
       executed on 64-bit machines (when mp_uint_t is 64-bit).  This meant that
       *args beyond 32 positions would not be handled correctly.
    
    2. star_args must fit as a positive small int so that it is encoded
       correctly in the emitted code.  MP_SMALL_INT_BITS is too big because it
       overflows a small int by 1 bit.  MP_SMALL_INT_BITS - 1 does not work
       because it produces a signed small int which is then sign extended when
       extracted (even by mp_obj_get_int_truncated), and this sign extension
       means that any position arg after *args is also treated as a star-arg.
       So the maximum bit position is MP_SMALL_INT_BITS - 2.  This means that
       MP_OBJ_SMALL_INT_VALUE() can be used instead of
       mp_obj_get_int_truncated() to get the value of star_args.
    
    These issues are fixed by this commit, and a test added.
    
    Signed-off-by: Damien George <damien@micropython.org>
    dpgeorge committed Mar 31, 2022
    Configuration menu
    Copy the full SHA
    bd556b6 View commit details
    Browse the repository at this point in the history
  3. py/runtime: Remove unnecessary check for kw_value == MP_OBJ_NULL.

    The values are always real objects, only the key can be MP_OBJ_NULL to
    indicate a **kwargs entry.
    
    Signed-off-by: Damien George <damien@micropython.org>
    dpgeorge committed Mar 31, 2022
    Configuration menu
    Copy the full SHA
    40f5c74 View commit details
    Browse the repository at this point in the history
  4. tests/basics/fun_callstardblstar: Add test for large arg allocation.

    Signed-off-by: Damien George <damien@micropython.org>
    dpgeorge committed Mar 31, 2022
    Configuration menu
    Copy the full SHA
    1dbf393 View commit details
    Browse the repository at this point in the history