Skip to content

Commit b0890e3

Browse files
committed
Merge PR ceph#62107 into main
* refs/pull/62107/head: pybind/cephfs: use legacy noexcept for cdefs for cython 3.Y.Z pybind/cephfs: increment ref before calling out to c++ Reviewed-by: Kotresh Hiremath Ravishankar <[email protected]> Reviewed-by: Casey Bodley <[email protected]>
2 parents 6126a50 + 90ac740 commit b0890e3

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/pybind/cephfs/c_cephfs.pxd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# cython: language_level=3
2+
# cython: legacy_implicit_noexcept=True
3+
14
from libc.stdint cimport *
25
from types cimport *
36

src/pybind/cephfs/cephfs.pyx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# cython: language_level=3
2+
# cython: legacy_implicit_noexcept=True
3+
14
"""
25
This module is a thin wrapper around libcephfs.
36
"""
@@ -114,10 +117,14 @@ cdef extern from "Python.h":
114117
cdef void completion_callback(int rc, const void* out, size_t outlen, const void* outs, size_t outslen, void* ud) nogil:
115118
# This GIL awkwardness is due to incompatible types with function pointers defined with mds_command2:
116119
with gil:
117-
pyout = (<unsigned char*>out)[:outlen]
118-
pyouts = (<unsigned char*>outs)[:outslen]
119-
(<object>ud).complete(rc, pyout, pyouts)
120-
ref.Py_DECREF(<object>ud)
120+
try:
121+
pyout = (<unsigned char*>out)[:outlen]
122+
pyouts = (<unsigned char*>outs)[:outslen]
123+
(<object>ud).complete(rc, pyout, pyouts)
124+
except:
125+
pass # we can't handle this in any useful way: e.g. which thread should get the exception?
126+
finally:
127+
ref.Py_DECREF(<object>ud)
121128

122129
class Error(Exception):
123130
def get_error_code(self):
@@ -2316,16 +2323,16 @@ cdef class LibCephFS(object):
23162323

23172324

23182325
try:
2326+
ref.Py_INCREF(result)
23192327
with nogil:
23202328
ret = ceph_mds_command2(self.cluster, _mds_spec,
23212329
<const char **>_cmd, _cmdlen,
23222330
<const char*>_inbuf, _inbuf_len,
23232331
_one_shot,
23242332
completion_callback,
23252333
<void*>result)
2326-
if ret == 0:
2327-
ref.Py_INCREF(result)
2328-
else:
2334+
if ret != 0:
2335+
ref.Py_DECREF(result)
23292336
raise make_ex(ret, "error in mds_command2")
23302337
finally:
23312338
free(_cmd)

0 commit comments

Comments
 (0)