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

59 commits

Author SHA1 Message Date
Andy Wingo
a41bed83ab Merge remote-tracking branch 'origin/stable-2.0'
Conflicts:
	libguile/read.c
	test-suite/tests/tree-il.test
2012-02-11 18:14:48 +01:00
Andy Wingo
c2c3bddb1d more efficient scm_string_to_utf8, scm_string_to_utf32
* libguile/bytevectors.c (scm_string_to_utf8): More efficient
  implementation.
  (scm_string_to_utf32): Likewise.
2012-02-10 13:42:15 +01:00
Andy Wingo
0aed71aa51 Revert "add SCM_HEAP_OBJECT_BASE"
This reverts commit 47ed8656db.

Conflicts:

	libguile/foreign.c
2012-01-31 22:58:24 +01:00
Andy Wingo
b2208d2e98 Merge remote-tracking branch 'origin/stable-2.0'
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-12-01 23:31:50 +01:00
Ludovic Courtès
8071964943 Allow overlapping regions to be passed to `bytevector-copy!'.
Reported by Dmitry Chestnykh <dmitry@codingrobots.com>.
Fixes <http://debbugs.gnu.org/10070>.

* libguile/bytevectors.c (scm_bytevector_copy_x): Use `memmove', not
  `memcpy'.

* test-suite/tests/bytevectors.test ("2.2 General
  Operations")["bytevector-copy! overlapping"]: New test.

* doc/ref/api-data.texi (Bytevector Manipulation): Mention possible
  overlapping.
2011-11-20 01:10:58 +01:00
Andy Wingo
0607ebbfcf locking for putc, puts
* 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-11-08 00:55:05 +01:00
Andy Wingo
47ed8656db add SCM_HEAP_OBJECT_BASE
* 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-24 18:59:35 +02:00
Andy Wingo
21041372ed add SCM_{PACK,UNPACK}_POINTER
* 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-24 18:54:04 +02:00
Andy Wingo
8b66aa8f54 Merge remote-tracking branch 'origin/stable-2.0'
Conflicts:
	libguile/bytevectors.c
	libguile/bytevectors.h
	libguile/objcodes.c
	libguile/r6rs-ports.c
	libguile/strings.c
	libguile/vm.c
2011-08-31 09:34:54 +02:00
Andy Wingo
fb031aba42 fix a couple of leaks
* libguile/bytevectors.h:
* libguile/bytevectors.c (scm_c_take_gc_bytevector): Rename this
  internal function, from scm_c_take_bytevector.  This indicates that
  unlike the other scm_take_* functions, this one takes GC-managed
  memory.

* libguile/objcodes.c (scm_objcode_to_bytecode):
* libguile/vm.c (really_make_boot_program): Use
  scm_gc_malloc_pointerless, not scm_malloc.  Thanks to Stefan
  Israelsson Tampe!

* libguile/r6rs-ports.c:
* libguile/strings.c: Adapt to renames.
2011-08-18 12:53:28 +02:00
Andy Wingo
3b08b1c24d minor style fix in bytevectors.c
* libguile/bytevectors.c (SCM_BYTEVECTOR_HEADER_BYTES): Use sizeof
  scm_t_bits, not sizeof SCM.  It's the same, but it seems like the
  right thing.
2011-07-29 09:11:24 +02:00
Andy Wingo
ab4bc85398 Merge remote-tracking branch 'origin/stable-2.0'
Conflicts:
	GUILE-VERSION
	test-suite/tests/srfi-4.test
2011-07-25 18:26:37 +02:00
Ludovic Courtès
4bc95fccad Add type and range checks to the complex generalized vector accessors.
* libguile/bytevectors.c (COMPLEX_ACCESSOR_PROLOGUE, COMPLEX_NATIVE_REF,
  COMPLEX_NATIVE_SET): New macros.
  (bytevector_ref_c32, bytevector_ref_c64): Defined in terms of
  `COMPLEX_NATIVE_REF'.
  (bytevector_set_c32, bytevector_set_c64): Defined in terms of
  `COMPLEX_NATIVE_SET'.
  (bytevector_ref_fns): Make `static'.

* test-suite/tests/srfi-4.test ("c32 vectors")["generalized-vector-ref",
  "generalized-vector-set!", "generalized-vector-ref, out-of-range",
  "generalized-vector-set!, out-of-range"]: New tests.
  ("c64 vectors")["generalized-vector-ref", "generalized-vector-set!",
  "generalized-vector-ref, out-of-range",
  "generalized-vector-set!, out-of-range"]: New tests.
2011-07-01 19:09:29 +02:00
Ludovic Courtès
1e8f939229 Fix unaligned accesses for bytevectors of complex numbers.
* libguile/bytevectors.c (bytevector_ref_c32, bytevector_ref_c64,
  bytevector_set_c32, bytevector_set_c64): Use `memcpy' to avoid
  unaligned accesses.  This fixes SIGBUS on SPARC and possibly other
  alignment-sensitive platforms.
2011-07-01 16:21:21 +02:00
Andy Wingo
871054f08e remove SCM_I_SIZE limits defines
* libguile/__scm.h: Remove defines for SCM_I_SIZE_MAX, SCM_I_SSIZE_MIN,
  and SCM_I_SSIZE_MAX, as there is no longer a scm_t_size / scm_size_t
  type.
* libguile/bytevectors.c (make_bytevector): Replace a use of
  SCM_I_SIZE_MAX with ((size_t) -1).
2011-05-15 15:34:15 +02:00
Andy Wingo
86fb1eb631 merge strictness branch from 2.0 2011-05-13 15:45:43 +02:00
Andy Wingo
d223c3fcdd scm_is_eq for SCM vals, not == or !=
* libguile/bytevectors.c (scm_make_bytevector, STRING_TO_UTF)
  (UTF_TO_STRING):
* libguile/continuations.c (scm_i_check_continuation):
* libguile/expand.h (SCM_EXPANDED_P):
* libguile/fluids.c (scm_i_make_with_fluids):
* libguile/generalized-vectors.c (scm_make_generalized_vector):
* libguile/goops.c (SCM_GOOPS_UNBOUNDP, slot_definition_using_name):
  (scm_c_extend_primitive_generic, more_specificp, scm_make)
* libguile/i18n.c (SCM_VALIDATE_OPTIONAL_LOCALE_COPY):
  (scm_locale_string_to_integer)
* libguile/modules.c (resolve_duplicate_binding):
  (scm_module_reverse_lookup)
* libguile/posix.c (scm_to_resource):
* libguile/r6rs-ports.c (scm_put_bytevector):
* libguile/socket.c (scm_connect, scm_bind, scm_sendto
* libguile/stacks.c (find_prompt):
* libguile/variable.c (scm_variable_ref, scm_variable_bound_p):
* libguile/vm-engine.h (ASSERT_BOUND_VARIABLE, ASSERT_BOUND)
* libguile/vm-i-system.c (VARIABLE_BOUNDP, local_bound)
  (long_local_bound, fluid_ref): Use scm_is_eq to compare, not == / !=.
2011-05-13 13:49:32 +02:00
Andy Wingo
059a588fed bytevectors have internal parent field
* 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-05-07 14:57:15 +02:00
Mark H Weaver
ae255d65c3 Fix bytevectors VALIDATE_REAL to test for reals, not rationals
Reported and fixed by Daniel Llorens <dll@bluewin.ch>.

* libguile/bytevectors.c (VALIDATE_REAL): Test for reals, not rationals.

* test-suite/tests/srfi-4.test (f32 vectors, f64 vectors): Add tests.
2011-03-08 17:52:52 -05:00
Mark H Weaver
73ea546c51 Fix bytevectors VALIDATE_REAL to test for reals, not rationals
Reported and fixed by Daniel Llorens <dll@bluewin.ch>.

* libguile/bytevectors.c (VALIDATE_REAL): Test for reals, not rationals.

* test-suite/tests/srfi-4.test (f32 vectors, f64 vectors): Add tests.
2011-03-08 17:50:47 -05:00
Andy Wingo
4a655e50a3 use scm_from_latin1_symboln for string literals and load-symbol
* libguile/bytevectors.c:
* libguile/eval.c:
* libguile/goops.c:
* libguile/i18n.c:
* libguile/load.c:
* libguile/memoize.c:
* libguile/modules.c:
* libguile/ports.c:
* libguile/print.c:
* libguile/procs.c:
* libguile/programs.c:
* libguile/read.c:
* libguile/script.c:
* libguile/srfi-14.c:
* libguile/stacks.c:
* libguile/strings.c:
* libguile/throw.c:
* libguile/vm.c: Use scm_from_latin1_symboln to make symbols from string
  literals, because they aren't in the user's locale -- they are in
  ASCII, and we can optimize this case.

* libguile/vm-i-loader.c: Also use scm_from_latin1_symboln when loading
  narrow symbols.
2011-01-07 09:18:41 -08:00
Andy Wingo
3ef6650def make-string et al nulls memory if not given an initializer
* 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-12-04 19:31:20 +01:00
Andy Wingo
e25f37271a fix a number of assuptions that a long could hold an inum
* libguile/bytevectors.c:
* libguile/goops.c:
* libguile/instructions.c:
* libguile/numbers.c:
* libguile/random.c:
* libguile/read.c:
* libguile/vm-i-scheme.c: Fix a number of assumptions that a long could
  hold an inum. This is not the case on platforms whose void* is larger
  than their long.

* libguile/numbers.c (scm_i_inum2big): New helper, only implemented for
  sizeof(void*) == sizeof(long); produces a compile error on other
  platforms. Basically gmp doesn't have a nice interface for converting
  between mpz values and intmax_t.
2010-11-19 15:22:43 +01: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
Andy Wingo
a587d6a973 more fixes to equal? for arrays
* libguile/array-map.c (array_compare, scm_array_equal_p): Rewrite as
  something that operates on the generic array handle infrastructure.
  Based on array->list.
  (scm_i_array_equal_p): Change the docs, as array-equal? is now the same
  as equal?, except that it typechecks its args.

* doc/ref/api-compound.texi (Array Procedures): Update array-equal?
  docs.

* libguile/deprecated.h:
* libguile/deprecated.c (scm_raequal): Deprecate.

* libguile/bytevectors.c (scm_bytevector_eq_p): Bugfix: bytevectors are
  bytevector=? only if their element type is the same.

* libguile/eq.c (scm_equal_p): Only dispatch to scm_array_equal_p if
  both args are arrays (generically).

* test-suite/tests/arrays.test ("equal?"): Add some more tests.
2010-04-01 00:25:06 +02: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
a268973767 reimplement srfi-4 vectors on top of bytevectors
* libguile/srfi-4.h:
* libguile/srfi-4.c (scm_make_srfi_4_vector): New function, exported by
  (srfi srfi-4 gnu).
* libguile/srfi-4.i.c: Removed.
* module/srfi/srfi-4.scm:
* module/srfi/srfi-4/gnu.scm: Reimplement srfi-4 vectors on top of
  bytevectors. The implementation is mostly in Scheme now.

* test-suite/tests/unif.test: Update to use (srfi srfi-4 gnu).

* libguile/bytevectors.c (bytevector_ref_c32, bytevector_ref_c64)
  (bytevector_set_c32, bytevector_set_c64): Fix some embarrassing bugs.
  Still need to do an upper bounds check.

* libguile/deprecated.h: Remove deprecated array functions:
  scm_i_arrayp, scm_i_array_ndim, scm_i_array_mem, scm_i_array_v,
  scm_i_array_base, scm_i_array_dims, and the deprecated macros:
  SCM_ARRAYP, SCM_ARRAY_NDIM, SCM_ARRAY_CONTP, SCM_ARRAY_MEM,
  SCM_ARRAY_V, SCM_ARRAY_BASE, SCM_ARRAY_DIMS.
* libguile/deprecated.c (scm_uniform_vector_read_x)
  (scm_uniform_vector_write, scm_uniform_array_read_x)
  (scm_uniform_array_write): Newly deprecated functions.

* libguile/generalized-arrays.c (scm_array_type): Remove the bytevector
  hack.

* libguile/objcodes.c (scm_bytecode_to_objcode, scm_objcode_to_bytecode):
  Rework to operate on bytevectors, as scm_make_u8vector now causes a
  module lookup, which can't be done e.g. when loading the VM boot
  program for psyntax-pp.go on a fresh bootstrap.

* libguile/objcodes.h (SCM_F_OBJCODE_IS_BYTEVECTOR):
  (SCM_OBJCODE_IS_BYTEVECTOR): s/U8VECTOR/BYTEVECTOR/.

* module/ice-9/boot-9.scm (the-scm-module): A terrible hack to pull in
  (srfi srfi-4), as the bindings are primarily there now. We'll worry
  about this later.
2010-01-07 22:06:56 +01:00
Andy Wingo
3dc2afe2b8 Revert "Remove unused internal bytevector functions."
This reverts commit c4daa51910.
2010-01-07 22:06:20 +01:00
Andy Wingo
562cd1b8f8 more boot cleanup
* libguile/bytevectors.c (scm_bootstrap_bytevectors): Remove a call to
  scm_gc_protect_object.

* libguile/gc.h:
* libguile/gc.c (scm_init_gc_protect_object): Rename from
  scm_init_storage, and just return void. Make the GC boot procs have
  internal linkage.

* libguile/init.c: Adapt to the name change.
2009-12-05 11:44:09 +01:00
Andy Wingo
f39448c5a3 remove a bunch of needless scm_permanent_object calls
* libguile/array-handle.c:
* libguile/bytevectors.c:
* libguile/deprecated.c:
* libguile/eval.c:
* libguile/feature.c:
* libguile/filesys.c:
* libguile/gc.c:
* libguile/gdbint.c:
* libguile/goops.c:
* libguile/instructions.c:
* libguile/load.c:
* libguile/modules.c:
* libguile/numbers.c:
* libguile/options.c:
* libguile/ports.c:
* libguile/scmsigs.c:
* libguile/srcprop.c:
* libguile/srfi-4.c:
* libguile/stacks.c:
* libguile/threads.c:
* libguile/vm.c: Remove calls to scm_permanent_object, as they are no
  longer needed with the BDW GC.
2009-12-05 11:32:50 +01:00
Ludovic Courtès
3fe87cf7af Re-add an indirection in bytevectors.
The intent is to allow for mmap(3) bindings and to actually reuse
user-provided buffers in `scm_c_take_bytevector ()'.

* libguile/bytevectors.h (SCM_BYTEVECTOR_HEADER_SIZE): Increment.
  (SCM_BYTEVECTOR_CONTENTS): Take the pointer from the second word.
  (SCM_BYTEVECTOR_CONTIGUOUS_P): New macro.
  (SCM_BYTEVECTOR_ELEMENT_TYPE): Adjust to live alongside the CONTIGUOUS
  flag.

* libguile/bytevectors.c (SCM_BYTEVECTOR_SET_CONTENTS,
  SCM_BYTEVECTOR_SET_CONTIGUOUS_P): New macros.
  (SCM_BYTEVECTOR_SET_ELEMENT_TYPE): Adjust.
  (SCM_BYTEVECTOR_TYPED_LENGTH): Properly parenthesize.
  (make_bytevector): Adjust to new bytevector header.
  (make_bytevector_from_buffer): Reuse CONTENTS.
  (scm_c_shrink_bytevector): Differentiate between contiguous and
  non-contiguous bytevectors.
2009-11-16 09:23:45 +01:00
Ludovic Courtès
c4daa51910 Remove unused internal bytevector functions.
* libguile/bytevectors.c (scm_i_make_typed_bytevector,
  scm_c_take_typed_bytevector): Remove.

* libguile/bytevectors.h: Adjust accordingly.
2009-11-16 09:23:45 +01:00
Michael Gran
3a5bc4fada Modify bytevectors/string conversions to allow wide strings
The bytevector to string conversion functions were accomplished
by converting via locale strings.  This did not allow conversions
of wide strings in an 8-bit locale.  This is avoided by using knowledge
of the storage format of the string.

* libguile/bytevectors.c (STRING_TO_UTF, scm_string_to_utf8): modify
  string to bytevector conversion to use internal string information
  (UTF_TO_STRING, scm_utf8_to_string): modify bytevector to string
  conversion
2009-10-28 06:24:23 -07:00
Andy Wingo
b0fae4ecaa bitvector tweaks
* libguile/arrays.c (scm_from_contiguous_typed_array):
* libguile/bytevectors.c (scm_uniform_array_to_bytevector): Error if the
  uniform element size is more than 8 bits, but not divisible by 8 --
  because our math could overflow in that case.

* module/ice-9/deprecated.scm (#\y): Indeed, #* is the valid bitvector
  syntax :)
2009-10-16 11:59:30 +02:00
Ludovic Courtès
29553c54b5 Fix segfault for `(uniform-array->bytevector (bitvector))'.
* libguile/bytevectors.c (scm_uniform_array_to_bytevector): Fix BYTE_LEN
  computation for bitvectors.

* test-suite/tests/bytevectors.test ("uniform-array->bytevector"): New
  test prefix.
2009-10-15 23:24:19 +02:00
Andy Wingo
f5a51caec1 fix bitvectors after the array handle refactoring
* libguile/uniform.h (scm_array_handle_uniform_element_bit_size): New
  public accessor.

* libguile/uniform.c (scm_array_handle_uniform_element_size): Better
  errors in non-byte-aligned arrays.
  (scm_uniform_vector_element_type, scm_uniform_vector_element_size)
  (scm_c_uniform_vector_ref, scm_c_uniform_vector_set_x):
  (scm_uniform_vector_to_list): Don't require byte-aligned access.

* libguile/bytevectors.c (scm_uniform_array_to_bytevector):
* libguile/arrays.c (scm_from_contiguous_typed_array):  Fix for
  uniform arrays whose element size is not a multiple of the byte size.
2009-09-18 16:27:32 +02:00
Ludovic Courtès
0665b3ffcb Remove the distinction between inline/outline storage for bytevectors.
* libguile/bytevectors.c (SCM_BYTEVECTOR_INLINE_THRESHOLD,
  SCM_BYTEVECTOR_INLINEABLE_SIZE_P, SCM_BYTEVECTOR_SET_CONTENTS,
  SCM_BYTEVECTOR_SET_INLINE): Remove.
  (SCM_BYTEVECTOR_HEADER_BYTES): New macro.
  (SCM_BYTEVECTOR_SET_ELEMENT_TYPE): Adjust to new flag layout.
  (make_bytevector): Remove content inlining machinery; use
  `scm_gc_malloc_pointerless ()' in all cases; special-case zero-sized
  vu8 buffers.
  (make_bytevector_from_buffer): Simplified.
  (scm_c_shrink_bytevector): New, formerly `scm_i_shrink_bytevector ()'.
  Remove buffer inlining machinery.
  (scm_bootstrap_bytevectors): Use `make_bytevector ()' for
  SCM_NULL_BYTEVECTOR.

* libguile/bytevectors.h (SCM_BYTEVECTOR_HEADER_SIZE): New macro.
  (SCM_BYTEVECTOR_CONTENTS): Adjust to new layout.
  (SCM_SET_BYTEVECTOR_FLAGS): Properly cast F.
  (SCM_F_BYTEVECTOR_INLINE, SCM_BYTEVECTOR_INLINE_P): Remove.
  (SCM_BYTEVECTOR_ELEMENT_TYPE): Adjust.
  (scm_c_shrink_bytevector): Remove macro, make a C function
  declaration.
2009-08-31 01:07:30 +02:00
Ludovic Courtès
807e5a6641 Use a TC7 tag instead of a SMOB for bytevectors.
* libguile/bytevectors.c (scm_tc16_bytevector): Remove.
  (SCM_BYTEVECTOR_SET_LENGTH, SCM_BYTEVECTOR_SET_CONTENTS,
  SCM_BYTEVECTOR_SET_INLINE, SCM_BYTEVECTOR_SET_ELEMENT_TYPE,
  make_bytevector_from_buffer, scm_is_bytevector,
  scm_bootstrap_bytevectors): Adjust to the SMOB->tc7 change.
  (scm_i_print_bytevector): New, formerly `print_bytevector ()'.
  (bytevector_equal_p): Remove.

* libguile/bytevectors.h (SCM_BYTEVECTOR_LENGTH,
  SCM_BYTEVECTOR_CONTENTS, SCM_BYTEVECTOR_P): Adjust to SMOB->tc7
  change.
  (SCM_BYTEVECTOR_FLAGS, SCM_SET_BYTEVECTOR_FLAGS): New macros.
  (scm_tc16_bytevector): Remove declaration.
  (scm_i_print_bytevector): New declaration.

* libguile/eq.c (scm_equal_p): Handle `scm_tc7_bytevector'.

* libguile/evalext.c (scm_self_evaluating_p): Likewise.

* libguile/print.c (iprin1): Likewise.

* libguile/tags.h (scm_tc7_bytevector): New.
  (scm_tc7_unused_8): Remove.

* libguile/validate.h (SCM_VALIDATE_BYTEVECTOR): Adjust.

* test-suite/tests/bytevectors.test ("Datum
  Syntax")["self-evaluating?"]: New test.
2009-08-30 20:12:09 +02:00
Ludovic Courtès
7af531508c Merge branch 'master' into boehm-demers-weiser-gc
Conflicts:
	libguile/Makefile.am
	libguile/bytevectors.c
	libguile/gc-card.c
	libguile/gc-mark.c
	libguile/programs.c
	libguile/srcprop.c
	libguile/srfi-14.c
	libguile/symbols.c
	libguile/threads.c
	libguile/unif.c
	libguile/vm.c
2009-08-28 19:16:46 +02:00
Ludovic Courtès
05762e724b Use `scm_gc_malloc_pointerless ()' for bytevectors.
* libguile/bytevectors.c (make_bytevector): Use
  `scm_gc_malloc_pointerless ()' for the buffer itself.

* libguile/r6rs-ports.c (scm_get_bytevector_some,
  scm_get_bytevector_all, bop_buffer_grow): Likewise.
2009-08-18 22:12:31 +02:00
Ludovic Courtès
3b882d69fb Remove unneeded SMOB mark/free procedures.
* libguile/bytevectors.c (free_bytevector): Remove.
  (scm_bootstrap_bytevectors): Update accordingly.

* libguile/r6rs-ports.c (bip_mark, cbp_mark, bop_free, bop_proc_mark):
  Remove.
  (initialize_bytevector_input_ports,
  initialize_custom_binary_input_ports,
  initialize_bytevector_output_ports,
  initialize_custom_binary_output_ports): Update accordingly.
2009-08-18 00:31:32 +02:00
Ludovic Courtès
1ac8a47f01 Fix malloc/scm_c_take_bytevector mismatch.
* libguile/bytevectors.c (STRING_TO_UTF): Use `make_bytevector ()'
  instead of `scm_c_take_bytevector ().
  (scm_string_to_utf8): Likewise.
2009-08-18 00:09:26 +02:00
Andy Wingo
cd43fdc5b7 fix (bytevector-ieee-single-native-set! x 0 0)
* libguile/bytevectors.c (VALIDATE_REAL): SCM_VALIDATE_REAL is not what
  we need for checking values for bytevector-ieee-single-native-set! et
  al, so define our own validator.
  (IEEE754_SET, IEEE754_NATIVE_SET): Use it.
2009-07-19 15:38:01 +02:00
Andy Wingo
e286c973fc bytevectors have "element type" field, e.g. for generalized-vector-ref
Bytevectors have a very close relationship to other forms of uniform
vectors. Often you want to view a u64vector as a series of bytes, for
writing over a socket; or to process an incoming stream using the
convenient and less error-prone s16vector-ref API rather than
bytevector-s16-native-ref.

The essential needs of the representation of a bytevector and an
s64vector are the same, so we take advantage of that and extend the
bytevector implementation to have a "native type" field, which defaults
to VU8.

This commit doesn't actually expose any user-noticeable changes,
however.

* libguile/bytevectors.h (SCM_BYTEVECTOR_ELEMENT_TYPE): New internal
  defines.
  (scm_i_make_typed_bytevector, scm_c_take_typed_bytevector): New
  internal functions.

* libguile/bytevectors.c (SCM_BYTEVECTOR_SET_ELEMENT_TYPE):
  (SCM_BYTEVECTOR_TYPE_SIZE):
  (SCM_BYTEVECTOR_TYPED_LENGTH): New internal macros.
  (make_bytevector, make_bytevector_from_buffer): Take an extra
  argument, the element type. The length argument is interpreted as
  being the number of elements, which corresponds to the number of bytes
  in the default VU8 case. Doing it this way eliminates a class of bugs
  -- e.g. a u32vector of length 3 bytes doesn't make sense. We do have
  to check for another class of bugs: overflow. The length stored on the
  bytevector itself is still the byte length, though.
  (scm_i_make_typed_bytevector):
  (scm_c_take_typed_bytevector): New internal functions.
  (scm_i_shrink_bytevector): Make sure the new size is valid for the
  bytevector's type.
  (scm_i_bytevector_generalized_set_x): Remove this function, the
  array-handle infrastructure takes care of this for us.
  (print_bytevector): Print the bytevector according to its type.
  (scm_make_bytevector, scm_bytevector_copy)
  (scm_uniform_array_to_bytevector)
  (scm_u8_list_to_bytevector, scm_bytevector_to_uint_list): Adapt to
  make_bytevector extra arg.
  (bv_handle_ref, bv_handle_set_x): Adapt to ref and set based on the
  type of the bytevector, e.g. f64 or u8.
  (bytevector_get_handle): Set the typed length of the vector, not the
  byte length.

Conflicts:

	libguile/bytevectors.c
2009-07-19 15:34:59 +02:00
Andy Wingo
f332089ed4 bytevector inlinedness indicated by flag, not length
* libguile/bytevectors.h (SCM_BYTEVECTOR_INLINE_P): Change to check a
  flag instead of checking the length of the bytevector.

* libguile/bytevectors.c (make_bytevector_from_buffer): Handle the len
  <= inline threshold case as well. Set the inline flag as appropriate.
  (make_bytevector): Updat the inline flag as appropriate.
  (scm_c_take_bytevector): Just dispatch to make_bytevector_from_buffer.
  (scm_i_shrink_bytevector): Update the inline flag as appropriate.
  Update the length when shrinking an already-inlined vector.
  (STRING_TO_UTF): Fix some indentation.
2009-07-19 15:15:44 +02:00
Andy Wingo
f45eccffa7 add registry of vector constructors, make-generalized-vector
* libguile/generalized-vectors.h:
* libguile/generalized-vectors.c: Add a registry of vector constructors.
  (scm_make_generalized_vector): New public function, constructs a
  vector of a given type.

* libguile/bitvectors.c:
* libguile/bytevectors.c:
* libguile/srfi-4.c:
* libguile/strings.c:
* libguile/vectors.c: Register vector constructors.

* libguile/extensions.c (scm_init_extensions): No need to NULL the list
  of registered extensions here, the static init does it for us. Allows
  scm_c_register_extension to be called before scm_init_extensions.

* libguile/init.c (scm_i_init_guile): Move array initialization earlier,
  so e.g. scm_init_strings has access to a valid list of array element
  types when registering its vector constructor.
2009-07-19 15:15:44 +02:00
Andy Wingo
476b894c71 uniform vector functions to their own file
* libguile/uniform.c:
* libguile/uniform.h:
* libguile/srfi-4.c:
* libguile/srfi-4.h:
* libguile/Makefile.am: Move uniform vector funcs out of srfi-4 to their
  own file.

* libguile.h:
* libguile/arrays.c:
* libguile/bytevectors.c: Update includers.
2009-07-19 15:15:44 +02:00
Andy Wingo
2a610be594 add generic array implementation facility
* libguile/array-handle.c (scm_i_register_array_implementation):
  (scm_i_array_implementation_for_obj): Add generic array facility,
  which will (in a few commits) detangle the array code.
  (scm_array_get_handle): Use the generic array facility. Note that
  scm_t_array_handle no longer has ref and set function pointers;
  instead it has a pointer to the array implementation. It is unlikely
  that code out there used these functions, however, as the supported
  way was through scm_array_handle_ref/set_x.
  (scm_array_handle_pos): Move this function here from arrays.c.
  (scm_array_handle_element_type): New function, returns a Scheme value
  representing the type of element stored in this array.

* libguile/array-handle.h (scm_t_array_element_type): New enum, for
  generically determining the type of an array.
  (scm_array_handle_rank):
  (scm_array_handle_dims): These are now just #defines.

* libguile/arrays.c:
* libguile/bitvectors.c:
* libguile/bytevectors.c:
* libguile/srfi-4.c:
* libguile/strings.c:
* libguile/vectors.c: Register array implementations for all of these.

* libguile/inline.h: Update for array_handle_ref/set change.
* libguile/deprecated.h: Need to include arrays.h now.
2009-07-19 15:15:40 +02:00
Andy Wingo
2fa901a51f rename unif.[ch] to arrays.[ch]
* libguile/Makefile.am:
* libguile/unif.c:
* libguile/unif.h:
* libguile/arrays.c:
* libguile/arrays.h: Rename unif.[ch] to arrays.[ch].

* libguile.h:
* libguile/array-handle.c:
* libguile/array-map.c:
* libguile/bitvectors.c:
* libguile/bytevectors.c:
* libguile/eq.c:
* libguile/gc-card.c:
* libguile/gc-malloc.c:
* libguile/gc-mark.c:
* libguile/gc.c:
* libguile/init.c:
* libguile/inline.h:
* libguile/print.c:
* libguile/random.c:
* libguile/read.c:
* libguile/socket.c:
* libguile/sort.c:
* libguile/srfi-4.c:
* libguile/srfi-4.h:
* libguile/strports.c:
* libguile/vectors.c:
* libguile/vectors.h: Update includers.
2009-07-19 14:53:03 +02:00
Andy Wingo
caa92f5e95 bytevectors provide scm_i_native_endianness to the vm
* libguile/bytevectors.h (scm_i_native_endianness): Allow the VM to use
  scm_i_native_endianness, but still keep it marked as internal.

* libguile/bytevectors.c: Adjust to use scm_i_native_endianness instead
  of native_endianness. Define it at bootstrap time.
2009-06-26 12:42:10 +02:00