Jump to content

Call a function in a shared library: Difference between revisions

→‎Call uname on Linux: Explain with-dyn-lib.
(→‎Call uname on Linux: Explain with-dyn-lib.)
Line 1,404:
 
The argument of <code>uname</code> is <code>(ptr-out utsname)</code>. The semantics of <code>ptr-out</code> in this situation is that FFI prepares a C version of the Lisp structure, but doesn't perform any conversions from Lisp to initialize it. This not only saves CPU cycles, but allows us to use a blank structure produced by <code>(new utsname)</code> all of whose slots are <code>nil</code> and so wouldn't convert to C character arrays anyway! The function is called, and then conversions out of the structure to the Lisp structure take place, filling its slots with string values.
 
The <code>nil</code> argument in the <code>with-dyn-lib</code> macro causes the underlying implementation to call <code>dlopen(NULL)</code> to get access to the dynamic symbols available in the executable. We can use the name of a shared library instead, or a handle from TXR's <code>dlopen</code> library function.
 
=={{header|Ursala}}==
543

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.