Index: gimp/plug-ins/script-fu/tinyscheme/scheme-private.h
===================================================================
RCS file: /cvs/gnome/gimp/plug-ins/script-fu/tinyscheme/scheme-private.h,v
retrieving revision 1.8
diff -p -u -u -r1.8 scheme-private.h
--- gimp/plug-ins/script-fu/tinyscheme/scheme-private.h	23 Nov 2006 21:14:01 -0000	1.8
+++ gimp/plug-ins/script-fu/tinyscheme/scheme-private.h	12 Dec 2006 22:14:37 -0000
@@ -36,6 +36,7 @@ struct cell {
   union {
     struct {
       char   *_svalue;
+      char   *_skey;
       int   _length;
     } _string;
     num _number;
Index: gimp/plug-ins/script-fu/tinyscheme/scheme.c
===================================================================
RCS file: /cvs/gnome/gimp/plug-ins/script-fu/tinyscheme/scheme.c,v
retrieving revision 1.25
diff -p -u -u -r1.25 scheme.c
--- gimp/plug-ins/script-fu/tinyscheme/scheme.c	7 Dec 2006 18:57:10 -0000	1.25
+++ gimp/plug-ins/script-fu/tinyscheme/scheme.c	12 Dec 2006 22:14:38 -0000
@@ -46,6 +46,11 @@
 
 #include "scheme-private.h"
 
+#include <strings.h>
+# ifndef __APPLE__
+#  define stricmp strcasecmp
+# endif
+
 /* Used for documentation purposes, to signal functions in 'interface' */
 #define INTERFACE
 
@@ -78,23 +83,6 @@
 # include <malloc.h>
 #endif
 
-#define stricmp utf8_stricmp
-
-static int utf8_stricmp(const char *s1, const char *s2)
-{
-  char *s1a, *s2a;
-  int result;
-
-  s1a = g_utf8_casefold(s1, -1);
-  s2a = g_utf8_casefold(s2, -1);
-
-  result = g_utf8_collate(s1a, s2a);
-
-  g_free(s1a);
-  g_free(s2a);
-  return result;
-}
-
 #define min(a, b)  ((a <= b) ? a : b)
 
 #if USE_STRLWR
@@ -176,6 +164,7 @@ static num num_one;
 
 INTERFACE INLINE int is_string(pointer p)     { return (type(p)==T_STRING); }
 #define strvalue(p)      ((p)->_object._string._svalue)
+#define strkey(p)        ((p)->_object._string._skey)
 #define strlength(p)     ((p)->_object._string._length)
 
 INTERFACE static int is_list(scheme *sc, pointer p);
@@ -217,6 +206,8 @@ INTERFACE pointer set_cdr(pointer p, poi
 
 INTERFACE INLINE int is_symbol(pointer p)   { return (type(p)==T_SYMBOL); }
 INTERFACE INLINE char *symname(pointer p)   { return strvalue(car(p)); }
+/* For now, we don't want foreign functions to access the string key */
+INLINE           char *symkey(pointer p)    { return strkey(car(p)); }
 #if USE_PLIST
 SCHEME_EXPORT INLINE int hasprop(pointer p)     { return (typeflag(p)&T_SYMBOL); }
 #define symprop(p)       cdr(p)
@@ -800,15 +791,22 @@ static INLINE pointer oblist_find_by_nam
   int location;
   pointer x;
   char *s;
+  char *key;
+
+  /* case-insensitive, per R5RS section 2. */
+  s = g_utf8_casefold(name, -1);
+  key = g_utf8_collate_key(s, -1);
+  free(s);
 
   location = hash_fn(name, ivalue_unchecked(sc->oblist));
   for (x = vector_elem(sc->oblist, location); x != sc->NIL; x = cdr(x)) {
-    s = symname(car(x));
-    /* case-insensitive, per R5RS section 2. */
-    if(stricmp(name, s) == 0) {
+    s = symkey(car(x));
+    if(strcmp(key, s) == 0) {
+      free(key);
       return car(x);
     }
   }
+  free(key);
   return sc->NIL;
 }
 
@@ -837,14 +835,21 @@ static INLINE pointer oblist_find_by_nam
 {
      pointer x;
      char    *s;
+     char    *key;
+
+     /* case-insensitive, per R5RS section 2. */
+     s = g_utf8_casefold(name, -1);
+     key = g_utf8_collate_key(s, -1);
+     free(s);
 
      for (x = sc->oblist; x != sc->NIL; x = cdr(x)) {
-        s = symname(car(x));
-        /* case-insensitive, per R5RS section 2. */
-        if(stricmp(name, s) == 0) {
+        s = symkey(car(x));
+        if(strcmp(key, s) == 0) {
+          free(key);
           return car(x);
         }
      }
+     free(key);
      return sc->NIL;
 }
 
@@ -979,19 +984,27 @@ INTERFACE pointer mk_string(scheme *sc, 
 /* len is the length of str in characters */
 INTERFACE pointer mk_counted_string(scheme *sc, const char *str, int len) {
      pointer x = get_cell(sc, sc->NIL, sc->NIL);
+     char   *s;
 
      strvalue(x) = store_string(sc,len,str,0);
+     s = g_utf8_casefold(strvalue(x), -1);
+     strkey(x) = g_utf8_collate_key(s, -1);
      typeflag(x) = (T_STRING | T_ATOM);
      strlength(x) = len;
+     free(s);
      return (x);
 }
 
 static pointer mk_empty_string(scheme *sc, int len, gunichar fill) {
      pointer x = get_cell(sc, sc->NIL, sc->NIL);
+     char   *s;
 
      strvalue(x) = store_string(sc,len,0,fill);
+     s = g_utf8_casefold(strvalue(x), -1);
+     strkey(x) = g_utf8_collate_key(s, -1);
      typeflag(x) = (T_STRING | T_ATOM);
      strlength(x) = len;
+     free(s);
      return (x);
 }
 
@@ -1312,6 +1325,7 @@ static void gc(scheme *sc, pointer a, po
 static void finalize_cell(scheme *sc, pointer a) {
   if(is_string(a)) {
     sc->free(strvalue(a));
+    sc->free(strkey(a));
   } else if(is_port(a)) {
     if(a->_object._port->kind&port_file
        && a->_object._port->rep.stdio.closeit) {
@@ -3287,7 +3301,11 @@ static pointer opexe_2(scheme *sc, enum 
           newstr[newlen] = '\0';
 
           free(strvalue(a));
+          free(strkey(a));
           strvalue(a)=newstr;
+          p1 = g_utf8_casefold(strvalue(a), -1);
+          strkey(x) = g_utf8_collate_key(p1, -1);
+          free(p1);
           strlength(a)=newlen;
 
           s_return(sc,a);
