Skip to content

Make GraalPy use cyfunction Limited API structure - #7971

Merged
da-woods merged 5 commits into
cython:masterfrom
da-woods:graalpy-limited-api
Sep 7, 2026
Merged

da-woods merged 5 commits into
cython:masterfrom
da-woods:graalpy-limited-api

Conversation

@da-woods

@da-woods da-woods commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator

This avoids them having to write accessor functions to reach inside PyCFunctionObject.

Use macros to avoid repeating the MethodDef and Module access.

This avoids them having to write accessor functions to reach
inside PyCFunctionObject.
@da-woods

da-woods commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator Author

This is my proposed replacement for the CyFunction bits of #7964. My claim is that it's better because it reduces the amount of #ifdef GRAALPY code that we need, and also reduces the amount of special Cython-helper functions that they need to support.

It's only really for CPython where we benefit from using the same structure for our functions and Python C functions as an optimization for optimizations. The Limited API version has full functionality so they don't lose anything by using it.

@da-woods da-woods changed the title Make GraalPy use Limited API structure Make GraalPy use cyfunction Limited API structure Sep 5, 2026

@scoder scoder left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Simplifies a lot of code. Nice.

Comment on lines +43 to +44
#define __Pyx_CyFunction_MethodDef(cyfunc) ((cyfunc)->func_methoddef)
#define __Pyx_CyFunction_Module(cyfunc) ((cyfunc)->func_module)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Might be worth a comment that these macros are expected to be lvalues (thus the missing Get in their name).

@da-woods

da-woods commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator Author

I'll wait for confirmation from the GraalPy people that this doesn't cause unexpected problems for them before merging it. I'm pretty sure it is good. But it would be a bit unhelpful to make a change for their benefit that actually makes things worse.

Comment thread Cython/Utility/CythonFunction.c Outdated
#if CYTHON_COMPILING_IN_LIMITED_API || CYTHON_COMPILING_IN_GRAAL
PyObject *func_weakreflist;
// No-args super() class cell
PyObject *func_classobj;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Moving this field up changes much of the struct layout. I know that we only share our extension types per Cython version, but this seems something I wouldn't expect in a point release.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Reverted. I think it should be harmless but it also doesn't give us anything except one less pre-processor guard.

@msimacek

msimacek commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Looks good to me

@da-woods da-woods added this to the 3.3.1 milestone Sep 7, 2026
@da-woods
da-woods merged commit 640e333 into cython:master Sep 7, 2026
112 checks passed
@da-woods
da-woods deleted the graalpy-limited-api branch September 7, 2026 17:29
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.

3 participants