句柄和指向对象的指针
我有一个用 C++ 编写的 python 解释器,据说来自 Python API 的 PyRun_String 函数返回一个句柄,但是在我的代码中我将它分配给指向 PyObject
的指针?
PyObject* presult = PyRun_String(code, parse_mode, dict, dict);
这实际上是正确的吗?您可以将此句柄隐式转换为此对象指针吗?
它不应该是一个HANDLE吗?
I have a python Interpreter written in C++, the PyRun_String function from the Python API is said to return a handle, however in my code I have it assigned to pointer to a PyObject
?
PyObject* presult = PyRun_String(code, parse_mode, dict, dict);
Is this actually correct? Can you implicitly cast this handle to this object pointer?
Should it not be a HANDLE instead?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
API 文档中的“句柄”一词通常并不特指
HANDLE
类型,而是指任何对用户不透明的类型。PyRun_String
特别返回一个PyObject*
,没有进行任何转换。The word "handle" in API documentation usually does not refer specifically to the
HANDLE
type, but rather to any type intended to be opaque to the user.PyRun_String
in particular returns aPyObject*
, there is no cast going on.