* libguile/integers.c (scm_integer_gcd_ii)
(scm_integer_gcd_zi, scm_integer_gcd_zz): New internal functions.
* libguile/integers.h: Declare internal functions.
* libguile/numbers.c (scm_gcd): Use the new functions.
* libguile/integers.c (scm_integer_ceiling_remainder_ii)
(scm_integer_ceiling_remainder_iz, scm_integer_ceiling_remainder_zi)
(scm_integer_ceiling_remainder_zz): New internal functions.
(bignum_is_positive): New helper.
* libguile/integers.h: Declare internal functions.
* libguile/numbers.c (scm_ceiling_remainder): Use the new functions.
* libguile/integers.c (scm_integer_ceiling_quotient_ii)
(scm_integer_ceiling_quotient_iz, scm_integer_ceiling_quotient_zi)
(scm_integer_ceiling_quotient_zz): New internal functions.
(take_bignum_from_mpz): Change to also normalize the mpz, as all callers
required.
(long_sign, bignum_cmp_long): New helpers.
* libguile/integers.h: Declare internal functions.
* libguile/numbers.c (scm_ceiling_quotient): Use the new functions.
* libguile/integers.c (scm_integer_abs_i, scm_integer_abs_z): New
internal functions.
* libguile/integers.h: Declare internal functions.
* libguile/numbers.c (scm_abs): Use the new functions.
* libguile/integers.c (scm_is_integer_odd_i):
(scm_is_integer_odd_z): New internal functions. Add a number of
internal support routines.
* libguile/integers.h: Declare internal functions.
* libguile/numbers.c (scm_odd_p, scm_even_p): Use the new functions.
The goal is to factor out some fixnum/bignum code here from
numbers.[ch].
* libguile/Makefile.am: Add new files.
* libguile/integers.c:
* libguile/integers.h: New files
When heap-numbers-equal? is called from eqv?, we have already ensured
that the both objects have the same heap type. However when called by
the VM, the precondition is just that both are heap numbers -- not
necessarily of the same type. Fix to add an additional check in
heap-numbers-equal?. Could cause crashers!
* libguile/eq.c (scm_i_heap_numbers_equal_p): Add additional check.
This patch removes the undocumented function make-srfi-4-vector from
(guile). That function is still exported from (srfi srfi-4 gnu).
* libguile/srfi-4.h (scm_init_srfi_4): Split into scm_bootstrap_srfi_4()
and scm_init_srfi_4(), after the pattern of scm_init_bytevectors() and
scm_bootstrap_bytevectors().
* libguile/init.c: Replace scm_init_srfi_4() call by scm_bootstrap_srfi_4().
* module/srfi/srfi-4.scm: Load newly defined srfi-4 extension. This
provides undocumented make-srfi-4-vector.
* module/srfi/srfi-4/gnu.scm: Export srfi-4-vector-type-size.
* doc/ref/srfi-modules.texi: Document srfi-4-vector-type-size.
* 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.
This avoids gmp aborting e.g. with (ash 1 (expt 2 37)). The new limit is
such that (ash 1 (expt 30)) is accepted but (ash 1 (expt 31)) throws.
Fixes https://bugs.gnu.org/48150
* libguile/numbers.c (ash, round-ash): As stated.
* test-suite/tests/numbers.test: Test a case known to make gmp abort before.
These use the argument conventions of vector-copy!, string-copy!,
etc. and not that of bytevector-copy! (which is from r6rs).
* module/srfi/srfi-4/gnu.scm: As stated.
* test-suite/tests/srfi-4.test: Tests.
* doc/ref/srfi-modules.texi: Documentation.
* libguile/bytevectors.c (bytevector-copy!): Add overlap note to
docstring.
* libguile/vectors.c (vector-copy!): Reuse text for the overlap note.
* libguile/bytevectors.c (bytevector-fill!): As stated.
(scm_bytevector_fill_x): Stub to avoid changing the C API.
* doc/ref/api-data.texi: Documentation.
* libguile/vectors.c (vector-fill!): Less confusing variable names.
* test-suite/tests/bytevectors.test: Test partial fill cases for
bytevector-fill!.
This flag was set, but never used in Guile, and there was no documented
API to access it.
To check if an array is contiguous, use (array-contents <> #t).
* libguile/arrays.h (scm_i_raw_array): New function.
SCM_I_ARRAY_CONTIGUOUS, SCM_SET_ARRAY_CONTIGUOUS_FLAG,
SCM_CLR_ARRAY_CONTIGUOUS_FLAG, SCM_I_ARRAY_CONTP: Remove.
scm_t_array_dim: Declare here, not in array-handle.h.
SCM_I_ARRAY_NDIM: Shift by one bit since the contp flag isn't there
anymore.
* module/syste/vm/assembler.scm: Match removal of contp flag.
* libguile/arrays.c (scm_i_make_array): Reuse scm_i_raw_array.
(scm_i_ra_set_contp): Remove.
(scm_transpose_array): Don't set or clear the contp flag.
(scm_make_shared_array): Don't set or clear the contp flag.
(scm_make_typed_array): Don't set the contp flag.
* libguile/array-map.c (scm_i_array_rebase): Reuse scm_i_raw_array.
* Deprecate scm_is_simple_vector.
* libguile/vectors.c (scm_vector_elements,
scm_vector_writable_elements): These functions take an array; reword
to make this clear.
* libguile/print.h: Remove reference to 'simple vector'.
* doc/ref/api-data.texi: Remove documentation for scm_is_simple_vector.
Remove references to 'simple vector'.
Fix documentation for scm_vector_elements,
scm_vector_writable_elements.
* test-suite/tests/arrays.test:
* test-suite/tests/vectors.test: Remove references to 'simple vector'.
This is up to 20%-30% faster than the previous versions in (scheme base) or
(srfi srfi-43) that used vector-move-left!/vector-move-right!.
* libguile/vectors.h:
* libguile/vectors.c: As stated.
* doc/ref/api-data.texi (vector-copy!): Document the new function.
(vector-fill!): Document optional arguments.
(vector-copy): Document optional arguments.
* module/scheme/base.scm: Reuse core vector-copy!.
* module/srfi/srfi-43.scm: Reuse core vector-copy!.
These functions weren't advertised to work on non-vector arrays. They
did try to, but only incorrectly. For example:
(define a (vector 1 2 3 4 5))
(define b (make-array 0 '(1 5)))
(vector-move-right! a 0 2 b 2)
b
=> #1@1(0 0 1 2 0)
instead of the correct result #1@1(0 1 2 0 0).
* libguile/vectors.c (vector-move-left!, vector-move-right!): As stated.
Partly fixes <https://bugs.gnu.org/41948>.
Previously, the child process could end up using the same 'sleep_pipe'
as its parent, leading to a race condition handling signals.
* libguile/posix.c (do_fork): New function.
(scm_fork): Call 'do_fork' via 'scm_without_guile'.
* test-suite/standalone/test-signal-fork: New test.
* test-suite/standalone/Makefile.am (check_SCRIPTS, TESTS): Add it.
Partly fixes <https://bugs.gnu.org/41948>.
Reported by Mathieu Othacehe <othacehe@gnu.org>.
Previously, after 'fork', the child process could end up sharing the
finalization thread with its parent.
* libguile/finalizers.c (finalization_pipe): Initialize.
(reset_finalization_pipe): Factored out.
(start_finalization_thread): Create the pipe immediately before
launching the thread. Ensure the pipe is cleaned up if thread creation
fails. Update the finalizer callback if thread creation succeeds.
(stop_finalization_thread): Clean up the pipe after stopping the thread.
(spawn_finalizer_thread): Remove finalizer callback logic.
(scm_set_automatic_finalization_enabled): Remove pipe management.
(scm_init_finalizer_thread): Remove pipe management.
Co-authored-by: Ludovic Courtès <ludo@gnu.org>
* libguile/mini-gmp.c: Add config.h include. Handles the case in which
gnulib provides some part of the standard library of mini-gmp, as is
apparently the case on FreeBSD for example. Thanks to RhodiumToad for
the report and fix.
* libguile/intrinsics.h:
* libguile/intrinsics.c (lookup_bound_public, lookup_bound_private): Two
new intrinsics.
(scm_bootstrap_intrinsics): Wire them up.
* libguile/jit.c (compile_call_scm_from_scmn_scmn):
(compile_call_scm_from_scmn_scmn_slow):
(COMPILE_X8_S24__N32__N32__C32): Add JIT support for new instruction
kind.
* libguile/vm-engine.c (call-scm<-scmn-scmn): New instruction, takes
arguments as non-immediate offsets, to avoid needless loads and register
pressure.
* module/language/cps/effects-analysis.scm: Add cases for new
primcalls.
* module/language/cps/compile-bytecode.scm (compile-function): Add new
primcalls.
* module/language/cps/reify-primitives.scm (cached-module-box): If the
variable is bound, call lookup-bound-public / lookup-bound-private as
appropriate instead of separately resolving the module, name, and doing
the bound check.
* module/language/tree-il/compile-bytecode.scm (emit-cached-module-box):
Use new instructions.
* module/system/vm/assembler.scm (define-scm<-scmn-scmn-intrinsic):
(lookup-bound-public, lookup-bound-private): Add assembler support.