summaryrefslogtreecommitdiff
path: root/libguile/foreign.c
AgeCommit message (Collapse)AuthorFilesLines
2013-08-11Merge remote-tracking branch 'origin/stable-2.0'Mark H Weaver1-1/+7
2013-08-09dereference-pointer: check for null pointer.Mark H Weaver1-1/+7
* libguile/foreign.c (scm_dereference_pointer): Check for attempts to dereference a null pointer. * test-suite/tests/foreign.test ("null pointer"): Add test.
2013-05-23add scm_{to,from}_{u,}intptr_tAndy Wingo1-13/+3
* libguile/numbers.h (scm_to_intptr_t, scm_from_intptr_t) (scm_to_uintptr_t, scm_from_uintptr_t): New defines. * libguile/foreign.c: Remove definitions here; adapt callers to use new names with _t suffixes.
2013-03-28Merge remote-tracking branch 'origin/stable-2.0'Mark H Weaver1-35/+80
Conflicts: configure.ac libguile/deprecated.c libguile/deprecated.h libguile/filesys.h libguile/fluids.c libguile/fports.c libguile/gc.c libguile/guile.c libguile/numbers.c libguile/objcodes.c libguile/r6rs-ports.c libguile/smob.c libguile/socket.c libguile/threads.h module/language/scheme/decompile-tree-il.scm module/language/tree-il/peval.scm test-suite/tests/syncase.test
2013-02-28Support calling foreign functions of 10 arguments or more.Mark H Weaver1-35/+80
* libguile/foreign.c (OBJCODE_HEADER, META_HEADER, META): Change these into higher-order macros. (GEN_CODE): New higher-order macro based on 'CODE'. (M_STATIC, M_DYNAMIC): New macros. (CODE): Reimplement using 'GEN_CODE' and 'M_STATIC'. (make_objcode_trampoline): New static function. (large_objcode_trampolines, large_objcode_trampolines_mutex): New static variables. (get_objcode_trampoline): New static function. (cif_to_procedure): Use 'get_objcode_trampoline'. * test-suite/standalone/test-ffi-lib.c (test_ffi_sum_many): New function. * test-suite/standalone/test-ffi: Add test.
2013-02-18Merge remote-tracking branch 'origin/stable-2.0'Andy Wingo1-1/+23
Conflicts: libguile/array-handle.c libguile/deprecated.h libguile/inline.c libguile/inline.h module/ice-9/deprecated.scm module/language/tree-il/peval.scm
2013-02-02Add foreign types: ssize_t and ptrdiff_t.Mark H Weaver1-1/+23
* 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.
2012-07-06Merge remote-tracking branch 'origin/stable-2.0'Andy Wingo1-1/+1
Conflicts: libguile/expand.c libguile/hashtab.c libguile/ports.c libguile/vectors.c libguile/weaks.c module/language/ecmascript/compile-tree-il.scm module/language/tree-il/effects.scm module/language/tree-il/fix-letrec.scm module/language/tree-il/peval.scm test-suite/tests/peval.test
2012-07-02Use `void *' instead of `GC_PTR' internally.Ludovic Courtès1-1/+1
* libguile/finalizers.c, libguile/foreign.c, libguile/guardians.c, libguile/hashtab.c, libguile/numbers.c, libguile/ports.c, libguile/smob.c, libguile/struct.c, libguile/vectors.c, libguile/weaks.c: Use `void *' instead of `GC_PTR'.
2012-06-22Merge remote-tracking branch 'origin/stable-2.0'Andy Wingo1-2/+2
Conflicts: libguile/deprecated.c libguile/ports.c libguile/ports.h libguile/strports.c test-suite/tests/cse.test
2012-05-31Add the `%default-port-conversion-strategy' fluid.Ludovic Courtès1-2/+2
Fixes <http://bugs.gnu.org/11468>. * libguile/ports.c (scm_conversion_strategy): Remove. (default_conversion_strategy_var, sym_error, sym_substitute, sym_escape): New variables. (scm_i_get_conversion_strategy, scm_i_set_conversion_strategy_x): Remove. (scm_i_default_port_conversion_handler, scm_i_set_default_port_conversion_handler): New functions. (scm_port_conversion_strategy): Use `scm_i_default_port_conversion_handler' when PORT is #f. (scm_set_port_conversion_strategy_x): Use SYM_ERROR, SYM_SUBSTITUTE, and SYM_ESCAPE. Use `scm_i_set_default_port_conversion_handler' when PORT is #f. (scm_init_ports): Initialize DEFAULT_CONVERSION_STRATEGY_VAR. * libguile/ports.h: Update declarations accordingly. * libguile/foreign.c: Change `scm_i_get_conversion_strategy (SCM_BOOL_F)' to `scm_i_default_port_conversion_handler ()'. * libguile/strings.c: Likewise. * test-suite/tests/ports.test ("%default-port-conversion-strategy"): New test prefix. * test-suite/tests/foreign.test ("pointer<->string")["%default-port-conversion-strategy is error", "%default-port-conversion-strategy is soft"]: New tests. * test-suite/test-suite/lib.scm (exception:encoding-error): Allow the regexp to match `scm_to_stringn' error messages. * doc/ref/api-io.texi (Ports): Document `%default-port-conversion-strategy'.
2012-05-21Fix FFI struct sizing to account for trailing padding.Ken Raeburn1-1/+2
* libguile/foreign.c (scm_sizeof): Make sure the overall size is a multiple of the alignment of the structure. * test-suite/tests/foreign.test: Test size of { double, int8 }.
2012-03-08use the new finalizer helpersAndy Wingo1-21/+4
* libguile/foreign.c (scm_set_pointer_finalizer_x) * libguile/ports.c (finalize_port) * libguile/smob.c (scm_i_new_smob, scm_i_new_double_smob) * libguile/struct.c (scm_i_alloc_struct) * libguile/numbers.c (make_bignum): Use the new API.
2012-02-19use the new finalizer helpersAndy Wingo1-21/+4
* libguile/foreign.c (scm_set_pointer_finalizer_x) * libguile/ports.c (finalize_port, scm_c_make_port_with_encoding) (open_iconv_descriptors) * libguile/smob.c (scm_i_new_smob, scm_i_new_double_smob) * libguile/struct.c (scm_i_alloc_struct) * libguile/weak-set.c (weak_gc_finalizer) (scm_c_register_weak_gc_callback) * libguile/weak-table.c (scm_c_register_weak_gc_callback) (weak_gc_finalizer) * libguile/numbers.c (make_bignum): Use the new API.
2012-02-08Merge remote-tracking branch 'origin/stable-2.0'Andy Wingo1-3/+12
Conflicts: GUILE-VERSION libguile/gc-malloc.c libguile/ports.c
2012-02-02Implement scm_to_pointerMark H Weaver1-0/+9
* libguile/foreign.c, libguile/foreign.h (scm_to_pointer): New C function. * test-suite/standalone/test-loose-ends.c: Add test.
2012-02-02Improve the usage of variable names in C docstrings.Bake Timmons1-3/+3
* libguile/alist.c: * libguile/array-map.c: * libguile/arrays.c: * libguile/bitvectors.c: * libguile/filesys.c: * libguile/foreign.c: * libguile/generalized-arrays.c: * libguile/hashtab.c: * libguile/ioext.c: * libguile/load.c: * libguile/numbers.c: * libguile/ports.c: * libguile/posix.c: * libguile/print.c: * libguile/procprop.c: * libguile/promises.c: * libguile/simpos.c: * libguile/socket.c: * libguile/srfi-1.c: * libguile/srfi-13.c: * libguile/srfi-14.c: * libguile/stacks.c: * libguile/stime.c: * libguile/strings.c: * libguile/struct.c: * libguile/symbols.c: * libguile/threads.c: * libguile/weak-table.c: * libguile/weak-vector.c: Make the variable names in the C docstrings more consistent. Replace a few instances of @var with @code when appropriate.
2012-01-31Revert "add SCM_HEAP_OBJECT_BASE"Andy Wingo1-2/+2
This reverts commit 47ed8656db8800f3ad20a40eb2c4e9ef3dc891e3. Conflicts: libguile/foreign.c
2012-01-30Merge commit '3d51e57cfb0404db568a6adfde2a346d3fd9907e'Andy Wingo1-2/+0
Conflicts: libguile/foreign.c libguile/hashtab.c module/ice-9/psyntax-pp.scm module/language/tree-il/compile-glil.scm
2012-01-30Merge commit '9b0975f1dc41ddd10d81fb5b0965b9e9a54ef37a'Andy Wingo1-3/+4
Conflicts: libguile/foreign.c module/ice-9/psyntax-pp.scm module/ice-9/psyntax.scm
2012-01-23FFI: Fix `set-pointer-finalizer!' to leave the type cell unchanged.Ludovic Courtès1-2/+0
This is a followup to 690a0112e55823aa8b862daeddcf44cea97e7917 ("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-14Fix signed/unsigned pointer mismatches.Ludovic Courtès1-3/+4
* libguile/foreign.c (scm_pointer_to_bytevector, scm_bytevector_to_pointer): Use pointers of the same signedness.
2011-12-19Merge remote-tracking branch 'origin/stable-2.0'Andy Wingo1-24/+46
Conflicts: libguile/feature.c m4/gnulib-cache.m4 module/ice-9/deprecated.scm module/language/tree-il/peval.scm
2011-12-19FFI: Properly unpack small integer return values in closure call.Andreas Schwab1-9/+31
Fixes <http://debbugs.gnu.org/10203>. * libguile/foreign.c (unpack): Add parameter return_value_p. Properly store integer return values smaller than int. (scm_i_foreign_call): Update call to unpack. (invoke_closure): Likewise.
2011-12-14Use `alignof_type' instead of `alignof'.Ludovic Courtès1-15/+15
* libguile/foreign.c: Use `alignof_type' instead of `alignof'; the latter was removed from Gnulib's <alignof.h> in 408e170e3ae81f73fb65686c5834693d89a96594 (Nov. 1 2011). * libguile/vm-i-scheme.c: Likewise.
2011-12-01Merge remote-tracking branch 'origin/stable-2.0'Andy Wingo1-3/+13
Conflicts: configure.ac libguile/fluids.c libguile/gc.c libguile/gc.h libguile/objcodes.c libguile/procprop.c libguile/vm.c module/ice-9/psyntax-pp.scm module/ice-9/psyntax.scm
2011-11-26FFI: Hold a weak reference to the procedure passed to `procedure->pointer'.Ludovic Courtès1-2/+4
* 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-16FFI: Hold a weak reference to the CIF made by `procedure->pointer'.Ludovic Courtès1-3/+11
* libguile/foreign.c (scm_procedure_to_pointer): Keep a weak reference to CIF so that it is not reclaimed before POINTER. Before that it could be reclaimed and typically reused to store the CIF of another procedure with the same arity, leading to obscure wrong-type-arg errors.
2011-11-08locking for putc, putsAndy Wingo1-2/+2
* libguile/ports.c (scm_putc, scm_puts): * libguile/ports.h (scm_putc_unlocked, scm_puts_unlocked): Separate into _unlocked and locked variants. Change all callers to use the _unlocked versions.
2011-10-24add SCM_HEAP_OBJECT_BASEAndy Wingo1-2/+2
* libguile/tags.h (SCM_HEAP_OBJECT_BASE): New macro. Given a SCM, returns a pointer to the start of its memory area on the heap. * libguile/bytevectors.c: * libguile/fluids.c: * libguile/foreign.c: * libguile/gc.h: * libguile/guardians.c: * libguile/numbers.h: * libguile/ports.c: * libguile/smob.c: * libguile/struct.c: * libguile/weak-set.c: * libguile/weak-table.c: * libguile/weak-vector.c: Use it.
2011-10-24add SCM_HEAP_OBJECT_PAndy Wingo1-1/+1
* libguile/tags.h (SCM_HEAP_OBJECT_P): New macro, an alias for SCM_NIMP. * libguile/arrays.c: * libguile/debug.c: * libguile/foreign.c: * libguile/gdbint.c: * libguile/guardians.c: * libguile/list.c: * libguile/modules.c: * libguile/options.c: * libguile/smob.c: * libguile/validate.h: * libguile/weak-set.c: * libguile/weak-table.c: * libguile/weak-vector.c: Use it instead of SCM_NIMP or !SCM_IMP.
2011-10-24add SCM_{PACK,UNPACK}_POINTERAndy Wingo1-3/+3
* libguile/tags.h (SCM_UNPACK_POINTER, SCM_PACK_POINTER): New macros. The old SCM2PTR and PTR2SCM were defined in such a way that round-tripping through a pointer could lose precision, even in the case in which you weren't interested in actually dereferencing the pointer, it was simply that you needed to plumb a SCM through APIs that take pointers. These new macros are more like SCM_PACK and SCM_UNPACK, but for pointer types. The bit representation of the pointer should be the same as the scm_t_bits representation. * libguile/gc.h (PTR2SCM, SCM2PTR): Remove support for (old) UNICOS pointers. We are going to try tagging the SCM object itself in the future, and I don't think that keeping this support is worth its cost. It probably doesn't work anyway. * libguile/backtrace.c: * libguile/bytevectors.c: * libguile/continuations.c: * libguile/fluids.c: * libguile/foreign.c: * libguile/gc.h: * libguile/guardians.c: * libguile/hashtab.c: * libguile/load.c: * libguile/numbers.c: * libguile/ports.c: * libguile/smob.c: * libguile/strings.c: * libguile/symbols.c: * libguile/vm.c: * libguile/weak-set.c: * libguile/weak-table.c: * libguile/weak-vector.c: Update many sites to use the new macros.
2011-10-24convert internal weak hash table users to use the weak table apiAndy Wingo1-5/+2
The weak table API isn't public yet. It could be after some review. But we can go ahead and use it now internally. * libguile/foreign.c: * libguile/goops.c: * libguile/objprop.c: * libguile/procprop.c: * libguile/smob.c: * libguile/srcprop.c: Update weak table users to new API. No locking needed!
2011-05-09Merge remote-tracking branch 'origin/stable-2.0'Andy Wingo1-10/+39
2011-05-08Fix small integer return value packing on big endian machines.Ludovic Courtès1-10/+39
* libguile/foreign.c (pack): Add `return_value_p' parameter. Update callers. When RETURN_VALUE_P is true, assume LOC points to an `ffi_arg', and cast its results to the relevant type. This fixes packing of integer return values smaller than `int' on SPARC64 and PowerPC64. Reported by Nelson H. F. Beebe <beebe@math.utah.edu>.
2011-05-07bytevectors have internal parent fieldAndy Wingo1-2/+2
* libguile/bytevectors.h (SCM_BYTEVECTOR_HEADER_SIZE): Bump, giving bytevectors another word: a parent pointer. Will allow for sub-bytevectors and efficient mmap bindings. * libguile/bytevectors.c (make_bytevector): (make_bytevector_from_buffer): Init parent to #f. (scm_c_take_bytevector, scm_c_take_typed_bytevector): Another argument, the parent, which gets set in the bytevector. * libguile/foreign.c (scm_pointer_to_bytevector): Use the parent field instead of registering a weak reference from bytevector to foreign pointer. * libguile/objcodes.c (scm_objcode_to_bytecode): Use the parent field to avoid copying the objcode. * libguile/srfi-4.c (DEFINE_SRFI_4_C_FUNCS): * libguile/strings.c (scm_from_stringn): * libguile/vm.c (really_make_boot_program): * libguile/r6rs-ports.c (scm_get_bytevector_some) (scm_get_bytevector_all, bytevector_output_port_procedure): Set the parent to #f.
2011-04-01string->pointer and pointer->string have optional encoding argAndy Wingo1-14/+65
* 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-03-29Fix `procedure->pointer' for functions returning `void'.Ludovic Courtès1-0/+3
* 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-17add pointer->scm, scm->pointerAndy Wingo1-0/+28
* 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-10FFI: Return the right alignment for structures.Ludovic Courtès1-2/+18
* 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-02-10make static hash table access thread-safe in foreign.cAndy Wingo1-0/+5
* libguile/foreign.c (register_weak_reference): Wrap static hash table access in a mutex.
2011-02-09Improve type checking when invoking foreign functions.Ludovic Courtès1-0/+4
* 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-01-30Add `pointer?'.Ludovic Courtès1-0/+10
* 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-30Remove the "has finalizer?" bit from pointer objects.Ludovic Courtès1-4/+1
* libguile/foreign.h (SCM_POINTER_HAS_FINALIZER): Remove. * libguile/foreign.c (scm_from_pointer): Store nothing more than `scm_tc7_pointer' in the type slot.
2011-01-27objcode type is an enumeration, not flagsAndy Wingo1-2/+2
* libguile/objcodes.h (SCM_OBJCODE_TYPE_MMAP) (SCM_OBJCODE_TYPE_BYTEVECTOR, SCM_OBJCODE_TYPE_SLICE) (SCM_OBJCODE_TYPE_STATIC): Enumerate objcode types instead of expressing them as flags. (SCM_OBJCODE_TYPE): Type is held in bits 8-15. (SCM_OBJCODE_FLAGS): Flags are now shifted by 16 bits, not 8. (SCM_MAKE_OBJCODE_TAG): New helper. * libguile/continuations.c (STATIC_OBJCODE_TAG): * libguile/control.c (STATIC_OBJCODE_TAG): * libguile/foreign.c (STATIC_OBJCODE_TAG): * libguile/gsubr.c (STATIC_OBJCODE_TAG): * libguile/smob.c (STATIC_OBJCODE_TAG): * libguile/objcodes.c (make_objcode_by_mmap, scm_c_make_objcode_slice) (scm_bytecode_to_objcode): : Use SCM_MAKE_OBJCODE_TAG.
2010-12-04make-string et al nulls memory if not given an initializerAndy Wingo1-0/+2
* libguile/gc-malloc.c: Add a note that the gc-malloc does not clear the memory block, so users need to make sure it is initialized. * libguile/bitvectors.c (scm_c_make_bitvector): * libguile/bytevectors.c (scm_make_bytevector): * libguile/strings.c (scm_c_make_string): If no initializer is given, initialize the bytes to 0. Prevents information leakage if an app uses make-string et al without initializers. * libguile/foreign.c (make_cif): Initialize this too, to prevent leakage in the struct holes. Paranoia...
2010-11-19Include <alloca.h> wherever `alloca' is used.Ludovic Courtès1-0/+1
Patch provided by <carlo.bramix@libero.it> (tiny change). * libguile/control.c, libguile/fluids.c, libguile/foreign.c, libguile/hashtab.c, libguile/strings.c: Include <alloca.h>.
2010-11-11Add FFI support for `short' and `unsigned short'.Ludovic Courtès1-0/+26
* 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-09-06Rename `make-foreign-function' to `pointer->procedure'.Ludovic Courtès1-3/+3
* 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-03Add `procedure->pointer' to the FFI.Ludovic Courtès1-26/+114
* 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'.