mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-18 17:50:29 +02:00
Change `dynamic-link' to return a global handle when the argument is omitted.
* libguile/dynl.c (sysdep_dynl_link): Handle FNAME == NULL. (scm_dynamic_link): Make argument optional. Adjust body accordingly. * test-suite/standalone/test-ffi (global, strerror, strlen): New bindings. Add test for these bindings. * doc/ref/api-modules.texi (Low level dynamic linking): Update description of `dynamic-link'.
This commit is contained in:
parent
dd1464bf38
commit
d12f974b43
3 changed files with 61 additions and 9 deletions
|
@ -168,6 +168,31 @@ exec guile -q -s "$0" "$@"
|
|||
'(0 1 2 3 4 5 6 7 0 0 0 0 0 0 0 0))
|
||||
(error "unexpected dest")))
|
||||
|
||||
|
||||
;;;
|
||||
;;; Global symbols.
|
||||
;;;
|
||||
|
||||
(use-modules ((rnrs bytevector) #:select (utf8->string)))
|
||||
|
||||
(if (defined? 'setlocale)
|
||||
(setlocale LC_ALL "C"))
|
||||
|
||||
(define global (dynamic-link))
|
||||
|
||||
(define strerror
|
||||
(make-foreign-function '* (dynamic-func "strerror" global)
|
||||
(list int)))
|
||||
|
||||
(define strlen
|
||||
(make-foreign-function size_t (dynamic-func "strlen" global)
|
||||
(list '*)))
|
||||
|
||||
(let* ((ptr (strerror ENOENT))
|
||||
(len (strlen ptr))
|
||||
(bv (foreign->bytevector ptr 'u8 0 len))
|
||||
(str (utf8->string bv)))
|
||||
(test #t (not (not (string-contains str "file")))))
|
||||
|
||||
;; Local Variables:
|
||||
;; mode: scheme
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue