Fortran-compiled DLLs in Python

byte biscuit stephen.mcphail at casaccia.enea.it
Fri May 28 06:06:33 EDT 2004


I feel we're getting there...

recapitulating:
>>> from ctypes import *
>>> h2o = windll.H2O             # loads DLL in python
>>> tt=c_double(20.)                # tt, pp and state are inputs, given
values in C datatypes
>>> pp=c_double(1.0)
>>> state=c_int(1)
>>> dierr = c_int()                       #dierr, sig and prop are outputs,
initialised in C datatypes
>>> sig = c_double()
>>> prop = (c_double * 16)()     # create a 16 element double array

access violation error:

>>> h2o.WATER(tt, pp, state, byref(dierr), byref(sig), prop)
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
WindowsError: exception: access violation

which in fact - Dennis - is caused by non-referencing, because:

>>> h2o.WATER(byref(tt), byref(pp), byref(state), byref(dierr), byref(sig),
prop)
returns without error.

It is interesting (for me, that is) to note that prop in fact does NOT need
referencing, whereas all other variables (input&output) DO. But, the
returned answer is:

0

which shouldn't be of course............... so there does seem to be a
problem in the definition/passing of the prop parameter, I would say?

stephen


"Thomas Heller" <theller at python.net> ha scritto nel messaggio
news:mailman.362.1085666603.6949.python-list at python.org...
> >
>
> This is the classical GP fault, which would normally crash a program.
> ctypes catches it, but doesn't give more information (in current CVS, it
> would have informed you about which memory location could not be written
> or read, but that would probably not help you very much).
>
> > - Prop (datatype: double precision array[16 elements])   [output]
>
> I do not know how fortran passes this parameter, in the example code I
> posted I assumed that the caller allocates an array, passes a pointer to
> it to fortran, and the fortran code fills in the elements.
>
> Do you have C sample code that works?
>
> Thomas
>
"Dennis Lee Bieber" <wlfraed at ix.netcom.com> ha scritto nel messaggio
news:p00cb0hvqdj9u9ar7jddgr9qcpnra8im6k at 4ax.com...

> C passes by value, and to get a "modifiable" argument, the
programmer has to explicitly pass an address (as the value) and then,
also, explicitly dereference through the value.

Traditionally, FORTRAN passes ALL arguments by address, not
value. This may vary a bit in more modern implementations -- character
strings may pass a "string descriptor", which is a structure containing
the address of the string (as normal) along with an added word
containing the size of the space allocated for the string.

I suspect you need to use byref() on all of the arguments.

-- 
 > ============================================================== <
 >   wlfraed at ix.netcom.com  | Wulfraed  Dennis Lee Bieber  KD6MOG <
 >      wulfraed at dm.net     |       Bestiaria Support Staff       <
 > ============================================================== <
 >           Home Page: <http://www.dm.net/~wulfraed/>            <
 >        Overflow Page: <http://wlfraed.home.netcom.com/>        <





More information about the Python-list mailing list