* libguile/fports.c (close_the_fd, fport_close): Arrange to always close
the fd, even if the flush procedure throws an exception. Perhaps the
port machinery should do this for us, though. Don't wrap the close
call in SCM_SYSCALL, EINTR leaves the fd in an unspecified state.
Don't bother freeing buffers, the collector will handle that; simply
drop references via scm_port_non_buffer.
* libguile/ports.c (do_free, finalize_port): Catch exceptions caused by
the free procedure. Don't bother setting the stream to 0 at all.
(scm_close_port): Ensure that exceptions thrown by the "close"
procedure don't prevent the port from being marked as closed.
* libguile/strings.c (scm_from_utf8_stringn): Embarassingly, my
scm_from_utf8_stringn implementation was buggy for non-ascii
characters, since October (41d1d984). Fixed. Will be tested with the
next patch.
* libguile/ports.h (scm_t_port_type_flags, scm_t_ptob_descriptor): Add
flags to ptob descriptors.
* libguile/ports.c (scm_set_port_flush): Set the SCM_PORT_TYPE_HAS_FLUSH
flag here.
(scm_c_make_port_with_encoding): Only add ports to the table if
SCM_PORT_TYPE_HAS_FLUSH is set. Only add finalizers to ports if there
is a free function.
(scm_close_port): Inline scm_i_remove_port here. Only remove from the
weak set if SCM_PORT_TYPE_HAS_FLUSH is set.
(scm_set_port_revealed_x): Add a comment.
* libguile/ports.h (struct scm_t_port): Add a flag for the port encoding
mode: UTF8 or iconv. The iconv descriptors are now in a separate
structure so that we can avoid attaching finalizers to the ports
themselves, in some cases.
* libguile/ports.c (scm_c_make_port_with_encoding): Init the encoding
mode.
(scm_i_remove_port): Adapt to call close_iconv_descriptors.
(finalize_iconv_descriptors, open_iconv_descriptors):
(close_iconv_descriptors): New infrastructure to manage iconv
descriptors.
(scm_i_port_iconv_descriptors): New internal helper.
(scm_i_set_port_encoding_x): Use open_iconv_descriptors, if needed.
(get_iconv_codepoint): Use pt->iconv_descriptors.
(get_codepoint): Check the port encoding mode flags.
* libguile/print.c (display_string_using_iconv): Use
scm_i_port_iconv_descriptors.
(display_string): Use pt->encoding_mode flag.
* libguile/strports.c (st_fill_input): Rename from stfill_buffer, and
remove an unneeded scm_return_first_int.
(st_resize_port): Minor variable renaming.
(st_write): Keep read_pos updated to be the same as write_pos. If we
need to resize, do so only once.
(st_seek): No more need to flush.
(st_truncate): Update read_pos here too.
(scm_mkstrport): No need to flush here.
(scm_strport_to_string): Just call scm_from_stringn; rely on it to
detect the latin1 case.
(scm_make_stptob): No more flush function.
* libguile/weak-set.c (resize_set):
* libguile/weak-table.c (resize_table): Drop the set/table lock while
allocating the new vector. Fixes a bug in which a finalizer could
recursively try to grab the port table lock.
* libguile/read.c (scm_read_array): New internal helper that
calls scm_i_read_array and sets its source property if the
'positions' reader option is set.
(scm_read_string): Set source properties on strings if the 'positions'
reader option is set.
(scm_read_vector, scm_read_srfi4_vector, scm_read_bytevector,
scm_read_guile_bitvector, scm_read_sharp): Add new arguments for the
'line' and 'column' of the first character of the datum being read.
Set source properties if the 'positions' reader option is set.
(scm_read_expression): Pass 'line' and 'column' to scm_read_sharp.
* doc/ref/api-debug.texi (Source Properties): Update manual.
* libguile/read.c (scm_read_string): Return a freshly allocated string
every time, even for empty strings. The motivation is to allow source
properties to be added to all strings. Previously, the shared global
'scm_nullstr' was returned for empty strings. Note that empty strings
still share a common global 'null_stringbuf'.
* test-suite/tests/srfi-13.test (substring/shared): Fix tests to reflect
the fact that empty string literals are no longer guaranteed to be
'eq?' to each other.
* libguile/strings.c (scm_i_substring_copy): When asked to create an
empty substring, use 'scm_i_make_string' to make use of its
optimization for empty strings that reuses the global null_stringbuf.
* libguile/gc-malloc.c (do_realloc, do_calloc, do_gc_malloc)
(do_gc_malloc_atomic, do_gc_realloc, do_gc_free): Wrap the allocators
in helper methods. The non-GC allocators call
scm_gc_register_allocation, and the GC allocators ensure that
gc_malloc returns a nonzero value.
(scm_realloc, scm_calloc): Allow NULL return for malloc(0). It is
permitted by POSIX. Don't wrap in a SCM_SYSCALL; the only possible
errno is ENOMEM.
(scm_gc_malloc_pointerless, scm_gc_malloc, scm_gc_calloc):
(scm_gc_realloc, scm_gc_free, scm_gc_strndump): Use the wrappers.
Don't call the debug-malloc registrations and deregistrations, as it
is neither mandatory nor advised to call scm_gc_free. Fixes
compilation with debug-malloc.
(scm_must_free): Don't scm_malloc_unregister.
* libguile/boolean.c (scm_nil_p): New function.
* libguile/vm-i-scheme.c (nilp, not_nilp):
* libguile/vm-i-system.c (br_if_nil, br_if_not_nil): New instructions.
Renumber other ops.
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Increment.
* module/language/assembly/compile-bytecode.scm (compile-bytecode): Add
support for writing `br-if-nil' and `br-if-not-nil' instructions.
* module/language/assembly/disassemble.scm (code-annotation): Add
`br-if-nil' and `br-if-not-nil' to the list of branch instructions.
* module/language/tree-il/compile-glil.scm: Add `nil?' to
`*primcall-ops*'.
(flatten): Use the new branch instructions for `nil?' conditionals.
* module/language/tree-il/primitives.scm: Add `nil?' to
`*interesting-primitive-names*', `*effect-free-primitives', and
`*effect+exception-free-primitives*'.
* libguile/control.c:
* libguile/continuations.c: Fix for the case in which SCM_ALIGNED is not
defined. Though I wonder, perhaps we should just error out in those
cases.
* configure.ac: Remove checks for <langinfo.h> and <nl_types.h>, and
`nl_langinfo'.
* libguile/i18n.c: Remove #ifdefs for HAVE_LANGINFO_H, HAVE_NL_TYPES_H,
HAVE_NL_ITEM, and HAVE_LANGINFO_CODESET.
(SCM_VALIDATE_OPTIONAL_LOCALE_COPY): Use `SCM_UNBNDP'.
* m4/gnulib-cache.m4 (gl_MODULES): Add `nl_langinfo'.
* module/ice-9/i18n.scm (define-vector-langinfo-mapping): Remove
`defaults' parameter; assume (provided? 'nl-langinfo) is always true.
Update users accordingly.
(define-simple-langinfo-mapping): Likewise.
(define-monetary-langinfo-mapping): Likewise, but do not assume
LOCAL-ITEM and INTL-ITEM are always defined.
This should help with regex portability, as reported in
<http://bugs.gnu.org/10684> for Darwin 8.11.
* m4/gnulib-cache.m4 (gl_MODULES): Add `regex'.
* configure.ac: Remove header checks for regex.h, rxposix.h, and
rx/rxposix.h. Remove check for the `regcomp' function. Remove
definition of `HAVE_REGCOMP'. Define `ENABLE_REGEX'.
* libguile/init.c: Check for `ENABLE_REGEX' instead of `HAVE_REGCOMP'.
* libguile/regex-posix.c: Always include <regex.h>. Remove #ifdefs for
rxposix.h and co.
* doc/ref/posix.texi (Network Databases): Update description of
`EAI_NODATA' to mention that Darwin provides it.
* libguile/net_db.c (scm_getaddrinfo): Likewise.
* test-suite/tests/net-db.test ("getaddrinfo")["wrong service name"]:
Accept `EAI_NODATA' too. Reported by David Fang <fang@csl.cornell.edu>,
see <http://bugs.gnu.org/10684>.
* libguile/load.c (search_path): When the provided 'filename' is an
absolute pathname, perform a 'stat' on that pathname to fill the
'stat_buf'. Previously, 'stat_buf' was left uninitialized in this
case, even though 'scm_primitive_load_path' assumes that 'stat_buf'
will be filled. Update the header comment to explicitly specify that
'stat_buf' will be filled. Also 'goto end' in a few failure cases
instead of replicating its code.
* libguile/foreign.h: Remove comment about the finalizer bit, as I don't
think that is the case any more.
* test-suite/tests/gc.test: Ignore flakiness in the gc-modules test.
* libguile/i18n.c (scm_make_locale): Null out c_locale_name after it's
freed, so it doesn't get freed again. While this only has effect if
USE_GNU_LOCALE_API is unset, the nulling out happens in both cases,
to be consistent and robust.
(scm_nl_langinfo): Free c_result in all switch cases, in particular
P_SIGN_POSN, N_SIGN_POSN, INT_P_SIGN_POSN, and INT_N_SIGN_POSN.
* libguile/vm-engine.h (DEAD): New macro, nulls out a value.
* libguile/vm-i-system.c:
* libguile/vm-i-loader.c:
* libguile/vm-i-scheme.c: Use DEAD when variables become dead.
Later we can #ifdef this out, but I want to give the buildbots a try
with this patch to make sure it's correct.
* libguile/macros.c (scm_init_macros): Add definition of new
syntax-session-id helper.
* module/ice-9/psyntax.scm: Capture a reference to syntax-session-id at
boot time. Uniquify marks and labels using the session id.
* module/ice-9/boot-9.scm: Shunt syntax-session-id off to (system
syntax) once we finished booting.
* module/ice-9/compile-psyntax.scm: Override syntax-session-id when
remaking psyntax to avoid spurious diffs.
* module/ice-9/psyntax-pp.scm: Regenerate.
This reverts commit ad432bc831.
Not all gensyms need to be universally-unique: most of them just need to
be unique within some portion of a Guile session. We'll take a
different tack on this problem in the next commit.
* module/ice-9/local-eval.scm: New module (ice-9 local-eval) which
exports `the-environment', `local-eval', and `local-compile'.
* libguile/debug.c (scm_local_eval): New C function that calls the
Scheme implementation of `local-eval' in (ice-9 local-eval).
* libguile/debug.h (scm_local_eval): Add prototype.
* doc/ref/api-evaluation.texi (Local Evaluation): Add documentation.
* test-suite/tests/eval.test (local evaluation): Add tests.
* test-suite/standalone/test-loose-ends.c (test_scm_local_eval):
Add test.
* module/Makefile.am: Add ice-9/local-eval.scm.
Based on a patch by Mark H Weaver <mhw@netris.org>.
Fixes part of <http://bugs.gnu.org/10520>.
Reported by Bruno Haible <bruno@clisp.org>.
* libguile/vm-i-system.c (COMPILER_BARRIER): New macro.
(halt, return, return_values): Insert compiler barrier after each
assignment to `fp'.
This is a followup to 690a0112e5 ("Remove
the "has finalizer?" bit from pointer objects.")
* libguile/foreign.c (scm_set_pointer_finalizer_x): Leave the type cell
unchanged. Before, `equal?' would break on pointers on which
`set-pointer-finalizer!' had been called.
* test-suite/tests/foreign.test ("make-pointer")["equal? modulo
finalizer (set-pointer-finalizer!)"]: New test.
* libguile/hashtab.c (scm_i_hashtable_print): Use `SCM_UNPACK', not
`SCM2PTR'.
* test-suite/tests/hash.test: Adjust tests that rely on the output of
the printer to just check for the suffix of the hash table's external
representation.