[Guile-commits] branch master updated (1e51ffa -> 8157c2a)

2017-03-07 Thread Andy Wingo
wingo pushed a change to branch master
in repository guile.

  from  1e51ffa   Fix documentation build
   new  8157c2a   Fix new thread-local fluids test

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "adds" were already present in the repository and have only
been added to this reference.


Summary of changes:
 test-suite/tests/fluids.test | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)



[Guile-commits] 01/01: Fix new thread-local fluids test

2017-03-07 Thread Andy Wingo
wingo pushed a commit to branch master
in repository guile.

commit 8157c2a3acc61b561903957f69e7e83163d5a1b5
Author: Andy Wingo 
Date:   Tue Mar 7 21:35:52 2017 +0100

Fix new thread-local fluids test

* test-suite/tests/fluids.test ("dynamic states"): Fix test.
---
 test-suite/tests/fluids.test | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/test-suite/tests/fluids.test b/test-suite/tests/fluids.test
index 9eca6f2..a5ca885 100644
--- a/test-suite/tests/fluids.test
+++ b/test-suite/tests/fluids.test
@@ -265,5 +265,5 @@
   (pass-if "exception handler not captured"
 (let ((state (catch #t (lambda () (current-dynamic-state)) error)))
   (catch #t
-(lambda () (with-dynamic-state state (/ 1 0)))
+(lambda () (with-dynamic-state state (lambda () (/ 1 0
 (lambda _ #t)



[Guile-commits] branch master updated (fb8c91a -> 1e51ffa)

2017-03-07 Thread Andy Wingo
wingo pushed a change to branch master
in repository guile.

  from  fb8c91a   Add thread local fluids
   new  1e51ffa   Fix documentation build

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "adds" were already present in the repository and have only
been added to this reference.


Summary of changes:
 doc/ref/api-control.texi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)



[Guile-commits] 01/01: Fix documentation build

2017-03-07 Thread Andy Wingo
wingo pushed a commit to branch master
in repository guile.

commit 1e51ffa63422c28572aa4ab1a5b3924d54614485
Author: Andy Wingo 
Date:   Tue Mar 7 21:34:01 2017 +0100

Fix documentation build

* doc/ref/api-control.texi (Fluids and Dynamic States): Fix link.
---
 doc/ref/api-control.texi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc/ref/api-control.texi b/doc/ref/api-control.texi
index b0c9e72..2d696ea 100644
--- a/doc/ref/api-control.texi
+++ b/doc/ref/api-control.texi
@@ -1727,7 +1727,7 @@ used for testing whether an object is actually a fluid.  
The values
 stored in a fluid can be accessed with @code{fluid-ref} and
 @code{fluid-set!}.
 
-@xref{Thread-Local Variables}, for further notes on fluids, threads,
+@xref{Thread Local Variables}, for further notes on fluids, threads,
 parameters, and dynamic states.
 
 @deffn {Scheme Procedure} make-fluid [dflt]



[Guile-commits] 01/01: Add thread local fluids

2017-03-07 Thread Andy Wingo
wingo pushed a commit to branch master
in repository guile.

commit fb8c91a35c0a1c357aab96a6721a8b65c93368b0
Author: Andy Wingo 
Date:   Tue Mar 7 20:57:59 2017 +0100

Add thread local fluids

* libguile/fluids.h (struct scm_dynamic_state): Add thread_local_values
  table.  Thread locals are flushed to a separate thread-local table.
  The references are strong references since the table never escapes the
  thread.
  (scm_make_thread_local_fluid, scm_fluid_thread_local_p): New
  functions.
* libguile/fluids.c (FLUID_F_THREAD_LOCAL):
  (SCM_I_FLUID_THREAD_LOCAL_P): New macros.
  (restore_dynamic_state): Add comment about precondition.
  (save_dynamic_state): Flush thread locals.
  (scm_i_fluid_print): Print thread locals nicely.
  (new_fluid): Add flags arg.
  (scm_make_fluid, scm_make_fluid_with_default, scm_make_unbound_fluid):
  Adapt.
  (scm_make_thread_local_fluid, scm_fluid_thread_local_p): New
  functions.
  (fluid_set_x): Special flushing logic for thread-locals.
  (fluid_ref): Special cache miss logic for thread locals.
* libguile/stacks.c (scm_init_stacks):
* libguile/throw.c (scm_init_throw): %stacks and %exception-handler are
  thread-locals.
* libguile/threads.c (guilify_self_2): Init thread locals table.
* test-suite/tests/fluids.test ("dynamic states"): Add test.
* doc/ref/api-control.texi (Fluids and Dynamic States): Add link to
  Thread-Local Variables.
* doc/ref/api-scheduling.texi (Thread Local Variables): Update with real
  thread-locals.
* NEWS: Update.
---
 NEWS |  7 
 doc/ref/api-control.texi |  3 ++
 doc/ref/api-scheduling.texi  | 54 ---
 libguile/fluids.c| 77 ++--
 libguile/fluids.h|  3 ++
 libguile/stacks.c|  2 +-
 libguile/threads.c   |  1 +
 libguile/throw.c |  2 +-
 test-suite/tests/fluids.test |  8 -
 9 files changed, 125 insertions(+), 32 deletions(-)

diff --git a/NEWS b/NEWS
index 96cc959..d70397e 100644
--- a/NEWS
+++ b/NEWS
@@ -23,6 +23,13 @@ guile2.2, guile-2, guile2, and then guile.  The found prefix 
is also
 applied to guild, guile-config, and the like.  Thanks to Freja Nordsiek
 for this work.
 
+** Add thread-local fluids
+
+Guile now has support for fluids whose values are not captured by
+`current-dynamic-state' and not inheritied by child threads, and thus
+are local to the kernel thread they run on.  See "Thread-Local
+Variables" in the manual, for more.
+
 * Bug fixes
 
 ** Fix type inference when multiplying flonum with complex
diff --git a/doc/ref/api-control.texi b/doc/ref/api-control.texi
index 77d98b4..b0c9e72 100644
--- a/doc/ref/api-control.texi
+++ b/doc/ref/api-control.texi
@@ -1727,6 +1727,9 @@ used for testing whether an object is actually a fluid.  
The values
 stored in a fluid can be accessed with @code{fluid-ref} and
 @code{fluid-set!}.
 
+@xref{Thread-Local Variables}, for further notes on fluids, threads,
+parameters, and dynamic states.
+
 @deffn {Scheme Procedure} make-fluid [dflt]
 @deffnx {C Function} scm_make_fluid ()
 @deffnx {C Function} scm_make_fluid_with_default (dflt)
diff --git a/doc/ref/api-scheduling.texi b/doc/ref/api-scheduling.texi
index ff8473a..7b39a03 100644
--- a/doc/ref/api-scheduling.texi
+++ b/doc/ref/api-scheduling.texi
@@ -9,7 +9,7 @@
 
 @menu
 * Threads:: Multiple threads of execution.
-* Thread Local Variables::  Guile doesn't really have these.
+* Thread Local Variables::  Some fluids are thread-local.
 * Asyncs::  Asynchronous interrupts.
 * Atomics:: Atomic references.
 * Mutexes and Condition Variables:: Synchronization primitives.
@@ -169,9 +169,7 @@ information.
 @subsection Thread-Local Variables
 
 Sometimes you want to establish a variable binding that is only valid
-for a given thread: a ``thread-local variable''.  Guile doesn't really
-have this facility, but what it does have can work well for most use
-cases we know about.
+for a given thread: a ``thread-local variable''.
 
 You would think that fluids or parameters would be Guile's answer for
 thread-local variables, since establishing a new fluid binding doesn't
@@ -191,26 +189,44 @@ bindings comes from a desire to isolate a binding from 
its setting in
 unrelated threads, then fluids and parameters apply nicely.
 
 On the other hand, if your use case is to prevent concurrent access to a
-value from multiple threads, then using fluids or parameters is not
-appropriate.  In this case, our current suggestion is to use weak hash
-tables or object properties whose keys are thread objects.  For example:
+value from multiple threads, then using vanilla fluids or parameters is
+not appropriate.  For this purpose, Guile has @dfn{thread-local fluids}.
+A fluid created with @code{make-thread-local-fluid} won't be captured 

[Guile-commits] branch master updated (84a740d -> fb8c91a)

2017-03-07 Thread Andy Wingo
wingo pushed a change to branch master
in repository guile.

  from  84a740d   psyntax: Generate identifiers in a deterministic fashion.
   new  fb8c91a   Add thread local fluids

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "adds" were already present in the repository and have only
been added to this reference.


Summary of changes:
 NEWS |  7 
 doc/ref/api-control.texi |  3 ++
 doc/ref/api-scheduling.texi  | 54 ---
 libguile/fluids.c| 77 ++--
 libguile/fluids.h|  3 ++
 libguile/stacks.c|  2 +-
 libguile/threads.c   |  1 +
 libguile/throw.c |  2 +-
 test-suite/tests/fluids.test |  8 -
 9 files changed, 125 insertions(+), 32 deletions(-)



[Guile-commits] branch master updated (70cfabd -> 84a740d)

2017-03-07 Thread Ludovic Court�s
civodul pushed a change to branch master
in repository guile.

  from  70cfabd   Check for working profiling and virtual itimers
   new  84a740d   psyntax: Generate identifiers in a deterministic fashion.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "adds" were already present in the repository and have only
been added to this reference.


Summary of changes:
 module/ice-9/boot-9.scm|  41 +--
 module/ice-9/psyntax-pp.scm| 123 -
 module/ice-9/psyntax.scm   |  15 ++--
 module/language/tree-il/fix-letrec.scm |   6 +-
 module/system/base/syntax.scm  |   8 +--
 5 files changed, 143 insertions(+), 50 deletions(-)



[Guile-commits] 01/01: psyntax: Generate identifiers in a deterministic fashion.

2017-03-07 Thread Ludovic Court�s
civodul pushed a commit to branch master
in repository guile.

commit 84a740d86a5afd235f1b47ac66c88db010b1d56b
Author: Mark H Weaver 
Date:   Fri Feb 12 11:19:38 2016 -0500

psyntax: Generate identifiers in a deterministic fashion.

Fixes .

* module/ice-9/boot-9.scm (module-generate-unique-id!)
(module-gensym): New procedures.
(module): Add 'next-unique-id' field.
(the-root-module): Inherit 'next-unique-id' value from early stub.
(make-module, make-autoload-interface): Adjust calls to
module-constructor.
* module/ice-9/psyntax.scm (gen-label, new-mark): Generate unique
identifiers from the module name and the per-module unique-id.
(build-lexical-var, generate-temporaries): Use
'module-gensym' instead of 'gensym'.
* module/ice-9/psyntax-pp.scm: Regenerate.
* module/language/tree-il/fix-letrec.scm (fix-letrec!): Use
'module-gensym' instead of 'gensym'.
* module/system/base/syntax.scm (define-record): Likewise.
(transform-record): Likewise.

Co-authored-by: Ludovic Courtès 
---
 module/ice-9/boot-9.scm|  41 +--
 module/ice-9/psyntax-pp.scm| 123 -
 module/ice-9/psyntax.scm   |  15 ++--
 module/language/tree-il/fix-letrec.scm |   6 +-
 module/system/base/syntax.scm  |   8 +--
 5 files changed, 143 insertions(+), 50 deletions(-)

diff --git a/module/ice-9/boot-9.scm b/module/ice-9/boot-9.scm
index 75906ff..2777672 100644
--- a/module/ice-9/boot-9.scm
+++ b/module/ice-9/boot-9.scm
@@ -1,6 +1,6 @@
 ;;; -*- mode: scheme; coding: utf-8; -*-
 
- Copyright (C) 1995-2014  Free Software Foundation, Inc.
+ Copyright (C) 1995-2014, 2016  Free Software Foundation, Inc.
 
  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
@@ -373,6 +373,13 @@ If returning early, return the return value of F."
 (define (module-ref module sym)
   (let ((v (module-variable module sym)))
 (if v (variable-ref v) (error "badness!" (pk module) (pk sym)
+(define module-generate-unique-id!
+  (let ((next-id 0))
+(lambda (m)
+  (let ((i next-id))
+(set! next-id (+ i 1))
+i
+(define module-gensym gensym)
 (define (resolve-module . args)
   #f)
 
@@ -1982,7 +1989,8 @@ name extensions listed in %load-extensions."
  submodules
  submodule-binder
  public-interface
- filename)))
+ filename
+ next-unique-id)))
 
 
 ;; make-module &opt size uses binder
@@ -2005,7 +2013,7 @@ initial uses list, or binding procedure."
   (make-hash-table)
   '()
   (make-weak-key-hash-table 31) #f
-  (make-hash-table 7) #f #f #f))
+  (make-hash-table 7) #f #f #f 0))
 
 
 
@@ -2542,6 +2550,11 @@ interfaces are added to the inports list."
   (let ((m (make-module 0)))
 (set-module-obarray! m (%get-pre-modules-obarray))
 (set-module-name! m '(guile))
+
+;; Inherit next-unique-id from preliminary stub of
+;; %module-get-next-unique-id! defined above.
+(set-module-next-unique-id! m (module-generate-unique-id! #f))
+
 m))
 
 ;; The root interface is a module that uses the same obarray as the
@@ -2570,6 +2583,11 @@ interfaces are added to the inports list."
   the-root-module
   (error "unexpected module to resolve during module boot" name)))
 
+(define (module-generate-unique-id! m)
+  (let ((i (module-next-unique-id m)))
+(set-module-next-unique-id! m (+ i 1))
+i))
+
 ;; Cheat.  These bindings are needed by modules.c, but we don't want
 ;; to move their real definition here because that would be unnatural.
 ;;
@@ -2600,6 +2618,21 @@ interfaces are added to the inports list."
 (nested-define-module! (resolve-module '() #f) name mod)
 (accessor mod))
 
+(define* (module-gensym #:optional (id " mg") (m (current-module)))
+  "Return a fresh symbol in the context of module M, based on ID (a
+string or symbol).  As long as M is a valid module, this procedure is
+deterministic."
+  (define (->string number)
+(number->string number 16))
+
+  (if m
+  (string->symbol
+   (string-append id "-"
+  (->string (hash (module-name m) most-positive-fixnum))
+  "-"
+  (->string (module-generate-unique-id! m
+  (gensym id)))
+
 (define (make-modules-in module name)
   (or (nested-ref-module module name)
   (let ((m (make-module 31)))
@@ -2891,7 +2924,7 @@ error if selected binding does not exist in the used 
module."
   #:warning "Failed to autoload ~a in ~a:\n" sym name
 (module-constructor (make-hash-table 0) '() b #f #f name 'autoload #f
 (make-hash-table 0) '() (make-weak-value-hash-table 
31) #f
-(make-hash-table 0) #f #f #f)))
+   

[Guile-commits] Success: Hydra job gnu:guile-master:build.i686-linux

2017-03-07 Thread Hydra Build Daemon
Hi,

The status of Hydra job ‘gnu:guile-master:build.i686-linux’ has changed from 
"Failed with output" to "Success".  For details, see

  https://hydra.nixos.org/build/49784388

Yay!

Regards,

The Hydra build daemon.



[Guile-commits] branch master updated (4ce31fd -> 70cfabd)

2017-03-07 Thread Mike Gran
mike121 pushed a change to branch master
in repository guile.

  from  4ce31fd   Can't recursively search DLLs with FFI on Cygwin
   new  70cfabd   Check for working profiling and virtual itimers

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "adds" were already present in the repository and have only
been added to this reference.


Summary of changes:
 configure.ac   | 53 -
 doc/ref/posix.texi | 15 ++---
 doc/ref/statprof.texi  | 12 ---
 libguile/scmsigs.c | 27 ---
 test-suite/tests/asyncs.test   |  5 +--
 test-suite/tests/signals.test  | 76 --
 test-suite/tests/statprof.test | 15 +
 7 files changed, 148 insertions(+), 55 deletions(-)



[Guile-commits] 01/01: Check for working profiling and virtual itimers

2017-03-07 Thread Mike Gran
mike121 pushed a commit to branch master
in repository guile.

commit 70cfabd7e87f93d210bad377feb7ca50fa3bd133
Author: Mike Gran 
Date:   Mon Mar 6 23:06:12 2017 -0800

Check for working profiling and virtual itimers

* configure.ac (HAVE_USABLE_GETITIMER_PROF, HAVE_USABLE_GETITIMER_VIRTUAL): 
new tests
* doc/ref/posix.texi (setitimer, getitimer): document provided? 
'ITIMER_VIRTUAL and 'ITIMER_PROF
* doc/ref/statprof.texi (statprof): document ITIMER_PROF requirements
* libguile/scmsigs.c (scm_setitimer, scm_getitimer): document (provided? 
'ITIMER_VIRTUAL) and (provided? 'ITIMER_PROF)
  (scm_init_scmsigs): add features ITIMER_VIRTUAL and ITIMER_PROF
* test-suite/tests/asyncs.test ("prevention via sigprof"): throw when 
unsupported
* test-suite/tests/signals.test: throw when not supported
* test-suite/tests/statprof.test: throw when not supported
---
 configure.ac   | 53 -
 doc/ref/posix.texi | 15 ++---
 doc/ref/statprof.texi  | 12 ---
 libguile/scmsigs.c | 27 ---
 test-suite/tests/asyncs.test   |  5 +--
 test-suite/tests/signals.test  | 76 --
 test-suite/tests/statprof.test | 15 +
 7 files changed, 148 insertions(+), 55 deletions(-)

diff --git a/configure.ac b/configure.ac
index 8c90d3f..24ee878 100644
--- a/configure.ac
+++ b/configure.ac
@@ -5,7 +5,7 @@ dnl
 define(GUILE_CONFIGURE_COPYRIGHT,[[
 
 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
-  2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Free Software 
Foundation, Inc.
+  2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Free 
Software Foundation, Inc.
 
 This file is part of GUILE
 
@@ -880,6 +880,57 @@ main (void)
   esac
 fi
 
+# Cygwin and Hurd (circa 2017) and various prior versions defined stub
+# versions of the virtual and profiling itimers that would always fail
+# when called.
+if test "$ac_cv_func_getitimer" = yes; then
+
+  AC_CACHE_CHECK([whether getitimer(ITIMER_PROF) is usable],
+guile_cv_use_getitimer_prof,
+[AC_RUN_IFELSE([AC_LANG_SOURCE([[
+#include 
+int
+main (void)
+{
+  struct itimerval I;
+  if (getitimer (ITIMER_PROF, &I) == 0)
+return 0;  /* good */
+  else
+return 1;  /* bad */
+}]])],
+[guile_cv_use_getitimer_prof=yes],
+[guile_cv_use_getitimer_prof=no],
+[guile_cv_use_getitimer_prof="yes, hopefully (cross-compiling)"])])
+  case $guile_cv_use_getitimer_prof in
+yes*)
+  AC_DEFINE([HAVE_USABLE_GETITIMER_PROF], 1, [Define to 1 if 
getitimer(ITIMER_PROF, ...) is functional])
+  ;;
+  esac
+
+  AC_CACHE_CHECK([whether getitimer(ITIMER_VIRTUAL) is usable],
+guile_cv_use_getitimer_virtual,
+[AC_RUN_IFELSE([AC_LANG_SOURCE([[
+#include 
+int
+main (void)
+{
+  struct itimerval I;
+  if (getitimer (ITIMER_VIRTUAL, &I) == 0)
+return 0;  /* good */
+  else
+return 1;  /* bad */
+}]])],
+[guile_cv_use_getitimer_virtual=yes],
+[guile_cv_use_getitimer_virtual=no],
+[guile_cv_use_getitimer_virtual="yes, hopefully (cross-compiling)"])])
+  case $guile_cv_use_getitimer_virtual in
+yes*)
+  AC_DEFINE([HAVE_USABLE_GETITIMER_VIRTUAL], 1, [Define to 1 if 
getitimer(ITIMER_VIRTUAL, ...) is functional])
+  ;;
+  esac
+fi
+
+
 AC_CACHE_SAVE
 
 dnl GMP tests
diff --git a/doc/ref/posix.texi b/doc/ref/posix.texi
index 64e668d..5cb68a2 100644
--- a/doc/ref/posix.texi
+++ b/doc/ref/posix.texi
@@ -1,7 +1,7 @@
 @c -*-texinfo-*-
 @c This is part of the GNU Guile Reference Manual.
 @c Copyright (C)  1996, 1997, 2000, 2001, 2002, 2003, 2004, 2006, 2007,
-@c   2008, 2009, 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc.
+@c   2008, 2009, 2010, 2011, 2012, 2013, 2014, 2017 Free Software Foundation, 
Inc.
 @c See the file guile.texi for copying conditions.
 
 @node POSIX
@@ -2162,12 +2162,12 @@ expiry will be signalled.
 A real-time timer, counting down elapsed real time.  At zero it raises
 @code{SIGALRM}.  This is like @code{alarm} above, but with a higher
 resolution period.
-@end defvar 
+@end defvar
 
 @defvar ITIMER_VIRTUAL
 A virtual-time timer, counting down while the current process is
 actually using CPU.  At zero it raises @code{SIGVTALRM}.
-@end defvar 
+@end defvar
 
 @defvar ITIMER_PROF
 A profiling timer, counting down while the process is running (like
@@ -2176,7 +2176,7 @@ process's behalf.  At zero it raises a @code{SIGPROF}.
 
 This timer is intended for profiling where a program is spending its
 time (by looking where it is when the timer goes off).
-@end defvar 
+@end defvar
 
 @code{getitimer} returns the restart timer value and its current value,
 as a list containing two pairs.  Each pair is a time in seconds and
@@ -2196,6 +2196,13 @@ previous setting, in the same form as @code{getitimer} 
returns.
 
 Although the timers are programmed in microseconds, the actual
 accuracy might not be that high.
+
+Note that @code{