Skip to content

Commit 6c25bf0

Browse files
authored
pythongh-89452: Prefer gdbm-compat over ndbm (python#92208)
This makes macOS gdbm provided by Homebrew not segfault through correct selection of the linked library (-lgdbm_compat) *AND* the correct ndbm-style header (gdbm-ndbm.h instead of the invalid ndbm.h).
1 parent feca9bb commit 6c25bf0

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
gdbm-compat is now preferred over ndbm if both are available on the system.
2+
This allows avoiding the problematic ndbm.h on macOS.

Modules/_dbmmodule.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212
/* Some Linux systems install gdbm/ndbm.h, but not ndbm.h. This supports
1313
* whichever configure was able to locate.
1414
*/
15-
#if defined(USE_NDBM)
16-
#include <ndbm.h>
17-
static const char which_dbm[] = "GNU gdbm"; /* EMX port of GDBM */
18-
#elif defined(USE_GDBM_COMPAT)
15+
#if defined(USE_GDBM_COMPAT)
1916
#ifdef HAVE_GDBM_NDBM_H
2017
#include <gdbm/ndbm.h>
2118
#elif HAVE_GDBM_DASH_NDBM_H
@@ -24,6 +21,9 @@
2421
#error "No gdbm/ndbm.h or gdbm-ndbm.h available"
2522
#endif
2623
static const char which_dbm[] = "GNU gdbm";
24+
#elif defined(USE_NDBM)
25+
#include <ndbm.h>
26+
static const char which_dbm[] = "GNU gdbm";
2727
#elif defined(USE_BERKDB)
2828
#ifndef DB_DBM_HSEARCH
2929
#define DB_DBM_HSEARCH 1

configure

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

+2-2
Original file line numberDiff line numberDiff line change
@@ -3850,7 +3850,7 @@ AC_CHECK_HEADERS([db.h], [
38503850
AC_MSG_CHECKING(for --with-dbmliborder)
38513851
AC_ARG_WITH(dbmliborder,
38523852
AS_HELP_STRING([--with-dbmliborder=db1:db2:...], [override order to check db backends for dbm; a valid value is a colon separated string with the backend names `ndbm', `gdbm' and `bdb'.]),
3853-
[], [with_dbmliborder=ndbm:gdbm:bdb])
3853+
[], [with_dbmliborder=gdbm:ndbm:bdb])
38543854

38553855
have_gdbm_dbmliborder=no
38563856
as_save_IFS=$IFS
@@ -3865,7 +3865,7 @@ for db in $with_dbmliborder; do
38653865
done
38663866
IFS=$as_save_IFS
38673867
AS_VAR_IF([with_dbmliborder], [error], [
3868-
AC_MSG_ERROR([proper usage is --with-dbmliborder=db1:db2:... (ndbm:gdbm:bdb)])
3868+
AC_MSG_ERROR([proper usage is --with-dbmliborder=db1:db2:... (gdbm:ndbm:bdb)])
38693869
])
38703870
AC_MSG_RESULT($with_dbmliborder)
38713871

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,7 @@ def detect_dbm_gdbm(self):
12071207
if dbm_args:
12081208
dbm_order = [arg.split('=')[-1] for arg in dbm_args][-1].split(":")
12091209
else:
1210-
dbm_order = "ndbm:gdbm:bdb".split(":")
1210+
dbm_order = "gdbm:ndbm:bdb".split(":")
12111211
dbmext = None
12121212
for cand in dbm_order:
12131213
if cand == "ndbm":

0 commit comments

Comments
 (0)