Skip to content

Commit cd8eea2

Browse files
committed
all: Update extmod, ports, examples to build with new berkeley-db lib.
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 micropython#13092. Signed-off-by: Damien George <[email protected]>
1 parent 305707b commit cd8eea2

File tree

7 files changed

+40
-19
lines changed

7 files changed

+40
-19
lines changed

examples/natmod/btree/Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ SRC = btree_c.c btree_py.py
1111
ARCH = x64
1212

1313
BTREE_DIR = $(MPY_DIR)/lib/berkeley-db-1.xx
14-
BTREE_DEFS = -D__DBINTERFACE_PRIVATE=1 -Dmpool_error="(void)" -Dabort=abort_ "-Dvirt_fd_t=void*" $(BTREE_DEFS_EXTRA)
15-
CFLAGS += -I$(BTREE_DIR)/PORT/include
16-
CFLAGS += -Wno-old-style-definition -Wno-sign-compare -Wno-unused-parameter $(BTREE_DEFS)
14+
BERKELEY_DB_CONFIG_FILE ?= \"extmod/berkeley-db/berkeley_db_config_port.h\"
15+
CFLAGS += -I$(BTREE_DIR)/include
16+
CFLAGS += -DBERKELEY_DB_CONFIG_FILE=$(BERKELEY_DB_CONFIG_FILE)
17+
CFLAGS += -Wno-old-style-definition -Wno-sign-compare -Wno-unused-parameter
1718

1819
SRC += $(addprefix $(realpath $(BTREE_DIR))/,\
1920
btree/bt_close.c \

examples/natmod/btree/btree_c.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ void abort_(void) {
3939
nlr_raise(mp_obj_new_exception(mp_load_global(MP_QSTR_RuntimeError)));
4040
}
4141

42+
int puts(const char *s) {
43+
return mp_printf(&mp_plat_print, "%s\n", s);
44+
}
45+
4246
int native_errno;
4347
#if defined(__linux__)
4448
int *__errno_location (void)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Berkeley-db configuration.
2+
3+
#define __DBINTERFACE_PRIVATE 1
4+
#define mpool_error printf
5+
#define abort abort_
6+
#define virt_fd_t void*
7+
8+
#ifdef MICROPY_BERKELEY_DB_DEFPSIZE
9+
#define DEFPSIZE MICROPY_BERKELEY_DB_DEFPSIZE
10+
#endif
11+
12+
#ifdef MICROPY_BERKELEY_DB_MINCACHE
13+
#define MINCACHE MICROPY_BERKELEY_DB_MINCACHE
14+
#endif
15+
16+
__attribute__((noreturn)) void abort_(void);

extmod/extmod.cmake

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,27 +132,27 @@ if(MICROPY_PY_BTREE)
132132
)
133133

134134
target_include_directories(micropy_extmod_btree PRIVATE
135-
${MICROPY_LIB_BERKELEY_DIR}/PORT/include
135+
${MICROPY_LIB_BERKELEY_DIR}/include
136136
)
137137

138+
if(NOT BERKELEY_DB_CONFIG_FILE)
139+
set(BERKELEY_DB_CONFIG_FILE "${MICROPY_DIR}/extmod/berkeley-db/berkeley_db_config_port.h")
140+
endif()
141+
138142
target_compile_definitions(micropy_extmod_btree PRIVATE
139-
__DBINTERFACE_PRIVATE=1
140-
mpool_error=printf
141-
abort=abort_
142-
"virt_fd_t=void*"
143+
BERKELEY_DB_CONFIG_FILE="${BERKELEY_DB_CONFIG_FILE}"
143144
)
144145

145146
# The include directories and compile definitions below are needed to build
146147
# modbtree.c and should be added to the main MicroPython target.
147148

148149
list(APPEND MICROPY_INC_CORE
149-
"${MICROPY_LIB_BERKELEY_DIR}/PORT/include"
150+
"${MICROPY_LIB_BERKELEY_DIR}/include"
150151
)
151152

152153
list(APPEND MICROPY_DEF_CORE
153154
MICROPY_PY_BTREE=1
154-
__DBINTERFACE_PRIVATE=1
155-
"virt_fd_t=void*"
155+
BERKELEY_DB_CONFIG_FILE="${BERKELEY_DB_CONFIG_FILE}"
156156
)
157157

158158
list(APPEND MICROPY_SOURCE_EXTMOD

extmod/extmod.mk

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,10 @@ endif
381381

382382
ifeq ($(MICROPY_PY_BTREE),1)
383383
BTREE_DIR = lib/berkeley-db-1.xx
384-
BTREE_DEFS = -D__DBINTERFACE_PRIVATE=1 -Dmpool_error=printf -Dabort=abort_ "-Dvirt_fd_t=void*" $(BTREE_DEFS_EXTRA)
385-
INC += -I$(TOP)/$(BTREE_DIR)/PORT/include
384+
BERKELEY_DB_CONFIG_FILE ?= \"extmod/berkeley-db/berkeley_db_config_port.h\"
385+
CFLAGS_EXTMOD += -DBERKELEY_DB_CONFIG_FILE=$(BERKELEY_DB_CONFIG_FILE)
386+
CFLAGS_EXTMOD += $(BTREE_DEFS_EXTRA)
387+
INC += -I$(TOP)/$(BTREE_DIR)/include
386388
SRC_THIRDPARTY_C += $(addprefix $(BTREE_DIR)/,\
387389
btree/bt_close.c \
388390
btree/bt_conv.c \
@@ -401,9 +403,7 @@ SRC_THIRDPARTY_C += $(addprefix $(BTREE_DIR)/,\
401403
)
402404
CFLAGS_EXTMOD += -DMICROPY_PY_BTREE=1
403405
# we need to suppress certain warnings to get berkeley-db to compile cleanly
404-
# and we have separate BTREE_DEFS so the definitions don't interfere with other source code
405-
$(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)
406-
$(BUILD)/extmod/modbtree.o: CFLAGS += $(BTREE_DEFS)
406+
$(BUILD)/$(BTREE_DIR)/%.o: CFLAGS += -Wno-old-style-definition -Wno-sign-compare -Wno-unused-parameter -Wno-deprecated-non-prototype -Wno-unknown-warning-option
407407
endif
408408

409409
################################################################################

extmod/modbtree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@
5757
#undef CIRCLEQ_INSERT_TAIL
5858
#undef CIRCLEQ_REMOVE
5959

60-
#include <db.h>
61-
#include <../../btree/btree.h>
60+
#include "berkeley-db/db.h"
61+
#include "berkeley-db/btree.h"
6262

6363
typedef struct _mp_obj_btree_t {
6464
mp_obj_base_t base;

ports/esp8266/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ MICROPY_ROM_TEXT_COMPRESSION ?= 1
3838
MICROPY_PY_SSL = 1
3939
MICROPY_SSL_AXTLS = 1
4040
AXTLS_DEFS_EXTRA = -Dabort=abort_ -DRT_MAX_PLAIN_LENGTH=1024 -DRT_EXTRA=4096
41-
BTREE_DEFS_EXTRA = -DDEFPSIZE=1024 -DMINCACHE=3
41+
BTREE_DEFS_EXTRA = -DMICROPY_BERKELEY_DB_DEFPSIZE=1024 -DMICROPY_BERKELEY_DB_MINCACHE=3
4242

4343
FROZEN_MANIFEST ?= boards/manifest.py
4444

0 commit comments

Comments
 (0)