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

35 commits

Author SHA1 Message Date
Mikael Djurfeldt
6af3362b05 Support C99 complex types conditionally in (system foreign)
496f69dba2 introduced C99 complex types in
libguile/foreign.h and (system foreign). Since these types are provided
conditionally in foreign.h based on autoconf tests they need to be used
conditionally in (system foreign) based on their presence.
2021-12-01 18:40:19 +01:00
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
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
Andy Wingo
a1aae2c3a0 Merge commit 'f6ddf827f8'
Conflicts:
	module/ice-9/boot-9.scm
	module/oop/goops.scm
2014-02-07 14:51:42 +01:00
Mark H Weaver
f6ddf827f8 Improve correctness and consistency of 'eval-when' usage.
* module/ice-9/boot-9.scm:
* module/ice-9/i18n.scm:
* module/ice-9/poll.scm:
* module/ice-9/popen.scm:
* module/ice-9/r6rs-libraries.scm:
* module/oop/goops.scm:
* module/oop/goops/compile.scm:
* module/oop/goops/dispatch.scm:
* module/srfi/srfi-88.scm:
* module/system/foreign.scm:
* module/texinfo/serialize.scm: Change most uses of 'compile' to
  'expand', except where we must avoid it during initial bootstrap
  before the module system is loaded.  Remove redundant uses of
  'compile' where 'expand' is also given.  Standardize on the
  "(expand load eval)" order of conditions.
2014-01-23 10:41:22 -05:00
Andy Wingo
9b977c836b Merge remote-tracking branch 'origin/stable-2.0'
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-18 17:59:38 +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
c4e83f74c2 remove a stale comment
* module/system/foreign.scm (define-wrapped-pointer-type): Remove stale
  comment.
2011-10-24 12:48:36 +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
ca33b501a9 Work around weak-value hash table bug in `define-wrapped-pointer-type'.
* module/system/foreign.scm (define-wrapped-pointer-type)[wrap]: Use
  `hash-ref' and `hash-set!' instead of `hash-create-handle!' and
  `set-cdr!'.
2011-03-13 16:09:55 +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
8a302b9f78 Hack around a defect in `define-wrapped-pointer-type'.
* module/system/foreign.scm (define-wrapped-pointer-type): Choose
  TYPE-NAME deterministically.
2011-02-07 23:53:25 +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
Andy Wingo
a6b1b27aad foreign: c-struct parsing simplification
* module/system/foreign.scm: Revert much of fb636a1cce. Short et al are
  not distinct types -- they are all aliases to e.g. int16. The only
  case that was not covered before was the pointer case.
  (bytevector-pointer-ref, bytevector-pointer-set!): Implement these,
  and use them for pointers.
2010-12-12 23:13:08 +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
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
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
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
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
54eb59cf49 Add %null-pointer' to (system foreign)'.
* libguile/foreign.c (sym_null, null_pointer): New variables.
  (scm_foreign_to_bytevector): Raise an error when PTR is NULL.
  (scm_init_foreign): Define SYM_NULL.

* module/system/foreign.scm (%null-pointer): New exported binding.
2010-03-18 00:28:14 +01:00
Ludovic Courtès
dd1464bf38 Provide int', long', size_t', etc. in (system foreign)'.
* libguile/foreign.c (sym_int, sym_long, sym_unsigned_int,
  sym_unsigned_long, sym_size_t): New variables.
  (scm_init_foreign): Define them at the Scheme level.

* module/system/foreign.scm (int, unsigned-int, long,
  unsigned-long, size_t): New exported bindings.
2010-03-17 00:54:01 +01:00
Andy Wingo
44602b0868 rename libguile to libguile-@EFFECTIVE_VERSION@, currently libguile-2.0
* libguile/Makefile.am (lib_LTLIBRARIES): Instead of just "libguile.la",
  make "libguile-@EFFECTIVE_VERSION@.la". This allows multiple versions
  of Guile to be installed at once. See
  http://www106.pair.com/rhp/parallel.html for a rationale.

  (libguile_@GUILE_EFFECTIVE_VERSION@_la_CFLAGS):
  (libguile_@GUILE_EFFECTIVE_VERSION@_la_SOURCES):
  (EXTRA_libguile_@GUILE_EFFECTIVE_VERSION@_la_SOURCES):
  (libguile_@GUILE_EFFECTIVE_VERSION@_la_DEPENDENCIES):
  (libguile_@GUILE_EFFECTIVE_VERSION@_la_LIBADD):
  (libguile_@GUILE_EFFECTIVE_VERSION@_la_LDFLAGS): Fixup automake vars
  to include the effective version.
  (guile_LDADD): Fix up the spelling of libguile.

* libguile/bytevectors.c (scm_bootstrap_bytevectors):
* libguile/foreign.c (scm_register_foreign):
* libguile/i18n.c (scm_bootstrap_i18n):
* libguile/instructions.c (scm_bootstrap_instructions):
* libguile/objcodes.c (scm_bootstrap_objcodes):
* libguile/programs.c (scm_bootstrap_programs):
* libguile/vm.c (scm_bootstrap_vm): Register extensions using e.g.
  "libguile-2.0" as the libname -- i.e., including the effective version
  in the libname.

* module/ice-9/i18n.scm:
* module/rnrs/bytevector.scm:
* module/rnrs/io/ports.scm:
* module/system/foreign.scm:
* module/system/vm/instruction.scm:
* module/system/vm/objcode.scm:
* module/system/vm/program.scm:
* module/system/vm/vm.scm: When doing a load-extension for something in
  Guile, use the effective version also.

* meta/guile-2.0-uninstalled.pc.in (Libs):
* meta/guile-2.0.pc.in (Libs): Use -lguile-@EFFECTIVE_VERSION@. This
  change should mean that code built against Guile should not be
  affected by the libguile rename.

* guile-readline/Makefile.am (libguilereadline_v_@LIBGUILEREADLINE_MAJOR@_la_LIBADD):
* srfi/Makefile.am
  (libguile_srfi_srfi_1_v_@LIBGUILE_SRFI_SRFI_1_MAJOR@_la_LIBADD):
  (libguile_srfi_srfi_4_v_@LIBGUILE_SRFI_SRFI_4_MAJOR@_la_LIBADD):
  (libguile_srfi_srfi_13_14_v_@LIBGUILE_SRFI_SRFI_13_14_MAJOR@_la_LIBADD):
  (libguile_srfi_srfi_60_v_@LIBGUILE_SRFI_SRFI_60_MAJOR@_la_LIBADD):
* test-suite/standalone/Makefile.am (test_num2integral_LDADD):
  (test_round_LDADD):
  (libtest_asmobs_la_LIBADD):
  (libtest_ffi_la_LIBADD):
  (test_list_LDADD):
  (test_unwind_LDADD):
  (test_conversion_LDADD):
  (test_loose_ends_LDADD):
  (test_scm_c_read_LDADD):
  (test_scm_take_locale_symbol_LDADD):
  (test_scm_take_u8vector_LDADD):
  (libtest_extensions_la_LIBADD):
  (test_with_guile_module_LDADD):
  (test_scm_with_guile_LDADD): Fix up the spelling of libguile.la.
2010-03-16 21:20:34 +01:00
Andy Wingo
3435f3c07c add simple foreign finalization, and pointer support
* libguile/foreign.h:
* libguile/foreign.c (scm_foreign_set_finalizer_x): New function, for a
  limited form of finalization (like `free').
  (scm_alignof, scm_sizeof, parse_ffi_type, fill_ffi_type): For the
  purposes of make-foreign-function, treat '* (the asterisk symbol) as a
  pointer.

* module/system/foreign.scm: Export foreign-set-finalizer!.
2010-01-27 22:12:58 +01:00
Andy Wingo
70ea39f70f add make-c-struct, parse-c-struct
* module/system/foreign.scm: Export alignof and sizeof.
  (make-c-struct, parse-c-struct): New public functions.
2010-01-26 22:56:42 +01:00
Andy Wingo
d8b04f04e9 first pass at implementing low-level foreign functions
* libguile/Makefile.am (AM_CPPFLAGS): Move LIBFFI_CFLAGS here (from
  AM_CFLAGS), allowing snarfing to work.

* libguile/foreign.h (scm_make_foreign_function): New public function.

* libguile/foreign.c: Flesh out an implementation of foreign functions.
  (scm_take_foreign_pointer): Bugfix for the case in which we have a
  finalizer.

* module/system/foreign.scm: Export `make-foreign-function'.
2010-01-26 22:56:41 +01:00
Andy Wingo
20aafae22a byte access to foreigns via bytevectors
* libguile/foreign.h:
* libguile/foreign.c (scm_foreign_ref, scm_foreign_set_x): Remove all
  bits about offsets and aliasing; bytevectors are much better at that.
  (scm_foreign_to_bytevector, scm_bytevector_to_foreign): New functions
  for getting at the bytes of a memory region.

* module/system/foreign.scm (foreign->bytevector, bytevector->foreign):
  Export these.
2010-01-26 22:56:41 +01:00
Andy Wingo
ab4779ffcf move foreign function interface to its own module
* libguile/foreign.h:
* libguile/init.c: Change so that init just registers an extension,
  later called by foreign.scm.

* libguile/foreign.c (scm_init_foreign): Define constants for the
  various foreign types.

* module/Makefile.am:
* module/system/foreign.scm: New module, for the foreign function
  interface.
2010-01-26 22:56:41 +01:00