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

14982 commits

Author SHA1 Message Date
Andy Wingo
6fa75029fa web server: use CLOEXEC
* module/web/server/http.scm (http-read): Pass SOCK_CLOEXEC to
  `accept'.
2012-02-14 22:47:15 +01:00
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
12087939ed Merge remote-tracking branch 'origin/stable-2.0' 2012-02-12 13:32:56 +01:00
Andy Wingo
164a78b355 web server: do not provide a response body where it is not permitted
* module/web/response.scm (response-must-not-include-body?): New
  function.

* doc/ref/web.texi: Doc the function.

* module/web/server.scm (sanitize-response): Error if we have a body,
  but the response type does not permit a body.  If we are responding to
  a HEAD request, silently drop the body.
2012-02-12 13:29:19 +01:00
Andy Wingo
e4c785f5df Merge remote-tracking branch 'origin/stable-2.0' 2012-02-11 18:28:37 +01:00
Andy Wingo
2263ccb53e web server: print backtrace on errors when run in batch mode
* module/web/server.scm (read-client, handle-request, write-client):
  When run in batch mode, give a full backtrace for errors.
2012-02-11 18:27:56 +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
e7cf0457d7 Support => within case, and improve error messages for cond and case
* module/ice-9/boot-9.scm (cond, case): Reimplement using syntax-case,
  with improved error messages and support for '=>' within 'case' as
  mandated by the R7RS.  Add warnings for duplicate case datums and
  case datums that cannot be meaningfully compared using 'eqv?'.

* module/system/base/message.scm (%warning-types): Add 'bad-case-datum'
  and 'duplicate-case-datum' warning types.

* test-suite/tests/syntax.test (cond, case): Update tests to reflect
  improved error reporting.  Add tests for '=>' within 'case'.

* test-suite/tests/tree-il.test (partial evaluation): Update tests to
  reflect changes in how 'case' is expanded.

* doc/ref/api-control.texi (Conditionals): Document '=>' within 'case'.
2012-02-08 16:27:48 -05: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
Ludovic Courtès
13fb25ba0c i18n: Skips ~h `format' tests when digit grouping info is missing.
* test-suite/tests/i18n.test ("format ~h"): Skip tests when
  `locale-digit-grouping' returns '().
2012-02-04 23:38:47 +01:00
Andy Wingo
bc02028b52 fix check for when libc already has clock_gettime / clock_getcpuclockid
* acinclude.m4 (gl_CLOCK_TIME): If both clock_gettime and
  clock_getcpuclockid are present without -lrt and -lposix4, don't add
  any libs to LIB_CLOCK_GETTIME.  Thanks to taylanbarirli@gmail.com.
2012-02-04 00:10:14 +01:00
Bake Timmons
5f6ffd6652 Improve consistency of definitions of C functions in manual.
* doc/ref/api-compound.texi
* doc/ref/api-evaluation.texi
* doc/ref/api-foreign.texi
* doc/ref/api-io.texi
* doc/ref/posix.texi
* doc/ref/srfi-modules.texi: Add missing parentheses and commas to definitions
  of C functions.

* doc/ref/api-data.texi: Change from @deffn to @deftypefn for C function
  with arguments not of SCM type.
2012-02-04 00:10:14 +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
Bake Timmons
df0a100250 Make notation for Scheme repeated arguments more consistent in manual.
* doc/ref/api-compound.texi
* doc/ref/api-control.texi
* doc/ref/api-data.texi
* doc/ref/api-debug.texi
* doc/ref/api-evaluation.texi
* doc/ref/api-macros.texi
* doc/ref/api-memory.texi
* doc/ref/api-modules.texi
* doc/ref/api-procedures.texi
* doc/ref/api-regex.texi
* doc/ref/api-scheduling.texi
* doc/ref/api-utility.texi
* doc/ref/goops.texi
* doc/ref/match.texi
* doc/ref/misc-modules.texi
* doc/ref/posix.texi
* doc/ref/r6rs.texi
* doc/ref/scheme-using.texi
* doc/ref/srfi-modules.texi
* doc/ref/sxml-match.texi: Make notation for Scheme repeated arguments more
  consistent in manual.
2012-02-04 00:10:13 +01:00
Ludovic Courtès
e7f7691f5f i18n: Provide default values for when Gnulib has no replacement.
This reverts parts of a0919aefee ("i18n:
Use Gnulib's `nl_langinfo' module.").

* module/ice-9/i18n.scm (define-simple-langinfo-mapping): Re-add
  `default' parameter, and update users accordingly.
2012-02-03 20:11:00 +01:00
Ludovic Courtès
b4af80a423 Augment -Wformat' analysis with support for ~:h'.
* module/language/tree-il/analyze.scm (format-string-argument-count):
  Add support for ~h.

* test-suite/tests/tree-il.test ("warnings")["format"]("~h", "~:h with
  locale object", "~:h without locale object"): New tests.
2012-02-03 16:52:15 +01:00
Ludovic Courtès
afd08fdf87 format: Add specifier ~h for localized number output.
* doc/ref/misc-modules.texi (Formatted Output): Document ~h.  Recommend
  use of ~h instead of ~:d.

* module/ice-9/format.scm (format): Add support for ~h.

* test-suite/tests/format.test ("~h localized number"): New test prefix.

* test-suite/tests/i18n.test (%american-english-locale-name,
  %american-english-locale): New variables.
  (under-american-english-locale-or-unresolved): New procedure.
  ("format ~h"): New test prefix.
2012-02-03 16:35:06 +01:00
Ludovic Courtès
c76fdf69a8 i18n: Add a couple of tests for `monetary-amount->locale-string'.
* test-suite/tests/i18n.test ("monetary-amount->locale-string"): New
  test prefix.
2012-02-03 14:31:17 +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
Ludovic Courtès
6f63f118ef tests: Work around erroneous tr_TR locale in Darwin 8.
* test-suite/tests/i18n.test (under-turkish-utf8-locale-or-unresolved):
  Add exception for Darwin 8.  Reported by David Fang <fang@csl.cornell.edu>,
  see <http://bugs.gnu.org/10684>.
2012-02-03 10:17:12 +01:00
Mike Gran
ec97a06f86 Update srfi-14 test for Unicode 6.1
Some Latin-1 symbols have been reclassified as punctuation

* test-suite/tests/srfi-14.test: updated
2012-02-02 19:50:07 -08: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
Andy Wingo
7fb9c4aff2 revert r5rs changes
* doc/r5rs/r5rs.texi: Reverts the recent changes to r5rs.texi.
2012-02-02 23:41:29 +01:00