Skip to content

gh-121249: unconditionally support complex types in struct #132864

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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

skirpichev
Copy link
Member

@skirpichev skirpichev commented Apr 24, 2025

Each complex type interpreted as an array type containing exactly two elements of the corresponding real type (real and imaginary parts, respectively).


📚 Documentation preview 📚: https://cpython-previews--132864.org.readthedocs.build/

…struct module

Each complex type interpreted as an array type containing exactly two
elements of the corresponding real type (real and imaginary parts,
respectively).
Co-authored-by: Lisandro Dalcin <dalcinl@gmail.com>
@skirpichev skirpichev requested a review from dalcinl April 24, 2025 07:43
@skirpichev

This comment was marked as resolved.

@picnixz picnixz self-requested a review April 25, 2025 01:38
@skirpichev skirpichev added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Apr 25, 2025
@skirpichev

This comment was marked as resolved.

@picnixz

This comment was marked as resolved.

@picnixz picnixz changed the title gh-121249: make complex types available unconditionally in the struct module gh-121249: unconditionally support complex types in struct Apr 25, 2025
Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot but what was the decision about ctypes?

skirpichev and others added 2 commits April 25, 2025 11:05
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@picnixz

This comment was marked as resolved.

@picnixz picnixz removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Apr 25, 2025
@picnixz
Copy link
Member

picnixz commented Apr 25, 2025

Buildbots didn't get launched apparently but that's good as we're modifying the code. Let's wait until everytihng is stable and we'll launch the buildbots again

@skirpichev
Copy link
Member Author

I forgot but what was the decision about ctypes?

@picnixz, are you about this suggestion: #121249 (comment)?

Patch is here: #121249 (comment). I think it's much less urgent, as for the ctypes module - support can't be available unconditionally.

PS: Not sure why bots aren't started. Perhaps, this label should be added by core dev.

@picnixz
Copy link
Member

picnixz commented Apr 25, 2025

I think it's much less urgent, as for the ctypes module - support can't be available unconditionally.

Ok! I actually wondered about the fate of ctypes because I wondered whether we still needed the _complex.h header.

PS: Not sure why bots aren't started. Perhaps, this label should be added by core dev.

I don't remember so? but maybe it is.. anyway, I'll add the label once you've confirmed whether the previous blurb needs an update.

@skirpichev skirpichev requested a review from picnixz April 25, 2025 09:32
{'F', 1, 0, nu_complex_stub, np_complex_stub},
{'D', 1, 0, nu_complex_stub, np_complex_stub},
#endif
{'F', 2*sizeof(float), _Alignof(float[2]), nu_float_complex, np_float_complex},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something we should actually care in the future but _Alignof is deprecated since C23 and it's renamed as alignof. It's unlikely it will be removed but for the future, we should likely use a macro Py_ALIGNOF or something like that. It's a follow-up work though.

@dalcinl
Copy link

dalcinl commented Apr 25, 2025

I forgot but what was the decision about ctypes?

I may be wrong, but I still believe that ctypes support for complex can be implemented by relying exclusively on what the FFI library (and the C compiler used to build that library) supports, and not what the C compiler used to build CPython supports. When all this work settles and everything gets merged, I can try to prove my claim with a patch.

@skirpichev
Copy link
Member Author

When all this work settles and everything gets merged, I can try to prove my claim with a patch.

Feel free to do this even right now. But you should be able to prove that my concern is invalid.

@skirpichev skirpichev added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Apr 25, 2025
@dalcinl
Copy link

dalcinl commented Apr 25, 2025

But you should be able to prove that my concern is invalid.

The thing is, I'm still not sure what's your concern, I don't understand what exactly you meant by "annex G support still required from system". I actually agree with such claim, as long a "system" mean the C compiler used to build FFI, and the C compiler used to build a shared lib that ctypes call into, but NOT the C compiler used to build CPython and ctypes.
For example, I claim that the FFI library and some third-party library that accepts/returns complex numbers can be built with a modern GCC version, thus both sides have annex G support. But then you can build CPython/ctypes with some experimental in-development compiler that does not implement annex G support just yet, and things should still work fine, ctypes is passing complex values back and forth via the FFI library, and not the C compiler used to build CPython/ctypes. If this claim is not correct, then for sure I have a misunderstanding of how the FFI library implementation works, and in such case, I apologize for all the noise.

@skirpichev
Copy link
Member Author

I don't understand what exactly you meant by "annex G support still required from system".

I tried to explain it twice: #121249 (comment) and #121249 (comment). Sorry, it's my best.

ctypes is passing complex values back and forth via the FFI library

The only way to pass it on ctypes side will be a two-element array then. I'm not sure if this will work, as it's not how complexes passed to a function.

Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hugovk Was it correct to amend the Misc/NEWS.d/3.14.0a1.rst for the main branch as the feature that we added there was actually changed? (that way, the online docs will contain only the most recent information and not duplicated entries). The entry will still exist in the tagged release though and will correctly reflect what 3.14.0a1 does.

EDIT: no it doesn't work that way :')

@picnixz picnixz added 🔨 test-with-buildbots Test PR w/ buildbots; report in status section and removed 🔨 test-with-buildbots Test PR w/ buildbots; report in status section labels Apr 25, 2025
@picnixz

This comment was marked as outdated.

@picnixz

This comment was marked as outdated.

@picnixz
Copy link
Member

picnixz commented Apr 25, 2025

@skirpichev I'm so sorry... but I didn't see that the entire changelog contains all previous alphas as well.. so, if we were to remove the NEWS we'll have a missing entry in the changelog page... So just restore the 3.14.0a1.rst file to what it has been but keep the new one for the beta section. You can say that previously it was conditioned though.

@skirpichev
Copy link
Member Author

CC @vstinner

@skirpichev skirpichev added 🔨 test-with-buildbots Test PR w/ buildbots; report in status section and removed 🔨 test-with-buildbots Test PR w/ buildbots; report in status section labels Apr 30, 2025
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @skirpichev for commit 38fa2a7 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F132864%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Apr 30, 2025
@skirpichev
Copy link
Member Author

I see no failures, related to the pr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants