Skip to content
Snippets Groups Projects
  1. May 21, 2019
    • stijn's avatar
      py/objarray: Add decode method to bytearray. · fb54736b
      stijn authored
      Reuse the implementation for bytes since it works the same way regardless
      of the underlying type.  This method gets added for CPython compatibility
      of bytearray, but to keep the code simple and small array.array now also
      has a working decode method, which is non-standard but doesn't hurt.
      fb54736b
  2. May 14, 2019
  3. May 06, 2019
    • Jun Wu's avatar
      py: remove "if (0)" and "if (false)" branches. · 089c9b71
      Jun Wu authored
      Prior to this commit, building the unix port with `DEBUG=1` and
      `-finstrument-functions` the compilation would fail with an error like
      "control reaches end of non-void function".  This change fixes this by
      removing the problematic "if (0)" branches.  Not all branches affect
      compilation, but they are all removed for consistency.
      089c9b71
  4. Feb 12, 2019
    • Damien George's avatar
      py: Downcase all MP_OBJ_IS_xxx macros to make a more consistent C API. · eee1e884
      Damien George authored
      These macros could in principle be (inline) functions so it makes sense to
      have them lower case, to match the other C API functions.
      
      The remaining macros that are upper case are:
      - MP_OBJ_TO_PTR, MP_OBJ_FROM_PTR
      - MP_OBJ_NEW_SMALL_INT, MP_OBJ_SMALL_INT_VALUE
      - MP_OBJ_NEW_QSTR, MP_OBJ_QSTR_VALUE
      - MP_OBJ_FUN_MAKE_SIG
      - MP_DECLARE_CONST_xxx
      - MP_DEFINE_CONST_xxx
      
      These must remain macros because they are used when defining const data (at
      least, MP_OBJ_NEW_SMALL_INT is so it makes sense to have
      MP_OBJ_SMALL_INT_VALUE also a macro).
      
      For those macros that have been made lower case, compatibility macros are
      provided for the old names so that users do not need to change their code
      immediately.
      eee1e884
  5. Dec 20, 2018
    • Paul Sokolovsky's avatar
      py/objarray: Introduce "memview_offset" alias for "free" field of object · a261d8b6
      Paul Sokolovsky authored
      Both mp_type_array and mp_type_memoryview use the same object structure,
      mp_obj_array_t, but for the case of memoryview, some fields, e.g. "free",
      have different meaning.  As the "free" field is also a bitfield, assume
      that (anonymous) union can't be used here (for the concerns of possible
      compatibility issues with wide array of toolchains), and just add a field
      alias using a #define.  As it's a define, it should be a selective
      identifier, so use verbose "memview_offset" to avoid any clashes.
      a261d8b6
  6. Sep 11, 2018
    • Paul Sokolovsky's avatar
      py/objarray: bytearray: Allow 2nd/3rd arg to constructor. · 674e069b
      Paul Sokolovsky authored
      If bytearray is constructed from str, a second argument of encoding is
      required (in CPython), and third arg of Unicode error handling is allowed,
      e.g.:
      
      bytearray("str", "utf-8", "strict")
      
      This is similar to bytes:
      
      bytes("str", "utf-8", "strict")
      
      This patch just allows to pass 2nd/3rd arguments to bytearray, but
      doesn't try to validate them to not impact code size. (This is also
      similar to how bytes constructor is handled, though it does a bit
      more validation, e.g. check that in case of str arg, encoding argument
      is passed.)
      674e069b
  7. Aug 14, 2018
  8. Jun 18, 2018
  9. Nov 24, 2017
    • Damien George's avatar
      py/runtime: Add MP_BINARY_OP_CONTAINS as reverse of MP_BINARY_OP_IN. · 5e34a113
      Damien George authored
      Before this patch MP_BINARY_OP_IN had two meanings: coming from bytecode it
      meant that the args needed to be swapped, but coming from within the
      runtime meant that the args were already in the correct order.  This lead
      to some confusion in the code and comments stating how args were reversed.
      It also lead to 2 bugs: 1) containment for a subclass of a native type
      didn't work; 2) the expression "{True} in True" would illegally succeed and
      return True.  In both of these cases it was because the args to
      MP_BINARY_OP_IN ended up being reversed twice.
      
      To fix these things this patch introduces MP_BINARY_OP_CONTAINS which
      corresponds exactly to the __contains__ special method, and this is the
      operator that built-in types should implement.  MP_BINARY_OP_IN is now only
      emitted by the compiler and is converted to MP_BINARY_OP_CONTAINS by
      swapping the arguments.
      5e34a113
  10. Oct 24, 2017
  11. Oct 04, 2017
    • Damien George's avatar
      all: Remove inclusion of internal py header files. · a3dc1b19
      Damien George authored
      Header files that are considered internal to the py core and should not
      normally be included directly are:
          py/nlr.h - internal nlr configuration and declarations
          py/bc0.h - contains bytecode macro definitions
          py/runtime0.h - contains basic runtime enums
      
      Instead, the top-level header files to include are one of:
          py/obj.h - includes runtime0.h and defines everything to use the
              mp_obj_t type
          py/runtime.h - includes mpstate.h and hence nlr.h, obj.h, runtime0.h,
              and defines everything to use the general runtime support functions
      
      Additional, specific headers (eg py/objlist.h) can be included if needed.
      a3dc1b19
  12. Aug 29, 2017
  13. Aug 13, 2017
    • Javier Candeira's avatar
      all: Raise exceptions via mp_raise_XXX · 35a1fea9
      Javier Candeira authored
        - Changed: ValueError, TypeError, NotImplementedError
        - OSError invocations unchanged, because the corresponding utility
          function takes ints, not strings like the long form invocation.
        - OverflowError, IndexError and RuntimeError etc. not changed for now
          until we decide whether to add new utility functions.
      35a1fea9
  14. Jul 31, 2017
  15. Mar 28, 2017
  16. Mar 25, 2017
  17. Mar 23, 2017
  18. Feb 27, 2017
  19. Feb 16, 2017
  20. Jan 17, 2017
  21. Oct 17, 2016
  22. Jul 06, 2016
  23. Apr 07, 2016
  24. Mar 14, 2016
  25. Feb 14, 2016
  26. Jan 11, 2016
    • Damien George's avatar
      py: Change first arg of type.make_new from mp_obj_t to mp_obj_type_t*. · 5b3f0b7f
      Damien George authored
      The first argument to the type.make_new method is naturally a uPy type,
      and all uses of this argument cast it directly to a pointer to a type
      structure.  So it makes sense to just have it a pointer to a type from
      the very beginning (and a const pointer at that).  This patch makes
      such a change, and removes all unnecessary casting to/from mp_obj_t.
      5b3f0b7f
    • Damien George's avatar
      py: Change type of .make_new and .call args: mp_uint_t becomes size_t. · a0c97814
      Damien George authored
      This patch changes the type signature of .make_new and .call object method
      slots to use size_t for n_args and n_kw (was mp_uint_t.  Makes code more
      efficient when mp_uint_t is larger than a machine word.  Doesn't affect
      ports when size_t and mp_uint_t have the same size.
      a0c97814
  27. Nov 29, 2015
  28. Oct 11, 2015
  29. Sep 04, 2015
  30. Sep 03, 2015
  31. Jun 06, 2015
  32. Jul 20, 2015
  33. Jul 02, 2015
  34. May 17, 2015
  35. Apr 16, 2015
    • Damien George's avatar
      py: Overhaul and simplify printf/pfenv mechanism. · 7f9d1d6a
      Damien George authored
      Previous to this patch the printing mechanism was a bit of a tangled
      mess.  This patch attempts to consolidate printing into one interface.
      
      All (non-debug) printing now uses the mp_print* family of functions,
      mainly mp_printf.  All these functions take an mp_print_t structure as
      their first argument, and this structure defines the printing backend
      through the "print_strn" function of said structure.
      
      Printing from the uPy core can reach the platform-defined print code via
      two paths: either through mp_sys_stdout_obj (defined pert port) in
      conjunction with mp_stream_write; or through the mp_plat_print structure
      which uses the MP_PLAT_PRINT_STRN macro to define how string are printed
      on the platform.  The former is only used when MICROPY_PY_IO is defined.
      
      With this new scheme printing is generally more efficient (less layers
      to go through, less arguments to pass), and, given an mp_print_t*
      structure, one can call mp_print_str for efficiency instead of
      mp_printf("%s", ...).  Code size is also reduced by around 200 bytes on
      Thumb2 archs.
      7f9d1d6a
Loading