Warning: This is the manual of the legacy Guile 2.0 series. You may want to read the manual of the current stable series instead.
Next: Void Pointers and Byte Access, Previous: Foreign Types, Up: Foreign Pointers [Contents][Index]
Pointers to variables in the current address space may be looked up
dynamically using dynamic-pointer
.
Return a “wrapped pointer” for the symbol name in the shared object referred to by dobj. The returned pointer points to a C object.
Regardless whether your C compiler prepends an underscore ‘_’ to the global names in a program, you should not include this underscore in name since it will be added automatically when necessary.
For example, currently Guile has a variable, scm_numptob
, as part
of its API. It is declared as a C long
. So, to create a handle
pointing to that foreign value, we do:
(use-modules (system foreign)) (define numptob (dynamic-pointer "scm_numptob" (dynamic-link))) numptob ⇒ #<pointer 0x7fb35b1b4688>
(The next section discusses ways to dereference pointers.)
A value returned by dynamic-pointer
is a Scheme wrapper for a C
pointer.
Return the numerical value of pointer.
(pointer-address numptob) ⇒ 139984413364296 ; YMMV
Return a foreign pointer object pointing to address. If finalizer is passed, it should be a pointer to a one-argument C function that will be called when the pointer object becomes unreachable.
Return #t
if obj is a pointer object, #f
otherwise.
A foreign pointer whose value is 0.
Return #t
if pointer is the null pointer, #f
otherwise.
For the purpose of passing SCM values directly to foreign functions, and allowing them to return SCM values, Guile also supports some unsafe casting operators.
Return a foreign pointer object with the object-address
of scm.
Unsafely cast pointer to a Scheme object. Cross your fingers!
Sometimes you want to give C extensions access to the dynamic FFI. At
that point, the names get confusing, because “pointer” can refer to a
SCM
object that wraps a pointer, or to a void*
value. We
will try to use “pointer object” to refer to Scheme objects, and
“pointer value” to refer to void *
values.
Create a pointer object from a pointer value.
If finalizer is non-null, Guile arranges to call it on the pointer value at some point after the pointer object becomes collectable.
Unpack the pointer value from a pointer object.
Next: Void Pointers and Byte Access, Previous: Foreign Types, Up: Foreign Pointers [Contents][Index]