Skip to content
Snippets Groups Projects
  1. 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
  2. Feb 05, 2019
  3. Oct 22, 2018
  4. Sep 26, 2018
    • Paul Sokolovsky's avatar
      py/objstr: format: Return bytes result for bytes format string. · a135bca4
      Paul Sokolovsky authored
      This is an improvement over previous behavior when str was returned for
      both str and bytes input format.  This new behaviour is also consistent
      with how the % operator works, as well as many other str/bytes methods.
      
      It should be noted that it's not how current versions of CPython work,
      where there's a gap in the functionality and bytes.format() is not
      supported.
      a135bca4
  5. Sep 20, 2018
  6. Jul 30, 2018
    • Damien George's avatar
      py/objstr: In format error message, use common string with %s for type. · aec6fa91
      Damien George authored
      This error message did not consume all of its variable args, a bug
      introduced long ago in baf6f14d.  By fixing
      it to use %s (instead of keeping the string as-is and deleting the last
      arg) the same error message string is now reused three times in this format
      function and gives a code size reduction of around 130 bytes.  It also now
      gives a better error message when a non-string is passed in as an argument
      to format, eg '{:d}'.format([]).
      aec6fa91
  7. Apr 05, 2018
  8. Mar 30, 2018
  9. Feb 20, 2018
  10. Feb 19, 2018
    • Damien George's avatar
      py/objstr: Protect against creating bytes(n) with n negative. · 4e469085
      Damien George authored
      Prior to this patch uPy (on a 32-bit arch) would have severe issues when
      calling bytes(-1): such a call would call vstr_init_len(vstr, -1) which
      would then +1 on the len and call vstr_init(vstr, 0), which would then
      round this up and allocate a small amount of memory for the vstr.  The
      bytes constructor would then attempt to zero out all this memory, thinking
      it had allocated 2^32-1 bytes.
      4e469085
  11. Feb 14, 2018
    • Damien George's avatar
      py/unicode: Clean up utf8 funcs and provide non-utf8 inline versions. · 19aee943
      Damien George authored
      This patch provides inline versions of the utf8 helper functions for the
      case when unicode is disabled (MICROPY_PY_BUILTINS_STR_UNICODE set to 0).
      This saves code size.
      
      The unichar_charlen function is also renamed to utf8_charlen to match the
      other utf8 helper functions, and the signature of this function is adjusted
      for consistency (const char* -> const byte*, mp_uint_t -> size_t).
      19aee943
  12. Nov 29, 2017
  13. 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
  14. Nov 16, 2017
    • Damien George's avatar
      py/objstr: When constructing str from bytes, check for existing qstr. · 8d956c26
      Damien George authored
      This patch uses existing qstr data where possible when constructing a str
      from a bytes object.
      8d956c26
    • Damien George's avatar
      py/objstr: Make mp_obj_new_str_of_type check for existing interned qstr. · 1f1d5194
      Damien George authored
      The function mp_obj_new_str_of_type is a general str object constructor
      used in many places in the code to create either a str or bytes object.
      When creating a str it should first check if the string data already exists
      as an interned qstr, and if so then return the qstr object.  This patch
      makes the function have such behaviour, which helps to reduce heap usage by
      reusing existing interned data where possible.
      
      The old behaviour of mp_obj_new_str_of_type (which didn't check for
      existing interned data) is made available through the function
      mp_obj_new_str_copy, but should only be used in very special cases.
      
      One consequence of this patch is that the following expression is now True:
      
          'abc' is ' abc '.split()[0]
      1f1d5194
    • Damien George's avatar
      py/objstr: Remove "make_qstr_if_not_already" arg from mp_obj_new_str. · 4601759b
      Damien George authored
      This patch simplifies the str creation API to favour the common case of
      creating a str object that is not forced to be interned.  To force
      interning of a new str the new mp_obj_new_str_via_qstr function is added,
      and should only be used if warranted.
      
      Apart from simplifying the mp_obj_new_str function (and making it have the
      same signature as mp_obj_new_bytes), this patch also reduces code size by a
      bit (-16 bytes for bare-arm and roughly -40 bytes on the bare-metal archs).
      4601759b
  15. Oct 04, 2017
    • Damien George's avatar
      py/objstr: Make empty bytes object have a null-terminating byte. · dfa563c7
      Damien George authored
      Because a lot of string processing functions assume there is a null
      terminating byte, so they can work in an efficient way.
      
      Fixes issue #3334.
      dfa563c7
    • 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
  16. Sep 19, 2017
  17. Sep 06, 2017
    • tll's avatar
      py/objstr: Add check for valid UTF-8 when making a str from bytes. · 68c28174
      tll authored
      This patch adds a function utf8_check() to check for a valid UTF-8 encoded
      string, and calls it when constructing a str from raw bytes.  The feature
      is selectable at compile time via MICROPY_PY_BUILTINS_STR_UNICODE_CHECK and
      is enabled if unicode is enabled.  It costs about 110 bytes on Thumb-2, 150
      bytes on Xtensa and 170 bytes on x86-64.
      68c28174
  18. Aug 29, 2017
  19. Aug 28, 2017
  20. 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
  21. Aug 09, 2017
  22. Jul 31, 2017
  23. Jul 03, 2017
  24. Jul 02, 2017
  25. Jun 07, 2017
  26. Jun 02, 2017
  27. May 29, 2017
  28. Apr 02, 2017
  29. Mar 29, 2017
    • Damien George's avatar
    • Damien George's avatar
      py: Convert mp_uint_t to size_t for tuple/list accessors. · 6213ad7f
      Damien George authored
      This patch changes mp_uint_t to size_t for the len argument of the
      following public facing C functions:
      
      mp_obj_tuple_get
      mp_obj_list_get
      mp_obj_get_array
      
      These functions take a pointer to the len argument (to be filled in by the
      function) and callers of these functions should update their code so the
      type of len is changed to size_t.  For ports that don't use nan-boxing
      there should be no change in generate code because the size of the type
      remains the same (word sized), and in a lot of cases there won't even be a
      compiler warning if the type remains as mp_uint_t.
      
      The reason for this change is to standardise on the use of size_t for
      variables that count memory (or memory related) sizes/lengths.  It helps
      builds that use nan-boxing.
      6213ad7f
  30. Mar 23, 2017
  31. Mar 20, 2017
    • stijn's avatar
      py/objstr: Use better msg in bad implicit str/bytes conversion exception · bf29fe2e
      stijn authored
      Instead of always reporting some object cannot be implicitly be converted
      to a 'str', even when it is a 'bytes' object, adjust the logic so that
      when trying to convert str to bytes it is shown like that.
      This will still report bad implicit conversion from e.g. 'int to bytes'
      as 'int to str' but it will not result in the confusing
      'can't convert 'str' object to str implicitly' anymore for calls like
      b'somestring'.count('a').
      bf29fe2e
  32. Mar 16, 2017
  33. Mar 07, 2017
  34. Feb 16, 2017
Loading