[all-commits] [llvm/llvm-project] 4440e8: [mlir:python] Fix crash in from_python in type cas...

Ingo Müller via All-commits all-commits at lists.llvm.org
Mon Apr 13 11:40:54 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 4440e87baef3b28d1c6b06c389a861174c670b8d
      https://github.com/llvm/llvm-project/commit/4440e87baef3b28d1c6b06c389a861174c670b8d
  Author: Ingo Müller <ingomueller at google.com>
  Date:   2026-04-13 (Mon, 13 Apr 2026)

  Changed paths:
    M mlir/include/mlir/Bindings/Python/NanobindAdaptors.h
    M mlir/test/python/dialects/python_test.py
    M mlir/test/python/lib/PythonTestModuleNanobind.cpp

  Log Message:
  -----------
  [mlir:python] Fix crash in from_python in type casters. (#191764)

This PR fixes a crash due to a failed assertion in the `from_python`
implementations of the type casters. The assertion obviously only
triggers if assertions are enabled, which isn't the case for many Python
installations, *and* if a Python capsule of the wrong type is attempted
to be used, so this this isn't triggered easily. The problem is that the
conversion from Python capsules may set the Python error indicator but
the callers of the type casters do not expect that. In fact, if there
are several operloads of a function, the first may cause the error
indicator to be set and the second runs into the assertion. The fix is
to unset the error indicator after a failed capsule conversion, which is
indicated with the return value of the function anyways.

In alternative fix would be to unset the error indicator *inside* the
`mlirPythonCapsuleTo*` functions; however, their documentations does say
that the Python error indicator is set, so I assume that some callers
may *want* to see the indicator and that the responsibility to handle it
is on them.

Signed-off-by: Ingo Müller <ingomueller at google.com>



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list