[Python-Dev] ANN: Pyrex - a language for writing Python extension modules

Greg Ewing greg@cosc.canterbury.ac.nz
Tue, 09 Apr 2002 13:45:54 +1200 (NZST)

Kevin Butler <kbutler@campuspipeline.com>:

> 1- Any chance of having "typecast" spelled as one of:
> 	char*(value)		#consistent w/ Python
> 	(char *)value		#consistent w/ C
> 	cdef char*(value)	#cdef + Python
> 	(cdef char *)value	#cdef + C
> 	cdef(char*, value)	#umm. Maybe easier for parsing?

Probably not. I don't like the idea of overloading "cdef"
that way, and the others are too hard to parse. Besides,
I think it's a feature that typecasts look ugly. :-)

If it helps, I have some features planned that will make
it unnecessary to call malloc explicitly in most cases,
which should remove a large source of the need for

> I think parsing C (& especially C++!) headers is likely to bring in
> more headaches than it is worth. How deeply do you want to get into
> macros, typedefs, other extern declarations, etc.?

In the case of plain C, most of the machinery needed to parse and
understand anything likely to be found in a .h is already there.
Macros could be a problem, though. And I don't even want to think
about C++ yet.

>	cdef extern class Grail:
>	    # all members implicity "cdef extern"
>	    int age
>	    float volume
>	    # To self or not to self?
>	    # Let declarations be consistent w/ C++?
>	    def __init__( int age, float volume )
>	    def float quaff( float amount )

That will probably be

  cdef extern struct Grail:
    int age
    float volume
    Grail(int age, float volume)
    float quaff(float amount)

i.e. C++ style constructor declaration, no self, and no def (which
is reserved for declaring Python functions). Also "cdef struct",
because "cdef class" will mean something different (that's how
extension types will be defined).

> (Next, I'll hit you up for exceptions and default args, then
> overloading, then templates & RTTI... )

Oh, no... please... no... :-)

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