[macruby-changes] [2057] MacRuby/branches/experimental/ext/digest

source_changes at macosforge.org source_changes at macosforge.org
Wed Jul 22 17:53:14 PDT 2009


Revision: 2057
          http://trac.macosforge.org/projects/ruby/changeset/2057
Author:   lsansonetti at apple.com
Date:     2009-07-22 17:53:12 -0700 (Wed, 22 Jul 2009)
Log Message:
-----------
fixing a few bugs

Modified Paths:
--------------
    MacRuby/branches/experimental/ext/digest/bubblebabble/bubblebabble.c
    MacRuby/branches/experimental/ext/digest/digest.c

Modified: MacRuby/branches/experimental/ext/digest/bubblebabble/bubblebabble.c
===================================================================
--- MacRuby/branches/experimental/ext/digest/bubblebabble/bubblebabble.c	2009-07-23 00:27:22 UTC (rev 2056)
+++ MacRuby/branches/experimental/ext/digest/bubblebabble/bubblebabble.c	2009-07-23 00:53:12 UTC (rev 2057)
@@ -19,9 +19,8 @@
 static VALUE
 bubblebabble_str_new(VALUE str_digest)
 {
-    char *digest;
+    const char *digest;
     size_t digest_len;
-    VALUE str;
     char *p;
     int i, j, seed = 1;
     static const char vowels[] = {
@@ -40,8 +39,8 @@
 	rb_raise(rb_eRuntimeError, "digest string too long");
     }
 
-    str = rb_str_new(0, (digest_len | 1) * 3 + 2);
-    p = RSTRING_PTR(str);
+    const size_t p_len = (digest_len | 1) * 3 + 2;
+    p = (char *)alloca(p_len + 1);
 
     i = j = 0;
     p[j++] = 'x';
@@ -75,7 +74,7 @@
 
     p[j] = 'x';
 
-    return str;
+    return rb_str_new(p, p_len);
 }
 
 /*

Modified: MacRuby/branches/experimental/ext/digest/digest.c
===================================================================
--- MacRuby/branches/experimental/ext/digest/digest.c	2009-07-23 00:27:22 UTC (rev 2056)
+++ MacRuby/branches/experimental/ext/digest/digest.c	2009-07-23 00:53:12 UTC (rev 2057)
@@ -34,10 +34,9 @@
 static VALUE
 hexencode_str_new(VALUE str_digest)
 {
-    char *digest;
+    const char *digest;
     size_t digest_len;
     int i;
-    VALUE str;
     char *p;
     static const char hex[] = {
         '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
@@ -52,16 +51,17 @@
         rb_raise(rb_eRuntimeError, "digest string too long");
     }
 
-    str = rb_str_new(0, digest_len * 2);
+    const size_t p_len = digest_len * 2;
+    p = (char *)alloca(p_len + 1);
 
-    for (i = 0, p = RSTRING_PTR(str); i < digest_len; i++) {
+    for (i = 0; i < digest_len; i++) {
         unsigned char byte = digest[i];
 
         p[i + i]     = hex[byte >> 4];
         p[i + i + 1] = hex[byte & 0x0f];
     }
 
-    return str;
+    return rb_str_new(p, p_len);
 }
 
 /*
@@ -266,7 +266,7 @@
 {
     VALUE str;
     size_t digest_len = 32;	/* about this size at least */
-    char *cname;
+    const char *cname;
 
     cname = rb_obj_classname(self);
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090722/bb5c3caf/attachment.html>


More information about the macruby-changes mailing list