Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-45847: Port _gdbm to PY_STDLIB_MOD (GH-29720) #29720

Merged
merged 1 commit into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Modules/Setup.stdlib.in
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
@MODULE__LZMA_TRUE@_lzma _lzmamodule.c
@MODULE_ZLIB_TRUE@zlib zlibmodule.c

# dbm/gdbm
# dbm needs either libndbm, libgdbm_compat, or libdb 5.x
# gdbm module needs -lgdbm
@MODULE__GDBM_TRUE@_gdbm _gdbmmodule.c

# hashing builtins, can be disabled with --without-builtin-hashlib-hashes
@MODULE__MD5_TRUE@_md5 md5module.c
@MODULE__SHA1_TRUE@_sha1 sha1module.c
Expand Down
119 changes: 97 additions & 22 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,8 @@ MODULE__SQLITE3_FALSE
MODULE__SQLITE3_TRUE
MODULE_NIS_FALSE
MODULE_NIS_TRUE
MODULE__GDBM_FALSE
MODULE__GDBM_TRUE
MODULE__DECIMAL_FALSE
MODULE__DECIMAL_TRUE
MODULE__BLAKE2_FALSE
Expand Down Expand Up @@ -799,6 +801,8 @@ DTRACE_OBJS
DTRACE_HEADERS
DFLAGS
DTRACE
GDBM_LIBS
GDBM_CFLAGS
TCLTK_LIBS
TCLTK_INCLUDES
LIBSQLITE3_LIBS
Expand Down Expand Up @@ -1036,6 +1040,8 @@ LIBNSL_CFLAGS
LIBNSL_LIBS
LIBSQLITE3_CFLAGS
LIBSQLITE3_LIBS
GDBM_CFLAGS
GDBM_LIBS
ZLIB_CFLAGS
ZLIB_LIBS
BZIP2_CFLAGS
Expand Down Expand Up @@ -1822,6 +1828,8 @@ Some influential environment variables:
C compiler flags for LIBSQLITE3, overriding pkg-config
LIBSQLITE3_LIBS
linker flags for LIBSQLITE3, overriding pkg-config
GDBM_CFLAGS C compiler flags for gdbm
GDBM_LIBS additional linker flags for gdbm
ZLIB_CFLAGS C compiler flags for ZLIB, overriding pkg-config
ZLIB_LIBS linker flags for ZLIB, overriding pkg-config
BZIP2_CFLAGS
Expand Down Expand Up @@ -11644,17 +11652,25 @@ else
TCLTK_LIBS="$with_tcltk_libs"
fi

# check for _gdbmmodulec dependencies
for ac_header in gdbm.h


save_CFLAGS=$CFLAGS
save_CPPFLAGS=$CPPFLAGS
save_LDFLAGS=$LDFLAGS
save_LIBS=$LIBS


CPPFLAGS="$GDBM_CFLAGS $CFLAGS"
LDFLAGS="$GDBM_LIBS $LDFLAGS"
for ac_header in gdbm.h
do :
ac_fn_c_check_header_mongrel "$LINENO" "gdbm.h" "ac_cv_header_gdbm_h" "$ac_includes_default"
if test "x$ac_cv_header_gdbm_h" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_GDBM_H 1
_ACEOF

LIBS_SAVE=$LIBS
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for gdbm_open in -lgdbm" >&5
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for gdbm_open in -lgdbm" >&5
$as_echo_n "checking for gdbm_open in -lgdbm... " >&6; }
if ${ac_cv_lib_gdbm_gdbm_open+:} false; then :
$as_echo_n "(cached) " >&6
Expand Down Expand Up @@ -11691,21 +11707,29 @@ fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_gdbm_gdbm_open" >&5
$as_echo "$ac_cv_lib_gdbm_gdbm_open" >&6; }
if test "x$ac_cv_lib_gdbm_gdbm_open" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_LIBGDBM 1
_ACEOF

LIBS="-lgdbm $LIBS"
have_gdbm=yes
GDBM_LIBS="$GDBM_LIBS -lgdbm"

else
have_gdbm=no
fi

LIBS=$LIBS_SAVE

else
have_gdbm=no
fi

done


CFLAGS=$save_CFLAGS
CPPFLAGS=$save_CPPFLAGS
LDFLAGS=$save_LDFLAGS
LIBS=$save_LIBS



# check for _dbmmodule.c dependencies
for ac_header in ndbm.h
do :
Expand Down Expand Up @@ -11985,22 +12009,33 @@ $as_echo_n "checking for --with-dbmliborder... " >&6; }
# Check whether --with-dbmliborder was given.
if test "${with_dbmliborder+set}" = set; then :
withval=$with_dbmliborder;
if test x$with_dbmliborder = xyes
then
as_fn_error $? "proper usage is --with-dbmliborder=db1:db2:..." "$LINENO" 5
else
as_save_IFS=$IFS
IFS=:
for db in $with_dbmliborder; do
if test x$db != xndbm && test x$db != xgdbm && test x$db != xbdb
then
as_fn_error $? "proper usage is --with-dbmliborder=db1:db2:..." "$LINENO" 5
fi
done
IFS=$as_save_IFS
fi
with_dbmliborder=ndbm:gdbm:bdb
fi


have_gdbm_dbmliborder=no
as_save_IFS=$IFS
IFS=:
for db in $with_dbmliborder; do
case $db in #(
ndbm) :
;; #(
gdbm) :
have_gdbm_dbmliborder=yes ;; #(
bdb) :
;; #(
*) :
with_dbmliborder=error
;;
esac
done
IFS=$as_save_IFS
if test "x$with_dbmliborder" = xerror; then :

as_fn_error $? "proper usage is --with-dbmliborder=db1:db2:... (ndbm:gdbm:bdb)" "$LINENO" 5

fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_dbmliborder" >&5
$as_echo "$with_dbmliborder" >&6; }

Expand Down Expand Up @@ -21406,6 +21441,42 @@ fi
$as_echo "$py_cv_module__decimal" >&6; }


{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for stdlib extension module _gdbm" >&5
$as_echo_n "checking for stdlib extension module _gdbm... " >&6; }
case $py_stdlib_not_available in #(
*_gdbm*) :
py_cv_module__gdbm=n/a ;; #(
*) :
if test "$have_gdbm_dbmliborder" = yes; then :
if test "$have_gdbm" = yes; then :
py_cv_module__gdbm=yes
else
py_cv_module__gdbm=missing
fi
else
py_cv_module__gdbm=disabled
fi
;;
esac
as_fn_append MODULE_BLOCK "MODULE__GDBM=$py_cv_module__gdbm$as_nl"
if test "x$py_cv_module__gdbm" = xyes; then :

as_fn_append MODULE_BLOCK "MODULE__GDBM_CFLAGS=$GDBM_CFLAGS$as_nl"
as_fn_append MODULE_BLOCK "MODULE__GDBM_LDFLAGS=$GDBM_LIBS$as_nl"

fi
if test "$py_cv_module__gdbm" = yes; then
MODULE__GDBM_TRUE=
MODULE__GDBM_FALSE='#'
else
MODULE__GDBM_TRUE='#'
MODULE__GDBM_FALSE=
fi

{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $py_cv_module__gdbm" >&5
$as_echo "$py_cv_module__gdbm" >&6; }


{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for stdlib extension module nis" >&5
$as_echo_n "checking for stdlib extension module nis... " >&6; }
case $py_stdlib_not_available in #(
Expand Down Expand Up @@ -22254,6 +22325,10 @@ if test -z "${MODULE__DECIMAL_TRUE}" && test -z "${MODULE__DECIMAL_FALSE}"; then
as_fn_error $? "conditional \"MODULE__DECIMAL\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
if test -z "${MODULE__GDBM_TRUE}" && test -z "${MODULE__GDBM_FALSE}"; then
as_fn_error $? "conditional \"MODULE__GDBM\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
if test -z "${MODULE_NIS_TRUE}" && test -z "${MODULE_NIS_FALSE}"; then
as_fn_error $? "conditional \"MODULE_NIS\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
Expand Down
53 changes: 33 additions & 20 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -3294,11 +3294,19 @@ else
TCLTK_LIBS="$with_tcltk_libs"
fi

# check for _gdbmmodulec dependencies
AC_CHECK_HEADERS([gdbm.h], [
LIBS_SAVE=$LIBS
AC_CHECK_LIB([gdbm], [gdbm_open])
LIBS=$LIBS_SAVE
dnl check for _gdbmmodule dependencies
dnl NOTE: gdbm does not provide a pkgconf file.
AC_ARG_VAR([GDBM_CFLAGS], [C compiler flags for gdbm])
AC_ARG_VAR([GDBM_LIBS], [additional linker flags for gdbm])
WITH_SAVE_ENV([
CPPFLAGS="$GDBM_CFLAGS $CFLAGS"
LDFLAGS="$GDBM_LIBS $LDFLAGS"
AC_CHECK_HEADERS([gdbm.h], [
AC_CHECK_LIB([gdbm], [gdbm_open], [
have_gdbm=yes
GDBM_LIBS="$GDBM_LIBS -lgdbm"
], [have_gdbm=no])
], [have_gdbm=no])
])

# check for _dbmmodule.c dependencies
Expand Down Expand Up @@ -3366,21 +3374,23 @@ AC_CHECK_HEADERS([db.h], [
AC_MSG_CHECKING(for --with-dbmliborder)
AC_ARG_WITH(dbmliborder,
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'.]),
[
if test x$with_dbmliborder = xyes
then
AC_MSG_ERROR([proper usage is --with-dbmliborder=db1:db2:...])
else
as_save_IFS=$IFS
IFS=:
for db in $with_dbmliborder; do
if test x$db != xndbm && test x$db != xgdbm && test x$db != xbdb
then
AC_MSG_ERROR([proper usage is --with-dbmliborder=db1:db2:...])
fi
done
IFS=$as_save_IFS
fi])
[], [with_dbmliborder=ndbm:gdbm:bdb])

have_gdbm_dbmliborder=no
as_save_IFS=$IFS
IFS=:
Comment on lines +3380 to +3381
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, why do we save IFS here? AFAICS, there's nothing touching it, but I may be mistaken.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm saving and setting IFS here so the for loop uses : as a field separator.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, just found it in the man page. Learned something new today.

for db in $with_dbmliborder; do
AS_CASE([$db],
[ndbm], [],
[gdbm], [have_gdbm_dbmliborder=yes],
[bdb], [],
[with_dbmliborder=error]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just put AC_MSG_ERROR here, avoiding the AS_VAR_IF below, but I'm fine with this variant as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it. For unknown reasons it does not work. I get a bunch of shell error messages when the error case is triggered.

)
done
IFS=$as_save_IFS
AS_VAR_IF([with_dbmliborder], [error], [
AC_MSG_ERROR([proper usage is --with-dbmliborder=db1:db2:... (ndbm:gdbm:bdb)])
])
AC_MSG_RESULT($with_dbmliborder)

# Templates for things AC_DEFINEd more than once.
Expand Down Expand Up @@ -6193,6 +6203,9 @@ PY_STDLIB_MOD([_sha3], [test "$with_builtin_sha3" = yes])
PY_STDLIB_MOD([_blake2], [test "$with_builtin_blake2" = yes])

PY_STDLIB_MOD([_decimal], [], [], [$LIBMPDEC_CFLAGS], [$LIBMPDEC_LDFLAGS])
PY_STDLIB_MOD([_gdbm],
[test "$have_gdbm_dbmliborder" = yes], [test "$have_gdbm" = yes],
[$GDBM_CFLAGS], [$GDBM_LIBS])
PY_STDLIB_MOD([nis],
[], [test "$have_nis" = yes -a "$ac_cv_header_rpc_rpc_h" = yes],
[$LIBNSL_CFLAGS], [$LIBNSL_LIBS])
Expand Down
3 changes: 0 additions & 3 deletions pyconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -604,9 +604,6 @@
/* Define to 1 if you have the `dld' library (-ldld). */
#undef HAVE_LIBDLD

/* Define to 1 if you have the `gdbm' library (-lgdbm). */
#undef HAVE_LIBGDBM

/* Define to 1 if you have the `gdbm_compat' library (-lgdbm_compat). */
#undef HAVE_LIBGDBM_COMPAT

Expand Down
8 changes: 1 addition & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1269,11 +1269,9 @@ def detect_dbm_gdbm(self):

# libdb, gdbm and ndbm headers and libraries
have_ndbm_h = sysconfig.get_config_var("HAVE_NDBM_H")
have_gdbm_h = sysconfig.get_config_var("HAVE_GDBM_H")
have_gdbm_ndbm_h = sysconfig.get_config_var("HAVE_GDBM_NDBM_H")
have_gdbm_dash_ndbm_h = sysconfig.get_config_var("HAVE_GDBM_DASH_NDBM_H")
have_libndbm = sysconfig.get_config_var("HAVE_LIBNDBM")
have_libgdbm = sysconfig.get_config_var("HAVE_LIBGDBM")
have_libgdbm_compat = sysconfig.get_config_var("HAVE_LIBGDBM_COMPAT")
have_libdb = sysconfig.get_config_var("HAVE_LIBDB")

Expand Down Expand Up @@ -1331,11 +1329,7 @@ def detect_dbm_gdbm(self):
self.missing.append('_dbm')

# Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
if 'gdbm' in dbm_order and have_libgdbm:
self.add(Extension('_gdbm', ['_gdbmmodule.c'],
libraries=['gdbm']))
else:
self.missing.append('_gdbm')
self.addext(Extension('_gdbm', ['_gdbmmodule.c']))

def detect_sqlite(self):
sources = [
Expand Down