[svn:parrot] r47941 - branches/gsoc_nfg/src/packfile

darbelo at svn.parrot.org darbelo at svn.parrot.org
Wed Jun 30 23:50:31 UTC 2010


Author: darbelo
Date: Wed Jun 30 23:50:31 2010
New Revision: 47941
URL: https://trac.parrot.org/parrot/changeset/47941

Log:
Add NFG thaw support.

Modified:
   branches/gsoc_nfg/src/packfile/pf_items.c

Modified: branches/gsoc_nfg/src/packfile/pf_items.c
==============================================================================
--- branches/gsoc_nfg/src/packfile/pf_items.c	Wed Jun 30 23:50:19 2010	(r47940)
+++ branches/gsoc_nfg/src/packfile/pf_items.c	Wed Jun 30 23:50:31 2010	(r47941)
@@ -1228,6 +1228,9 @@
     INTVAL    extra;
     const int wordsize          = pf ? pf->header->wordsize : sizeof (opcode_t);
     opcode_t  flag_charset_word = PF_fetch_opcode(pf, cursor);
+#if PARROT_HAS_ICU
+    grapheme_table *table = NULL;
+#endif
 
     if (flag_charset_word == -1)
         return STRINGNULL;
@@ -1240,7 +1243,28 @@
 
 
     size = (size_t)PF_fetch_opcode(pf, cursor);
-    extra = (size_t)PF_fetch_opcode(pf, cursor);
+    extra = PF_fetch_opcode(pf, cursor);
+
+    if (extra) {
+#if PARROT_HAS_ICU
+        INTVAL i;
+        table = create_grapheme_table(interp, extra);
+        for (i = 0; i < extra; i++) {
+            table->graphemes[i].len = *cursor++;
+            table->graphemes[i].hash = 0;
+            table->graphemes[i].codepoints =
+                mem_gc_allocate_n_typed(interp, table->graphemes[i].len, UChar32);
+
+            memcpy(table->graphemes[i].codepoints, cursor,
+                   table->graphemes[i].len * sizeof (UChar32));
+            cursor += ((table->graphemes[i].len * sizeof (UChar32)) 
+                      / sizeof (opcode_t)) + 1;
+        } 
+        table->used = extra;
+#else
+        Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_LIBRARY_ERROR, "no ICU lib loaded");
+#endif /* PARROT_HAS_ICU */
+    }
 
     TRACE_PRINTF(("PF_fetch_string(): flags=0x%04x, ", flags));
     TRACE_PRINTF(("encoding_nr=%ld, ", encoding_nr));
@@ -1259,10 +1283,9 @@
     s = Parrot_str_new_init(interp, (const char *)*cursor, size,
             encoding, charset, flags);
 
-    if (extra) {
-        // TODO.
-        Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_LIBRARY_ERROR, "no ICU lib loaded");
-    }
+#if PARROT_HAS_ICU
+    s->extra = rehash_grapheme_table(interp, table);
+#endif /* PARROT_HAS_ICU */
 
     /* print only printable characters */
     TRACE_PRINTF_VAL(("PF_fetch_string(): string is '%s' at 0x%x\n",
@@ -1336,23 +1359,22 @@
        INTVAL i = 0;
        *cursor++ = table->used;
 
-       while (i++ < table->used) {
-           char *auxcursor;
-           INTVAL len = table->graphemes[i].len;
-           /* Store the length and then memcpy() the codepoints over. */
-           *cursor++ = len;
-           auxcursor = (char *) memcpy(cursor, table->graphemes[i].codepoints,
-                                       len * sizeof (UChar32));
-
-           /* Adjust the cursor, and auxcursor ... */
-           cursor += ((len * sizeof (UChar32)) / sizeof (opcode_t)) + 1;
-           auxcursor += len * sizeof (UChar32);
-
-           /* ...and pad the difference with zeros. */
-           while ((unsigned long) (auxcursor - (char *) cursor) % sizeof (opcode_t)) {
-               *charcursor++ = 0;
-           }
-       }
+        while (i++ < table->used) {
+            char *auxcursor;
+            INTVAL len = table->graphemes[i].len;
+            /* Store the length and then memcpy() the codepoints over. */
+            *cursor++ = len;
+            auxcursor = (char *) memcpy(cursor, table->graphemes[i].codepoints,
+                                        len * sizeof (UChar32));
+
+            /* Adjust the cursor, and auxcursor ... */
+            cursor += ((len * sizeof (UChar32)) / sizeof (opcode_t)) + 1;
+            auxcursor += len * sizeof (UChar32); 
+
+            /* ...and pad the difference with zeros. */
+            while ((unsigned long) (auxcursor - (char *) cursor) % sizeof (opcode_t))
+                *charcursor++ = 0;
+        }
     }
     else {
         *cursor++ = 0;


More information about the parrot-commits mailing list