aboutsummaryrefslogtreecommitdiffstats
path: root/gc.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-02-14 05:04:07 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-02-14 05:04:07 +0000
commitaff08cfcd78e3fd711559a4519091e04b803c2bd (patch)
tree013519fbf0e67658128c7f4ca2a732bc2c374546 /gc.c
parent4d33c0e965a1ccce82f7e26a0ef21fef6bef3d2b (diff)
downloadruby-aff08cfcd78e3fd711559a4519091e04b803c2bd.tar.gz
gc.c: unit suffix
* gc.c (get_envparam_size): accept unit suffix 'k', 'm', and 'g'. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44936 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/gc.c b/gc.c
index b3ee9b7c52..e1ecec860f 100644
--- a/gc.c
+++ b/gc.c
@@ -5663,16 +5663,39 @@ get_envparam_size(const char *name, size_t *default_value, size_t lower_bound)
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);