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'.
* 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
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.
* 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.
* doc/ref/api-foreign.texi (Foreign Types): Replace references to the
old foreign->bytevector and bytevector->foreign with the new procedure
names using pointer.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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'.
* 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'.
* 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.
* 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.
* 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.