[Mlir-commits] [mlir] [mlir][python] Add stable ABI (abi3) support (PR #183856)
Maksim Levental
llvmlistbot at llvm.org
Sat Feb 28 20:57:26 PST 2026
================
@@ -2736,25 +2701,26 @@ MlirLocation tracebackToLocation(MlirContext ctx) {
for (; pyFrame != nullptr && count < framesLimit;
next = PyFrame_GetBack(pyFrame), Py_XDECREF(pyFrame), pyFrame = next) {
PyCodeObject *code = PyFrame_GetCode(pyFrame);
- auto fileNameStr =
- nb::cast<std::string>(nb::borrow<nb::str>(code->co_filename));
- std::string_view fileName(fileNameStr);
+ Py_ssize_t fileNameLen;
+ const char *fileNamePtr =
+ PyUnicode_AsUTF8AndSize(code->co_filename, &fileNameLen);
+ std::string_view fileName(fileNamePtr, fileNameLen);
if (!PyGlobals::get().getTracebackLoc().isUserTracebackFilename(fileName))
continue;
// co_qualname and PyCode_Addr2Location added in py3.11
#if PY_VERSION_HEX < 0x030B00F0
- std::string name =
- nb::cast<std::string>(nb::borrow<nb::str>(code->co_name));
- std::string_view funcName(name);
+ Py_ssize_t nameLen;
+ const char *namePtr = PyUnicode_AsUTF8AndSize(code->co_name, &nameLen);
+ std::string_view funcName(namePtr, nameLen);
----------------
makslevental wrote:
not that i mind going "straight to the source" but why were these necessary? is some part of `nb::cast<std::string>(nb::borrow<nb::str>` no supported under stable ABI?
https://github.com/llvm/llvm-project/pull/183856
More information about the Mlir-commits
mailing list