[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
6.20.5.2 Foreign Variables
Pointers to variables in the current address space may be looked up
dynamically using dynamic-pointer
.
- Scheme Procedure: dynamic-pointer name dobj
- C Function: scm_dynamic_pointer (name, dobj)
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.
- Scheme Procedure: pointer-address pointer
- C Function: scm_pointer_address pointer
Return the numerical value of pointer.
(pointer-address numptob) ⇒ 139984413364296 ; YMMV
- Scheme Procedure: make-pointer address [finalizer]
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.
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.
- Scheme Procedure: pointer->scm pointer
Unsafely cast pointer to a Scheme object. Cross your fingers!
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on February 3, 2012 using texi2html 5.0.