[pybsddb] berkelydb 18.1.6 compiler error with Clang

Jesus Cea jcea at jcea.es
Mon Aug 14 03:58:39 CEST 2023


On 10/8/23 4:39, Himanshu Gohel wrote:
> Hello Jesus,
> 
> First a big thank you for maintaining bsddb3/berkeleydb since 2008!

Thanks!. Much appreciated.

> Gramps <https://gramps-project.org/blog/>[1] software is a consumer of 
> bsddb3 6.2.9 package via MSYS2 <https://www.msys2.org/> [2]. The Windows 
> build of Gramps is stuck because the package isn't available on MSYS2 at 
> the moment. The maintainers at MSYS2 have removed it from the package 
> repo because it fails to compile with Clang. The issue is documented in 
> PR #17871 <https://github.com/msys2/MINGW-packages/pull/17871> [3] 
> specifically this error 
> <https://github.com/msys2/MINGW-packages/pull/17871#issuecomment-1653908229> [4].

I find the discussion confusing and somewhat misleading. I would guess 
the issue is that a pointer to a function is required and we are 
providing a "function", not a pointer to it.

The testsuite contains tests for both "set_bt_compare()" and 
"set_dup_compare", so the functions seems to compile and work fine under 
GCC.

I don't use CLANG, so I can't test the patch myself, but I wonder if you 
could try this:

"""
jcea at jcea:/tmp/pybsddb$ hg diff
diff --git a/src/Module/berkeleydb.c b/src/Module/berkeleydb.c
--- a/src/Module/berkeleydb.c
+++ b/src/Module/berkeleydb.c
@@ -2847,7 +2847,7 @@
      Py_INCREF(comparator);
      self->btCompareCallback = comparator;

-    err = self->db->set_bt_compare(self->db, _db_compareCallback);
+    err = self->db->set_bt_compare(self->db, &_db_compareCallback);

      if (err) {
          /* restore the old state in case of error */
@@ -2964,7 +2964,7 @@
      Py_INCREF(comparator);
      self->dupCompareCallback = comparator;

-    err = self->db->set_dup_compare(self->db, _db_dupCompareCallback);
+    err = self->db->set_dup_compare(self->db, &_db_dupCompareCallback);

      if (err) {
          /* restore the old state in case of error */
"""

If this solves the problem, I could do a new release with this patch.

Thanks for raising the issue.

Could you also try to compile this code?:

"""
#include <stdio.h>

int a(int x) {
     return 2*x;
}

int main(void) {
     int (*f) (int);

     f = a;
     printf("a) 10 * 2 = %d\n", (*f)(10));

     f = &a;
     printf("b) 7 * 2 = %d\n", (*f)(7));
     return 0;
}
"""

Under GCC, it compiles fine with no warnings and produces the expected 
output:

"""
jcea at jcea:/tmp/ram$ gcc -O3 -Wall a.c
jcea at jcea:/tmp/ram$ ./a.out
a) 10 * 2 = 20
b) 7 * 2 = 14
"""

I guess that under CLANG it would fail to compile with an error related 
to incompatible pointer assignment.

-- 
Jesús Cea Avión                         _/_/      _/_/_/        _/_/_/
jcea at jcea.es - https://www.jcea.es/    _/_/    _/_/  _/_/    _/_/  _/_/
Twitter: @jcea                        _/_/    _/_/          _/_/_/_/_/
jabber / xmpp:jcea at jabber.org  _/_/  _/_/    _/_/          _/_/  _/_/
"Things are not so easy"      _/_/  _/_/    _/_/  _/_/    _/_/  _/_/
"My name is Dump, Core Dump"   _/_/_/        _/_/_/      _/_/  _/_/
"El amor es poner tu felicidad en la felicidad de otro" - Leibniz


More information about the pybsddb mailing list