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

ruby-changes:38838

From: nobu <ko1@a...>
Date: Tue, 16 Jun 2015 18:47:24 +0900 (JST)
Subject: [ruby-changes:38838] nobu:r50919 (trunk): date_parse.c: use ALLOCV

nobu	2015-06-16 18:46:06 +0900 (Tue, 16 Jun 2015)

  New Revision: 50919

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

  Log:
    date_parse.c: use ALLOCV
    
    * ext/date/date_parse.c (s3e, date_zone_to_diff, parse_ddd_cb):
      use ALLOCV instead of ALLOCA get rid of stack overflow.

  Modified files:
    trunk/ext/date/date_parse.c
Index: ext/date/date_parse.c
===================================================================
--- ext/date/date_parse.c	(revision 50918)
+++ ext/date/date_parse.c	(revision 50919)
@@ -68,6 +68,7 @@ static const char *abbr_months[] = { https://github.com/ruby/ruby/blob/trunk/ext/date/date_parse.c#L68
 static void
 s3e(VALUE hash, VALUE y, VALUE m, VALUE d, int bc)
 {
+    VALUE vbuf = 0;
     VALUE c = Qnil;
 
     if (!RB_TYPE_P(m, T_STRING))
@@ -164,10 +165,11 @@ s3e(VALUE hash, VALUE y, VALUE m, VALUE https://github.com/ruby/ruby/blob/trunk/ext/date/date_parse.c#L165
 	{
 	    char *buf;
 
-	    buf = ALLOCA_N(char, ep - bp + 1);
+	    buf = ALLOCV_N(char, vbuf, ep - bp + 1);
 	    memcpy(buf, bp, ep - bp);
 	    buf[ep - bp] = '\0';
 	    iy = cstr2num(buf);
+	    ALLOCV_END(vbuf);
 	}
 	set_hash("year", iy);
     }
@@ -189,10 +191,11 @@ s3e(VALUE hash, VALUE y, VALUE m, VALUE https://github.com/ruby/ruby/blob/trunk/ext/date/date_parse.c#L191
 	{
 	    char *buf;
 
-	    buf = ALLOCA_N(char, ep - bp + 1);
+	    buf = ALLOCV_N(char, vbuf, ep - bp + 1);
 	    memcpy(buf, bp, ep - bp);
 	    buf[ep - bp] = '\0';
 	    im = cstr2num(buf);
+	    ALLOCV_END(vbuf);
 	}
 	set_hash("mon", im);
     }
@@ -211,10 +214,11 @@ s3e(VALUE hash, VALUE y, VALUE m, VALUE https://github.com/ruby/ruby/blob/trunk/ext/date/date_parse.c#L214
 	{
 	    char *buf;
 
-	    buf = ALLOCA_N(char, ep - bp + 1);
+	    buf = ALLOCV_N(char, vbuf, ep - bp + 1);
 	    memcpy(buf, bp, ep - bp);
 	    buf[ep - bp] = '\0';
 	    id = cstr2num(buf);
+	    ALLOCV_END(vbuf);
 	}
 	set_hash("mday", id);
     }
@@ -420,6 +424,7 @@ VALUE https://github.com/ruby/ruby/blob/trunk/ext/date/date_parse.c#L424
 date_zone_to_diff(VALUE str)
 {
     VALUE offset = Qnil;
+    VALUE vbuf = 0;
 
     long l, i;
     char *s, *dest, *d;
@@ -428,7 +433,7 @@ date_zone_to_diff(VALUE str) https://github.com/ruby/ruby/blob/trunk/ext/date/date_parse.c#L433
     l = RSTRING_LEN(str);
     s = RSTRING_PTR(str);
 
-    dest = d = ALLOCA_N(char, l + 1);
+    dest = d = ALLOCV_N(char, vbuf, l + 1);
 
     for (i = 0; i < l; i++) {
 	if (isspace((unsigned char)s[i]) || s[i] == '\0') {
@@ -543,9 +548,10 @@ date_zone_to_diff(VALUE str) https://github.com/ruby/ruby/blob/trunk/ext/date/date_parse.c#L548
 		    goto num;
 		}
 		if (strpbrk(RSTRING_PTR(str), ",.")) {
+		    VALUE astr = 0;
 		    char *a, *b;
 
-		    a = ALLOCA_N(char, RSTRING_LEN(str) + 1);
+		    a = ALLOCV_N(char, astr, RSTRING_LEN(str) + 1);
 		    strcpy(a, RSTRING_PTR(str));
 		    b = strpbrk(a, ",.");
 		    *b = '\0';
@@ -557,6 +563,7 @@ date_zone_to_diff(VALUE str) https://github.com/ruby/ruby/blob/trunk/ext/date/date_parse.c#L563
 				 f_expt(INT2FIX(10),
 					LONG2NUM((long)strlen(b)))),
 				INT2FIX(60));
+		    ALLOCV_END(astr);
 		    goto num;
 		}
 		{
@@ -605,6 +612,7 @@ date_zone_to_diff(VALUE str) https://github.com/ruby/ruby/blob/trunk/ext/date/date_parse.c#L612
     }
     RB_GC_GUARD(str);
   ok:
+    ALLOCV_END(vbuf);
     return offset;
 }
 
@@ -1975,7 +1983,8 @@ parse_ddd_cb(VALUE m, VALUE hash) https://github.com/ruby/ruby/blob/trunk/ext/date/date_parse.c#L1983
 	set_hash("zone", s5);
 
 	if (*cs5 == '[') {
-	    char *buf = ALLOCA_N(char, l5 + 1);
+	    VALUE vbuf = 0;
+	    char *buf = ALLOCV_N(char, vbuf, l5 + 1);
 	    char *s1, *s2, *s3;
 	    VALUE zone;
 
@@ -1997,6 +2006,7 @@ parse_ddd_cb(VALUE m, VALUE hash) https://github.com/ruby/ruby/blob/trunk/ext/date/date_parse.c#L2006
 	    if (isdigit((unsigned char)*s1))
 		*--s1 = '+';
 	    set_hash("offset", date_zone_to_diff(rb_str_new2(s1)));
+	    ALLOCV_END(vbuf);
 	}
 	RB_GC_GUARD(s5);
     }

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

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