1. 20 Feb, 2018 4 commits
  2. 19 Feb, 2018 1 commit
    • 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.
  3. 14 Feb, 2018 1 commit
    • 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).
  4. 29 Nov, 2017 1 commit
  5. 24 Nov, 2017 1 commit
    • 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.
  6. 16 Nov, 2017 3 commits
    • 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.
    • 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]
    • 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).
  7. 04 Oct, 2017 2 commits
    • 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.
    • 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.
  8. 19 Sep, 2017 1 commit
  9. 06 Sep, 2017 1 commit
    • 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.
  10. 29 Aug, 2017 1 commit
  11. 28 Aug, 2017 1 commit
  12. 13 Aug, 2017 1 commit
    • 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.
  13. 09 Aug, 2017 1 commit
  14. 31 Jul, 2017 1 commit
  15. 03 Jul, 2017 1 commit
  16. 02 Jul, 2017 1 commit
  17. 07 Jun, 2017 1 commit
  18. 02 Jun, 2017 1 commit
  19. 29 May, 2017 1 commit
  20. 02 Apr, 2017 1 commit
  21. 29 Mar, 2017 2 commits
    • 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:
      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.
  22. 23 Mar, 2017 1 commit
  23. 20 Mar, 2017 1 commit
    • 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
  24. 16 Mar, 2017 1 commit
  25. 07 Mar, 2017 1 commit
  26. 16 Feb, 2017 2 commits
  27. 03 Feb, 2017 2 commits
  28. 26 Jan, 2017 1 commit
    • Paul Sokolovsky's avatar
      py/objstr: Optimize string concatenation with empty string. · e2e66329
      Paul Sokolovsky authored
      In this, don't allocate copy, just return non-empty string. This helps
      with a standard pattern of buffering data in case of short reads:
          buf = b""
          while ...:
              s = f.read(...)
              buf += s
      For a typical case when single read returns all data needed, there won't
      be extra allocation. This optimization helps uasyncio.
  29. 27 Sep, 2016 1 commit
  30. 02 Sep, 2016 1 commit
  31. 14 Aug, 2016 1 commit