summaryrefslogtreecommitdiff
path: root/libguile/foreign.h
AgeCommit message (Collapse)AuthorFilesLines
2013-10-18Foreign procedures are RTL programsAndy Wingo1-1/+5
* libguile/foreign.c: Convert to using RTL stubs. Because RTL code has different GC characteristics than objcode -- it's mostly assumed that RTL code will never go away -- we go ahead and pre-generate code for 100 arguments. This is actually less memory than the stack VM code, and doesn't require any relocations at load-time: bonus! We'll cross the >=100 args bridge if we ever come to it. (get_foreign_stub_code) New function. (scm_i_foreign_arity): New helper, like scm_i_primitive_arity. (cif_to_procedure): Rework to make RTL programs. * libguile/foreign.h: Declare scm_pointer_to_scm and scm_scm_to_pointer. Declare new internal helpers. * libguile/gsubr.c (create_subr): Refactor to set the flags when the object is allocated. * libguile/instructions.h: Define SCM_PACK_RTL_12_12. * libguile/programs.c (scm_i_rtl_program_minimum_arity): Dispatch to scm_i_foreign_arity if the procedure has the FOREIGN flag. * libguile/programs.h (SCM_F_PROGRAM_IS_FOREIGN) (SCM_PROGRAM_IS_FOREIGN): New interfaces. * test-suite/tests/foreign.test ("procedure->pointer"): Add a test for foreign arities.
2012-02-08Merge remote-tracking branch 'origin/stable-2.0'Andy Wingo1-3/+3
Conflicts: GUILE-VERSION libguile/gc-malloc.c libguile/ports.c
2012-02-02Implement scm_to_pointerMark H Weaver1-0/+1
* libguile/foreign.c, libguile/foreign.h (scm_to_pointer): New C function. * test-suite/standalone/test-loose-ends.c: Add test.
2012-02-02leniency in the "unused modules are removed" gc.testAndy Wingo1-3/+2
* libguile/foreign.h: Remove comment about the finalizer bit, as I don't think that is the case any more. * test-suite/tests/gc.test: Ignore flakiness in the gc-modules test.
2011-10-24refactor tc7 and tc16 checksAndy Wingo1-2/+1
* libguile/tags.h (SCM_HAS_TYP7, SCM_HAS_TYP7S, SCM_HAS_TYP16): New macros. * libguile/bytevectors.h (SCM_BYTEVECTOR_P): * libguile/control.h (SCM_PROMPT_P): * libguile/filesys.h (SCM_DIRP): * libguile/fluids.h (SCM_WITH_FLUIDS_P, SCM_FLUID_P) (SCM_I_DYNAMIC_STATE_P): * libguile/foreign.h (SCM_POINTER_P): * libguile/fports.h (SCM_FPORTP): * libguile/frames.h (SCM_VM_FRAME_P): * libguile/hashtab.h (SCM_HASHTABLE_P): * libguile/inline.h (scm_get_byte_or_eof): * libguile/numbers.h (SCM_REALP, SCM_BIGP, SCM_COMPLEXP, SCM_FRACTIONP): * libguile/objcodes.h (SCM_OBJCODE_P): * libguile/ports.h (SCM_OUTPUT_PORT_P): * libguile/programs.h (SCM_PROGRAM_P): * libguile/smob.h (SCM_SMOB_PREDICATE): * libguile/srfi-14.h (SCM_CHARSETP): * libguile/strings.c (IS_STRING): * libguile/strports.h (SCM_STRPORTP): * libguile/symbols.h (scm_is_symbol): * libguile/variable.h (SCM_VARIABLEP): * libguile/vectors.h (SCM_I_IS_VECTOR, SCM_I_IS_NONWEAK_VECTOR): * libguile/vm-i-system.c (call, tail-call, mv-call) * libguile/vm.h (SCM_VM_P, SCM_VM_CONT_P): * libguile/weak-set.c (SCM_WEAK_SET_P): * libguile/weak-table.c (SCM_WEAK_TABLE_P): * libguile/weak-vector.h (SCM_I_WVECTP): Use them.
2011-04-01string->pointer and pointer->string have optional encoding argAndy Wingo1-2/+2
* 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-01-30Add `pointer?'.Ludovic Courtès1-0/+1
* 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-3/+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.
2010-09-06Rename `make-foreign-function' to `pointer->procedure'.Ludovic Courtès1-2/+2
* 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-0/+2
* 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-08-15Add `string->pointer' and `pointer->string' to the FFI.Ludovic Courtès1-1/+4
* 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-07-28Remove unused parameter from `bytevector->pointer'.Ludovic Courtès1-1/+1
* libguile/foreign.c (scm_bytevector_to_pointer): Remove unused LEN parameter. Update docstring.
2010-07-28Use "pointer" instead of "foreign" when dealing with wrapped pointers.Ludovic Courtès1-17/+17
* 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-26Add `dereference-pointer' to `(system foreign)'.Ludovic Courtès1-0/+1
* 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-26Simplify the (system foreign) API.Ludovic Courtès1-45/+15
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-03-20Cosmetic changes in `foreign.c'.Ludovic Courtès1-1/+1
* libguile/foreign.c (unpack, pack): Add `const' qualifier for `type'. Comment. Indent. (scm_i_foreign_call): Add `const' qualifier for `argv'. Punctuate comments. Clarify argument unpacking loop.
2010-02-17Include <libguile/__scm.h> in "foreign.h".Ludovic Courtès1-4/+4
* libguile/foreign.h: Include <libguile/__scm.h>.
2010-01-27add simple foreign finalization, and pointer supportAndy Wingo1-0/+1
* 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-26add `alignof' and `sizeof' Scheme functionsAndy Wingo1-0/+2
* libguile/foreign.h: * libguile/foreign.c (scm_alignof, scm_sizeof): New functions.
2010-01-26implement foreign-callAndy Wingo1-0/+1
* libguile/foreign.h: * libguile/foreign.c (scm_i_foreign_call): New internal function, actually implementing foreign calls. Untested. * libguile/vm-i-system.c (foreign-call): Wire up the call to scm_i_foreign_call.
2010-01-26first pass at implementing low-level foreign functionsAndy Wingo1-0/+23
* 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-26byte access to foreigns via bytevectorsAndy Wingo1-2/+5
* 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-26move foreign function interface to its own moduleAndy Wingo1-1/+1
* 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-26foreign.h presents a more pointer-centric interfaceAndy Wingo1-25/+39
* libguile/foreign.c: * libguile/foreign.h: Rework interface to be more pointer-centric. Details are: (SCM_FOREIGN_TYPE_STRUCT, SCM_FOREIGN_TYPE_POINTER): Removed; now the pointer in a foreign is first-class. If it points to a native type like uint32, then it still has a tag; but if it points to something else, like a struct or a pointer or something, then its type is VOID (i.e., void*). (SCM_FOREIGN_POINTER): Rename from SCM_FOREIGN_OBJECT. (SCM_FOREIGN_VALUE_REF, SCM_FOREIGN_VALUE_SET): Rename from SCM_FOREIGN_OBJECT_REF and SCM_FOREIGN_OBJECT_SET, to indicate that they only work with value types. (SCM_FOREIGN_HAS_FINALIZER): Reserve a bit to indicate if the foreign pointer in question has a finalizer registered. (SCM_FOREIGN_LEN): For void* pointers, optionally store the length in bytes of the associated memory region. (SCM_FOREIGN_VALUE_P): Rename from SCM_FOREIGN_SIMPLE_P. (SCM_VALIDATE_FOREIGN_VALUE): Rename from SCM_VALIDATE_FOREIGN_SIMPLE. (scm_take_foreign_pointer): Rename from scm_c_take_foreign. Remove scm_c_from_foreign. (scm_foreign_type): New accessor. (scm_foreign_ref, scm_foreign_set_x): Take some optional args, used when dereferencing void pointers. * libguile/dynl.h: * libguile/dynl.c (scm_dynamic_pointer): New function, used by scm_dynamic_func. Adapt code to foreign.h changes. * libguile/goops.c (scm_enable_primitive_generic_x) (scm_set_primitive_generic_x): Use the SCM_SET_SUBR_GENERIC macro. * libguile/gsubr.c (create_gsubr): Adapt to API change. * libguile/gsubr.h (SCM_SUBRF, SCM_SUBR_GENERIC): Store the pointer directly, not indirected. * libguile/snarf.h (SCM_DEFINE, SCM_IMMUTABLE_FOREIGN): Store subr pointers directly. Adapt to SCM_FOREIGN_TYPE_VOID change. * libguile/vm-i-system.c (subr-call): Access the void* directly.
2010-01-04add foreign value wrapperAndy Wingo1-0/+87
* libguile/foreign.h: * libguile/foreign.c: New files, implementing simple wrappers around foreign values, such as those that one might link in dynamically from a library. * libguile/tags.h (scm_tc7_foreign): Take a tc7 for foreign values. * libguile.h: * libguile/init.c: Add foreign.h to headers and init. * libguile/print.c (iprin1): Add printer for foreign values. * libguile/gc.c (scm_i_tag_name): Case for foreign values. * libguile/goops.c (scm_class_of, create_standard_classes): Add a class for foreign values. * libguile/evalext.c (scm_self_evaluating_p): Add case for foreign values. * libguile/Makefile.am: Add foreign.[ch] to the build.