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

15001 commits

Author SHA1 Message Date
Andy Wingo
5077c02d74 avoid allocating finalizer data for symbols in weak sets
* libguile/weak-set.c (symbol_finalizer, register_finalizer): Add a fast
  path for symbols, to avoid allocating the finalizer data.
2012-02-19 20:52:25 +01:00
Andy Wingo
36931b31b5 reimplement guardians in terms of chained finalizers and weak tables
* libguile/guardians.c: Reimplement in terms of chained finalizers and
  weak tables.

* test-suite/tests/guardians.test: Add test for weak mappings added
  after registering an object with a guardian.
2012-02-19 20:52:25 +01:00
Andy Wingo
b7ad674fdc reimplement weak sets using finalizers instead of disappearing links
* libguile/weak-set.c: Reimplement using finalizers.  Removes the need
  for the periodic vacuum_table calls.
2012-02-19 20:52:25 +01:00
Andy Wingo
543328b5ae reimplement weak tables using finalizers instead of disappearing links
* libguile/weak-table.c: Rewrite to use finalizers instead of
  disappearing links.  This will allow weak table associations to
  persist beyond resuscitation of an object by a guardian.  It also
  removes the need to periodically vacuum the table.

* test-suite/tests/guardians.test: Add test for weak maps persisting
  across guardian resuscitations.
2012-02-19 20:52:03 +01:00
Andy Wingo
6978c67339 use the new finalizer helpers
* libguile/foreign.c (scm_set_pointer_finalizer_x)
* libguile/ports.c (finalize_port, scm_c_make_port_with_encoding)
  (open_iconv_descriptors)
* libguile/smob.c (scm_i_new_smob, scm_i_new_double_smob)
* libguile/struct.c (scm_i_alloc_struct)
* libguile/weak-set.c (weak_gc_finalizer)
  (scm_c_register_weak_gc_callback)
* libguile/weak-table.c (scm_c_register_weak_gc_callback)
  (weak_gc_finalizer)
* libguile/numbers.c (make_bignum): Use the new API.
2012-02-19 20:46:14 +01:00
Andy Wingo
6e9ec86dc0 add scm_i_set_finalizer, scm_i_add_finalizer, scm_i_add_resuscitator
* libguile/finalizers.h:
* libguile/finalizers.c: New files.

* libguile.h:
* libguile/Makefile.am: Add to build.
2012-02-19 20:46:14 +01:00
Andy Wingo
7932759fc7 better hysteresis in weak-set, weak-table
* libguile/weak-set.c:
* libguile/weak-table.c: Attempt to avoid bouncing between sizes when
  growing the vector causes elements to be removed from the set/table.
2012-02-19 20:46:14 +01:00
Andy Wingo
917b0e72f7 tune default hash table sizes
* libguile/modules.c: In my current image, there are 1790 bindings in
  the root module, which tips over to the next hash vector size, so
  declare that to prevent rehashing.
* libguile/srcprop.c (scm_init_srcprop): Don't preallocate a big
  source_whash table, as we might not need it (if everything is
  compiled, for example).
* module/ice-9/boot-9.scm (make-module): Don't preall-cate big hash
  tables for imported bindings.  Instead trust that resizing works
  correctly.
2012-02-19 20:46:14 +01:00
Andy Wingo
3753e22736 move revealed-count mechanism to fports.c
* libguile/fports.c (scm_revealed_count, scm_port_revealed)
  (scm_set_port_revealed_x, scm_adjust_port_revealed_x): Move these APIs
  here, and only operate on fports.  To keep revealed ports alive, now
  we will just keep them in a data structure that the GC knows about --
  a static list.

* libguile/fports.h: Add revealed count to scm_t_fport, and move decls
  of revealed-count functions here.

* libguile/ports.h:
* libguile/ports.c: Adapt to change.  Remove SCM_REVEALED and
  SCM_SETREVEALED; since they only apply to fports now, keeping them
  around would be inviting type errors.
  (finalize_port): We don't need to worry about resuscitating ports
  here.

* libguile/init.c: Use the scm_set_port_revealed_x function to set the
  revealed counts on stream ports.
2012-02-19 13:30:30 +01:00
Andy Wingo
bc1bc9e320 ice-9/poll optimization
* module/ice-9/poll.scm (poll-set-add!): Use fileno instead of
  port->fdes, to avoid manipulating revealed counts.
2012-02-19 13:30:30 +01:00
Andy Wingo
8dfb7bbfd9 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-17 12:11:35 +01:00
Andy Wingo
6a97b1f93a install pthread_atfork handlers for guile's static mutexen
* libguile/async.c:
* libguile/deprecation.c:
* libguile/fluids.c:
* libguile/gc.c:
* libguile/instructions.c:
* libguile/ports.c:
* libguile/posix.c:
* libguile/strings.c:
* libguile/threads.c: Use the SCM_PTHREAD_ATFORK_LOCK_STATIC_MUTEX
  mechanism to lock a number of static mutexen.
2012-02-17 12:11:14 +01:00
Andy Wingo
2f745b64a1 add pthread_atfork helpers to our threading shims
* libguile/null-threads.h:
* libguile/pthread-threads.h (SCM_DEFINE_ATFORK_HANDLERS_FOR_MUTEX)
  (scm_i_pthread_atfork): Define a pthread_atfork shim, and a helper to
  declare procedures to lock and unlock a mutex.

* libguile/threads.h (SCM_PTHREAD_ATFORK_LOCK_STATIC_MUTEX): New macro,
  causes the snarfer to emit a pthread_atfork call to lock a mutex, if
  threads are enabled.
2012-02-17 12:09:28 +01:00
Andy Wingo
f609480611 with a threaded guile, lock weak sets and tables during a fork
* libguile/weak-set.c (make_weak_set):
* libguile/weak-table.c (make_weak_table): If we have a threaded Guile,
* keep a weak set (table) of weak sets (tables).  Use this and the
  pthread_atfork mechanism to lock and unlock weak sets and weak tables
  during a fork().

* libguile/weak-set.h (scm_weak_set_prehistory): New internal API.
* libguile/init.c: Add call to scm_weak_set_prehistory().
2012-02-17 12:09:28 +01:00
Andy Wingo
58565208bd Merge remote-tracking branch 'local-2.0/stable-2.0'
Conflicts:
	libguile/read.c
	libguile/srcprop.c
	module/ice-9/psyntax-pp.scm
2012-02-17 10:21:50 +01:00
Andy Wingo
2c84211e63 remove deprecated features test
* test-suite/tests/procprop.test ("procedure-arity"): Remove a test of
  deprecated features.
2012-02-15 23:40:42 +01:00
Andy Wingo
2988685d84 Merge remote-tracking branch 'origin/stable-2.0'
Conflicts:
	module/ice-9/psyntax-pp.scm
2012-02-15 23:04:53 +01:00
Mark H Weaver
cac24946da Add tests to verify that 'read' sets source properties when appropriate
* test-suite/tests/srcprop.test (source properties): Add tests.
2012-02-15 12:23:12 -05:00
Mark H Weaver
38f190749d Add support for source properties on non-immediate numbers
* libguile/read.c (scm_read_number): Set source properties on
  non-immediate numbers if the 'positions' reader option is set.

* doc/ref/api-debug.texi (Source Properties): Update manual.
2012-02-15 11:47:31 -05:00
Mark H Weaver
32fbc38fbb psyntax: access source properties for all supported objects
* module/ice-9/psyntax.scm (decorate-source): Set source properties on
  any object that satisfies 'supports-source-properties?'.  Previously
  we used 'pair?' as the predicate.

  (source-annotation): Apply 'source-properties' to _any_ kind of source
  expression, where previously only pairs were queried.  If the argument
  is a syntax-object, apply the source-properties to the syntax-object's
  expression.

  In the peculiar case of a syntax-object whose expression is also a
  syntax-object: previously we would iterate, but with this commit we
  now call 'syntax-object-expression' only once.

* module/ice-9/psyntax-pp.scm: Regenerate.
2012-02-15 11:24:43 -05:00
Mark H Weaver
76b9bac565 Add 'supports-source-properties?' predicate
* libguile/srcprop.c (scm_supports_source_properties_p): New procedure.
  (supports_source_props): New static C function.

* libguile/srcprop.h (scm_supports_source_properties_p): Add prototype.

* doc/ref/api-debug.texi (Source Properties): Add documentation.
2012-02-15 11:23:27 -05:00
Andy Wingo
df65503101 Merge remote-tracking branch 'origin/stable-2.0' 2012-02-15 11:43:32 +01:00
Mark H Weaver
fb3a112122 Relax validation of source property accessors
* libguile/srcprop.c (scm_source_properties, scm_source_property,
  scm_i_has_source_properties): Relax validation to allow _any_ object
  to be queried for source properties.
2012-02-15 03:23:42 -05:00
Mark H Weaver
bbd1281ae5 syntax-violation: prefer 'subform' for source info, with 'form' as fallback
* module/ice-9/psyntax.scm (syntax-violation): Look for source
  properties of 'subform' first.  If 'subform' has none, 'form' is used.
  Previously, the source information of 'form' was used unless 'form'
  _itself_ was '#f', in which case 'subform' was used.

* module/ice-9/psyntax-pp.scm: Regenerate.
2012-02-15 00:41:24 -05:00
Mark H Weaver
30398e94f9 Fix psyntax bugs that would cause bad source annotations
* module/ice-9/psyntax.scm (rebuild-macro-output): Fix two bugs that
  would cause bogus source properties to be added to vectors and
  macro-introduced syntax objects.  These bugs were masked by the
  limitation that only pairs can be decorated with source properties.
  Due to a typo, each vector in the macro output was decorated using the
  vector itself as its source.  Due to accidental variable capture, each
  syntax-object introduced by the macro had its expression decorated
  with its own wrap-subst.

* module/ice-9/psyntax-pp.scm: Regenerate.
2012-02-15 00:17:18 -05:00
Mark H Weaver
db24306887 Fix typo in comment in message.scm: 'know' to 'known' warning types
* module/system/base/message.scm (%warning-types): Fix typo.
2012-02-14 23:39:22 -05:00
Andy Wingo
5a771d5f51 better handling for exceptions in close-port and port finalizers
* 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:47:26 +01:00
Andy Wingo
eec3a50867 web server: fix spurious warning
* module/web/server.scm (sanitize-response): Quick fix to the
  304-has-no-body sanitizer.
2012-02-14 17:32:25 +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
Mark H Weaver
7cc8ef6235 Fix manual: scm_foreign_to_bytevector to scm_pointer_to_bytevector
* doc/ref/api-foreign.texi (Void Pointers and Byte Access): Fix outdated
  function name: scm_foreign_to_bytevector to scm_pointer_to_bytevector.
2012-02-12 17:05:28 -05: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