-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[mypyc] Move API table definitions to .c files #21183
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
Merged
p-sawicki
merged 16 commits into
python:master
from
p-sawicki:move-api-tables-to-static_data
Apr 13, 2026
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
d243357
Move strings api table
p-sawicki dfe2fee
Move other global pointers
p-sawicki 912f66f
Move API tables to separate files
p-sawicki 5d86dcf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 20f793c
Add new files to librt sources
p-sawicki edf9c52
Move dependency header includes to internal header
p-sawicki a5cd7d9
Add separate _api.c file for each librt module
p-sawicki 8c30b33
Fix filename
p-sawicki cea8a11
Remove stale includes
p-sawicki 635d1d7
Add file suffix; use quote includes for consistency
p-sawicki 2c21c2a
Remove duplicated defines
p-sawicki 9f9c90d
Compile librt_internal_api.c in multi-file mode
p-sawicki 96cc352
Move dependency headers back to external C ext header
p-sawicki d3613a5
Add type annotation
p-sawicki 45a8258
Serialize new SourceDep members
p-sawicki de13126
Add TODO comment
p-sawicki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #include "librt_base64_api.h" | ||
|
|
||
| void *LibRTBase64_API[LIBRT_BASE64_API_LEN] = {0}; | ||
|
|
||
| int | ||
| import_librt_base64(void) | ||
| { | ||
| PyObject *mod = PyImport_ImportModule("librt.base64"); | ||
| if (mod == NULL) | ||
| return -1; | ||
| Py_DECREF(mod); // we import just for the side effect of making the below work. | ||
| void *capsule = PyCapsule_Import("librt.base64._C_API", 0); | ||
| if (capsule == NULL) | ||
| return -1; | ||
| memcpy(LibRTBase64_API, capsule, sizeof(LibRTBase64_API)); | ||
| if (LibRTBase64_ABIVersion() != LIBRT_BASE64_ABI_VERSION) { | ||
| char err[128]; | ||
| snprintf(err, sizeof(err), "ABI version conflict for librt.base64, expected %d, found %d", | ||
| LIBRT_BASE64_ABI_VERSION, | ||
| LibRTBase64_ABIVersion() | ||
| ); | ||
| PyErr_SetString(PyExc_ValueError, err); | ||
| return -1; | ||
| } | ||
| if (LibRTBase64_APIVersion() < LIBRT_BASE64_API_VERSION) { | ||
| char err[128]; | ||
| snprintf(err, sizeof(err), | ||
| "API version conflict for librt.base64, expected %d or newer, found %d (hint: upgrade librt)", | ||
| LIBRT_BASE64_API_VERSION, | ||
| LibRTBase64_APIVersion() | ||
| ); | ||
| PyErr_SetString(PyExc_ValueError, err); | ||
| return -1; | ||
| } | ||
| return 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #ifndef LIBRT_BASE64_API_H | ||
| #define LIBRT_BASE64_API_H | ||
|
|
||
| #include "librt_base64.h" | ||
|
|
||
| extern void *LibRTBase64_API[LIBRT_BASE64_API_LEN]; | ||
|
|
||
| #define LibRTBase64_ABIVersion (*(int (*)(void)) LibRTBase64_API[0]) | ||
| #define LibRTBase64_APIVersion (*(int (*)(void)) LibRTBase64_API[1]) | ||
| #define LibRTBase64_b64encode_internal (*(PyObject* (*)(PyObject *source, bool urlsafe)) LibRTBase64_API[2]) | ||
| #define LibRTBase64_b64decode_internal (*(PyObject* (*)(PyObject *source, bool urlsafe)) LibRTBase64_API[3]) | ||
|
|
||
| int import_librt_base64(void); | ||
|
|
||
| #endif // LIBRT_BASE64_API_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was pretty confusing. Is this only used for the header? The SourceDep however has a reference to a .c file, which is quite different. I think it could be cleaner to separate e.g. librt_strings.h and librt_strings.c dependencies, since their use cases are quite different. This can happen in a follow-up PR, if you add a TODO here.