summaryrefslogtreecommitdiffstats
path: root/ffi.h
Commit message (Collapse)AuthorAgeFilesLines
* Better identify functions that misuse COBJ-s and hashes.Kaz Kylheku2018-11-071-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In this patch, the cobj_handle, cobj_ops and variants of gethash get an additional argument to identify the caller. Many functions are updated to pass this down. * buf.c (buf_strm): Pass self name to cobj_handle. * eval.c (env_fbind, env_vbind, rt_defvarl, me_case): Pass self name to gethash_c or gethash_e. (load): Pass self name to read_eval_stream and read_compiled_file. (reg_symacro): Pass situation-identifying string to gethash_c. * ffi.c (ffi_type_struct_checked, ffi_closure_struct_checked, ffi_call_desc_checked, uni_struct_checked): Take self name parameter, and pass down to cobj_handle. (ffi_get_type, ffi_get_lisp_type): Take self name and pass down to ffi_type_struct_checked. (union_get_ptr): Take self name and pass to uni_struct_checked. (ffi_union_in, ffi_union_put): Pass self name to union_get_ptr. (ffi_type_compile): Pass self name to ffi_get_lisp_type. (ffi_make_call_desc): Pass self name to ffi_type_struct_checked, ffi_get_type and ffi_call_desc_checked. (ffi_make_closure): Pass self name to ffi_call_desc_checked. (ffi_closure_get_fptr): Take self name, pass to ffi_closure_struct_checked. (ffi_typedef, ffi_size, ffi_alignof, ffi_offsetof, ffi_arraysize, ffi_elemsize, ffi_elemtype, ffi_put_into, ffi_put, ffi_in, ffi_get, ffi_out, make_carray): Pass self name to ffi_closure_struct_checked. (carray_struct_checked): Take self name, pass to cobj_handle. (carray_set_length, carray_dup, carray_own, carray_free, carray_type, length_carray, copy_carray, carray_ptr, buf_carray, vec_carray, list_carray, carray_ref, carray_refset, carray_sub, carray_replace, carray_get_common, carray_put_common, unum_carray, num_carray, put_carray, fill_carray): Pass self name to carray_struct_checked. (carray_blank, carray_buf, carray_cptr): Pass self name ffi_type_struct_checked. (carray_pun): Pass self name to carray_struct_checked and ffi_type_struct_checked. (make_union): Pass self name to ffi_type_struct_checked. (union_members, union_get, union_put, union_in, union_out): Pass self name to uni_struct_checked. (make_zstruct, zero_fill, put_obj, get_obj, fill_obj): Pass self-name to ffi_type_struct_checked. * ffi.h (ffi_closure_get_fptr, union_get_ptr): Declarations updated. * filter.c (trie_add): Pass self-name to gethash_l. * hash.c (make_similar_hash, copy_hash, hash_count, get_hash_userdata, set_hash_userdata, hash_begin, hash_next, hash_uni, hash_diff, hash_isec): Pass self name to cobj_handle. (gethash_c, gethash_e): Take self name parameter and pass down to cobj_handle. (gethash_f): Take self parameter and pass down to gethash_e. (gethash, inhash, gethash_n, sethash, pushhash, remhash, clearhash, hash_update_1): Pass self name to gethash_e or gethash_c. * hash.h (gethash_c, gethash_e, gethash_f): Declarations updated. (gethash_l): Take self name, and pass down to gethash_c. * lib.c (class_check): Take self name parameter and use in type mismatch diagnostic. (use_sym, unuse_sym, symbol_needs_prefix, find_symbol, intern, unintern, intern_fallback, unique, in, sel, obj_print_impl, populate_obj_hash, obj_hash_merge): Pass self name to gethash_f or gethash_l. (symbol_visible, obj_init): Pass situation-identifying string to gethash_e. (cobj_handle, cobj_ops): Take self name parameter and pass down to class_check. * lib.h (class_check, cobj_handle, cobj_ops): Declarations updated. * match.c (v_load): Pass self name to read_compiled_file and read_eval_stream. * parser.c (get_parser_impl): Take self name and pass to cobj_handle. (ensure_parser): Pass situation-identifying string to gethash_c. (parser_circ_def): Pass self-name to gethash_c. (lisp_parser_impl): Pass self name to get_parser_impl and class_check. (lisp_parse, nread, iread): Pass self-name to lisp_parser_impl. (read_file_common): Take self name parameter and pass down to get_parser_impl. (read_eval_stream, read_compiled_file): Take self name and pass down to read_file_common. (load_rcfile): Pass situation-identifying string to read_eval_streem. (get_visible_syms): Pass situation-identifying string to gethash_c. (parser_errors, parser_eof): Pass self name to cobj_handle. * parser.h (read_eval_stream, read_compiled_file): Declarations updated. * parser.y (rlset): Pass self name to gethash_c. * rand.c (make_random_state, random_state_get_vec,l random_fixnum, random_float): Pass self name to cobj_handle. * regex.c (regex_source, regex_print, regex_run): Pass self-name to cobj_handle. (regex_machine_init): Take self name param and pass to cobj_handle. (search_regex, match_regex, match_regex_right, regex_prefix_match, read_until_match): Pass self-name to regex_machine_init. * stream.c (stdio_get_fd): Pass self name to cobj_handle. (generic_get_line): Get COBJ operations via unsafe, diret object access rather than cobj_ops. (set_mode_props): Get object handle via unsafe, direct object access. (stream_fd, sock_family, sock_type, sock_peer, set_sock_peer, get_string_from_stream, get_list_from_stream, stream_set_prop, stream_get_prop, close_stream, get_error, get_error_str, clear_error, get_line, get_char, get_byte, unget_char, unget_byte, put_buf, fill_buf, put_string, put_char, put_byte, flush_stream, seek_stream, truncate_stream, get_indent_mode, test_set_indent_mode, set_indent_mode, get_indent, set_indent, inc_indent, width_check, force_break, get_set_ctx, get_ctx): Pass self name to cobj_ops. (make_delegate_stream): Take self name parameter, pass down to cobj_ops. (record_adapter): Pass self name down to make_delegate_stream. (format): Pass self name to class_check. * struct.c (stype_handle): Pass self name to cobj_handle. (make_struct_type): Pass self name to class_check. * txr.c (read_eval_stream_noerr): Take self name parameter, pass to read_eval_stream. (txr_main): Pass istuation-identifying string to read_compiled_file and read_eval_stream_noerr. * unwind.c (revive_cont): Pass self-name to cobj_handle. * vm.c (vm_desc_struct): Take self name parameter, pass to cobj_handle. (vm_desc_nlevels, vm_desc_nregs, vm_desc_bytecode, vm_desc_datavec, vm_desc_symvec, vm_execute_toplevel, vm_execute_closure, vm_closure_entry): Pass self name to vm_desc_struct. (vm_closure_struct): Take self name parameter, pass to cobj_handle.
* Copyright year bump 2018.Kaz Kylheku2018-02-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * LICENSE, LICENSE-CYG, METALICENSE, Makefile, args.c, args.h, arith.c, arith.h, buf.c, buf.h, cadr.c, cadr.h, combi.c, combi.h, configure, debug.c, debug.h, eval.c, eval.h, ffi.c, ffi.h, filter.c, filter.h, ftw.c, ftw.h, gc.c, gc.h, glob.c, glob.h, hash.c, hash.h, itypes.c, itypes.h, jmp.S, lib.c, lib.h, lisplib.c, lisplib.h, match.c, match.h, parser.c, parser.h, parser.l, parser.y, protsym.c, rand.c, rand.h, regex.c, regex.h, share/txr/stdlib/awk.tl, share/txr/stdlib/build.tl, share/txr/stdlib/cadr.tl, share/txr/stdlib/conv.tl, share/txr/stdlib/doloop.tl, share/txr/stdlib/error.tl, share/txr/stdlib/except.tl, share/txr/stdlib/ffi.tl, share/txr/stdlib/getopts.tl, share/txr/stdlib/getput.tl, share/txr/stdlib/hash.tl, share/txr/stdlib/ifa.tl, share/txr/stdlib/keyparams.tl, share/txr/stdlib/op.tl, share/txr/stdlib/package.tl, share/txr/stdlib/path-test.tl, share/txr/stdlib/place.tl, share/txr/stdlib/pmac.tl, share/txr/stdlib/socket.tl, share/txr/stdlib/stream-wrap.tl, share/txr/stdlib/struct.tl, share/txr/stdlib/tagbody.tl, share/txr/stdlib/termios.tl, share/txr/stdlib/txr-case.tl, share/txr/stdlib/type.tl, share/txr/stdlib/with-resources.tl, share/txr/stdlib/with-stream.tl, share/txr/stdlib/yield.tl, signal.c, signal.h, socket.c, socket.h, stream.c, stream.h, struct.c, struct.h, strudel.c, strudel.h, sysif.c, sysif.h, syslog.c, syslog.h, termios.c, termios.h, txr.1, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h, win/cleansvg.txr: Extended Copyright line to 2018.
* ffi: new FFI type I/O functions.Kaz Kylheku2017-08-161-0/+3
| | | | | | | | | * ffi.c (put_obj, get_obj, fill_obj): New functions. (ffi_init): put-obj, get-obj, fill-obj intrinsics registered. * ffi.h (put_obj, get_obj, fill_obj): Declared. * txr.1: Documented.
* ffi: new buf-carray function.Kaz Kylheku2017-08-081-0/+2
| | | | | | | | | * ffi.c (buf_carray): New function. (ffi_init): Registered buf-carray intrinsic. * ffi.c (buf_carray): Declared. * txr.1: Documented.
* ffi: add offset argument to ffi buffer functions.Kaz Kylheku2017-07-161-4/+4
| | | | | | | | | | | | | * ffi.c (ffi_put_into, ffi_in, ffi_get, ffi_out): New offset parameter. (ffi_init): Re-register ffi-put-into, ffi-in, ffi-get and ffi-out with new optional parameter. * ffi.c (ffi_put_into, ffi_in, ffi_get, ffi_out): Declarations updated. * txr.1: Documented new argument on ffi-put-into, ffi-in and ffi-get. The documentation for ffi-out doesn't exist!
* carray: add offset to carray-buf.Kaz Kylheku2017-07-151-2/+2
| | | | | | | | | | | | | | * ffi.c (struct carray): New member, offs. (make_carray): Initiialize offs member from new argument. (copy_carray, carray_blank, carry_ptr, carray_sub, carray_pun, carray_unum, carray_num): Pass zero offset to (carray_buf): New optional parameter off_in. (carray_buf_sync): Handle offset. (ffi_init): Update registration of carray-buf. * ffi.h (make_carray, carray_buf): Declaration updated. * txr.1: Documented.
* ffi: new function, zero-fill.Kaz Kylheku2017-07-091-0/+1
| | | | | | | | | * ffi.c (zero_fill): New function. (ffi_init): zero-fill intrinsic registered. * ffi.h (zero_fill): Declared. * txr.1: Documented.
* ffi: new make-zstruct function and znew macro.Kaz Kylheku2017-07-021-0/+1
| | | | | | | | | | | | | * ffi.c (make_zstruct): New function. (ffi_init): Register make-zstruct instrinsic. * ffi.h (make_zstruct): Declared. * lisplib.c (ffi_set_entries): Add znew to autload list. * share/txr/stdlib/ffi.tl (znew): New macro. * txr.1: Documented make-zstruct and znew.
* ffi: new ffi-type-operator-p and ffi-type-p.Kaz Kylheku2017-06-301-0/+2
| | | | | | | | | | * ffi.c (ffi_type_operator_p, ffi_type_p): New functions. (ffi_init): Register ffi-type-operator-p and ffi-type-p intrinsics. * ffi.h (ffi_type_operator_p, ffi_type_p): Declared. * txr.1: Documented.
* ffi: make-union can initialize.Kaz Kylheku2017-06-291-1/+1
| | | | | | | | | | | * ffi.c (make_union): Two arguments added. These are optional. (ffi_init): Update registration of make-union as three-parameter function, with one required arg. * ffi.h (make_union): Declaration updated. * txr.1: Documented.
* ffi: new enumed type operator: enums with base type.Kaz Kylheku2017-06-271-1/+1
| | | | | | | | | | * ffi.c (enumed_s): New symbol variable. (ffi_type_compile): New case for enumed type op. (ffi_init): Initialize enumed_s. * ffi.h (enumed_s): Declared. * txr.1: enumed documented.
* ffi: provide support for unions.Kaz Kylheku2017-06-231-1/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | * ffi.c (union_s): New symbol variable. (ffi_find_memb, ffi_memb_not_found): New static functions. (ffi_union_in, ffi_union_put, ffi_union_get): New static functions. (make_ffi_type_union): New static function. (ffi_struct_compile): Handle union syntax using ffi_struct_compile to compile the member definitions to types, and make_ffi_type_union to produce the type node. (struct uni): New struct type. (uni_struct, uni_struct_checked): New static functions. (union_destroy_op, union_mark_op): New static functions. (union_ops): New static struct. (make_union_common, make_union_tft): New static functions. (union_get_ptr, make_union, union_members, union_get, union_put, union_in, union_out): New functions. (ffi_init): Initialize union_s. Register intrinsics make-union, union-members, union-get, union-put, union-in, union-out. * ffi.h (union_s, union_get_ptr, make_union, union_members, union_get, union_put, union_in, union_out): Declared. * txr.1: Documented unions.
* ffi: bool type.Kaz Kylheku2017-06-201-0/+2
| | | | | | | | | | | | * ffi.c (bool_s): New symbol variable. (ffi_bool_put, ffi_bool_get): New static functions. (ffi_type_compile): Handle (bool <type>) parametrized type. (ffi_init_types): Register bool typedef for (bool uchar). (ffi_init): Initialize bool_s. * ffi.h (bool_s): Declared. * txr.1: Documented.
* ffi: copy-carray, hooked into copy.Kaz Kylheku2017-06-151-0/+1
| | | | | | | | | | | | * ffi.c (copy_carray): New function (ffi_init): Register copy-carray intrinsic. * ffi.h (copy_carray): Declared. * lib.c (copy): Call copy_array for carray objects. * txr.1: Documented copy-carray and updated copy description.
* ffi: new put-carray and fill-carray functions.Kaz Kylheku2017-06-151-0/+2
| | | | | | | | | | * ffi.c (put_carray, fill_carray): New functions. (ffi_init): put-carray and fill-carray intrinsics registered. * ffi.h (put_carray, fill_carray): Declared. * txr.1: Documented.
* ffi: new integer-carray conversion functions.Kaz Kylheku2017-06-141-0/+4
| | | | | | | | | | | | * ffi.c (carray_unum, carray_num, unum_carray, num_carray): New functions. (ffi_init): New intrinsics registered: carray-unum, carray-num, unum-carray, num-carray. * ffi.h (carray_unum, carray_num, unum_carray, num_carray): Declared. * txr.1: Documented.
* ffi: add carrayp function.Kaz Kylheku2017-06-121-0/+1
| | | | | | | | | * ffi.c (carrayp): New function. (ffi_init): Register carrayp intrinsic. * ffi.h (carrayp): Declared. * txr.1: Documented.
* ffi: new carray-replace function.Kaz Kylheku2017-06-111-0/+1
| | | | | | | | | | | | | | Thanks to this (set [ca from..to] list) works. * ffi.c (carray_replace): New function. (ffi_init): Register carray-replace intrinsic. * ffi.h (carray_replace): Declared. * ffi.c (replace): Hook in carray_replace. * txr.1: Mention carray under replace, and document carray-replace.
* ffi: new function, carray-pun.Kaz Kylheku2017-06-111-0/+1
| | | | | | | | | * ffi.c (carray_pun): New function. (ffi_init): Registered carray-pun intrinsic. * ffi.h (carray_pun): Declared. * txr.1: Documented.
* ffi: handle sub operation in carray.Kaz Kylheku2017-06-111-0/+1
| | | | | | | | | | | | | | | | Thus, [ca 3..5] syntax works for slice extraction. However, this works referentially, not by making a copy. The extracted subarray points to the original memory, until carray-dup is invoked on it. * ffi.c (carray_sub): New function. (ffi_init): carray-sub intrinsic registered. * ffi.h (carray_sub): Declared. * lib.c (sub): Handle carray via carray_sub. * txr.1: Documented changes in sub.
* ffi: support sel operation on carray.Kaz Kylheku2017-06-111-0/+1
| | | | | | | | | | | | | | | | | | | | Thus (select ca '(0 3 4 ...)) works and so does the sytnax [ca '(0 3 4 ...)]. This is inefficiently implemented. The selected elements are extracted to a list which is then converted to a carray of the same kind agan. * ffi.c (carray_list): New function. (ffi_init): Register carray-list intrinsic. * ffi.h (carray_list): Declared. * lib.c (make_like): Add carray case, so we can turn a list into a carray based on an example carray. This uses carray_list, with the type pulled from the original carray. The target isn't null terminated. (sel): Handle carray via vector case. * txr.1: Document changes in select and make-like.
* ffi: new carray-get and carray-put functions.Kaz Kylheku2017-06-101-0/+4
| | | | | | | | | | | | | | | | | * ffi.c (struct carray): New member, artype. (carray_mark_op): Mark artype member. (make_carray): Initialize artype to nil. (carray_ensure_artype, carray_get_common, carray_put_common): New static functions. (carray_get, carray_getz, carray_put, carray_putz): New functions. (ffi_init): Register intrinsics carray-get, carray-getz, carray-put, carray-putz. * ffi.h (carray_get, carray_getz, carray_put, carray_putz): Declared. * txr.1: Documented new functions.
* Rename carray_get.Kaz Kylheku2017-06-101-1/+1
| | | | | | | | * ffi.c (carray_get): Renamed to carray_ptr. (ffi_carray_put): Follow rename. * ffi.h (carray_get): Declaration removed. (carray_put): Declared.
* ffi: support bitfields on types narrower than int.Kaz Kylheku2017-06-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * ffi.c (bit_s): New symbol variable. (ffi_generic_sbit_put, ffi_generic_sbit_get, ffi_generic_ubit_put, ffi_generic_ubit_get): New static functions. (bitfield_syntax_p): Include bit symbol in the check. (make_ffi_type_pointer): Zero size is no longer an early rejection test for bitfields; don't rely on it. (make_ffi_type_struct): Revise the member calculating loop to handle bitfields of various sizes. If a bitfield follows one of a different size, it starts a new cell even if the previous one has room, et cetera. The masking and shifting is set up to work on cells of int size; however, the new ffi_generic_s?bit_{put,get} functions use a temporary buffer and transfer just the right number of bytes to and from the actual buffer. (ffi_struct_compile): The check against incomplete type members only needs to test size zero; bitfields have nonzero size now, which is the true size of the underlying storage unit. They also have true alignment, which is used in make_ffi_type_struct rather than hard-coding to alignof (int). New syntax (bit width type) is now handled, where type can be any of the signed and unsigned integral types up to int32 and int. The endian types are not supported for now. (ffi_typedef, ffi_size, ffi_alignof): Zero size is no longer an early rejection test for bitfields; don't rely on it. (ffi_init): Initialize bit_s. * ffi.h (bit_s): Declared. * txr.1: Documented.
* ffi: big and little endian types.Kaz Kylheku2017-06-041-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | * ffi.c (be_uint16_s, be_int16_s, be_uint32_s, be_int32_s, be_uint64_s, be_int64_s, be_float_s, be_double_s, le_uint16_s, le_int16_s, le_uint32_s, le_int32_s, le_uint64_s, le_int64_s, le_float_s, le_double_s): New symbol variables. (ffi_be_i16_put, ffi_be_i16_get, ffi_be_u16_put, ffi_be_u16_get, ffi_le_i16_put, ffi_le_i16_get, ffi_le_u16_put, ffi_le_u16_get, ffi_be_i32_put, ffi_be_i32_get, ffi_be_u32_put, ffi_be_u32_get, ffi_le_i32_put, ffi_le_i32_get, ffi_le_u32_put, ffi_le_u32_get, ffi_be_i64_put, ffi_be_i64_get, ffi_be_u64_put, ffi_be_u64_get, ffi_le_i64_put, ffi_le_i64_get, ffi_le_u64_put, ffi_le_u64_get, ffi_be_float_put, ffi_be_float_get, ffi_le_float_put, ffi_le_float_get, ffi_be_double_put, ffi_be_double_get, ffi_le_double_put, ffi_le_double_get): New static functions. (ffi_init_types): Register new type symbols via typedef mechanism. (ffi_init): Initialize new symbol variables. * ffi.c (be_uint16_s, be_int16_s, be_uint32_s, be_int32_s, be_uint64_s, be_int64_s, be_float_s, be_double_s, le_uint16_s, le_int16_s, le_uint32_s, le_int32_s, le_uint64_s, le_int64_s, le_float_s, le_double_s): Declared.
* ffi: new type operator align for customizing alignment.Kaz Kylheku2017-06-041-0/+2
| | | | | | | | | | | | | | | | | | | | | | | * ffi.c (align_s): New symbol variable. (struct txr_ffi_type): New function pointer member, clone. (ffi_simple_clone): New static function. (make_ffi_type_builtin, make_ffi_type_pointer, make_ffi_type_enum): Wire in ffi_simple_clone as the clone function. (ffi_struct_clone): New static function. (make_ffi_type_struct): Wire in ffi_struct_clone as the clone function for struct types. (ffi_array_clone): New static function. (make_ffi_type_array): Wire in ffi_array_clone as the clone function for array types. (ffi_type_copy): New static function. (ffi_type_compile): Recognize new (align <num> <type>) syntax. This works by cloning <type>, and then punching in the specified alignment. The align syntax then denotes this modified type. (ffi_init): Initialize align_s. * ffi.h (align_s): Declared.
* ffi: functions and macros for basic type properties.Kaz Kylheku2017-06-021-0/+5
| | | | | | | | | | | | | | | | | | * ffi.c (ffi_alignof, ffi_offsetof, ffi_arraysize, ffi_elemsize, ffi_elemtype): New functions. (ffi_init): Registered intrinsics ffi-alignof, ffi-offsetof, ffi-arraysize, ffi-elemsize, ffi-elemtype. * ffi.h (ffi_alignof, ffi_offsetof, ffi_arraysize, ffi_elemsize, ffi_elemtype): Declared. * lisplib.c (ffi_set_entries): New autoload entries alignof, offsetof, arraysize, elemsize, elemtype. * share/txr/stdlib/ffi.tl (alignof, offsetof, arraysize, elemsize, elemtype): New macros. * txr.1: Documented new functions and macros.
* ffi: new feature: enums.Kaz Kylheku2017-05-311-0/+2
| | | | | | | | | | | | | | | | * ffi.c (enum_s): New symbol variable. (struct txr_ffi_type): New member, sym_num, num_sym. (ffi_enum_type_mark): New static function. (ffi_type_enum_ops): New static structure. (ffi_enum_put, ffi_enum_get, ffi_enum_rput, ffi_enum_rget): New static functions. (make_ffi_type_enum): New static function. (ffi_type_compile): Extend with enum syntax. (ffi_init): Initialize enum_s with new interned symbol. * ffi.c (enum_s): Declared. * txr.1: Documented.
* ffi: bitfield support.Kaz Kylheku2017-05-251-0/+2
| | | | | | | | | | | | | | | | | | | | | | | * ffi.c (sbit_s, ubit_s): New symbol variables. (struct txr_ffi_type): New members, shift and mask. (ffi_sbit_put, ffi_sbit_get, ffi_ubit_put, ffi_ubit_get, bitfield_syntax_p): New static functions. (make_ffi_type_pointer): Disallow pointers to bitfields. (make_ffi_type_struct): Process bitfield members and set up shifts and masks accordingly. Recently introduced bug fixed here at the same time: the alignment calculation for each member must be done top-of-loop. (ffi_struct_compile): Exclude bitfields from the check against members with zero type. Compile the bitfield syntax. (ffi_typedef): Do not allow typedefs of bitfield type. Not only doesn't this make sense, but bitfield types are destructively modified in make_ffi_type_struct: they are imbued with a mask and offset tied to their position in a particular struct. * ffi.h (sbit_s, ubit_s): Delared. * txr.1: Documented bitfields.
* ffi: val type.Kaz Kylheku2017-05-231-0/+2
| | | | | | | | | | | * ffi.c (val_s): New symbol variable. (ffi_val_put, ffi_val_get): New functions. (ffi_init_types): Register val type. (ffi_init): Initialize val_s. * ffi.h (val_s): Declared. * txr.1: Documented.
* ffi: overhaul ffi-call API and document it.Kaz Kylheku2017-05-201-1/+1
| | | | | | | | | | | | | | | * ffi.c (ffi_call_wrap): Take struct args * parameters rather than a list. Check that number of arguments matches required number from call desc. No need to build argument array any more; we just refer to the one in args. Also, the first two parameters are reversed for consistency with other functions. (ffi_init): Update registration of ffi-call to reflect type change. * ffi.h (ffi_call_wrap): Declaration updated. * txr.1: Documented ffi-call.
* ffi: new carray-buf-sync function.Kaz Kylheku2017-05-201-0/+1
| | | | | | | | | * ffi.c (carray_buf_sync): New function. (ffi_init): carray-buf-sync intrinsic registered. * ffi.h (carray_buf_sync): Declared. * txr.1: Documented.
* ffi: new function, carray-cptr.Kaz Kylheku2017-05-191-0/+1
| | | | | | | | | * ffi.c (carray_cptr): New function. (ffi_init): Registered intrinsic. * ffi.h (carray_cptr): Declared. * txr.1: Documented.
* ffi: new carray_buf function.Kaz Kylheku2017-05-171-0/+1
| | | | | | | | | Treat a buffer through a carray view. * ffi.c (carray_buf): New function. (ffi_init): Register carray-buf intrinsic. * ffi.h (carray_buf): Declared.
* ffi: carrays able to reference objects.Kaz Kylheku2017-05-171-1/+1
| | | | | | | | | | | | | | | | | | | | | The idea here is that carrays can have a pointer to some area that is owned by another object. So that the area doesn't disappear when the other object becomes garbage, a carray which does this maintains a pointer to that other object. * ffi.c (ffi_carray_get): Pass new parameter to make_carray. (struct carray): New member, ref. (carray_mark_op): Mark new ref member. (make_carray): New parameter: the object which is stored in the structure as ref. (carray_dup): Null out the ref member. When a carray is duplicated, it owns its own buffer, and henceforth mustn't prevent the original object from being reclaimed. (carray_own): Don't allow a carray to claim ownership of the pointer if it references another object; we have no protocol to inform that other object. * ffi.h (make_carray): Declaration updated.
* ffi: carray type to round out semantics.Kaz Kylheku2017-05-171-1/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The carray type deals with C array passing conventions as a pointer to the first element of an array of unknown size. It fills in the functionality gap not covered by array and varray. * ffi.c (carray_s): New symbol variable. (ffi_carray_get, ffi_carray_put): New static functions. (ffi_type_compile): Handle (carray <type>) syntax. (struct carray): New struct type. (carray_struct, carray_struct_checked, carray_print_op, carray_mark_op, carray_destroy_op): New static functions. (carray_borrowed_ops, carray_owned_ops): New static structs. (make_carray, carray_set_length, carray_dup, carray_own, carray_free, carray_type, length_carray, carray_get, carray_vec, carray_blank, vec_carray, list_carray, carray_ref, carray_refset): New functions. (ffi_init): Initialize carray_s. Register carray-set_length, carray_dup, carray_own, carray-free, carray_type, length_carray, carray-vec, array_blank, vec_carray, list_carray, carray_ref and carray-refset intrinsics. * ffi.h (carray_s): Declared. (make_carray, carray_set_length, carray_dup, carray_own, carray_free, carray_type, length_carray, carray_get, carray_vec, carray_blank, vec_carray, list_carray, carray_ref, carray_refset): Declared.
* ffi: support programmable abort return value.Kaz Kylheku2017-05-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | * ffi.c (stuct txr_ffi_closure): New member, abort_retval. (ffi_closure_mark_op): Mark the new member. (ffi_closure_dispatch_safe): Implement the abort_retval. If it is not nil, use put to place the value into the return buffer. There is a risk that this could also throw an exception, which is no longer protected: programer's problem. (ffi_make_closure): New abort_ret_in argument, which is defaulted and stored. (ffi_init): Update registration of ffi-make-closure to reflect new argument. * ffi.h (ffi_make_closure): Declaration updated. * share/txr/stdlib/ffi.tl (sys:deffi-cb-expander): Add abort-retval parameter; insert into ffi-make-closure call. (deffi-cb): Take optional abort-retval expression; pass it down to the expander function. (deffi-cb-unsafe): Pass nil as abort-retval down to expander. * txr.1: Documented.
* ffi: a measure of safety for callbacks.Kaz Kylheku2017-05-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We don't want, by default, for callbacks to capture delimited continuations across foreign code, or perpetrate non-local transfers across foreign code. Here, we take an approach similar for what was done in ftw_wrap. * ffi.c (s_exit_point): New global variable with internal linkage. (ffi_call_wrap): If s_exit_point isn't nil, then it means that the callback intercepted a nonlocal transfer and stored its exit point. We resume the transfer to that exit point instead of returning normally. (ffi_closure_dispatch_safe): New static function. (ffi_make_closure): Support a new argument which indicates whether to make a closure which uses ffi_closure_dispatch_safe, or ffi_closure_dispatch. (ffi_init): Update registration of ffi-make-closure intrinsic. * ffi.h (ffi_make_closure): Declaration updated. * share/txr/stdlib/ffi.tl (sys:deffi-cb-expander): New function. (deffi-cb): Macro internals replaced by call to new function. (deffi-cb-safe): New macro. * txr.1: Documentation of ffi-make-closure updated. New deffi-cb-unsafe macro documented.
* ffi: bugfix: all in calls must fall back on get.Kaz Kylheku2017-05-071-1/+1
| | | | | | | | | | | | | | | | * ffi.c (ffi_ptr_out_in, ffi_ptr_out_s_in): If the target type has no in handler, fall back on its get. Here, it is without regard for the copy flag, because a zero value of that flag just indicates that the ptr-out itself is passed by-value. The target object is never by value (ffi_in): Add copy flag parameter, so the full interface is exposed, like in ffi_out. Fall back on get, if there is no in and the copy flag is true. Just return the original object if the type has no in, and copy is false. (ffi_init): Registration of ffi-in adjusted to four parameters. * ffi.h (ffi_in): Declaration updated.
* ffi: ffi-size function.Kaz Kylheku2017-05-061-0/+1
| | | | | | | | | This will support a sizeof macro. * ffi.c (ffi_size): New function. (ffi_init): Register ffi-size intrinsic. * ffi.h (ffi_size): Declared.
* ffi: functions for type-system-driven buffer coding.Kaz Kylheku2017-05-041-0/+5
| | | | | | | | | | * ffi.c (ffi_put_into, ffi_put, ffi_in, ffi_get, ffi_out): New functions. (ffi_init): ffi-put-into, ffi-put, ffi-in, ffi-get, ffi-out: intrinsics registered. * ffi.h (ffi_put_into, ffi_put, ffi_in, ffi_get, ffi_out): Declared.
* ffi: new bstr type.Kaz Kylheku2017-05-041-1/+1
| | | | | | | | | | | | | | | | | | The bstr type is like str, but doesn't perform UTF-8 conversion. The C data is assumed to be null terminated byte strings representing code points U+0000 through U+00FF. * ffi.c (bstr_s, bstr_d_s): New symbol variables. (ffi_bstr_put, ffi_bstr_get, ffi_bstr_d_get): New static functions. (ffi_init_types): Register bstr and bstr-d types. (ffi_init): Initialize bstr_s and bstr_d_s. * ffi.h (bstr_s, bstr_d_s): Declared. * lib.c (chk_strdup_8bit, string_8bit): New function. * lib.h (chk_strdup_8bit, string_8bit): Declared.
* ffi: implement bchar type.Kaz Kylheku2017-05-041-1/+1
| | | | | | | | | | | | bchar is like uchar, except that in the decode direction, it produces character objects rather than integers. * ffi.c (bchar_s): New symbol variable. (ffi_bchar_get): New static function. (ffi_init_types): Register bchar type. (ffi_init): Initialize bchar_s. * ffi.h (bchar_s): Declared.
* ffi: new ptr-out-s type.Kaz Kylheku2017-05-031-1/+1
| | | | | | | | | | | | | | | | | | One more ptr type is useful. This type is for objects returned via pointers embedded in arrays or structures, whereby the callee establishes both the pointer and the data. This is similar to ptr-out-d; the difference is that the data has an indefinite lifetime ("s" denotes "static") and so the pointer is not freed after the call takes place and the data is extracted into Lisp objects. * ffi.c (ptr_out_s_s): New symbol variable. (ffi_ptr_out_s_in): New function. (ffi_type_compile): Handle new ptr_out_s_s. (ffi_init): Initialize ptr_out_s. * ffi.h (ptr_out_s_s): Declared.
* ffi: remove ffi-copy-type.Kaz Kylheku2017-05-021-1/+0
| | | | | | | | | | | | | | | | | We don't need type copying because the need for this was driven by the rtvec implementation, which assigned a unique rtidx to the nodes in a type tree, requiring like types to be separately instantiated. * ffi.c (struct txr_ffi_type): Remove member dup. (ffi_struct_dup, ffi_ptr_dup): Function removed. (make_ffi_type_builtin, make_ffi_type_struct, make_ffi_type_array): Don't initialize dup. (ffi_copy_type): Function removed. (ffi_type_compile): don't call ffi_copy_type. (ffi_init): ffi-copy-type intrinsic removed. * ffi.h (ffi_copy_type): Declaration removed.
* ffi: simple typedef mechanism.Kaz Kylheku2017-05-011-0/+1
| | | | | | | | | | | | * ffi.c (ffi_typedef_hash): New static variable. (ffi_type_compile): Handle undefined atom case by trying through typedef hash. (ffi_typedef): New function. (ffi_init): gc-protect ffi_type_compile variable and initialize it with a hash table. Register ffi-typedef intrinsic. * ffi.h (ffi_typedef): Declared
* ffi: support for duplicating type objects.Kaz Kylheku2017-05-011-0/+1
| | | | | | | | | | | | * ffi.c (struct txr_ffi_type): New member, dup. (ffi_struct_dup, ffi_ptr_dup): New static functions. (make_ffi_type_pointer, make_ffi_type_struct, make_ffi_type_array): Set up dup virtual function for these types. (ffi_copy_type): New function. (ffi_init): Register ffi-copy-type intrinsic. * ffi.h (ffi_copy_type): Declared.
* ffi: implementing FFI callback closures.Kaz Kylheku2017-04-301-1/+5
| | | | | | | | | | | | | | | | | | | * ffi.c (closure_s, ffi_closure_s): New symbol vars. (struct txr_ffi_closure): New type. (ffi_closure_struct, ffi_closure_struct_checked, ffi_closure_print_op, ffi_closure_destroy_op, ffi_closure_mark_op): New static functions. (ffi_closure_ops): New static struct. (ffi_closure_put): New static function. (ffi_type_compile): Handle closure_s to support closure type specifier. (ffi_closure_dispatch): New static function. (ffi_make_closure, ffi_closure_get_fptr): New function. (ffi_init): Initialize closure_ and ffi_closure_s. Register ffi-make-closure intrinsic. * ffi.c (closure_s, ffi_closure_s, ffi_make_closure, ffi_closure_get_fptr): Likewise.
* ffi: housecleaning: reorder type sym declarations.Kaz Kylheku2017-04-301-5/+5
| | | | | | | | | | | | * ffi.c: Move declarations of array_s and zarray_s after void_s, to keep built-in FFI types together. Eliminate some blank lines. (ffi_init): Move initialization of void_s to to match declaration order. * ffi.h: Update declarations of type symbol variables to match ffi.c. (struct_s): Now declared.
* ffi: add support for wchar_t type.Kaz Kylheku2017-04-291-1/+1
| | | | | | | | | | | | We have wstr strings already but no wchar type. * ffi.c (wchar_s): New symbol variable. (ffi_type_wchar): New macro. (ffi_wchar_put, ffi_wchar_get): New static functions. (ffi_type_compile): Handle wchar_s. (ffi_init): Initialize wchar_s. * ffi.h (wchar_s): Declared.