1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 11:50:28 +02:00
Commit graph

40 commits

Author SHA1 Message Date
Daniel Llorens
496f69dba2 Support C99 complex types in (system foreign)
* libguile/foreign.h (SCM_FOREIGN_TYPE_COMPLEX_FLOAT,
  SCM_FOREIGN_TYPE_COMPLEX_DOUBLE): New enums.
* module/system/foreign.scm (complex-float, complex-double): Export new types.
  (make-c-struct, parse-c-struct): Support the new types.
* libguile/foreign.c (complex-float, complex-double): Define new types.
  (alignof, sizeof, pack, unpack): Support the new types.
* test-suite/tests/foreign.test: Test.
2021-11-15 11:34:09 +01:00
Arun Isaac
c5f443de79 Fix typos in SRFI docs
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=50127

* doc/ref/api-foreign.texi, doc/ref/srfi-modules.texi: Fix typos.
2021-11-03 12:15:42 +01:00
Mike Gran
5a1e78a278 On Cygwin, 'lib' DLLs use 'cyg' prefix
When using automake and libtool to build DLLs on Cygwin, libtool
will rename libXXX to cygXXX. 'load-foreign-library' should
emulate libltdl behavior and search for DLLs using that convention.

* module/system/foreign-library.scm (lib->cyg): new helper function
  (load-foreign-library): add rename-on-cygwin? option to rename
    libraries using Cygwin semantics
* test-suite/tests/foreign.test: new test section 'lib->cyg'
* doc/ref/api-foreign.text: document new rename-on-cygwin? option
    for load-foreign-library
2021-03-13 09:09:30 -08:00
Andy Wingo
2e26538d6a Replace libltdl with raw dlopen, dlsym
* NEWS: Update.
* am/bootstrap.am (SOURCES):
* module/Makefile.am (SOURCES): Add system/foreign-library.scm.
* configure.ac: Replace ltdl check with -ldl check.
* libguile/dynl.c: Rewrite to just expose core dlopen / dlsym / etc to a
  helper Scheme module.
  (scm_dynamic_link, scm_dynamic_pointer, scm_dynamic_function)
  (scm_dynamic_object_p, scm_dynamic_call): Rewrite in terms of (system
  foreign-library).
* libguile/extensions.c (load_extension): Avoid scm_dynamic_call.
* module/system/foreign-library.scm: New file.
* module/oop/goops.scm (<dynamic-object>): Hackily export
  <foreign-library> instead of a class here.
* doc/ref/api-foreign.texi (Foreign Function Interface): Rewrite to only
  document the new interfaces.  Eventually we will deprecate
  dynamic-link and friends.
* doc/ref/guile.texi (API Reference): Move Foreign Objects after Foreign
  Function Interface.  Seems there should be some closer relationship
  but this will do for now.
* doc/ref/tour.texi (Putting Extensions into Modules):
* doc/ref/libguile-parallel.texi (Parallel Installations): Update for
  rename of Modules and Extensions to Foreign Extensions.
* libguile/deprecated.h:
* libguile/deprecated.c (scm_dynamic_unlink): Deprecate.
* libguile/guile.c: Remove ltdl include.
* test-suite/tests/foreign.test: Update tests to use new API, and update
  error expectations.
2021-02-03 23:02:21 +01:00
Isaac Jurado
bef5e0b393 Interpret dynamic library name as literal file name first.
Fixes <https://bugs.gnu.org/21076>.

* libguile/dynl.c (sysdep_dyn_link): Try plain lt_dlopen first, to
  interpret fname as a literal path.
* doc/ref/api-foreign.texi: Update explanation to describe the new
  behavior.

Co-authored-by: Ludovic Courtès <ludo@gnu.org>
2020-03-22 00:27:12 +01:00
Matt Wette
bb5d316b16 foreign: Add 'uintptr_t' and 'intptr_t'.
* libguile/foreign.c (scm_uintptr_t, scm_intptr_t): New variables.
(scm_init_foreign): Define them.
* module/system/foreign.scm: Export 'intptr_t' and 'uintptr_t'.
* doc/ref/api-foreign.texi (Foreign Types): Document them.

Co-authored-by: Ludovic Courtès <ludo@gnu.org>
2017-11-22 16:33:57 +01:00
Mark H Weaver
d3fcefc3d5
doc: Document 'short' and 'unsigned-short' foreign types.
This is a followup to commit 42f7c01e0a.
Reported by Adriano Peluso <catonano@gmail.com>.

* doc/ref/api-foreign.texi (Foreign Types): Add missing entries for
'short' and 'unsigned-short'.
2017-06-11 22:02:26 -04:00
Mike Gran
4ce31fd387 Can't recursively search DLLs with FFI on Cygwin
* doc/ref/api-foreign.text (dynamic-link): document problems with recursive DLLs.
* test-suite/standalone/test-ffi (global): with Cygwin, dynamic-link C library explicitly
* test-suite/standalone/test-foreign-object-scm (libc-ptr): with Cygwin, link C library explicitly
* test-suite/tests/foreign.test (qsort): with Cygwin, link C library explicitly
2017-03-05 12:45:54 -08:00
Mark H Weaver
a396e14cb1 FFI: Add support for functions that set 'errno'.
Implements wishlist item <https://debbugs.gnu.org/18592>.
Requested by Frank Terbeck <ft@bewatermyfriend.org>.
Based on a proposed patch by Nala Ginrut <nalaginrut@gmail.com>.
Patch ported to 2.2 by Andy Wingo <wingo@pobox.com>.

* libguile/foreign.c (cif_to_procedure): Add 'with_errno' argument.
  If true, truncate result to only one return value.
  (scm_i_foreign_call): Separate the arguments.  Always return errno.
  (pointer_to_procedure): New static function.
  (scm_pointer_to_procedure_with_errno): New C API function, implemented
  in terms of 'pointer_to_procedure'.
  (scm_pointer_to_procedure): Reimplement in terms of
  'pointer_to_procedure', no longer bound to "pointer->procedure".  See
  below.
  (scm_i_pointer_to_procedure): New C function bound to
  "pointer->procedure" which now accepts the optional #:return-errno?
  keyword argument, implemented in terms of 'pointer_to_procedure'.
  (k_return_errno): New keyword #:return-errno?.
* libguile/foreign.h (scm_pointer_to_procedure_with_errno): Add prototype.
* doc/ref/api-foreign.texi (Dynamic FFI): Adjust documentation.
* libguile/vm-engine.c (foreign-call): Return two values.
2016-12-18 23:05:15 +01:00
Ricardo Wurmus
e868fae658 doc: Do not gender the programmer.
* doc/ref/api-foreign.texi: Replace "his" with "their".
* doc/ref/sxml.texi: Likewise.
2016-07-25 11:44:52 +02:00
Mark H Weaver
caa3d99be9 Fix typo in manual.
* doc/ref/api-foreign.texi (Void Pointers and Byte Access):
  (rnrs bytevector) --> (rnrs bytevectors).
2014-02-27 22:26:05 -05:00
Andy Wingo
fb7dd00169 Deprecate general "uniform-vector" interface
* libguile/uniform.h:
* libguile/uniform.c (scm_is_uniform_vector, scm_uniform_vector_p)
  (scm_c_uniform_vector_length, scm_uniform_vector_length)
  (scm_uniform_vector_element_type, scm_uniform_vector_element_size)
  (scm_c_uniform_vector_ref, scm_uniform_vector_ref):
  (scm_c_uniform_vector_set_x, scm_uniform_vector_set_x):
  (scm_uniform_vector_to_list)
  (scm_uniform_vector_elements, scm_uniform_vector_writable_elements):
  Deprecate.  This interface lacked both generality and specificity.
  The general replacement is array-length, array-ref, and friends on the
  scheme side, or the array handle interface on the C side.  On the
  specific side of things, there are the specific bytevector, srfi-4,
  and bitvector interfaces.

* test-suite/tests/arrays.test:
* test-suite/tests/bitvectors.test:
* test-suite/tests/ports.test:
* test-suite/tests/srfi-4.test: Update to use array interfaces.

* doc/ref/api-foreign.texi (Void Pointers and Byte Access):
* doc/ref/srfi-modules.texi (SRFI-4): Update.
2014-02-08 14:28:07 +01:00
Daniel Hartwig
5ad85ba15f update old references in FFI doc
* doc/ref/api-foreign.texi (Foreign Types): Replace references to the
  old foreign->bytevector and bytevector->foreign with the new procedure
  names using pointer.
2013-02-14 10:45:27 +01:00
Mark H Weaver
3a3bea729f Add foreign types: ssize_t and ptrdiff_t.
* libguile/foreign.c (sym_ssize_t, sym_ptrdiff_t): New symbols.
  (scm_init_foreign): Add bindings for ssize_t and ptrdiff_t.

* module/system/foreign.scm: Export ssize_t and ptrdiff_t.

* doc/ref/api-foreign.texi (Foreign Types): Add docs.
2013-02-02 04:13:44 -05:00
Andy Wingo
8cdb03c23e fix dynamic-call doc
* doc/ref/api-foreign.texi (Foreign Functions): Fix doc: interrupts are
  not deferred in a dynamic-call.
2013-01-23 09:38:13 +01:00
Andy Wingo
467be245cb add scm_{to,from}_pointer docs
* doc/ref/api-foreign.texi: Add documentation for scm_to_pointer and
  scm_from_pointer.
2012-07-04 17:43:53 +02:00
Mark H Weaver
7cc8ef6235 Fix manual: scm_foreign_to_bytevector to scm_pointer_to_bytevector
* doc/ref/api-foreign.texi (Void Pointers and Byte Access): Fix outdated
  function name: scm_foreign_to_bytevector to scm_pointer_to_bytevector.
2012-02-12 17:05:28 -05:00
Bake Timmons
5f6ffd6652 Improve consistency of definitions of C functions in manual.
* doc/ref/api-compound.texi
* doc/ref/api-evaluation.texi
* doc/ref/api-foreign.texi
* doc/ref/api-io.texi
* doc/ref/posix.texi
* doc/ref/srfi-modules.texi: Add missing parentheses and commas to definitions
  of C functions.

* doc/ref/api-data.texi: Change from @deffn to @deftypefn for C function
  with arguments not of SCM type.
2012-02-04 00:10:14 +01:00
Andy Wingo
0740cb49d1 more documentation on the process of loading source and compiled files
* doc/ref/api-evaluation.texi (Load Paths): Move documentation of
  %load-path and related procedures here, from Build Config.  Add docs
  for %load-compiled-path.

* doc/ref/api-foreign.texi:
* doc/ref/api-modules.texi:
* doc/ref/api-options.texi:
* doc/ref/scheme-using.texi: Update xrefs.
2012-01-27 16:33:11 +01:00
Ludovic Courtès
aed9483ba1 doc: Fix typo in `define-wrapped-pointer-type' example.
* doc/ref/api-foreign.texi (Void Pointers and Byte Access): Fix typo in
  `define-wrapped-pointer-type' example.
2012-01-03 23:31:30 +01:00
Andy Wingo
c6b08d2194 string->pointer and pointer->string have optional encoding arg
* test-suite/tests/foreign.test ("pointer<->string"): Add test cases.

* libguile/foreign.c (scm_string_to_pointer, scm_pointer_to_string): Add
  optional encoding, and in the pointer->string case, length arguments.

* libguile/foreign.h: Update prototypes of internal functions.
  Shouldn't affect ABI as they are internal.

* doc/ref/api-foreign.texi (Void Pointers and Byte Access): Update
  docs.
2011-04-01 13:31:26 +02:00
Andy Wingo
148c331769 add pointer->scm, scm->pointer
* libguile/foreign.c (scm_pointer_to_scm, scm_scm_to_pointer): New
  functions, useful to pass and receive SCM values to and from foreign
  functions.

* module/system/foreign.scm: Export the new functions.

* doc/ref/api-foreign.texi (Foreign Variables): Add docs.

* test-suite/tests/foreign.test ("pointer<->scm"): Tests.
2011-03-17 10:39:02 +01:00
Ludovic Courtès
fba502dbcc Improve the documentation for `dynamic-link'.
* doc/ref/api-foreign.texi (Foreign Libraries): Make it clear that the
  LIBRARY argument of `dynamic-link' should not contain an extension.
  (Foreign Functions): Add cross-reference from `load-extension' to
  `dynamic-link'.  Typeset file names and module names correctly.
2011-03-02 22:12:56 +01:00
Andy Wingo
4b93693dff @value{EFFECTIVE-VERSION} instead of 2.0 in some places in the manual
* doc/ref/history.texi (A Timeline of Selected Guile Releases): Update
  the 2.0 release blurb.

* doc/ref/api-foreign.texi (Modules and Extensions):
* doc/ref/libguile-extensions.texi (A Sample Guile Extension):
* doc/ref/tour.texi (Linking Guile into Programs): Use
  @value{EFFECTIVE-VERSION} instead of 2.0.  Also fix sample extension
  compilation line to include the Guile CFLAGS.
2011-02-20 13:16:37 +01:00
Ludovic Courtès
de6fb1875d Have `define-wrapped-pointer-type' take a type name.
* module/system/foreign.scm (define-wrapped-pointer-type): Add a
  `type-name' argument instead of non-hygienically generating one.

* test-suite/tests/foreign.test (foo): Update.

* doc/ref/api-foreign.texi (Void Pointers and Byte Access): Update
  accordingly.
2011-02-08 22:42:45 +01:00
Ludovic Courtès
6e0975603e Add `pointer?'.
* libguile/foreign.c (scm_pointer_p): New function.
* libguile/foreign.h (scm_pointer_p): New declaration.
* module/system/foreign.scm: Export `pointer?'.

* test-suite/tests/foreign.test ("null pointer")["pointer?"]: New
  test.
  ("make-pointer")["pointer?"]: New test.

* doc/ref/api-foreign.texi (Foreign Variables): Document `pointer?'.
2011-01-30 23:29:30 +01:00
Ludovic Courtès
1f4f7674bc Add `define-wrapped-pointer-type'.
* module/system/foreign.scm (define-wrapped-pointer-type): New macro.

* doc/ref/api-foreign.texi (Foreign Types): Mention the `*' symbol.
  (Void Pointers and Byte Access): Document `define-wrapped-pointer-type'.

* test-suite/tests/foreign.test ("define-wrapped-pointer-type"): New
  test prefix.
2011-01-30 23:29:29 +01:00
Neil Jerram
6887d0a1c6 Manual sections don't need a page break before
* doc/ref/api-coverage.texi (Code Coverage): Remove @page.

* doc/ref/api-foreign.texi (Foreign Function Interface): Ditto.

* doc/ref/api-lalr.texi: (LALR(1) Parsing): Ditto.

* doc/ref/api-macros.texi (Macros): Ditto.
2010-10-31 08:34:05 +00:00
Neil Jerram
0b9bdb1b57 Fix manual typo
* doc/ref/api-foreign.texi: "prodedures" -> "procedures".
2010-10-26 09:11:52 +01:00
Ludovic Courtès
2ee073587a Rename make-foreign-function' to pointer->procedure'.
* libguile/foreign.c (scm_make_foreign_function): Rename to...
  (scm_pointer_to_procedure): ... this.
* libguile/foreign.h: Adjust accordingly.
* module/system/foreign.scm: Likewise.
* test-suite/standalone/test-ffi: Likewise.
* test-suite/tests/foreign.test: Likewise.
* doc/ref/api-foreign.texi: Likewise.
2010-09-06 22:24:44 +02:00
Ludovic Courtès
3318635666 Add `procedure->pointer' to the FFI.
* libguile/foreign.c (make_cif): New procedure, with code formerly in
  `scm_make_foreign_function'.
  (scm_make_foreign_function): Use it.
  (invoke_closure, scm_procedure_to_pointer)[FFI_CLOSURES]: New
  functions.

* libguile/foreign.h (scm_procedure_to_pointer): New declaration.

* module/system/foreign.scm: Export `procedure->pointer' when available.

* test-suite/standalone/test-ffi (f-callback-1, f-callback-2): New
  procedures and related tests.

* test-suite/standalone/test-ffi-lib.c (test_ffi_callback_1,
  test_ffi_callback_2): New functions.

* test-suite/tests/foreign.test ("procedure->pointer"): New test prefix.

* doc/ref/api-foreign.texi (Dynamic FFI): Document `procedure->pointer'.
2010-09-03 15:26:37 +02:00
Ludovic Courtès
fa2a89a6d1 Add string->pointer' and pointer->string' to the FFI.
* libguile/foreign.c (scm_string_to_pointer, scm_pointer_to_string): New
  functions.

* libguile/foreign.h (scm_string_to_pointer, scm_pointer_to_string): New
  declarations.

* module/system/foreign.scm: Export `string->pointer' and
  `pointer->string'.

* test-suite/tests/foreign.test ("pointer<->string"): New test prefix.

* doc/ref/api-foreign.texi (Void Pointers and Byte Access): Add
  `string->pointer' and `pointer->string'.
2010-08-15 16:43:39 +02:00
Andy Wingo
e5f7f675d0 add docs for extensiondir; misc other fixes
* libguile/foreign.c (scm_i_pointer_print): Print in hexadecimal.

* doc/ref/api-foreign.texi (Modules and Extensions): Update for
  "extensiondir", and a discussion of Guile versions.
  (Foreign Variables): Fix discussion of types.
  (Void Pointers and Byte Access): Fix typo.
2010-08-06 13:43:47 +02:00
Andy Wingo
ba270f8c26 remove type discusison from dynamic-pointer docstring
* doc/ref/api-foreign.texi:
* libguile/dynl.c (scm_dynamic_pointer): Remove discussion of types from
  the docstring.
2010-08-06 13:41:58 +02:00
Ludovic Courtès
183a2a224b Update the FFI doc.
* doc/ref/api-foreign.texi (Foreign Types): Remove bits about typed
  foreign pointers.  Add `void'.
  (Foreign Variables): Update the doc of `dynamic-pointer' and the
  `numptob' example.  Remove `foreign-set!' and `foreign-ref'.  Add
  `pointer-address', `make-pointer', `%null-pointer', and
  `null-pointer?'
  (Void Pointers and Byte Access): Make it clear that wrapped pointers
  are untyped.  Remove `void' from here.  Replace `foreign->bytevector'
  and `bytevector->foreign' by `pointer->bytevector' and
  `bytevector->pointer'.  Add `dereference-pointer' and the rest of the
  `numptob' example.
  (Dynamic FFI): Update examples.  Remove `%null-pointer' from here.

* libguile/dynl.c (scm_dynamic_pointer): Update docstring.

* libguile/foreign.c (scm_dereference_pointer,
  scm_pointer_to_bytevector): Likewise.

* module/system/foreign.scm (null-pointer?): Add docstring.
2010-07-28 12:24:25 +02:00
Andy Wingo
07d22c0259 rename (rnrs bytevector) to (rnrs bytevectors)
* module/rnrs/bytevectors.scm: Rename to (rnrs bytevectors), from (rnrs
  bytevector), to match the name from the R6RS.

* benchmark-suite/benchmarks/bytevectors.bm:
* doc/ref/api-data.texi:
* doc/ref/api-foreign.texi:
* libguile/bytevectors.c:
* module/6/rnrs.scm:
* module/language/assembly.scm:
* module/language/assembly/compile-bytecode.scm:
* module/language/assembly/decompile-bytecode.scm:
* module/language/glil/compile-assembly.scm:
* module/language/tree-il/primitives.scm:
* module/srfi/srfi-4.scm:
* module/srfi/srfi-4/gnu.scm:
* module/system/foreign.scm:
* test-suite/standalone/test-ffi:
* test-suite/tests/asm-to-bytecode.test:
* test-suite/tests/bytevectors.test:
* test-suite/tests/foreign.test:
* test-suite/tests/r6rs-ports.test: Update all referrers.
2010-06-01 13:26:11 +02:00
Andy Wingo
b9264dc5f3 finish ffi docs
* libguile/foreign.c: Some doc tweaks.
* doc/ref/api-foreign.texi: Finish FFI docs.
2010-04-06 23:17:10 +02:00
Andy Wingo
71725997c7 more ffi docs
* libguile/foreign.c (scm_make_foreign_function): Doc a little.
* doc/ref/api-foreign.texi (Foreign Function Interface): Document some
  more.
2010-04-06 00:45:35 +02:00
Andy Wingo
43cd9cec23 deprecate dynamic-args-call, and update docs some more
* libguile/deprecated.h (scm_dynamic_args_call): Deprecate.
* libguile/deprecated.c:
* libguile/dynl.h:
* libguile/dynl.c:

* doc/ref/api-foreign.texi: More doc updates.
2010-04-02 00:34:49 +02:00
Andy Wingo
726b8ba3fd add api-foreign.texi
* doc/ref/api-foreign.texi: New file.
* doc/ref/api-modules.texi: Reorganize bits about dynamic linking into
  api-foreign.

* doc/ref/guile.texi:
* doc/ref/Makefile.am: Adapt to api-foreign.texi.
2010-04-02 00:23:24 +02:00