1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-09 07:00:23 +02:00
Commit graph

9590 commits

Author SHA1 Message Date
Andy Wingo
a13c30eeba Remove GUILE_DEBUG_MALLOC configuration
* configure.ac: Remove --enable-debug-malloc.
* doc/ref/api-memory.texi (Memory Blocks): Remove malloc-stats mention.
* libguile/debug-malloc.c:
* libguile/debug-malloc.h: Remove.
* libguile/Makefile.am (EXTRA_libguile_@GUILE_EFFECTIVE_VERSION@_la_SOURCES):
(modinclude_HEADERS): Remove debug-malloc mentions.
* libguile/gc-malloc.c (scm_gc_register_collectable_memory):
(scm_calloc):
* libguile/init.c (scm_i_init_guile): Remove debug-malloc things.
2025-04-30 11:21:52 +02:00
Andy Wingo
f3649d7d1b Move scm_c_shrink_bytevector off realloc
* libguile/bytevectors.c (scm_c_shrink_bytevector): Return buf as is if
length is more than half of previous.  Otherwise make a fresh buffer and
copy.
2025-04-30 11:01:14 +02:00
Andy Wingo
337eaec77d Refactor srfi-14.c to use malloc instead of realloc
* libguile/srfi-14.c (char_ranges_insert, char_ranges_delete): New
helpers.
(scm_i_charset_set, scm_i_charset_set_range, scm_i_charset_unset): Use
the new helpers.
2025-04-30 10:42:07 +02:00
Andy Wingo
53dda2ecec Remove accidental chars in srfi-14.h
* libguile/srfi-14.h: Remove typo
2025-04-30 10:42:07 +02:00
Andy Wingo
2bfc1779c5 Move r6rs-ports off scm_gc_realloc
* libguile/r6rs-ports.c (grow_byte_buffer, shrink_byte_buffer): New
helpers.
* libguile/r6rs-ports.c (bytevector_output_port_buffer_grow):
(bytevector_output_port_procedure): Use new helpers.
2025-04-30 10:39:20 +02:00
Andy Wingo
4ccd57aca8 Use scm_inline_gc_malloc for scm_gc_malloc
* libguile/gc-malloc.c (do_realloc, do_calloc): Remove.
(scm_gc_malloc): Dispatch to scm_inline_gc_malloc.
(scm_gc_calloc): Dispatch to scm_gc_malloc.
(scm_gc_realloc): Mark for removal.  The issue is that the realloc'd
object should have the same kind.  We could add Whippet API but it would
be nice to not do that.
2025-04-23 17:39:40 +02:00
Andy Wingo
1b6055dbbd Adapt to Whippet inline allocation changes
* libguile/jit.c (compile_allocate_words_immediate):
(compile_allocate_words_immediate_slow):
(compile_allocate_pointerless_words_immediate):
(compile_allocate_pointerless_words_immediate_slow): Update for new API.
2025-04-23 17:35:27 +02:00
Andy Wingo
975860e5e2 Merge remote-tracking branch 'whippet/main' into wip-whippet 2025-04-23 17:30:27 +02:00
Andy Wingo
e0c5adf52c Move scm_gc_malloc_pointerless to use Whippet API
* libguile/gc-malloc.c: Trim set of includes.
(do_gc_malloc_atomic): Remove.
(scm_gc_malloc_pointerless): Call scm_inline_gc_malloc_pointerless.
(scm_gc_strndup): Call scm_gc_malloc_pointerless.
2025-04-23 15:33:52 +02:00
Andy Wingo
bb4e9a289c Remove scm_gc_free
* libguile/gc.h:
* libguile/gc-malloc.c (do_gc_free, scm_gc_free): Remove.
2025-04-23 15:27:15 +02:00
Andy Wingo
af567f0575 Vtables avoid zero-sized bitmap allocation
* libguile/struct.c (set_vtable_access_fields): If there are no fields,
we don't need to allocate an unboxed fields array.
2025-04-23 15:23:42 +02:00
Andy Wingo
befac2cf85 Remove some uses of scm_gc_free
* libguile/i18n.c (scm_make_locale):
* libguile/random.c (scm_c_random_bignum):
* libguile/regex-posix.c (regex_free):
(scm_make_regexp):
* libguile/srfi-14.c (scm_i_charset_unset, charsets_intersection)
(charsets_complement): Remove calls to scm_gc_free.
2025-04-23 15:15:57 +02:00
Andy Wingo
23d204b5a0 Hook up gc_heap_set_allocation_failure_handler
* libguile/gc.h:
* libguile/gc.c (scm_gc_after_nonlocal_exit): Give it a scm_thread
argument, and cause GC with whippet API.
(scm_init_gc): Set alloc failure handler using Whippet API instead of
BDW.
(scm_oom_fn): Add heap argumnet.

* libguile/eval.c (eval):
* libguile/exceptions.c (scm_c_with_exception_handler):
* libguile/vm.c (scm_call_n): Adapt.
2025-04-23 14:04:23 +02:00
Andy Wingo
25db208603 Merge remote-tracking branch 'whippet/main' into wip-whippet 2025-04-23 13:48:18 +02:00
Andy Wingo
0532602cd3 Switch to use Whippet allocation fast paths
* libguile/Makefile.am (noinst_HEADERS, modinclude_HEADERS): Move
gc-inline.h to be a private header.
* libguile/gc-inline.h (scm_inline_gc_malloc_pointerless):
(scm_inline_gc_malloc): Use gc_allocate.
* libguile/intrinsics.c (allocate_words_with_freelist):
(allocate_pointerless_words_with_freelist): Remove these intrinsics.
Renumbers the intrinsics.
(scm_bootstrap_intrinsics):
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): Adapt to intrinsics
change.
* libguile/jit.c (emit_update_alloc_table):
(emit_allocate_bytes_fast_freelist):
(emit_allocate_words_slow): New helpers.
(compile_allocate_words):
(compile_allocate_words_immediate):
(compile_allocate_words_immediate_slow):
(compile_allocate_pointerless_words):
(compile_allocate_pointerless_words_immediate):
(compile_allocate_pointerless_words_immediate_slow): Use new helpers.
* libguile/threads.c (scm_trace_thread_mutator_roots):
(on_thread_exit):
* libguile/threads.h: Remove Guile-managed thread-local freelists.
2025-04-22 13:44:44 +02:00
Andy Wingo
7696344634 Bump version to 3.9.x
Headed towards a 4.0.  The binary format will change slightly but
incompatibly (e.g. renumbering of intrinsics).  Having a new GC is
enough of a change to warrant a minor version bump, and it's been 5
years so why not go major.

* GUILE-VERSION (GUILE_EFFECTIVE_VERSION): Bump to 4.0.
(GUILE_MICRO_VERSION, GUILE_MINOR_VERSION): Bump to 3.9.0.
(LIBGUILE_INTERFACE_CURRENT, LIBGUILE_INTERFACE_AGE): Reset.

* meta/guile-4.0.pc.in:
* meta/guile-4.0-uninstalled.pc.in: Rename from guile-3.0.
* .gitignore: Ignore pkg-config files with 4.0 effective version.

* README: Update slightly.

* doc/ref/api-evaluation.texi (Load Paths):
* doc/ref/api-options.texi (Build Config):
* doc/ref/guile-invoke.texi (Environment Variables):
* doc/ref/history.texi (A Timeline of Selected Guile Releases):
* doc/ref/libguile-parallel.texi (Parallel Installations):
* doc/ref/srfi-modules.texi (SRFI-0): Update references to stable
version in paths.

* module/system/vm/assembler.scm (*bytecode-minor-version*):
* libguile/loader.h (SCM_OBJCODE_MAJOR_VERSION):
(SCM_OBJCODE_MINIMUM_MINOR_VERSION):
(SCM_OBJCODE_MINOR_VERSION): Use the same major objcode version for now
but bump the minor to 99.

* meta/guile.m4 (GUILE_PKG, GUILE_PROGS): Check for Guile 4.0.
* module/ice-9/boot-9.scm (%cond-expand-features): Add new cond-expand
features.
2025-04-22 13:23:00 +02:00
Andy Wingo
27f0490801 Use Whippet API to boot threads
* libguile/scm.h (scm_tc7_thread): Give threads their own tc7.
* libguile/threads.h (struct scm_thread): Add a tag, so that struct
thread can be a SCM directly.  Add a struct gc_mutator* member.
(scm_thread_handle): New inline function.
(SCM_I_IS_THREAD, SCM_I_THREAD_DATA, SCM_VALIDATE_THREAD): Update to use
tc7 instead of SMOB tags.

* libguile/continuations.c (scm_i_with_continuation_barrier)
* libguile/finalizers.c (queue_finalizer_async)
* libguile/jit.c (compile_current_thread)
* libguile/threads.c (block_self, guilify_self_2)
(lock_mutex, unlock_mutex, timed_wait scm_current_thread)
(scm_all_threads)
* libguile/vm-engine.c (current-thread): Use scm_thread_handle instead
of thread->handle.

* libguile/evalext.c (scm_self_evaluating_p):
* libguile/goops.c (class_thread, scm_class_of, scm_sys_goops_early_init)
* libguile/print.c (iprin1)
* module/language/cps/compile-bytecode.scm (compile-function)
* module/oop/goops.scm (<thread>)
* module/system/base/types.scm (cell->object)
* module/system/base/types/internal.scm (heap-tags)
* module/system/vm/assembler.scm: (emit-thread?): Adapt to
scm_tc7_thread.

* libguile/gc-internal.h: Move init functions that take "struct
gc_stack_addr" here, so that internal Whippet uses don't cause Whippet
to be added to public headers.
* libguile/gc.c (scm_storage_prehistory): Take struct gc_stack_addr as
arg, and pass to gc_init.  Return a mutator pointer.
* libguile/init.c (scm_i_init_guile): Pass mutator and stack base to GC
and thread init routines.
* libguile/threads.c (scm_trace_dynstack, scm_trace_thread)
(scm_trace_thread_mutator_roots): New infra for marking threads in terms
of Whippet API.
* libguile/threads.c (guilify_self_1): Since we don't use a separate GC
kind for threads any more, and thread marking is keyed off
gc_mutator_set_roots, we can avoid some of the gnarly synchronization.
(on_thread_exit): Arrange to gc_finish_for_thread.
(scm_i_init_thread_for_guile): Use gc_init_for_thread.
(init_main_thread, with_guile, scm_i_with_guile): Use Whippet API.
(scm_threads_prehistory): Take main-thread mutator and the stack base as
arguments.
* libguile/vm.c (scm_trace_vm): Rework in terms of Whippet API.
* libguile/whippet-embedder.h (gc_trace_mutator_roots): Arrange to trace
the current mutator's SCM thread object.
* libguile/trace.h: New file, to declare implementations of trace
routines.
* libguile/Makefile.am (noinst_HEADERS): Add trace.h.
2025-04-22 10:36:30 +02:00
Andy Wingo
55e9d0672b Merge remote-tracking branch 'whippet/main' into wip-whippet 2025-04-22 10:01:34 +02:00
Andy Wingo
68d495f081 Adapt to Whippet changes
* libguile/gc.c (scm_storage_prehistory): Adapt to new gc_init
prototype.
2025-04-18 15:15:06 +02:00
Andy Wingo
b6236fdcdc Merge remote-tracking branch 'whippet/main' into wip-whippet 2025-04-18 15:11:40 +02:00
Andy Wingo
9b7f7f7554 Switch statistics collection, GC hooks to use Whippet API
* libguile/gc.c: Define an event listener that collects basic
statistics, runs C hooks, and arranges to run the Scheme hook if it is
nonempty.
(scm_gc_stats): Fetch statistics from the gathered event data.
(scm_gc_dump): Use scm_basic_stats_print.
(scm_storage_prehistory): Fix indentation.
(scm_init_gc_protect_object): Remove dead code.
(queue_after_gc_hook): Not really needed, as we have an after-GC C event
to run the C hooks.  Scheme hook activation is inlined into the event
listener.
(start_gc_timer, accumulate_gc_timer): No need any more.
(scm_init_gc): Simplify hook registration.
2025-04-17 14:37:39 +02:00
Andy Wingo
7f23dea7de Merge remote-tracking branch 'whippet/main' into wip-whippet 2025-04-17 12:29:51 +02:00
Andy Wingo
57e8686cea Initialize BDW-GC using Whippet API
* libguile/gc.c (scm_storage_prehistory): Use Whippet API instead of
BDW-GC API.
2025-04-17 09:32:53 +02:00
Andy Wingo
2d5d9f6ba9 Update for changes to Whippet build
* libguile/Makefile.am (WHIPPET_EMBEDDER_H): Define this variable
instead of using -include; otherwise we don't get the chance to set
_LARGEFILE64_SOURCE before including Whippet files.
(AM_CPPFLAGS): Simplify.
(libguile_@GUILE_EFFECTIVE_VERSION@_la_DEPENDENCIES): Explicitly add
libwhippet.la as a dependency.
(noinst_HEADERS): Add gc-internal.h
* libguile/gc-internal.h: New file.
* libguile/gc.c: Include gc-internal.h.
2025-04-16 13:48:36 +02:00
Andy Wingo
fd7b5d2d0c Merge remote-tracking branch 'whippet/main' into wip-whippet 2025-04-16 13:42:18 +02:00
Andy Wingo
7126bd19b0 Link Whippet into Guile
* libguile/Makefile.am (libguile_@GUILE_EFFECTIVE_VERSION@_la_LIBADD):
Add libwhippet.la.
2025-04-16 10:04:33 +02:00
Andy Wingo
a80e401540 Add Whippet to libguile/Makefile.am
* configure.ac: Add subdir-objects Makefile.am option, to prevent
accidental collision between object file names.
* libguile/Makefile.am: Include whippet/embed.am, and add the
appropriate hooks to the Makefile.
* libguile/whippet-embedder.h: New file.
2025-04-16 10:00:51 +02:00
Andy Wingo
a463e0d376 Merge remote-tracking branch 'whippet/main' into wip-whippet 2025-04-16 09:25:11 +02:00
Andy Wingo
f4d118ebaa Reserve a tc3 cell type for forwarded objects
* libguile/scm.h (scm_tc3_forwarded): Reserve.
2025-04-16 09:24:16 +02:00
Andy Wingo
556a3ae671 Merge remote-tracking branch 'whippet/main' into wip-whippet 2025-04-15 11:05:53 +02:00
Andy Wingo
db181e67ff Merged Whippet into libguile/whippet 2025-04-11 14:10:41 +02:00
Michael Gran
af96820e07 Windows 11: for fport input from the console, ignore terminal returns
There is an apparent bug in Windows 11 (not Windows 10) where,
when reading from an fd backed by the Console, a single
return character will always be available.

* libguile/posix-w32.c (console_has_return_keyevent_w32): new procedure
* libguile/posix-w32.h: declare console_has_return_keyevent_w32
* libguile/fports.c [__MINGW32__](fport_input_waiting): ignore return keyevent
2025-03-23 10:26:40 -07:00
Michael Gran
adbf2156ab Remove posix-w32 subsitutes that require access to process handles
Now that Guile uses the posix_spawn gnulib module, several of Guile's
custom w32 functions substitutes no longer work. Some functions
relied on populating and maintaining an internal PID-to-Handle database,
which is no longer possible.

kill, getpriority, setpriority, getaffinity and setaffinity
are removed. waitpid is simplified and does not handle ENOHANG.

* NEWS: updated
* libguile/posix-w32.c (struct proc_record, find_proc, proc_handle): removed
  (record_proc, delete_proc, prepare_child_handle, compenv): removed
  (prepare_envblk, lookup_cmd, prepare_cmdline, start_child): removed
  (kill, getpriority, setpriority, sched_getaffinity): removed
  (sched_setaffinity): removed
  (waitpid): modified to just use _cwait. ENOHANG emlation removed.
* libguile/posix-w32.h (CPU_ZERO, CPU_ISSET, CPU_SET, CPU_SETSIZE): removed
  (cpu_set_t, PRIO_PROCESS, PRIO_PGRP, PRIO_USER): removed
  (HAVE_START_CHILD, HAVE_KILL, HAVE_GETPRIORITY): removed
  (HAVE_SETPRIORITY, HAVE_SCHED_GETAFFINITY, HAVE_SCHED_SETAFFINITY): removed
  declarations for waitpid, start_child, kill, getpriority: removed
  declarations for setpriority, sched_getaffinity, sched_set_affinity: Removed
2025-03-22 21:57:59 -07:00
Michael Gran
2e51d3fa26 In piped_process, replace dprintf with more portable functions
dprint is missing on many non-glic platforms

* libguile/posix.c (piped_process): replace dprintf with sprintf+write
2025-03-22 21:33:33 -07:00
Michael Gran
9c86c5936e Allow piped-process and system* to exist when fork is undefined
piped-process only uses fork to match legacy behavior, but on systems
that never had fork, there is no need to match that behavior.
piped-process and system* can be provided without fork.

* libguile/posix.c (piped_process): allow function definition without HAVE_FORK,
    but stub out internal dummy process with HAVE_FORK
  (restore_sigaction, scm_dynwind_sigaction, scm_system_star): don't
    require HAVE_FORK
  (scm_init_popen): don't require HAVE_FORK
  (scm_init_posix): don't require HAVE_FORK to add posix feature or
    register popen extension
2025-03-22 21:32:45 -07:00
Michael Gran
87402c849e MinGW32: cast arguments to execvp
MinGW32's MSVCRT library requires strict casting for exec family functions

* libguile/posix.c (scm_execl, scm_execlp, scm_execle) [__MINGW32__]: cast
  arguments
2025-03-22 21:02:42 -07:00
Michael Gran
0f2125e66f Add missing #include in syscalls.h
SCM_SYSCALL uses scm_async_tick.

* libguile/syscalls.h: include async.h
2025-03-22 14:17:41 -07:00
Michael Gran
0e20c0c8c6 Add replacement for missing getpagesize() on MINGW
* libguile/posix-w32.c (getpagesize_w32): new procedure
* libguile/posix-w32.h: declaration of getpagesize_w32
* libguile/loader.c [__MINGW32__](scm_bootstrap_loader): use new procedure
* libguile/vm.c [__MINGW32__](scm_i_vm_prepare_stack): use new procedure
2025-03-22 14:17:30 -07:00
Ludovic Courtès
462d3c85ed
Provide ‘scm_i_is_finalizer_thread’ when building ‘--without-threads’.
Fixes a regression in ‘--without-threads’ builds introduced in
b8031fc965.

* libguile/finalizers.c (scm_i_is_finalizer_thread) [!SCM_USE_PTHREAD_THREADS]:
New function.
2025-03-21 18:10:07 +01:00
Rob Browning
c6e0826667 libguile/Makefile.am: move date -d arg before format string
This fixes a problem on at least NetBSD.

* libguile/Makefile.am (libpath.h): move date -d argument before format
string.

Thanks to Thomas Klausner for reporting the problem and proposing the
fix.

Closes: 26121
2025-03-20 13:22:14 -05:00
Tomas Volf
4f39181b2f filesys.c: Use scm_sendfile to copy files
Use scm_sendfile instead of read-write loop.  This moves the work into
the kernel, improving performance.  This implements Ludovic's suggestion
from https://debbugs.gnu.org/68504

* libguile/filesys.c (scm_copy_file2): Use scm_sendfile.

[rlb@defaultvalue.org: add NEWS]
2025-03-19 21:25:40 -05:00
Rob Browning
11b027d7e2 piped_process: silence spurious -Wmaybe-uninitialized warnings
libguile/posix.c: initialize pipes to silence spurious warnings.
2025-03-18 14:34:49 -05:00
Michael Gran
4af6331a65 Fixes potential buffer overflow in getsockopt for timevals
struct timeval is a possible return value of getsockopt (e.g. SO_RCVTIMEO
and SO_SNDTIMEO), but it is not included in the scm_t_getsockopt_result
union, which may then be too small (and is on Debian amd64).
* libguile/socket.c: add struct timeval to scm_t_getsockopt union

[rlb@defaultvalue.org: adjust commit message; add NEWS]

Closes: 76907
2025-03-18 12:24:31 -05:00
Olivier Dion
7b7340b2d9
Warn about mutation of ‘environ’ when multi-threaded.
This is an amendment to 84bf840322.

The warning was only emitted for calling `environ', even if only reading
and no mutation occurred.

However, it is correct to read the environment in a multi-threaded
process.  It is however unsafe to mutate it.

The same logic also applies to `putenv'.

* libguile/posix.c
  (maybe_warn_about_environ_mutation): New private procedure ...
  (scm_environ): ... called here when mutating the environment ...
  (scm_putenv): ... and here.
* NEWS: Update.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2025-02-28 22:12:04 +01:00
Ludovic Courtès
b8031fc965
Exclude the finalizer thread from the ‘all-threads’ result.
Fixes <https://bugs.gnu.org/76343>.

Fixes a bug whereby “echo '(environ)' | guile” would wrongfully trigger
the multiple-thread warning.

* libguile/finalizers.c (finalizer_thread): New variable.
(finalization_thread_proc): Set it.
(scm_i_is_finalizer_thread): New function.
(run_finalization_thread): Clear FINALIZER_THREAD.
* libguile/finalizers.h (scm_i_is_finalizer_thread): New declaration.
* libguile/threads.c (scm_all_threads): Use it.
* NEWS: Update.

Reported-by: Simon Josefsson <simon@josefsson.org>
2025-02-28 22:12:03 +01:00
Hannes Müller
ff4d79074c
libguile/scm.h: Allow compilation with ‘-Werror=undef’.
* libguile/scm.h: BUILDING_LIBGUILE is not always defined. This is
signaled by -Werror=undef in code using libguile. This patch fixes
commit dc3a3a84f9
* NEWS: Update.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2025-02-28 22:12:03 +01:00
Andy Wingo
5d3f561d7d Merge remote-tracking branch 'lightening/main' 2025-01-29 16:52:29 +01:00
Rob Browning
48b1c4eff4 fport_print: handle ttyname ENODEV
In some situations, ttyname may return ENODEV even though isatty is
true.  From ttyname(3):

  A process that keeps a file descriptor that refers to a pts(4) device
  open when switching to another mount namespace that uses a different
  /dev/ptmx instance may still accidentally find that a device path of
  the same name for that file descriptor exists.  However, this device
  path refers to a different device and thus can't be used to access the
  device that the file descriptor refers to.  Calling ttyname() or
  ttyname_r() on the file descriptor in the new mount namespace will
  cause these functions to return NULL and set errno to ENODEV.

Observed in a Debian riscv64 porterbox schroot.

When ttyname fails with ENODEV, just include the file descriptor integer
value instead.  Call ttyname() directly to avoid having to catch the
ENODEV.

* libguile/fports.c (fport_print): fall back to the integer fd when
ttyname() fails with ENODEV.
2025-01-23 12:49:33 -06:00
Rob Browning
63756efbc5 Don't hold lock during scm_async_tick in readdir and ttyname
Only hold scm_i_misc_mutex while making the C calls.  This also avoids
the need for a dynamic-wind.  Add SCM_I_LOCKED_SYSCALL (similar to
SCM_SYSCALL) to handle the locking and EINTR loop.

libguile/filesys.c (scm_readdir): rely on SCM_I_LOCKED_SYSCALL to limit
locking.
libguile/filesys.c (scm_ttyname): rely on SCM_I_LOCKED_SYSCALL to limit
locking.
libguile/syscalls.h: add SCM_I_LOCKED_SYSCALL.
2025-01-22 19:24:07 -06:00
Rob Browning
35f13806af scm_i_utf8_string_hash: don't overrun when len is zero
When the length is zero, the previous code would include the byte after
the end of the string in the hash.  Fix that (the wide and narrow
hashers also guard against it via "case 0"), and don't bother mutating
length for the trailing bytes.

Since we already compute the char length, use that to detect all ASCII
strings and follow the same narrow string path that we do for latin-1.

libguile/hash.c (scm_i_utf8_string_hash): avoid overrun when len == 0.
2024-12-11 11:46:40 -06:00