Hello,
I have gotten pretty comfortable using FFI to access external libraries from squeak, but have hit a seemingly simple snag: I want to access some constant structures defined in my external lib. If there was a function that returned them, it would be no problem, but I don't see any obvious way to directly access them. Are my only options 1) enhance the external lib to make constants accessible via functions; 2) abandon FFI for a plugin approach ? The constants are defined in the library like: extern const stuctType *constantName; best, Jim M |
Jim McLoughlin wrote:
> I want to access some constant structures defined in my external lib. > If there was a function that returned them, it would be no problem, > but I don't see any obvious way to directly access them. Unfortunately, there isn't. The FFI doesn't expose the direct equivalent of dlsym() but only uses it implicitly when invoking an FFI call. I guess this should be considered a bug... Cheers, - Andreas |
Ah, of course obviously if there is some way to expose the value via
a library call, you could do that in FFI. Like use dlsym() to get the address of the constant, then memcpy to a squeak external data object.... On Feb 13, 2007, at 1:34 PM, Andreas Raab wrote: > Jim McLoughlin wrote: >> I want to access some constant structures defined in my external lib. >> If there was a function that returned them, it would be no problem, >> but I don't see any obvious way to directly access them. > > Unfortunately, there isn't. The FFI doesn't expose the direct > equivalent of dlsym() but only uses it implicitly when invoking an > FFI call. I guess this should be considered a bug... > > Cheers, > - Andreas > -- ======================================================================== === John M. McIntosh <[hidden email]> Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com ======================================================================== === |
John M McIntosh wrote:
> Ah, of course obviously if there is some way to expose the value via a > library call, you could do that in FFI. > Like use dlsym() to get the address of the constant, then memcpy to a > squeak external data object.... Good point! Of course, you can just use FFI to access dlopen(), dlsym() and friends and then construct the appropriate handle from it. It's a little bit awkward and I don't know if that works correctly on all platforms (e.g. whether the system will use the already mapped shared library or actually map a new one) but if you're really desperate this is definitely worth trying. Cheers, - Andreas > > > On Feb 13, 2007, at 1:34 PM, Andreas Raab wrote: > >> Jim McLoughlin wrote: >>> I want to access some constant structures defined in my external lib. >>> If there was a function that returned them, it would be no problem, >>> but I don't see any obvious way to directly access them. >> >> Unfortunately, there isn't. The FFI doesn't expose the direct >> equivalent of dlsym() but only uses it implicitly when invoking an FFI >> call. I guess this should be considered a bug... >> >> Cheers, >> - Andreas >> > > -- > =========================================================================== > John M. McIntosh <[hidden email]> > Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com > =========================================================================== > > > > |
I am on OSX - I used ffi calls to dlopen(), dlsym() in
module:System.framework and it worked like a charm. Many thanks. Jim M On 2/13/07, Andreas Raab <[hidden email]> wrote: > John M McIntosh wrote: > > Ah, of course obviously if there is some way to expose the value via a > > library call, you could do that in FFI. > > Like use dlsym() to get the address of the constant, then memcpy to a > > squeak external data object.... > > Good point! Of course, you can just use FFI to access dlopen(), dlsym() > and friends and then construct the appropriate handle from it. It's a > little bit awkward and I don't know if that works correctly on all > platforms (e.g. whether the system will use the already mapped shared > library or actually map a new one) but if you're really desperate this > is definitely worth trying. > > Cheers, > - Andreas |
Free forum by Nabble | Edit this page |