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

9559 commits

Author SHA1 Message Date
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
Rob Browning
c45e1f57ec scm_i_utf8_string_hash: switch to u8_mbtouc
libguile/hash.c (scm_i_utf8_string_hash): Switch from u8_mbtouc_unsafe
to u8_mbtouc since the unsafe variant is now the same (see the info
pages).
2024-12-11 11:21:47 -06:00
Rob Browning
76afb429ee Eight byte align statically allocated stringbufs
Previously they were unaligned, unlike their parent strings, and so
could end up with the wrong pointer tag.  Observed on i686-linux-gnu,
where they ended up tagged as immediates (SCM_IMP()), causing failures
in TYP7 related checks.

* libguile/strings.h (SCM_IMMUTABLE_STRINGBUF): align resulting buffer
  via SCM_ALIGNED(8).
2024-11-29 12:24:57 -06:00
Natanael Copa
bb7154fb80
Fix build failure with GCC 14 and musl on 32-bit systems.
Fixes <https://bugs.gnu.org/73835>.

This fixes this error when compiling with GCC 14 and musl libc on 32-bit
Alpine Linux:

  filesys.c: In function 'scm_sendfile':
  filesys.c:1405:16: error: assignment to 'off_t *' {aka 'long long int *'} from incompatible pointer type 'scm_t_off *' {aka 'long int *'} [-Wincompatible-pointer-types]
   1405 |     offset_ptr = SCM_UNBNDP (offset) ? NULL : &c_offset;
	|                ^

* libguile/filesys.c (scm_sendfile): Change type of ‘c_offset’.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2024-10-26 19:45:12 +02:00
Tomas Volf
0175343deb
posix.c: Set errno when pipe2 is not available and flags provided.
If pipe2 is not available (e.g. on MacOS) and flags are set,
SCM_SYSERROR was correctly signaled, however errno was not set, so it
reported as:

    Undefined error: 0

That sucks both in tests (the test is not skipped) and in actual
usage (user has no idea what went wrong).

So set errno to ENOSYS as well.

* libguile/posix.c (scm_pipe2) [!HAVE_PIPE2] <c_flags>: Set errno to
ENOSYS.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2024-10-20 21:22:23 +02:00
Tomas Volf
0ceb0036c3
filesys.c: Fix readlink for ports on Darwin.
When passed a port, `readlink' relies on the Linux specific behavior of
empty c_path meaning "the fd itself".  That does not work on Darwin.
Since there is no branch that would yield both fd and c_path, fallback
to freadlink when __APPLE__ is defined.

* libguile/filesys.c (do_readlink): Call freadlink for !__APPLE__.
* configure.ac (AC_CHECK_FUNCS): Add freadlink.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2024-10-20 21:22:23 +02:00
Michael Käppler
08e26836f1
Fix setjmp/longjmp-related crashes on Windows
* libguile/Makefile.am: add new header file setjump-win.h
* libguile/continuations.h, libguile/dynstack.c, libguile/dynstack.h,
  libguile/intrinsics.h, libguile/vm.h:
  supply custom `setjmp` macro on Windows

Mingw implements `setjmp (env)` as a macro that expands to

 _setjmp (env, faddr)

where `faddr` is set to the current frame address.

This address is then stored as first element in the jump buffer `env`.
When `longjmp` is called, it tries to unwind the stack up
to the saved address by calling `RtlUnwindEx` from MSVCRT,
which will fail, if the stack frames are interwoven with
JIT-generated code, that violate the Windows x64 calling conventions.

Thus implement the macro ourselves as

_setjmp (env, NULL)

which will toggle a code path in `longjmp` that does no unwinding.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2024-10-20 12:14:21 +02:00
Matthew Wette
78e9e51065 Redirect diagnostice output messages (e.g., auto-compiling code) to a newly defined current-info-port, and add a command line argument -I' to set the current-info-port to a void-port. * libguile/ports.c: add cur_infoport_fluid, scm_current_info_port, scm_set_current_info_port; define default current-info-port to stderr * libguile/load.c(compiled_is_fresh,load_thunk_from_path, do_try_auto_compile,scm_sys_warn_auto_compilation_enabled, scm_primitive_load_path): direct output messages to current_info_port; was current_warning_port * libguile/init.c(scm_init_standard_ports): set default current_info_port * module/ice-9/ports.scm: define current-info-port and set-current-info-port * module/ice-9/command-line.scm(*usage*,compile-shell-switches): add argument -I' to silence diagnostics (or current-info-port to void-port) * doc/ref/guile-invoke.texi: add description for `-I' command argument 2024-10-12 13:16:25 +02:00
Matthew Wette
3d2fd7a262 Fix typo in naming function set-current-output-port * libguile/ports.c(scm_set_current_output_port): scheme name is set-current-output-port 2024-10-12 13:16:12 +02:00
Rob Browning
1c96e4ab6d Ensure tests have guile-procedures.txt
The tests depend on libguile/guile-procedures.txt, for example via
documented? in bit-operations.test.  Previously "make check -j..." in a
clean tree would fail because libguile/guile-procedures.txt is built by
./Makefile.am (rather than libguile/Makefile.am) so that it will have a
built module/ available, but when "." is not listed in SUBDIRS, it
builds last, and so the test-suite runs before guile-procedures.txt is
built.

To fix the problem add "." to SUBDIRS before the test-suite so that the
tests will be able depend on everything else, and move the existing
guile-procedures.txt target into libguile/ next to its
guile-procedures.texi dependency.  That gives a better overview and
simplifies the recipe a bit.  It also allows us to drop the explict
"all-local:" dependency, and to let the existing libguile/ code handle
the cleanup.

* Makefile.am (SUBDIRS): add . just before the test-suite.
(libguile/guile-procedures.txt): rely on libguile/Makefile.am.
(CLEANFILES): Drop libguile/procedures.txt.
* libguile/Makefile.am: (all-local): drop.
(libguile/guile-procedures.txt): move Makefile.am recipe here.
2024-09-27 19:51:00 -05:00
Andy Wingo
c2e7d834c2 Fix compilation with C23
* libguile/jit.c (is_unreachable): Rename from "unreachable", which is
apparently a new reserved word in C23.
2024-08-13 13:40:45 +02:00
Daniel Llorens
83d6d6afd9 Better error messages in array functions
* doc/ref/api-data.texi (Arrays as arrays of arrays): Clarify
  ambiguities, fix examples.
* libguile/arrays.c (make-shared-array): Make error messages specific to
  each error case, report relevant arguments.
  (array_from_pos): Return NULL on error instead of reporting error
  ourselves.
  (array_from_get_o): Handle the trivial case.
  (scm_array_slice, scm_array_cell_ref, scm_array_cell_set_x): Don't
  build error arguments before error happens. Let array_from_get_o
  handle the trivial case.
2024-08-12 14:24:58 +02:00
Rob Browning
c03115c39d basename: check suffix against basename, not full argument
* libguile/filesys: check suffix against basename, not full argument.

Closes: 69437
2024-08-03 14:39:26 -05:00
Rob Browning
9a57c237d2 basename: drop last_component null check
Prepare for fixes to the suffix pruning.  Since last_component doesn't
document a possible null result in lib/basename-lgpl.h, and the current
code also doesn't appear capable of producing one, drop the check.

libguile/filesys.c (basename): drop check for last_component null result.
2024-08-03 14:29:47 -05:00
Rob Browning
6338459159 Drop libguile srfi-1
...now that all of the C code has been migrated to Scheme.

* libguile/Makefile.am (libguile_@GUILE_EFFECTIVE_VERSION@_la_SOURCES):
remove srfi-1.c.
(DOC_X_FILES): Remove srfi-1.x.
(DOT_DOC_FILES): Remove srfi-1.doc.
(modinclude_HEADERS): Remove srfi-1.h.
* libguile/init.c (scm_i_init_guile): Don't call scm_register_srfi_1.
* libguile/srfi-1.c: Remove.
* libguile/srfi-1.h: Remove.
* module/srfi/srfi-1.scm: Don't load srfi-1 from libguile.
2024-07-30 19:39:32 -05:00
Rob Browning
51b7021de1 srfi-1 delete-duplicates: move from C to Scheme
* libguile/srfi-1.c (scm_srfi1_delete-duplicates): delete.
* libguile/srfi-1.h (scm_srfi1_delete-duplicates): delete.
* module/srfi/srfi-1.scm: add delete-duplicates.
2024-07-30 19:28:37 -05:00
Rob Browning
a94b4406b7 srfi-1 delete-duplicates!: move from C to Scheme
* libguile/srfi-1.c (scm_srfi1_delete-duplicates_x): delete.
* libguile/srfi-1.h (scm_srfi1_delete-duplicates_x): delete.
* module/srfi/srfi-1.scm: add delete-duplicates!.
2024-07-30 19:28:37 -05:00
Rob Browning
945c97b14d srfi-1 lset-difference!: move from C to Scheme
* libguile/srfi-1.c (scm_srfi1_lset-difference_x): delete.
* libguile/srfi-1.h (scm_srfi1_lset-difference_x): delete.
* module/srfi/srfi-1.scm: add lset-difference!.
* test-suite/tests/srfi-1.test: extend lset-difference! tests to cover
lset-difference.
2024-07-30 19:28:37 -05:00
Rob Browning
3eb6afe738 srfi-1 partition!: move from C to Scheme
* libguile/srfi-1.c (scm_srfi1_partition_x): delete.
* libguile/srfi-1.h (scm_srfi1_partition_x): delete.
* module/srfi/srfi-1.scm: add partition!.
2024-07-30 19:28:37 -05:00
Rob Browning
925faf1f01 srfi-1 partition: move from C to Scheme
* libguile/srfi-1.c (scm_srfi1_partition): delete.
* libguile/srfi-1.h (scm_srfi1_partition): delete.
* module/srfi/srfi-1.scm: add partition.
2024-07-30 19:28:37 -05:00
Rob Browning
58246aee24 srfi-1 count: move from C to Scheme
* libguile/srfi-1.c (scm_srfi1_count): delete.
* libguile/srfi-1.h (scm_srfi1_count): delete.
* module/srfi/srfi-1.scm: add count.
2024-07-30 19:28:37 -05:00
Rob Browning
372a52e6aa srfi-1 length+: move from C to Scheme
* libguile/srfi-1.c (scm_srfi1_length_plus): delete.
* libguile/srfi-1.h (scm_srfi1_length_plus): delete.
* module/srfi/srfi-1.scm: add length+.
2024-07-30 19:28:37 -05:00
Rob Browning
3cb6309f62 srfi-1 append-reverse!: move from C to Scheme
* libguile/srfi-1.c (scm_srfi1_append_reverse_x): delete.
* libguile/srfi-1.h (scm_srfi1_append_reverse_x): delete.
* module/srfi/srfi-1.scm: add append-reverse!.
2024-07-30 19:28:37 -05:00
Rob Browning
17281519df srfi-1 append-reverse: move from C to Scheme
* libguile/srfi-1.c (scm_srfi1_append_reverse): delete.
* libguile/srfi-1.h (scm_srfi1_append_reverse): delete.
* module/srfi/srfi-1.scm: add append-reverse.
2024-07-30 19:11:34 -05:00
Rob Browning
c62d2962d4 srfi-1 concatenate concatenate!: move from C to Scheme
* libguile/srfi-1.c (scm_srfi1_concatenate, scm_srfi1_concatenate_x): delete.
* libguile/srfi-1.h (scm_srfi1_concatenate, scm_srfi1_concatenate_x): delete.
* module/srfi/srfi-1.scm: add concatenate and concatenate!.
2024-07-30 18:54:45 -05:00
Rob Browning
a816b2484b srfi-1 delete delete!: move from C to Scheme
* libguile/srfi-1.c (scm_srfi1_delete, scm_srfi1_delete_x): delete.
* libguile/srfi-1.h (scm_srfi1_delete, scm_srfi1_delete_x): delete.
* module/srfi/srfi-1.scm: add delete and delete!.
2024-07-30 18:54:45 -05:00
Rob Browning
c5f26d4c27 srfi-1 remove!: move from C to Scheme
* libguile/srfi-1.c (scm_srfi1_remove_x): delete.
* libguile/srfi-1.h (scm_srfi1_remove_x): delete.
* module/srfi/srfi-1.scm: add remove!.
2024-07-30 18:54:45 -05:00
Rob Browning
03d4a3b5df srfi-1 remove: move from C to Scheme
The Scheme implementation is an adapted version of the approach used by
delete-duplicates, which allows sharing any common tail.

* libguile/srfi-1.c (scm_srfi1_remove): delete.
* libguile/srfi-1.h (scm_srfi1_remove): delete.
* module/srfi/srfi-1.scm: add remove.
2024-07-30 18:54:45 -05:00
Rob Browning
aa44035ee8 srfi-1 list-copy: move from C to Scheme
* libguile/srfi-1.c (scm_srfi1_list_copy): delete.
* libguile/srfi-1.h (scm_srfi1_list_copy): delete.
* module/srfi/srfi-1.scm: add list-copy.
* test-suite/tests/srfi-1.test: ensure copied spine is independent.
2024-07-30 18:54:45 -05:00
Ludovic Courtès
c117f8edc4
build: Fix in-tree cross-compilation build.
Commit 57a889b728 fixed out-of-tree
cross-compilation builds but broke in-tree cross-compilation builds.
With this change, we should have both.

* libguile/Makefile.am (gen-scmconfig.$(OBJEXT)): Use ‘-iquote’ instead
of ‘-I’.
2024-07-17 00:00:00 +02:00
Andy Wingo
d7ed457620 Ensure the signal-delivery thread is completely stopped before fork
* libguile/scmsigs.c: Use raw pthread_create / pthread_join instead of
Guile's scm_spawn_thread, to ensure that the thread is entirely stopped
before a fork.
* libguile/scmsigs.h (scm_i_is_signal_delivery_thread): New internal
procedure, replacing a manual check against scm_i_signal_delivery_thread.
* libguile/threads.c: Use the new procedure.

Based on a patch by Rob Browning.  Thanks!
2024-06-21 11:11:46 +02:00
Rob Browning
0a8a1eb595 Document wait-condition-variable's spurious returns 2024-06-20 15:57:26 +02:00