Python Forum
Trying to debug segfault in ctypes binding to Fortran
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to debug segfault in ctypes binding to Fortran
#2
Finally got it working. The code below worked.

import ctypes as ct

flib = ct.CDLL('euler.so')
ode_spec = ct.CFUNCTYPE(None, ct.POINTER(ct.c_int), ct.POINTER(ct.c_float), ct.POINTER(ct.c_float * 1), ct.POINTER(ct.c_float * 1))

flib.euler_.restype = None
flib.euler_.argtypes = [
    ode_spec,
    ct.POINTER(ct.c_int),
    ct.POINTER(ct.c_float * 1),
    ct.POINTER(ct.c_float),
    ct.POINTER(ct.c_float),
    ct.POINTER(ct.c_float)
]

@ode_spec
def df(neq, t, y, dy):
    dy[0] = y[0]
    return

t = ct.c_float(0.1)
to = ct.c_float(0.2)
neq = ct.c_int(1)
relarr = ct.c_float * 1
y = relarr()
y[0] = 0.1
h = ct.c_float(0.001)
flib.euler_(df, ct.byref(neq) , ct.byref(y), ct.byref(t), ct.byref(to), ct.byref(h))
jefsummers likes this post
Reply


Messages In This Thread
RE: Trying to debug segfault in ctypes binding to Fortran - by bthomas - Sep-01-2023, 11:26 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  no debug messages going into log file robertkwild 0 527 Jul-09-2024, 05:30 PM
Last Post: robertkwild
  using ctypes to use a dll in a python module dauriac 3 2,948 Mar-06-2024, 04:38 PM
Last Post: dauriac
  Exponeniation and Right Binding PhDoctus 3 3,250 Feb-15-2024, 07:09 AM
Last Post: Gribouillis
  ctypes juliolop 7 2,763 Apr-20-2023, 03:33 PM
Last Post: Larz60+
  pycharm debug help mg24 1 1,690 Nov-18-2022, 05:38 AM
Last Post: deanhystad
  Python debug suddenly got bad ben1122 3 1,796 Sep-03-2022, 06:20 AM
Last Post: ben1122
  Issue while using ctypes in python GiggsB 6 5,357 Mar-27-2022, 03:38 AM
Last Post: GiggsB
  Ctypes and libffi.so.7 luxedo 1 7,373 Oct-23-2021, 09:24 PM
Last Post: DeaD_EyE
Bug Help Debug please jamesaarr 12 5,849 Jul-28-2021, 11:20 PM
Last Post: Pedroski55
  Binding Complex data to Combobox gcfernando 2 2,834 Sep-14-2020, 03:24 PM
Last Post: gcfernando

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020