diff --git a/test cases/python/11 extmodule limited api lib/meson.build b/test cases/python/11 extmodule limited api lib/meson.build new file mode 100644 index 000000000000..812677e8a4e7 --- /dev/null +++ b/test cases/python/11 extmodule limited api lib/meson.build @@ -0,0 +1,28 @@ +# Test that we can build a library that uses the limited API +# and link it to an extension module. + +project('Python limited api lib', 'c', + default_options : ['buildtype=release', 'werror=true']) + +py_mod = import('python') +py = py_mod.find_installation(limited_api: '3.7') +py_dep = py.dependency(required: true) + +nanolib = static_library( + 'nanolib', + 'nanolib.c', + dependencies: [py_dep], +) + +ext_mod = py.extension_module('mymodule', + 'module.c', + install: true, + link_with: [nanolib], +) + +test('load-test', + py, + args: [files('test_module.py')], + env: { 'PYTHONPATH': meson.current_build_dir() }, + workdir: meson.current_source_dir() +) diff --git a/test cases/python/11 extmodule limited api lib/module.c b/test cases/python/11 extmodule limited api lib/module.c new file mode 100644 index 000000000000..2b0d03aba3b9 --- /dev/null +++ b/test cases/python/11 extmodule limited api lib/module.c @@ -0,0 +1,27 @@ +#include + +#ifndef Py_LIMITED_API +#error Py_LIMITED_API must be defined. +#elif Py_LIMITED_API != 0x03070000 +#error Wrong value for Py_LIMITED_API +#endif + +PyObject * +hello(PyObject * Py_UNUSED(self), PyObject * Py_UNUSED(args)); + +static struct PyMethodDef methods[] = { + { "hello", hello, METH_NOARGS, NULL }, + { NULL, NULL, 0, NULL }, +}; + +static struct PyModuleDef mymodule = { + PyModuleDef_HEAD_INIT, + "mymodule", + NULL, + -1, + methods +}; + +PyMODINIT_FUNC PyInit_mymodule(void) { + return PyModule_Create(&mymodule); +} diff --git a/test cases/python/11 extmodule limited api lib/nanolib.c b/test cases/python/11 extmodule limited api lib/nanolib.c new file mode 100644 index 000000000000..4d34a0754264 --- /dev/null +++ b/test cases/python/11 extmodule limited api lib/nanolib.c @@ -0,0 +1,12 @@ +#include + +#ifndef Py_LIMITED_API +#error Py_LIMITED_API must be defined. +#elif Py_LIMITED_API != 0x03070000 +#error Wrong value for Py_LIMITED_API +#endif + +PyObject * +hello(PyObject * Py_UNUSED(self), PyObject * Py_UNUSED(args)) { + return PyUnicode_FromString("hello world"); +} diff --git a/test cases/python/11 extmodule limited api lib/test.json b/test cases/python/11 extmodule limited api lib/test.json new file mode 100644 index 000000000000..ffb1f29813bd --- /dev/null +++ b/test cases/python/11 extmodule limited api lib/test.json @@ -0,0 +1,6 @@ +{ + "installed": [ + {"type": "python_limited_lib", "file": "usr/@PYTHON_PLATLIB@/mymodule"}, + {"type": "py_limited_implib", "file": "usr/@PYTHON_PLATLIB@/mymodule"} + ] +} diff --git a/test cases/python/11 extmodule limited api lib/test_module.py b/test cases/python/11 extmodule limited api lib/test_module.py new file mode 100644 index 000000000000..5c50705d6923 --- /dev/null +++ b/test cases/python/11 extmodule limited api lib/test_module.py @@ -0,0 +1,6 @@ +from mymodule import hello + +def test_hello(): + assert hello() == "hello world" + +test_hello() diff --git a/test cases/python/9 extmodule limited api/meson.build b/test cases/python/9 extmodule limited api/meson.build index bdf1b7b904f1..4779495ccf1c 100644 --- a/test cases/python/9 extmodule limited api/meson.build +++ b/test cases/python/9 extmodule limited api/meson.build @@ -21,3 +21,32 @@ test('load-test', env: { 'PYTHONPATH': meson.current_build_dir() }, workdir: meson.current_source_dir() ) + +# Test inheritance and override of limited_api + +py_limited = py_mod.find_installation(limited_api: '3.7') + +py_limited.extension_module('limited_inherit', + 'limited.c', +) + +py_limited.extension_module('not_limited_override', + 'not_limited.c', + limited_api: '', +) + +py_dep_limited = py.dependency(required: true, limited_api: '3.7') + +static_library( + 'limited_dependency', + 'limited.c', + dependencies: [py_dep_limited], +) + +py_dep_inherit = py_limited.dependency(required: true) + +static_library( + 'limited_dependency_inherit', + 'limited.c', + dependencies: [py_dep_inherit], +)