1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-02 04:40:29 +02:00
Commit graph

5525 commits

Author SHA1 Message Date
Neil Jerram
a24f4637ea Fix build when compiled with -Wundef -Werror
(Reported by David Fang)

* libguile/inline.h: Check if __APPLE_CC__ is defined before testing
  its value.
2009-02-05 22:13:17 +00:00
Neil Jerram
94922b177b Fix build when scm_t_timespec is different from struct timespec
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.
2009-01-23 01:27:20 +00:00
Neil Jerram
d681856755 Fix MinGW HAVE_STRUCT_TIMESPEC build problem
Reported by Carlo Bramini.  See the comment in _scm.h.

* THANKS: Add Carlo Bramini.

* libguile/_scm.h: Undefine HAVE_STRUCT_TIMESPEC.
2009-01-23 01:02:46 +00:00
Neil Jerram
53a79cd060 Fix implementation of %fast-slot-ref and %fast-slot-set!
* libguile/goops.c (scm_sys_fast_slot_ref, scm_sys_fast_slot_set_x):
  Correct incantation for getting the number of slots of the specified
  instance.

* libguile/goops.h (SCM_NUMBER_OF_SLOTS): Removed (because wrong).

* test-suite/standalone/test-fast-slot-ref.in: New standalone test.

* configure.in: Generate test-suite/standalone/test-fast-slot-ref.

* test-suite/standalone/Makefile.am (check_SCRIPTS): Add
  test-fast-slot-ref.
2009-01-04 22:41:51 +00:00
Ludovic Courtès
a97cd69632 Don't use deprecated functions in `debug-malloc.c'.
* libguile/debug-malloc.c (scm_malloc_stats): Use
  `scm_from_locale_string ()'.  Patch by Linas Vepstas
  <linasvepstas@gmail.com>.
2008-12-18 22:48:45 +01:00
Ludovic Courtès
72db29f200 Remove useless references to Libtool's `dlpreopen' mechanism.
* 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.
2008-12-07 22:08:39 +01:00
Ludovic Courtès
deee086c8d Fix sloppy bound checking in `string-{ref,set!}' with the empty string.
* 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.
2008-12-02 19:42:39 +01:00
Ludovic Courtès
a87c991545 Fix potential deadlock in `make-struct'.
* libguile/struct.c (scm_make_struct): Remove critical section, as
  suggested by Linas Vepstas <linasvepstas@gmail.com>.  See
  http://lists.gnu.org/archive/html/bug-guile/2008-11/msg00036.html for
  a discussion.
2008-11-30 20:28:47 +01:00
Ludovic Courtès
b12a5fd7f6 Check the return value of libc's functions to make `_FORTIFY_SOURCE=2' work.
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).
2008-11-30 18:58:57 +01:00
Ludovic Courtès
664d1f5eb2 Use orthodox libtoology in `guile'.
* libguile/guile.c (main): Use `LTDL_SET_PRELOADED_SYMBOLS ()' instead
  of our own trick.
2008-11-24 23:15:22 +01:00
Neil Jerram
1d17348b54 Make scm_c_read use caller buffer only for unbuffered ports.
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.
2008-11-23 22:38:34 +00:00
Ludovic Courtès
cd1a1e47b5 Update the thread stack base when `scm_with_guile' is invoked multiple times.
* 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'.
2008-11-14 00:35:32 +01:00
Neil Jerram
9b20fde272 Fix stack calibration-related errors when running make distcheck.
* libguile/Makefile.am (stack-limit-calibration.scm): Use $(srcdir), to
  support building in a different directory.
  (MOSTLYCLEANFILES): Add stack-limit-calibration.scm.
2008-10-26 21:44:35 +00:00
Neil Jerram
28f979acf1 Add measure-hwm.scm to the set of distribution files.
* libguile/Makefile.am (EXTRA_DIST): Add measure-hwm.scm.
2008-10-24 22:46:43 +01:00
Neil Jerram
05675184ee Avoid Stack overflow' errors when running make check'
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.
2008-10-17 22:02:17 +01:00
Ludovic Courtès
c18ed8cead Fix compilation error due to strict aliasing rules on `i386-unknown-freebsd7.0'.
* 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'.
2008-10-10 10:00:21 +02:00
Ludovic Courtès
4b600701b9 Revert "Make literal strings (i.e., returned by `read') read-only."
This reverts commit be5c4a82ab.

The rationale is that `read' must return mutable strings, as reported
by szgyg <szgyg@ludens.elte.hu>.
2008-10-09 23:23:27 +02:00
Ludovic Courtès
be5c4a82ab Make literal strings (i.e., returned by `read') read-only.
* 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.
2008-09-23 18:39:18 +02:00
Ludovic Courtès
40de0323e7 Make `symbol->string' return a read-only string.
* 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.
2008-09-23 18:39:10 +02:00
Neil Jerram
0bf4fe19a6 Fix for incorrect (gcd -2) => -2; should give 2.
(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).
2008-09-22 21:18:01 +01:00
Neil Jerram
bed2e15fc9 Make multi-byte reads on unbuffered ports more efficient.
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).
2008-09-15 18:50:14 +01:00
Ludovic Courtès
7a4e0d105e Include <config.h> in all C files; use #ifdef HAVE_CONFIG_H' rather than #if'. 2008-09-13 15:49:50 +02:00
Ludovic Courtès
8073f24ccd Add `ChangeLog-2008' files to the distribution. 2008-09-12 21:46:32 +02:00
Ludovic Courtès
e9d9445b50 Rename ChangeLog' files to ChangeLog-2008'. 2008-09-12 21:42:26 +02:00
Ludovic Courtès
1778e9f5fb Include <config.h> in `discouraged.c'.
* libguile/discouraged.c: Include <config.h> first so that files that
  rely on `config.h' macros (such as Gnulib-provided headers) work as
  expected.
2008-09-12 09:42:58 +02:00
Ludovic Courtès
365db7e640 Remove `.cvsignore' files. 2008-09-11 21:48:53 +02:00
Julian Graham
1eb4952693 Resolve a deadlock caused by not checking mutex state after calling `SCM_TICK'.
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2008-09-08 14:32:22 +02:00
Ludovic Courtès
cfabe1e2e4 Revert "Add `SCM_INTERNAL' macro, use it."
This reverts commit f0c64044d3.
2008-09-04 20:26:55 +02:00
Ludovic Courtès
ca71113651 Revert "Fix `SCM_INTERNAL' with GCC 4.3."
This reverts commit bc566d672f.
2008-09-04 20:24:22 +02:00
Ludovic Courtès
ef8d3d3a2c Remove `coop-threads' files that had been useless since 2005-03-02. 2008-08-27 23:48:19 +02:00
Ludovic Courtès
e210266510 Use AC_USE_SYSTEM_EXTENSIONS' instead of the obsolete AC_AIX', etc. 2008-08-20 19:02:41 +02:00
Ludovic Courtès
dc0f35ca61 Add ChangeLog and NEWS entry for the GOOPS `class-redefinition' memory
corruption fix.
2008-08-20 00:46:42 +02:00
Ludovic Courtès
ba368578f3 Complete fix of `hell' allocation in GOOPS. 2008-08-20 00:46:40 +02:00
Han-Wen Nienhuys
2e503afaf7 Fix sizeof() nitpick for goops corruption. 2008-08-20 00:46:12 +02:00
Han-Wen Nienhuys
49f325df90 Fix memory corruption issue with hell[] array: realloc/calloc need to
factor in sizeof(scm_t_bits)
2008-08-20 00:45:42 +02:00
Neil Jerram
7ed52b7bbb Fix misleading output from `(help rationalize)'
* numbers.c (scm_rationalize): Update docstring to match the
	manual (which is more correct).  Change argument "err" to "eps",
	also to match the manual.
2008-08-03 00:18:33 +01:00
Neil Jerram
305d3e761e Merge branch 'branch_release-1-8' of ssh://ossau@git.sv.gnu.org/srv/git/guile into branch_release-1-8 2008-07-17 22:15:29 +01:00
Neil Jerram
ac370d9737 ChangeLog for "Improved MIPS/Linux gc_os_dep.c definitions" 2008-07-17 22:02:01 +01:00
Ludovic Courtès
dc329592ff Handle lack of struct dirent64' and readdir64_r ()' on HP-UX 11.11. 2008-07-17 00:17:56 +02:00
Neil Jerram
4ff3575c77 Improved MIPS/Linux gc_os_dep.c definitions
From Thiemo Seufer <ths@networkno.de>:

	* gc_os_dep.c (CPP_WORDSZ, ALIGN_DOUBLE, DATAEND,
	DYNAMIC_LOADING): Added #defines.
	(_fdata, _end): Added declarations.
	(DATASTART): Use _fdata instead of __data_start.
	(STACKBOTTOM): Changed from 0x80000000 to 0x7fff8000.
2008-07-12 19:26:39 +01:00
Ludovic Courtès
47463c8fd7 Add `scm_c_symbol_length ()'. 2008-07-05 20:11:22 +02:00
Ludovic Courtès
bc566d672f Fix `SCM_INTERNAL' with GCC 4.3. 2008-07-04 22:22:54 +02:00
Ludovic Courtès
e01343d646 Modernize Automake files. 2008-06-28 22:14:40 +02:00
Ludovic Courtès
a9f32e12c4 Disable type-checking of `SCM_UNPACK' for the broken HP compilers. 2008-06-28 20:38:36 +02:00
Ludovic Courtès
c4df2cca63 Work around `#define except' on Tru64. 2008-06-02 21:51:27 +02:00
Ludovic Courtès
f0c64044d3 Add `SCM_INTERNAL' macro, use it. 2008-05-31 23:16:41 +02:00
Neil Jerram
0d185db93e Expand DEFFROM and DEFTO macros in discouraged.c
* discouraged.c: Expand DEFFROM and DEFTO macros, to avoid
compiler warnings about excess semicolons.  (Reported by Didier
Godefroy.)
2008-05-13 00:01:57 +01:00
Neil Jerram
78aa4a8850 Fix continuation problems on IA64.
* Specific problems in IA64 make check

** test-unwind

Representation of the relevant dynamic context:

                  non-rewindable
           catch      frame       make cont.
  o----o-----a----------b-------------c
        \
         \             call cont.
          o-----o-----------d

A continuation is captured at (c), with a non-rewindable frame in the
dynamic context at (b).  If a rewind through that frame was attempted,
Guile would throw to the catch at (a).  Then the context unwinds back
past (a), then winds forwards again, and the captured continuation is
called at (d).

We should end up at the catch at (a).  On ia64, we get an "illegal
instruction".

The problem is that Guile does not restore the ia64 register backing
store (RBS) stack (which is saved off when the continuation is
captured) until all the unwinding and rewinding is done.  Therefore,
when the rewind code (scm_i_dowinds) hits the non-rewindable frame at
(b), the RBS stack hasn't yet been restored.  The throw finds the
jmp_buf (for the catch at (a)) correctly from the dynamic context, and
jumps back to (a), but the RBS stack is invalid, hence the illegal
instruction.

This could be fixed by restoring the RBS stack earlier, at the same
point (copy_stack) where the normal stack is restored.  But that
causes a problem in the next test...

** continuations.test

The dynamic context diagram for this case is similar:

                   non-rewindable
  catch                 frame       make cont.
    a----x-----o----------b-------------c
          \
           \    call cont.
            o-------d

The only significant difference is that the catch point (a) is
upstream of where the dynamic context forks.  This means that the RBS
stack at (d) already contains the correct RBS contents for throwing
back to (a), so it doesn't matter whether the RBS stack that was saved
off with the continuation gets restored.

This test passes with the Guile 1.8.4 code, but fails (with an
"illegal instruction") when the code is changed to restore the RBS
stack earlier as described above.

The problem now is that the RBS stack is being restored _too_ early;
specifically when there is still stuff to do that relies on the old
RBS contents.  When a continuation is called, the sequence of relevant
events is:

  (1) Grow the (normal) stack until it is bigger than the (normal)
      stack saved off in the continuation.  (scm_dynthrow, grow_stack)

  (2) scm_i_dowinds calls itself recursively, such that

      (2.1) for each rewind (from (x) to (c)) that will be needed,
            another frame is added to the stack (both normal and RBS),
            with local variables specifying the required rewind; the
            rewinds don't actually happen yet, they will happen when
            the stack unwinds again through these frames

      (2.2) required unwinds - back from where the continuation was
            called (d) to the fork point (x) - are done immediately.

  (3) The normal (i.e. non-RBS) stack that was stored in the
      continuation is restored (i.e. copied on top of the actual
      stack).

      Note that this doesn't overwrite the frames that were added in
      (2.1), because the growth in (1) ensures that the added frames
      are beyond the end of the restored stack.

  (4) ? Restore the RBS stack here too ?

  (5) Return (from copy_stack) through the (2.1) frames, which means
      that the rewinds now happen.

  (6) setcontext (or longjmp) to the context (c) where the
      continuation was captured.

The trouble is that step (1) does not create space in the RBS stack in
the same kind of way that it does for the normal stack.  Therefore, if
the saved (in the continuation) RBS stack is big enough, it can
overwrite the RBS of the (2.1) frames that still need to complete.
This causes an illegal instruction when we return through those frames
and try to perform the rewinds.

* Fix

The key to the fix is that the saved RBS stack only needs to be
restored at some point before the next setcontext call, and that doing
it as close to the setcontext call as possible will avoid bad
interactions with the pre-setcontext stack.  Therefore we do the
restoration at the last possible point, immediately before the next
setcontext call.

The situation is complicated by there being two ways that the next
setcontext call can happen.

  - If the unwinding and rewinding is all successful, the next
    setcontext will be the one from step (6) above.  This is the
    "normal" continuation invocation case.

  - If one of the rewinds throws an error, the next setcontext will
    come from the throw implementation code.  (And the one in step (6)
    will never happen.)  This is the rewind error case.

In the rewind error case, the code calling setcontext knows nothing
about the continuation.  So to cover both cases, we:

  - copy (in step (4) above) the address and length of the
    continuation's saved RBS stack to the current thread state
    (SCM_I_CURRENT_THREAD)

  - modify all setcontext callers so that they check the current
    thread state for a saved RBS stack, and restore it if so before
    calling setcontext.

* Notes

** I think rewinders cannot rely on using any stack data

Unless it can be guaranteed that the data won't go into a register.
I'm not 100% sure about this, but I think it follows from the fact
that the RBS stack is not restored until after the rewinds have
happened.

Note that this isn't a regression caused by the current fix.  In Guile
1.8.4, the RBS stack was restored _after_ the rewinds, and this is
still the case now.

** Most setcontext calls for `throw' don't need to change the RBS stack

In the absence of continuation invocation, the setcontext call in the
throw implementation code always sets context to a place higher up the
same stack (both normal and RBS), hence no stack restoration is
needed.

* Other changes

** Using setcontext for all non-local jumps (for __ia64__)

Along the way, I read a claim somewhere that setcontext was more
reliable than longjmp, in cases where the stack has been manipulated.

I don't now have any reason to believe this, but it seems reasonable
anyway to leave the __ia64__ code using getcontext/setcontext, instead
of setjmp/longjmp.

(I think the only possible argument against this would be performance -
if getcontext was significantly slower than setjmp.  It that proves to
be the case, we should revisit this.)

** Capping RBS base for non-main threads

Somewhere else along the way, I hit a problem in GC, involving the RBS
stack of a non-main thread.  The problem was, in
SCM_MARK_BACKING_STORE, that scm_ia64_register_backing_store_base was
returning a value that was massively greater than the value of
scm_ia64_ar_bsp, leading to a seg fault.  This is because the
implementation of scm_ia64_register_backing_store_base is only valid
for the main thread.  I couldn't find a neat way of getting the true
RBS base of a non-main thread, but one idea is simply to call
scm_ia64_ar_bsp when guilifying a thread, and use the value returned
as an upper bound for that thread's RBS base.  (Note that the RBS
stack grows upwards.)

(Were it not for scm_init_guile, we could be much more definitive
about this.  We could take the value of scm_ia64_ar_bsp as a
definitive base address for the part of the RBS stack that Guile cares
about.  We could also then discard
scm_ia64_register_backing_store_base.)
2008-05-12 23:06:04 +01:00
Ludovic Courtès
19da7c42c1 Avoid warning with GCC on FreeBSD 6.2 in `numbers.c'. 2008-05-07 17:43:17 +02:00
Neil Jerram
00ec6b610f Fix c-tokenize.c error: 'input' defined but not used, when compiling with GCC 4.3.0 2008-05-05 23:49:02 +01:00