From effeb40a4ccd770dc6e7aae2e80f52eb7880449a Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Thu, 14 Oct 2021 05:30:16 +0000 Subject: [PATCH] bpo-45452: Able to use GDBM_NUMSYNC flag if gdbm supports. --- Doc/library/dbm.rst | 7 +++++++ Doc/whatsnew/3.11.rst | 7 +++++++ Lib/test/test_dbm_gnu.py | 6 +++--- .../next/Library/2021-10-14-05-33-44.bpo-45452.xJrxAT.rst | 2 ++ Modules/_gdbmmodule.c | 8 ++++++++ 5 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2021-10-14-05-33-44.bpo-45452.xJrxAT.rst diff --git a/Doc/library/dbm.rst b/Doc/library/dbm.rst index 2be499337a2a15..bae8f508787e22 100644 --- a/Doc/library/dbm.rst +++ b/Doc/library/dbm.rst @@ -196,6 +196,9 @@ supported. +---------+--------------------------------------------+ | ``'u'`` | Do not lock database. | +---------+--------------------------------------------+ + | ``'x'`` | Create the database with the extended | + | | numsync format. | + +---------+--------------------------------------------+ Not all flags are valid for all versions of ``gdbm``. The module constant :const:`open_flags` is a string of supported flag characters. The exception @@ -210,6 +213,10 @@ supported. .. versionchanged:: 3.11 Accepts :term:`path-like object` for filename. + .. versionadded:: 3.11 + Creating the database with the extended numsync format is available + if installed gdbm supports. + .. method:: gdbm.firstkey() It's possible to loop over every key in the database using this method and the diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 48d454d9aac99f..bd2b9579f887ba 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -190,6 +190,13 @@ New Modules Improved Modules ================ +dbm +--- + +* :mod:`_gdbm` now able to create a database with the extended numsync format + if installed gdbm supports. (Contributed by Dong-hee Na in :issue:`45452`.) + + fractions --------- diff --git a/Lib/test/test_dbm_gnu.py b/Lib/test/test_dbm_gnu.py index 4eaa0f474b0209..8089291e66d4ba 100644 --- a/Lib/test/test_dbm_gnu.py +++ b/Lib/test/test_dbm_gnu.py @@ -67,18 +67,18 @@ def test_error_conditions(self): self.g.close() self.assertRaises(gdbm.error, lambda: self.g['a']) # try pass an invalid open flag - self.assertRaises(gdbm.error, lambda: gdbm.open(filename, 'rx').close()) + self.assertRaises(gdbm.error, lambda: gdbm.open(filename, 'rz').close()) def test_flags(self): # Test the flag parameter open() by trying all supported flag modes. all = set(gdbm.open_flags) # Test standard flags (presumably "crwn"). - modes = all - set('fsu') + modes = all - set('fsux') for mode in sorted(modes): # put "c" mode first self.g = gdbm.open(filename, mode) self.g.close() - # Test additional flags (presumably "fsu"). + # Test additional flags (presumably "fsux"). flags = all - set('crwn') for mode in modes: for flag in flags: diff --git a/Misc/NEWS.d/next/Library/2021-10-14-05-33-44.bpo-45452.xJrxAT.rst b/Misc/NEWS.d/next/Library/2021-10-14-05-33-44.bpo-45452.xJrxAT.rst new file mode 100644 index 00000000000000..3c64c3661ebb04 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-10-14-05-33-44.bpo-45452.xJrxAT.rst @@ -0,0 +1,2 @@ +:mod:`_gdbm` is able to use GDBM_NUMSYNC flag if the installed gdbm supports +it. Patch by Dong-hee Na. diff --git a/Modules/_gdbmmodule.c b/Modules/_gdbmmodule.c index 445500c7ee4c15..fdd2533ea3086b 100644 --- a/Modules/_gdbmmodule.c +++ b/Modules/_gdbmmodule.c @@ -664,6 +664,11 @@ dbmopen_impl(PyObject *module, PyObject *filename, const char *flags, case 'u': iflags |= GDBM_NOLOCK; break; +#endif +#ifdef GDBM_NUMSYNC + case 'x': + iflags |= GDBM_NUMSYNC; + break; #endif default: PyOS_snprintf(buf, sizeof(buf), "Flag '%c' is not supported.", @@ -698,6 +703,9 @@ static const char gdbmmodule_open_flags[] = "rwcn" #endif #ifdef GDBM_NOLOCK "u" +#endif +#ifdef GDBM_NUMSYNC + "x" #endif ;