Window's tmpnam expects that you will prepend it with the temporary
directory. Using _tempnam gives a path that is already prepended
with a temporary directory.
* NEWS: updated
* libguile/posix.c [_WIN32](scm_tmpnam): use _tempnam to create
a temporary filename
* test-suite/tests/posix.test ("tmpnam"): new test
For systems that do not have a posix shell.
* configure.ac (GUILE_TOOLS_EXE): new conditional
* libguile/Makefile.am (guile-tools)[GUILE_TOOLS_EXE]: new binary target
* libguile/guile-tools.c: new file
* meta/Makefile.am (guile.scm): new data
[!GUILE_TOOLS_EXE](install-exec-hook): don't alias guile-tools to guild
(CLEANFILES): add guild.exe
Adds CRLF as a line ending. %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 CRLF line delimiter
* module/ice-9/suspendable-ports.scm (%read-line): modify to handle CRLF
line delimiter
(read-line): use modified %read-line
* test-suite/tests/rdelim.test ("two lines, split, CRLF"): new test
("two long lines, split, CRLF"): new test
* doc/ref/api-io.texi: update read-line documentation
This variable will help indicate if, on Win32, the C library is
closer to C99 capable.
* libguile/posix.c (scm_init_posix): new define %UCRT
* test-suite/tests/i18n.test (old-ms?): use new define allow UTF-8
tests on MINGW
Guile has an enum scm_inline_gc_kind used to replace GC constants
that were private. Those defines were made public in 2015, so it
is should be safe to use them now.
Replace SCM_INLINE_GC_KIND_POINTERLESS with GC_I_PTRFREE.
Replace SCM_INLINE_GC_KIND_NORMAL with GC_I_NORMAL.
* libguile/gc-inline.h (scm_inline_gc_kind): remove type
(scm_inline_gc_alloc): kind argument is now int
(scm_inline_gc_malloc_pointerless): use GC_I_PTRFREE
(scm_inline_gc_malloc): use GC_I_NORMAL
* libguile/intrinsics.c (allocate_words_with_freelist): use GC_I_NORMAL
(allocate_pointerless_words): use GC_I_PTRFREE
For 64-bit Windows, there was an existing special setjmp handling
to avoid jumping into Guile frames. Expand this handling to 32-bit
Windows as well.
*
* libguile/posix-w32.c (mkdtemp): new win32 replacement procedure
* libguile/posix-w32.h: add declaration for mkdtemp
(HAVE_MKDTEMP): new define
* libguile/filesys.c: include posix-w32.h
FFS is missing on MINGW.
* libguile/lightening/lightening/x86-cpu.c
[__GNUC__ && _WIN32](USE_BUILTIN_FFS): new macro
(__ffs): wrapper function
(ffsw): use __ffs;
For MinGW, there is a native signal function in UCRT. It handles
a limited set of signals.
* libguile/scmsigs.c (scm_sigaction_for_thread)[__MINGW32__]: removed
(scm_sigaction_for_thread)[!__MINGW32__]: use for MinGW as well.
For signals outside UCRT's native signal set, always return SIG_IGN.
After installing a signal handler, these are handled
* C-c
* kill -SIGINT <guile.exe-pid> (the wine process) works
these result in a direct terminate (or kill even?)
- kill <guile.exe-pid>
- wine cmd /c guile -c '(kill <guile-exe.pid> SIGINT)'
- wine cmd /c guile -c '(kill <guile-exe.pid> SIGTERM)'
* libguile/scmsigs.c (mingw_take_signal)[__MINGW32__]: New function.
install_mingw_take_signal)[__MINGW32__]: New function.
(scm_init_scmsigs)[__MINGW32__]: Use it.
On x86-64-MinGW the size of long is 4. As long is used for
SCM_FIXNUM_BIT, that would mean incompatible .go files, and waste of
cell space. So we would like to use long long, but the GMP interface
uses long.
To get around this, the x86-64-MinGW port now requires the use of
mini-GMP. Mini-GMP has been changed to use intptr_t and uintptr_t.
Likewise, "integers.{h,c}" and "numbers.{h,c}" now use intptr_t instead
of scm_t_inum or long, and uintptr_t instead of unsigned long.
* configure.ac: When x86_64-w64-mingw32, require mini-GMP.
* libguile/mini-gmp.h: Use intptr_t instead of long, uintptr_t instead
of unsigned long throughout.
* libguile/mini-gmp.c: Likewise.
* libguile/scm.h (SCM_INTPTR_T_BIT): New define.
* libguile/numbers.h (SCM_FIXNUM_BIT): Use it.
* libguile/numbers.c (L1, UL1): New macros. Use them thoughout instead
of 1L, 1UL.
(verify): Use SCM_INTPTR_T_BIT.
(verify): Use SCM_INTPTR_T_MAX and SCM_INTPTR_T_MIN.
(scm_from_inum): Remove macro.
Use intptr_t and uintptr_t instead of scm_t_inum or long, and unsigned
long.
* libguile/numbers.h (scm_from_intptr, scm_from_uintptr, scm_to_intptr,
scm_to_uintptr): New defines.
* libguile/integers.h: Use intptr_t and uintptr_t instead of scm_t_inum
and unsigned long.
* libguile/integers.c (L1) : New macro. Use it thoughout instead of 1L.
Use intptr_t and uintptr_t instead of long and unsigned long.
(long_magnitude): Rename to...
(intptr_t_magnitude): ...this. Use intptr_t, uintptr_t.
(negative_long): Rename to...
(negative_t_intptr): ...this. Use uintptr_t, INTPTR_MIN.
(inum_magnitude): Use intptr_t.
(ulong_to_bignum): Rename to...
(uintptr_t_to_bignum): ...this. Use uintptr_t.
(long_to_bignum): Rename to...
(intptr_t_to_bignum): ...this. Use intptr_t.
(long_to_scm): Rename to...
(intptr_t_to_scm): ...this. Use intptr_to_bignum.
(ulong_to_scm): Rename to...
(uintptr_t_to_scm): ...this. Use uintptr_to_bignum.
(long_sign): Rename to..
(intptr_t_sign): ...this. Use SCM_SIZEOF_INTPTR_T.
(bignum_cmp_long): Rename to...
(bignum_cmp_intptr_t): ...this. Use uintptr_t.
* libguile/array-map.c (array_compare): Use uintptr_t instead of
unsigned long and intptr_t instead of long.
* libguile/arrays.c (make-shared-array): Use ssize_t instead of long.
* libguile/bytevectors.c (is_signed_int32, is_unsigned_int32)
[MINGW32 && __x86_64__]: Use ULL.
(twos_complement): Use uintptr_t instead of unsigned long.
* libguile/hash.c (JENKINS_LOOKUP3_HASHWORD2): Likewise.
(narrow_string_hash, wide_string_hash, scm_i_string_hash,
scm_i_locale_string_hash, scm_i_latin1_string_hash,
scm_i_utf8_string_hash, scm_i_struct_hash, scm_raw_ihashq,
scm_raw_ihash): Use and return uintptr_t instead of unsigned long.
(scm_hashv, scm_hash): Use SCM_UINTPTR_T_MAX.
* libguile/hash.h (scm_i_locale_string_hash, scm_i_latin1_string_hash,
scm_i_utf8_string_hash): update prototypes.
* libguile/scmsigs.c (sigaction): Use intptr_t instead of long.
* libguile/strings.c (scm_i_make_symbol, (scm_i_c_make_symbol): Use
uintptr_t instead of unsigned long.
* libguile/strings.h (scm_i_make_symbol, (scm_i_c_make_symbol): Update
declacations.
* libguile/srfi-60.c: Use scm_to_uintptr, scm_from_intptr and variants
throughout.
* libguile/symbols.c (symbol-hash): Use scm_from_uintptr.
Co-authored-by: Mike Gran <spk121@yahoo.com>
Co-authored-by: Andy Wingo <wingo@pobox.com>
* libguile/posix-w32.c (canonicalize_device_name,
slashify_file_name): New static functions.
(canonicalize_file_name_mingw): Use them in new function.
* libguile/posix-w32.h (canonicalize_file_name_mingw): Declare it.
(canonicalize_file_name): New define.
* libguile/filesys.c[__MINGW32__]: Include posix-w32.h to use it.
* libguile/fports.c[__MINGW32__]: Likewise.
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
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
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
* 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
Fixes a regression in ‘--without-threads’ builds introduced in
b8031fc965.
* libguile/finalizers.c (scm_i_is_finalizer_thread) [!SCM_USE_PTHREAD_THREADS]:
New function.
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
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]
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
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>
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>
* 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>
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.
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.
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.
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).
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>
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>
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>
* 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>