[Pyrex] Just some thoughts

Josiah Carlson jcarlson at uci.edu
Tue Apr 18 21:41:46 CEST 2006


Tomasz Primke <tprimke at interia.pl> wrote:
> 1) The syntax of integer-loops: I find it too long. In my opinion, instead 
> of writing:
> 
> for i from lower_bound <= i < upper_bound:
>   ...
> 
> it would be better (and easier, faster, more convenient) to write just:
> 
> for i from lower_bound <= upper_bound:
>   ...

Your proposed syntax is crap.  It doesn't explicitly relate lower_bound,
i, and upper_bound (which could cause confusion for learning, reading,
etc.). A better syntax that avoids the same double-typing is...

    for lower_bound <= i < upper_bound:

Overall, I wouldn't care if it was changed.  It's a minor annoyance, far
less annoying than 


> 2) I think that Pyrex should offer some low-level memory managment routines. 
> I think of sizeof operator, as well as the C standard *alloc and free 
> functions. It would be also nice to have something like the g_new macro 
> known from the GLib library.

I disagree.  Pyrex is not C.  If you want the memory management
capabilities of C, write interfaces in C, and use it in Pyrex.  As for
g_new, it's glibc only, and/or your own simple macro redefinition, etc. 
Further, you can gain access to all of your desired C-level macros via a
macro and extern (though g_new doesn't look usable via extern).

#define g_new(n_count, n_type) malloc(n_count*sizeof(n_type))
#define _alloc(x) malloc(x)
#define _free(x) free(x)

cdef extern from "cstuff.c":
    void* _alloc(unsigned long)
    void _free(void*)


>   But another way to gain some speed is to code some low-level memory
>   management. There are, for example, some "array" routines available in
>   SWIG, that make developer's life much easier. In Pyrex developer has to
>   code them for himself (herself). Therefore I think that such a low-level
>   routines (perhaps even some array routines?) would be a great
>   improvement.

Which specific array rutines do you like in SWIG?


> 3) It would be great to have some easy way to auto-create Python wrappers 
> for chosen C functions and/or methods.
> 
> cdef void some_c_func( ... ):
>   ...
> 
> def python_func( ... ):
>   some_c_func( ... )
> 
>   I think it would be easier to achieve the same functionality with some
>   simpler syntax, like:
> 
> cpdef void some_c_func( ... ):
>   ...

In the majority of cases where I have found myself writing cdefs and def
wrappers, I need to do data manipulation and translation for subsequent
cdef calls.  For me, it is because I pass various string-like objects to
Pyrex/C, which are then translated into char* via the Python buffer
interface. I think cpdef would be a useful addition, but not compelling.

 - Josiah




More information about the Pyrex mailing list