1

我有一个类似于以下的课程。它有一个嵌套的枚举 OptionTag。

class MediaPacket
{
    public:
           struct RtcpAppName {
           char mName[RTCP_APPNAME_LENGTH];
           };

          enum OptionTag {
                         RESERVED  = 0,
                         PROFILE   = 1,
                         LATENCY   = 2,
                         PKTLOSS   = 3,
                         JITTER    = 4,
                         LEGACYMIX = 5,
                         LASTTAG   = 255
                     };

                    ....
                    ....
          list<OptionTag> GetOptions(unsigned int ssrc) const;
};

为此,我创建了一个 swig 界面,如下所示

%module mediaopts_packet
%include "stdint.i"

//Redefining nested structure in swig
struct RtcpAppName {
char mName[RTCP_APPNAME_LENGTH];
};


%{
    #define SWIG_FILE_WITH_INIT
    #include "../include/mediaopts_packet.h"
%}

//nestedworkaround key for the nested struct
%nestedworkaround CRtcpAppPacket::RtcpAppName;
%{
typedef CRtcpAppPacket::RtcpAppName RtcpAppName;
%}

//Some swig definitions that are not related to this problem
//%include "carrays.i"
//%array_class(uint8_t, buffer);

//%include "typemaps.i"
//%apply (unit8_t *STRING, int LENGTH) { (uint8_t *id, uint32_t len) };
//%apply uint32_t & OUTPUT { uint32_t & xmitOpt };
//%apply uint32_t & OUTPUT { uint32_t & rcvOpt };
//%apply uint32_t & OUTPUT { uint32_t & optValue };

%include "std_list.i"

namespace std
{
    %template(ListUint32) list<uint32_t>;
    %template(ListOptionTag) list<CRtcpAppMediaoptsPacket::OptionTag>;
}

%include "../include/mediaopts_packet.h"

在python中使用代码

Python 2.7.2+ (default, Oct  4 2011, 20:03:08)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mediaopts_packet
>>>
>>> packet = mediaopts_packet.MediaPacket()
>>>
>>> packet.AddSSRC(0,1,1)
>>>
>>> packet.GetAllSSRC()
(0,)
>>> ssrc_list = mediaopts_packet.ListUint32()
>>>
>>> ssrc_list = packet.GetAllSSRC()
>>>
>>> ssrc_list
(0,)
>>> ssrc_list[0]
0
>>> packet.AddOption(0, mediaopts_packet.MediaPacket.RESERVED, 0)
0
>>> packet.GetOptions(0)
Segmentation fault

在我在 python 中使用它时构建后,我得到一个分段错误。我无法理解我错过了什么。请帮忙。

4

0 回答 0