Boost.Python方法返回字符串截断,意外的整数值

时间:2010-09-17 06:41:37

标签: c++ python boost boost-python

我正在使用Boost.Python来公开JRA的BWRepLib所以我可以尝试在python中对sc:bw重放进行一些数据挖掘,并且我遇到了一个小问题,从C ++方法。当运行任何旧的简单程序(如教程)时,我得到返回到python的预期值(打印出来的“hello,world”字符串)。但是,当我运行bwreplib程序时,我遇到了所有字符串被截断并且某些整数返回方法返回意外值的问题。例如,在一次重播中,C ++中的玩家名称正确返回,因为玩家1是SlayerS_'BoxeR',玩家2是iloveoov。但是在python中打印的值是erS_'Boxer'和eoov,缺少最初的4个字节/字符。另一个例子是玩家种族应该是一个整数值1,2,3或6,但是我得到更大的无关值,如97,120,111和78但是某些值,如120和97应该是相同的竞争并从纯C ++程序中返回相同的值。因为我看到数字之间没有二元相关性,我怀疑这可能是由python中的一个单词抵消并从不同的位置返回一个值?有没有人遇到类似的问题?

我很擅长使用Boost.Python而不是C ++专家。我可以发布包装器,但除了公开诸如

之类的功能之外它没有什么用处
class_<BWrepPlayer>("BWrepPlayer")
.def("getName", &BWrepPlayer::getName)
.def("getNumber", &BWrepPlayer::getNumber)

我怀疑我应该做一些特别的事情来包装我没有做的功能。然而,在网上搜索和阅读文档我无法找到它会是什么,但是我相信一旦我找到它就会非常明显。

编辑:日志输出

...patience...
...patience...
...found 1547 targets...
...updating 4 targets...
compile-c-c++ bin\msvc-9.0\debug\threading-multi\BWrepAPI.obj
BWrepAPI.cpp
BWrepAPI.cpp(19) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
        c:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\string.h(74) : see declaration of 'strcpy'
BWrepAPI.cpp(88) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
        c:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\string.h(74) : see declaration of 'strcpy'
BWrepAPI.cpp(245) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
        c:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\string.h(74) : see declaration of 'strcpy'
BWrepAPI.cpp(246) : warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
        c:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\string.h(79) : see declaration of 'strcat'
BWrepAPI.cpp(259) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
        c:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\string.h(74) : see declaration of 'strcpy'
BWrepAPI.cpp(265) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
        c:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\string.h(74) : see declaration of 'strcpy'
BWrepAPI.cpp(277) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
        c:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\string.h(74) : see declaration of 'strcpy'
BWrepAPI.cpp(323) : warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
        c:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\stdio.h(237) : see declaration of 'fopen'
msvc.link.dll bin\msvc-9.0\debug\threading-multi\pybwrep.pyd
   Creating library bin\msvc-9.0\debug\threading-multi\pybwrep.lib and object bin\msvc-9.0\debug\threading-multi\pybwrep.exp
msvc.manifest.dll bin\msvc-9.0\debug\threading-multi\pybwrep.pyd
...updated 4 targets...

0 个答案:

没有答案