ruby-changes:32857
From: nobu <ko1@a...>
Date: Fri, 14 Feb 2014 14:04:11 +0900 (JST)
Subject: [ruby-changes:32857] nobu:r44936 (trunk): gc.c: unit suffix
nobu 2014-02-14 14:04:07 +0900 (Fri, 14 Feb 2014) New Revision: 44936 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44936 Log: gc.c: unit suffix * gc.c (get_envparam_size): accept unit suffix 'k', 'm', and 'g'. Modified files: trunk/gc.c Index: gc.c =================================================================== --- gc.c (revision 44935) +++ gc.c (revision 44936) @@ -5663,16 +5663,39 @@ get_envparam_size(const char *name, size https://github.com/ruby/ruby/blob/trunk/gc.c#L5663 ssize_t val; if (ptr != NULL && *ptr) { + size_t unit = 0; char *end; #if SIZEOF_SIZE_T == SIZEOF_LONG_LONG val = strtoll(ptr, &end, 0); #else val = strtol(ptr, &end, 0); #endif - if (!*ptr || *end) { + switch (*end) { + case 'k': case 'K': + unit = 1024; + ++end; + break; + case 'm': case 'M': + unit = 1024*1024; + ++end; + break; + case 'g': case 'G': + unit = 1024*1024*1024; + ++end; + break; + } + while (*end && isspace(*end)) end++; + if (*end) { if (RTEST(ruby_verbose)) fprintf(stderr, "invalid string for %s: %s\n", name, ptr); return 0; } + if (unit > 0) { + if (val < -(ssize_t)(SIZE_MAX / 2 / unit) || (ssize_t)(SIZE_MAX / 2 / unit) < val) { + if (RTEST(ruby_verbose)) fprintf(stderr, "%s=%s is ignored because it overflows\n", name, ptr); + return 0; + } + val *= unit; + } if (val > 0 && (size_t)val > lower_bound) { if (RTEST(ruby_verbose)) { fprintf(stderr, "%s=%"PRIdSIZE" (default value: %"PRIdSIZE")\n", name, val, *default_value); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/