]> granicus.if.org Git - python/commitdiff
Fix compiling error when missing gdbm version macros (GH-7823)
authorXiang Zhang <angwerzx@126.com>
Wed, 20 Jun 2018 13:23:30 +0000 (21:23 +0800)
committerGitHub <noreply@github.com>
Wed, 20 Jun 2018 13:23:30 +0000 (21:23 +0800)
Lib/test/pythoninfo.py
Lib/test/test_dbm_gnu.py
Modules/_gdbmmodule.c

index 3958764a6ae94173b8adbc9ee7d763682f994790..f058185c2f8097fc30bac9707527fc071057856f 100644 (file)
@@ -527,11 +527,11 @@ def collect_cc(info_add):
 
 def collect_gdbm(info_add):
     try:
-        import _gdbm
+        from _gdbm import _GDBM_VERSION
     except ImportError:
         return
 
-    info_add('gdbm.GDBM_VERSION', '.'.join(map(str, _gdbm._GDBM_VERSION)))
+    info_add('gdbm.GDBM_VERSION', '.'.join(map(str, _GDBM_VERSION)))
 
 
 def collect_info(info):
index 49f91705b5b8ec4190720538d1aa236d2f81cb23..c96eff5a319e64fbc4af94de6388f78f74ff88c4 100644 (file)
@@ -12,9 +12,8 @@ class TestGdbm(unittest.TestCase):
     def setUpClass():
         if support.verbose:
             try:
-                import _gdbm
-                version = _gdbm._GDBM_VERSION
-            except (ImportError, AttributeError):
+                from _gdbm import _GDBM_VERSION as version
+            except ImportError:
                 pass
             else:
                 print(f"gdbm version: {version}")
index a68cf029429ab5d9c62b4bf26ea00787489a1b40..10560040e446b3b5a39aaef9d7af3b16e2d5d80e 100644 (file)
@@ -678,6 +678,8 @@ PyInit__gdbm(void) {
         goto error;
     }
 
+#if defined(GDBM_VERSION_MAJOR) && defined(GDBM_VERSION_MINOR) && \
+    defined(GDBM_VERSION_PATCH)
     PyObject *obj = Py_BuildValue("iii", GDBM_VERSION_MAJOR,
                                   GDBM_VERSION_MINOR, GDBM_VERSION_PATCH);
     if (obj == NULL) {
@@ -687,6 +689,7 @@ PyInit__gdbm(void) {
         Py_DECREF(obj);
         goto error;
     }
+#endif
 
     return m;