-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
python: Add test cases for PEP 803/820 ft-compatible limited API #15695
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #include <Python.h> | ||
|
|
||
| #ifndef Py_LIMITED_API | ||
| #error Py_LIMITED_API must be defined. | ||
| #elif Py_LIMITED_API != 0x030f0000 | ||
| #error Wrong value for Py_LIMITED_API | ||
| #endif | ||
|
|
||
| static PyObject * | ||
| hello(PyObject * Py_UNUSED(self), PyObject * Py_UNUSED(args)) { | ||
| return PyUnicode_FromString("hello world"); | ||
| } | ||
|
|
||
| static struct PyMethodDef methods[] = { | ||
| { "hello", hello, METH_NOARGS, NULL }, | ||
| { NULL, NULL, 0, NULL }, | ||
| }; | ||
|
|
||
| PyABIInfo_VAR(abi_info); | ||
|
|
||
| static PySlot limited_module_slots[] = { | ||
| PySlot_STATIC_DATA(Py_mod_name, "limited"), | ||
| PySlot_STATIC_DATA(Py_mod_methods, methods), | ||
| PySlot_STATIC_DATA(Py_mod_gil, Py_MOD_GIL_NOT_USED), | ||
| PySlot_STATIC_DATA(Py_mod_abi, &abi_info), | ||
| PySlot_END, | ||
| }; | ||
|
|
||
| PyMODEXPORT_FUNC PyModExport_limited(void) { | ||
| return limited_module_slots; | ||
| } | ||
|
|
||
| PyMODINIT_FUNC PyInit_limited(void) { | ||
| PyErr_SetString(PyExc_NotImplementedError, "legacy init not supported"); | ||
| return NULL; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| project('Python limited api ft', 'c', | ||
| default_options : ['buildtype=release', 'werror=true']) | ||
|
|
||
| py_mod = import('python') | ||
| py = py_mod.find_installation() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: more idiomatic to collapse these 2 lines to 1 line and not use a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was copying the existing test, but I suppose I can change that. |
||
|
|
||
| if py.language_version().version_compare('<3.15') | ||
| error('MESON_SKIP_TEST: Py_TARGET_ABI3T is supported since 3.15.0a8') | ||
| endif | ||
|
|
||
| ext_mod_limited = py.extension_module('limited', | ||
| 'limited.c', | ||
| limited_api: '3.15', | ||
| install: true, | ||
| ) | ||
|
|
||
| test('load-test', | ||
| py, | ||
| args: [files('test_limited.py')], | ||
| env: { 'PYTHONPATH': meson.current_build_dir() }, | ||
| workdir: meson.current_source_dir() | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "installed": [ | ||
| {"type": "python_limited_lib", "file": "usr/@PYTHON_PLATLIB@/limited"}, | ||
| {"type": "py_limited_implib", "file": "usr/@PYTHON_PLATLIB@/limited"} | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| from limited import hello | ||
|
|
||
| def test_hello(): | ||
| assert hello() == "hello world" | ||
|
|
||
| test_hello() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,8 +4,8 @@ project('Python limited api', 'c', | |
| py_mod = import('python') | ||
| py = py_mod.find_installation() | ||
|
|
||
| if py.get_variable('Py_GIL_DISABLED', 0) == 1 and py.language_version().version_compare('<3.15') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. addressed, resolving. |
||
| error('MESON_SKIP_TEST: Freethreading Python does not support limited API') | ||
| if py.get_variable('Py_GIL_DISABLED', 0) == 1 | ||
| error('MESON_SKIP_TEST: Freethreading Python does not support (old) limited API') | ||
| endif | ||
|
|
||
| ext_mod_limited = py.extension_module('limited', | ||
|
|
||
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.
Is this better than not defining the
PyInit_symbol at all?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.
To be honest, I don't recall anymore why I did it that way in the stable-abi-testing repo, but there was probably a reason. Yes, it's one of these things :-).
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.
Checked upstream, it's done the same way there in the one test package they have:
https://github.com/python/cpython/blob/4ae1a260c7dbada6db099d3335a784b5aae91723/Lib/test/test_cext/extension.c#L145
so resolving.