diff --git a/examples/natmod/btree/Makefile b/examples/natmod/btree/Makefile index d795102b4a..218ec15a2a 100644 --- a/examples/natmod/btree/Makefile +++ b/examples/natmod/btree/Makefile @@ -11,9 +11,10 @@ SRC = btree_c.c btree_py.py ARCH = x64 BTREE_DIR = $(MPY_DIR)/lib/berkeley-db-1.xx -BTREE_DEFS = -D__DBINTERFACE_PRIVATE=1 -Dmpool_error="(void)" -Dabort=abort_ "-Dvirt_fd_t=void*" $(BTREE_DEFS_EXTRA) -CFLAGS += -I$(BTREE_DIR)/PORT/include -CFLAGS += -Wno-old-style-definition -Wno-sign-compare -Wno-unused-parameter $(BTREE_DEFS) +BERKELEY_DB_CONFIG_FILE ?= \"extmod/berkeley-db/berkeley_db_config_port.h\" +CFLAGS += -I$(BTREE_DIR)/include +CFLAGS += -DBERKELEY_DB_CONFIG_FILE=$(BERKELEY_DB_CONFIG_FILE) +CFLAGS += -Wno-old-style-definition -Wno-sign-compare -Wno-unused-parameter SRC += $(addprefix $(realpath $(BTREE_DIR))/,\ btree/bt_close.c \ diff --git a/examples/natmod/btree/btree_c.c b/examples/natmod/btree/btree_c.c index 3c60e41b2d..bbf51c731f 100644 --- a/examples/natmod/btree/btree_c.c +++ b/examples/natmod/btree/btree_c.c @@ -39,6 +39,10 @@ void abort_(void) { nlr_raise(mp_obj_new_exception(mp_load_global(MP_QSTR_RuntimeError))); } +int puts(const char *s) { + return mp_printf(&mp_plat_print, "%s\n", s); +} + int native_errno; #if defined(__linux__) int *__errno_location (void) diff --git a/extmod/berkeley-db/berkeley_db_config_port.h b/extmod/berkeley-db/berkeley_db_config_port.h new file mode 100644 index 0000000000..41e4acd81e --- /dev/null +++ b/extmod/berkeley-db/berkeley_db_config_port.h @@ -0,0 +1,16 @@ +// Berkeley-db configuration. + +#define __DBINTERFACE_PRIVATE 1 +#define mpool_error printf +#define abort abort_ +#define virt_fd_t void* + +#ifdef MICROPY_BERKELEY_DB_DEFPSIZE +#define DEFPSIZE MICROPY_BERKELEY_DB_DEFPSIZE +#endif + +#ifdef MICROPY_BERKELEY_DB_MINCACHE +#define MINCACHE MICROPY_BERKELEY_DB_MINCACHE +#endif + +__attribute__((noreturn)) void abort_(void); diff --git a/extmod/extmod.cmake b/extmod/extmod.cmake index 957580d15d..60f1a23ad6 100644 --- a/extmod/extmod.cmake +++ b/extmod/extmod.cmake @@ -132,27 +132,27 @@ if(MICROPY_PY_BTREE) ) target_include_directories(micropy_extmod_btree PRIVATE - ${MICROPY_LIB_BERKELEY_DIR}/PORT/include + ${MICROPY_LIB_BERKELEY_DIR}/include ) + if(NOT BERKELEY_DB_CONFIG_FILE) + set(BERKELEY_DB_CONFIG_FILE "${MICROPY_DIR}/extmod/berkeley-db/berkeley_db_config_port.h") + endif() + target_compile_definitions(micropy_extmod_btree PRIVATE - __DBINTERFACE_PRIVATE=1 - mpool_error=printf - abort=abort_ - "virt_fd_t=void*" + BERKELEY_DB_CONFIG_FILE="${BERKELEY_DB_CONFIG_FILE}" ) # The include directories and compile definitions below are needed to build # modbtree.c and should be added to the main MicroPython target. list(APPEND MICROPY_INC_CORE - "${MICROPY_LIB_BERKELEY_DIR}/PORT/include" + "${MICROPY_LIB_BERKELEY_DIR}/include" ) list(APPEND MICROPY_DEF_CORE MICROPY_PY_BTREE=1 - __DBINTERFACE_PRIVATE=1 - "virt_fd_t=void*" + BERKELEY_DB_CONFIG_FILE="${BERKELEY_DB_CONFIG_FILE}" ) list(APPEND MICROPY_SOURCE_EXTMOD diff --git a/extmod/extmod.mk b/extmod/extmod.mk index bf686fbbb4..f7c6f9988e 100644 --- a/extmod/extmod.mk +++ b/extmod/extmod.mk @@ -381,8 +381,10 @@ endif ifeq ($(MICROPY_PY_BTREE),1) BTREE_DIR = lib/berkeley-db-1.xx -BTREE_DEFS = -D__DBINTERFACE_PRIVATE=1 -Dmpool_error=printf -Dabort=abort_ "-Dvirt_fd_t=void*" $(BTREE_DEFS_EXTRA) -INC += -I$(TOP)/$(BTREE_DIR)/PORT/include +BERKELEY_DB_CONFIG_FILE ?= \"extmod/berkeley-db/berkeley_db_config_port.h\" +CFLAGS_EXTMOD += -DBERKELEY_DB_CONFIG_FILE=$(BERKELEY_DB_CONFIG_FILE) +CFLAGS_EXTMOD += $(BTREE_DEFS_EXTRA) +INC += -I$(TOP)/$(BTREE_DIR)/include SRC_THIRDPARTY_C += $(addprefix $(BTREE_DIR)/,\ btree/bt_close.c \ btree/bt_conv.c \ @@ -401,9 +403,7 @@ SRC_THIRDPARTY_C += $(addprefix $(BTREE_DIR)/,\ ) CFLAGS_EXTMOD += -DMICROPY_PY_BTREE=1 # we need to suppress certain warnings to get berkeley-db to compile cleanly -# and we have separate BTREE_DEFS so the definitions don't interfere with other source code -$(BUILD)/$(BTREE_DIR)/%.o: CFLAGS += -Wno-old-style-definition -Wno-sign-compare -Wno-unused-parameter -Wno-deprecated-non-prototype -Wno-unknown-warning-option $(BTREE_DEFS) -$(BUILD)/extmod/modbtree.o: CFLAGS += $(BTREE_DEFS) +$(BUILD)/$(BTREE_DIR)/%.o: CFLAGS += -Wno-old-style-definition -Wno-sign-compare -Wno-unused-parameter -Wno-deprecated-non-prototype -Wno-unknown-warning-option endif ################################################################################ diff --git a/extmod/modbtree.c b/extmod/modbtree.c index f8c38e0ad4..55c13ac911 100644 --- a/extmod/modbtree.c +++ b/extmod/modbtree.c @@ -57,8 +57,8 @@ #undef CIRCLEQ_INSERT_TAIL #undef CIRCLEQ_REMOVE -#include -#include <../../btree/btree.h> +#include "berkeley-db/db.h" +#include "berkeley-db/btree.h" typedef struct _mp_obj_btree_t { mp_obj_base_t base; diff --git a/ports/esp8266/Makefile b/ports/esp8266/Makefile index 32eb39a203..8af7aba0aa 100644 --- a/ports/esp8266/Makefile +++ b/ports/esp8266/Makefile @@ -38,7 +38,7 @@ MICROPY_ROM_TEXT_COMPRESSION ?= 1 MICROPY_PY_SSL = 1 MICROPY_SSL_AXTLS = 1 AXTLS_DEFS_EXTRA = -Dabort=abort_ -DRT_MAX_PLAIN_LENGTH=1024 -DRT_EXTRA=4096 -BTREE_DEFS_EXTRA = -DDEFPSIZE=1024 -DMINCACHE=3 +BTREE_DEFS_EXTRA = -DMICROPY_BERKELEY_DB_DEFPSIZE=1024 -DMICROPY_BERKELEY_DB_MINCACHE=3 FROZEN_MANIFEST ?= boards/manifest.py