Ludovic Courtès
5765c5a82c
FFI: Fix `set-pointer-finalizer!' to leave the type cell unchanged.
...
This is a followup to 690a0112e5
("Remove
the "has finalizer?" bit from pointer objects.")
* libguile/foreign.c (scm_set_pointer_finalizer_x): Leave the type cell
unchanged. Before, `equal?' would break on pointers on which
`set-pointer-finalizer!' had been called.
* test-suite/tests/foreign.test ("make-pointer")["equal? modulo
finalizer (set-pointer-finalizer!)"]: New test.
2012-01-23 23:51:33 +01:00
Ludovic Courtès
59a0273338
FFI: Hold a weak reference to the procedure passed to `procedure->pointer'.
...
* libguile/foreign.c (scm_procedure_to_pointer): Keep a weak reference
to PROC.
* test-suite/tests/foreign.test ("procedure->pointer")["procedure is
retained"]: New test.
2011-11-26 22:27:32 +01:00
Ludovic Courtès
449c4d44d0
FFI: Add a `procedure->pointer' test.
...
* test-suite/tests/foreign.test ("procedure->pointer")["procedures
returning a pointer"]: New test.
2011-11-16 23:51:34 +01:00
Ludovic Courtès
1f78c6691f
Fix `foreign.test' for big endian machines.
...
* test-suite/tests/foreign.test ("pointer<->bytevector")["pointer from
bits", "dereference-pointer"]: Fix iteration order for big endian
machines.
2011-05-06 17:43:37 +02: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
Michael Gran
0f1fd214f1
More descriptive error for dynamic-pointer
...
* libguile/dynl.c (sysdep_dynl_value): Failure to find a symbol is not
an error, so raise our own, more appropriate error.
* test-suite/tests/foreign.test ("dynamic-pointer"): Add a test.
2011-03-31 12:34:47 +02:00
Ludovic Courtès
443f25dcff
Fix procedure->pointer' for functions returning
void'.
...
* libguile/foreign.c (unpack): Handle `FFI_TYPE_VOID'.
* test-suite/tests/foreign.test ("procedure->pointer")["procedures
returning void"]: New test. Reported by
Tristan Colgate <tcolgate@gmail.com>.
2011-03-29 23:35:24 +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
d82f8518b9
FFI: Return the right alignment for structures.
...
* libguile/foreign.c (scm_alignof): Fix handling of structure alignment.
Reported by Aidan Gauland <aidalgol@no8wireless.co.nz>.
* test-suite/tests/foreign.test ("structs")["alignof { int8, double,
int8 }", "int8, { int8, double, int8 }, int16"]: New tests.
2011-03-10 22:24:23 +01:00
Ludovic Courtès
9970cf6708
Improve type checking when invoking foreign functions.
...
* libguile/foreign.c (unpack): Make sure X is a pointer before using
`SCM_POINTER_VALUE'.
* test-suite/tests/foreign.test ("pointer->procedure"): New test prefix.
2011-02-09 00:08:14 +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
Ludovic Courtès
16f0612864
Add FFI tests for `sizeof' and structs.
...
* test-suite/tests/foreign.test ("structs")["sizeof { int8, double }",
"sizeof { short, int, long, pointer }"]: New tests.
2010-11-11 16:41:15 +01:00
Ludovic Courtès
42f7c01e0a
Add FFI support for short' and
unsigned short'.
...
* libguile/foreign.c (sym_short, sym_unsigned_short): New variables.
(scm_init_foreign): Define Scheme variables SYM_SHORT and
SYM_UNSIGNED_SHORT.
* module/system/foreign.scm (short, unsigned-short): New exports.
(integer-ref, integer-set): Support (= (sizeof TYPE) 2).
(%read-short, %write-short!, %read-unsigned-short,
%write-unsigned-short!): New variables.
(*writers*): Add support for `short' and `unsigned-short'.
(*readers*): Likewise.
* test-suite/tests/foreign.test ("structs")["int8, pointer, short,
double"]: New test.
2010-11-11 16:41:15 +01:00
Ludovic Courtès
fb636a1cce
Have parse-c-struct' and
make-c-struct' support `int', pointers, etc.
...
Reported by Tristan Colgate <tcolgate@gmail.com>.
* module/system/foreign.scm: Call `load-extension' at compile-time too.
(compile-time-value): New macro.
(integer-ref, integer-set): New procedures.
(define-integer-reader, define-integer-writer): New macros.
(%read-int, %read-long, %write-int!, %write-long!, %read-unsigned-int,
%read-unsigned-long, %write-unsigned-int!, %write-unsigned-long!,
%read-size_t, %write-size_t!, %read-pointer, %write-pointer!): New
procedures.
(*writers*): Add writers for `int', `unsigned-int', `long',
`unsigned-long', `size_t', and `*'.
(*readers*): Likewise.
* test-suite/tests/foreign.test ("structs")["int8, pointer",
"unsigned-long, int8, size_t", "long, int, pointer"]: New tests.
2010-11-11 16:41:15 +01:00
Ludovic Courtès
1f864a1685
FFI: Honor alignment constraints in `parse-c-struct'.
...
* module/system/foreign.scm (parse-c-struct): Honor alignment
constraints for TYPE.
* test-suite/tests/foreign.test ("structs")["alignment constraints
honored"]: New test.
2010-11-11 16:41:15 +01:00
Ludovic Courtès
cb2d8076ef
Define `equal?' for pointer objects.
...
* libguile/eq.c (scm_equal_p): Handle pointer objects.
* test-suite/tests/foreign.test ("make-pointer")["equal?", "equal?
modulo finalizer", "not equal?"]: New tests.
2010-09-23 21:55:21 +02: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
fb0b64c12a
Add an entertaining `procedure->pointer' test.
...
* test-suite/tests/foreign.test ("procedure->pointer")["bijection"]: New
test.
2010-09-04 14:39:48 +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
Ludovic Courtès
7387c231ee
Fix `parse-c-struct'.
...
* module/system/foreign.scm (parse-c-struct): Update use of
`pointer->bytevector' to the new API.
* test-suite/tests/foreign.test ("structs"): New test prefix.
2010-07-28 12:24:25 +02:00
Ludovic Courtès
5b46a8c2c8
Use "pointer" instead of "foreign" when dealing with wrapped pointers.
...
* libguile/foreign.h (scm_t_foreign_finalizer): Rename to...
(scm_t_pointer_finalizer): ... this.
(SCM_FOREIGN_P): Rename to...
(SCM_POINTER_P): this.
(SCM_VALIDATE_FOREIGN): Rename to...
(SCM_VALIDATE_POINTER): ... this.
(SCM_FOREIGN_HAS_FINALIZER): Rename to...
(SCM_POINTER_HAS_FINALIZER): ... this.
(scm_take_foreign_pointer): Rename to...
(scm_from_pointer): ... this.
(scm_foreign_address): Rename to...
(scm_pointer_address): ... this.
(scm_foreign_to_bytevector): Rename to...
(scm_pointer_to_bytevector): ... this.
(scm_foreign_set_finalizer_x): Rename to...
(scm_set_pointer_finalizer_x): ... this.
(scm_bytevector_to_foreign): Rename to...
(scm_bytevector_to_pointer): ... this.
(scm_i_foreign_print): Rename to...
(scm_i_pointer_print): ... this.
* libguile/foreign.c: Update accordingly.
* libguile/tags.h (scm_tc7_foreign): Rename to...
(scm_tc7_pointer): ... this.
* libguile/foreign.c, libguile/deprecated.c, libguile/dynl.c,
libguile/evalext.c, libguile/gc.c, libguile/goops.c, libguile/gsubr.c,
libguile/gsubr.h, libguile/print.c, libguile/snarf.h,
libguile/vm-i-system.c, module/system/foreign.scm,
test-suite/standalone/test-ffi, test-suite/tests/foreign.test: Update
accordingly.
2010-07-28 12:24:25 +02:00
Ludovic Courtès
17fc9efecb
Add dereference-pointer' to
(system foreign)'.
...
* libguile/foreign.c (scm_dereference_pointer): New function.
* libguile/foreign.h (scm_dereference_pointer): New declaration.
* module/system/foreign.scm (dereference-pointer): Likewise.
* test-suite/tests/foreign.test
("foreign<->bytevector")["dereference-pointer"]: New test.
2010-07-26 19:38:52 +02:00
Ludovic Courtès
d4149a510e
Simplify the (system foreign) API.
...
Suggested by Neil Jerram.
* libguile/foreign.h (SCM_FOREIGN_TYPE, SCM_FOREIGN_VALUE_REF,
SCM_FOREIGN_VALUE_SET, SCM_FOREIGN_LEN, SCM_FOREIGN_TYPED_P,
SCM_FOREIGN_VALUE_P, SCM_VALIDATE_FOREIGN_VALUE, scm_foreign_set_x,
scm_foreign_type): Remove.
(scm_foreign_ref): Rename to...
(scm_foreign_address): ... this.
(scm_take_foreign_pointer): Update.
(SCM_FOREIGN_POINTER): Remove CTYPE argument. Update callers.
(scm_make_pointer): New declaration.
* libguile/foreign.c (scm_to_uintptr, scm_from_uintptr): New macros.
(scm_make_pointer): New function.
(scm_take_foreign_pointer): Remove TYPE and LEN arguments. Update
callers.
(scm_foreign_ref): Remove to...
(scm_foreign_address): ... this. Remove type-related code.
(scm_foreign_set_x): Remove.
(scm_foreign_to_bytevector): Change argument order; make LEN argument
compulsory.
(scm_i_foreign_print): Remove type printing.
(unpack): Remove foreign-type checking.
* libguile/deprecated.c (scm_dynamic_args_call): Update accordingly.
* libguile/dynl.c (scm_dynamic_pointer): Remove the TYPE and LEN
arguments; update callers. Update to the new foreign API.
* libguile/dynl.h (scm_dynamic_pointer): Update.
* libguile/gsubr.c (create_gsubr): Update to the new foreign API.
* libguile/gsubr.h (SCM_SUBRF, SCM_SUBR_GENERIC): Ditto.
* libguile/snarf.h (SCM_IMMUTABLE_FOREIGN): Ditto.
* libguile/vm-i-system.c (subr_call): Ditto.
* module/system/foreign.scm (null-pointer?): New procedure.
* test-suite/standalone/test-ffi: Update to the new
`bytevector->foreign' signature.
* test-suite/tests/foreign.test ("null pointer")["null pointer
identity", "null-pointer? %null-pointer"]: New tests.
["foreign-set! other-null-pointer", "foreign->bytevector
other-null-pointer"]: Remove.
("make-pointer", "foreign<->bytevector"): New test prefixes.
2010-07-26 19:38:52 +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
Ludovic Courtès
01ad5a7ba9
Raise an error when attempting to modify the value of `%null-pointer'.
...
* libguile/foreign.c (sym_null_pointer_error): New variable.
(null_pointer_error): New function.
(scm_foreign_set_x): Raise an error if attempting to modify
NULL_POINTER.
(scm_foreign_to_bytevector): Use `null_pointer_error ()' instead of
`scm_misc_error ()'.
* test-suite/tests/foreign.test: New file.
* test-suite/Makefile.am (SCM_TESTS): Add tests/foreign.test.
* test-suite/lib.scm (exception:null-pointer-error): New variable.
2010-04-09 00:32:15 +02:00