Skip to content

Commit

Permalink
all: Update extmod, ports, examples to build with new berkeley-db lib.
Browse files Browse the repository at this point in the history
This provides a MicroPython-specific berkeley-db configuration in
extmod/berkeley-db/berkeley_db_config_port.h, and cleans up the include
path for this library.

Fixes issue #13092.

Signed-off-by: Damien George <damien@micropython.org>
  • Loading branch information
dpgeorge committed Mar 16, 2024
1 parent 305707b commit cd8eea2
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 19 deletions.
7 changes: 4 additions & 3 deletions examples/natmod/btree/Makefile
Expand Up @@ -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 \
Expand Down
4 changes: 4 additions & 0 deletions examples/natmod/btree/btree_c.c
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions 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);
16 changes: 8 additions & 8 deletions extmod/extmod.cmake
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions extmod/extmod.mk
Expand Up @@ -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 \
Expand All @@ -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

################################################################################
Expand Down
4 changes: 2 additions & 2 deletions extmod/modbtree.c
Expand Up @@ -57,8 +57,8 @@
#undef CIRCLEQ_INSERT_TAIL
#undef CIRCLEQ_REMOVE

#include <db.h>
#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;
Expand Down
2 changes: 1 addition & 1 deletion ports/esp8266/Makefile
Expand Up @@ -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

Expand Down

0 comments on commit cd8eea2

Please sign in to comment.