diff options
| author | mirichi <[email protected]> | 2013-06-14 20:01:03 +0900 |
|---|---|---|
| committer | mirichi <[email protected]> | 2013-06-14 20:01:03 +0900 |
| commit | a5f63e486473595d67601851f00b6bb96b377a8d (patch) | |
| tree | 8550bf598238104c6490d15ad2db20d4c103ea75 | |
| parent | 4b2bdbe2cc0e3b1b0f6916bdc308933f17f74537 (diff) | |
| parent | dbc93621c94b9b2d2b437cde40d8efec7337a64d (diff) | |
| download | mruby-a5f63e486473595d67601851f00b6bb96b377a8d.tar.gz mruby-a5f63e486473595d67601851f00b6bb96b377a8d.zip | |
Merge remote-tracking branch 'upstream/master'
| -rw-r--r-- | include/mrbconf.h | 68 | ||||
| -rw-r--r-- | include/mruby.h | 4 | ||||
| -rw-r--r-- | include/mruby/value.h | 69 | ||||
| -rw-r--r-- | src/class.c | 13 | ||||
| -rw-r--r-- | src/gc.c | 12 | ||||
| -rw-r--r-- | src/numeric.c | 1 | ||||
| -rw-r--r-- | src/parse.y | 2 | ||||
| -rw-r--r-- | src/state.c | 12 | ||||
| -rw-r--r-- | test/t/class.rb | 17 |
9 files changed, 111 insertions, 87 deletions
diff --git a/include/mrbconf.h b/include/mrbconf.h index 0d65ae13a..57148d428 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -7,9 +7,6 @@ #ifndef MRUBYCONF_H #define MRUBYCONF_H -#include <stdint.h> -#include <stddef.h> - /* configuration options: */ /* add -DMRB_USE_FLOAT to use float instead of double for floating point numbers */ //#define MRB_USE_FLOAT @@ -67,49 +64,6 @@ /* end of configuration */ -#ifdef MRB_USE_FLOAT - typedef float mrb_float; -# define mrb_float_to_str(buf, i) sprintf(buf, "%.7e", i) -# define str_to_mrb_float(buf) strtof(buf, NULL) -#else - typedef double mrb_float; -# define mrb_float_to_str(buf, i) sprintf(buf, "%.16e", i) -# define str_to_mrb_float(buf) strtod(buf, NULL) -#endif - -#if defined(MRB_INT16) && defined(MRB_INT64) -# error "You can't define MRB_INT16 and MRB_INT64 at the same time." -#endif - -#if defined(MRB_INT64) -# ifdef MRB_NAN_BOXING -# error Cannot use NaN boxing when mrb_int is 64bit -# else - typedef int64_t mrb_int; -# define MRB_INT_MIN INT64_MIN -# define MRB_INT_MAX INT64_MAX -# define PRIdMRB_INT PRId64 -# define PRIiMRB_INT PRIi64 -# define PRIoMRB_INT PRIo64 -# define PRIxMRB_INT PRIx64 -# define PRIXMRB_INT PRIX64 -# endif -#elif defined(MRB_INT16) - typedef int16_t mrb_int; -# define MRB_INT_MIN INT16_MIN -# define MRB_INT_MAX INT16_MAX -#else - typedef int32_t mrb_int; -# define MRB_INT_MIN INT32_MIN -# define MRB_INT_MAX INT32_MAX -# define PRIdMRB_INT PRId32 -# define PRIiMRB_INT PRIi32 -# define PRIoMRB_INT PRIo32 -# define PRIxMRB_INT PRIx32 -# define PRIXMRB_INT PRIX32 -#endif -typedef short mrb_sym; - /* define ENABLE_XXXX from DISABLE_XXX */ #ifndef DISABLE_STDIO #define ENABLE_STDIO @@ -118,28 +72,6 @@ typedef short mrb_sym; #define DISABLE_DEBUG #endif -#ifdef _MSC_VER -# define _ALLOW_KEYWORD_MACROS -# include <float.h> -# define inline __inline -# define snprintf _snprintf -# define isnan _isnan -# define isinf(n) (!_finite(n) && !_isnan(n)) -# define strtoll _strtoi64 -# define PRId32 "I32d" -# define PRIi32 "I32i" -# define PRIo32 "I32o" -# define PRIx32 "I32x" -# define PRIX32 "I32X" -# define PRId64 "I64d" -# define PRIi64 "I64i" -# define PRIo64 "I64o" -# define PRIx64 "I64x" -# define PRIX64 "I64X" -#else -# include <inttypes.h> -#endif - #ifdef ENABLE_STDIO # include <stdio.h> #endif diff --git a/include/mruby.h b/include/mruby.h index ce2fa79ae..33a15de0e 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -32,8 +32,10 @@ extern "C" { #endif -#include "mrbconf.h" +#include <stdint.h> +#include <stddef.h> +#include "mrbconf.h" #include "mruby/value.h" typedef uint32_t mrb_code; diff --git a/include/mruby/value.h b/include/mruby/value.h index 86f51eae2..06241ec76 100644 --- a/include/mruby/value.h +++ b/include/mruby/value.h @@ -7,6 +7,71 @@ #ifndef MRUBY_VALUE_H #define MRUBY_VALUE_H +#ifdef MRB_USE_FLOAT + typedef float mrb_float; +# define mrb_float_to_str(buf, i) sprintf(buf, "%.7e", i) +# define str_to_mrb_float(buf) strtof(buf, NULL) +#else + typedef double mrb_float; +# define mrb_float_to_str(buf, i) sprintf(buf, "%.16e", i) +# define str_to_mrb_float(buf) strtod(buf, NULL) +#endif + +#if defined(MRB_INT16) && defined(MRB_INT64) +# error "You can't define MRB_INT16 and MRB_INT64 at the same time." +#endif + +#if defined(MRB_INT64) +# ifdef MRB_NAN_BOXING +# error Cannot use NaN boxing when mrb_int is 64bit +# else + typedef int64_t mrb_int; +# define MRB_INT_MIN INT64_MIN +# define MRB_INT_MAX INT64_MAX +# define PRIdMRB_INT PRId64 +# define PRIiMRB_INT PRIi64 +# define PRIoMRB_INT PRIo64 +# define PRIxMRB_INT PRIx64 +# define PRIXMRB_INT PRIX64 +# endif +#elif defined(MRB_INT16) + typedef int16_t mrb_int; +# define MRB_INT_MIN INT16_MIN +# define MRB_INT_MAX INT16_MAX +#else + typedef int32_t mrb_int; +# define MRB_INT_MIN INT32_MIN +# define MRB_INT_MAX INT32_MAX +# define PRIdMRB_INT PRId32 +# define PRIiMRB_INT PRIi32 +# define PRIoMRB_INT PRIo32 +# define PRIxMRB_INT PRIx32 +# define PRIXMRB_INT PRIX32 +#endif +typedef short mrb_sym; + +#ifdef _MSC_VER +# define _ALLOW_KEYWORD_MACROS +# include <float.h> +# define inline __inline +# define snprintf _snprintf +# define isnan _isnan +# define isinf(n) (!_finite(n) && !_isnan(n)) +# define strtoll _strtoi64 +# define PRId32 "I32d" +# define PRIi32 "I32i" +# define PRIo32 "I32o" +# define PRIx32 "I32x" +# define PRIX32 "I32X" +# define PRId64 "I64d" +# define PRIi64 "I64i" +# define PRIo64 "I64o" +# define PRIx64 "I64x" +# define PRIX64 "I64X" +#else +# include <inttypes.h> +#endif + typedef uint8_t mrb_bool; struct mrb_state; @@ -16,6 +81,10 @@ struct mrb_state; # error ---->> MRB_NAN_BOXING and MRB_USE_FLOAT conflict <<---- #endif +#ifdef MRB_INT64 +# error ---->> MRB_NAN_BOXING and MRB_INT64 conflict <<---- +#endif + enum mrb_vtype { MRB_TT_FALSE = 1, /* 1 */ MRB_TT_FREE, /* 2 */ diff --git a/src/class.c b/src/class.c index 4264129b6..f94f9a933 100644 --- a/src/class.c +++ b/src/class.c @@ -1047,6 +1047,9 @@ mrb_instance_new(mrb_state *mrb, mrb_value cv) mrb_value *argv; int argc; + if (c->tt == MRB_TT_SCLASS) + mrb_raise(mrb, E_TYPE_ERROR, "can't create instance of singleton class"); + if (ttype == 0) ttype = MRB_TT_OBJECT; o = (struct RObject*)mrb_obj_alloc(mrb, ttype, c); obj = mrb_obj_value(o); @@ -1414,14 +1417,17 @@ mrb_mod_alias(mrb_state *mrb, mrb_value mod) return mrb_nil_value(); } - static void undef_method(mrb_state *mrb, struct RClass *c, mrb_sym a) { mrb_value m; - MRB_SET_VALUE(m, MRB_TT_PROC, value.p, 0); - mrb_define_method_vm(mrb, c, a, m); + if (!mrb_obj_respond_to(c, a)) { + mrb_name_error(mrb, a, "undefined method '%S' for class '%S'", mrb_sym2str(mrb, a), mrb_obj_value(c)); + } else { + MRB_SET_VALUE(m, MRB_TT_PROC, value.p, 0); + mrb_define_method_vm(mrb, c, a, m); + } } void @@ -1873,7 +1879,6 @@ mrb_init_class(mrb_state *mrb) mrb_name_class(mrb, mod, mrb_intern(mrb, "Module")); mrb_name_class(mrb, cls, mrb_intern(mrb, "Class")); - mrb_undef_method(mrb, mod, "new"); MRB_SET_INSTANCE_TT(cls, MRB_TT_CLASS); mrb_define_method(mrb, bob, "initialize", mrb_bob_init, MRB_ARGS_NONE()); mrb_define_method(mrb, bob, "!", mrb_bob_not, MRB_ARGS_NONE()); @@ -184,15 +184,19 @@ mrb_malloc(mrb_state *mrb, size_t len) void* mrb_calloc(mrb_state *mrb, size_t nelem, size_t len) { - void *p = NULL; - size_t size; + void *p; - if (nelem <= SIZE_MAX / len) { + if (nelem > 0 && len > 0 && + nelem <= SIZE_MAX / len) { + size_t size; size = nelem * len; p = mrb_realloc(mrb, 0, size); - if (p && size > 0) + if (p) { memset(p, 0, size); + } + } else { + p = NULL; } return p; diff --git a/src/numeric.c b/src/numeric.c index 6b118dfb4..6cd82d8b6 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -1374,7 +1374,6 @@ mrb_init_numeric(mrb_state *mrb) mrb_define_method(mrb, integer, "to_int", int_to_i, MRB_ARGS_NONE()); fixnum = mrb->fixnum_class = mrb_define_class(mrb, "Fixnum", integer); - mrb_undef_class_method(mrb, fixnum, "new"); mrb_define_method(mrb, fixnum, "+", fix_plus, MRB_ARGS_REQ(1)); /* 15.2.8.3.1 */ mrb_define_method(mrb, fixnum, "-", fix_minus, MRB_ARGS_REQ(1)); /* 15.2.8.3.2 */ mrb_define_method(mrb, fixnum, "-@", fix_uminus, MRB_ARGS_REQ(1)); /* 15.2.7.4.2 */ diff --git a/src/parse.y b/src/parse.y index 54e8eafce..f5dbdb6fd 100644 --- a/src/parse.y +++ b/src/parse.y @@ -4925,7 +4925,7 @@ parser_yylex(parser_state *p) pushback(p, c); } } - if (result == 0 && isupper((int)tok(p)[0])) { + if (result == 0 && isupper((int)(unsigned char)tok(p)[0])) { result = tCONSTANT; } else { diff --git a/src/state.c b/src/state.c index 76b506d3e..34de1e45e 100644 --- a/src/state.c +++ b/src/state.c @@ -21,12 +21,22 @@ inspect_main(mrb_state *mrb, mrb_value mod) return mrb_str_new(mrb, "main", 4); } +#ifdef MRB_NAN_BOXING +#include <assert.h> +#endif + mrb_state* mrb_open_allocf(mrb_allocf f, void *ud) { static const mrb_state mrb_state_zero = { 0 }; static const struct mrb_context mrb_context_zero = { 0 }; - mrb_state *mrb = (mrb_state *)(f)(NULL, NULL, sizeof(mrb_state), ud); + mrb_state *mrb; + +#ifdef MRB_NAN_BOXING + assert(sizeof(void*) == 4); +#endif + + mrb = (mrb_state *)(f)(NULL, NULL, sizeof(mrb_state), ud); if (mrb == NULL) return NULL; *mrb = mrb_state_zero; diff --git a/test/t/class.rb b/test/t/class.rb index 72214a2fc..c558c6437 100644 --- a/test/t/class.rb +++ b/test/t/class.rb @@ -30,13 +30,9 @@ assert('Class#initialize_copy', '15.2.3.3.2') do end assert('Class#new', '15.2.3.3.3') do - # at the moment no exception on singleton class - #e1 = nil - #begin - # class1 = e1.singleton_class.new - #rescue => e1 - # e2 = e1 - #end + assert_raise(TypeError, 'Singleton should raise TypeError') do + "a".singleton_class.new + end class TestClass def initialize args, &block @@ -304,3 +300,10 @@ assert('Class Undef 2') do result1 == true and result2 == true end +assert('Var undef') do + assert_raise(NameError) do + a=1 + undef a + end +end + |
