Python C API:PyEval_CallFunction?
我在 Python C API 中发现了一个名为 PyEval_CallFunction
的函数,它似乎很有用。它允许您通过以下内容来调用 Python 可调用函数:
PyEval_CallFunction(obj, "OOO", a, b, c);
但是,我找不到有关此函数的任何官方文档。谷歌搜索会显示各种非官方 教程讨论了这个函数,但是:
函数不是 官方文档中记录了 Python 文档,所以我不知道它是否是 即使是应该做的事情 成为公共 API 的一部分。
网络搜索发现 使用政策不一致。一些 教程表明 格式字符串需要括号 围绕类型列表,例如
“(OiiO)”
,而其他时候我 看到它不带括号使用。 当我实际尝试该功能时 一个真正的程序,似乎需要 括号内,否则 段错误。
我想使用这个功能,因为它很方便。有谁知道这件事,或者知道为什么没有记录?它是公共 API 的一部分吗?
I've discovered a function in the Python C API named PyEval_CallFunction
which seems to be useful. It allows you to invoke a Python callable by saying something like:
PyEval_CallFunction(obj, "OOO", a, b, c);
However, I can't find any official documentation on this function. A google search brings up various unofficial tutorials which discuss this function, but:
The function isn't
documented in the official
Python docs, so I don't know if it's
even something that is supposed to
be part of the public API.Searching the web turns up
inconsistent usage policies. Some
tutorials indicate the
format string needs parenthesis
around the type list, like"(OiiO)"
, whereas other times I
see it used without the parenthesis.
When I actually try the function in
a real program, it seems to require
the parenthesis, otherwise it
segfaults.
I'd like to use this function because it's convenient. Does anyone know anything about this, or know why it isn't documented? Is it part of the public API?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我也找不到很多参考资料,但您链接到的教程提到了这一点:
我认为
PyEval_CallFunction
不是公共 API,因为它的价值似乎相当有限。这两者之间没有太大区别。但话又说回来,我并没有真正参与 python 扩展,所以这只是我对此的看法。PyEval_CallObject
本身只是一个围绕PyEval_CallObjectWithKeywords
的宏。关于“什么是公共API?”的问题以下是 Martin 诉 Löwis 的最新消息:
http://mail.python.org/pipermail/python-dev /2011-2月/107973.html
I couldn't find many references to it either, but the tutorial you linked to mentions this:
I suppose
PyEval_CallFunction
is not public API, as its value seems rather limited. There is not much of a difference between these two. But then again, I'm not really involved in python extensions, so this is just my view on this.PyEval_CallObject
itself is just a macro aroundPyEval_CallObjectWithKeywords
.On the matter of "What is public API?" here is a recent message from Martin v. Löwis:
http://mail.python.org/pipermail/python-dev/2011-February/107973.html
未记录的原因是您应该使用 PyObject_CallFunction< /a> 相反。
PyEval_*
函数系列是解释器评估循环的原始内部调用。相应记录的PyObject_*
调用包括所有附加的解释器状态完整性检查、参数验证和堆栈保护。The reason it isn't documented is because you should be using PyObject_CallFunction instead.
The
PyEval_*
function family are the raw internal calls for the interpreter evaluation loop. The corresponding documentedPyObject_*
calls include all the additional interpreter state integrity checks, argument validation and stack protection.