Skip to content

Meson doesn't handle limited_api_suffix = None from python_info.py #14673

@mgorny

Description

@mgorny

Describe the bug
Noticed this while working on #14657.

limited_api_suffix can technically be None:

limited_api_suffix = None
if sys.version_info >= (3, 2):
try:
from importlib.machinery import EXTENSION_SUFFIXES
limited_api_suffix = EXTENSION_SUFFIXES[1]
except Exception:
pass
# pypy supports modules targeting the limited api but
# does not use a special suffix to distinguish them:
# https://doc.pypy.org/en/latest/cpython_differences.html#permitted-abi-tags-in-extensions
if is_pypy:
limited_api_suffix = suffix

Though admittedly I don't know of any real life use case when this would happen. However, if it does, Meson crashes when trying to build limited API code:

Traceback (most recent call last):
  File "/home/mgorny/git/meson/mesonbuild/mesonmain.py", line 193, in run
    return options.run_func(options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mgorny/git/meson/mesonbuild/msetup.py", line 392, in run
    app.generate()
  File "/home/mgorny/git/meson/mesonbuild/msetup.py", line 194, in generate
    return self._generate(env, capture, vslite_ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mgorny/git/meson/mesonbuild/msetup.py", line 251, in _generate
    intr.run()
  File "/home/mgorny/git/meson/mesonbuild/interpreter/interpreter.py", line 3049, in run
    super().run()
  File "/home/mgorny/git/meson/mesonbuild/interpreterbase/interpreterbase.py", line 178, in run
    self.evaluate_codeblock(self.ast, start=1)
  File "/home/mgorny/git/meson/mesonbuild/interpreterbase/interpreterbase.py", line 203, in evaluate_codeblock
    raise e
  File "/home/mgorny/git/meson/mesonbuild/interpreterbase/interpreterbase.py", line 195, in evaluate_codeblock
    self.evaluate_statement(cur)
  File "/home/mgorny/git/meson/mesonbuild/interpreterbase/interpreterbase.py", line 215, in evaluate_statement
    return self.method_call(cur)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/mgorny/git/meson/mesonbuild/interpreterbase/interpreterbase.py", line 565, in method_call
    res = obj.method_call(method_name, args, kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mgorny/git/meson/mesonbuild/interpreterbase/baseobjects.py", line 81, in method_call
    return method(args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^
  File "/home/mgorny/git/meson/mesonbuild/interpreterbase/decorators.py", line 103, in wrapped
    return f(*wrapped_args, **wrapped_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mgorny/git/meson/mesonbuild/interpreterbase/decorators.py", line 237, in wrapper
    return f(*nargs, **wrapped_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mgorny/git/meson/mesonbuild/interpreterbase/decorators.py", line 556, in wrapper
    return f(*wrapped_args, **wrapped_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mgorny/git/meson/mesonbuild/modules/python.py", line 223, in extension_module_method
    split, target_suffix = target_suffix.rsplit('.', 1)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'rsplit'

test cases/unit/125 python extension/meson.build:10:3: ERROR: Unhandled python exception

    This is a Meson bug and should be reported!

To Reproduce

project('python extension', 'c')

py = import('python').find_installation()

py.extension_module(
    'foo_stable', 'foo.c',
    install: true,
    limited_api: '3.10',
)

(foo.c can be empty)

To reproduce, I've used PyPy, but removed the limited_api_suffix = suffix fallback

Expected behavior
I think Meson should throw an explicit error that limited API is not supported.

system parameters

  • Is this a cross build or just a plain native build (for the same computer)? Native.
  • what operating system: Gentoo Linux amd64
  • what Python version are you using: PyPy3.11 7.3.19
  • what meson --version: 1.8.99 (5555027)
  • what ninja --version if it's a Ninja build: n/a

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions