]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
pybind: add legacy_implicit_noexcept for Cython 3.x compatibility wip-pr-67045-kefu-1
authorKefu Chai <k.chai@proxmox.com>
Thu, 22 Jan 2026 12:06:58 +0000 (20:06 +0800)
committerKefu Chai <k.chai@proxmox.com>
Thu, 22 Jan 2026 12:09:35 +0000 (20:09 +0800)
Add legacy_implicit_noexcept compiler directive to all pybind modules
(rados, cephfs, rbd, rgw) when building with Cython 3.x. This maintains
compatibility with Cython 0.29 (Ubuntu Jammy) by allowing callback
functions to work without explicit noexcept declarations.

Cython 3.x requires explicit noexcept declarations for callback functions,
but Cython 0.29 doesn't support the noexcept keyword. The
legacy_implicit_noexcept directive tells Cython 3.x to use the old
behavior, allowing the same code to work with both versions.

This fixes errors like:
  Cannot assign type 'int (*)(uint64_t, uint64_t, void *) except? -1'
  to 'librbd_progress_fn_t'. Exception values are incompatible.

And warnings like:
  performance hint: Exception check on '__aio_complete_cb' will always
  require the GIL to be acquired.

The rbd module already had this directive, but rados, cephfs, and rgw
were missing it.

Signed-off-by: Kefu Chai <k.chai@proxmox.com>
src/pybind/cephfs/setup.py
src/pybind/rados/setup.py
src/pybind/rgw/setup.py

index c94ac2037ed7e615d7cec4127a77f3e32dc3c5dd..bff66659da331af8bd9a6a2489802fcfd1b3bd73 100755 (executable)
@@ -156,12 +156,21 @@ else:
     sys.exit(1)
 
 cmdclass = {}
+compiler_directives = {'language_level': sys.version_info.major}
 try:
     from Cython.Build import cythonize
     from Cython.Distutils import build_ext
     from Cython import Tempita
+    from Cython import __version__ as cython_version
+    from packaging import version
 
     cmdclass = {'build_ext': build_ext}
+
+    # Enable legacy_implicit_noexcept for Cython 3.x to maintain compatibility
+    # with Cython 0.29 (Ubuntu Jammy). This allows callback functions to work
+    # without explicit noexcept declarations.
+    if version.parse(cython_version) >= version.parse('3'):
+        compiler_directives['legacy_implicit_noexcept'] = True
 except ImportError:
     print("WARNING: Cython is not installed.")
 
@@ -226,7 +235,7 @@ setup(
                 **ext_args
             )
         ],
-        compiler_directives={'language_level': sys.version_info.major},
+        compiler_directives=compiler_directives,
         build_dir=os.environ.get("CYTHON_BUILD_DIR", None),
         **cythonize_args
     ),
index 72cfe365dda9c04c83201fdd307d0b963f0f4562..34218fe21256a92b379fdf96c3d7848b30ac53f9 100755 (executable)
@@ -148,12 +148,21 @@ else:
     sys.exit(1)
 
 cmdclass = {}
+compiler_directives = {'language_level': sys.version_info.major}
 try:
     from Cython.Build import cythonize
     from Cython.Distutils import build_ext
     from Cython import Tempita
+    from Cython import __version__ as cython_version
+    from packaging import version
 
     cmdclass = {'build_ext': build_ext}
+
+    # Enable legacy_implicit_noexcept for Cython 3.x to maintain compatibility
+    # with Cython 0.29 (Ubuntu Jammy). This allows callback functions to work
+    # without explicit noexcept declarations.
+    if version.parse(cython_version) >= version.parse('3'):
+        compiler_directives['legacy_implicit_noexcept'] = True
 except ImportError:
     print("WARNING: Cython is not installed.")
 
@@ -217,8 +226,7 @@ setup(
                 **ext_args
             )
         ],
-        # use "3str" when Cython 3.0 is available
-        compiler_directives={'language_level': sys.version_info.major},
+        compiler_directives=compiler_directives,
         compile_time_env=cython_constants,
         build_dir=os.environ.get("CYTHON_BUILD_DIR", None),
     ),
index 8b9b9ac1fef26e953102916e2ee7582904f752b3..54fbd8b0f421eaf0467c0a2ac48b9d94c8213fb7 100755 (executable)
@@ -157,12 +157,21 @@ else:
     sys.exit(1)
 
 cmdclass = {}
+compiler_directives = {'language_level': sys.version_info.major}
 try:
     from Cython.Build import cythonize
     from Cython.Distutils import build_ext
     from Cython import Tempita
+    from Cython import __version__ as cython_version
+    from packaging import version
 
     cmdclass = {'build_ext': build_ext}
+
+    # Enable legacy_implicit_noexcept for Cython 3.x to maintain compatibility
+    # with Cython 0.29 (Ubuntu Jammy). This allows callback functions to work
+    # without explicit noexcept declarations.
+    if version.parse(cython_version) >= version.parse('3'):
+        compiler_directives['legacy_implicit_noexcept'] = True
 except ImportError:
     print("WARNING: Cython is not installed.")
 
@@ -226,7 +235,7 @@ setup(
                 **ext_args
             )
         ],
-        compiler_directives={'language_level': sys.version_info.major},
+        compiler_directives=compiler_directives,
         build_dir=os.environ.get("CYTHON_BUILD_DIR", None),
         **cythonize_args
     ),