Stefan Behnel wrote:
> Dag Sverre Seljebotn wrote:
>   
>> 1) A "fortran" calling convention on external function declarations, and
>> perhaps a "module"/"namespace" declaration (which one could reuse for
>> C++):
>>
>> cdef extern:
>>     module mymodule: # reusable for C++ wrapping, could say "namespace"
>> instead
>>         cdef fortran sometype myfunc(sometype arg)
>>     
>
> Fine with me. What about
>
>     cdef extern from "myheader.h":
>
> for C and
>
>     cdef extern from module "mymodule":
>
> for Fortran and
>
>     cdef extern from namespace "mynamespace":
>
> for C++, which would automatically enable C, C++ and Fortran conventions
> for their body? (i.e. without a "fortran" or "module" keyword).
>   
Comments: I like the explicitness of the "fortran" keyword, and C++ 
requires a header file to be included as well as a namespace.

>> When "fortran" is in effect, one may accept some extra syntax for the
>> arguments, i.e. "in" or "inout" (but "const" and no const could serve
>> the same purpose).
>>     
>
> I'm for using in/inout (maybe as a Py3 annotation or whatever) rather than
> overloading "const".
>   
Actually, I slipped here. Pointers would be "inout", i.e.

cdef fortran void myfunc(int* foo) # foo is inout argument

I would *not* like to have Cython code where "myfunc(x)" can change the 
value of x :-)

But for array/buffer arguments, "in"/"out"/"inout" would be nice to have.

>> Implementation-wise, there would be a transform which would deal with
>> calls to functions using the Fortran calling convention, and generates a
>> mymodule.f90 wrapper to supplement mymodule.c -- however this is a very
>> thin wrapper to retype the Fortran functions from Fortran-side to use
>> some C conventions and some Cython-specific conventions, and most of the
>> things would be C-side.
>>     
>
> Wouldn't the external .pxd generator tool be the right place to also
> generate the .f90 wrapper? I don't see Cython generate a Fortran module
> while compiling a Cython module to C code that *calls* the module.
>   
I was hoping to do this without ever touching Fortran parsing at first, 
the way one does it with wrapping C. This would loose the possibility of 
working from a manually written pxd at first.

Also the f90 wrapper would insert Cython-specific structs in the call 
signature to marshal PEP-3118 buffers across. So it doesn't seem to make 
so much sense to decouple the two (from an end-user perspective), though 
it could certainly be done that way.

> Maybe a second backend to F2Py would do the trick already?
>   
F2py does the parsing-from-Fortran-source stuff, but that is not at all 
the focus here. Whatever happens, noone will rewrite a Fortran parser :-)

Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to