Fw: [C++-sig] Pyste and STL types

Nicodemus nicodemus at globalite.com.br
Thu Mar 20 02:29:44 CET 2003


David Abrahams wrote:

>My point is that if there's no way to know that the active member is
>"d", the union is useless anyway, so the user "always" has some member
>like is_float which she is keeping in synch to indicate the correct
>member to access.
>
>  
>
>>(unless this is a common practice: like I said before, I know little
>>about unions). 
>>    
>>
>
>I'm saying it's a common practice.  How would you use the union
>otherwise?
>  
>

I never used unions before, that's why I claimed that tha I knew little 
about them. 8)

>>So I don't think this solution is optimal. Sure, the user could
>>provide wrappers for functions like "use", but it's a lot of work
>>compared to the gains, in my opinion. 
>>    
>>
>
>That's debatable.  Part of the philosophy of Boost.Python is that you
>should be able to wrap C++ code in such a way that it can't be abused
>from Python to cause a crash.  Some unions are like that naturally,
>e.g.:
>
>        union { int x; char bytes[sizeof(int)]; };
>
>but others like the union in Test above are not.
>  
>

I see... like the operator[] for vectors, where the missuse can cause a 
crash.

>>Given this, I think exporting it to python as it is seen in C++ is
>>enough. Don't get me wrong: I would gladly implement in Pyste a
>>system to export unions like you suggested (I'm not lazy), but I
>>don't know if it is possible to do it in a reasonable way for the
>>user.
>>    
>>
>
>It requires the user to write some extra code.  Worth it?  I don't
>know; I hardly ever use unions myself ;-)
>

I never used them too. 8)

I propose we wait for user feedback. If people start to ask for unions, 
we could then discuss a way to export them nicely. Boost.Python doesn't 
support them, and I never seen anyone asking for it.

Regards,
Nicodemus.






More information about the Cplusplus-sig mailing list