我有一个C/C++代码,它使用perlcall来调用perl脚本,并使用Perl版本的5.8.90.由于5.8.90中的一些内存泄漏/堆损坏,我们计划使用最新版本的perl 5.12.3.
在使用5.12.3版本的libperl.so时,我们的程序在调用"PUSHMARK(SP);"时崩溃了.我尝试在dbx中进行调试但是只能得到以下信息t @ 32(l @ 32),它被信号SEGV终止(故障地址没有映射)
如果有人发现这个问题,请告诉我.任何找到根本原因的指针都会非常有用.
我有下面的示例程序,它将参数推送到Perl堆栈,然后调用"eval_sv".样本perl语句被执行但我无法检索从C++传递的变量作为Perl参数.请让我知道以下程序中缺少的内容
该计划的输出
你好,世界
测试
100测试完成
此行不会打印$ a和$ b的值
string three = "print 'Test\n'; my $z = 100; print $a; print $b; print $z;";
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
#include <EXTERN.h>
#include <perl.h>
#include <string>
using namespace std;
string perlScript;
static PerlInterpreter *my_perl;
SV* my_eval_sv(I32 croak_on_error)
{
STRLEN n_a;
char *p1 = new char [perlScript.size()+1];
strcpy(p1, perlScript.c_str());
const char *p = p1;
int len = strlen(p);
dSP;
ENTER ;
SAVETMPS ;
PUSHMARK(SP) ;
int a, b;
a = 10;
b = 20;
PERL_SET_CONTEXT(my_perl);
XPUSHs(sv_2mortal(newSViv(a)));
PERL_SET_CONTEXT(my_perl); …Run Code Online (Sandbox Code Playgroud) Windows x64位,带5GB RAM.我的二进制文件是64位版本,使用版本编译器构建 - "Microsoft(R)C/C++优化编译器版本14.00.50727.762 for x64"
Microsoft建议设置以下注册表项以测试64位应用程序,并在我的框中设置相同.如果我没有设置以下注册表,则不会发生此问题,因为程序位于低地址.讨论中提到了相同的注册表项 - 作为程序员,在迁移到64位窗口时需要担心什么?
要强制分配在较低地址之前从较高地址分配以进行测试,请在调用VirtualAlloc时指定MEM_TOP_DOWN或将以下注册表值设置为0x100000:
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Memory Management\AllocationPreference
char *alloc_str()
{
char *temp;
temp = (char *) malloc(60);
/* copy some data to temp */
return temp;
}
main()
{
char *str;
str = (char *)alloc_str();
}
Run Code Online (Sandbox Code Playgroud)
malloc返回0x000007fffe999b40存储的地址,temp但当指针返回时main(),str只获取后半部分 - 0xfffffffffe999b40我无法访问该位置的数据.