* libguile/symbols.c (default_gensym_prefix): New variable.
(scm_gensym): Use it. Use `scm_from_latin1_stringn' instead of
`scm_from_locale_stringn'.
(scm_init_symbols): Initialize DEFAULT_GENSYM_PREFIX.
* libguile/strports.c (INITIAL_BUFFER_SIZE): New macro.
(scm_mkstrport): If STR is false, allocate a bytevector on the
caller's behalf.
(scm_object_to_string, scm_call_with_output_string,
scm_open_output_string): Pass SCM_BOOL_F as the STR argument of
`scm_mkstrport'.
* libguile/backtrace.c (scm_display_application,
display_backtrace_body): Likewise.
* libguile/gdbint.c (scm_init_gdbint): Likewise.
* libguile/print.c (scm_simple_format): Likewise.
* libguile/strports.c (st_resize_port): Adjust to deal with OLD_STREAM
and NEW_STREAM as bytevectors.
(scm_mkstrport): Store a bytevector in the port's stream rather than a
string.
* libguile/guile-snarf.in (modern_snarf): Allow programs to specify
multiple initialization actions on a single line. This makes it
possible for C programs to define multiple subrs with a single macro
invocation.
* test-suite/standalone/test-guile-snarf: Enable more tests.
* libguile/read.c (scm_i_scan_for_encoding): If possible, just use the
read buffer for the encoding scan, and avoid seeking. Fixes
`(open-input-file "/dev/urandom")', because /dev/urandom can't be
seeked backwards.
* libguile/read.c (scm_read_scsh_block_comment): Use `scm_getc' instead
of `scm_get_byte_or_eof'.
* test-suite/tests/reader.test ("read-options")["position of SCSH block
comment"]: New test.
* libguile/i18n.c (scm_nl_langinfo)[GROUPING]: Consider negative numbers
like `CHAR_MAX'. Reported by David Fang <fang@csl.cornell.edu>.
Fix suggested by Bruno Haible <bruno@clisp.org>.
* libguile/hashtab.c (scm_c_register_weak_gc_callback): New private
helper, arranges for a C function to be called with a SCM as an
argument, as long as the argument is reachable by GC.
(scm_make_weak_key_hash_table)
(scm_make_weak_value_hash_table)
(scm_make_doubly_weak_hash_table): Register a weak GC callback to
vacuum_weak_hash_table.
* libguile/gc.c (scm_gc): No need to take a mutex here. Don't run the
hook, the hook will run itself.
(scm_c_register_gc_callback): New private helper, registers a callback
the next time GC happens.
(system_gc_callback): Guile's internal callback that runs
scm_after_gc_c_hook, which itself queues a call to the after-gc-hook.
(scm_storage_prehistory): Queue up a call to system_gc_callback.
* libguile/hashtab.c (vacuum_weak_hash_table): New helper, goes through
the entirety of a weak hash table, vacuuming dead entries.
(scm_hash_fn_create_handle_x): If when adding to a weak hash table, we
would trigger a rehash, vacuum the table first. The weak_bucket_assoc
would have only caught dead entries within one bucket.
Without this patch, the following code leaks:
(let lp ()
(call-with-output-string
(lambda (port)
(display "foo" port)))
(lp))
* libguile/ports.c (scm_i_remove_port): Fix a case in which ports
explictly closed via close-port would leak their iconv_t data.
(scm_set_port_encoding_x): scm_i_set_port_encoding_x strdups its
argument, so we need to free the locale encoding of the incoming str.
* libguile/numbers.c (log_of_shifted_double, log_of_exact_integer,
log_of_exact_integer_with_size, log_of_fraction): New internal static
functions used by scm_log and scm_log10.
(scm_log, scm_log10): Robustly handle large integers, large and small
fractions, and fractions close to 1. Previously, computing logarithms
of fractions close to 1 yielded grossly inaccurate results, and the
other cases yielded infinities even though the answer could easily fit
in a double. (log -0.0) now returns -inf.0+<PI>i, where previously it
returned -inf.0. (log 0) now throws a numerical overflow exception,
where previously it returned -inf.0. (log 0.0) still returns -inf.0.
Analogous changes made to `log10'.
* test-suite/tests/numbers.test (log, log10): Add tests.
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
* libguile/numbers.c (scm_i_inexact_truncate_divide): Use trunc instead
of floor and ceil. Important for consistency with
scm_truncate_quotient and scm_truncate_remainder.
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
* libguile/Makefile.am (c-tokenize.$(OBJEXT)): When cross-compiling,
don't include any CPPFLAGS since we could end up seeing Gnulib's
replacements, e.g., `rpl_malloc', which we can't use.
* libguile/Makefile.am (version_info): New variable.
(libguile_@GUILE_EFFECTIVE_VERSION@_la_LIBADD): Remove
`$(LTLIBUNISTRING) $(LTLIBICONV) $(LTLIBINTL)'.
(libguile_@GUILE_EFFECTIVE_VERSION@_la_LDFLAGS): Add all the flags
from Gnulib, one per line as in the `gnulib-tool' output, including
those above.
* libguile/numbers.c (scm_c_truncate, scm_truncate_number,
scm_i_inexact_truncate_quotient, scm_i_inexact_truncate_remainder):
Use trunc directly, now that we have its gnulib module.
* libguile/numbers.h (SCM_NUMP, SCM_NUMBERP): Mask out more bits in the
cell type field when doing the comparison, in order to accept future
numeric types that have not yet been implemented. This should allow
us to add more core numeric types without breaking ABI compatibility.
As a bonus, these macros are now more efficient.
* libguile/numbers.c (scm_quotient): Reimplement in terms of
scm_truncate_quotient.
(scm_remainder): Reimplement in terms of scm_truncate_remainder.
(scm_modulo): Reimplement in terms of scm_floor_remainder.
(scm_euclidean_quotient, scm_euclidean_remainder,
scm_euclidean_divide): Reimplement in terms of floor and ceiling.
Make them non-extensible, because there is no need; they will work
with any objects that implement the floor and ceiling division
operators, and that can be tested using `negative?'.
* libguile/numbers.c (scm_c_truncate): Use ceil (x) instead of
-floor (-x).
(scm_truncate_number): Implement directly instead of by checking the
sign and using scm_floor or scm_ceiling. Use scm_truncate_quotient
for fractions. Make extensible, so that new number types implemented
in GOOPS will be able to do the job more efficiently, since it is
often easier to implement truncate than floor or ceiling.
(scm_round_number): Optimize fractions case by using
scm_round_quotient. Make extensible, so that new number types
implemented in GOOPS will be able to do the job efficiently.
(scm_floor, scm_ceiling): Optimize fractions case by using
scm_floor_quotient and scm_ceiling_quotient, respectively.
* test-suite/tests/numbers.test: Add test cases.
* libguile/numbers.c: (scm_euclidean_quotient, scm_euclidean_remainder,
scm_euclidean_divide, scm_centered_quotient, scm_centered_remainder,
scm_centered_divide): Optimize case where both arguments are exact and
at least one is a fraction, by reducing to a subproblem involving only
integers, and then adjusting the resulting remainder as needed.
* libguile/numbers.c (scm_euclidean_divide, scm_centered_divide): Change
API to return two values via output arguments of type (SCM *), instead
of packing into a values object.
(scm_i_euclidean_divide, scm_i_centered_divide): New internal wrappers
that call the above functions and pack the result into a values
object.
* libguile/numbers.h: Change prototypes to reflect new API.
* doc/ref/api-data.h (Arithmetic): Update manual.
* libguile/values.c (scm_i_extract_values_2): New internal function
that extracts two values from a values object.
* libguile/values.h: Added prototype.
* configure.ac: Detect when struct sockaddr_in has a sin_len field.
Remove obsolete comment.
* libguile/socket.c (scm_to_sockaddr, scm_fill_sockaddr): Set the
sin_len field in our struct sockaddr_in when it exists.
* libguile/_scm.h (SCM_OBJCODE_MAJOR_VERSION): Bump to 2.
(SCM_OBJCODE_MINOR_VERSION): Reset to 0.
(SCM_OBJCODE_MACHINE_VERSION_STRING, SCM_OBJCODE_COOKIE): Reorder so
the minor version is the last byte.
* libguile/objcodes.c (make_objcode_by_mmap): Accept objcodes whose
minor version is less than SCM_OBJCODE_MINOR_VERSION, not just equal
to.
* libguile/read.c (scm_read_opts): Default "positions" to #t. The
compiler was already turning it on anyway, and this allows
primitive-load without --auto-compile to also propagate source
information through the expander, for better errors and to let macros
know their source.
* module/language/scheme/spec.scm: No need to enable positions here
now.
* libguile/numbers.c (scm_euclidean_quotient, scm_euclidean_divide,
scm_centered_quotient, scm_centered_divide): Fix bug in inum/inum
case, where (quotient most-negative-fixnum -1) would not be converted
to a bignum.
(scm_euclidean_quotient): Be more anal-retentive about calling
scm_remember_upto_here_1 after mpz_sgn, (even though mpz_sgn is
documented as being implemented as a macro and certainly won't
do any allocation). It's better to be safe than sorry here.
(scm_euclidean_quotient, scm_centered_quotient): In the bignum/inum
case, check if the divisor is 1, since this will allow us to avoid
allocating a new bignum.
(scm_euclidean_divide, scm_centered_quotient, scm_centered_divide):
When computing the intermediate truncated quotient (xx / yy) and
remainder, use (xx % yy) instead of (xx - qq * yy), on the theory that
the compiler is more likely to handle this case intelligently and
maybe combine the operations.
(scm_euclidean_divide): In the bignum/inum case, we know that the
remainder will fit in an fixnum, so don't bother allocating a bignum
for it.
(scm_euclidean_quotient, scm_euclidean_remainder,
scm_euclidean_divide, scm_centered_quotient, scm_centered_remainder,
scm_centered_divide): Minor stylistic changes.
* test-suite/tests/numbers.test: Rework testing framework for
number-theoretic division operators to be more efficient and
comprehensive in its testing of code paths and problem cases.
* libguile/numbers.c (scm_atan): Call SCM_WTA_DISPATCH_1 instead of
SCM_WTA_DISPATCH_2 if the second argument is unbound. Arguably,
SCM_WTA_DISPATCH_* should handle that case gracefully, but currently
it doesn't.
* libguile/tags.h: Fix comment in discussion of data representation.
tc3-code #0b110 indicates a small integer and #0b100 indicates a
non-integer immediate. Previously, these were reversed.