[Pyrex] newby guidance

Greg Ewing greg at cosc.canterbury.ac.nz
Thu Jun 26 04:17:58 CEST 2003


John J Lee <jjl at pobox.com>:

> I *think* you can use Pyrex extension types to wrap structs without
> explicitly declaring the struct members, but in my experiment I ran into
> trouble zero-initialising whole structs as you would in C with the {}
> aggregate-initialisation syntax.

That's probably more to do with the fact that Pyrex currently doesn't
*have* an aggregate-initialisation syntax!

>    def __new__(self, *args, **kwargs):
>        # XXX casting to TidyBuffer here causes C compile error -- is this a
>        #   bug (shouldn't Pyrex spot the error, not leave it to the C
>        #   compiler)?
>##         self.buf = 0

That would never have worked, even in C, and even with a cast.

>        self.buf.bp = NULL
>        self.buf.size = 0
>        self.buf.allocated = 0
>        self.buf.next = 0

What you could perhaps have done instead is

         memset(&self.buf, 0, sizeof(TidyBuffer))

although that assumes that a null pointer has a bit pattern of 0 on
your platform, which is not guaranteed, so for strict portability you
have to initialise things individually anyway.

> I may as well ask about the XXX there too -- is it always regarded as a
> bug if Pyrex doesn't report an error but the C compiler does?  Or is
> casting (for example) at one's own risk even at Pyrex-compile time?

It's pretty much at your own risk. It's not possible for Pyrex to
check this any better, since it can't be sure of the sizes of things
as seen by the C compiler.

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg at cosc.canterbury.ac.nz	   +--------------------------------------+




More information about the Pyrex mailing list