Skip to content

bpo-45452: Able to use GDBM_NUMSYNC flag if gdbm supports. #28942

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

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 7 additions & 0 deletions Doc/library/dbm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions Doc/whatsnew/3.11.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------

Expand Down
6 changes: 3 additions & 3 deletions Lib/test/test_dbm_gnu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:mod:`_gdbm` is able to use GDBM_NUMSYNC flag if the installed gdbm supports
it. Patch by Dong-hee Na.
8 changes: 8 additions & 0 deletions Modules/_gdbmmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -698,6 +703,9 @@ static const char gdbmmodule_open_flags[] = "rwcn"
#endif
#ifdef GDBM_NOLOCK
"u"
#endif
#ifdef GDBM_NUMSYNC
"x"
#endif
;

Expand Down