[svn:parrot] r46230 - trunk/src/dynpmc

chromatic at svn.parrot.org chromatic at svn.parrot.org
Mon May 3 07:55:30 UTC 2010


Author: chromatic
Date: Mon May  3 07:55:30 2010
New Revision: 46230
URL: https://trac.parrot.org/parrot/changeset/46230

Log:
[dynpmc] Fixed some compilation warnings in GzipHandle PMC.

Modified:
   trunk/src/dynpmc/gziphandle.pmc

Modified: trunk/src/dynpmc/gziphandle.pmc
==============================================================================
--- trunk/src/dynpmc/gziphandle.pmc	Mon May  3 07:55:26 2010	(r46229)
+++ trunk/src/dynpmc/gziphandle.pmc	Mon May  3 07:55:30 2010	(r46230)
@@ -76,20 +76,23 @@
 */
     METHOD open(STRING *filename, STRING *mode :optional,
                                INTVAL has_mode :opt_flag) {
+        char *path  = Parrot_str_to_cstring(INTERP, filename);
         gzFile file;
-        char *path;
-        char *mod = (char *)"rb";
-        path = Parrot_str_to_cstring(INTERP, filename);
-        if (has_mode)
-            mod = Parrot_str_to_cstring(INTERP, mode);
-        file = gzopen(path, mod);
-        Parrot_str_free_cstring(path);
-        if (has_mode)
+
+        if (has_mode) {
+            char *mod = Parrot_str_to_cstring(INTERP, mode);
+            file      = gzopen(path, mod);
             Parrot_str_free_cstring(mod);
-        if (NULL == file) {
+        }
+        else
+            file = gzopen(path, "rb");
+
+        Parrot_str_free_cstring(path);
+
+        if (!file)
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
                 "gzopen fails");
-        }
+
         SET_ATTR_file(INTERP, SELF, file);
         RETURN(PMC SELF);
     }
@@ -246,20 +249,24 @@
         STRING *dst = NULL;
         UINTVAL srcLen, bufSize, dstLen;
         char *src = Parrot_str_to_cstring(INTERP, str);
-        if (NULL == src) {
+
+        if (!src)
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
                 "failed to allocate");
-        }
-        srcLen = Parrot_str_byte_length(INTERP, str);
+
+        srcLen  = Parrot_str_byte_length(INTERP, str);
         bufSize = 12 + srcLen + srcLen / 1000;
-        buf = mem_allocate_n_zeroed_typed(bufSize, char);
-        if (NULL == buf) {
+        buf     = mem_allocate_n_zeroed_typed(bufSize, char);
+
+        if (!buf) {
             Parrot_str_free_cstring(src);
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
                 "failed to allocate");
         }
+
         rc = compress((Bytef *)buf, &dstLen, (const Bytef *)src, srcLen);
         Parrot_str_free_cstring(src);
+
         switch (rc) {
           case Z_OK:
             dst = Parrot_str_new(INTERP, buf, dstLen);
@@ -277,7 +284,12 @@
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
                 "output buffer error");
             break;
+
+          default:
+            /* these are the only three documented return values */
+            break;
         }
+
         RETURN(STRING *dst);
     }
 


More information about the parrot-commits mailing list