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

Do no-type-slots dictoffset check as python lookup #5698

Merged
merged 7 commits into from
Nov 1, 2023

Conversation

da-woods
Copy link
Contributor

Rather than just declaring it impossible.

Fixes #5696

(Note that this isn't sufficient to declare multiply-inherited cdef classes in the limited api - the calling code generates a few PyTuple_GET_ITEMs. However, I have tested the dictoffset code itself)

Rather than just declaring it impossible.

Fixes cython#5696
if (b_dictoffset == -1 && PyErr_Occurred()) goto dictoffset_return;
#endif
if (b_dictoffset) {
__Pyx_TypeName b_name = __Pyx_PyType_GetName(b);
Copy link
Contributor

Choose a reason for hiding this comment

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

The declaration of b_name is between the goto and the label, which will fail in C++

Copy link
Contributor

@mattip mattip Sep 12, 2023

Choose a reason for hiding this comment

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

Adding another set of braces to enclose the scope of b_name fixes the c++ compilation error, but then running the test on PyPy I get

CFLAGS="-DCYTHON_USE_TYPE_SPECS=1" ../pypy/pypy3.9-c runtests.py cdef_multiple_inheritance_nodict --no-c --no-cleanup
...
File "tests/run/cdef_multiple_inheritance_nodict.pyx", line 16, in init cdef_multiple_inheritance_nodict (cdef_multiple_inheritance_nodict.cpp:7472)
    cdef class Both(CBase, PyBase):
AttributeError: type object 'PyBase' has no attribute '__dictoffset__'

which seems to be an incompatibility in PyPy: classes never have __dictoffset__. It turns out there is an open issue about the lack of proper handling of _PyObject_GetDictPtr and tp_dictoffset for pybind11, that was never resolved. So while this PR fixes a corner case for CPython, it doesn't fix the PyPy test failure.

Sorry for the bother. I am not sure how to fix this.

Copy link
Contributor

Choose a reason for hiding this comment

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

well, I guess I could get USE_CYTHON_TYPE_SLOTS to work on PyPy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made the test

#if CYTHON_USE_TYPE_SLOTS || CYTHON_COMPILING_IN_PYPY

Not completely sure if this'll work or not though, but it seems easier than trying to get the whole of CYTHON_USE_TYPE_SLOTS to work with PyPy.

Sorry for the bother. I am not sure how to fix this.

It's still worth fixing the limited api side of it anyway, even if it doesn't fix PyPy.

Cython/Utility/ExtensionTypes.c Outdated Show resolved Hide resolved
Cython/Utility/ExtensionTypes.c Outdated Show resolved Hide resolved
Co-authored-by: Matti Picus <matti.picus@gmail.com>
Copy link
Contributor

@scoder scoder left a comment

Choose a reason for hiding this comment

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

Good improvement, just one thing to fix.

Cython/Utility/ExtensionTypes.c Outdated Show resolved Hide resolved
Co-authored-by: scoder <stefan_ml@behnel.de>
@da-woods
Copy link
Contributor Author

da-woods commented Nov 1, 2023

Seems to have broken something in PyPy.

I'm away from my PC for the rest of the week so I'll investigate properly when I get back.

@scoder
Copy link
Contributor

scoder commented Nov 1, 2023

Seems to have broken something in PyPy.

No, it's fine, that was a hickup in master on my part.

@scoder scoder merged commit e6094e2 into cython:master Nov 1, 2023
83 checks passed
@scoder scoder added this to the 3.0.6 milestone Nov 1, 2023
@da-woods da-woods deleted the fix-limited-api-dictoffset-check branch November 1, 2023 16:16
rinarakaki pushed a commit to rinarakaki/cython that referenced this pull request Nov 3, 2023
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.

Failing cdef_multiple_inheritance_nodict test when CYTHON_USE_TYPE_SPECS=1 and CYTHON_USE_TYPE_SLOTS=0
3 participants