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

Support object members #347

Merged
merged 11 commits into from
Sep 21, 2022
Merged

Support object members #347

merged 11 commits into from
Sep 21, 2022

Conversation

timfel
Copy link
Contributor

@timfel timfel commented Sep 19, 2022

We already define HPyMember_OBJECT, but using it in

HPyDef_MEMBER(Foo_OBJECT_member, "OBJECT_member", HPyMember_OBJECT, offsetof(FooObject, OBJECT_member))

fails in universal mode, as the included test demonstrates, since the embedded member must an HPyField in this mode. This should work, since it's annoying to have to define getters/setters manually here.

@hodgestar
Copy link
Contributor

What happens during porting a C extension? Presumably initially the member is a PyObject *. Will compilation in universal mode then fail? And once the member is been made an HPyField, will compilation work in both CPython and universal mode?

I am wondering whether we need a legacy_defines or similar? Or at least some way to make it clear "these object members should use HPyField and those should use PyObject*".

@timfel
Copy link
Contributor Author

timfel commented Sep 20, 2022

What happens during porting a C extension? Presumably initially the member is a PyObject *. Will compilation in universal mode then fail? And once the member is been made an HPyField, will compilation work in both CPython and universal mode?

As long as it is a PyObject*, compilation in universal mode just fails. After it is an HPyField, it works in both CPython C ABI mode and HPy universal mode. It even works to have an HPyField and still use the legacy definition for members, since then you have to compile in C ABI mode and the HPyField is binary equivalent to PyObject* in that mode. So afaics, nothing can go wrong even if you just partially port.

@ambv ambv merged commit 3e809a7 into master Sep 21, 2022
@ambv ambv deleted the tim/object_members branch September 21, 2022 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants