From 2725a791929f901c692d09f0afe7cc6a700384d5 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 13 Apr 2020 14:52:10 +1000 Subject: [PATCH] py: Always give noop defines when MICROPY_ROM_TEXT_COMPRESSION disabled. This commit provides a typedef for mp_rom_error_text_t, and a macro define for MP_COMPRESSED_ROM_TEXT, when MICROPY_ROM_TEXT_COMPRESSION is disabled. This simplifies the configuration (it no longer has a special case for MICROPY_ENABLE_DYNRUNTIME) and makes it work for other cases that don't use compression (eg examples/embedding). This commit also ensures MICROPY_ROM_TEXT_COMPRESSION is defined during qstr processing. --- py/misc.h | 20 ++++++++------------ py/mkrules.mk | 15 +++++++-------- py/objexcept.c | 5 +++-- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/py/misc.h b/py/misc.h index d1f8a65177..c7060ddf9d 100644 --- a/py/misc.h +++ b/py/misc.h @@ -259,26 +259,21 @@ typedef union _mp_float_union_t { /** ROM string compression *************/ +#if MICROPY_ROM_TEXT_COMPRESSION + #ifdef NO_QSTR -// QSTR extraction sets NO_QSTR. +// Compression enabled but doing QSTR extraction. // So leave MP_COMPRESSED_ROM_TEXT in place for makeqstrdefs.py / makecompresseddata.py to find them. -// However, dynamic native modules also set NO_QSTR, so provide a dummy implementation. -#if MICROPY_ENABLE_DYNRUNTIME -typedef const char *mp_rom_error_text_t; -#define MP_COMPRESSED_ROM_TEXT(x) x -#endif - #else -#if MICROPY_ROM_TEXT_COMPRESSION +// Compression enabled and doing a regular build. +// Map MP_COMPRESSED_ROM_TEXT to the compressed strings. // Force usage of the MP_ERROR_TEXT macro by requiring an opaque type. typedef struct {} *mp_rom_error_text_t; -// Regular build -- map MP_COMPRESSED_ROM_TEXT to the compressed strings. - #include inline __attribute__((always_inline)) const char *MP_COMPRESSED_ROM_TEXT(const char *msg) { @@ -297,16 +292,17 @@ inline __attribute__((always_inline)) const char *MP_COMPRESSED_ROM_TEXT(const c return msg; } +#endif + #else // Compression not enabled, just make it a no-op. + typedef const char *mp_rom_error_text_t; #define MP_COMPRESSED_ROM_TEXT(x) x #endif // MICROPY_ROM_TEXT_COMPRESSION -#endif // NO_QSTR - // Might add more types of compressed text in the future. // For now, forward directly to MP_COMPRESSED_ROM_TEXT. #define MP_ERROR_TEXT(x) (mp_rom_error_text_t)MP_COMPRESSED_ROM_TEXT(x) diff --git a/py/mkrules.mk b/py/mkrules.mk index 6c7d3701f4..c37c25db4b 100644 --- a/py/mkrules.mk +++ b/py/mkrules.mk @@ -7,20 +7,19 @@ endif # Extra deps that need to happen before object compilation. OBJ_EXTRA_ORDER_DEPS = +ifeq ($(MICROPY_ROM_TEXT_COMPRESSION),1) +# If compression is enabled, trigger the build of compressed.data.h... +OBJ_EXTRA_ORDER_DEPS += $(HEADER_BUILD)/compressed.data.h +# ...and enable the MP_COMPRESSED_ROM_TEXT macro (used by MP_ERROR_TEXT). +CFLAGS += -DMICROPY_ROM_TEXT_COMPRESSION=1 +endif + # QSTR generation uses the same CFLAGS, with these modifications. # Note: := to force evalulation immediately. QSTR_GEN_CFLAGS := $(CFLAGS) QSTR_GEN_CFLAGS += -DNO_QSTR QSTR_GEN_CFLAGS += -I$(BUILD)/tmp -ifeq ($(MICROPY_ROM_TEXT_COMPRESSION),1) -# If compression is enabled, trigger the build of compressed.data.h... -OBJ_EXTRA_ORDER_DEPS += $(HEADER_BUILD)/compressed.data.h -# ...and enable the MP_COMPRESSED_ROM_TEXT macro (used by MP_ERROR_TEXT). -# Note, this doesn't get added to the QSTR_GEN_CFLAGS. -CFLAGS += -DMICROPY_ROM_TEXT_COMPRESSION=1 -endif - # This file expects that OBJ contains a list of all of the object files. # The directory portion of each object file is used to locate the source # and should not contain any ..'s but rather be relative to the top of the diff --git a/py/objexcept.c b/py/objexcept.c index 59a0557b13..517427ed71 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -38,8 +38,9 @@ #include "py/gc.h" #include "py/mperrno.h" -// Extract the MP_MAX_UNCOMPRESSED_TEXT_LEN macro from "genhdr/compressed.data.h" -#if MICROPY_ROM_TEXT_COMPRESSION +#if MICROPY_ROM_TEXT_COMPRESSION && !defined(NO_QSTR) +// Extract the MP_MAX_UNCOMPRESSED_TEXT_LEN macro from "genhdr/compressed.data.h". +// Only need this if compression enabled and in a regular build (i.e. not during QSTR extraction). #define MP_MATCH_COMPRESSED(...) // Ignore #define MP_COMPRESSED_DATA(...) // Ignore #include "genhdr/compressed.data.h"