[gimp/gimp-2-6] Fixed issue with list length mentioned in comment 18 of bug #499443.



commit 8d93ae092bf4181964a049d4e3d70351be299844
Author: Kevin Cozens <kcozens cvs gnome org>
Date:   Tue Jun 1 17:10:57 2010 -0400

    Fixed issue with list length mentioned in comment 18 of bug #499443.
    
    Applied changes from CVS version 1.24 of official version of TinyScheme.
    Merged redundant list_length, is_list, OP_LISTP code.
    (backport of commit 4c862bf6787986d30d1cd83c3acd9df9e07cbe57)

 plug-ins/script-fu/tinyscheme/scheme.c |   46 ++++++++++---------------------
 1 files changed, 15 insertions(+), 31 deletions(-)
---
diff --git a/plug-ins/script-fu/tinyscheme/scheme.c b/plug-ins/script-fu/tinyscheme/scheme.c
index 3d0b096..c38014d 100644
--- a/plug-ins/script-fu/tinyscheme/scheme.c
+++ b/plug-ins/script-fu/tinyscheme/scheme.c
@@ -3507,34 +3507,15 @@ static pointer opexe_2(scheme *sc, enum scheme_opcodes op) {
      return sc->T;
 }
 
-static int is_list(scheme *sc, pointer a) {
-    pointer slow, fast;
-
-    slow = fast = a;
-    while (1)
-    {
-        if (fast == sc->NIL)
-                return 1;
-        if (!is_pair(fast))
-                return 0;
-        fast = cdr(fast);
-        if (fast == sc->NIL)
-                return 1;
-        if (!is_pair(fast))
-                return 0;
-        fast = cdr(fast);
-
-        slow = cdr(slow);
-        if (fast == slow)
-        {
-            /* the fast pointer has looped back around and caught up
-               with the slow pointer, hence the structure is circular,
-               not of finite length, and therefore not a list */
-            return 0;
-        }
-    }
-}
-
+static int is_list(scheme *sc, pointer a)
+{ return list_length(sc,a) >= 0; }
+
+/* Result is:
+   proper list: length
+   circular list: -1
+   not even a pair: -2
+   dotted list: -2 minus length before dot
+*/
 int list_length(scheme *sc, pointer a) {
     int i=0;
     pointer slow, fast;
@@ -3545,16 +3526,18 @@ int list_length(scheme *sc, pointer a) {
         if (fast == sc->NIL)
                 return i;
         if (!is_pair(fast))
-                return i;
+                return -2 - i;
         fast = cdr(fast);
         ++i;
         if (fast == sc->NIL)
                 return i;
         if (!is_pair(fast))
-                return i;
+                return -2 - i;
         ++i;
         fast = cdr(fast);
 
+    /* Safe because we would have already returned if `fast'
+       encountered a non-pair. */
         slow = cdr(slow);
         if (fast == slow)
         {
@@ -3645,7 +3628,8 @@ static pointer opexe_3(scheme *sc, enum scheme_opcodes op) {
      case OP_PAIRP:       /* pair? */
           s_retbool(is_pair(car(sc->args)));
      case OP_LISTP:       /* list? */
-          s_retbool(is_list(sc, car(sc->args)));
+          s_retbool(list_length(sc, car(sc->args)) >= 0);
+
      case OP_ENVP:        /* environment? */
           s_retbool(is_environment(car(sc->args)));
      case OP_VECTORP:     /* vector? */



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