从 C++ 中确定 perl 文件的行号和文件名
我正在将 Perl 嵌入到我们的应用程序中。我们已经安装了很多从 Perl 内部调用的 C++ 函数。其中之一是日志记录功能。我想将调用此函数的 Perl 文件的文件名和行号添加到日志消息中。
我知道在 Perl 端我可以使用“caller()”函数来获取此信息,但此函数已经在数百个位置使用,所以我更愿意修改 C++ 端,将此信息传递给 C++ XSUB功能,如果是的话我该如何获得它?
谢谢。
I am working with Perl embedded in our application. We have installed quite a few C++ functions that are called from within Perl. One of them is a logging function. I would like to add the file name and line number of the Perl file that called this function to the log message.
I know on the Perl side I can use the "caller()" function to get this information, but this function is already used in hundreds of locations, so I would prefer to modify the C++ side, is this information passed to the C++ XSUB functions and if so how would I get at it?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这应该有效:
— 警察.h
This should work:
— cop.h
你不能从 XS 调用 perl 内置函数吗?我承认我不知道。
如果没有,您总是可以这样做:
假设您的函数被称为 logger(并且您将 C++ XS 函数重命名为 _real_logger )。您也可以这样做,据推测,如果您需要将自己隐藏在调用树中:
这当然是 AUTOLOAD 中使用的 goto 的正常形式,
当然,这些会增加开销,但对于日志记录来说可能不是什么大问题。功能。
Can't you call perl builtins from XS? I confess I don't know.
If not, you could always do something like this:
assuming
logger
is what your function is called (and you rename your C++ XS function to_real_logger
. You could also do this, presumably, if you need to hide yourself in the call tree:which is of course the normal form of goto used in
AUTOLOAD
.These will add overhead, of course, but probably not a big deal for a logging function.