[f2py] Resend: Threading and Wrapping C-code with f2py

Pearu Peterson pearu@cens.ioc.ee
Wed, 29 Aug 2001 14:53:24 +0200 (EET)


Hi Travis,

On Wed, 29 Aug 2001, Travis Oliphant wrote:

> 
> ***I'm resending this message because I did not get it back from the list.  
> If you see this twice I apologize.***

I hope you got it this time. There was some bouncing regarding to your
first message. Hopefully this problem has gone away.

> Some questions:
> 
> 1.  Threading:
> 
> Would it be possible to add to f2py a directive indicating that a wrapped
> module is thread-safe.  This directive would instruct f2py to insert
> 
> Py_BEGIN_ALLOW_THREADS
>   function call
> Py_END_ALLOW_THREADS
> 

Sure. (This feature has been requested also earlier)
Easiest way would be to introduce a command line flag,
eg. --with-threads. Though the users may want only some routines to be
thread safe. So, a new directive needs to be introduced anyway.


> 2. Calling C-libraries.
> 
> For simple C-libraries it is possible to use f2py.  However, this seems to
> only work if all of the arguments to the C-function are pointers.
> 
> Is there any way to add to f2py a directive that instructs f2py to build a
> module that is intended to call a C-library, so that scalar arguments are
> passed directly by value in the function call.

How badly is this feature required? How often it would be used?
I am working with the 3rd edition of f2py where a bit clearer structure of
f2py internals is planned.
I am thinking of a program - c2py - that would, similarly to f2py,
generate wrappers for C codes. I guess it would not be a big project as
most of the f2py code could be reused.


> 3. Using a different Python name.
> 
> This has been discussed on this list before.  But, it would be really useful
> to be able to rename the Python-determined function.  There are many ways to
> do this but it would be useful if some meaningful directive were added to the
> CrackFortran code.

Yes. It is often requested feature. Any suggestions about what directives
could be used in pyf files?
THough this feature should go into f2py3e (unless it is easy to implement 
for f2py2e - I have not tried yet)



 
> 
> 4.  f2py directives
> 
> I noticed that there is some support in crackfortran for f2py directives.
> When are these used currently.  I've been assuming that some of the requested
> features could be inserted as f2py directives, but perhaps I misunderstand
> their use.

The idea is very simple: if the Fortran compiler reads line starting with
'Cf2py', it ignores it (obviously); if f2py reads that line, then it
replaces 'Cf2py' with 5 spaces and proceedes with that line as ordinary
Fortran line.

So, you are absolutely right about the usage of new f2py directives.

Note that I am away from my computer for the next three weeks so that I
could not impement any above. However, I still can read E-mails;-)

Regards,
	Pearu