summaryrefslogtreecommitdiff
path: root/libguile
Commit message (Collapse)AuthorAgeFilesLines
* loader: Handle interned constants as well as plain bytevectors.Ricardo Wurmus2020-05-171-6/+15
| | | | | | | This is a follow-up to commit b04e79283ada9a6af05552dda6446a0934c0fbe2. * libguile/loader.c (scm_load_thunk_from_memory): Extract constants only if the object is a pair.
* guile-snarf fixRobin Templeton2020-04-041-1/+2
| | | | | | (Best-ability ChangeLog annotation added by Christopher Allan Webber.) * libguile/guile-snarf.in (modern_snarf): Adjusted.
* multiple obarraysBT Templeton2020-04-042-16/+87
| | | | | | | | | * libguile/symbols.c (lookup_uninterned_symbol) (lookup_interned_latin1_symbol, lookup_interned_utf8_symbol) (scm_i_str2symbol): Take an `obarray' argument. All callers changed. (scm_make_obarray, scm_find_symbol, scm_intern, scm_unintern) (scm_obarray_for_each): New functions.
* intern arbitrary constantsRobin Templeton2020-04-041-6/+17
| | | | | | | | | | | | | | | | | | | | | | | | (Best-ability ChangeLog annotation added by Christopher Allan Webber.) * libguile/loader.c (load_thunk_from_memory): Refactor, adding "constants" argument and passing to "init" if appropriate. (load_thunk_from_file): Call "load-thunk-from-memory" with "constants" set to #f. (scm_load_thunk_from_memory): Instead of a bytevector, accept a cons of "(bytevector . constants)", where constants is either a vector or #f. Pass this into "load_thunk_from_memory". * module/language/bytecode/spec.scm: Adapt printer. * module/language/cps/compile-bytecode.scm (compile-bytecode): New variable. * module/system/repl/command.scm (disassemble): Adapt to expect pair which includes bytevector as its car. * module/system/vm/assembler.scm <asm>: Add "to-file?" slot. (fresh-block): New variable. (make-assembler): Adapt to expect "to-file?" keyword argument. (intern-constant): Support "asm-to-file?" in checks. (emit-init-constants, link-data): Likewise. (link-assembly): Update logic for handling "(bytevector . constants)" pair, as well as the expectations of its invocation by compile-bytecode.
* Remove CFLAGS from snarfcppopts.Robin Templeton2020-04-041-1/+1
| | | | libguile/Makefile.am (snarfcppopts): Remove CFLAGS
* Revert "Fix build on platforms where the stack grows upwards."Andy Wingo2020-03-131-1/+1
| | | | This patch was only meant to apply to the 3.0 branch.
* Fix build on platforms where the stack grows upwards.John Paul Adrian Glaubitz2020-02-121-1/+1
| | | | | | | * libguile/continuations.c (scm_dynthrow): Fix missing mra parameter to grow_stack for SCM_STACK_GROWS_UP. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
* Handle GMP allocations through libgc and remove bignum finalizers.Ludovic Courtès2020-02-121-7/+12
| | | | | | | | | | | | | | | | This significantly speeds up loads that create lots of bignums, like (language cps slot-allocation) for files with many top-level definitions. Compiling such a file is typically 2.5 times faster. See <https://lists.gnu.org/archive/html/guile-devel/2020-02/msg00023.html>. * libguile/numbers.c (custom_gmp_malloc): Use 'scm_gc_malloc_pointerless' instead of 'scm_malloc'. (custom_gmp_realloc): Use 'scm_gc_realloc'. (custom_gmp_free): Remove call to 'free'. (make_bignum): Use 'scm_gc_malloc' instead of 'scm_gc_malloc_pointerless'. Call 'scm_i_set_finalizer' only when SCM_INSTALL_GMP_MEMORY_FUNCTIONS is false.
* Respect thread local fluid defaultsRob Browning2020-01-121-14/+9
| | | | | | | | | | | | | Previously (fluid-ref (make-thread-local-fluid #t)) would return #f via scm_fluid_ref because the internal scm_hashq_ref would return #f when the fluid had not been set, and that was interpreted as an actual value for the fluid. Instead, just pass the fluid default as the default for the hash table lookups so that we don't need a second step to determine if the fluid was set. Thanks to Andrew Gierth for tracking down the problem.
* Fix non-deterministic crash in 'finalization_thread_proc'.Ludovic Courtès2019-12-091-13/+18
| | | | | | | | Fixes <https://bugs.gnu.org/37757>. Reported by Jesse Gibbons <jgibbons2357@gmail.com>. * libguile/finalizers.c (finalization_thread_proc): Do not enter the "switch (data.byte)" condition when data.n <= 0.
* ports: 'scm_port_poll' honors "w" flags.Ludovic Courtès2019-11-181-1/+1
| | | | | | | Fixes <https://bugs.gnu.org/36709>. Reported by Mark H Weaver <mhw@netris.org>. * libguile/ports.c (scm_port_poll): Replace second POLLIN by POLLOUT.
* 'strftime' and 'strptime' honor the locale encoding.Ludovic Courtès2019-06-301-12/+12
| | | | | | | | | | | | | | | Fixes <https://bugs.gnu.org/35920>. Reported by Christopher Lam <christopher.lck@gmail.com>. * libguile/stime.c (scm_strftime): Use 'scm_to_locale_stringn' instead of 'scm_to_utf8_stringn'. (scm_strptime): Likewise, and use 'scm_string_length' instead of 'u8_strnlen'. * test-suite/tests/time.test ("strftime")["strftime passes wide characters"]: Wrap body in 'with-locale'. ["strftime fr_FR.utf8", "strftime fr_FR.iso88591"]: New tests. ("strptime")["strftime fr_FR.utf8", "strftime fr_FR.iso88591"]: New tests.
* Remove references to 'inet-ntoa' and 'inet-aton'.Ludovic Courtès2019-06-241-3/+1
| | | | | | | | | | | | These procedures were removed in Guile 2.2 by commit fc7bd367ab4b5027a7f80686b1e229c62e43c90b (May 2011). * libguile/socket.h (scm_inet_aton, scm_inet_ntoa): Remove. * module/system/repl/server.scm (make-tcp-server-socket): Use 'inet-pton' instead of 'inet-aton'. * doc/ref/web.texi (HTTP): Likewise in 'declare-header!' example. * doc/ref/posix.texi (Network Address Conversion): Remove documentation of 'inet-ntoa' and 'inet-aton'.
* Copy terminating zero in 'scm_cat_path'.Ludovic Courtès2019-06-201-2/+2
| | | | | * libguile/script.c (scm_cat_path): Pass N + 1, not N, to 'strncat'. Reported by GCC 9.1.0.
* srfi-14: Fix possible buffer overrun in '%char-set-dump'.Ludovic Courtès2019-06-201-1/+1
| | | | | * libguile/srfi-14.c (scm_sys_char_set_dump): Change array size from 9 to 11 as suggested by GCC 9.1.0.
* Rename 'scm_c_make_char' to 'scm_i_make_char'.Mark H Weaver2019-06-188-34/+34
| | | | | | | * libguile/chars.c, libguile/chars.h, libguile/ports.c, libguile/print.c, libguile/read.c, libguile/srfi-13.c, libguile/strings.c, libguile/vm-engine.c: Rename 'scm_c_make_char' to 'scm_i_make_char'.
* fport_seek: Eliminate a fruitless use of 'off_t_or_off64_t'.Mark H Weaver2019-06-181-7/+2
| | | | | | | | | This is a followup to commit 91ba73b397fcc2a36ae7e434522a924c7a8887d0. * libguile/fports.c (fport_seek): Use 'lseek' instead of 'lseek_or_lseek64', and use 'scm_t_off' uniformly. That's the type used in the function signature, and there's no benefit to using a wider type internally. Remove the overflow check, which is no longer needed.
* open-process: Fix dup(2) and execvp(2) error handling.Mark H Weaver2019-06-181-9/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, in the case where OUT is 0, or ERR is 0 or 1, e.g. when (current-error-port) points to STDOUT, the code in 'start_child' to relocate OUT/ERR out of the way to another file descriptor had multiple bugs: (1) It neglected to close the original file descriptor. (2) It checked 'errno' without first checking the return value of dup(2). This doesn't work because dup(2) leaves 'errno' unchanged if there's no error. (3) In case 'errno' contained EINTR, the retry code failed because OUT (or ERR) was overwritten by the result of the previous failed dup(2) call. This commit fixes these problems, as well as another problem with 'execvp' error reporting. * libguile/posix.c (renumber_file_descriptor): New static helper function. (start_child): Use 'renumber_file_descriptor'. If 'execvp' fails, write the error message to file descriptor 2. Previously, we wrote the error message to ERR, which was the old file descriptor before being relocated to 2.
* Refresh a stale comment.Mark H Weaver2019-06-181-1/+1
| | | | * libguile/numbers.h: In a comment, update the count of number subtypes.
* scm_mkstrport: Optimize the POS -> BYTE_POS conversion.Mark H Weaver2019-06-181-2/+2
| | | | | * libguile/strports.c (scm_mkstrport): Use 'scm_c_string_utf8_length' to avoid the conversion to UTF-8.
* Add get-bytevector-some!.Mark H Weaver2019-06-182-2/+48
| | | | | | | | * libguile/r6rs-ports.c (scm_get_bytevector_some_x): New procedure. * libguile/r6rs-ports.h (scm_get_bytevector_some_x): Add prototype. (scm_unget_bytevector): Move prototype next to 'scm_get_bytevector_some_x'. * module/ice-9/binary-ports.scm: Export 'get-bytevector-some!'. * doc/ref/api-io.texi (Binary I/O): Document it.
* scm_to_stringn: Avoid passing NULL to c_strcasecmp.Mark H Weaver2019-06-181-6/+5
| | | | | | | | | Reported by Massimiliano Gubinelli <m.gubinelli@gmail.com> in <https://lists.gnu.org/archive/html/guile-user/2019-05/msg00070.html>. * libguile/strings.c (scm_to_stringn): Check for (encoding == NULL) before passing it to 'c_strcasecmp'. Eliminate redundant 'enc' variable.
* Fix typo in tags.h comment.Mark H Weaver2019-06-181-1/+1
| | | | * libguile/tags.h: Fix typo in comment.
* Save and restore errno in the signal handler.Mark H Weaver2019-06-181-0/+2
| | | | * libguile/scmsigs.c (take_signal): Save and restore errno.
* Improve overflow checks in bytevector, string, and I/O operations.Mark H Weaver2019-06-188-76/+142
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * libguile/bytevectors.c (INTEGER_ACCESSOR_PROLOGUE) (scm_bytevector_copy_x, bytevector_large_set): Rewrite checks to reliably detect overflows. (make_bytevector): Constrain the bytevector length to avoid later overflows during allocation. (make_bytevector_from_buffer): Fix indentation. (scm_bytevector_length): Use 'scm_from_size_t' to convert a 'size_t', not 'scm_from_uint'. * libguile/fports.c (fport_seek): Check for overflow before the implicit conversion of the return value. * libguile/guardians.c (guardian_print): Use 'scm_from_ulong' to convert an 'unsigned long', not 'scm_from_uint'. * libguile/ports.c (scm_unread_string): Change a variable to type 'size_t'. (scm_seek, scm_truncate_file): Use 'scm_t_off' instead of 'off_t_or_off64_t' to avoid implicit type conversions that could overflow, because 'ptob->seek' and 'ptob->truncate' use 'scm_t_off'. * libguile/r6rs-ports.c (bytevector_input_port_seek) (custom_binary_port_seek, bytevector_output_port_seek): Rewrite offset calculations to reliably detect overflows. Use 'scm_from_off_t' to convert a 'scm_t_off', not 'scm_from_long' nor 'scm_from_int'. (scm_get_bytevector_n_x, scm_get_bytevector_all, scm_unget_bytevector) (bytevector_output_port_write): Rewrite checks to reliably detect overflows. Use 'size_t' where appropriate. (bytevector_output_port_buffer_grow): Rewrite size calculations to reliably detect overflows. Minor change in the calculation of the new size: now it is max(min_size, 2*current_size), whereas previously it would multiply current_size by the smallest power of 2 needed to surpass min_size. * libguile/strings.c (make_stringbuf): Constrain the stringbuf length to avoid later overflows during allocation. (scm_string_append): Change overflow check to use INT_ADD_OVERFLOW. * libguile/strports.c (string_port_write): Rewrite size calculations to reliably detect overflows. (string_port_seek): Rewrite offset calculations to reliably detect overflows. Use 'scm_from_off_t' to convert a 'scm_t_off', not 'scm_from_long'. (string_port_truncate): Use 'scm_from_off_t' to convert a 'scm_t_off', not 'scm_from_off_t_or_off64_t'. * libguile/vectors.c (scm_c_make_vector): Change a variable to type 'size_t'.
* 'basename' correctly handles "/" and "//".Ludovic Courtès2019-06-041-4/+13
| | | | | * libguile/filesys.c (scm_basename): Special-case "/" and "//". * test-suite/tests/filesys.test ("basename"): New test prefix.
* Strings, i18n: Limit the use of alloca to approximately 8 kilobytes.Mark H Weaver2019-05-072-36/+79
| | | | | | | | | | | | | * libguile/i18n.c (SCM_MAX_ALLOCA): New macro. (SCM_STRING_TO_U32_BUF): Accept an additional variable to remember whether we used malloc to allocate the buffer. Use malloc if the allocation size is greater than SCM_MAX_ALLOCA. (SCM_CLEANUP_U32_BUF): New macro. (compare_u32_strings, compare_u32_strings_ci, str_to_case): Adapt. * libguile/strings.c (SCM_MAX_ALLOCA): New macro. (normalize_str, unistring_escapes_to_r6rs_escapes): Use malloc if the allocation size is greater than SCM_MAX_ALLOCA. * test-suite/tests/i18n.test, test-suite/tests/strings.test: Add tests.
* put-u8: Always write a single byte, regardless of the port encoding.Mark H Weaver2019-05-071-1/+1
| | | | | | | | Previously, 'put-u8' used textual I/O to write a single character, relying on the usual practice of setting the port encoding to ISO-8859-1 for binary ports. * libguile/r6rs-ports.c (scm_put_u8): Use 'scm_c_write', not 'scm_putc'.
* Optimize fixnum exact integer square roots.Mark H Weaver2019-05-071-32/+41
| | | | | | | * libguile/numbers.c (scm_exact_integer_sqrt, scm_sqrt) (exact_integer_is_perfect_square, exact_integer_floor_square_root): Where it is trivial to do so, use GMP's low-level mpn functions to avoid heap allocation.
* Fix indentation in scm_sum.Mark H Weaver2019-05-071-67/+68
|
* Fix typo in comment.Mark H Weaver2019-05-071-1/+1
|
* Add 'scm_c_make_char' and use it where appropriate.Mark H Weaver2019-05-079-47/+59
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts the change to SCM_MAKE_CHAR made in the previous commit 63818453ad226cd3c2d1fd8ade12e3d7c1d43c05, which used an arithmetic trick to avoid evaluating its argument more than once. Here, we restore the previous implementation of SCM_MAKE_CHAR, which evaluates its argument twice. Instead, we introduce a new inlinable function 'scm_c_make_char' and replace uses of SCM_MAKE_CHAR with calls to 'scm_c_make_char' where appropriate. * libguile/chars.h (scm_c_make_char): New inline function. * libguile/inline.c: Include chars.h. * libguile/srfi-13.c (REF_IN_CHARSET, scm_string_any, scm_string_every) (scm_string_trim, scm_string_trim_right, scm_string_trim_both) (scm_string_index, scm_string_index_right, scm_string_skip) (scm_string_skip_right, scm_string_count, string_titlecase_x) (string_reverse_x, scm_string_fold, scm_string_fold_right) (scm_string_for_each, scm_string_filter, scm_string_delete): Use 'scm_c_make_char' instead of 'SCM_MAKE_CHAR' in cases where the argument calls a function. * libguile/chars.c (scm_char_upcase, scm_char_downcase, scm_char_titlecase), libguile/ports.c (scm_port_decode_char), libguile/print.c (scm_simple_format), libguile/read.c (scm_read_character), libguile/strings.c (scm_string_ref, scm_c_string_ref), libguile/vm-engine.c ("string-ref"): Ditto.
* Reimplement SCM_MAKE_CHAR to evaluate its argument only once.Mark H Weaver2019-04-171-9/+12
| | | | | | | | | The motivation for this change is that SCM_MAKE_CHAR is sometimes passed an expression that involves a procedure call that is not always trivial. In other cases, the results are not guaranteed to be the same both times, which could lead to the creation of invalid SCM objects. * libguile/chars.h (SCM_MAKE_CHAR): Reimplement.
* Fix gc.test "after-gc-hook gets called" failures.Andrea Azzarone2019-04-161-0/+8
| | | | | | * libguile/scmsigs.c (signal_delivery_thread): Call scm_async_tick to give any pending asyncs a chance to run before we block indefinitely waiting for a signal to arrive.
* Avoid passing NULL to 'memcpy' and 'memcmp'.Mark H Weaver2019-04-164-7/+24
| | | | | | | | | | | | | | | | | | | | | | | Reported by Jeffrey Walton <noloader@gmail.com> in <https://lists.gnu.org/archive/html/guile-devel/2019-03/msg00001.html>. Note that C11 section 7.1.4 (Use of library functions) states that: "unless explicitly stated otherwise in the detailed descriptions [of library functions] that follow: If an argument to a function has an invalid value (such as ... a null pointer ...) ..., the behavior is undefined." Note that 'strxfrm' is an example of a standard C function that explicitly states otherwise, allowing NULL to be passed in the first argument if the size argument is zero, but no similar allowance is specified for 'memcpy' or 'memcmp'. * libguile/bytevectors.c (scm_uniform_array_to_bytevector): Call memcpy only if 'byte_len' is non-zero. * libguile/srfi-14.c (charsets_equal): Call memcmp only if the number of ranges is non-zero. * libguile/stime.c (setzone): Pass 1-character buffer to 'scm_to_locale_stringbuf', instead of NULL. * libguile/strings.c (scm_to_locale_stringbuf): Call memcpy only if the number of bytes to copy is non-zero.
* Remove vestigial comment in tags.h.Mark H Weaver2019-04-161-6/+1
| | | | | * libguile/tags.h: Remove a vestigial comment which seems to have been separated from its associated code long ago.
* Handle newlib C library's langinfo constant namesMichael Gran2019-02-231-1/+26
| | | | | | | | | | | | | The newlib C library (used in Cygwin) has alternative names for nl_langinfo GNU extensions * configure.ac (_NL_NUMERIC_GROUPING): new test * libguile/i18n.c (INT_CURR_SYMBOL, MON_DECIMAL_POINT, MON_THOUSANDS_SEP) (MON_GROUPING, POSITIVE_SIGN, NEGATIVE_SIGN, GROUPING, INT_FRAC_DIGITS) (FRAC_DIGITS, P_CS_PRECEDES, P_SEP_BY_SPACE, N_CS_PRECEDES, N_SEP_BY_SPACE) (P_SIGN_POSN, N_SIGN_POSN, INT_P_CS_PRECEDES, INT_P_SEP_BY_SPACE) (INT_N_CS_PRECEDES, INT_N_SEP_BY_SPACE, INT_P_SIGN_POSN, INT_N_SIGN_POSN) [HAVE_DECL__NL_NUMERIC_GROUPING]: map to newlib C constants, when present
* Fix binary output on files created by mkstemp!Mike Gran2019-02-091-4/+4
| | | | | | | Some operating systems require a O_BINARY flag. * libguile/filesys.c (scm_i_mkstemp): Don't mask out O_BINARY flag * test-suite/tests/posix.test ("binary mode honored"): new test
* Fix strftime compile with null threadsMike Gran2019-02-091-2/+2
| | | | * libguile/stime.c (scm_strftime): use correct pthread lock function
* Do not warn the user when 'madvise' returns ENOSYS.Ludovic Courtès2018-12-161-2/+5
| | | | | * libguile/vm.c (return_unused_stack_to_os): Avoid 'perror' calls when 'madvise' returns ENOSYS.
* scm_seed_to_random_state: Support wide string arguments.Mark H Weaver2018-10-191-2/+24
| | | | | | | | | | Partially fixes <https://bugs.gnu.org/33044>. Reported by Tom de Vries <tdevries@suse.de>. * libguile/random.c (scm_seed_to_random_state): Use 'scm_to_utf8_string' (or 'scm_to_latin1_string' for a narrow string, for compatibility) to convert the string into raw bytes for use by 'scm_c_make_rstate'. Make sure the length in bytes fits within an 'int'.
* Fix typo in strings.h.Mark H Weaver2018-10-191-2/+2
| | | | | * libguile/strings.h: In a comment, add the missing "i_" in "scm_i_is_narrow_string".
* Use 'scm_from_utf8_{string,symbol,keyword}' for C string literals.Mark H Weaver2018-10-1722-102/+115
| | | | | | | | | | | | | | | | | | | | | | Partial fix for <https://bugs.gnu.org/33044>. Reported by Tom de Vries <tdevries@suse.de>. Fix several instances of the mistake of using 'scm_from_locale_*' for C strings that originally came from a C string literal. Change several uses of 'scm_from_latin1_*' as well, to promote the practice of writing code that works for arbitrary C string literals. Also add missing years to the copyright notices of changed files, based on the git history. * libguile/debug-malloc.c, libguile/deprecation.c, libguile/error.c, libguile/eval.c, libguile/expand.c, libguile/extensions.c, libguile/filesys.c, libguile/init.c, libguile/load.c, libguile/modules.c, libguile/pairs.c, libguile/posix.c, libguile/print.c, libguile/random.c, libguile/read.c, libguile/regex-posix.c, libguile/snarf.h, libguile/srfi-13.c, libguile/stacks.c, libguile/stime.c, libguile/strports.c, libguile/values.c: Use 'scm_from_utf8_*' where appropriate.
* In 'ash' and 'round-ash', handle right shift count of LONG_MIN.Mark H Weaver2018-10-141-2/+11
| | | | | | | | | | | | Fixes <https://bugs.gnu.org/21901>. Reported by Zefram <zefram@fysh.org>. * libguile/numbers.c: Add another top-level 'verify' to ensure that LONG_MIN is not a fixnum. (scm_ash, scm_round_ash): Ensure that when the shift count is LONG_MIN, it is not handled via the normal code path, to avoid signed overflow when the shift count is negated. * test-suite/tests/numbers.test: Add tests.
* Fix 'round-ash' of negative integers by huge right shift counts.Mark H Weaver2018-10-141-6/+10
| | | | | | | | | | | | | | This is a followup to commit 011aec7e240ef987931548d90c53e6692c85d01c. When rounding, right shifting a negative integer by a huge shift count results in 0, not -1. * libguile/numbers.c: Add top-level 'verify' to ensure that the assumptions in 'scm_ash' and 'scm_round_ash' are valid. (scm_round_ash): In the case that handles huge right shifts, require that the shift count _exceeds_ the integer length, and return 0 instead of -1. * test-suite/tests/numbers.test: Adjust tests accordingly.
* Gracefully handle huge shift counts in 'ash' and 'round-ash'.Mark H Weaver2018-10-141-3/+31
| | | | | | | | | | | | Fixes <https://bugs.gnu.org/32644>. Reported by Stefan Israelsson Tampe <stefan.itampe@gmail.com>. The need for this arose because the type inferrer for 'ursh' sometimes passes (- 1 (expt 2 64)) as the second argument to 'ash'. * libguile/numbers.c (scm_ash, scm_round_ash): Gracefully handle several cases where the shift count does not fit in a C 'long'. * test-suite/tests/numbers.test: Add tests.
* Fix list validation of *list->bytevector procedures.Mark H Weaver2018-10-141-4/+8
| | | | | | | | | | | | Fixes <https://bugs.gnu.org/32938>. Reported by Josh Datko <jbd@cryptotronix.com>. * libguile/validate.h (SCM_VALIDATE_LIST_COPYLEN) (SCM_VALIDATE_NONEMPTYLIST_COPYLEN): Use '!=' instead of '>=' to validate the result of 'scm_ilength' after it has been stored in the user variable 'cvar'. * test-suite/tests/bytevectors.test: Add tests. Use '#:use-module' instead of ':use-module' in 'define-module' form.
* Improve the documentation for 'nil?'.Mark H Weaver2018-10-141-2/+11
| | | | | | | * libguile/boolean.c (scm_nil_p): Improve docstring. * doc/ref/api-languages.texi (Nil): Add documentation for 'nil?', along with a description of how Elisp interprets Scheme booleans and end-of-list.
* Fix 32/64 bit bug in INTEGER_ACCESSOR_PROLOGUEDaniel Llorens2018-10-101-1/+1
|
* Fix 'atomic-box-compare-and-swap!'.Mark H Weaver2018-10-052-9/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes <https://bugs.gnu.org/32786>. 'scm_atomic_compare_and_swap_scm' is a thin wrapper around 'atomic_compare_exchange_weak' (where available), and therefore it may spuriously fail on some platforms, leaving the atomic object unchanged even when the observed value is equal to the expected value. Since 'scm_atomic_compare_and_swap_scm' returns both a boolean result and the observed value, the caller is able to detect spurious failures when using that API. 'atomic-box-compare-and-swap!' presents a simpler API, returning only the observed value. The documentation advises callers to assume that the exchange succeeded if the observed value is 'eq?' to the expected value. It's therefore not possible to report spurious failures with this API. 'atomic-box-compare-and-swap!' uses 'scm_atomic_compare_and_swap_scm', and prior to this commit would simply ignore the boolean result and return the observed value. In case of spurious failures, the caller would legitimately conclude that the exchange had succeeded. With this commit, 'atomic-box-compare-and-swap!' now retries in case of spurious failures. * libguile/atomic.c (scm_atomic_box_compare_and_swap_x): If 'scm_atomic_compare_and_swap_scm' returns false and the observed value is equal to 'expected', then try again. * libguile/vm-engine.c (atomic-box-compare-and-swap!): Ditto.