-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Runtime Error when use shared lib in python #185
Comments
It's a little difficult to tell exactly what's happening from the screencaps, but I would be very surprised for this to work without more explicit type annotations. The Go types of the arguments and results are generated as structures, and the FFI library is unlikely to map correctly from I was able to make the following work as of f28fc12. Setup: git clone [email protected]:src-d/enry.git
cd enry
go generate
go build -buildmode=c-shared -o enry.so shared/enry.go Test: import ctypes
lib = ctypes.CDLL('enry.so')
with file('common.go', 'rb') as fp:
data = fp.read()
class GoString (ctypes.Structure):
_fields_ = [
('p', ctypes.c_char_p),
('n', ctypes.c_long),
]
class GoSlice (ctypes.Structure):
_fields_ = [
('data', ctypes.c_char_p),
('len', ctypes.c_int64),
('cap', ctypes.c_int64),
]
lib.GetLanguage.argtypes = (GoString, GoSlice)
lib.GetLanguage.restype = GoString
def GetLanguage(path, data):
s = GoString(p=path, n=len(path))
d = GoSlice(data=data, len=len(data), cap=len(data))
res = lib.GetLanguage(s, d)
if res.p is not None:
return res.p[:res.n]
print GetLanguage('common.go', data) I implemented the type wrappers by hand based on inspection of |
I think @creachadair is right. And we have #154 open for a Adding CFFI-based python bindings for Enry, that I'm also hoping to find some time soon to grapple with. |
If no objections, going to close this as the question seems to be answered, further work on bindings is planned and there is no further discussion. |
Hey Guys,
I got error when using enry as shared lib in python, it looks like below:
here is the way i built it:
here is the way i used it:
even tried in cffi:
can anyone tell me what't wrong?
thx...
The text was updated successfully, but these errors were encountered: