]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind: Fix C type errors in Cython-generated Python bindings 54974/head
authorFlorian Weimer <fweimer@redhat.com>
Wed, 20 Dec 2023 13:59:19 +0000 (14:59 +0100)
committerFlorian Weimer <fweimer@redhat.com>
Mon, 8 Jan 2024 11:04:16 +0000 (12:04 +0100)
Several Ceph APIs use bool * types, which correspond to
libcpp.bool * types in Cython.  The bint type has an incorrect
size 4 and cannot be used as a replacement.

This prevents a compilation failure with future compilers:

…-build/src/pybind/rbd/rbd.c: In function ‘__pyx_pf_3rbd_3RBD_104namespace_exists’:
…-build/src/pybind/rbd/rbd.c:42165:76: error: passing argument 3 of ‘rbd_namespace_exists’ from incompatible pointer type
42165 |         __pyx_v_ret = rbd_namespace_exists(__pyx_v__ioctx, __pyx_v__name, (&__pyx_v__exists));
      |                                                                           ~^~~~~~~~~~~~~~~~~
      |                                                                            |
      |                                                                            int *
In file included from …-build/src/pybind/rbd/rbd.c:1268:
…/src/include/rbd/librbd.h:1496:45: note: expected ‘_Bool *’ but argument is of type ‘int *’
 1496 |                                       bool *exists);
      |                                             ^

Signed-off-by: Florian Weimer <fweimer@redhat.com>
src/pybind/rbd/c_rbd.pxd
src/pybind/rbd/mock_rbd.pxi
src/pybind/rbd/rbd.pyx
src/pybind/rgw/mock_rgw.pxi
src/pybind/rgw/rgw.pyx

index 885f7bd46abde8e6d379c256f9c0de910a1a1061..bda23bbc4735f87298c46d02c8efe72c26caef39 100644 (file)
@@ -2,6 +2,7 @@
 
 from libc.stdint cimport *
 from ctime cimport time_t, timespec
+cimport libcpp
 
 cdef extern from "rados/librados.h":
     enum:
@@ -525,7 +526,7 @@ cdef extern from "rbd/librbd.h" nogil:
     int rbd_snap_unprotect(rbd_image_t image, const char *snap_name)
     int rbd_snap_is_protected(rbd_image_t image, const char *snap_name,
                               int *is_protected)
-    int rbd_snap_exists(rbd_image_t image, const char *snapname, bint *exists)
+    int rbd_snap_exists(rbd_image_t image, const char *snapname, libcpp.bool *exists)
     int rbd_snap_get_limit(rbd_image_t image, uint64_t *limit)
     int rbd_snap_set_limit(rbd_image_t image, uint64_t limit)
     int rbd_snap_get_timestamp(rbd_image_t image, uint64_t snap_id, timespec *timestamp)
@@ -711,7 +712,7 @@ cdef extern from "rbd/librbd.h" nogil:
     int rbd_namespace_list(rados_ioctx_t io, char *namespace_names,
                            size_t *size)
     int rbd_namespace_exists(rados_ioctx_t io, const char *namespace_name,
-                             bint *exists)
+                             libcpp.bool *exists)
 
     int rbd_pool_init(rados_ioctx_t, bint force)
 
index 11872bd8146de7fd29765a129a2fca080f121ece..364f965fbad43f2c96c7c3f71276faf80fdad00a 100644 (file)
@@ -3,6 +3,11 @@
 from libc.stdint cimport *
 from ctime cimport time_t, timespec
 
+# Make the bool type available as libcpp.bool, for both C and C++.
+cimport libcpp
+cdef extern from "<stdbool.h>":
+    pass
+
 cdef nogil:
     enum:
         _LIBRADOS_SNAP_HEAD "LIBRADOS_SNAP_HEAD"
@@ -637,7 +642,7 @@ cdef nogil:
     int rbd_snap_is_protected(rbd_image_t image, const char *snap_name,
                               int *is_protected):
         pass
-    int rbd_snap_exists(rbd_image_t image, const char *snapname, bint *exists):
+    int rbd_snap_exists(rbd_image_t image, const char *snapname, libcpp.bool *exists):
         pass
     int rbd_snap_get_limit(rbd_image_t image, uint64_t *limit):
         pass
@@ -896,7 +901,7 @@ cdef nogil:
                            size_t *size):
         pass
     int rbd_namespace_exists(rados_ioctx_t io, const char *namespace_name,
-                             bint *exists):
+                             libcpp.bool *exists):
         pass
     int rbd_pool_init(rados_ioctx_t io, bint force):
         pass
index fcb2fb347060020c15c2fead57437211dc35025b..f59ba23f0fe21063f5a13a6d9abd2c00b1f8fb19 100644 (file)
@@ -23,6 +23,7 @@ from libc cimport errno
 from libc.stdint cimport *
 from libc.stdlib cimport malloc, realloc, free
 from libc.string cimport strdup, memset
+cimport libcpp
 
 try:
     from collections.abc import Iterable
@@ -1935,12 +1936,12 @@ class RBD(object):
         cdef:
             rados_ioctx_t _ioctx = convert_ioctx(ioctx)
             const char *_name = name
-            bint _exists = False
+            libcpp.bool _exists = False
         with nogil:
             ret = rbd_namespace_exists(_ioctx, _name, &_exists)
         if ret != 0:
             raise make_ex(ret, 'error verifying namespace')
-        return bool(_exists != 0)
+        return _exists
 
     def namespace_list(self, ioctx):
         """
@@ -3679,12 +3680,12 @@ cdef class Image(object):
         name = cstr(name, 'name')
         cdef:
             char *_name = name
-            bint _exists = False
+            libcpp.bool _exists = False
         with nogil:
             ret = rbd_snap_exists(self.image, _name, &_exists)
         if ret != 0:
             raise make_ex(ret, 'error getting snapshot exists for %s' % self.name)
-        return bool(_exists != 0)
+        return _exists
 
     @requires_not_closed
     def get_snap_limit(self):
index ca893a5bb8a16f097d319cf5ef24f504806fb0d6..806d4df75de05c42b3eacf0dc304faf3d535235e 100644 (file)
@@ -1,5 +1,10 @@
 # cython: embedsignature=True
 
+# Make the bool type available as libcpp.bool, for both C and C++.
+cimport libcpp
+cdef extern from "<stdbool.h>":
+    pass
+
 cdef nogil:
     ctypedef void* librgw_t
 
@@ -111,8 +116,8 @@ cdef nogil:
 
     int rgw_readdir(rgw_fs *fs,
                     rgw_file_handle *parent_fh, uint64_t *offset,
-                    bint (*cb)(const char *name, void *arg, uint64_t offset, stat *st, uint32_t st_mask, uint32_t flags) nogil except? -9000,
-                    void *cb_arg, bint *eof, uint32_t flags) except? -9000:
+                    libcpp.bool (*cb)(const char *name, void *arg, uint64_t offset, stat *st, uint32_t st_mask, uint32_t flags) nogil except? -9000,
+                    void *cb_arg, libcpp.bool *eof, uint32_t flags) except? -9000:
         pass
 
     int rgw_getattr(rgw_fs *fs,
index 9bbcdfff586a8a842095a80678a4abf08c8409c8..d210a70bbb8e3c9f58b7909b619a4adf243d71c6 100644 (file)
@@ -7,6 +7,7 @@ from cpython cimport PyObject, ref, exc, array
 from libc.stdint cimport *
 from libc.stdlib cimport malloc, realloc, free
 from cstat cimport stat
+cimport libcpp
 
 IF BUILD_DOC:
     include "mock_rgw.pxi"
@@ -373,7 +374,7 @@ cdef class LibRGWFS(object):
         cdef:
             rgw_file_handle *_dir_handler = <rgw_file_handle*>dir_handler.handler
             uint64_t _offset = offset
-            bint _eof
+            libcpp.bool _eof
             uint32_t _flags = flags
         with nogil:
             ret = rgw_readdir(self.fs, _dir_handler, &_offset, &readdir_cb,