guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] GNU Guile branch, stable-2.0, updated. v2.0.1-87-gea742d


From: Andy Wingo
Subject: [Guile-commits] GNU Guile branch, stable-2.0, updated. v2.0.1-87-gea742d2
Date: Tue, 24 May 2011 20:57:00 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Guile".

http://git.savannah.gnu.org/cgit/guile.git/commit/?id=ea742d29c50c6fc4a4c03288c4ddbe33f24f1913

The branch, stable-2.0 has been updated
       via  ea742d29c50c6fc4a4c03288c4ddbe33f24f1913 (commit)
       via  2f045fc1f6e53fa9bcaa821c18ec49b19560fe4e (commit)
       via  26c8cc144f4d58871098347df7462ea60b72a72c (commit)
       via  c0937f0988d202d1062fea6e5b61d68d387d1542 (commit)
      from  f2ed447383f0398777719a2cda92c38e9838bf85 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit ea742d29c50c6fc4a4c03288c4ddbe33f24f1913
Author: Andy Wingo <address@hidden>
Date:   Tue May 24 22:52:39 2011 +0200

    threadsafe addition to the goops vtable_class_map
    
    * libguile/goops.c (scm_i_define_class_for_vtable): Lock around
      additions to the vtable_class_map.  Use is unlocked though; solving
      GOOPS parallel-initialization would be a good thing.

commit 2f045fc1f6e53fa9bcaa821c18ec49b19560fe4e
Author: Andy Wingo <address@hidden>
Date:   Tue May 24 22:46:09 2011 +0200

    threadsafe access to source properties weak hash table
    
    * libguile/srcprop.c: Add a lock around scm_source_whash, and use it.

commit 26c8cc144f4d58871098347df7462ea60b72a72c
Author: Andy Wingo <address@hidden>
Date:   Tue May 24 21:25:11 2011 +0200

    read + source properties simplification
    
    * libguile/srcprop.h: Remove internal scm_source_whash declaration.
    * libguile/srcprop.c (scm_i_set_source_properties_x)
      (scm_i_has_source_properties): New helpers.
      (scm_source_whash): Make static.
    
    * libguile/read.c (scm_read_sexp): Remove register declarations here;
      let's trust the compiler.  Remove code to incrementally build up a
      copy; instead let's let scm_i_set_source_properties_x handle copying
      the expression if needed.
      (scm_read_quote, scm_read_syntax): Use scm_i_set_source_properties_x.
      (recsexpr): Remove this helper from 1996.
      (scm_read_sharp_extension): Instead of trying to recursively label
      sharp-read subforms with source properties, just label the outside
      form and rely on the macro-expander to propagate it down.

commit c0937f0988d202d1062fea6e5b61d68d387d1542
Author: Andy Wingo <address@hidden>
Date:   Tue May 24 21:09:24 2011 +0200

    safely access the trampoline weak map
    
    * libguile/smob.c (scm_i_smob_apply_trampoline): Protect the trampoline
      weak map with a mutex.

-----------------------------------------------------------------------

Summary of changes:
 libguile/goops.c   |   12 +++++-
 libguile/read.c    |  119 +++++-----------------------------------------------
 libguile/smob.c    |   15 +++++-
 libguile/srcprop.c |   59 +++++++++++++++++++++++++-
 libguile/srcprop.h |    4 +-
 5 files changed, 94 insertions(+), 115 deletions(-)

diff --git a/libguile/goops.c b/libguile/goops.c
index 899ba73..dfe26c3 100644
--- a/libguile/goops.c
+++ b/libguile/goops.c
@@ -170,6 +170,7 @@ static SCM class_bytevector;
 static SCM class_uvec;
 
 static SCM vtable_class_map = SCM_BOOL_F;
+static scm_i_pthread_mutex_t vtable_class_map_lock = 
SCM_I_PTHREAD_MUTEX_INITIALIZER;
 
 /* Port classes.  Allocate 3 times the maximum number of port types so that
    input ports, output ports, and in/out ports can be stored at different
@@ -197,6 +198,8 @@ scm_i_define_class_for_vtable (SCM vtable)
 {
   SCM class;
 
+  scm_i_pthread_mutex_lock (&vtable_class_map_lock);
+
   if (scm_is_false (vtable_class_map))
     vtable_class_map = scm_make_weak_key_hash_table (SCM_UNDEFINED);
   
@@ -205,6 +208,8 @@ scm_i_define_class_for_vtable (SCM vtable)
 
   class = scm_hashq_ref (vtable_class_map, vtable, SCM_BOOL_F);
   
+  scm_i_pthread_mutex_unlock (&vtable_class_map_lock);
+
   if (scm_is_false (class))
     {
       if (SCM_UNPACK (scm_class_class))
@@ -219,8 +224,12 @@ scm_i_define_class_for_vtable (SCM vtable)
       else
         /* `create_struct_classes' will fill this in later.  */
         class = SCM_BOOL_F;
-        
+
+      /* Don't worry about races.  This only happens when creating a
+         vtable, which happens by definition in one thread.  */
+      scm_i_pthread_mutex_lock (&vtable_class_map_lock);
       scm_hashq_set_x (vtable_class_map, vtable, class);
+      scm_i_pthread_mutex_unlock (&vtable_class_map_lock);
     }
 
   return class;
@@ -2660,6 +2669,7 @@ make_struct_class (void *closure SCM_UNUSED,
 static void
 create_struct_classes (void)
 {
+  /* FIXME: take the vtable_class_map while initializing goops?  */
   scm_internal_hash_fold (make_struct_class, 0, SCM_BOOL_F,
                           vtable_class_map);
 }
diff --git a/libguile/read.c b/libguile/read.c
index 3760ce1..4d22ead 100644
--- a/libguile/read.c
+++ b/libguile/read.c
@@ -357,24 +357,20 @@ flush_ws (SCM port, const char *eoferr)
 
 static SCM scm_read_expression (SCM port);
 static SCM scm_read_sharp (int chr, SCM port);
-static SCM recsexpr (SCM obj, long line, int column, SCM filename);
 
 
 static SCM
 scm_read_sexp (scm_t_wchar chr, SCM port)
 #define FUNC_NAME "scm_i_lreadparen"
 {
-  register int c;
-  register SCM tmp;
-  register SCM tl, ans = SCM_EOL;
-  SCM tl2 = SCM_EOL, ans2 = SCM_EOL, copy = SCM_BOOL_F;
+  int c;
+  SCM tmp, tl, ans = SCM_EOL;
   const int terminating_char = ((chr == '[') ? ']' : ')');
 
   /* Need to capture line and column numbers here. */
   long line = SCM_LINUM (port);
   int column = SCM_COL (port) - 1;
 
-
   c = flush_ws (port, FUNC_NAME);
   if (terminating_char == c)
     return SCM_EOL;
@@ -393,12 +389,6 @@ scm_read_sexp (scm_t_wchar chr, SCM port)
   /* Build the head of the list structure. */
   ans = tl = scm_cons (tmp, SCM_EOL);
 
-  if (SCM_COPY_SOURCE_P)
-    ans2 = tl2 = scm_cons (scm_is_pair (tmp)
-                          ? copy
-                          : tmp,
-                          SCM_EOL);
-
   while (terminating_char != (c = flush_ws (port, FUNC_NAME)))
     {
       SCM new_tail;
@@ -415,10 +405,6 @@ scm_read_sexp (scm_t_wchar chr, SCM port)
        {
          SCM_SETCDR (tl, tmp = scm_read_expression (port));
 
-         if (SCM_COPY_SOURCE_P)
-           SCM_SETCDR (tl2, scm_cons (scm_is_pair (tmp) ? copy : tmp,
-                                      SCM_EOL));
-
          c = flush_ws (port, FUNC_NAME);
          if (terminating_char != c)
            scm_i_input_error (FUNC_NAME, port,
@@ -429,27 +415,12 @@ scm_read_sexp (scm_t_wchar chr, SCM port)
       new_tail = scm_cons (tmp, SCM_EOL);
       SCM_SETCDR (tl, new_tail);
       tl = new_tail;
-
-      if (SCM_COPY_SOURCE_P)
-       {
-         SCM new_tail2 = scm_cons (scm_is_pair (tmp)
-                                   ? copy
-                                   : tmp, SCM_EOL);
-         SCM_SETCDR (tl2, new_tail2);
-         tl2 = new_tail2;
-       }
     }
 
  exit:
   if (SCM_RECORD_POSITIONS_P)
-    scm_hashq_set_x (scm_source_whash,
-                     ans,
-                     scm_make_srcprops (line, column,
-                                        SCM_FILENAME (port),
-                                        SCM_COPY_SOURCE_P
-                                        ? ans2
-                                        : SCM_UNDEFINED,
-                                        SCM_EOL));
+    scm_i_set_source_properties_x (ans, line, column, SCM_FILENAME (port));
+
   return ans;
 }
 #undef FUNC_NAME
@@ -805,16 +776,7 @@ scm_read_quote (int chr, SCM port)
 
   p = scm_cons2 (p, scm_read_expression (port), SCM_EOL);
   if (SCM_RECORD_POSITIONS_P)
-    scm_hashq_set_x (scm_source_whash, p,
-                     scm_make_srcprops (line, column,
-                                        SCM_FILENAME (port),
-                                        SCM_COPY_SOURCE_P
-                                        ? (scm_cons2 (SCM_CAR (p),
-                                                      SCM_CAR (SCM_CDR (p)),
-                                                      SCM_EOL))
-                                        : SCM_UNDEFINED,
-                                        SCM_EOL));
-
+    scm_i_set_source_properties_x (p, line, column, SCM_FILENAME (port));
 
   return p;
 }
@@ -864,16 +826,7 @@ scm_read_syntax (int chr, SCM port)
 
   p = scm_cons2 (p, scm_read_expression (port), SCM_EOL);
   if (SCM_RECORD_POSITIONS_P)
-    scm_hashq_set_x (scm_source_whash, p,
-                     scm_make_srcprops (line, column,
-                                        SCM_FILENAME (port),
-                                        SCM_COPY_SOURCE_P
-                                        ? (scm_cons2 (SCM_CAR (p),
-                                                      SCM_CAR (SCM_CDR (p)),
-                                                      SCM_EOL))
-                                        : SCM_UNDEFINED,
-                                        SCM_EOL));
-
+    scm_i_set_source_properties_x (p, line, column, SCM_FILENAME (port));
 
   return p;
 }
@@ -1332,14 +1285,11 @@ scm_read_sharp_extension (int chr, SCM port)
       SCM got;
 
       got = scm_call_2 (proc, SCM_MAKE_CHAR (chr), port);
-      if (!scm_is_eq (got, SCM_UNSPECIFIED))
-       {
-         if (SCM_RECORD_POSITIONS_P)
-           return (recsexpr (got, line, column,
-                             SCM_FILENAME (port)));
-         else
-           return got;
-       }
+
+      if (scm_is_pair (got) && !scm_i_has_source_properties (got))
+        scm_i_set_source_properties_x (got, line, column, SCM_FILENAME (port));
+      
+      return got;
     }
 
   return SCM_UNSPECIFIED;
@@ -1550,53 +1500,6 @@ SCM_DEFINE (scm_read, "read", 0, 1, 0,
 
 
 
-/* Used when recording expressions constructed by `scm_read_sharp ()'.  */
-static SCM
-recsexpr (SCM obj, long line, int column, SCM filename)
-{
-  if (!scm_is_pair(obj)) {
-    return obj;
-  } else {
-    SCM tmp, copy;
-    /* If this sexpr is visible in the read:sharp source, we want to
-       keep that information, so only record non-constant cons cells
-       which haven't previously been read by the reader. */
-    if (scm_is_false (scm_hashq_ref (scm_source_whash, obj, SCM_BOOL_F)))
-      {
-       if (SCM_COPY_SOURCE_P)
-         {
-           copy = scm_cons (recsexpr (SCM_CAR (obj), line, column, filename),
-                            SCM_UNDEFINED);
-           for (tmp = obj; scm_is_pair (tmp); tmp = SCM_CDR (tmp))
-             {
-               SCM_SETCDR (copy, scm_cons (recsexpr (SCM_CAR (tmp),
-                                                     line,
-                                                     column,
-                                                     filename),
-                                           SCM_UNDEFINED));
-               copy = SCM_CDR (copy);
-             }
-           SCM_SETCDR (copy, tmp);
-         }
-       else
-         {
-           recsexpr (SCM_CAR (obj), line, column, filename);
-           for (tmp = obj; scm_is_pair (tmp); tmp = SCM_CDR (tmp))
-             recsexpr (SCM_CAR (tmp), line, column, filename);
-           copy = SCM_UNDEFINED;
-         }
-       scm_hashq_set_x (scm_source_whash,
-                         obj,
-                         scm_make_srcprops (line,
-                                            column,
-                                            filename,
-                                            copy,
-                                            SCM_EOL));
-      }
-    return obj;
-  }
-}
-
 /* Manipulate the read-hash-procedures alist.  This could be written in
    Scheme, but maybe it will also be used by C code during initialisation.  */
 SCM_DEFINE (scm_read_hash_extend, "read-hash-extend", 2, 0, 0,
diff --git a/libguile/smob.c b/libguile/smob.c
index adb34ba..c414913 100644
--- a/libguile/smob.c
+++ b/libguile/smob.c
@@ -418,12 +418,16 @@ scm_set_smob_apply (scm_t_bits tc, SCM (*apply) (),
 }
 
 static SCM tramp_weak_map = SCM_BOOL_F;
+static scm_i_pthread_mutex_t tramp_lock = SCM_I_PTHREAD_MUTEX_INITIALIZER;
+
 SCM
 scm_i_smob_apply_trampoline (SCM smob)
 {
-  /* could use hashq-create-handle!, but i don't know what to do if it returns 
a
-     weak pair */
-  SCM tramp = scm_hashq_ref (tramp_weak_map, smob, SCM_BOOL_F);
+  SCM tramp;
+
+  scm_i_pthread_mutex_lock (&tramp_lock);
+  tramp = scm_hashq_ref (tramp_weak_map, smob, SCM_BOOL_F);
+  scm_i_pthread_mutex_unlock (&tramp_lock);
 
   if (scm_is_true (tramp))
     return tramp;
@@ -440,7 +444,12 @@ scm_i_smob_apply_trampoline (SCM smob)
       SCM_SIMPLE_VECTOR_SET (objtable, 1, scm_from_locale_symbol (name));
       tramp = scm_make_program (SCM_SMOB_DESCRIPTOR 
(smob).apply_trampoline_objcode,
                                 objtable, SCM_BOOL_F);
+
+      /* Race conditions (between the ref and this set!) cannot cause
+         any harm here.  */
+      scm_i_pthread_mutex_lock (&tramp_lock);
       scm_hashq_set_x (tramp_weak_map, smob, tramp);
+      scm_i_pthread_mutex_unlock (&tramp_lock);
       return tramp;
     }
 }
diff --git a/libguile/srcprop.c b/libguile/srcprop.c
index 4eb1cca..dc333d4 100644
--- a/libguile/srcprop.c
+++ b/libguile/srcprop.c
@@ -38,6 +38,8 @@
 
 #include "libguile/validate.h"
 #include "libguile/srcprop.h"
+#include "libguile/private-options.h"
+
 
 /* {Source Properties}
  *
@@ -57,8 +59,9 @@ SCM_GLOBAL_SYMBOL (scm_sym_filename, "filename");
 SCM_GLOBAL_SYMBOL (scm_sym_copy, "copy");
 SCM_GLOBAL_SYMBOL (scm_sym_line, "line");
 SCM_GLOBAL_SYMBOL (scm_sym_column, "column");
-SCM scm_source_whash;
 
+static SCM scm_source_whash;
+static scm_i_pthread_mutex_t source_lock = SCM_I_PTHREAD_MUTEX_INITIALIZER;
 
 
 /*
@@ -163,7 +166,11 @@ SCM_DEFINE (scm_source_properties, "source-properties", 1, 
0, 0,
 {
   SCM p;
   SCM_VALIDATE_NIM (1, obj);
-  p = scm_hashq_ref (scm_source_whash, obj, SCM_EOL);
+
+  scm_i_pthread_mutex_lock (&source_lock);
+  p = scm_hashq_ref (scm_source_whash, obj, SCM_EOL); 
+  scm_i_pthread_mutex_unlock (&source_lock);
+
   if (SRCPROPSP (p))
     return scm_srcprops_to_alist (p);
   else
@@ -181,11 +188,49 @@ SCM_DEFINE (scm_set_source_properties_x, 
"set-source-properties!", 2, 0, 0,
 #define FUNC_NAME s_scm_set_source_properties_x
 {
   SCM_VALIDATE_NIM (1, obj);
+
+  scm_i_pthread_mutex_lock (&source_lock);
   scm_hashq_set_x (scm_source_whash, obj, alist);
+  scm_i_pthread_mutex_unlock (&source_lock);
+
   return alist;
 }
 #undef FUNC_NAME
 
+int
+scm_i_has_source_properties (SCM obj)
+#define FUNC_NAME "%set-source-properties"
+{
+  int ret;
+  
+  SCM_VALIDATE_NIM (1, obj);
+
+  scm_i_pthread_mutex_lock (&source_lock);
+  ret = scm_is_true (scm_hashq_ref (scm_source_whash, obj, SCM_BOOL_F));
+  scm_i_pthread_mutex_unlock (&source_lock);
+
+  return ret;
+}
+#undef FUNC_NAME
+  
+
+void
+scm_i_set_source_properties_x (SCM obj, long line, int col, SCM fname)
+#define FUNC_NAME "%set-source-properties"
+{
+  SCM_VALIDATE_NIM (1, obj);
+
+  scm_i_pthread_mutex_lock (&source_lock);
+  scm_hashq_set_x (scm_source_whash, obj,
+                   scm_make_srcprops (line, col, fname,
+                                      SCM_COPY_SOURCE_P
+                                      ? scm_copy_tree (obj)
+                                      : SCM_UNDEFINED,
+                                      SCM_EOL));
+  scm_i_pthread_mutex_unlock (&source_lock);
+}
+#undef FUNC_NAME
+
 SCM_DEFINE (scm_source_property, "source-property", 2, 0, 0,
             (SCM obj, SCM key),
            "Return the source property specified by @var{key} from\n"
@@ -194,7 +239,11 @@ SCM_DEFINE (scm_source_property, "source-property", 2, 0, 
0,
 {
   SCM p;
   SCM_VALIDATE_NIM (1, obj);
+
+  scm_i_pthread_mutex_lock (&source_lock);
   p = scm_hashq_ref (scm_source_whash, obj, SCM_EOL);
+  scm_i_pthread_mutex_unlock (&source_lock);
+
   if (!SRCPROPSP (p))
     goto alist;
   if (scm_is_eq (scm_sym_line, key))
@@ -222,6 +271,8 @@ SCM_DEFINE (scm_set_source_property_x, 
"set-source-property!", 3, 0, 0,
 {
   SCM p;
   SCM_VALIDATE_NIM (1, obj);
+
+  scm_i_pthread_mutex_lock (&source_lock);
   p = scm_hashq_ref (scm_source_whash, obj, SCM_EOL);
 
   if (scm_is_eq (scm_sym_line, key))
@@ -258,6 +309,8 @@ SCM_DEFINE (scm_set_source_property_x, 
"set-source-property!", 3, 0, 0,
        scm_hashq_set_x (scm_source_whash, obj,
                          scm_acons (key, datum, p));
     }
+  scm_i_pthread_mutex_unlock (&source_lock);
+
   return SCM_UNSPECIFIED;
 }
 #undef FUNC_NAME
@@ -272,10 +325,12 @@ SCM_DEFINE (scm_cons_source, "cons-source", 3, 0, 0,
 {
   SCM p, z;
   z = scm_cons (x, y);
+  scm_i_pthread_mutex_lock (&source_lock);
   /* Copy source properties possibly associated with xorig. */
   p = scm_hashq_ref (scm_source_whash, xorig, SCM_BOOL_F);
   if (scm_is_true (p))
     scm_hashq_set_x (scm_source_whash, z, p);
+  scm_i_pthread_mutex_unlock (&source_lock);
   return z;
 }
 #undef FUNC_NAME
diff --git a/libguile/srcprop.h b/libguile/srcprop.h
index 5c9ccb9..250756d 100644
--- a/libguile/srcprop.h
+++ b/libguile/srcprop.h
@@ -33,7 +33,6 @@
 #define SCM_SOURCE_PROPERTY_FLAG_BREAK 1
 
 SCM_API scm_t_bits scm_tc16_srcprops;
-SCM_INTERNAL SCM scm_source_whash;
 
 SCM_API SCM scm_sym_filename;
 SCM_API SCM scm_sym_copy;
@@ -47,6 +46,9 @@ SCM_API SCM scm_source_property (SCM obj, SCM key);
 SCM_API SCM scm_set_source_property_x (SCM obj, SCM key, SCM datum);
 SCM_API SCM scm_source_properties (SCM obj);
 SCM_API SCM scm_set_source_properties_x (SCM obj, SCM props);
+SCM_INTERNAL int scm_i_has_source_properties (SCM obj);
+SCM_INTERNAL void scm_i_set_source_properties_x (SCM obj, long line, int col,
+                                                 SCM fname);
 SCM_API SCM scm_cons_source (SCM xorig, SCM x, SCM y);
 SCM_INTERNAL void scm_init_srcprop (void);
 


hooks/post-receive
-- 
GNU Guile



reply via email to

[Prev in Thread] Current Thread [Next in Thread]