4db83e6
commit a49d154f4a8e493baf2296a15c7b5c56cd25e993
4db83e6
Author: Florian Weimer <fweimer@redhat.com>
4db83e6
Date:   Wed Dec 20 14:59:19 2023 +0100
4db83e6
4db83e6
    pybind: Fix C type errors in Cython-generated Python bindings
4db83e6
    
4db83e6
    Several Ceph APIs use bool * types, which correspond to
4db83e6
    libcpp.bool * types in Cython.  The bint type has an incorrect
4db83e6
    size 4 and cannot be used as a replacement.
4db83e6
    
4db83e6
    This prevents a compilation failure with future compilers:
4db83e6
    
4db83e6
    …-build/src/pybind/rbd/rbd.c: In function ‘__pyx_pf_3rbd_3RBD_104namespace_exists’:
4db83e6
    …-build/src/pybind/rbd/rbd.c:42165:76: error: passing argument 3 of ‘rbd_namespace_exists’ from incompatible pointer type
4db83e6
    42165 |         __pyx_v_ret = rbd_namespace_exists(__pyx_v__ioctx, __pyx_v__name, (&__pyx_v__exists));
4db83e6
          |                                                                           ~^~~~~~~~~~~~~~~~~
4db83e6
          |                                                                            |
4db83e6
          |                                                                            int *
4db83e6
    In file included from …-build/src/pybind/rbd/rbd.c:1268:
4db83e6
    …/src/include/rbd/librbd.h:1496:45: note: expected ‘_Bool *’ but argument is of type ‘int *’
4db83e6
     1496 |                                       bool *exists);
4db83e6
          |                                             ^
4db83e6
    
4db83e6
    Signed-off-by: Florian Weimer <fweimer@redhat.com>
4db83e6
4db83e6
diff --git a/src/pybind/rbd/c_rbd.pxd b/src/pybind/rbd/c_rbd.pxd
4db83e6
index 885f7bd46a..bda23bbc47 100644
4db83e6
--- a/src/pybind/rbd/c_rbd.pxd
4db83e6
+++ b/src/pybind/rbd/c_rbd.pxd
4db83e6
@@ -2,6 +2,7 @@
4db83e6
 
4db83e6
 from libc.stdint cimport *
4db83e6
 from ctime cimport time_t, timespec
4db83e6
+cimport libcpp
4db83e6
 
4db83e6
 cdef extern from "rados/librados.h":
4db83e6
     enum:
4db83e6
@@ -525,7 +526,7 @@ cdef extern from "rbd/librbd.h" nogil:
4db83e6
     int rbd_snap_unprotect(rbd_image_t image, const char *snap_name)
4db83e6
     int rbd_snap_is_protected(rbd_image_t image, const char *snap_name,
4db83e6
                               int *is_protected)
4db83e6
-    int rbd_snap_exists(rbd_image_t image, const char *snapname, bint *exists)
4db83e6
+    int rbd_snap_exists(rbd_image_t image, const char *snapname, libcpp.bool *exists)
4db83e6
     int rbd_snap_get_limit(rbd_image_t image, uint64_t *limit)
4db83e6
     int rbd_snap_set_limit(rbd_image_t image, uint64_t limit)
4db83e6
     int rbd_snap_get_timestamp(rbd_image_t image, uint64_t snap_id, timespec *timestamp)
4db83e6
@@ -711,7 +712,7 @@ cdef extern from "rbd/librbd.h" nogil:
4db83e6
     int rbd_namespace_list(rados_ioctx_t io, char *namespace_names,
4db83e6
                            size_t *size)
4db83e6
     int rbd_namespace_exists(rados_ioctx_t io, const char *namespace_name,
4db83e6
-                             bint *exists)
4db83e6
+                             libcpp.bool *exists)
4db83e6
 
4db83e6
     int rbd_pool_init(rados_ioctx_t, bint force)
4db83e6
 
4db83e6
diff --git a/src/pybind/rbd/mock_rbd.pxi b/src/pybind/rbd/mock_rbd.pxi
4db83e6
index 11872bd814..364f965fba 100644
4db83e6
--- a/src/pybind/rbd/mock_rbd.pxi
4db83e6
+++ b/src/pybind/rbd/mock_rbd.pxi
4db83e6
@@ -3,6 +3,11 @@
4db83e6
 from libc.stdint cimport *
4db83e6
 from ctime cimport time_t, timespec
4db83e6
 
4db83e6
+# Make the bool type available as libcpp.bool, for both C and C++.
4db83e6
+cimport libcpp
4db83e6
+cdef extern from "<stdbool.h>":
4db83e6
+    pass
4db83e6
+
4db83e6
 cdef nogil:
4db83e6
     enum:
4db83e6
         _LIBRADOS_SNAP_HEAD "LIBRADOS_SNAP_HEAD"
4db83e6
@@ -637,7 +642,7 @@ cdef nogil:
4db83e6
     int rbd_snap_is_protected(rbd_image_t image, const char *snap_name,
4db83e6
                               int *is_protected):
4db83e6
         pass
4db83e6
-    int rbd_snap_exists(rbd_image_t image, const char *snapname, bint *exists):
4db83e6
+    int rbd_snap_exists(rbd_image_t image, const char *snapname, libcpp.bool *exists):
4db83e6
         pass
4db83e6
     int rbd_snap_get_limit(rbd_image_t image, uint64_t *limit):
4db83e6
         pass
4db83e6
@@ -896,7 +901,7 @@ cdef nogil:
4db83e6
                            size_t *size):
4db83e6
         pass
4db83e6
     int rbd_namespace_exists(rados_ioctx_t io, const char *namespace_name,
4db83e6
-                             bint *exists):
4db83e6
+                             libcpp.bool *exists):
4db83e6
         pass
4db83e6
     int rbd_pool_init(rados_ioctx_t io, bint force):
4db83e6
         pass
4db83e6
diff --git a/src/pybind/rbd/rbd.pyx b/src/pybind/rbd/rbd.pyx
4db83e6
index fcb2fb3470..f59ba23f0f 100644
4db83e6
--- a/src/pybind/rbd/rbd.pyx
4db83e6
+++ b/src/pybind/rbd/rbd.pyx
4db83e6
@@ -23,6 +23,7 @@ from libc cimport errno
4db83e6
 from libc.stdint cimport *
4db83e6
 from libc.stdlib cimport malloc, realloc, free
4db83e6
 from libc.string cimport strdup, memset
4db83e6
+cimport libcpp
4db83e6
 
4db83e6
 try:
4db83e6
     from collections.abc import Iterable
4db83e6
@@ -1935,12 +1936,12 @@ class RBD(object):
4db83e6
         cdef:
4db83e6
             rados_ioctx_t _ioctx = convert_ioctx(ioctx)
4db83e6
             const char *_name = name
4db83e6
-            bint _exists = False
4db83e6
+            libcpp.bool _exists = False
4db83e6
         with nogil:
4db83e6
             ret = rbd_namespace_exists(_ioctx, _name, &_exists)
4db83e6
         if ret != 0:
4db83e6
             raise make_ex(ret, 'error verifying namespace')
4db83e6
-        return bool(_exists != 0)
4db83e6
+        return _exists
4db83e6
 
4db83e6
     def namespace_list(self, ioctx):
4db83e6
         """
4db83e6
@@ -3679,12 +3680,12 @@ cdef class Image(object):
4db83e6
         name = cstr(name, 'name')
4db83e6
         cdef:
4db83e6
             char *_name = name
4db83e6
-            bint _exists = False
4db83e6
+            libcpp.bool _exists = False
4db83e6
         with nogil:
4db83e6
             ret = rbd_snap_exists(self.image, _name, &_exists)
4db83e6
         if ret != 0:
4db83e6
             raise make_ex(ret, 'error getting snapshot exists for %s' % self.name)
4db83e6
-        return bool(_exists != 0)
4db83e6
+        return _exists
4db83e6
 
4db83e6
     @requires_not_closed
4db83e6
     def get_snap_limit(self):
4db83e6
diff --git a/src/pybind/rgw/mock_rgw.pxi b/src/pybind/rgw/mock_rgw.pxi
4db83e6
index ca893a5bb8..806d4df75d 100644
4db83e6
--- a/src/pybind/rgw/mock_rgw.pxi
4db83e6
+++ b/src/pybind/rgw/mock_rgw.pxi
4db83e6
@@ -1,5 +1,10 @@
4db83e6
 # cython: embedsignature=True
4db83e6
 
4db83e6
+# Make the bool type available as libcpp.bool, for both C and C++.
4db83e6
+cimport libcpp
4db83e6
+cdef extern from "<stdbool.h>":
4db83e6
+    pass
4db83e6
+
4db83e6
 cdef nogil:
4db83e6
     ctypedef void* librgw_t
4db83e6
 
4db83e6
@@ -111,8 +116,8 @@ cdef nogil:
4db83e6
 
4db83e6
     int rgw_readdir(rgw_fs *fs,
4db83e6
                     rgw_file_handle *parent_fh, uint64_t *offset,
4db83e6
-                    bint (*cb)(const char *name, void *arg, uint64_t offset, stat *st, uint32_t st_mask, uint32_t flags) nogil except? -9000,
4db83e6
-                    void *cb_arg, bint *eof, uint32_t flags) except? -9000:
4db83e6
+                    libcpp.bool (*cb)(const char *name, void *arg, uint64_t offset, stat *st, uint32_t st_mask, uint32_t flags) nogil except? -9000,
4db83e6
+                    void *cb_arg, libcpp.bool *eof, uint32_t flags) except? -9000:
4db83e6
         pass
4db83e6
 
4db83e6
     int rgw_getattr(rgw_fs *fs,
4db83e6
diff --git a/src/pybind/rgw/rgw.pyx b/src/pybind/rgw/rgw.pyx
4db83e6
index 9bbcdfff58..d210a70bbb 100644
4db83e6
--- a/src/pybind/rgw/rgw.pyx
4db83e6
+++ b/src/pybind/rgw/rgw.pyx
4db83e6
@@ -7,6 +7,7 @@ from cpython cimport PyObject, ref, exc, array
4db83e6
 from libc.stdint cimport *
4db83e6
 from libc.stdlib cimport malloc, realloc, free
4db83e6
 from cstat cimport stat
4db83e6
+cimport libcpp
4db83e6
 
4db83e6
 IF BUILD_DOC:
4db83e6
     include "mock_rgw.pxi"
4db83e6
@@ -373,7 +374,7 @@ cdef class LibRGWFS(object):
4db83e6
         cdef:
4db83e6
             rgw_file_handle *_dir_handler = <rgw_file_handle*>dir_handler.handler
4db83e6
             uint64_t _offset = offset
4db83e6
-            bint _eof
4db83e6
+            libcpp.bool _eof
4db83e6
             uint32_t _flags = flags
4db83e6
         with nogil:
4db83e6
             ret = rgw_readdir(self.fs, _dir_handler, &_offset, &readdir_cb,