[PyQt] Typedefs and SIP

Phil Thompson phil at riverbankcomputing.com
Thu Jan 27 10:28:23 GMT 2011


On Wed, 26 Jan 2011 10:18:55 -0800, Nate Reid <gnatty7 at hotmail.com> wrote:
> If I'm using a typedef with a MappedType, and a container that's a
> MappedType,  it seems like I have to use a #define to tell SIP that the
> specific typedef is the same as the MappedType.
> E.g.
> 
> I've wrapped std::string with MappedType, so it's type is
> sipType_std_string
> 
> and I've also wrapped std::set in a MappedType where template<TYPE>
> std::set<TYPE> is defined.
> 
> If I do a typedef in my C++ code as:
> // C++ file...
> namespace foo {
>     typedef std::string NameType
> }
> 
> And also in my SIP file, create an equivalent typedef
> // SIP module file
> namespace foo {
>     typedef std::string NameType;
>     typedef std::set<foo::NameType> SetOfNames; // Aside, it'd be great
if
>     SIP knew that NameType was already a member of foo, and I didn't
have
>     to explicitly qualify it!
> };
> 
> SIP will come back with a compile error like this when using NameType in
> my MappedType for std::set
> python/util/set.sip(73): error: identifier "sipType_foo_NameType" is
> undefined
>               foo::NameType *copy = reinterpret_cast<foo::NameType
>               *>(sipConvertToType(item, sipType_foo_NameType,
>               sipTransferObj, SIP_NOT_NONE, &state, sipIsErr))
> 
> I was able to get rid of the compile error by adding a #define to my
> %ModuleHeaderCode section of the SIP file like this
> %ModuleHeaderCode
> ...
> #define sipType_foo_NameType sipType_std_string
> 
> It seems to me that this is fragile.  If I change the namespace of where
> NameType lives, I'd have to manually change all of the #defines,
typedefs
> in the SIP files, etc.  Also, requiring this 'hint' to SIP seems
erroneous
> to me.  Shouldn't the typedef be sufficient for creating a new sipType
in
> the API file?
> Or, am I doing something wrong? :)
> Thanks,
> -Nate

typedef shouldn't create a new sipType because you are creating an alias
to an existing type, not creating a new one. If you move the typedef to a
different namespace then you are changing its name and should expect to
have to make corresponding changes in the rest of your source.

Automatically generating the #defines seems to be a reasonable suggestion.

Phil




More information about the PyQt mailing list