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

8554 commits

Author SHA1 Message Date
Michael Gran
d5b48cb039 Don't presume sigset_t available in <signal.h>
In MinGW, sigset_t is not availab.e

* libguile/gen-scmconfig.c (SCM_HAVE_PTHREAD_SIGMASK): new conditional
* libguile/null-threads.h (scm_i_pthread_sigmask): now conditional on
    SCM_HAVE_PTHREAD_SIGMASK
2018-04-25 14:52:22 -07:00
Michael Gran
925485c276 typo, lost a parenthesis
* libguile/posix-w32.c (start_child): fix build regression
2018-04-19 17:10:52 -07:00
Michael Gran
d21e7074c7 make strftime compile with null threads
* libguile/stime.c (scm_strftime): use scm_i_pthread_mutex_lock
    instead of scm_pthread_mutex_lock
2018-04-19 17:09:38 -07:00
Michael Gran
b2a50874bb In win32, system* shouldn't launch shell when command not found
When system* was called to execute a script/excutable without args, if
that did not exist, it would launch an interactive session. Now it fails
with an error.

* libguile/posix-w32.c (start_child): return when cmd not found
* test-suite/tests/posix.test (system*): system* test should handle errors
2018-04-19 13:21:47 -07:00
Michael Gran
eac111dde6 Wrong preprocessor test for include guard for sys/select.h
Should use #if SCM_HAVE_SYS_SELECT_H

* libguile/iselect.h: [SCM_HAVE_SYS_SELECT_H] guarde inclusion of sys/select.h
2018-04-18 06:20:31 -07:00
Michael Gran
77b33170f4 Let read-line handle alternate line endings
Adds CRLF, NEL, PS and LS as line endings. %read-line will return
these. In the case of CRLF, %read-line will return a string "\r\n"
as the line ending.

* libguile/rdelim.c (scm_read_line): handle more line delimiters
* test-suite/tests/rdelim.test ("two lines, split, CRLF"): new test
  ("two long lines, split, CRLF", "two lines, split, NEL"): new tests
  ("two lines, split, LS", "two lines, split, PS"): new tests
2018-04-17 08:22:18 -07:00
Michael Gran
7b6c483595 In libpath.h, use absolute paths on MinGW
* libguile/Makefile.am (libpath.h): convert msys paths to absolute paths
2018-04-16 19:06:31 -07:00
Michael Gran
82832992c4 Don't presume existence of sys/select.h in headers
* libguile/iselect.h: guard sys/select.h with winsock2.h as fallback
2018-04-16 10:31:42 -07:00
Michael Gran
dbc10620a4 SCM-to-C number conversion functions incorrect when SIZEOF_LONG != SIZEOF_SCM_T_BITS
* libguile/conv-integer.i.c (SCM_FROM_TYPE_PROTO, SCM_TO_TYPE_PROTO):
    prefer fixnum size to scm_t_bits size
* libguile/conv-uinteger.i.c (SCM_FROM_TYPE_PROTO, SCM_TO_TYPE_PROTO):
    prefer fixnum size to scm_t_bits size
2018-04-13 14:20:02 -07:00
Michael Gran
c56d2d1023 Fix binary output for mkstemp! on MinGW
* libguile/filesys.c (scm_i_mkstemp): Don't mask out O_BINARY flag
* test-suite/tests/posix.test ("binary mode-honored"): new test
2018-04-11 18:36:08 -07:00
Michael Gran
b9731ee5ee start_child should return pid_t
This is to make the definition and declaration agree.

* posix-w32.h: change return value of start_child to pid_t
2018-04-10 14:01:12 -07:00
Michael Gran
9bf1ae81e1 Conditionally include netinet/tcp.h
It is not present on MinGW.

* configure.ac: (AC_CHECK_HEADERS) add netinet/tcp.h
* socket.c: [HAVE_NETINET_TCP_H] conditionally include netinet/tcp.h
2018-04-10 12:19:38 -07:00
Ludovic Courtès
7ade0485af build: Use 'sed' invocation compatible with BSD sed.
Fixes <https://bugs.gnu.org/30011>.
Reported by ilove zfs <ilovezfs@icloud.com>.

* libguile/Makefile.am (INSTANTIATE): Move '-i' first.
2018-02-16 15:29:35 +01:00
Ludovic Courtès
f390afa0cc 'select' returns empty sets upon EINTR and EAGAIN.
Fixes <https://bugs.gnu.org/30368>.

* libguile/filesys.c (scm_select): Clear READ_SET, WRITE_SET, and
EXCEPT_SET when RV < 0.
2018-02-16 15:29:35 +01:00
Andy Wingo
07b7490f73 Sync IP before allocating closures
* libguile/vm-engine.c (vm_engine): Sync IP before allocating closures.
2018-01-26 09:49:00 +01:00
Ludovic Courtès
a1793bc904 Revert "Honor '%fresh-auto-compile'."
This reverts commit 83d4c4d622,
which came from a misunderstanding.
2018-01-15 23:17:24 +01:00
Ludovic Courtès
cc8f41e7d8 Make sure the return value of 'scm_crypt' is always initialized.
* libguile/posix.c (scm_crypt): Always initialize 'ret'; error out even
when ERR is zero.
2018-01-10 16:19:09 +01:00
Ludovic Courtès
deef64a739 'load-thunk-from-memory' reports the correct error.
Previously 'load-thunk-from-memory' would often throw to 'system-error'
when passed an incorrect ELF file, leading to incorrect error messages.

* libguile/loader.c (load_thunk_from_memory): Reset 'errno' when
'check_elf_header' returns non-NULL.
* test-suite/tests/vm.test: New file.
* test-suite/Makefile.am (SCM_TESTS): Add it.
2017-12-22 11:40:27 +01:00
Ludovic Courtès
6d391bf1a4 Fix 'crypt' deadlock upon error.
* libguile/posix.c (scm_crypt): Take 'scm_i_misc_mutex' right before
calling 'crypt'.  Move 'SCM_SYSERROR' call after 'scm_dynwind_end'.
* test-suite/tests/posix.test ("crypt"): New test prefix.
2017-12-22 11:12:57 +01:00
Ludovic Courtès
48d42553ef ltdl wrappers now use a recursive mutex.
Fixes <https://bugs.gnu.org/29275>.
Reported by noxdafox <noxdafox@gmail.com>.

* libguile/dynl.c (scm_init_dynamic_linking): Add call to
'scm_i_pthread_mutex_init'.
2017-11-22 16:46:11 +01:00
Matt Wette
bb5d316b16 foreign: Add 'uintptr_t' and 'intptr_t'.
* libguile/foreign.c (scm_uintptr_t, scm_intptr_t): New variables.
(scm_init_foreign): Define them.
* module/system/foreign.scm: Export 'intptr_t' and 'uintptr_t'.
* doc/ref/api-foreign.texi (Foreign Types): Document them.

Co-authored-by: Ludovic Courtès <ludo@gnu.org>
2017-11-22 16:33:57 +01:00
Sergei Trofimovich
f928888534 ia64: Fix crash in thread context switch.
Fixes <https://bugs.gnu.org/29151> and <https://bugs.gentoo.org/613986>.

Backtrace looks like that:

  Program terminated with signal SIGSEGV, Segmentation fault.
  #0  0x200000000014a5c0 in scm_ia64_longjmp (JB=0x6000000000817020, VAL=1) at continuations.c:372
  372                   t->pending_rbs_continuation->backing_store,
  [Current thread is 1 (Thread 0x2000000000049340 (LWP 8190))]
  (gdb) bt
  #0  0x200000000014a5c0 in scm_ia64_longjmp (JB=0x6000000000817020, VAL=1) at continuations.c:372
  #1  0x2000000000148e00 in scm_c_abort (vm=0x60000000000edea0, tag=0x6000000000795ba0, n=0, argv=0x60000fffff7f0ce0, cookie=-1) at control.c:239
  #2  0x2000000000149070 in scm_at_abort (tag=0x6000000000795ba0, args=0x304) at control.c:258
  (gdb) print t
  $2 = (scm_i_thread *) 0x6000000000068000
  (gdb) print t->pending_rbs_continuation
  $3 = (scm_t_contregs *) 0xffeb

The problem here is the value of 't->pending_rbs_continuation' pointer.
It's supposed to poin to a register stack pointer or be NULL if not yet
backed up.

The problem is it is never initialized to NULL at creation time and
contained garbage on stack. Sometimes people are lucky and have zeros
on stack and guile works. But sometimes there is something and guile
crashes.

The fix is trivial: initialize 'pending_rbs_continuation = NULL'
at thread registration time (the same way other threads are registered).

Reported-by: Matt Turner

* libguile/threads.c (guilify_self_1): Initialize pending_rbs_continuation
to avoid crash on ia64.

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2017-11-22 16:15:20 +01:00
Ludovic Courtès
83d4c4d622 Honor '%fresh-auto-compile'.
Fixes <https://bugs.gnu.org/29226>.

* libguile/load.c (scm_primitive_load_path): Set 'compiled_thunk' to
SCM_BOOL_F when *scm_loc_fresh_auto_compile is true.
* module/ice-9/boot-9.scm (load-in-vicinity)[load-absolute]: Call
'pre-compiled' only when %FRESH-AUTO-COMPILE is false.
2017-11-22 16:04:24 +01:00
Ludovic Courtès
2fe9a852fb Destroy the mutex associated with a dirstream.
This is a followup to 187655cedb.

* libguile/filesys.c (scm_dir_free): Add call to
'scm_i_pthread_mutex_destroy'.
2017-11-18 21:09:26 +01:00
Ludovic Courtès
187655cedb 'readdir' no longer deadlocks upon error.
If 'readdir' returned an error, we'd call SCM_SYSERROR, which would try
to acquire 'scm_i_misc_mutex' and sit there forever because it was
already taken.

Reported at <https://bugs.gnu.org/29335>.

* libguile/filesys.c (scm_opendir): Allocate storage for a mutex and
store it as the third word of the SMOB.
(scm_readdir): Use that mutex instead of 'scm_i_misc_mutex'.  Fixes the
deadlock upon error.
(scm_rewindir): Lock the mutex around the 'rewinddir' call.
2017-11-17 23:05:53 +01:00
Ludovic Courtès
81d2e35266 Allow GDB support to be used with GDB-linked-against-Guile-2.0.
* libguile/Makefile.am (INSTANTIATE): New variable.
(install-data-hook): Use it.
* libguile/libguile-2.2-gdb.scm: Autoload (system vm debug).
Augment %load-path and %load-compiled-path, and reload (system base
types).
* module/system/base/types.scm: Remove #:hide to be 2.0-compatible.
Use (system syntax internal) conditionally when on 2.2.
2017-11-05 18:21:35 +01:00
Andy Wingo
dc8dda77e0 More robust vacuuming of in-use weak tables
* libguile/weak-table.c (scm_t_weak_table); Add last_gc_no member.
* libguile/weak-table.c (vacuum_weak_table): Only vacuum if we haven't
  done so since the last GC.
  (scm_c_weak_table_ref, scm_c_weak_table_put_x, scm_c_weak_table_remove_x)
  (scm_c_weak_table_fold): Vacuum the weak table if needed.
  (scm_weak_table_clear_x): Update last_gc_no flag, as no more vacuuming
  will be needed.
2017-11-01 09:46:03 +01:00
Andy Wingo
d01addeb1f Refactor weak table to use bitmaps for weak entries 2017-11-01 09:46:03 +01:00
Andy Wingo
a053c0510c Weak tables are now bucket-and-chain tables
This change should make weak tables work better with libgc, as the weak
components that need mark functions are smaller, so they don't overflow
the mark queue.  Also this prevents the need to move disappearing
links.

* libguile/weak-table.c (scm_t_weak_entry): Change to be a hash table
  chain entry.
  (struct weak_entry_data, do_read_weak_entry, read_weak_entry): Read
  out the key and value directly.
  (GC_move_disappearing_link, move_disappearing_links, move_weak_entry):
  Remove.
  (scm_t_weak_table): Rename "entries" member to "buckets", and "size" to
  "n_buckets".
  (hash_to_index, entry_distance, rob_from_rich, give_to_poor): Remove.
  (mark_weak_key_entry, mark_weak_value_entry): Mark a single link, and
  the next link.
  (mark_doubly_weak_entry): New kind.
  (allocate_entry): Allocate a single entry.
  (add_entry): New helper.
  (resize_table): Reimplement more like normal hash tables.
  (vacuum_weak_table): Adapt to new implementation.
  (weak_table_ref, weak_table_put_x, weak_table_remove_x): Adapt.
  (make_weak_table): Adapt.
  (scm_weak_table_clear_x): Actually unregister the links to prevent a
  memory leak.
  (scm_c_weak_table_fold): Collect items in an alist, then fold outside
  the lock.
  (scm_weak_table_prehistory): Initialize doubly_weak_gc_kind.
2017-11-01 09:46:03 +01:00
Daniel Llorens
badcbd0fe9 Support general arrays in random:hollow-sphere!
* libguile/random.c (vector_scale_x, vector_sum_squares): Handle general
  rank-1 #t or 'f64 arrays.
* test-suite/tests/random.test: Add tests for random:hollow-sphere!.
2017-10-31 13:30:01 +01:00
Daniel Llorens
e0bcda4ad9 Fix bitvectors and non-zero lower bound arrays in truncated-print
* module/ice-9/arrays.scm (array-print-prefix): New private function.
* libguile/arrays.c (scm_i_print_array): Reuse (array-print-prefix) from
  (ice-9 arrays). Make sure to release the array handle.
* module/ice-9/pretty-print.scm (truncated-print): Support
  bitvectors.
  Don't try to guess the array prefix but call array-print-prefix from
  (ice-9 arrays) instead.
  Fix call to print-sequence to support non-zero lower bound arrays.
* test-suite/tests/arrays.test: Test that arrays print properly.
* test-suite/tests/print.test: Test truncated-print with bitvectors,
  non-zero lower bound arrays.
2017-10-31 13:23:44 +01:00
Daniel Llorens
f52fc0566f Support non-zero lower bounds in array-slice-for-each
* libguile/array-handle.c (scm_array_handle_writable_elements): Fix
  error message.
* libguile/array-map.c (scm_array_slice_for_each): Support non-zero
  lower bounds. Fix error messages.
* test-suite/tests/array-map.test: Test scm_array_slice_for_each with
  non-zero lower bound argument.
2017-10-31 13:23:17 +01:00
Daniel Llorens
3bfd4aaa6e Fix sort, sort! for arrays with nonzero lower bound
* module/ice-9/arrays.scm (array-copy): New function, export.
* module/Makefile.am: Install (ice-9 arrays).
* doc/ref/api-data.texi: Add documentation for (ice-9 arrays).
* libguile/quicksort.i.c: Use signed bounds throughout.
* libguile/sort.c (scm_restricted_vector_sort_x): Fix error calls. Fix
  calls to quicksort.
* test-suite/tests/sort.test: Actually test that the sorted results
  match the original data. Test cases for non-zero base index arrays for
  sort, sort!, and stable-sort!.
2017-10-31 13:23:17 +01:00
Daniel Llorens
4212f29655 Allow scm_XXX_writable_elements on empty vectors, even if immutable
* libguile/array-handle.c (initialize_vector_handle): Set both element
  pointers to NULL if the vector is empty.
* libguile/array-map.c (racp): Ignore immutability if destination is
  empty.
* test-suite/tests/sort.test: Check empty/mutable/immutable vectors with
  sort!.
* test-suite/tests/array-map.test: Check array-copy! with
  empty/immutable destination.
2017-10-31 13:23:17 +01:00
Ludovic Courtès
1008ea3154 Allow garbage collection of revealed file ports.
Reported at <https://bugs.gnu.org/28784>.
Discussed at
<https://lists.gnu.org/archive/html/guile-devel/2017-10/msg00003.html>.

* libguile/fports.c (revealed_ports, revealed_lock): Remove.
(scm_revealed_count): Just return 'SCM_REVEALED (port)'.
(scm_set_port_revealed_x, scm_adjust_port_revealed_x): Remove
REVEALED_PORTS manipulation.
(fport_close): Do nothing when SCM_REVEALED (port) > 0.
* libguile/fports.h (scm_t_fport): Adjust comment; make 'revealed'
unsigned.
* libguile/ports.c (do_close): Call 'close_port' instead of
'scm_close_port'.
(scm_close_port): Rename to...
(close_port): ... this.  Add 'explicit' parameter.  Clear 'revealed'
field when PORT is a file port and EXPLICIT is true.
(scm_close_port): Call 'close_port'.
* test-suite/tests/ports.test ("close-port & revealed port")
("revealed port fdes not closed"): New tests.
2017-10-25 11:39:38 -07:00
Andy Wingo
a74d4ee4f6 Add struct-ref/unboxed, struct-set!/unboxed
* NEWS: Add news entry.
* doc/ref/api-data.texi (Vtables, Structure Basics): Update
  documentation.
* libguile/struct.c (scm_i_struct_equalp): Avoid using struct-ref on
  unboxed fields.
  (scm_struct_ref, scm_struct_set_x_unboxed): Issue deprecation warning
  when accessing unboxed fields.
  (scm_struct_ref_unboxed, scm_struct_set_x_unboxed): New functions.
* libguile/struct.h (scm_struct_ref_unboxed, scm_struct_set_x_unboxed):
  New functions.
* module/oop/goops.scm (class-add-flags!, class-clear-flags!):
  (class-has-flags?, <class>, %allocate-instance, <slot>):
  (compute-get-n-set, unboxed-get, unboxed-set, unboxed-slot?):
  (allocate-slots, %prep-layout!, make-standard-class, initialize):
  Adapt to access unboxed nfields and flags fields via the new
  accessors.
2017-09-25 21:54:36 +02:00
Andy Wingo
b0ecf83ef0 Deprecate opaque struct fields
* NEWS: Add entry.
* doc/ref/api-data.texi (Vtables, Structure Basics): Remove mention of
  opaque field protection.
* libguile/struct.c (scm_make_struct_layout, scm_make_struct_no_tail):
  Remove discussion of opaque fields.
  (set_vtable_layout_flags): Issue a deprecation warning when opaque
  fields are used.
2017-09-23 11:14:27 +02:00
Andy Wingo
84aa050f92 Remove needless static variables from goops.c
* libguile/goops.c: Remove many static SCM variables that were not
  used on the C level, like class_protected for <protected-slot> and so
  on.
2017-09-22 16:12:07 +02:00
Andy Wingo
c7c7588f24 Fix up make-struct-layout and make-struct/no-tail docstrings
* libguile/struct.c (scm_make_struct_layout, scm_make_struct_no_tail):
  Fix up docstrings for self and tail deprecation.
2017-09-22 11:38:41 +02:00
Andy Wingo
04f48e94b5 Deprecate struct "self" slots
* libguile/print.h (SCM_PRINT_STATE_LAYOUT): Use a normal slot instead
  of a self slot.
* libguile/print.c (make_print_state): Initialize "handle" slot
  manually.
* libguile/struct.c (issue_deprecation_warning_for_self_slots): New
  helper, called when making vtables to issue deprecation warnings for
  "self" slots.  Avoids warning for the "self" slot that's part of the
  fixed vtable slots.
  (scm_i_struct_inherit_vtable_magic): Call
  issue_deprecation_warning_for_self_slots.
* doc/ref/api-data.texi (Vtables, Structure Basics): Remove references
  to self slots.
* NEWS: Add entry.
2017-09-22 11:35:36 +02:00
Andy Wingo
9ac0544eff Remove unused code in struct.c
* libguile/struct.c (scm_make_struct_layout, scm_struct-ref)
  (scm_struct_set_x): Remove commented-out support for signed and double
  raw fields.
2017-09-22 10:32:36 +02:00
Andy Wingo
fe4a34d20d Deprecate make-struct
* libguile/struct.c: Replace uses of scm_make_struct with
  scm_make_struct_no_tail or scm_c_make_struct.
  (scm_make_struct_no_tail): Move this function to C instead of Scheme
  to be able to deprecate scm_make_struct.
* libguile/struct.h (scm_make_struct_no_tail): New public declaration.
* libguile/deprecated.h:
* libguile/deprecated.c (scm_make_struct): Deprecate.
* libguile/print.c:
* libguile/procs.c:
* libguile/stacks.c: Replace uses of scm_make_struct with
  scm_make_struct_no_tail.
* test-suite/tests/coverage.test:
* test-suite/tests/structs.test: Use make-struct/no-tail instead of
  make-struct.
* NEWS: Add entry.
2017-09-22 10:32:33 +02:00
Mark H Weaver
ac0d3dcc53 put-bytevector, unget-bytevector: Allow start == bytevector length.
* libguile/r6rs-ports.c (scm_put_bytevector, scm_unget_bytevector): When
three arguments (port bv start) are provided, allow start to be equal to
the length of the bytevector, resulting in a zero-length write.
2017-07-31 11:37:58 -04:00
Ludovic Courtès
155ddcdc3b Correctly relativize file names in the presence of common prefixes.
* libguile/filesys.c (scm_i_relativize_path): When DIR is a prefix of
SCANON, make sure DIR ends with a separator or SCANON starts with a
separator.
* test-suite/tests/ports.test (%temporary-directory): New variable.
("%file-port-name-canonicalization")["relative canonicalization with
common prefixes"]: New test.
2017-06-15 17:48:12 +02:00
Andy Wingo
2e5f7d8f6d Syntax objects are comparable with equal?
* libguile/eq.c (scm_equal_p, scm_raw_ihash): Add cases for syntax
  objects, which should be comparable with equal?.
* test-suite/tests/syntax.test ("syntax objects"): Add tests.
2017-04-21 11:56:51 +02:00
Andy Wingo
40df57a8a2 Restore libgc 7.2 compatibility
* configure.ac: Check for GC_is_heap_ptr, added after libgc 7.2.
* libguile/pairs.h (GC_is_heap_ptr): Define a shim for GC_is_heap_ptr,
  inside BUILDING_LIBGUILE so as not to expose it to users.
2017-04-20 10:40:07 +02:00
Sergei Trofimovich
f775ab3654 guile-snarf: skip -g* arguments to avoid build failure
* libguile/guile-snarf.in: skip -g* arguments to avoid failure on
  -ggdb3.

Bug: https://bugs.gentoo.org/608190
Bug: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=25803
Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
2017-04-19 17:19:40 +02:00
Andy Wingo
5d5d3d75d0 Fix spurious warnings in net_db.c
* libguile/guile-func-name-check (/^SCM_DEFINE /): Fix pattern to not
  produce spurious warnings.  Thanks to Dale Smith for the suggestion.
  Fixes https://bugs.gnu.org/26123.
2017-04-19 16:48:56 +02:00
Andy Wingo
6010792787 Avoid causing GC when lookup up exception handler
* libguile/fluids.c (scm_fluid_ref_star): Avoid causing GC.  Possibly
  fixes some crashes during out-of-memory conditions (#26351).
2017-04-19 14:48:44 +02:00
Andy Wingo
e0502f3c77 Bump objcode version in a compatible way
* libguile/_scm.h (SCM_OBJCODE_MINIMUM_MINOR_VERSION): New definition,
  indicating the oldest objcode version that we support.
  (SCM_OBJCODE_MINOR_VERSION): Bump.
* libguile/loader.c (process_dynamic_segment): Support a range of
  versions.
* module/system/vm/assembler.scm (*bytecode-minor-version*): Bump.
2017-04-18 21:37:36 +02:00