Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow definition of C++ noexcept and override inside Cython #3394

Open
McSinyx opened this issue Mar 4, 2020 · 6 comments
Open

Allow definition of C++ noexcept and override inside Cython #3394

McSinyx opened this issue Mar 4, 2020 · 6 comments

Comments

@McSinyx
Copy link
Contributor

@McSinyx McSinyx commented Mar 4, 2020

In other words, it would be great if something similar to this is possible:

cdef cppclass Foo:
    Foo(...):
        ...
    ~Foo():
        ...
    ... bar(...) noexcept:
        ...

This is to support inheritance of C++ class directly in Cython; might relates with CEP 529.

I guess a better title for this issue would be to extend support for cppclass, but the C++ standard is rather huge and unless we have a more generic approach than the current manual Cython to C++ compilation, I'd love to have the features my project is currently in need.

Edit: as discussed below, destructors in Cython is already supported. Additionally, our project'd need override too. There is no rush on my side though, since we are not aiming to require Cython 3 any time soon.

@da-woods

This comment has been minimized.

Copy link
Contributor

@da-woods da-woods commented Mar 4, 2020

The constructor and destructor syntax is supported but you have to call them __init__ and __dealloc__. I'm not sure about noexcept.

https://github.com/cython/cython/blob/a8cb127df0cb970b00a8f58797740ef571dc8817/tests/run/cpp_classes_def.pyx#L94-104

@McSinyx

This comment has been minimized.

Copy link
Contributor Author

@McSinyx McSinyx commented Mar 4, 2020

The constructor and destructor syntax is supported but you have to call them __init__ and __dealloc__.

Thank you, this should be added to the documentation (probably when this issue is solved altogether). I've been using constructor by name and it appears to be working though, is it an expected behavior?

@da-woods

This comment has been minimized.

Copy link
Contributor

@da-woods da-woods commented Mar 4, 2020

this should be added to the documentation (probably when this issue is solved altogether).

I don't think the ability to define new cppclasses within Cython is documented at all (unless you can tell me otherwise). I think it was put in as a kind of work-in-progress feature and was never that official...

I've been using constructor by name and it appears to be working though, is it an expected behavior?

Don't know - sorry

@McSinyx

This comment has been minimized.

Copy link
Contributor Author

@McSinyx McSinyx commented Mar 4, 2020

I don't think the ability to define new cppclasses within Cython is documented at all (unless you can tell me otherwise). I think it was put in as a kind of work-in-progress feature and was never that official...

I totally forgot about that. @scoder had similar reaction when asked about this too.

Don't know - sorry

You are the second upstream being sorry to me today, please don't be! You guys are putting incredible effort into your projects and we (downstreams) are grateful for that!

@McSinyx McSinyx changed the title Allow definition of C++ destructor and noexcept inside Cython Allow definition of C++ noexcept inside Cython Mar 4, 2020
@da-woods

This comment has been minimized.

Copy link
Contributor

@da-woods da-woods commented Mar 4, 2020

You are the second upstream being sorry to me today, please don't be!

I think you're using the American English definition of "sorry" rather than the British English one. It's more of a polite shrug.


I suspect scoder also suggested using cdef extern from * to include literal C++ code as the better option for defining new C++ classes? I guess you know about that and have good reasons for not doing it, but it's worth a reminder.

@McSinyx

This comment has been minimized.

Copy link
Contributor Author

@McSinyx McSinyx commented Mar 4, 2020

I think you're using the American English definition of "sorry" rather than the British English one. It's more of a polite shrug.

I guess so 😄

I suspect scoder also suggested using cdef extern from * to include literal C++ code as the better option for defining new C++ classes? I guess you know about that and have good reasons for not doing it, but it's worth a reminder.

I really hope I do know what I am doing; basically the C++ definition in Cython is for less-hassle playing with Python objects and calls inside C++ code. However, it did come back and bite with the GIL deadlock. The discussion is in McSinyx/palace#40 if you want to checkout the use case.

@McSinyx McSinyx changed the title Allow definition of C++ noexcept inside Cython Allow definition of C++ noexcept and override inside Cython Mar 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.