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

7279 commits

Author SHA1 Message Date
Andy Wingo
d7bbda6fd7 optional flags arg to scm_accept, which uses accept4
* libguile/socket.c (scm_accept): Take another argument, "flags".  This
  dispatches to accept4, if it's available, to possibly set the CLOEXEC
  flag on the accepted port.
2012-02-14 22:47:15 +01:00
Andy Wingo
f503c1d6be primitive-move->fdes preserves CLOEXEC flag
* libguile/ioext.c (scm_primitive_move_to_fdes): Use dup3 to preserve
  the CLOEXEC flag, if appropriate.
2012-02-14 22:47:15 +01:00
Andy Wingo
7565b9fc09 add file-port-close-on-exec?; popen takes advantage of it.
* libguile/fports.c (scm_i_evict_port): Use F_DUPFD_CLOEXEC if the port
  is CLOEXEC.
  (scm_file_port_close_on_exec_p): New interface.
  (scm_i_fdes_to_port): Use F_GETFD on the fd to see if it is cloexec,
  and if it is, mark it in the scm_t_fport.  That way popen.scm won't
  have to do anything about it.

* module/ice-9/popen.scm (ensure-fdes): No need for false-if-exception
  here.
  (open-process): Rework the port-for-each call to not bother with file
  descriptors that are CLOEXEC.
2012-02-14 22:47:15 +01:00
Andy Wingo
a01a9308f0 fcntl: support F_DUPFD_CLOEXEC and O_CLOEXEC.
* libguile/filesys.c (scm_fcntl): Document F_DUPFD_CLOEXEC.
  (scm_init_filesys): Define O_CLOEXEC and F_DUPFD_CLOEXEC.
2012-02-14 22:47:15 +01:00
Andy Wingo
86150ed040 wrap iconv_open / iconv_close with a lock to help in thread/fork issues
* libguile/bytevectors.c (STRING_TO_UTF, scm_string_to_utf8)
  (UTF_TO_STRING):
* libguile/ports.c (open_iconv_descriptors, close_iconv_descriptors):
* libguile/strings.c (scm_from_stringn, scm_to_stringn): Wrap operations
  that acquire and destroy iconv contexts with a mutex.  While iconv is
  threadsafe, internally it uses a lock, and we need to make sure when
  we fork() that no one has that lock -- so we surround it with another
  one.  Gross.
2012-02-14 22:47:15 +01:00
Andy Wingo
7329a5dba1 use scm_c_atfork_lock_static_mutex for guile's static mutexen
* libguile/async.c (scm_init_async):
* libguile/deprecation.c (scm_init_deprecation):
* libguile/fluids.c (scm_init_fluids):
* libguile/gc.c (scm_init_gc):
* libguile/instructions.c (scm_bootstrap_instructions):
* libguile/ports.c (scm_init_ports):
* libguile/posix.c (scm_init_posix):
* libguile/strings.c (string_get_handle):
* libguile/threads.c (scm_init_threads): Use the atfork mutex mechanism
  to lock a number of static mutexen.
2012-02-14 22:47:14 +01:00
Andy Wingo
585eb4f702 add scm_c_atfork_lock_static_mutex
* libguile/posix.h:
* libguile/posix.c (scm_c_atfork_lock_static_mutex): New interface.
2012-02-14 22:47:14 +01:00
Andy Wingo
9f6ac5d71d add atfork interface
* libguile/posix.h:
* libguile/posix.c (scm_c_atfork): New interface.
  (scm_fork): Wrap fork calls in atfork pre/post invocations, and
  finally a GC_call_with_alloc_lock.  It's an attempt to grab the
  interesting mutexes in Guile.

* libguile/weak-set.c (make_weak_set):
* libguile/weak-table.c (make_weak_table): Use atfork mechanism to lock
  and unlock weak sets and weak tables during a fork(), in such a way
  that does not prevent those tables from being gc'd.
2012-02-14 22:47:14 +01:00
Andy Wingo
981bace7e4 fix a race (one of many) relating to close-port
* libguile/ports.c (scm_close_port): Remove the port from the weak
  set before nulling out the stream.  Fixes a case in which
  port-for-each traversers can see a NULL stream.

better handling for exceptions in port free / close vmethods

* 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.
2012-02-14 22:46:55 +01:00
Andy Wingo
098818a165 scm_from_stringn utf8 optimization
* libguile/strings.c (scm_from_stringn): Optimize scm_from_stringn for
  utf-8.
2012-02-14 14:24:32 +01:00
Andy Wingo
33aadcab8a fix buggy scm_from_utf8_stringn (!)
* 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.
2012-02-14 14:24:32 +01:00
Andy Wingo
03a2eeb0cc ports: avoid adding port table entries and finalizers if possible
* 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.
2012-02-14 14:10:53 +01:00
Andy Wingo
6c98257f2e refactor port encoding modes: utf-8 and iconv
* 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.
2012-02-14 14:10:53 +01:00
Andy Wingo
ca2ec018f2 string ports simplification
* 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.
2012-02-14 00:11:39 +01:00
Andy Wingo
aac980de43 weaks: move an allocation outside a critical section
* 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.
2012-02-13 15:29:21 +01:00
Andy Wingo
a41bed83ab Merge remote-tracking branch 'origin/stable-2.0'
Conflicts:
	libguile/read.c
	test-suite/tests/tree-il.test
2012-02-11 18:14:48 +01:00
Andy Wingo
c2c3bddb1d more efficient scm_string_to_utf8, scm_string_to_utf32
* libguile/bytevectors.c (scm_string_to_utf8): More efficient
  implementation.
  (scm_string_to_utf32): Likewise.
2012-02-10 13:42:15 +01:00
Andy Wingo
e3d4597469 more efficient scm_to_utf8_stringn, scm_to_utf32_stringn
* libguile/strings.c (scm_to_utf8_stringn): More efficient
  implementation than calling scm_to_stringn.
  (scm_to_utf32_stringn): Likewise.
2012-02-10 13:42:15 +01:00
Mark H Weaver
b131b233ff Add source properties to many more types of data
* 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.
2012-02-08 16:27:41 -05:00
Mark H Weaver
043850d984 Unoptimize 'read' to return freshly allocated empty strings
* 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.
2012-02-08 16:27:32 -05:00
Mark H Weaver
d5b75b6c80 Optimize empty substring case of scm_i_substring_copy
* 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.
2012-02-08 15:29:10 -05:00
Mark H Weaver
d6cb0203cb Add and use maybe_annotate_source helper in read.c
* libguile/read.c (maybe_annotate_source): New static helper function.
  (scm_read_sexp, scm_read_quote, scm_read_syntax): Use
  'maybe_annotate_source'.
2012-02-08 15:15:14 -05:00
Mark H Weaver
cfd15439b2 Remove inline and register attributes from read.c
* libguile/read.c: Remove all 'inline' and 'register' attributes.
2012-02-08 15:14:32 -05:00
Mark H Weaver
58996e37bb Remove incorrect comment in read.c
* libguile/read.c (scm_read_sharp): Remove incorrect comment that
  claims that scm_read_boolean might return a SRFI-4 vector.
2012-02-08 15:14:26 -05:00
Andy Wingo
bbabae997d Merge remote-tracking branch 'origin/stable-2.0' 2012-02-08 12:25:10 +01:00
Andy Wingo
4fbbf346a6 i18: avoid freelocale (NULL)
* libguile/i18n.c (smob_locale_free): Don't freelocale (NULL).
2012-02-08 12:20:47 +01:00
Andy Wingo
0858753e82 Merge remote-tracking branch 'origin/stable-2.0'
Conflicts:
	GUILE-VERSION
	libguile/gc-malloc.c
	libguile/ports.c
2012-02-08 11:48:08 +01:00
Andy Wingo
817307ccac Fix --enable-debug-malloc
* 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.
2012-02-05 15:55:37 +01:00
Andy Wingo
5556c17511 fix compilation of control.c, continuations.c when SCM_ALIGNED is not defined
* 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.
2012-02-04 00:10:14 +01:00
Ludovic Courtès
a0919aefee i18n: Use Gnulib's `nl_langinfo' module.
* 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.
2012-02-03 14:14:14 +01:00
Ludovic Courtès
eb4a14ed47 Use Gnulib's `regex' module.
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.
2012-02-03 10:51:46 +01:00
Ludovic Courtès
1ba05158eb tests: Have `getaddrinfo' test work for Darwin 8.
* 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>.
2012-02-03 10:30:52 +01:00
Mark H Weaver
1d00abb04f Implement scm_to_pointer
* libguile/foreign.c, libguile/foreign.h (scm_to_pointer):
  New C function.

* test-suite/standalone/test-loose-ends.c: Add test.
2012-02-02 18:34:52 -05:00
Ludovic Courtès
bb796c4630 Fix `SCM_I_ERROR' definition for MinGW without networking.
* libguile/error.c (SCM_I_ERROR)[__MINGW32__]: Conditionalize on
  `HAVE_NETWORKING'.
2012-02-02 21:58:04 +01:00
Bake Timmons
b7e64f8b26 Improve the usage of variable names in C docstrings.
* libguile/alist.c:
* libguile/array-map.c:
* libguile/arrays.c:
* libguile/bitvectors.c:
* libguile/filesys.c:
* libguile/foreign.c:
* libguile/generalized-arrays.c:
* libguile/hashtab.c:
* libguile/ioext.c:
* libguile/load.c:
* libguile/numbers.c:
* libguile/ports.c:
* libguile/posix.c:
* libguile/print.c:
* libguile/procprop.c:
* libguile/promises.c:
* libguile/simpos.c:
* libguile/socket.c:
* libguile/srfi-1.c:
* libguile/srfi-13.c:
* libguile/srfi-14.c:
* libguile/stacks.c:
* libguile/stime.c:
* libguile/strings.c:
* libguile/struct.c:
* libguile/symbols.c:
* libguile/threads.c:
* libguile/weak-table.c:
* libguile/weak-vector.c: Make the variable names in the C docstrings more
  consistent.  Replace a few instances of @var with @code when appropriate.
2012-02-02 12:22:10 +01:00
Mike Gran
bf8d845468 Update srfi-14 character sets to Unicode 6.1
* libguile/srfi-14.i.c (cs_lower_case_ranges, cs_lower_case)
  (cs_upper_case_ranges, cs_upper_case, cs_letter_ranges, cs_letter)
  (cs_digit_ranges, cs_digit, cs_letter_plus_digit_ranges, cs_letter_plus_digit)
  (cs_graphic_ranges, cs_graphic, cs_printing_ranges, cs_printing)
  (cs_punctuation_ranges, cs_punctuation, cs_symbol_ranges, cs_symbol)
  (cs_designated_ranges, cs_designated): modified
* doc/ref/api-data.texi: modified
2012-02-01 19:51:35 -08:00
Mark H Weaver
c12da2be81 Fix search_path to fill stat_buf when given an absolute pathname
* 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.
2012-02-01 20:58:55 -05:00
Andy Wingo
52de2ab45a leniency in the "unused modules are removed" gc.test
* 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.
2012-02-02 00:10:11 +01:00
Andy Wingo
0aed71aa51 Revert "add SCM_HEAP_OBJECT_BASE"
This reverts commit 47ed8656db.

Conflicts:

	libguile/foreign.c
2012-01-31 22:58:24 +01:00
Andy Wingo
dfadcf85cb Merge remote-tracking branch 'origin/stable-2.0'
Conflicts:
	libguile/debug.h
	module/ice-9/psyntax-pp.scm
	module/ice-9/psyntax.scm
	module/language/tree-il/peval.scm
	module/language/tree-il/primitives.scm
2012-01-30 20:27:35 +01:00
Andy Wingo
252acfe8e7 Merge commit '3d51e57cfb'
Conflicts:
	libguile/foreign.c
	libguile/hashtab.c
	module/ice-9/psyntax-pp.scm
	module/language/tree-il/compile-glil.scm
2012-01-30 18:52:46 +01:00
Andy Wingo
855db1905d Merge commit '9b0975f1dc'
Conflicts:
	libguile/foreign.c
	module/ice-9/psyntax-pp.scm
	module/ice-9/psyntax.scm
2012-01-30 18:25:07 +01:00
Andy Wingo
e1fbe716e8 fix hook invocation during thread guilification
* libguile/gc.c (run_before_gc_c_hook): Don't run pre-GC hooks from a
  thread that is in the process of guilification.
2012-01-30 17:06:37 +01:00
Mark H Weaver
07c2ca0f0d Rename scm_call_varargs -> scm_call
* libguile/eval.c, libguile/eval.h, doc/ref/api-evaluation.texi,
  test-suite/standalone/test-loose-ends.c, NEWS: Rename
  scm_call_varargs -> scm_call

Suggested by Ludovic Courtès <ludo@gnu.org>
2012-01-30 11:02:29 -05:00
Mark H Weaver
741b8a2300 Implement scm_call_varargs and scm_call_{7,8,9}
* libguile/eval.c (scm_call_7, scm_call_8, scm_call_9,
  scm_call_varargs): New functions.

* libguile/eval.h: Add prototypes.

* doc/ref/api-evaluation.texi: Add documentation.

* test-suite/standalone/test-loose-ends.c: Add tests.

* NEWS: Add news entry.
2012-01-30 10:27:44 -05:00
Andy Wingo
a18e13a57c Revert "vm-i-scheme.c slight refactor"
This reverts commit c0e4449908.

This refactor was needed for the introduction of DEAD(), which does not
appear to have been necessary.
2012-01-29 22:31:49 +01:00
Andy Wingo
a39b116f00 Revert "attempt to clear stale references on VM C stack"
This reverts commit 04b2d77354.

Since it wasn't fixing the "lexical vars are collectable" test, it added
complexity with no benefit.
2012-01-29 22:30:21 +01:00
Ludovic Courtès
5e80f2cea3 Revert "Work around instruction reordering on SPARC and HPPA in the VM."
This reverts commit 2b264d7e4f, which is
unnecessary after commit f5ea0499a4
("Build with `-fno-strict-aliasing' when available.").
2012-01-29 22:18:15 +01:00
Chris K. Jester-Young
e22ad42bdb Fix double-free error on non-GNU systems.
* 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.
2012-01-28 15:23:16 -05:00
Andy Wingo
04b2d77354 attempt to clear stale references on VM C stack
* 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.
2012-01-27 19:34:19 +01:00