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

9452 commits

Author SHA1 Message Date
Daniel Llorens
a34c762de0 Extend core vector-copy to r7rs vector-copy
* libguile/vectors.h: Declare scm_vector_copy_partial.
* libguile/vectors.c (scm_vector_copy_partial): As stated.
  (scm_vector_copy): Reuse scm_vector_copy_partial.
* module/scheme/base.scm: Reuse core vector-copy.
* module/srfi/srfi-43: Reuse core vector-copy.
* test-suite/tests/vectors.test: Test vector-copy.
2021-08-06 13:06:51 +02:00
Daniel Llorens
bfda8d3972 Deprecate use of vector-move-left! and vector-move-right! on non-vector arrays
These functions weren't advertised to work on non-vector arrays. They
did try to, but only incorrectly. For example:

  (define a (vector 1 2 3 4 5))
  (define b (make-array 0 '(1 5)))
  (vector-move-right! a 0 2 b 2)
  b
  => #1@1(0 0 1 2 0)

instead of the correct result #1@1(0 1 2 0 0).

* libguile/vectors.c (vector-move-left!, vector-move-right!): As stated.
2021-08-06 13:06:51 +02:00
Daniel Llorens
81f12bf86e Deprecate using vector->list, vector-copy on arrays
* libguile/vectors.c (vector-copy, vector->list): As stated. Provide
  array free implementation for the supported case.
2021-08-05 12:33:34 +02:00
Daniel Llorens
bc7bd22267 Merge libguile/generalized-arrays.* into libguile/arrays.*
* libguile/arrays.h:
* libguile/arrays.c: As stated.
* libguile/init.c: Remove call to scm_init_generalized_arrays().

Elsewhere fix references to generalized-arrays.*.
2021-08-03 14:21:41 +02:00
Andy Wingo
afd268ac1d Bump objcode version
* libguile/loader.h (SCM_OBJCODE_MINOR_VERSION):
* module/system/vm/assembler.scm (*bytecode-minor-version*): Bump, as
we're going to start adding inlinable exports.
2021-05-11 21:39:07 +02:00
Ludovic Courtès
381291f5ff 'primitive-fork' closes and recreates the current thread's 'sleep_pipe'.
Partly fixes <https://bugs.gnu.org/41948>.

Previously, the child process could end up using the same 'sleep_pipe'
as its parent, leading to a race condition handling signals.

* libguile/posix.c (do_fork): New function.
(scm_fork): Call 'do_fork' via 'scm_without_guile'.
* test-suite/standalone/test-signal-fork: New test.
* test-suite/standalone/Makefile.am (check_SCRIPTS, TESTS): Add it.
2021-05-08 21:39:15 +02:00
Andrew Whatson
5a281e35f4 Close the finalization pipe before forking.
Partly fixes <https://bugs.gnu.org/41948>.
Reported by Mathieu Othacehe <othacehe@gnu.org>.

Previously, after 'fork', the child process could end up sharing the
finalization thread with its parent.

* libguile/finalizers.c (finalization_pipe): Initialize.
(reset_finalization_pipe): Factored out.
(start_finalization_thread): Create the pipe immediately before
launching the thread.  Ensure the pipe is cleaned up if thread creation
fails.  Update the finalizer callback if thread creation succeeds.
(stop_finalization_thread): Clean up the pipe after stopping the thread.
(spawn_finalizer_thread): Remove finalizer callback logic.
(scm_set_automatic_finalization_enabled): Remove pipe management.
(scm_init_finalizer_thread): Remove pipe management.

Co-authored-by: Ludovic Courtès <ludo@gnu.org>
2021-05-08 21:31:37 +02:00
Maxime Devos
553c82cee9 Define `O_NOFOLLOW' and various other flags when supported.
* libguile/filesys.c (scm_init_filesys): Define ‘O_IGNORE_CTTY’,
  ‘O_NOLINK’, ‘O_NOFOLLOW’, ‘O_PATH’, ‘O_TMPFILE’, ‘O_SHLOCK’,
  ‘O_EXLOCK’, ‘O_ASYNC’, ‘O_NOATIME’, ‘O_DIRECTORY’, ‘O_CLOEXEC’
  and ‘O_DIRECT’ when available.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2021-05-07 17:22:52 +02:00
Andy Wingo
81094013be Include config.h in mini-gmp.c, if present
* libguile/mini-gmp.c: Add config.h include.  Handles the case in which
gnulib provides some part of the standard library of mini-gmp, as is
apparently the case on FreeBSD for example.  Thanks to RhodiumToad for
the report and fix.
2021-05-01 22:39:30 +02:00
Andy Wingo
75babf8df9 Add GUILE_INSTALL_GMP_MEMORY_FUNCTIONS to NEWS; use at build-time
* NEWS (GUILE_INSTALL_GMP_MEMORY_FUNCTIONS): Update
* libguile/numbers.c: Add needed include.
* meta/build-env.in (GUILE_INSTALL_GMP_MEMORY_FUNCTIONS): Set when
building Guile.
2021-04-27 21:23:08 +02:00
Andy Wingo
534dd35a3c Allow users to force gmp to use libgc
* doc/ref/guile-invoke.texi (Environment Variables): Document
GUILE_INSTALL_GMP_MEMORY_FUNCTIONS.
* libguile/numbers.c (scm_init_numbers): Use environment variable.
2021-04-26 22:27:22 +02:00
Andy Wingo
04e9245918 Bump minor objcode version for new intrinsics
* libguile/loader.h (SCM_OBJCODE_MINOR_VERSION): Bump.
* module/system/vm/assembler.scm (*bytecode-minor-version*): Bump.
2021-04-26 17:05:34 +02:00
Andy Wingo
e0d022c347 Fix error when argument to < not a real
* libguile/intrinsics.c (less_p): scm_nan_p raises an error if arg is
not a real; guard.
2021-04-26 12:26:33 +02:00
Andy Wingo
83023160b1 Simplify module variable lookup slow-path
* libguile/intrinsics.h:
* libguile/intrinsics.c (lookup_bound_public, lookup_bound_private): Two
new intrinsics.
(scm_bootstrap_intrinsics): Wire them up.
* libguile/jit.c (compile_call_scm_from_scmn_scmn):
(compile_call_scm_from_scmn_scmn_slow):
(COMPILE_X8_S24__N32__N32__C32): Add JIT support for new instruction
kind.
* libguile/vm-engine.c (call-scm<-scmn-scmn): New instruction, takes
arguments as non-immediate offsets, to avoid needless loads and register
pressure.
* module/language/cps/effects-analysis.scm: Add cases for new
primcalls.
* module/language/cps/compile-bytecode.scm (compile-function): Add new
primcalls.
* module/language/cps/reify-primitives.scm (cached-module-box): If the
variable is bound, call lookup-bound-public / lookup-bound-private as
appropriate instead of separately resolving the module, name, and doing
the bound check.
* module/language/tree-il/compile-bytecode.scm (emit-cached-module-box):
Use new instructions.
* module/system/vm/assembler.scm (define-scm<-scmn-scmn-intrinsic):
(lookup-bound-public, lookup-bound-private): Add assembler support.
2021-04-26 09:48:52 +02:00
Jan (janneke) Nieuwenhuizen
6069fa5ce2
Compile fix for x86_64-MinGW.
* libguile/posix-w32.h (start_child): Return pid_t.
2021-04-12 12:18:53 +02:00
Jan (janneke) Nieuwenhuizen
3db293a71d
Document write-line.
* libguile/rdelim.c (SCM_DEFINE): Use "procedure" rather than
"function".
* doc/ref/api-io.texi (Line/Delimited): Use it to document 'write-line'.
2020-10-05 15:25:52 +02:00
Andy Wingo
72bf9d93ca Fix buffer overread in string-locale<?
* libguile/i18n.c (compare_strings): In all cases, convert to a
null-terminated string.  While we're doing that, might as well use
utf-8.
* test-suite/tests/i18n.test ("text collation (French)"): Add test.

Thanks again to Rob Browning for the report.
2021-03-15 22:02:12 +01:00
Andy Wingo
d87b57a00b Fix buffer overread in string-locale-ci=? and related functions
* libguile/i18n.c (u32_locale_casecoll): Take lengths of incoming
strings as parameters rather than assuming "nul" termination.
(compare_u32_strings_ci): Pass string lengths as computed from the
Scheme strings.
* test-suite/tests/i18n.test ("text collation (English)"): Add a test
case.

Thanks a million to Rob Browning for the report.
2021-03-15 21:23:43 +01:00
Mike Gran
5a1a1eee50 Add JIT capability for MinGW
* libguile/jit.c [__MING32__]: add windows.h on Win32
  (struct code_arena) [__MINGW32__]: a HANDLE for Win32 mmap
  (BIGENDIAN): rename to JIT_BIGENDIAN, to avoid collision with
    Win32 BIGENDIAN constant. All users changed
  (allocate_code_arena) [__MINGW32__]: add Win32 mmap allocator
  (emit_code) [__MINGW32__]: add Win32 munmap
* libguile/lightening/lightening/lightening.c: remove unnecessary mman.h
2021-03-13 15:43:57 -08:00
Andy Wingo
db9725fd02 Don't force installation of GMP allocators in guile shell
* libguile/guile.c (main): Don't override initial setting of
scm_install_gmp_memory_functions.  Thanks to Andrew Whatson for the
fix.
2021-03-12 22:38:21 +01:00
Andy Wingo
e30ee90478 Revert "Handle CRLF and Unicode line endings in read-line"
This reverts commit 0f983e3db0.

After discussing with Mike we are going to punt the read-line changes
for now.  Open the port in O_TEXT mode if you want to chomp the CR in
CFLF sequences.
2021-03-12 22:08:16 +01:00
Mike Gran
0f983e3db0 Handle CRLF and Unicode line endings in read-line
* libguile/rdelim.c (scm_read_line): handle CRLF, LS and PS
* module/ice-9/suspendable-ports.scm (read-line): handle CRLF, LS, and PS
* module/web/http.scm (read-header-line): take advantage of CRLF in read-line
   (read-header): don't need to test for \return
* test-suite/tests/rdelim.test: new tests for read-line CRLF, LS and PS
* doc/ref/api-io.texi: update doc for read-line
2021-03-11 19:42:33 -08:00
Michael Gran
3f4d5d128c For MinGW use Windows filepaths in libpath.h
* configure.ac (MINGW_LIBPATH): new automake conditional and test
* libguile/Makefile.am (libpath.h) [MINGW_LIBPATH]: use Windows-style
    paths
2021-03-11 10:46:06 -08:00
Mike Gran
1b0da42672 on MinGW, prefer winsock2.h over sys/select in iselect
* libguile/iselect.h [__MINGW32__]: add winsock2 include
2021-03-11 09:37:12 -08:00
Mike Gran
7d08c72cf9 Add windows stubs for dlopen, dlclose, dlsym, dlerror
* libguile/dynl.c [__MING32__] (dlopen, dlsym, dlclose, dlerror): use windows stubs
* libguile/posix-w32.c (dlopen_w32, dlsym_w32, dlclose_w32, dlerror_w32):
    new procedures
    (dlerror_str): new module-level variable
    (DLERROR_LEN): new define
* libguile/posix-w32.h: declare dlopen_w32, dlsym_w32, dlclose_w32, dlerror_w32.
    Declare RTLD_NOW, RTLD_LAZY, RTLD_GLOBAL, RTLD_LOCAL
2021-03-11 08:30:57 -08:00
Andy Wingo
85433fc2b1 Add mkstemp; undocument mkstemp!
* doc/ref/posix.texi (File System): Update to document mkstemp only.
* libguile/filesys.c: Make a mkstemp that doesn't modify the input
template.  Instead the caller has to get the file name from
port-filename.
(scm_mkstemp): Use the new mkstemp to implement mkstemp!.  Can't
deprecate yet though as the replacement hasn't been there for long
enough.
* libguile/posix.c (scm_tempnam): Update to mention mkstemp instead.
* module/system/base/compile.scm (call-with-output-file/atomic): Use
mkstemp.
* test-suite/tests/posix.test:
* test-suite/tests/r6rs-files.test: Use mkstemp.
* NEWS: Update.
2021-03-10 20:40:10 +01:00
Mike Gran
89a299102f On Win32, prefer winsock2 header for socket declarations
* libguile/posix-w32.h: prefer lowercase windows.h for MinGW cross-builds
* libguile/socket.c [HAVE_WINSOCK2_H]: use only winsock2.h for socket
    declarations
2021-03-10 02:01:03 -08:00
Michael Gran
1b697d339b remove 2nd attempt at invoking ComSpec when spawning child
The start_child procedure is used to spawn a child process. If it fails
to launch the given argv[0] as if it were a command, it has logic to
retry using the ComSpec as a command interpreter, treating argv[0] as
a batch file name. Usually, this fails because batch files would have
been handled in the first pass if they were valid.  Also, this has
the unfortunate side effect of spawning a shell awaiting user input.

It is safer to remove this attempt.

* libguile/posix-w32.c (start_child): remove fallback processing
2021-03-10 02:00:15 -08:00
Michael Gran
fedb65b98e Use lower-case windows.h
On some linux cross-builds, Windows.h is windows.h. On MinGW
case is irrelevant.

* libguile/posix-w32.h: modified
2021-03-10 01:53:03 -08:00
Michael Gran
870dfc0227 Fix define error for mini-gmp
* libguile/gen-scmconfig.c [!SCM_I_GSC_ENABLE_MINI_GMP]: define
    SCM_ENABLE_MINI_GMP as zero, not undef
2021-03-08 21:17:22 -08:00
Andy Wingo
ee1ed277ce Only install libgc as GMP allocator with mini-gmp
* libguile/numbers.c (scm_install_gmp_memory_functions): Default to 1
only if mini-gmp is enabled.
2021-03-08 22:28:25 +01:00
Andy Wingo
f46477f6f5 Don't expose mini-gmp to users
* libguile.h: Don't import anything GMP-related.
* libguile/numbers.h: Import GMP here instead.  If we are using
mini-GMP, only import it when building Guile.
(scm_to_mpz, scm_from_mpz): Don't define when mini-gmp is enabled.
2021-03-08 22:16:15 +01:00
Michael Gran
6ca3ab621c don't presume availability of gmp.pc
This suggests moving the conditional that determines if mini-gmp is used
into scmconfig.h.

* configure.ac: replace PKG_CHECK_MODULES for gmp with AC_LIB_HAVE_LINKFLAGS
    Remove ENABLE_MINI_GMP define.  Also don't run mpz_inits test for
    --enable-mini-gmp.
* libguile/gen-scmconfig.c (main) [ENABLE_MINI_GMP]: replace ENABLE_MINI_GMP
    with SCM_I_GSC_ENABLE_MINI_GMP
* libguile/bytevectors.c [ENABLE_MINI_GMP]: replace ENABLE_MINI_GMP
    with SCM_ENABLE_MINI_GMP
* libguile/init.c [ENABLE_MINI_GMP]: replace ENABLE_MINI_GMP
    with SCM_ENABLE_MINI_GMP
* libguile/numbers.c: include scm.h
    [SCM_ENABLE_MINI_GMP]: provide mpz_inits and mpz_clears
    [ENABLE_MINI_GMP]: prefer SCM_ENABLE_MINI_GMP to ENABLE_MINI_GMP
* libguile/numbers.h: include scm.h
* libguile/random.c [ENABLE_MINI_GMP]: replace ENABLE_MINI_GMP
    with SCM_ENABLE_MINI_GMP
* libguile/socket.c [ENABLE_MINI_GMP]: replace ENABLE_MINI_GMP
    with SCM_ENABLE_MINI_GMP
2021-03-03 14:06:29 -08:00
Andy Wingo
a574fdf964 Remove read extension support from primitive-read
* libguile/read.c (scm_read_sharp_extension): Remove.
(scm_read_sharp): Adapt.
2021-03-03 22:30:49 +01:00
Andy Wingo
f2a2baa042 More read.c simplifications
* libguile/read.c: Use "return EXPR" instead of "return (EXPR)".  Avoid
passing around line and column info, as we don't use it any more.
2021-03-03 22:22:56 +01:00
Andy Wingo
38abf6b247 primitive-read handles only default reader options
* libguile/read.c: Remove support for all non-default reader options.
Also remove support for source positions.  The idea is that
primitive-read should just be a stripped-down, easy-to-understand reader
that is enough to bootstrap the C reader.  Probably more refactoring
will follow.
2021-03-03 22:17:16 +01:00
Andy Wingo
a1fdb76455 Scheme reader fully replaces C reader
* libguile/read.h:
* libguile/read.c (scm_primitive_read): New name for C reader.
(scm_read): Call current value of "read" variable.
(scm_init_read): Initialize "read" binding to "primitive-read".
Replaced later in boot-9.
2021-03-03 21:43:33 +01:00
Andy Wingo
5ea8c69e91 Invalid charset at EOF does not cause decoding error
* libguile/ports.c (peek_iconv_codepoint): If the input has no bytes,
there's little point in raising a decoding error here.  Therefore remove
the needless iconv acquisition, harmonising with suspendable-ports.
* test-suite/tests/ports.test ("port-encoding"): Update test to include
some input so that the exception gets raised.
2021-03-03 16:22:56 +01:00
Michael Gran
54adbd6f0f improve autoconfigury for minigmp
* configure.ac: add SCM_I_GSC_ENABLE_MINI_GMP var and rename
    GUILE_MINI_GMP to ENABLE_MINI_GMP
* libguile/bytevectors (GUILE_MINI_GMP): rename to ENABLE_MINI_GMP
* libguile/gen-scmconfig.c: renamed GUILE_MINI_GMP to ENABLE_MINI_GMP.
    rename GUILE_MINI_GMP to SCM_ENABLE_MINI_GMP
* libguile/gen-scmconfig.h: add SCM_I_GSC_ENABLE_MINI_GMP
* libguile/init.c [GUILE_MINI_GMP]: prefer ENABLE_MINI_GMP
* libguile/numbers.c [GUILE_MINI_GMP]: prefer ENABLE_MINI_GMP
* libguile/numbers.h: include scmconfig.h
    rename GUILE_MINI_GMP to SCM_ENABLE_MINI_GMP
* libguile/random.c [GUILE_MINI_GMP]: prefer ENABLE_MINI_GMP
* libguile/socket.c [GUILE_MINI_GMP]: prefer ENABLE_MINI_GMP
* libguile.h [GUILE_MINI_GMP]: prefer SCM_ENABLE_MINI_GMP
2021-03-02 06:18:32 -08:00
Michael Gran
eb1bd8050e Enable option to prefer mini-gmp over libgmp
* configure.ac: rework gmp library detection. Add new flag.
* libguile.h: modify gmp header inclusion
* libguile/Makefile.am: add mini-gmp.[ch] files
* libguile/bytevectors.c: add mini-gmp headers
* libguile/gen-scmconfig.c: new #include variable GUILE_MINI_GMP
* libguile/init.c: add mini-gmp header
* libguile/mini-gmp.c: new file
* libguile/mini-gmp.h: new file
* libguile/numbers.c: add fallback for missing mpz_get_d_2exp
* libguile/numbers.h: yse mini-gmp header
* libguile/random.c: use mini-gmp header
* libguile/socket.c: use mini-gmp header
2021-03-02 06:18:32 -08:00
Andy Wingo
07f63cf4f3 Add syntax-sourcev
* libguile/syntax.c (sourcev_to_props, props_to_sourcev)
(scm_syntax_source, scm_syntax_sourcev): Add alternate source
representation for syntax objects.
2021-02-25 21:17:36 +01:00
Andy Wingo
2edf91d51c Syntax objects have "source" field
* libguile/syntax.c (scm_make_syntax): Add optional "source" argument.
  Note that this function is internal.
  (scm_syntax_source): New function, replacing definition in boot-9.scm.
* libguile/syntax.h: Add new declarations.
* module/ice-9/psyntax-pp.scm:
* module/ice-9/psyntax.scm (source-annotation): For syntax objects, the
  source annotation comes direct from the syntax object.
* module/system/vm/assembler.scm (link-data, intern-constant): Write
  5-word syntax objects.
2021-02-20 20:19:34 +01:00
Andy Wingo
2e26538d6a Replace libltdl with raw dlopen, dlsym
* NEWS: Update.
* am/bootstrap.am (SOURCES):
* module/Makefile.am (SOURCES): Add system/foreign-library.scm.
* configure.ac: Replace ltdl check with -ldl check.
* libguile/dynl.c: Rewrite to just expose core dlopen / dlsym / etc to a
  helper Scheme module.
  (scm_dynamic_link, scm_dynamic_pointer, scm_dynamic_function)
  (scm_dynamic_object_p, scm_dynamic_call): Rewrite in terms of (system
  foreign-library).
* libguile/extensions.c (load_extension): Avoid scm_dynamic_call.
* module/system/foreign-library.scm: New file.
* module/oop/goops.scm (<dynamic-object>): Hackily export
  <foreign-library> instead of a class here.
* doc/ref/api-foreign.texi (Foreign Function Interface): Rewrite to only
  document the new interfaces.  Eventually we will deprecate
  dynamic-link and friends.
* doc/ref/guile.texi (API Reference): Move Foreign Objects after Foreign
  Function Interface.  Seems there should be some closer relationship
  but this will do for now.
* doc/ref/tour.texi (Putting Extensions into Modules):
* doc/ref/libguile-parallel.texi (Parallel Installations): Update for
  rename of Modules and Extensions to Foreign Extensions.
* libguile/deprecated.h:
* libguile/deprecated.c (scm_dynamic_unlink): Deprecate.
* libguile/guile.c: Remove ltdl include.
* test-suite/tests/foreign.test: Update tests to use new API, and update
  error expectations.
2021-02-03 23:02:21 +01:00
Michael Gran
75b0db1a28 getsockopt may return garbage for parameters < sizeof(int)
Uninitialized variable.

* libguile/socket.c (scm_getsockopt): zeroize arguments before use
2021-01-21 19:35:15 -08:00
Michael Gran
449b9bd5e1 in null threads, don't define sigmask stub when pthread_sigmask does not exist
* libguile/gen-scmconfig.c (main) [HAVE_PTHREAD_SIGMASK]: new output
    define SCM_HAVE_PTHREAD_SIGMASK
* libguile/null-threads.h (scm_i_pthread_sigmask) [SCM_HAVE_PTHREAD_SIGMASK]:
    make inline function conditional on existence of pthread_sigmask
2021-01-21 15:34:03 -08:00
Michael Gran
d3f7a1d0b7 Need Guile and Windows types for the declarations posix-w32
* libguile/posix-w32.h: include scm.h and windows.h
2021-01-21 15:33:52 -08:00
Michael Gran
c5faaf50cf missing includes for list.h
* libguile/loader.c: include list.h
* libguile/stime.c: include list.h
2021-01-21 15:33:43 -08:00
Michael Gran
32bf48e4b7 Replace mutating mkdtemp! with non-mutating mkdtemp
* doc/ref/posix.texi: replace mkdtemp! and scm_mkdtemp_x documentation
    with documentation for mkdtemp and scm_mkdtemp
* libguile/filesys.c (scm_mkdtemp_x): procedure mkdtemp! removed
    (scm_mkdtemp): new procedure mkdtemp
* libguile/filesys.h: Remove declaration for scm_mkdtemp_x.  New declaration
    scm_mkdtemp.
* test-suite/tests/filesys.test: Remove mkdtemp! tests.  Add tests
    for mkdtemp.
2021-01-21 10:33:08 -08:00
Michael Gran
758b31994c Fix incorrect docstring of mkdtemp!
* libguile/filesys.c (scm_mkdtemp_x): fix docstring
2021-01-19 15:06:57 -08:00
Michael Gran
d98e1d5e4f New procedure mkdtemp! to create unique temporary directory
* configure.ac (AC_CHECK_FUNCS): add mkdtemp! test
* doc/ref/posix.texi: document mkdtemp!
* libguile/filesys.c (scm_mkdtemp_x): new function
* libguile/filesys.h: new declaration for scm_mkdtemp_x
* test-suite/tests/filesys.test: add tests for mkdtemp!

Adapted from a patch by Rob Browning.
2021-01-19 05:58:14 -08:00