[git] GnuPG - branch, master, updated. gnupg-2.1.19-59-g6a3f857

by Justus Winter cvs at cvs.gnupg.org
Fri Mar 17 10:36:04 CET 2017


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 "The GNU Privacy Guard".

The branch, master has been updated
       via  6a3f857224eab108ae38e6259194b01b0ffdad8b (commit)
       via  38c955599f7c6c20faeec57d8e1df7d2c0eeba18 (commit)
      from  8c8ce8711d9c938fcb982b0341e6b052742cb887 (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 6a3f857224eab108ae38e6259194b01b0ffdad8b
Author: Justus Winter <justus at g10code.com>
Date:   Thu Mar 16 17:18:01 2017 +0100

    gpgscm: Simplify hash tables.
    
    * tests/gpgscm/scheme.c (oblist_add_by_name): We now always get a
    slot.  Simplify accordingly.
    (oblist_find_by_name): Always return the slot.
    (vector_elem_slot): New function.
    (new_slot_spec_in_env): We now always get a slot.  Remove parameter
    'env'.  Simplify accordingly.
    (find_slot_spec_in_env): Always return a slot.
    (new_slot_in_env): Adapt callsite.
    (opexe_0): Likewise.
    (opexe_1): Likewise.
    (scheme_define): Likewise.
    --
    
    Now that the ill-devised immediate values framework is gone, there is
    no need to tag the pointers in vectors anymore.  Therefore, we can
    always return a pointer to the slot in the hash table lookup
    functions.
    
    Signed-off-by: Justus Winter <justus at g10code.com>

diff --git a/tests/gpgscm/scheme.c b/tests/gpgscm/scheme.c
index ff91fc0..b76e83c 100644
--- a/tests/gpgscm/scheme.c
+++ b/tests/gpgscm/scheme.c
@@ -224,6 +224,7 @@ INTERFACE INLINE int is_vector(pointer p)    { return (type(p)==T_VECTOR); }
  * represent it.  */
 #define vector_size(len)	(1 + ((len) - 1 + 2) / 3)
 INTERFACE static void fill_vector(pointer vec, pointer obj);
+INTERFACE static pointer *vector_elem_slot(pointer vec, int ielem);
 INTERFACE static pointer vector_elem(pointer vec, int ielem);
 INTERFACE static pointer set_vector_elem(pointer vec, int ielem, pointer a);
 INTERFACE INLINE int is_number(pointer p)    { return (type(p)==T_NUMBER); }
@@ -1073,39 +1074,24 @@ static pointer oblist_initial_value(scheme *sc)
 /* Add a new symbol NAME at SLOT.  SLOT must be obtained using
  * oblist_find_by_name, and no insertion must be done between
  * obtaining the SLOT and calling this function.  Returns the new
- * symbol.
- *
- * If SLOT is NULL, the new symbol is be placed at the appropriate
- * place in the vector.  */
+ * symbol.  */
 static pointer oblist_add_by_name(scheme *sc, const char *name, pointer *slot)
 {
 #define oblist_add_by_name_allocates	3
   pointer x;
-  int location;
 
   gc_disable(sc, gc_reservations (oblist_add_by_name));
   x = immutable_cons(sc, mk_string(sc, name), sc->NIL);
   typeflag(x) = T_SYMBOL;
   setimmutable(car(x));
-
-  if (slot == NULL) {
-    location = hash_fn(name, vector_length(sc->oblist));
-    set_vector_elem(sc->oblist, location,
-		    immutable_cons(sc, x, vector_elem(sc->oblist, location)));
-  } else {
-    *slot = immutable_cons(sc, x, *slot);
-  }
-
+  *slot = immutable_cons(sc, x, *slot);
   gc_enable(sc);
   return x;
 }
 
 /* Lookup the symbol NAME.  Returns the symbol, or NIL if it does not
  * exist.  In that case, SLOT points to the point where the new symbol
- * is to be inserted.
- *
- * SLOT may be set to NULL if the new symbol should be placed at the
- * appropriate place in the vector.  */
+ * is to be inserted.  */
 static INLINE pointer
 oblist_find_by_name(scheme *sc, const char *name, pointer **slot)
 {
@@ -1115,7 +1101,7 @@ oblist_find_by_name(scheme *sc, const char *name, pointer **slot)
   int d;
 
   location = hash_fn(name, vector_length(sc->oblist));
-  for (*slot = NULL, x = vector_elem(sc->oblist, location);
+  for (*slot = vector_elem_slot(sc->oblist, location), x = **slot;
        x != sc->NIL; *slot = &cdr(x), x = **slot) {
     s = symname(car(x));
     /* case-insensitive, per R5RS section 2. */
@@ -1353,6 +1339,12 @@ INTERFACE static void fill_vector(pointer vec, pointer obj) {
      }
 }
 
+INTERFACE static pointer *vector_elem_slot(pointer vec, int ielem) {
+     assert (is_vector (vec));
+     assert (ielem < vector_length(vec));
+     return &vec->_object._vector._elements[ielem];
+}
+
 INTERFACE static pointer vector_elem(pointer vec, int ielem) {
      assert (is_vector (vec));
      assert (ielem < vector_length(vec));
@@ -2636,11 +2628,8 @@ static void new_frame_in_env(scheme *sc, pointer old_env)
 
 /* Insert (VARIABLE, VALUE) at SSLOT.  SSLOT must be obtained using
  * find_slot_spec_in_env, and no insertion must be done between
- * obtaining SSLOT and the call to this function.
- *
- * If SSLOT is NULL, the new slot is put into the appropriate place in
- * the environment vector.  */
-static INLINE void new_slot_spec_in_env(scheme *sc, pointer env,
+ * obtaining SSLOT and the call to this function.  */
+static INLINE void new_slot_spec_in_env(scheme *sc,
                                         pointer variable, pointer value,
 					pointer *sslot)
 {
@@ -2648,27 +2637,14 @@ static INLINE void new_slot_spec_in_env(scheme *sc, pointer env,
   pointer slot;
   gc_disable(sc, gc_reservations (new_slot_spec_in_env));
   slot = immutable_cons(sc, variable, value);
-
-  if (sslot == NULL) {
-    int location;
-    assert(is_vector(car(env)));
-    location = hash_fn(symname(variable), vector_length(car(env)));
-
-    set_vector_elem(car(env), location,
-                    immutable_cons(sc, slot, vector_elem(car(env), location)));
-  } else {
-    *sslot = immutable_cons(sc, slot, *sslot);
-  }
+  *sslot = immutable_cons(sc, slot, *sslot);
   gc_enable(sc);
 }
 
 /* Find the slot in ENV under the key HDL.  If ALL is given, look in
  * all environments enclosing ENV.  If the lookup fails, and SSLOT is
  * given, the position where the new slot has to be inserted is stored
- * at SSLOT.
- *
- * SSLOT may be set to NULL if the new symbol should be placed at the
- * appropriate place in the vector.  */
+ * at SSLOT.  */
 static pointer
 find_slot_spec_in_env(scheme *sc, pointer env, pointer hdl, int all, pointer **sslot)
 {
@@ -2681,13 +2657,11 @@ find_slot_spec_in_env(scheme *sc, pointer env, pointer hdl, int all, pointer **s
   for (x = env; x != sc->NIL; x = cdr(x)) {
     if (is_vector(car(x))) {
       location = hash_fn(symname(hdl), vector_length(car(x)));
-      sl = NULL;
-      y = vector_elem(car(x), location);
+      sl = vector_elem_slot(car(x), location);
     } else {
       sl = &car(x);
-      y = *sl;
     }
-    for ( ; y != sc->NIL; sl = &cdr(y), y = *sl) {
+    for (y = *sl ; y != sc->NIL; sl = &cdr(y), y = *sl) {
       d = pointercmp(caar(y), hdl);
       if (d == 0)
 	return car(y);		/* Hit.  */
@@ -2716,12 +2690,11 @@ static INLINE void new_frame_in_env(scheme *sc, pointer old_env)
 /* Insert (VARIABLE, VALUE) at SSLOT.  SSLOT must be obtained using
  * find_slot_spec_in_env, and no insertion must be done between
  * obtaining SSLOT and the call to this function.  */
-static INLINE void new_slot_spec_in_env(scheme *sc, pointer env,
+static INLINE void new_slot_spec_in_env(scheme *sc,
                                         pointer variable, pointer value,
 					pointer *sslot)
 {
 #define new_slot_spec_in_env_allocates	2
-  (void) env;
   assert(is_symbol(variable));
   *sslot = immutable_cons(sc, immutable_cons(sc, variable, value), *sslot);
 }
@@ -2772,7 +2745,7 @@ static INLINE void new_slot_in_env(scheme *sc, pointer variable, pointer value)
   assert(is_symbol(variable));
   slot = find_slot_spec_in_env(sc, sc->envir, variable, 0, &sslot);
   assert(slot == sc->NIL);
-  new_slot_spec_in_env(sc, sc->envir, variable, value, sslot);
+  new_slot_spec_in_env(sc, variable, value, sslot);
 }
 
 static INLINE void set_slot_in_env(scheme *sc, pointer slot, pointer value)
@@ -3534,7 +3507,7 @@ static pointer opexe_0(scheme *sc, enum scheme_opcodes op) {
           if (x != sc->NIL) {
                set_slot_in_env(sc, x, sc->value);
           } else {
-	       new_slot_spec_in_env(sc, sc->envir, sc->code, sc->value, sslot);
+	       new_slot_spec_in_env(sc, sc->code, sc->value, sslot);
           }
           s_return(sc,sc->code);
      }
@@ -3856,7 +3829,7 @@ static pointer opexe_1(scheme *sc, enum scheme_opcodes op) {
           if (x != sc->NIL) {
                set_slot_in_env(sc, x, sc->value);
           } else {
-	       new_slot_spec_in_env(sc, sc->envir, sc->code, sc->value, sslot);
+	       new_slot_spec_in_env(sc, sc->code, sc->value, sslot);
           }
           s_return(sc,sc->code);
      }
@@ -5811,7 +5784,7 @@ void scheme_define(scheme *sc, pointer envir, pointer symbol, pointer value) {
      if (x != sc->NIL) {
           set_slot_in_env(sc, x, value);
      } else {
-          new_slot_spec_in_env(sc, envir, symbol, value, sslot);
+          new_slot_spec_in_env(sc, symbol, value, sslot);
      }
 }
 

commit 38c955599f7c6c20faeec57d8e1df7d2c0eeba18
Author: Justus Winter <justus at g10code.com>
Date:   Thu Mar 16 16:58:00 2017 +0100

    gpgscm: Remove framework for immediate values.
    
    * tests/gpgscm/scheme.c (IMMEDIATE_TAG): Remove macro.
    (is_immediate): Likewise.
    (set_immediate): Likewise.
    (clr_immediate): Likewise.
    (enum scheme_types): Set the LSB in every value.
    (fill_vector): Adapt.
    (vector_elem): Likewise.
    (set_vector_elem): Likewise.
    (mark): Likewise.
    (gc): Test for the LSB to tell typeflags apart from pointers stored in
    the same memory location.
    --
    
    Supporting immediate values would require invasive changes to the
    interpreter and is likely not worth the trouble.  On the other hand,
    tagging pointers in vectors complicated the hash table implementation
    needlessly.  Therefore, I remove this again.
    
    This fixes a crash on big endian architectures.
    
    GnuPG-bug-id: 2996
    Signed-off-by: Justus Winter <justus at g10code.com>

diff --git a/tests/gpgscm/scheme.c b/tests/gpgscm/scheme.c
index af97c27..ff91fc0 100644
--- a/tests/gpgscm/scheme.c
+++ b/tests/gpgscm/scheme.c
@@ -117,41 +117,29 @@ static const char *strlwr(char *s) {
 
 

 
-/* Support for immediate values.
- *
- * Immediate values are tagged with IMMEDIATE_TAG, which is neither
- * used in types, nor in pointer values.
- *
- * XXX: Currently, we only use this to tag pointers in vectors.  */
-#define IMMEDIATE_TAG		1
-#define is_immediate(p)		((pointer) ((uintptr_t) (p) &  IMMEDIATE_TAG))
-#define set_immediate(p)	((pointer) ((uintptr_t) (p) |  IMMEDIATE_TAG))
-#define clr_immediate(p)	((pointer) ((uintptr_t) (p) & ~IMMEDIATE_TAG))
-
-

-
+/* All types have the LSB set.  The garbage collector takes advantage
+ * of that to identify types.  */
 enum scheme_types {
-  T_STRING=1 << 1,	/* Do not use the lsb, it is used for
-			 * immediate values.  */
-  T_NUMBER=2 << 1,
-  T_SYMBOL=3 << 1,
-  T_PROC=4 << 1,
-  T_PAIR=5 << 1,
-  T_CLOSURE=6 << 1,
-  T_CONTINUATION=7 << 1,
-  T_FOREIGN=8 << 1,
-  T_CHARACTER=9 << 1,
-  T_PORT=10 << 1,
-  T_VECTOR=11 << 1,
-  T_MACRO=12 << 1,
-  T_PROMISE=13 << 1,
-  T_ENVIRONMENT=14 << 1,
-  T_FOREIGN_OBJECT=15 << 1,
-  T_BOOLEAN=16 << 1,
-  T_NIL=17 << 1,
-  T_EOF_OBJ=18 << 1,
-  T_SINK=19 << 1,
-  T_LAST_SYSTEM_TYPE=19 << 1
+  T_STRING =		 1 << 1 | 1,
+  T_NUMBER =		 2 << 1 | 1,
+  T_SYMBOL =		 3 << 1 | 1,
+  T_PROC =		 4 << 1 | 1,
+  T_PAIR =		 5 << 1 | 1,
+  T_CLOSURE =		 6 << 1 | 1,
+  T_CONTINUATION =	 7 << 1 | 1,
+  T_FOREIGN =		 8 << 1 | 1,
+  T_CHARACTER =		 9 << 1 | 1,
+  T_PORT =		10 << 1 | 1,
+  T_VECTOR =		11 << 1 | 1,
+  T_MACRO =		12 << 1 | 1,
+  T_PROMISE =		13 << 1 | 1,
+  T_ENVIRONMENT =	14 << 1 | 1,
+  T_FOREIGN_OBJECT =	15 << 1 | 1,
+  T_BOOLEAN =		16 << 1 | 1,
+  T_NIL =		17 << 1 | 1,
+  T_EOF_OBJ =		18 << 1 | 1,
+  T_SINK =		19 << 1 | 1,
+  T_LAST_SYSTEM_TYPE =	19 << 1 | 1
 };
 
 static const char *
@@ -1361,20 +1349,20 @@ INTERFACE static void fill_vector(pointer vec, pointer obj) {
      size_t i;
      assert (is_vector (vec));
      for(i = 0; i < vector_length(vec); i++) {
-          vec->_object._vector._elements[i] = set_immediate(obj);
+          vec->_object._vector._elements[i] = obj;
      }
 }
 
 INTERFACE static pointer vector_elem(pointer vec, int ielem) {
      assert (is_vector (vec));
      assert (ielem < vector_length(vec));
-     return clr_immediate(vec->_object._vector._elements[ielem]);
+     return vec->_object._vector._elements[ielem];
 }
 
 INTERFACE static pointer set_vector_elem(pointer vec, int ielem, pointer a) {
      assert (is_vector (vec));
      assert (ielem < vector_length(vec));
-     vec->_object._vector._elements[ielem] = set_immediate(a);
+     vec->_object._vector._elements[ielem] = a;
      return a;
 }
 
@@ -1576,7 +1564,7 @@ E2:  setmark(p);
      if(is_vector(p)) {
           int i;
           for (i = 0; i < vector_length(p); i++) {
-               mark(clr_immediate(p->_object._vector._elements[i]));
+               mark(p->_object._vector._elements[i]);
           }
      }
 #if SHOW_ERROR_LINE
@@ -1677,8 +1665,9 @@ static void gc(scheme *sc, pointer a, pointer b) {
   for (i = sc->last_cell_seg; i >= 0; i--) {
     p = sc->cell_seg[i] + CELL_SEGSIZE;
     while (--p >= sc->cell_seg[i]) {
-      if (typeflag(p) & IMMEDIATE_TAG)
-        continue;
+      if ((typeflag(p) & 1) == 0)
+	/* All types have the LSB set.  This is not a typeflag.  */
+	continue;
       if (is_mark(p)) {
     clrmark(p);
       } else {

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

Summary of changes:
 tests/gpgscm/scheme.c | 140 ++++++++++++++++++--------------------------------
 1 file changed, 51 insertions(+), 89 deletions(-)


hooks/post-receive
-- 
The GNU Privacy Guard
http://git.gnupg.org




More information about the Gnupg-commits mailing list