diff options
author | Damien George <damien.p.george@gmail.com> | 2017-08-14 12:21:43 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2017-08-14 12:21:43 +1000 |
commit | 1db008349cc970fd83b85574492badbf0460ad51 (patch) | |
tree | 76ca40810fd44eec799ff01e3c3a753c494bae9e /py/objstr.c | |
parent | bb254ba0ea89ce60dd6deab94991b2651c00dff3 (diff) | |
parent | 3611dcc260cef08eaa497cea4e3ca17977848b6c (diff) |
Merge tag 'v1.8.4' into parse-bytecode
Support for stream decompression in uzlib, and more ESP8266 features
This release includes some bug fixes, code clean-up, updates to the docs,
more tests, and various feature additions. The uzlib module now supports
efficient stream decompression in the form of the uzlib.DecompIO class.
Freezing of bytecode now supports floats for the ESP8266 port, as well as
complex numbers for all ports. The stmhal port has ADC working on L4
microcontrollers, fixed initialisation for DAC, and addition of the
machine.WDT class and machine.reset_cause function.
For the ESP8266 port Pin(16) now works as an input pin and the hardware
SPI peripheral is exposed as machine.SPI(1). The os.umount function is
implemented and the port supports mounting of externally connected SD
cards. The machine.WDT class is added, wlan.scan() is fixed to return all
access points, and there is support for DS18S20 devices.
py core:
- runtime: factor out exception raising helpers
- runtime: define mp_check_self(pred) helper macro
- objdict: get rid of asserts (remove/replace with mp_check_self())
- get rid of assert() in method argument checking functions
- objtuple: in tuple_cmp_helper, use mp_check_self instead of raising
- objstr: use mp_raise_{Type,Value}Error instead of mp_raise_msg
- obj.h: for obj reprs A,B,C use void* explicitly for mp_obj_t typedef
- mpconfigport.h: remove typedef of machine_ptr_t, it's no longer needed
- sequence: allow to use bignums as indices in slice objects
- stream.c: use mp_obj_get_type in mp_get_stream_raise
- gc: add MICROPY_GC_CONSERVATIVE_CLEAR option to always zero memory
- compile: don't compile assert statements when optimisations enabled
- modstruct: use more compact mp_raise_ValueError function
- emitglue: use more compact mp_raise_ValueError function
- rename struct mp_code_state to mp_code_state_t
- mkrules.mk: allow to override name of libmicropython.a
- mpprint: fail an assertion with unsupported format specifiers
- makeqstrdata.py: compute the qstr hash from bytes, not characters
- if str/bytes hash is 0 then explicitly compute it
- emitglue.c: provide mp_raw_code_load_file for any unix architecture
- add MICROPY_USE_INTERNAL_PRINTF option, defaults to enabled
extmod:
- modwebrepl: set_password(): raise exception for too long password
- uzlib/: update uzlib to v2.0: new API supporting stream decompression
- moduzlib: refactor to new stream-compatible uzlib 2.0 API
- uzlib/: update uzlib to v2.0.1: fixes for pedantic compiler warnings
- uzlib/: update uzlib to v2.0.2: consistently use stdint types
- modbtree: do CHECK_ERROR after __bt_seq()
- modubinascii: implement binascii.crc32
- modubinascii: make crc32() support configurable
- modframebuf: fix pixel accessor to return a 1-bit result
- add machine_spi with generic SPI C-protocol and helper methods
- modframebuf: fix fill and scroll when height not divisible by 8
- moduzlib: implement zlib stream decompressor class, DecompIO
- moduzlib: use mperrno.h for error constants
- modframebuf: include font from stmhal directory explicitly
- moduzlib: support wbits arg to DecompIO
- framebuf: add the xstep!=0 case to scroll() method
lib:
- utils/stdout_helpers: fix function signature to match py/mphal.h
- berkeley-db-1.xx: update to upstream, fixes MacOSX build
- utils/pyexec: qstr_pool_info() requires size_t* parameters
drivers:
- sdcard: port the SDCard driver to new machine API, with backwards
compatibility for pyboard
tools:
- mpy-tool.py: support freezing float literals with obj-repr C
- mpy-tool.py: store qstr config values in global config object
- mpy-tool.py: compute the hash value for str/bytes objects
- mpy-tool.py: support freezing of complex numbers
tests:
- rename zlibd_decompress.py -> uzlib_decompress.py
- basics: add more tuple tests to improve coverage testing
- basics: add more list tests to improve coverage testing
- misc/non_compliant: add tests to improve coverage testing
- basics: add test for break from within try within a for-loop
- basics: add a test file for overriding special methods
- basics/special_methods: enable tests for extra special methods
- uzlib_decompress: actually test raw DEFLATE stream
- run-tests: disable thread/thread_lock4.py on Travis
- run-tests: disable thread/stress_heap.py when running on Travis
- cmdline: add test for -O option to check optimisation value
- extmod/vfs_fat_ramdisk: add tests for VFS.umount()
- run-tests: disable thread_gc1.py test on Travis
- unix/extra_coverage: add test for str/bytes with invalid hash
- extmod: add test for uzlib.DecompIO
- extmod: add a test for framebuf module, tested by coverage build
- extmod/uzlib_decompio: add zlib bitstream testcases
- extmod/framebuf1: add tests for scrolling in the x-direction
- run-tests: disable thread/stress_recurse.py test on Travis
unix port:
- mpconfigport.h: don't include stdio.h on MacOS
- when find'ing frozen files don't use extra slash, do follow symlinks
qemu-arm port:
- enable MICROPY_PY_ALL_SPECIAL_METHODS
stmhal port:
- boards: update STM32L476 pin defs to include ADC channels
- adc.c: get ADC working on STM32L4 MCUs
- fix timer capture/compare interrupt handling for TIM1 and TIM8
- remove obsolete code for special handling of TIM3 irq settings
- make ADC channel 16 available on L4 MCUs
- update pin print to print new constants
- modusocket: set self->nic to MP_OBJ_NULL after socket close
- update boot.py files to use VCP instead of CDC
- spi: factor out SPI transfer code to a single function
- spi: support new machine SPI methods in legacy SPI object
- add machine.WDT class
- set STM32F7DISC CPU Frequency to 216 MHz
- dac: fix DAC (re-)initialisation by resetting DMA
- wdt: implement keyword args to WDT constructor
- modmachine: implement machine.reset_cause() function, and consts
- machine.POWER_ON is renamed to machine.PWRON_RESET
- when find'ing frozen files don't use extra slash, do follow symlinks
cc3200 port:
- add machine.PWRON_RESET constant (machine.POWER_ON is now deprecated)
teensy port:
- fix execution of frozen boot.py and main.py
esp8266 port:
- fix reading of pin object for GPIO16; Pin(16) now works as an input
- PULL_UP is not supported on Pin(16), so raise an exception in this case
- enable support for all special methods
- modpybhspi: add a HSPI module for hardware SPI support
- modmachinespi: add a factory method for SoftSPI/HSPI
- esp_mphal: no longer disable watchdog on startup
- modpybrtc: use 64-bit arithmetic when computing alarm expiry
- hspi: enable duplex operation of hardware SPI
- modous: add os.umount method to unmount a filesystem
- modmachinewdt: implement machine.WDT class
- modules: split onewire.py into OneWire and DS18X20 driver
- modules/onewire: change onewire.read() to onewire.readinto()
- modules/ds18x20.py: add support for DS18S20 devices
- modpybspi: use generic SPI helper methods to implement SPI
- modpybhspi: simplify HSPI driver by using 1 function for xfers
- modmachinewdt: add .deinit() method
- modmachine: add WDT_RESET and SOFT_RESET constants
- modmachine: don't expose internal SoftSPI and HSPI classes
- modmachine: simplify SPI class implementation multiplexing
- espneopixel: disable IRQs during eps.neopixel_write
- modnetwork: fix wlan.scan() method so it returns all networks
- modmachine: map PWR_ON_RESET to vendor's REASON_DEFAULT_RST
- machine.PWR_ON_RESET is renamed to machine.PWRON_RESET
- when find'ing frozen files don't use extra slash, do follow symlinks
docs:
- esp8266/tutorial/pins: fix typo in commands for pin input mode
- esp8266/intro: add command to install esptool.py 1.0.1 via pip
- library/machine.WDT: add note that WDT is only available on WiPy
- esp8266/quickref: fix and update the SPI docs
- esp8266: update quickref and tutorial for OneWire/DS18X20 driver
- pyboard: update USB mouse tutorial to use VCP instead of CDC
- pyboard: update USB mouse tutorial to use pyb.USB_HID()
- library: add reference for pyb.usb_mode and pyb.USB_HID
- pyboard/quickref: add links to pinouts for other pyboard variants
- pyboard/quickref: add section on "delay and timing" for utime mod
- esp8266/quickref: add internal links to docs for some modules
- esp8266/quickref: update information on SPI classes
- esp8266/quickref: further improvements for SPI subsections
- library/machine.WDT: add that WDT is available on pyboard
- reference/isr_rules.rst: two minor additions to docs for using ISR
misc:
- add *.pyc to .gitignore, because Python 2 doesn't use __pycache__
- build mpy-cross as part of the Travis process
Diffstat (limited to 'py/objstr.c')
-rw-r--r-- | py/objstr.c | 104 |
1 files changed, 48 insertions, 56 deletions
diff --git a/py/objstr.c b/py/objstr.c index a6ee617c0..406ccf290 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -158,6 +158,9 @@ mp_obj_t mp_obj_str_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_ if (MP_OBJ_IS_TYPE(args[0], &mp_type_bytes)) { GET_STR_DATA_LEN(args[0], str_data, str_len); GET_STR_HASH(args[0], str_hash); + if (str_hash == 0) { + str_hash = qstr_compute_hash(str_data, str_len); + } mp_obj_str_t *o = MP_OBJ_TO_PTR(mp_obj_new_str_of_type(type, NULL, str_len)); o->data = str_data; o->hash = str_hash; @@ -191,6 +194,9 @@ STATIC mp_obj_t bytes_make_new(const mp_obj_type_t *type_in, size_t n_args, size } GET_STR_DATA_LEN(args[0], str_data, str_len); GET_STR_HASH(args[0], str_hash); + if (str_hash == 0) { + str_hash = qstr_compute_hash(str_data, str_len); + } mp_obj_str_t *o = MP_OBJ_TO_PTR(mp_obj_new_str_of_type(&mp_type_bytes, NULL, str_len)); o->data = str_data; o->hash = str_hash; @@ -231,7 +237,7 @@ STATIC mp_obj_t bytes_make_new(const mp_obj_type_t *type_in, size_t n_args, size mp_int_t val = mp_obj_get_int(item); #if MICROPY_CPYTHON_COMPAT if (val < 0 || val > 255) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "bytes value out of range")); + mp_raise_ValueError("bytes value out of range"); } #endif vstr_add_byte(&vstr, val); @@ -240,7 +246,7 @@ STATIC mp_obj_t bytes_make_new(const mp_obj_type_t *type_in, size_t n_args, size return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); wrong_args: - nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "wrong number of arguments")); + mp_raise_TypeError("wrong number of arguments"); } // like strstr but with specified length and allows \0 bytes @@ -412,7 +418,7 @@ STATIC mp_obj_t bytes_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { } STATIC mp_obj_t str_join(mp_obj_t self_in, mp_obj_t arg) { - assert(MP_OBJ_IS_STR_OR_BYTES(self_in)); + mp_check_self(MP_OBJ_IS_STR_OR_BYTES(self_in)); const mp_obj_type_t *self_type = mp_obj_get_type(self_in); // get separation string @@ -436,8 +442,8 @@ STATIC mp_obj_t str_join(mp_obj_t self_in, mp_obj_t arg) { mp_uint_t required_len = 0; for (mp_uint_t i = 0; i < seq_len; i++) { if (mp_obj_get_type(seq_items[i]) != self_type) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, - "join expects a list of str/bytes objects consistent with self object")); + mp_raise_TypeError( + "join expects a list of str/bytes objects consistent with self object"); } if (i > 0) { required_len += sep_len; @@ -511,7 +517,7 @@ mp_obj_t mp_obj_str_split(size_t n_args, const mp_obj_t *args) { const char *sep_str = mp_obj_str_get_data(sep, &sep_len); if (sep_len == 0) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "empty separator")); + mp_raise_ValueError("empty separator"); } for (;;) { @@ -609,7 +615,7 @@ STATIC mp_obj_t str_rsplit(size_t n_args, const mp_obj_t *args) { const char *sep_str = mp_obj_str_get_data(sep, &sep_len); if (sep_len == 0) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "empty separator")); + mp_raise_ValueError("empty separator"); } const byte *beg = s; @@ -648,8 +654,7 @@ STATIC mp_obj_t str_rsplit(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t str_finder(mp_uint_t n_args, const mp_obj_t *args, mp_int_t direction, bool is_index) { const mp_obj_type_t *self_type = mp_obj_get_type(args[0]); - assert(2 <= n_args && n_args <= 4); - assert(MP_OBJ_IS_STR_OR_BYTES(args[0])); + mp_check_self(MP_OBJ_IS_STR_OR_BYTES(args[0])); // check argument type if (mp_obj_get_type(args[1]) != self_type) { @@ -672,7 +677,7 @@ STATIC mp_obj_t str_finder(mp_uint_t n_args, const mp_obj_t *args, mp_int_t dire if (p == NULL) { // not found if (is_index) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "substring not found")); + mp_raise_ValueError("substring not found"); } else { return MP_OBJ_NEW_SMALL_INT(-1); } @@ -734,8 +739,7 @@ STATIC mp_obj_t str_endswith(size_t n_args, const mp_obj_t *args) { enum { LSTRIP, RSTRIP, STRIP }; STATIC mp_obj_t str_uni_strip(int type, mp_uint_t n_args, const mp_obj_t *args) { - assert(1 <= n_args && n_args <= 2); - assert(MP_OBJ_IS_STR_OR_BYTES(args[0])); + mp_check_self(MP_OBJ_IS_STR_OR_BYTES(args[0])); const mp_obj_type_t *self_type = mp_obj_get_type(args[0]); const byte *chars_to_del; @@ -878,7 +882,7 @@ STATIC mp_obj_t arg_as_int(mp_obj_t arg) { } STATIC NORETURN void terse_str_format_value_error(void) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "bad format string")); + mp_raise_ValueError("bad format string"); } STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *arg_i, mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { @@ -896,8 +900,7 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { terse_str_format_value_error(); } else { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, - "single '}' encountered in format string")); + mp_raise_ValueError("single '}' encountered in format string"); } } if (*str != '{') { @@ -936,12 +939,11 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { terse_str_format_value_error(); } else if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NORMAL) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, - "bad conversion specifier")); + mp_raise_ValueError("bad conversion specifier"); } else { if (str >= top) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, - "end of format while looking for conversion specifier")); + mp_raise_ValueError( + "end of format while looking for conversion specifier"); } else { nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "unknown conversion specifier %c", *str)); @@ -975,16 +977,14 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { terse_str_format_value_error(); } else { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, - "unmatched '{' in format")); + mp_raise_ValueError("unmatched '{' in format"); } } if (*str != '}') { if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { terse_str_format_value_error(); } else { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, - "expected ':' after format specifier")); + mp_raise_ValueError("expected ':' after format specifier"); } } @@ -997,13 +997,13 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { terse_str_format_value_error(); } else { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, - "can't switch from automatic field numbering to manual field specification")); + mp_raise_ValueError( + "can't switch from automatic field numbering to manual field specification"); } } field_name = str_to_int(field_name, field_name_top, &index); if ((uint)index >= n_args - 1) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_IndexError, "tuple index out of range")); + mp_raise_msg(&mp_type_IndexError, "tuple index out of range"); } arg = args[index + 1]; *arg_i = -1; @@ -1026,12 +1026,12 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { terse_str_format_value_error(); } else { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, - "can't switch from manual field specification to automatic field numbering")); + mp_raise_ValueError( + "can't switch from manual field specification to automatic field numbering"); } } if ((uint)*arg_i >= n_args - 1) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_IndexError, "tuple index out of range")); + mp_raise_msg(&mp_type_IndexError, "tuple index out of range"); } arg = args[(*arg_i) + 1]; (*arg_i)++; @@ -1120,8 +1120,7 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { terse_str_format_value_error(); } else { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, - "invalid format specifier")); + mp_raise_ValueError("invalid format specifier"); } } vstr_clear(&format_spec_vstr); @@ -1142,16 +1141,15 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { terse_str_format_value_error(); } else { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, - "sign not allowed in string format specifier")); + mp_raise_ValueError("sign not allowed in string format specifier"); } } if (type == 'c') { if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { terse_str_format_value_error(); } else { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, - "sign not allowed with integer format specifier 'c'")); + mp_raise_ValueError( + "sign not allowed with integer format specifier 'c'"); } } } else { @@ -1295,8 +1293,8 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { terse_str_format_value_error(); } else { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, - "'=' alignment not allowed in string format specifier")); + mp_raise_ValueError( + "'=' alignment not allowed in string format specifier"); } } @@ -1331,7 +1329,7 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar } mp_obj_t mp_obj_str_format(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { - assert(MP_OBJ_IS_STR_OR_BYTES(args[0])); + mp_check_self(MP_OBJ_IS_STR_OR_BYTES(args[0])); GET_STR_DATA_LEN(args[0], str, len); int arg_i = 0; @@ -1340,7 +1338,7 @@ mp_obj_t mp_obj_str_format(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs } STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, mp_uint_t n_args, const mp_obj_t *args, mp_obj_t dict) { - assert(MP_OBJ_IS_STR_OR_BYTES(pattern)); + mp_check_self(MP_OBJ_IS_STR_OR_BYTES(pattern)); GET_STR_DATA_LEN(pattern, str, len); const byte *start_str = str; @@ -1372,8 +1370,7 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, mp_uint_t n_args, const mp_o if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { terse_str_format_value_error(); } else { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, - "incomplete format key")); + mp_raise_ValueError("incomplete format key"); } } ++str; @@ -1431,8 +1428,7 @@ incomplete_format: if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { terse_str_format_value_error(); } else { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, - "incomplete format")); + mp_raise_ValueError("incomplete format"); } } @@ -1440,7 +1436,7 @@ incomplete_format: if (arg == MP_OBJ_NULL) { if ((uint)arg_i >= n_args) { not_enough_args: - nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "not enough arguments for format string")); + mp_raise_TypeError("not enough arguments for format string"); } arg = args[arg_i++]; } @@ -1450,16 +1446,14 @@ not_enough_args: mp_uint_t slen; const char *s = mp_obj_str_get_data(arg, &slen); if (slen != 1) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, - "%%c requires int or char")); + mp_raise_TypeError("%%c requires int or char"); } mp_print_strn(&print, s, 1, flags, ' ', width); } else if (arg_looks_integer(arg)) { char ch = mp_obj_get_int(arg); mp_print_strn(&print, &ch, 1, flags, ' ', width); } else { - nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, - "integer required")); + mp_raise_TypeError("integer required"); } break; @@ -1529,7 +1523,7 @@ not_enough_args: } if ((uint)arg_i != n_args) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "not all arguments converted during string formatting")); + mp_raise_TypeError("not all arguments converted during string formatting"); } return mp_obj_new_str_from_vstr(is_bytes ? &mp_type_bytes : &mp_type_str, &vstr); @@ -1538,7 +1532,7 @@ not_enough_args: // The implementation is optimized, returning the original string if there's // nothing to replace. STATIC mp_obj_t str_replace(size_t n_args, const mp_obj_t *args) { - assert(MP_OBJ_IS_STR_OR_BYTES(args[0])); + mp_check_self(MP_OBJ_IS_STR_OR_BYTES(args[0])); mp_int_t max_rep = -1; if (n_args == 4) { @@ -1644,8 +1638,7 @@ STATIC mp_obj_t str_replace(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t str_count(size_t n_args, const mp_obj_t *args) { const mp_obj_type_t *self_type = mp_obj_get_type(args[0]); - assert(2 <= n_args && n_args <= 4); - assert(MP_OBJ_IS_STR_OR_BYTES(args[0])); + mp_check_self(MP_OBJ_IS_STR_OR_BYTES(args[0])); // check argument type if (mp_obj_get_type(args[1]) != self_type) { @@ -1685,7 +1678,7 @@ STATIC mp_obj_t str_count(size_t n_args, const mp_obj_t *args) { #if MICROPY_PY_BUILTINS_STR_PARTITION STATIC mp_obj_t str_partitioner(mp_obj_t self_in, mp_obj_t arg, mp_int_t direction) { - assert(MP_OBJ_IS_STR_OR_BYTES(self_in)); + mp_check_self(MP_OBJ_IS_STR_OR_BYTES(self_in)); mp_obj_type_t *self_type = mp_obj_get_type(self_in); if (self_type != mp_obj_get_type(arg)) { bad_implicit_conversion(arg); @@ -1695,7 +1688,7 @@ STATIC mp_obj_t str_partitioner(mp_obj_t self_in, mp_obj_t arg, mp_int_t directi GET_STR_DATA_LEN(arg, sep, sep_len); if (sep_len == 0) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "empty separator")); + mp_raise_ValueError("empty separator"); } mp_obj_t result[3]; @@ -2061,8 +2054,7 @@ bool mp_obj_str_equal(mp_obj_t s1, mp_obj_t s2) { STATIC void bad_implicit_conversion(mp_obj_t self_in) { if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, - "can't convert to str implicitly")); + mp_raise_TypeError("can't convert to str implicitly"); } else { nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "can't convert '%s' object to str implicitly", |