diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2015-07-13 11:14:50 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2015-07-13 11:14:50 +0900 |
| commit | 02474daa14623f3ee24a5235e9b7b88c33d43455 (patch) | |
| tree | 923ca1bed5953d910c62da03e24b79d8d942b194 | |
| parent | 9c311ddc938ad2cc88e4119374e47cd496e15a94 (diff) | |
| download | mruby-02474daa14623f3ee24a5235e9b7b88c33d43455.tar.gz mruby-02474daa14623f3ee24a5235e9b7b88c33d43455.zip | |
allow '!' after 'S' specifier of mrb_get_args() that allow nil.
thus "S!" means String|nil type. you have to check nil before
dereferencing the value. this is added to address #2882 while
keeping code simplicity. besides that current #2882 fix lose
polymorphism provided by mrb_get_args().
| -rw-r--r-- | src/class.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/class.c b/src/class.c index 0f9a77b2a..8a9fdaca6 100644 --- a/src/class.c +++ b/src/class.c @@ -435,7 +435,7 @@ to_sym(mrb_state *mrb, mrb_value ss) ---------------------------------------------------------------------------------------------- o: Object [mrb_value] C: class/module [mrb_value] - S: String [mrb_value] + S: String [mrb_value] when ! follows the value may be nil A: Array [mrb_value] H: Hash [mrb_value] s: String [char*,mrb_int] Receive two arguments. @@ -525,6 +525,14 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) mrb_value *p; p = va_arg(ap, mrb_value*); + if (*format == '!') { + format++; + if (mrb_nil_p(*sp)) { + *p = *sp++; + i++; + break; + } + } if (i < argc) { *p = to_str(mrb, *sp++); i++; |
