Finding module names to call libc functions using FFI
Alexander Lazarević
Alexander at lazarevic.de
Fri Mar 4 11:44:16 UTC 2005
I did run into this a while ago and I don't have a perfect solution, but
to be "smart" about the possible names. The following is in the
ExternalWebbrowser package and shameless copy of the concept I found for
the OpenGL library in croquet.
ExternalWebBrowserUnix>>system: string
"system() executes a command specified in string by calling /bin/sh -c
string, and returns after the command has been completed."
<apicall: short 'system' (char*) module: 'c'>
^self externalCallFailed
On system startup this method gets executed
ExternalWebBrowserUnix class>>isCLibAvailable
| moduleNames index |
moduleNames _ #('c' 'libc.so.6'). "standard, debian"
index _ 1.
[^(self new system: nil) ~= 0] on: Error do: [:ex |
index <= moduleNames size ifTrue: [
((ExternalWebBrowserUnix compiledMethodAt: #system:) literalAt: 1)
setModule: (moduleNames at: index).
index _ index + 1.
ex retry].
^false]
Alex
Ned Konz schrieb:
> I've made UnixShell as a subclass of ExternalObject.
>
> It has one method:
>
> system: aString
> <cdecl: long 'system' (char *) module: 'c.so.6'>
> ^self externalCallFailed.
>
>
> This works fine. HOWEVER... note the 'c.so.6'. This refers to /lib/libc.so.6,
> which is a symlink to another .so file in /lib. These arguments work fine
> too:
>
> 'libc.so.6'
> '/lib/libc.so.6'
>
> But I'd really like to use just 'c' or 'libc' instead, because (obviously) the
> version of the .so file on my system may not be the named the same as yours.
>
> I have also tried (without success):
> * using '' as a module name (hoping to get the version linked into my Squeak
> executable, if any)
> * using the full name of my Squeak VM
> * making an ExternalLibraryFunction with a nil module
>
> Does anyone know a more universal way to get this information? Lookup table
> keyed by platform name (ick)?
>
> Thanks,
More information about the Squeak-dev
mailing list
|