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

8493 commits

Author SHA1 Message Date
Mike Gran
f5b362586d Check for working profiling and virtual itimers
* configure.ac (HAVE_USABLE_GETITIMER_PROF, HAVE_USABLE_GETITIMER_VIRTUAL): new tests
* doc/ref/posix.texi (setitimer, getitimer): document provided? 'ITIMER_VIRTUAL and 'ITIMER_PROF
* doc/ref/statprof.texi (statprof): document ITIMER_PROF requirements
* libguile/scmsigs.c (scm_setitimer, scm_getitimer): document (provided? 'ITIMER_VIRTUAL) and (provided? 'ITIMER_READ)
  (scm_init_scmsigs): add features ITIMER_VIRTUAL and ITIMER_PROF
* test-suite/tests/asyncs.test ("prevention via sigprof"): throw when unsupported
* test-suite/tests/signals.test: throw when not supported
* test-suite/tests/statprof.test: throw when not supported
2017-03-06 23:08:25 -08:00
Mike Gran
8dc0e8d622 Fix regression in non-mmap fallback elf loader
* libguile/loader.c [!HAVE_SYS_MMAN_H] (map_file_contents): updated
  variables and function calls to the current names
2017-03-03 09:50:27 -08:00
Ludovic Courtès
817a071209 build: Honor $SOURCE_DATE_EPOCH for the recorded timestamp.
Reported by Jan Nieuwenhuizen <janneke@gnu.org>
at <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=20272#36>.

* libguile/Makefile.am (libpath.h): Honor 'SOURCE_DATE_EPOCH'.
2017-03-01 20:58:37 +01:00
Ludovic Courtès
7d6f309ccd Treat 'SIG_IGN' as a pointer.
* libguile/posix.c (scm_system_star): Cast 'SIG_IGN' to
'scm_t_uintptr_t' and use 'scm_from_uintptr_t'.  This fixes an
'int-conversion' warning with GCC 6.2.
2017-03-01 19:58:31 +01:00
Ludovic Courtès
844b2cf758 Remove 'umask' calls from 'mkdir'.
Fixes <http://bugs.gnu.org/24659>.

* libguile/filesys.c (SCM_DEFINE): Remove calls to 'umask' when MODE is
unbound; instead, use 0777 as the mode.  Update docstring to clarify
this.
* doc/ref/posix.texi (File System): Adjust accordingly.
* NEWS: Mention it.
2017-03-01 19:54:31 +01:00
Andy Wingo
25652ff84c %port-encoding requires an open port
* libguile/ports.c (scm_sys_port_encoding)
  (scm_sys_set_port_encoding_x): Require an open port, to match 2.0
  behavior.
2017-03-01 19:52:17 +01:00
Mark H Weaver
8f7ed8abf2 build: .x and .doc files depend on generated includes.
Fixes <https://bugs.gentoo.org/show_bug.cgi?id=590528>.

* libguile/Makefile.am (BUILT_INCLUDES): New variable.
(BUILT_SOURCES): Put generated .h to BUILT_INCLUDES.
(DOT_X_FILES, EXTRA_DOT_X_FILES, DOT_DOC_FILES, EXTRA_DOT_DOC_FILES):
Depend on $(BUILT_INCLUDES), in place of scmconfig.h which is included
in $(BUILT_INCLUDES).
2017-03-01 19:31:42 +01:00
Mark H Weaver
1d257c27f0 Do not assume that sizeof (long) == sizeof (void *) == sizeof (SCM).
This assumption does not hold on systems that use the LLP64 data model.

Partially fixes <https://debbugs.gnu.org/22406>.
Reported by Peter TB Brett <peter@peter-b.co.uk>.

* libguile/numbers.h (scm_t_inum): Move here from numbers.c, and change
  to be equivalent to 'long' (formerly 'scm_t_signed_bits').
  (SCM_MOST_POSITIVE_FIXNUM, SCM_MOST_NEGATIVE_FIXNUM): Define based on
  SCM_I_FIXNUM_BIT instead of SCM_T_SIGNED_BITS_MAX.
  (SCM_I_INUM): Adjust definitions to return a 'scm_t_inum', and avoiding
  the assumption that SCM_UNPACK returns a 'long'.
* libguile/numbers.c (scm_t_inum): Move definition to numbers.h.
  Verify that 'scm_t_inum' fits within a SCM value.
  (scm_i_inum2big): Remove preprocessor code that forced a compile error
  unless sizeof (long) == sizeof (void *).
2017-03-01 19:08:42 +01:00
Mark H Weaver
a8d1c7d610 Avoid signed integer overflows in numeric conversions.
Reported by Miroslav Lichvar <mlichvar@redhat.com>
in <https://lists.gnu.org/archive/html/guile-devel/2016-02/msg00045.html>

* libguile/conv-integer.i.c: Avoid signed overflow.
* libguile/numbers.c (scm_is_signed_integer): Avoid signed overflow.
2017-03-01 19:05:30 +01:00
Andy Wingo
82ea7c763b Fix open-file mode misinterpretation
* libguile/fports.c (scm_i_mode_to_open_flags): Validate that argument
  is string.  Fixes #25498.
2017-03-01 17:34:41 +01:00
Andy Wingo
24eea1be08 "select" no longer throws exception on EINTR
* doc/ref/posix.texi (Ports and File Descriptors): Update.
* libguile/filesys.c (scm_select): Use scm_std_select so that pending
  interrupts can be delivered.  On EINTR or EAGAIN, just return directly
  so that calling Scheme code can run asyncs.
2017-03-01 17:27:56 +01:00
Andy Wingo
0660364998 scm_std_select doesn't tick itself
* libguile/threads.c (scm_std_select): If there are unblocked asyncs
  pending, return directly instead of ticking ourselves.
2017-03-01 17:23:48 +01:00
Andy Wingo
a86bb2e613 Fix (mkstemp! "XX" 0) errors
* libguile/filesys.c (scm_i_mkstemp): Validate "mode" argument as a
  string, and validate writability of template string early too.  Thanks
  to Jean Louis for the bug report.
2017-03-01 14:48:37 +01:00
Andy Wingo
1da66a6ab1 String ports can be truncated
* libguile/strports.c (string_port_truncate):
  (scm_make_string_port_type): Support truncate-file on string ports.
* test-suite/tests/ports.test ("string ports"): Add tests.
2017-03-01 14:24:36 +01:00
Andy Wingo
68f13adaaf Better errors for odd-length keyword args
* libguile/vm-engine.c (bind-kwargs):
* libguile/vm.c (vm_error_kwargs_missing_value):
* libguile/eval.c (error_missing_value)
  (prepare_boot_closure_env_for_apply): Adapt to mirror VM behavior.
* libguile/keywords.c (scm_c_bind_keyword_arguments): Likewise.
* module/ice-9/eval.scm (primitive-eval): Update to error on (foo #:kw)
  with a "Keyword argument has no value" instead of the horrible "odd
  argument list length".  Also adapts to the expected args format for
  the keyword-argument-error exception printer in all cases.  Matches
  1.8 optargs behavior also.
* test-suite/standalone/test-scm-c-bind-keyword-arguments.c (test_missing_value):
  (missing_value_error_handler): Update test.
* test-suite/tests/optargs.test: Add tests.
2017-02-28 22:01:20 +01:00
Andy Wingo
33514ffe22 Fix segfault introduced with R6RS port commit
* libguile/init.c (scm_i_init_guile): Move scm_register_r6rs_ports
  later, so that defining port types hsa the SCM trampoline subrs
  defined.
* libguile/bytevectors.c (scm_bootstrap_bytevectors): Cosmetic changes.
2017-02-28 17:02:25 +01:00
Andy Wingo
94d70684c1 Register R6RS port and bytevector internals early
* libguile/bytevectors.c (sym_big, sym_little): Rename from scm_sym_big
  and scm_sym_little, and don't use the snarf mechanism as we need to
  initialize this value eagerly in case the C API is used before the
  Scheme module is loaded.
  (scm_bootstrap_bytevectors): Initialize the endianness symbols here.
* libguile/r6rs-ports.c (scm_register_r6rs_ports): Register the R6RS
  port kinds here, for the same reason.
2017-02-28 14:19:24 +01:00
Andy Wingo
4c3bea3dba Fix support for threads already known to GC
* libguile/threads.h (scm_i_thread): Add bool tracking whether the
  thread needs to be unregistered from libgc.
* libguile/threads.c (guilify_self_1): Add needs_unregister arg.
  (on_thread_exit): Only unregister thread if the thread needs it.
  (scm_i_init_thread_for_guile): A thread needs unregistering if
  GC_register_my_thread succeeded.
  (scm_threads_prehistory): Don't unregister initial thread.

  Fixes #19523.  Thanks to Anthonin Bonnefoy for the report.
2017-02-28 13:14:02 +01:00
Andy Wingo
70d4c4b284 Fix (* x -1) for GOOPS types
* libguile/numbers.c (scm_product): Only reduce (* x -1) to (- x) when X
  is a bignum.  Fixes weirdness when X is not a number and instead
  multiplication should dispatch to GOOPS.  Thanks to Alejandro Sanchez
  for the report.
2017-02-28 10:12:57 +01:00
Andy Wingo
5333642b71 Use labs instead of abs where needed
* libguile/numbers.c (log_of_fraction): Use labs instead of abs on
  longs.  Thanks to Matt Wette for the tip.
2017-02-21 22:12:18 +01:00
Matt Wette
c4b0491e91 Fix make-polar signedness of zeros on macOS
* configure.ac: Check for __sincos.
* libguile/numbers.c (scm_c_make_polar): Fall back to __sincos if
  possible.  Fixes zero signedness of make-polar on macOS.
2017-02-21 22:09:01 +01:00
Andy Wingo
36023a0d2e Conditionally define SOCK_CLOEXEC, SOCK_NONBLOCK
* libguile/socket.c (scm_init_socket): Conditionally define SOCK_CLOEXEC
  and SOCK_NONBLOCK.  Fixes compilation on macOS.
2017-02-21 22:01:45 +01:00
Andy Wingo
bfa6c401ce Speed up number->string
* libguile/numbers.c (scm_number_to_string): Use scm_from_latin1_string
  where appropriate.  Avoids mucking about with iconv.
2017-02-17 11:58:22 +01:00
Andy Wingo
9ee21f3e97 Minor make-string optimization
* libguile/strings.c (STRINGBUF_SET_MUTABLE): New helper.
  (scm_i_string_ensure_mutable_x): Use new helper.
  (scm_make_string): Mark stringbuf as mutable.
2017-02-17 11:29:31 +01:00
Andy Wingo
2864f11d34 Bump fluid cache size to 16 entries
* libguile/cache-internal.h (SCM_CACHE_SIZE): Bump to 16.  It seems that
  a thread accesses more than 8 fluids by default (%stacks, the
  exception handler, current ports, current-fiber, port read/write
  waiters) which leads every fiber to cause cache eviction and copying
  the value table, which is a bottleneck.  Instead just bump this cache
  size.
  (scm_cache_lookup): Update unrolled search.
2017-02-17 11:04:16 +01:00
Andy Wingo
60035b66c7 Revert "Cheaper fluid-ref cache"
This reverts commit cd3ff33a31.
2017-02-17 11:04:16 +01:00
Andy Wingo
d0934df1f2 Stringbufs immutable by default
* libguile/snarf.h (SCM_IMMUTABLE_STRINGBUF): Remove shared flag.
  Stringbufs are immutable by default.
* libguile/strings.c: Rewrite blurb.  Change to have stringbufs be
  immutable by default and mutable only when marked as such.  Going
  mutable means making a private copy.
  (STRINGBUF_MUTABLE, STRINGBUF_F_MUTABLE): New definitions.
  (SET_STRINGBUF_SHARED): Remove.
  (scm_i_print_stringbuf): Simplify to just alias the stringbuf as-is.
  (substring_with_immutable_stringbuf): New helper.
  (scm_i_substring, scm_i_substring_read_only, scm_i_substring_copy):
  use new helper.
  (scm_i_string_ensure_mutable_x): New helper.
  (scm_i_substring_shared): Use scm_i_string_ensure_mutable_x.
  (stringbuf_write_mutex): Remove; yaaaaaaaay.
  (scm_i_string_start_writing): Use scm_i_string_ensure_mutable_x.  No
  more mutex.
  (scm_i_string_stop_writing): Now a no-op.
  (scm_i_make_symbol): Use substring/copy.
  (scm_sys_string_dump, scm_sys_symbol_dump): Update.
* libguile/strings.h (SCM_I_STRINGBUF_F_SHARED): Remove.
  (SCM_I_STRINGBUF_F_MUTABLE): Add.
* module/system/vm/assembler.scm (link-data): Don't add shared flag any
  more.  Existing compiled flags are harmless tho.
* test-suite/tests/strings.test ("string internals"): Update.
2017-02-16 13:11:29 +01:00
Andy Wingo
c38b9625c8 Remove unnecessary scm_i_string_start_writing calls
* libguile/strings.c (scm_string, scm_c_make_string):
* libguile/srfi-13.c (scm_reverse_list_to_string, scm_string_map)
  (scm_string_unfold, scm_string_unfold_right, scm_xsubstring)
  (scm_string_filter, scm_string_delete): Remove
  scm_i_string_start_writing / scm_i_string_stop_writing calls around
  fresh strings that aren't visible to other threads.
2017-02-16 10:43:23 +01:00
Andy Wingo
cd3ff33a31 Cheaper fluid-ref cache
* libguile/cache-internal.h (struct scm_cache_entry): Add needs_flush
  member.
  (scm_cache_evict_1): Clear needs_flush on newly evicted entry.
  (scm_cache_insert): Propagate needs_flush to new entry.
* libguile/fluids.c (restore_dynamic_state): Mark all restored entries
  as needing a flush.
  (save_dynamic_state): Only cons on "needs_flush" entries to the
  resulting dynamic state.  The result is the same as before but
  avoiding the refq on the weak table.
  (fluid_set_x): Propagate needs_flush down to the cache.
  (fluid_ref): When adding entry to cache, use needs_flush==0.
  (scm_fluid_set_x, scm_fluid_unset_x, scm_swap_fluid, swap_fluid): Use
  needs_flush==1.
2017-02-16 10:38:15 +01:00
Andy Wingo
6e0965104c Add accept4 support
* doc/ref/posix.texi (Network Sockets and Communication): Add
  documentation.
* libguile/socket.c (scm_accept4): New function, replaces accept
  implementation.
  (scm_accept): Call scm_accept4.
  (scm_init_socket): Define SOCK_CLOEXEC and SOCK_NONBLOCK.
* libguile/socket.h: Add private scm_accept4 decl.
* module/ice-9/suspendable-ports.scm (accept): Update.
2017-02-15 22:10:25 +01:00
Andy Wingo
9399c13479 Switch to accept4
* lib/Makefile.am:
* m4/gnulib-cache.m4:
* m4/gnulib-comp.m4: Switch from accept gnulib module to accept4.
* libguile/socket.c (scm_accept): Use accept4.
2017-02-15 21:45:17 +01:00
Andy Wingo
69ca2bb221 Elide syscalls in fdes->port
* libguile/fports.h (scm_t_fport): Add options field.
  (SCM_FDES_RANDOM_P): Deprecate.
  (scm_i_fdes_to_port): Add options argument.
* libguile/fports.c (scm_i_fdes_to_port): Add options argument.  Only
  verify FD if SCM_FPORT_OPTION_VERIFY is there.
  (scm_fdes_to_port, scm_open_file_with_encoding): Adapt to
  scm_i_fdes_to_port changes.
  (fport_random_access_p): Don't try to seek if NOT_SEEKABLE option is
  set.
* libguile/deprecated.h:
* libguile/deprecated.c (SCM_FDES_RANDOM_P): Deprecate.
* NEWS: Add deprecation.
* libguile/filesys.c:
* libguile/ioext.c:
* libguile/posix.c:
* libguile/read.c:
* libguile/socket.c: Adapt callers.
2017-02-14 22:03:21 +01:00
Andy Wingo
2c02bdda19 Fix compilation of continuations.c
* libguile/continuations.c (scm_i_continuation_to_frame): Remove unused
  assignment.  The previous commit removed the declaration in order to
  silence an unused-assignment warning, but forgot to remove the
  assignment :/
2017-02-13 10:13:27 +01:00
Andy Wingo
8e1af70c2c Remove unused variable in continuations.c
* libguile/continuations.c (scm_i_continuation_to_frame): Remove unused
  variable.
2017-02-12 20:33:37 +01:00
Andy Wingo
00ed4043c2 VM continuations store FP/SP by offset
* libguile/continuations.c (scm_i_continuation_to_frame):
* libguile/stacks.c (scm_make_stack):
* libguile/vm.c (scm_i_vm_cont_to_frame, scm_i_vm_capture_stack):
  (vm_return_to_continuation_inner)
  (struct vm_reinstate_partial_continuation_data):
  (vm_reinstate_partial_continuation_inner):
  (vm_reinstate_partial_continuation):
* libguile/vm.h (sstruct scm_vm_cont): Simplify VM continuations by
  recording the top FP by offset, not value + reloc.
* libguile/frames.c (frame_offset, scm_i_vm_frame_offset): Remove unused
  functions.
* libguile/frames.h (SCM_VALIDATE_VM_FRAME, scm_i_vm_frame_offset):
  Remove.
* libguile/control.c (reify_partial_continuation): Once we know the
  base_fp, relocate the dynamic stack.
* libguile/dynstack.h:
* libguile/dynstack.c (scm_dynstack_relocate_prompts): New function.
  (scm_dynstack_wind_prompt): Adapt to add new fp offset.
2017-02-12 20:31:14 +01:00
Andy Wingo
5048a8afbc Avoid reading garbage from dynstack
* libguile/dynstack.c (push_dynstack_entry_unchecked): Reset top
  dynstack tag to prevent garbage.
2017-02-12 18:02:53 +01:00
Andy Wingo
09a69dd712 Prevent TOCTTOU bugs in C ports
* libguile/ports-internal.h (scm_port_buffer_can_take):
  (scm_port_buffer_can_put): Add cur/end output arguments so that when a
  caller asks the buffer room, it can be relative to a fixed point in
  the buffer and not whatever point it's at when we go to fill it.
  (scm_port_buffer_did_take, scm_port_buffer_did_put): Similarly,
  require that the caller knows where they took/put data in the buffer.
  Prevents overflow.
  (scm_port_buffer_take_pointer, scm_port_buffer_put_pointer): Likewise,
  require that the caller has already checked and knows a position in
  the buffer and therefore how much data is available.
  (scm_port_buffer_take, scm_port_buffer_put, scm_port_buffer_putback):
  Adapt.
* libguile/ports.h (scm_fill_input): Add cur/avail output arguments.
* libguile/filesys.c:
* libguile/poll.c:
* libguile/ports.c:
* libguile/r6rs-ports.c:
* libguile/read.c:
* libguile/rw.c: Adapt all callers.  Gnarly work!
2017-02-08 15:09:14 +01:00
Daniel Llorens
a0028723da Fix bug #25492
* libguile/vm-engine.c (BR_F64_ARITHMETIC): Fix type.
2017-02-07 12:16:16 +01:00
Andy Wingo
498f3f9568 Avoid stacks in dynamically-bound values
* libguile/dynstack.h:
* libguile/dynstack.c (scm_dynstack_find_old_fluid_value): New
  function.
* libguile/fluids.c (saved_dynamic_state_ref): New helper.
  (scm_fluid_ref): Fix docstring.
  (scm_fluid_ref_star): New function allowing access to previous values
  for a fluid.
  (scm_dynamic_state_ref): New internal function.
* libguile/fluids.h: Add scm_fluid_ref_star and scm_dynamic_state_ref.
* libguile/stacks.c (scm_stack_id): Adapt to %stacks not being a chain.
* libguile/throw.c (catch, throw_without_pre_unwind): Adapt to
  %exception-handlers not being a chain.
* module/ice-9/boot-9.scm (catch, dispatch-exception): Instead of having
  %exception-handlers be a chain, use fluid-ref* to access the chain
  that is in place at the time the exception is thrown.  Prevents
  unintended undelimited capture of the current exception handler stack
  by a delimited "catch".
  (%start-stack): Similarly, don't be a chain.
* module/system/repl/debug.scm (frame->stack-vector):
* module/system/repl/error-handling.scm (call-with-error-handling):
* module/ice-9/save-stack.scm (save-stack): Adapt to %stacks not being a
  chain.
* test-suite/tests/exceptions.test ("delimited exception handlers"): Add
  tests.
* doc/ref/api-control.texi (Fluids and Dynamic States): Add docs.
2017-02-07 09:57:55 +01:00
Andy Wingo
eec9aeba56 Fix build warning
* libguile/stime.c (scm_init_stime): Remove unused variable.
2017-01-19 01:43:51 +01:00
David Thompson
35a9059250 Add unboxed floating point comparison instructions.
* libguile/vm-engine.c (BR_F64_ARITHMETIC): New preprocessor macro.
(br_if_f64_ee, br_if_f64_lt, br_if_f64_le, br_if_f64_gt, br_if_f64_ge):
New VM instructions.
* doc/ref/vm.texi ("Unboxed Floating-Point Arithmetic"): Document them.
* module/language/cps/compile-bytecode.scm (compile-function): Emit f64
comparison instructions.
* module/language/cps/effects-analysis.scm: Define effects for f64
primcalls.
* module/language/cps/primitives.scm (*branching-primcall-arities*): Add
arities for f64 primcalls.
* module/language/cps/specialize-numbers.scm (specialize-f64-comparison):
New procedure.
(specialize-operations): Specialize f64 comparisons.
* module/system/vm/assembler.scm (emit-br-if-f64-=, emit-br-if-f64-<)
(emit-br-if-f64-<=, emit-br-if-f64->, emit-br-if-f64->=): Export.
* module/system/vm/disassembler.scm (code-annotation): Add annotations
for f64 comparison instructions.
2017-01-12 09:27:43 -05:00
Andy Wingo
63bf6ffa0d Protect call-with-new-thread data from GC.
* libguile/threads.c (struct launch_data): Add prev/next pointers.
  (protected_launch_data, protected_launch_data_lock): New static vars.
  (protect_launch_data, unprotect_launch_data): New functions.
  (really_launch, scm_sys_call_with_new_thread): Preserve launch data
  from GC.  Thanks to Linas Vepstas for the report!
2017-01-11 22:19:31 +01:00
Daniel Llorens
7e93950552 Final names for new array functions
Globally rename (array-from* -> array-slice), (array-from ->
array-cell-ref), (array-amend! -> array-cell-set!), (array-for-each-cell
-> array-slice-for-each).
2017-01-09 09:02:04 +01:00
Andy Wingo
2976abdbbb Fix scm_init_stime for macOS
* libguile/stime.c (scm_init_stime): Remove needless test of
  clock_getcpuclockid.  Fixes build on macOS; thanks to Matt Wette for
  the report and fix.
2017-01-08 23:45:58 +01:00
Andy Wingo
81d8ff9e45 Fix alloc_aligned for high allocations
* libguile/loader.c (alloc_aligned): Widen alignment.  Thanks to Matt
  Wette for the report and the fix!
2017-01-08 23:41:12 +01:00
Andy Wingo
c391ab8c90 Speed up load-thunk-from-memory for page alignment
* libguile/loader.c (page_size): New static var.
  (alloc_aligned): Enable mmap path that was never used in the
  past (!).  Thanks to Matt Wette for the bug report!
  (load_thunk_from_memory): Use page_size instead of 4096.
  (scm_bootstrap_loader): Init page_size.
2017-01-08 23:39:42 +01:00
Andy Wingo
6ff1ec9c31 Fix mkstemp on macOS
* libguile/filesys.c (scm_i_mkstemp): Limit flags to mkostemp.  Based on
  a patch by Matt Wette; thanks!
2017-01-08 23:25:56 +01:00
Andy Wingo
b392d81c9c Fix close-port race.
* libguile/ports.c (release_port): Fix race.
2017-01-08 15:42:22 +01:00
Andy Wingo
dffe495d0d Exited threads retain less memory
* libguile/threads.c (on_thread_exit): Lessen excess retention.
2017-01-08 13:44:38 +01:00
Andy Wingo
12eb7b8256 Prevent some interrupts of wait-condition-variable
* libguile/threads.c (timed_wait): Disable interrupts while reacquiring
  mutex after wait-condition-variable.
2017-01-08 13:18:13 +01:00