Re: Attempting to subscript an atom Error[SOLVED]
- Posted by ghaberek (admin) Oct 17, 2022
- 610 views
Thank you Pete. I forgot to add .dll when loading the library and the first function was missing the "+". The primitive demo now works.
Sorry I had a busy weekend so I wasn't able to reply in time. The problem here is simply that define_c_func() is returning -1 because it could not find the function name, and c_func() isn't checking the function ID correctly. I will get some more error-checking added soon to help with this.
Could it be that you don't want the + at all, or (less likely) the first is missing a +?
FYI for anyone reading along, and I'll make sure the documentation reflects this as well, the indication of STDCALL (no plus) or CDECL (with plus) calling convention only affects 32-bit Windows and nothing else and I encourage everyone to use 64-bit Euphoria if they are on a 64-bit platform (which they should be) where the plus is silently ignored.
Also, have you checked that none of the xal_init_primitives_addon etc are getting set to -1?
This is the core of the issue. I'm currently using negative function IDs in the wrappers for c_func/proc to avoid collision with the positive function IDs returned by the interpreter's own define_c_func/proc. I just need a few checks in there and then I'll call crash() if the ID is not valid, as the interpreter would do.
You can see the offending code and its lack of error checking here: https://github.com/ghaberek/libffi-euphoria/blob/main/include/std/ffi.e#L900
And open_dll() isn't returning null - in my experience Windows is a bit fussy about not having ".dll" at the end of the name, but that might be a Phix thing.
I'm entertaining the idea of adding some library name guessing features to open_dll(), which would help avoid needing a bunch of ifdef PLATFORM then blocks or having a bunch of failed attempts to load libraries that don't exist.
So for libraries that have a common root name, you'd just call open_dll("foobar") and it would try foobar.dll, libfoobar.so, etc. based on the current platform.
-Greg