[svn:parrot] r46391 - in branches/codestring: . config/auto/zlib include/parrot ports/fedora/2.3.0 ports/suse/2.2.0 src/dynpmc src/interp src/pmc src/runcore t/dynpmc t/src tools/dev

coke at svn.parrot.org coke at svn.parrot.org
Fri May 7 15:35:45 UTC 2010


Author: coke
Date: Fri May  7 15:35:45 2010
New Revision: 46391
URL: https://trac.parrot.org/parrot/changeset/46391

Log:
merge latest changes from trunk

Modified:
   branches/codestring/   (props changed)
   branches/codestring/config/auto/zlib/   (props changed)
   branches/codestring/include/parrot/runcore_trace.h   (props changed)
   branches/codestring/ports/fedora/2.3.0/   (props changed)
   branches/codestring/ports/suse/2.2.0/   (props changed)
   branches/codestring/src/dynpmc/gziphandle.pmc
   branches/codestring/src/interp/inter_create.c   (props changed)
   branches/codestring/src/pmc/codestring.pmc
   branches/codestring/src/runcore/cores.c   (props changed)
   branches/codestring/src/runcore/trace.c   (props changed)
   branches/codestring/t/dynpmc/gziphandle.t
   branches/codestring/t/src/embed.t   (props changed)
   branches/codestring/tools/dev/mk_gitignore.pl   (props changed)

Modified: branches/codestring/src/dynpmc/gziphandle.pmc
==============================================================================
--- branches/codestring/src/dynpmc/gziphandle.pmc	Fri May  7 15:02:22 2010	(r46390)
+++ branches/codestring/src/dynpmc/gziphandle.pmc	Fri May  7 15:35:45 2010	(r46391)
@@ -248,7 +248,7 @@
     METHOD compress(STRING *str) {
         int rc;
         char *buf;
-        STRING *dst = NULL;
+        STRING *dst = STRINGNULL;
         UINTVAL srcLen, dstLen;
         char * const src = Parrot_str_to_cstring(INTERP, str);
 
@@ -295,6 +295,62 @@
         RETURN(STRING *dst);
     }
 
+    METHOD uncompress(STRING *str) {
+        int rc;
+        char *buf;
+        STRING *dst = STRINGNULL;
+        UINTVAL srcLen, dstLen;
+        char * const src = Parrot_str_to_cstring(INTERP, str);
+
+        if (!src)
+            Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
+                "failed to allocate");
+
+        srcLen = Parrot_str_byte_length(INTERP, str);
+        dstLen = srcLen;
+    REDO:
+        buf = mem_allocate_n_zeroed_typed(dstLen, char);
+
+        if (!buf) {
+            Parrot_str_free_cstring(src);
+            Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
+                "failed to allocate");
+        }
+
+        rc = uncompress((Bytef *)buf, &dstLen, (const Bytef *)src, srcLen);
+        Parrot_str_free_cstring(src);
+
+        switch (rc) {
+          case Z_OK:
+            dst = Parrot_str_new(INTERP, buf, dstLen);
+            mem_sys_free(buf);
+            break;
+
+          case Z_MEM_ERROR:
+            mem_sys_free(buf);
+            Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
+                "not enough memory");
+            break;
+
+          case Z_BUF_ERROR:
+            mem_sys_free(buf);
+            dstLen *= 2;
+            goto REDO;
+
+          case Z_DATA_ERROR:
+            mem_sys_free(buf);
+            Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
+                "input data corrupted");
+            break;
+
+          default:
+            /* these are the only three documented return values */
+            break;
+        }
+
+        RETURN(STRING *dst);
+    }
+
     METHOD crc32(INTVAL crc, STRING *str) {
         int rc;
         char *buf;

Modified: branches/codestring/src/pmc/codestring.pmc
==============================================================================
--- branches/codestring/src/pmc/codestring.pmc	Fri May  7 15:02:22 2010	(r46390)
+++ branches/codestring/src/pmc/codestring.pmc	Fri May  7 15:35:45 2010	(r46391)
@@ -171,10 +171,9 @@
         }
 
         /* Add a newline if necessary */
-        if ('\n' != Parrot_str_indexed(INTERP, fmt, Parrot_str_byte_length(INTERP, fmt) - 1))
+        if ('\n' != Parrot_str_indexed(INTERP, fmt, Parrot_str_length(INTERP, fmt) - 1))
             VTABLE_push_string(INTERP, stringbuilder, newline);
 
-
         RETURN(PMC *SELF);
     }
 
@@ -205,12 +204,12 @@
             linepos = Parrot_pmc_new(INTERP, enum_class_ResizableIntegerArray);
             /* get the string itself */
             str = SELF.get_string();
-            eos  = Parrot_str_byte_length(INTERP, str);
+            eos  = Parrot_str_length(INTERP, str);
             /* find the first newline, if any */
             jpos = Parrot_str_find_cclass(INTERP, enum_cclass_newline,
                                           str, 0, eos);
             while (jpos < eos) {
-                jpos++;
+                ++jpos;
                 /* add the start of line position */
                 VTABLE_push_integer(INTERP, linepos, jpos);
 

Modified: branches/codestring/t/dynpmc/gziphandle.t
==============================================================================
--- branches/codestring/t/dynpmc/gziphandle.t	Fri May  7 15:02:22 2010	(r46390)
+++ branches/codestring/t/dynpmc/gziphandle.t	Fri May  7 15:35:45 2010	(r46391)
@@ -22,7 +22,7 @@
     .local pmc config_hash, interp
     .local int num_tests
 
-    num_tests = 5
+    num_tests = 6
     plan(num_tests)
     interp = getinterp
     config_hash = interp[.IGLOBALS_CONFIG_HASH]
@@ -65,6 +65,8 @@
     $S0 = $P0.'compress'(data)
     $I0 = length $S0
     is($I0, 15, "compress")
+    $S0 = $P0.'uncompress'($S0)
+    is($S0, data, "uncompress")
 .end
 
 # Local Variables:


More information about the parrot-commits mailing list