[Mlir-commits] [mlir] [mlir][python] Add stable ABI (abi3) support (PR #183856)
Jakub Kuderski
llvmlistbot at llvm.org
Sun Mar 1 05:30:43 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);
----------------
kuhar wrote:
Good catch, this is a leftover code from when we tried to have autolocation supported and went through `Py_GetAttrString(code, “co_*”)`
https://github.com/llvm/llvm-project/pull/183856
More information about the Mlir-commits
mailing list