Closed
pyACL `get_recent_err_msg` 文档将字符串误写为整数状态码 #1424
KaranocaVeAdd on 6 days agoClosed at 1 day ago
6 days ago Associated pull request
6 days ago Modify description of issue
duanpengliang
6 days ago Comments:
6 days ago Comments:
初步分析,中英文文档将 acl.get_recent_err_msg() 的返回值写成整数状态码,与接口实现不符。该接口返回错误描述字符串,底层返回空指针时对应 None;将结果与 0 比较不能判断原接口调用是否成功,应依据原接口自身的返回码判断,并单独读取错误描述。两份文档应同步更正为 msg 的字符串或 None 说明。
已有相关文档修正 PR:https://gitcode.com/cann/runtime/merge_requests/6471,后续将对该 PR 进行检视。


6 days ago Assign KaranocaVe、xiao_cun as responsible person
2 days ago Assign wuyao51511 as responsible person
2 days ago Associated pull request
1 day ago changed custom state from 待办的 to 已解决
1 day ago Close issue
ykl999
1 day ago Comments:
1 day ago Comments:
你好,相关pr已合入。https://gitcode.com/cann/runtime/pull/6604/discuss
感谢指出文档相关问题!


pyACL
get_recent_err_msg文档将字符串误写为整数状态码cann/runtime506b161234801758c070c873da1c5d6e07c663b8E2问题
pyACL 的中文和英文 API 文档都把
acl.get_recent_err_msg()的返回值写成整数错误码,并说明 0 表示成功、非 0 表示失败。但示例将返回值赋给msg,C 原型返回const char *,Python 包装实现通过Py_BuildValue("s", ret)将其转换为 Python 字符串;C 指针为空时,Python 返回值为None。调用者按文档把结果作为状态码判断时,无法正确使用接口返回的错误描述信息。证据
python/docs/zh/api_ref/runtime/exception/function-get_recent_err_msg.md与英文对应文档的原型都展示msg = acl.get_recent_err_msg(),但返回值表却声明ret是整数错误码。include/external/acl/acl_rt.h声明aclGetRecentErrMsg()返回const char *。python/pyACL/py_init_acl.cpp的WrapAclGetRecentErrMsg将aclGetRecentErrMsg()的结果保存为const char *,再通过Py_BuildValue("s", ret)返回。CPython 的Py_BuildValue文档规定,s格式将 C 字符串转换为 Pythonstr,空指针转换为None。src/acl/aclrt_impl/acl.cpp在没有可用错误信息时返回空指针;tests/ut/acl/testcase_c/acl_rt_unittest.cpp的acl_GetRecentErrMsg用ASSERT_STREQ验证该接口返回错误描述字符串,并验证读取后再次调用返回空值。影响与范围
遵循文档编写的 Python 调用方可能把描述字符串或
None当作状态码与 0 比较,或把它当作整数错误码处理,因而无法按预期获得错误文本。本案只修正文档返回值类型;错误信息作用域配置、获取并清空语义和推荐调用顺序均不变。关联 PR: https://gitcode.com/cann/runtime/merge_requests/6471