[PyQt] Problems with wrapping complex types using typedefs

Casper Ti. Vector caspervector at gmail.com
Sat Jul 6 16:25:30 BST 2013


For now, aside from directly writing code to wrap
> std::map< std::pair<int, int>, std::vector<unsigned long> >
this is the only way that works; either
> #define sipType_cell sipFindType("cell")
> #define sipType_idxx sipFindType("idxx")
> typedef std::pair<int, int> cell;
> typedef std::vector<unsigned long> idxx;
> std::map<cell, idxx> Test;
or
> #define sipType_cell sipFindType("cell")
> typedef std::pair<int, int> cell;
> std::map<std::pair<int, int>, idxx> Test;
causes segfaults.

However, I still hope for a way to eradicate these disgusting segfaults
without reintroducing those magic numbers in headers.
Phil, could you help me?  Thanks...

On Fri, Jul 05, 2013 at 05:41:21PM +0800, Casper Ti. Vector wrote:
> For example, assuming all example use this header:
> > %Module test
> > %ModuleHeaderCode
> > #include "test.h"
> > %End
> > %Include types.sip // Where map, pair and vector are wrapped.
> 
> This code:
> > std::map<std::pair<int, int>, std::vector<unsigned long> > Test;
> fails because sip complains:
> > sip: Test has an unsupported type - provide %GetCode and %SetCode
> 
> while this code:
> > typedef std::pair<int, int> cell;
> > typedef std::vector<unsigned long> idxx;
> > std::map<cell, idxx> Test;
> fails because the compiler complains like:
> > error: 'sipType_cell' was not declared in this scope
> > error: 'sipType_idxx' was not declared in this scope
> 
> I searched Google for `python sip typedef' and found this message:
> <http://www.riverbankcomputing.com/pipermail/pyqt/2011-January/029111.html>
> It seems that adding something like:
> > #define sipType_cell sipType_std_pair_1800_1800
> > #define sipType_idxx sipType_std_vector_2100
> to the `%ModuleHeaderCode' section make everything runs well.
> 
> However, this trick seems quite unreliable because these magic numbers
> (1800, 2100, etc.) might vary from version to version.  So is there any
> elegant way to wrap these types?
> 
> In addition, I personally think it is favourable to generate `sipType's
> for typedefs, because this can greatly simplify efforts on wrapping
> complex template types, such as those in my examples.

-- 
My current OpenPGP key:
4096R/0xE18262B5D9BF213A (expires: 2017.1.1)
D69C 1828 2BF2 755D C383 D7B2 E182 62B5 D9BF 213A



More information about the PyQt mailing list