Re: [C++-sig] pyplusplus is alive :-)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: [C++-sig] pyplusplus is alive :-)

Niall Douglas
On 29 Mar 2006 at 23:55, Roman Yakovenko wrote:

> Problem number 1. pyplusplus generates invalid code mainly because of
> unions that have unnamed struct inside.
>
> struct FXAPI Header
> {
> FXuint length;
> char guid[16];
> union Flags
> {
> struct
> {
> FXuint hasItemIdList : 1;
> FXuint pointsToFileOrDir : 1;
> FXuint hasDescription : 1;
>                                 ...
> };
> FXuint raw;
> } flags;
>     }
>
> I am almost sure, that it can not be exported to Python.
> First of all I am not sure how I should export unions? What do you
> expect to get?

The above is simply a technique for mapping bits to the same place as
an int. Unnamed structs simply push their members into the enclosing
namespace, therefore you'd access the above as
header.flags.pointsToFileOrDir. Right now, pyplusplus is putting a
$_x after flags because gccxml gives unnamed structs an internal
name. To generate correct code, all pyplusplus needs to do is ignore
any unnamed structs it sees.

> According to this http://lists.boost.org/Archives/boost/2002/11/39157.php
> it will not be supported.
>
> So I propose you to change union to struct, or to write some hand written code
> that will export it. May be I could learn from it and will implement automatic
> solution. But I don't promise.

Thing is, we're not exporting a union. We're exporting the *members*
of a union. Boost.Python does not need to know that the members refer
to the same memory space - it just needs to know they are there like
any other normal members of a struct.

Worst case scenario - let pyplusplus only support accessing the first
member of a union only.

> Second and I think very important problem is unnamed structs within union.
> In order to export bit fields pyplusplus creates wrapper that will
> expose set\get
> properties to the fields. In this case it do generates invalid code, because of
> unnamed struct.
>
> What do you propose?

pyplusplus should specifically filter out any unnamed structs it
encounters and pretend they're not there. This will generate correct
code.

Cheers,
Niall



_______________________________________________
C++-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/c++-sig
Reply | Threaded
Open this post in threaded view
|

Re: [C++-sig] pyplusplus is alive :-)

Roman Yakovenko
On 3/31/06, Niall Douglas <[hidden email]> wrote:

> On 29 Mar 2006 at 23:55, Roman Yakovenko wrote:
>
> > Problem number 1. pyplusplus generates invalid code mainly because of
> > unions that have unnamed struct inside.
> >
> >       struct FXAPI Header
> >       {
> >               FXuint length;
> >               char guid[16];
> >               union Flags
> >               {
> >                       struct
> >                       {
> >                               FXuint hasItemIdList : 1;
> >                               FXuint pointsToFileOrDir : 1;
> >                               FXuint hasDescription : 1;
> >                                 ...
> >                       };
> >                       FXuint raw;
> >               } flags;
> >     }
> >
> > I am almost sure, that it can not be exported to Python.
> > First of all I am not sure how I should export unions? What do you
> > expect to get?
>
> The above is simply a technique for mapping bits to the same place as
> an int. Unnamed structs simply push their members into the enclosing
> namespace, therefore you'd access the above as
> header.flags.pointsToFileOrDir. Right now, pyplusplus is putting a
> $_x after flags because gccxml gives unnamed structs an internal
> name. To generate correct code, all pyplusplus needs to do is ignore
> any unnamed structs it sees.
>
> > According to this http://lists.boost.org/Archives/boost/2002/11/39157.php
> > it will not be supported.
> >
> > So I propose you to change union to struct, or to write some hand written code
> > that will export it. May be I could learn from it and will implement automatic
> > solution. But I don't promise.
>
> Thing is, we're not exporting a union. We're exporting the *members*
> of a union. Boost.Python does not need to know that the members refer
> to the same memory space - it just needs to know they are there like
> any other normal members of a struct.
>
> Worst case scenario - let pyplusplus only support accessing the first
> member of a union only.
>
> > Second and I think very important problem is unnamed structs within union.
> > In order to export bit fields pyplusplus creates wrapper that will
> > expose set\get
> > properties to the fields. In this case it do generates invalid code, because of
> > unnamed struct.
> >
> > What do you propose?
>
> pyplusplus should specifically filter out any unnamed structs it
> encounters and pretend they're not there. This will generate correct
> code.

Niall,  can you switch your code from union to struct and to named struct?
It is really a difficult situation to handle from code generator. If
you can not, then
I prefer to create hand written code that will expose FXWinShellLink class.
An other thought is that Python already has PyWin32 and os packages to deal
with paths. May be we should just skip this class?

> Cheers,
> Niall


--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
_______________________________________________
C++-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/c++-sig
Reply | Threaded
Open this post in threaded view
|

Re: [C++-sig] pyplusplus is alive :-)

Niall Douglas
On 31 Mar 2006 at 22:38, Roman Yakovenko wrote:

> Niall,  can you switch your code from union to struct and to named struct?
> It is really a difficult situation to handle from code generator. If
> you can not, then
> I prefer to create hand written code that will expose FXWinShellLink class.

I can't really change it as it breaks the code.

> An other thought is that Python already has PyWin32 and os packages to deal
> with paths. May be we should just skip this class?

Well, to my knowledge, FXWinShellLink is the ONLY portable Windows
shell link implementation anywhere in the world. It lets Linux and
FreeBSD work directly with windows shell link files which is really
very handy seeing as Windows doesn't have proper symbolic link
support. Python has no such support.

However, you're right that it's not essential. However, that specific
idiom of combining an unnamed bitfield struct with an integer
counterpart will surely come up again in the future.

Cheers,
Niall



_______________________________________________
C++-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/c++-sig
Reply | Threaded
Open this post in threaded view
|

Re: [C++-sig] pyplusplus is alive :-)

Roman Yakovenko
On 3/31/06, Niall Douglas <[hidden email]> wrote:
> On 31 Mar 2006 at 22:38, Roman Yakovenko wrote:
>
> > Niall,  can you switch your code from union to struct and to named struct?
> > It is really a difficult situation to handle from code generator. If
> > you can not, then
> > I prefer to create hand written code that will expose FXWinShellLink class.
>
> I can't really change it as it breaks the code.

I understand.

> > An other thought is that Python already has PyWin32 and os packages to deal
> > with paths. May be we should just skip this class?
>
> Well, to my knowledge, FXWinShellLink is the ONLY portable Windows
> shell link implementation anywhere in the world. It lets Linux and
> FreeBSD work directly with windows shell link files which is really
> very handy seeing as Windows doesn't have proper symbolic link
> support. Python has no such support.
>
> However, you're right that it's not essential. However, that specific
> idiom of combining an unnamed bitfield struct with an integer
> counterpart will surely come up again in the future.

I don't say no, I just prefer to concentrate on bug fixes. Lets skip this.
I will add it to my todo list.


> Cheers,
> Niall
>


--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
_______________________________________________
C++-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/c++-sig