This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Better error message in PybindAdaptors.h
ClosedPublic

Authored by ftynse on Jan 19 2022, 4:43 AM.

Details

Summary

When attempting to cast a pybind11 handle to an MLIR C API object through
capsules, the binding code would attempt to directly access the "_CAPIPtr"
attribute on the object, leading to a rather obscure AttributeError when the
attribute was missing, e.g., on non-MLIR types. Check for its presence and
throw a TypeError instead.

Depends On D117646

Diff Detail

Event Timeline

ftynse created this revision.Jan 19 2022, 4:43 AM
ftynse requested review of this revision.Jan 19 2022, 4:43 AM
stellaraccident accepted this revision.Jan 19 2022, 8:36 AM
stellaraccident added inline comments.
mlir/include/mlir/Bindings/Python/PybindAdaptors.h
58

I wonder if this shouldn't be a try-catch around this vs a double attribute lookup? That would make it zero cost on the success case.

This revision is now accepted and ready to land.Jan 19 2022, 8:36 AM
This revision was landed with ongoing or failed builds.Feb 1 2022, 8:49 AM
This revision was automatically updated to reflect the committed changes.