Skip to content

Commit b248e95

Browse files
authored
Fix compiling error when missing gdbm version macros (GH-7823)
1 parent 16eb3bc commit b248e95

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

Lib/test/pythoninfo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,11 +527,11 @@ def collect_cc(info_add):
527527

528528
def collect_gdbm(info_add):
529529
try:
530-
import _gdbm
530+
from _gdbm import _GDBM_VERSION
531531
except ImportError:
532532
return
533533

534-
info_add('gdbm.GDBM_VERSION', '.'.join(map(str, _gdbm._GDBM_VERSION)))
534+
info_add('gdbm.GDBM_VERSION', '.'.join(map(str, _GDBM_VERSION)))
535535

536536

537537
def collect_info(info):

Lib/test/test_dbm_gnu.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ class TestGdbm(unittest.TestCase):
1212
def setUpClass():
1313
if support.verbose:
1414
try:
15-
import _gdbm
16-
version = _gdbm._GDBM_VERSION
17-
except (ImportError, AttributeError):
15+
from _gdbm import _GDBM_VERSION as version
16+
except ImportError:
1817
pass
1918
else:
2019
print(f"gdbm version: {version}")

Modules/_gdbmmodule.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,8 @@ PyInit__gdbm(void) {
678678
goto error;
679679
}
680680

681+
#if defined(GDBM_VERSION_MAJOR) && defined(GDBM_VERSION_MINOR) && \
682+
defined(GDBM_VERSION_PATCH)
681683
PyObject *obj = Py_BuildValue("iii", GDBM_VERSION_MAJOR,
682684
GDBM_VERSION_MINOR, GDBM_VERSION_PATCH);
683685
if (obj == NULL) {
@@ -687,6 +689,7 @@ PyInit__gdbm(void) {
687689
Py_DECREF(obj);
688690
goto error;
689691
}
692+
#endif
690693

691694
return m;
692695

0 commit comments

Comments
 (0)