New warning with recent cython ...

36 views
Skip to first unread message

Jerome Kieffer

unread,
Apr 16, 2024, 10:42:25 AMApr 16
to cython...@googlegroups.com
Dear all,

I noticed new warnings when compiling a cython project with recent
version of python (3.12) and cython (3+).
https://github.com/silx-kit/pyFAI/issues/2136

The warning is about constructors & destructors of C++ classes which cannot be "noexcept" because they return Python objects...
The code is not from me and I am neither a guru of C++, so maybe one
of you can help me to understand the meaning of this warning ?

Here is a snippet of code with such class: the constructor & destructor
are raising a warning but not the `push` method. As you probably
recognized, this is used as a GIL-free container with resizable storage.

```
cdef cppclass PixelBin:
clist[pixel_t] _pixels
PixelBlock *_pixels_in_block

PixelBin(int block_size, Heap *heap) noexcept nogil:
if block_size > 0:
this._pixels_in_block = new PixelBlock(block_size, heap)
else:
this._pixels_in_block = NULL

__dealloc__() noexcept nogil:
if this._pixels_in_block != NULL:
del this._pixels_in_block
this._pixels_in_block = NULL
else:
this._pixels.clear()

void push(pixel_t &pixel) noexcept nogil:
if this._pixels_in_block != NULL:
this._pixels_in_block.push(pixel)
else:
this._pixels.push_back(pixel)
```

Thanks for your help

--
Jérôme Kieffer

da-woods

unread,
Apr 16, 2024, 12:51:47 PMApr 16
to cython...@googlegroups.com
That warning looks like it's wrong to me (so probably ignore it for now,
although I guess the question remains it generates suitable noexcept code).

There's a PR pending to address some different false positives with
those warnings so it's possible that it may be fixed there.

Antoine Pitrou

unread,
Apr 17, 2024, 11:17:34 AMApr 17
to cython...@googlegroups.com

Slightly unrelated, but my question would be:

why are you implementing a C++ class in Cython? I would strongly
recommend to implement it in regular C++, which allows using the full
breadth of modern C++ and stdlib features (and avoid manual new/delete
calls, for example).

Just let Cython do what it excels in, i.e. bridge "native" C or C++
libraries with high-level Python.

Regards

Antoine.

Jérôme Kieffer

unread,
Apr 18, 2024, 2:06:13 AMApr 18
to cython...@googlegroups.com
Hi Antoine,

Thanks for your suggestion, but I had this part of the code
subcontracted to an engineer who left, thus I don't master it at all,
neither the C++ side nor C++ class defined in cython.

Concerning "modern C++", this code is used by thousands of users
world-wild on python 3.7 -> 3.12, 3 operating systems (linux, mac,
windows) and 3 architectures (intel, ppc and arm). So I am rather
conservative regarding distribution ... reliablility counts much.

I will nevertheless condider your option which looks reasonable.

Cheers,

Jerome
> --
>
> ---
> You received this message because you are subscribed to the Google Groups "cython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to cython-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/cython-users/20240417162721.29853c88%40fsol.
>


--
Reply all
Reply to author
Forward
0 new messages