
Please forgive me if this question has been answered but I've searched for days now and cannot find it.
How do I expose a c++ struct with a bit field to python using boost::python?
When I try I get this error.
error: invalid pointer to bit-field ‘frameHdr_s::hdrSize’
Here is the struct:
#define DATA_SIZE 0x100
typedef struct frameHdr_s
{
#define USE_BIT_FIELDS
#ifdef USE_BIT_FIELDS
// Longword 0
uint32_t hdrSize : 16; ///< Size of the header
uint32_t revMin : 8; ///< Frame Minor Version
uint32_t revMaj : 8; ///< Frame Major Version
#else
// Longword 0
uint32_t hdrSize; ///< Size of the header
uint32_t revMin ; ///< Frame Minor Version
uint32_t revMaj ; ///< Frame Major Version
#endif
} frameHdr_t;
typedef struct frame_t
{
frameHdr_t frame_header; ///< frame header
uint8_t data[DATA_SIZE]; ///< Byte array of data
} frame_t;
Here is boost code to expose it:
using namespace boost::python;
BOOST_PYTHON_MODULE(api) {
class_

I used the c++ for developing, but now perhaps I wil begin use the boost. Is there quick way from standard c++ to boost c++?

I used the c++ for developing, but now perhaps I wil begin use the boost. Is there quick way from standard c++ to boost c++?
Boost is a collection of libraries written in standard c++ and interoperable with the standard c++ library. The most quick way to begin working with boost is to choose the libraries you need and to read the appropriate manuals: http://www.boost.org/doc/libs/1_53_0/

AMDG On 04/05/2013 08:19 AM, Chris Gem wrote:
Please forgive me if this question has been answered but I've searched for days now and cannot find it.
How do I expose a c++ struct with a bit field to python using boost::python?
When I try I get this error.
error: invalid pointer to bit-field ‘frameHdr_s::hdrSize’
You can't take that address of a bitfield. You'll have to use add_property directly. In Christ, Steven Watanabe

Thank you Steve, BOOST_PYTHON_MODULE(api) { class_<FrameHdr>("FrameHdr") //.def_readwrite("hdrSize", &frameHdr_t::hdrSize) .add_property("hdrSize", frameHdr_t) ; Still got the same error. However, after looking at add_property, I wrapped the struct with a class that implemented setters and getters for the bitfields, thusly: typedef struct frameHdr_s { #define USE_BIT_FIELDS #ifdef USE_BIT_FIELDS // Longword 0 uint32_t hdrSize : 16; ///< Size of the header uint32_t revMin : 8; ///< Frame Minor Version uint32_t revMaj : 8; ///< Frame Major Version #else // Longword 0 uint32_t hdrSize; ///< Size of the header uint32_t revMin ; ///< Frame Minor Version uint32_t revMaj ; ///< Frame Major Version #endif } frameHdr_t; class FrameHdr :public frameHdr_t { public: uint32_t getHdrSize() { return hdrSize; } void setHdrSize(uint32_t val) { hdrSize = val; } }; Then I used add_property to expose the setters and getters as the name of the property in question: BOOST_PYTHON_MODULE(api) { class_<FrameHdr>("FrameHdr") //.def_readwrite("hdrSize", &frameHdr_t::hdrSize) .add_property("hdrSize", &FrameHdr::getHdrSize, &FrameHdr::setHdrSize) ; Without trying to sound like too much of a whiner, this seems like a lot of work. Is this what you had in mind? Thanks for your time, Chris
Date: Sat, 6 Apr 2013 13:03:55 -0700 From: watanabesj@gmail.com To: boost-users@lists.boost.org Subject: Re: [Boost-users] c++ Bit Fields
AMDG
On 04/05/2013 08:19 AM, Chris Gem wrote:
Please forgive me if this question has been answered but I've searched for days now and cannot find it.
How do I expose a c++ struct with a bit field to python using boost::python?
When I try I get this error.
error: invalid pointer to bit-field ‘frameHdr_s::hdrSize’
You can't take that address of a bitfield. You'll have to use add_property directly.
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (4)
-
Chris Gem
-
Igor R
-
Steven Watanabe
-
yujian221