[前][次][番号順一覧][スレッド一覧]

ruby-changes:33712

From: normal <ko1@a...>
Date: Sat, 3 May 2014 04:21:25 +0900 (JST)
Subject: [ruby-changes:33712] normal:r45793 (trunk): avoid large alloca on Complex/Rational calls

normal	2014-05-03 04:21:18 +0900 (Sat, 03 May 2014)

  New Revision: 45793

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45793

  Log:
    avoid large alloca on Complex/Rational calls
    
    * complex.c (parse_comp): replace ALLOCA_N with ALLOCV_N/ALLOCV_END
      [Bug #9608]
    * rational.c (read_digits): ditto

  Modified files:
    trunk/ChangeLog
    trunk/complex.c
    trunk/rational.c
Index: complex.c
===================================================================
--- complex.c	(revision 45792)
+++ complex.c	(revision 45793)
@@ -1726,19 +1726,26 @@ parse_comp(const char *s, int strict, https://github.com/ruby/ruby/blob/trunk/complex.c#L1726
 	   VALUE *num)
 {
     char *buf, *b;
+    VALUE tmp;
+    int ret = 1;
 
-    buf = ALLOCA_N(char, strlen(s) + 1);
+    buf = ALLOCV_N(char, tmp, strlen(s) + 1);
     b = buf;
 
     skip_ws(&s);
-    if (!read_comp(&s, strict, num, &b))
-	return 0;
-    skip_ws(&s);
+    if (!read_comp(&s, strict, num, &b)) {
+	ret = 0;
+    }
+    else {
+	skip_ws(&s);
+
+	if (strict)
+	    if (*s != '\0')
+		ret = 0;
+    }
+    ALLOCV_END(tmp);
 
-    if (strict)
-	if (*s != '\0')
-	    return 0;
-    return 1;
+    return ret;
 }
 
 static VALUE
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 45792)
+++ ChangeLog	(revision 45793)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat May  3 04:04:16 2014  Eric Wong  <e@8...>
+
+	* complex.c (parse_comp): replace ALLOCA_N with ALLOCV_N/ALLOCV_END
+	  [Bug #9608]
+	* rational.c (read_digits): ditto
+
 Sat May  3 00:06:30 2014  Naohisa Goto  <ngotogenome@g...>
 
 	* file.c (HAVE_STRUCT_STATVFS_F_BASETYPE): File::Statfs#fstypename
Index: rational.c
===================================================================
--- rational.c	(revision 45792)
+++ rational.c	(revision 45793)
@@ -2136,13 +2136,14 @@ read_digits(const char **s, int strict, https://github.com/ruby/ruby/blob/trunk/rational.c#L2136
 {
     char *b, *bb;
     int us = 1, ret = 1;
+    VALUE tmp;
 
     if (!isdecimal(**s)) {
 	*num = ZERO;
 	return 0;
     }
 
-    bb = b = ALLOCA_N(char, strlen(*s) + 1);
+    bb = b = ALLOCV_N(char, tmp, strlen(*s) + 1);
 
     while (isdecimal(**s) || **s == '_') {
 	if (**s == '_') {
@@ -2169,6 +2170,7 @@ read_digits(const char **s, int strict, https://github.com/ruby/ruby/blob/trunk/rational.c#L2170
   conv:
     *b = '\0';
     *num = rb_cstr_to_inum(bb, 10, 0);
+    ALLOCV_END(tmp);
     return ret;
 }
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]