summaryrefslogtreecommitdiff
path: root/py/mpprint.c
AgeCommit message (Collapse)Author
2020-12-07py/mpprint: Fix length calculation for strings with precision-modifier.Joris Peeraer
Two issues are tackled: 1. The calculation of the correct length to print is fixed to treat the precision as a maximum length instead as the exact length. This is done for both qstr (%q) and for regular str (%s). 2. Fix the incorrect use of mp_printf("%.*s") to mp_print_strn(). Because of the fix of above issue, some testcases that would print an embedded null-byte (^@ in test-output) would now fail. The bug here is that "%s" was used to print null-bytes. Instead, mp_print_strn is used to make sure all bytes are outputted and the exact length is respected. Test-cases are added for both %s and %q with a combination of precision and padding specifiers.
2020-11-29py/mpprint: Prevent case fall-through when assert is disabled.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2020-04-18all: Fix implicit conversion from double to float.stijn
These are found when building with -Wfloat-conversion.
2020-02-28all: Reformat C and Python source code with tools/codeformat.py.Damien George
This is run with uncrustify 0.70.1, and black 19.10b0.
2019-04-23py/mpprint: Support printing %ld and %lu formats on 64-bit archs.Damien George
Fixes issue #4702.
2019-02-12py: Downcase all MP_OBJ_IS_xxx macros to make a more consistent C API.Damien George
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.
2017-12-07py/mpprint: Fix "%x" vs "%X" regression introduced in previous commit.Paul Sokolovsky
2017-12-07py/mpprint: Support "%lx" format on 64-bit systems.Paul Sokolovsky
Before that, the output was truncated to 32 bits. Only "%x" format is handled, because a typical use is for addresses. This refactor actually decreased x86_64 code size by 30 bytes.
2017-12-07py/mpprint: Make "%p" format work properly on 64-bit systems.Paul Sokolovsky
Before, the output was truncated to 32 bits.
2017-10-04py/mpprint: Only check for null string printing when NDEBUG not defined.Damien George
Printing "(null)" when a NULL string pointer is passed to %s is a debugging feature and not a feature that's relied upon by the code. So it only needs to be compiled in when debugging (such as assert) is enabled, and saves roughy 30 bytes of code when disabled. This patch also fixes this NULL check to not do the check if the precision is specified as zero.
2017-07-31all: Use the name MicroPython consistently in commentsAlexander Steffen
There were several different spellings of MicroPython present in comments, when there should be only one.
2017-06-30py/mpprint: Remove unreachable check for neg return of mp_format_float.Damien George
2017-03-15py/mpprint: Fix int formatting so "+" is printed for 0-valued integer.Damien George
2016-12-28py/mpprint: Add assertion for, and comment about, valid base values.Damien George
2016-10-11py/objint: Use size_t for arguments that measure bytes/sizes.Damien George
2016-09-01py/mpprint: Fail an assertion with unsupported format specifiers.Delio Brignoli
Arguments of an unknown type cannot be skipped and continuing to parse a format string after encountering an unknown format specifier leads to undefined behaviour. This patch helps to find use of unsupported formats.
2016-02-01py/mpprint: Fix sign extension when printf'ing %u, %x and %X.Damien George
2016-01-07py: Change mp_obj_int_is_positive to more general mp_obj_int_sign.Damien George
This function returns the sign (-1, 0 or 1) of the integer object.
2015-12-19py/mpprint: Fix printing of 64bit integers for 64bit windows buildsstijn
This makes all tests pass again for 64bit windows builds which would previously fail for anything printing ranges (builtin_range/unpack1) because they were printed as range( ld, ld ). This is done by reusing the mp_vprintf implementation for MICROPY_OBJ_REPR_D for 64bit windows builds (both msvc and mingw-w64) since the format specifier used for 64bit integers is also %lld, or %llu for the unsigned version. Note these specifiers used to be fetched from inttypes.h, which is the C99 way of working with printf/scanf in a portable way, but mingw-w64 wants to be backwards compatible with older MS C runtimes and uses the non-portable %I64i instead of %lld in inttypes.h, so remove the use of said header again in mpconfig.h and define the specifiers manually.
2015-12-17py/mpprint: Implement %llu and %lld format specifiers for mp_printf.Damien George
Only enabled for MICROPY_OBJ_REPR_D.
2015-12-02py/mpprint: Printing of doubles is now supported (by uPy own routine).fabien.lementec
2015-11-29py: Change qstr_* functions to use size_t as the type for str len arg.Damien George
2015-11-29py: Change mp_print_strn_t func type to use size_t for the str length.Damien George
2015-10-31all: Add py/mphal.h and use it in all ports.Damien George
py/mphal.h contains declarations for generic mp_hal_XXX functions, such as stdio and delay/ticks, which ports should provide definitions for. A port will also provide mphalport.h with further HAL declarations.
2015-05-28py: Remove unnecessary extra handling of padding of nan/inf.Damien George
C's printf will pad nan/inf differently to CPython. Our implementation originally conformed to C, now it conforms to CPython's way. Tests for this are also added in this patch.
2015-05-28py: Reduce size of mp_printf by eliminating unnecessary code.Damien George
Saves around 120 bytes on Thumb2 archs.
2015-05-17py: Implement mp_format_float for doubles and use where appropriatestijn
This allows using (almost) the same code for printing floats everywhere, removes the dependency on sprintf and uses just snprintf and applies an msvc-specific fix for snprintf in a single place so nan/inf are now printed correctly.
2015-04-16py: Add %q format support to mp_[v]printf, and use it.Damien George
2015-04-16py: Overhaul and simplify printf/pfenv mechanism.Damien George
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.