问题
I am trying to wrap a c++ enum using boost::python (boost 1.58). An enum is of type uint32_t and all values are wrapped without problem except large numbers, starting at 0x4000 0000.
An attempt to wrap enum value (uint32) of 0x4000 0000 lead to crash at enum.hpp, line 95 (boost 1.58). i observe this behaviour with VS2012 (win7).
Any ideas?
example:
enum EnumName: uint32_t
{
valueOK = 0x20000000,
valueCrash = 0x40000000
};
boost::python::enum_<EnumName>("EnumName")
.value("valueOK", valueOK)
.value("valueCrash", valueCrash)
;
回答1:
I can't reproduce the issue. Using
Live On Coliru
#include <boost/python.hpp>
enum EnumName: uint32_t
{
valueOK = 0x20000000,
valueCrash = 0x40000000
};
EnumName identity_(EnumName x) { return x; }
BOOST_PYTHON_MODULE(test)
{
boost::python::enum_<EnumName>("EnumName")
.value("valueOK", valueOK)
.value("valueCrash", valueCrash)
;
//boost::python::def("identity", identity_);
}
Building:
g++-5 -std=c++11 -Wall -pedantic -fPIC -fsanitize=undefined -g -O0 -isystem /home/sehe/custom/nonius/include -isystem /usr/include/python2.7 -pthread test.cpp -c -o test.o
g++-5 -std=c++11 -Wall -pedantic -fPIC -fsanitize=undefined -g -O0 -isystem /home/sehe/custom/nonius/include -isystem /usr/include/python2.7 -pthread test.o -shared -o test.so -lpython2.7 -lboost_python
Using
$ python2.7 <<< 'from test import *; print (EnumName.valueCrash+0);'
1073741824
来源:https://stackoverflow.com/questions/34332372/boostpythonenum-large-uint32-crash