* configure.in: Check for the declaration of unsetenv(3), which Tru64
5.1b doesn't have.
* libguile/posix.c: Include <stdlib.h> since that's where POSIX says
unsetenv(3) should reside.
(scm_putenv): Don't attempt to use unsetenv(3) if its declaration
isn't available since that wouldn't work well on Tru64.
* configure.in (enable_deprecated): Set SCM_WARN_DEPRECATED_DEFAULT
even when --disable-deprecated is passed.
* libguile/deprecation.h: Declare deprecation-issuing methods even
if SCM_ENABLE_DEPRECATED is not set.
* libguile/deprecation.c: Ditto.
(scm_init_deprecation): Include full body even for unset
SCM_ENABLE_DEPRECATED.
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
The crux of this problem was that the thread doing a throw, and so
checking scm_i_critical_section_level, was different from the thread
that was in a critical section.
* libguile/async.h (scm_i_critical_section_level): Removed, replaced
by per-thread critical_section_level.
(SCM_CRITICAL_SECTION_START, SCM_CRITICAL_SECTION_END): Use
per-thread critical_section_level.
* libguile/continuations.c (scm_dynthrow): Check per-thread
critical_section_level.
* libguile/threads.c (guilify_self_1): Init per-thread
critical_section_level.
(scm_i_critical_section_level): Removed.
* libguile/threads.h (scm_i_thread): New critical_section_level field.
* libguile/throw.c (scm_ithrow): Check per-thread critical_section_level.
* libguile/symbols.c (intern_symbol): New function, with code formerly
duplicated in `scm_i_c_mem2symbol ()' and `scm_i_mem2symbol ()'.
(scm_i_c_mem2symbol, scm_i_mem2symbol): Use it.
(scm_take_locale_symboln): Use `intern_symbol ()'. This fixes
bug #25865.
* test-suite/standalone/Makefile.am
(test_scm_take_locale_symbol_SOURCES,
test_scm_take_locale_symbol_CFLAGS,
test_scm_take_locale_symbol_LDADD): New variables.
(check_PROGRAMS, TESTS): Add `test-scm-take-locale-symbol'.
This fixes the following helgrind report.
Thread #1: lock order "0x4114748 before 0x4331084" violated
at 0x40234F7: pthread_mutex_lock (hg_intercepts.c:408)
by 0x407A55F: deval (eval.c:4077)
by 0x407A071: scm_dapply (eval.c:5012)
by 0x407888A: scm_apply (eval.c:4811)
by 0x407E20C: scm_call_0 (eval.c:4666)
by 0x406BDF7: scm_dynamic_wind (dynwind.c:111)
by 0x407620C: ceval (eval.c:4571)
by 0x407E8D9: scm_primitive_eval_x (eval.c:5921)
by 0x407E934: scm_eval_x (eval.c:5956)
by 0x40B9140: scm_shell (script.c:737)
by 0x4095AC5: invoke_main_func (init.c:367)
by 0x4065A81: c_body (continuations.c:349)
Required order was established by acquisition of lock at 0x4114748
at 0x40234F7: pthread_mutex_lock (hg_intercepts.c:408)
by 0x40B7BE1: scm_sigaction_for_thread (scmsigs.c:339)
by 0x40911DE: scm_gsubr_apply (gsubr.c:223)
by 0x4079E36: scm_dapply (eval.c:4930)
by 0x407AB68: deval (eval.c:4378)
by 0x407A071: scm_dapply (eval.c:5012)
by 0x407888A: scm_apply (eval.c:4811)
by 0x407E1D0: scm_call_1 (eval.c:4672)
by 0x407FEEE: scm_map (eval.c:5489)
by 0x407BDCC: deval (eval.c:4367)
by 0x407D197: deval (eval.c:3698)
by 0x407A071: scm_dapply (eval.c:5012)
followed by a later acquisition of lock at 0x4331084
at 0x40234F7: pthread_mutex_lock (hg_intercepts.c:408)
by 0x40DC397: scm_enter_guile (threads.c:377)
by 0x40DC8F4: scm_pthread_mutex_lock (threads.c:1485)
by 0x4083FAA: scm_gc_for_newcell (gc.c:484)
by 0x40A9781: scm_cons (inline.h:115)
by 0x4079867: scm_dapply (eval.c:4850)
by 0x407888A: scm_apply (eval.c:4811)
by 0x40796D6: scm_call_3 (eval.c:4684)
by 0x409A7C2: module_variable (modules.c:302)
by 0x409A7EE: module_variable (modules.c:312)
by 0x409A962: scm_sym2var (modules.c:466)
by 0x40738F4: scm_lookupcar1 (eval.c:2874)
* libguile/scmsigs.c (close_1): Renamed `handler_to_async'; also
handle #f case and wrapping the async in a cons, if necessary.
(install_handler): Pass in async instead of constructing it; combine
two branches into one.
(scm_sigaction_for_thread): Allocate async upfront instead of inside
the critical section, and pass it to install_handler calls. Leave
critical section before signaling out-of-range error.
This fixes lots of helgrind-reported problems, such as:
Thread #1: lock order "0x4325084 before 0x4108928" violated
at 0x40234F7: pthread_mutex_lock (hg_intercepts.c:408)
by 0x40CFD37: scm_enter_guile (threads.c:377)
by 0x40D0284: scm_pthread_mutex_lock (threads.c:1485)
by 0x405A736: scm_async_click (async.c:155)
by 0x406F9EE: deval (eval.c:4080)
by 0x40761D9: scm_primitive_eval_x (eval.c:5921)
by 0x40AD20E: install_handler (scmsigs.c:113)
by 0x40AD402: scm_sigaction_for_thread (scmsigs.c:394)
by 0x4087D1F: scm_gsubr_apply (gsubr.c:223)
by 0x406DF55: scm_dapply (eval.c:4930)
by 0x407147C: deval (eval.c:4378)
by 0x406E1BD: scm_dapply (eval.c:5012)
Required order was established by acquisition of lock at 0x4325084
at 0x40234F7: pthread_mutex_lock (hg_intercepts.c:408)
by 0x40CFD37: scm_enter_guile (threads.c:377)
by 0x408C58B: scm_i_init_guile (init.c:421)
by 0x40D1873: scm_i_init_thread_for_guile (threads.c:589)
by 0x40D18B4: scm_i_with_guile_and_parent (threads.c:731)
by 0x40D19BD: scm_with_guile (threads.c:720)
by 0x408C42E: scm_boot_guile (init.c:350)
by 0x8048710: main (guile.c:69)
followed by a later acquisition of lock at 0x4108928
at 0x40234F7: pthread_mutex_lock (hg_intercepts.c:408)
by 0x40AFD61: scm_make_smob_type (smob.c:294)
by 0x40AFF19: scm_smob_prehistory (smob.c:512)
by 0x408C595: scm_i_init_guile (init.c:423)
by 0x40D1873: scm_i_init_thread_for_guile (threads.c:589)
by 0x40D18B4: scm_i_with_guile_and_parent (threads.c:731)
by 0x40D19BD: scm_with_guile (threads.c:720)
by 0x408C42E: scm_boot_guile (init.c:350)
by 0x8048710: main (guile.c:69)
* libguile/async.c (scm_async_click): Don't leave Guile mode when
locking async_mutex. We don't need to, because none of the code
that has async_mutex locked can block, and doing so may lead to lock
ordering problems between async_mutex and a thread's heap_mutex.
This fixes the following helgrind report.
Thread #1: lock order "0x4325084 before 0x4105328" violated
at 0x40234F7: pthread_mutex_lock (hg_intercepts.c:408)
by 0x40D01EA: scm_i_thread_put_to_sleep (threads.c:1622)
by 0x4078958: scm_make_fluid (fluids.c:114)
by 0x40778D6: scm_init_feature (feature.c:101)
by 0x408C62E: scm_i_init_guile (init.c:464)
by 0x40D1873: scm_i_init_thread_for_guile (threads.c:583)
by 0x40D18B4: scm_i_with_guile_and_parent (threads.c:725)
by 0x40D19BD: scm_with_guile (threads.c:714)
by 0x408C42E: scm_boot_guile (init.c:350)
by 0x8048710: main (guile.c:69)
Required order was established by acquisition of lock at 0x4325084
at 0x40234F7: pthread_mutex_lock (hg_intercepts.c:408)
by 0x40CFFA4: guilify_self_1 (threads.c:468)
by 0x408C58B: scm_i_init_guile (init.c:421)
by 0x40D1873: scm_i_init_thread_for_guile (threads.c:583)
by 0x40D18B4: scm_i_with_guile_and_parent (threads.c:725)
by 0x40D19BD: scm_with_guile (threads.c:714)
by 0x408C42E: scm_boot_guile (init.c:350)
by 0x8048710: main (guile.c:69)
followed by a later acquisition of lock at 0x4105328
at 0x40234F7: pthread_mutex_lock (hg_intercepts.c:408)
by 0x40CFFAC: guilify_self_1 (threads.c:470)
by 0x408C58B: scm_i_init_guile (init.c:421)
by 0x40D1873: scm_i_init_thread_for_guile (threads.c:583)
by 0x40D18B4: scm_i_with_guile_and_parent (threads.c:725)
by 0x40D19BD: scm_with_guile (threads.c:714)
by 0x408C42E: scm_boot_guile (init.c:350)
by 0x8048710: main (guile.c:69)
* threads.c (guilify_self_1): Add self to global thread list _before_
entering Guile mode.
Reported by Roland Haeder. The declaration and definition of
scm_pthread_cond_timedwait were using possibly different types for the
third arg.
* THANKS: Added Roland Haeder.
* libguile/threads.h (scm_pthread_cond_timedwait): Use scm_t_timespec
for third arg rather than struct timespec, for consistency with the
function implementation.
* libguile/Makefile.am (guile_LDFLAGS): Remove `@DLPREOPEN@' since it
has no effect.
* libguile/guile.c (main): Don't invoke `LTDL_SET_PRELOADED_SYMBOLS ()'
since it had no effect given how we invoke `libtool'. It also fixes
compatibility issues when using libltdl 1.5 with a Libtool 2.2
package.
* libguile/strings.c (scm_string_ref): Add proper range checking for the
empty string.
(scm_string_set_x): Likewise.
Reported by Bill Schottstaedt <bil@ccrma.Stanford.EDU>.
* test-suite/tests/strings.test ("string-ref"): New test prefix.
("string-set!")["empty string", "empty string and non-zero index",
"out of range", "negative index", "regular string"]: New tests.
* NEWS: Update.
This fixes bug #24009 reported by Martin Pitt.
* libguile/threads.c (guilify_self_1): Check the return value of
pipe(2).
(scm_std_select): Store the return value of read(2) when reading
from WAKEUP_FD.
* libguile/async.c (scm_i_queue_async_cell): Store the return value
of write(2) when writing to SLEEP_FD.
* libguile/fports.c (fport_flush): Likewise.
* libguile/posix.c (getgroups): Use the return value of getgroups(2) as
NGROUPS.
(scm_nice): Get the return value of nice(2) to make glibc happy.
* libguile/scmsigs.c (take_signal): Store the return value of
write(2).
We recently modified scm_c_read so that it temporarily swaps the
caller's buffer with the port's normal read buffer, in order to
improve performance in the case where the port is unbuffered (which
actually means having a single-byte buffer) - but we implemented the
swap in the buffered case too. The latter turns out to be a bad idea
- because it means that the C code of a custom port implementation
cannot rely on a port's buffer always being the same as when it was
first set up - and so this commit reverts that. The buffer swapping
trick now applies to unbuffered ports only.
* libguile/ports.c (scm_c_read): Only do swapping of port and caller
buffer for unbuffered ports.
* NEWS: Update.
* libguile/threads.c (scm_i_init_thread_for_guile): When the thread is
already guilified, update `t->base' so that it corresponds to the new
stack base. Bug report and patch by Linas Vepstas <linasvepstas@gmail.com>.
* test-suite/standalone/Makefile.am (test_scm_with_guile_CFLAGS,
test_scm_with_guile_LDADD): New.
(check_PROGRAMS, TESTS): Add `test-scm-with-guile'.
* libguile/Makefile.am (stack-limit-calibration.scm): Use $(srcdir), to
support building in a different directory.
(MOSTLYCLEANFILES): Add stack-limit-calibration.scm.
For explanation, see comments and text in the new file
libguile/measure-hwm.scm.
* .gitignore: Add libguile/stack-limit-calibration.scm.
* check-guile.in: Load libguile/stack-limit-calibration.scm.
* configure.in: Add AC_CONFIG_FILES to generate test-use-srfi from
test-use-srfi.in.
* libguile/Makefile.am (TESTS, TESTS_ENVIRONMENT,
stack-limit-calibration.scm): New targets, so that `make check'
calibrates the stack limit before running the Guile test suite.
* libguile/measure-hwm.scm: New file, calibrates stack limit for `make
check'.
* libguile/stackchk.c (scm_sys_get_stack_size): New primitive.
* libguile/stackchk.h (scm_sys_get_stack_size): New primitive
(declaration).
* test-suite/standalone/test-use-srfi: Renamed test-use-srfi.in, so
that ./configure can fill in variables in it.
* test-suite/standalone/test-use-srfi.in: Load
libguile/stack-limit-calibration.scm.
* libguile/threads.c (scm_threads_mark_stacks): Cast `&t->regs' to
`(void *)' rather than `(SCM_STACKITEM *)' to avoid "warning:
dereferencing type-punned pointer will break strict-aliasing rules"
with GCC 4.2.1 on `i386-unknown-freebsd7.0'.
* libguile/read.c (scm_read_string): Use `scm_i_make_read_only_string ()' to
return a read-only string, as mandated by R5RS. Reported by Bill
Schottstaedt <bil@ccrma.Stanford.EDU>.
* libguile/strings.c (scm_i_make_read_only_string): New function.
(scm_i_shared_substring_read_only): Special-case the empty string
so that the read-only and read-write empty strings are `eq?'. This
optimization is relied on by the `substring/shared' `empty string'
test case in `srfi-13.test'.
* libguile/strings.h (scm_i_make_read_only_string): New declaration.
* test-suite/tests/strings.test ("string-set!")["literal string"]: New test.
* NEWS: Update.
* libguile/strings.c (scm_i_symbol_substring): Return a read-only string
since R5RS requires `symbol->string' to return a read-only string.
Reported by Bill Schottstaedt <bil@ccrma.Stanford.EDU>.
* test-suite/tests/symbols.test: Add `define-module' clause.
(exception:immutable-string): Adjust to current exception.
("symbol->string")["result is an immutable string"]: Use
`pass-if-exception' instead of `expect-fail-exception'.
* NEWS: Update.
(reported by Bill Schottstaedt)
* libguile/numbers.c (scm_gcd): When only one arg given, use scm_abs
to ensure that result is non-negative.
* test-suite/tests/numbers.test ("gcd"): New test, (gcd -2).
Idea and original patch were by Ludovic Courts, this is Neil Jerram's
reworking of it.
* libguile/srfi-4.c (scm_uniform_vector_read_x): Use scm_c_read,
instead of equivalent code here.
* libguile/ports.c (scm_fill_input): Add assertion that read
buffer is empty when called.
(port_and_swap_buffer, swap_buffer): New, for...
(scm_c_read): Use caller's buffer for reading, to avoid making N
1-byte low-level read calls, in the case where the port is
unbuffered (or has a very small buffer).