D struct with String type accessing from Python
alchemypy
me at alchemypy.com
Mon Dec 26 03:05:33 UTC 2022
Hi Everyone, I am new to Dlang and i am trying to consume .so
(Dlang based dynamic library) from Python.
My D program has something like below,
struct gph
{
string x;
}
struct myStruct
{
pragma(mangle, "Print_gph")
void Print_gph(gph g)
{
stderr.writeln("here: gph ");
stderr.writeln(g.x);
}
}
i have created a .so for the same and my Python code looks as
follows:
from ctypes import *
class gph(Structure):
_fields_ = (
('x_p', c_char_p),
('x_len', c_size_t)
)
def __init__(self, x):
self.x_p = x
self.x_len = len(x)
so_path = "./test.so"
lib = CDLL(so_path)
sample_struct = gph(b'gph')
lib.SubOcc_gph(c_void_p(),sample_struct)
When i executed i got bellow error,
here: gph
src/rt/dwarfeh.d:330: uncaught exception reached top of stack
This might happen if you're missing a top level catch in your
fiber or signal handler
std.exception.ErrnoException@/usr/include/dmd/phobos/std/stdio.d(3170): Enforcement failed (Bad address)
Aborted
Can you please help me what went wrong here ?
More information about the Digitalmars-d
mailing list