From ff47338973feec4b09f0025c1ffd02a6cf6eadaa Mon Sep 17 00:00:00 2001 From: NAKAMURA Usaku Date: Fri, 20 Apr 2012 15:34:41 +0900 Subject: In mruby.h, there is no definitions of RSTRING_* here, so cannot compile if the compiler is not GCC. --- include/mruby.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include') diff --git a/include/mruby.h b/include/mruby.h index 506158d3c..123f802ad 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -441,11 +441,14 @@ void mrb_bug(const char *fmt, ...); #ifdef __GNUC__ # define NUM2CHR(x) __extension__ ({mrb_value num2chr_x = (x); NUM2CHR_internal(num2chr_x);}) #else +/* TODO: there is no definitions of RSTRING_* here, so cannot compile. static inline char NUM2CHR(mrb_value x) { return NUM2CHR_internal(x); } +*/ +#define NUM2CHR(x) NUM2CHR_internal(x) #endif mrb_value mrb_io_gets(mrb_state *mrb, mrb_value); mrb_value mrb_io_getbyte(mrb_state *mrb, mrb_value); -- cgit v1.2.3 From 2161737c2dcae3ad6679d0b7bb752d201d3895a5 Mon Sep 17 00:00:00 2001 From: NAKAMURA Usaku Date: Fri, 20 Apr 2012 15:35:57 +0900 Subject: MRUBY_OBJECT_HEADER is always used with `;', but, in the definition of a struct, you cannot include any statement except declarations, even if the statement is void statement. --- include/mruby/object.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/mruby/object.h b/include/mruby/object.h index 151e36b96..e73ebe79a 100644 --- a/include/mruby/object.h +++ b/include/mruby/object.h @@ -6,7 +6,7 @@ int color:3;\ unsigned int flags:21;\ struct RClass *c;\ - struct RBasic *gcnext; + struct RBasic *gcnext /* white: 011, black: 100, gray: 000 */ -- cgit v1.2.3 From 43683ec87870f8d19767a7fa586433441bb368a2 Mon Sep 17 00:00:00 2001 From: mimaki Date: Fri, 20 Apr 2012 17:03:43 +0900 Subject: add file header in mruby.h --- include/mruby.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'include') diff --git a/include/mruby.h b/include/mruby.h index 123f802ad..8084735bf 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -1,3 +1,29 @@ +/* +** mruby - An embeddable Ruby implementaion +** +** Copyright (c) mruby developers 2010-2012 +** +** Permission is hereby granted, free of charge, to any person obtaining +** a copy of this software and associated documentation files (the +** "Software"), to deal in the Software without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Software, and to +** permit persons to whom the Software is furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be +** included in all copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +** +** [ MIT license: http://www.opensource.org/licenses/mit-license.php ] +*/ #ifndef MRUBY_H #define MRUBY_H -- cgit v1.2.3 From d1144220cb899b24ca949ee230606f76cd4e0b99 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Fri, 20 Apr 2012 17:18:30 +0900 Subject: move src/mdata.h to include/mruby/data.h --- include/mruby/data.h | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/array.c | 1 - src/encoding.h | 2 +- src/etc.c | 1 - src/gc.c | 2 +- src/kernel.c | 1 - src/mdata.h | 53 ---------------------------------------------------- src/object.c | 1 - 8 files changed, 55 insertions(+), 59 deletions(-) create mode 100644 include/mruby/data.h delete mode 100644 src/mdata.h (limited to 'include') diff --git a/include/mruby/data.h b/include/mruby/data.h new file mode 100644 index 000000000..07e0f72cd --- /dev/null +++ b/include/mruby/data.h @@ -0,0 +1,53 @@ +/********************************************************************** + + data.h - + + + Copyright (C) 2007 Yukihiro Matsumoto + +**********************************************************************/ + +#ifndef RUBY_DATA_H +#define RUBY_DATA_H 1 + +#if defined(__cplusplus) +extern "C" { +#endif + + +struct mrb_data_type { + const char *struct_name; + void (*dfree)(mrb_state *mrb, void*); +}; + +struct RData { + MRUBY_OBJECT_HEADER; + struct kh_iv *iv; + struct mrb_data_type *type; + void *data; +}; + +struct RData *mrb_data_object_alloc(mrb_state *mrb, struct RClass* klass, void *datap, const struct mrb_data_type *type); + +#define Data_Wrap_Struct(mrb,klass,type,ptr)\ + mrb_data_object_alloc(mrb,klass,ptr,type) + +#define Data_Make_Struct(mrb,klass,strct,type,sval) (\ + sval = mrb_malloc(mrb, sizeof(strct)),\ + memset(sval, 0, sizeof(strct)),\ + Data_Wrap_Struct(mrb,klass,type,sval)\ +) + +#define RDATA(obj) ((struct RData *)((obj).value.p)) +#define DATA_PTR(d) (RDATA(d)->data) +#define DATA_TYPE(d) (RDATA(d)->type) +void *mrb_check_datatype(mrb_state *mrb, mrb_value, const struct mrb_data_type*); +#define Data_Get_Struct(mrb,obj,type,sval) do {\ + sval = mrb_check_datatype(mrb, obj, type); \ +} while (0) + +#if defined(__cplusplus) +} /* extern "C" { */ +#endif + +#endif /* RUBY_DATA_H */ diff --git a/src/array.c b/src/array.c index 855a45aba..69f5fd8b3 100644 --- a/src/array.c +++ b/src/array.c @@ -2,7 +2,6 @@ #include "mruby/array.h" #include #include "mruby/string.h" -#include "mdata.h" #include "mruby/class.h" #ifdef INCLUDE_REGEXP diff --git a/src/encoding.h b/src/encoding.h index 784d67f44..92e16e5f2 100644 --- a/src/encoding.h +++ b/src/encoding.h @@ -18,7 +18,7 @@ extern "C" { #include #include "oniguruma.h" -#include "mdata.h" +#include "mruby/data.h" int mrb_tolower(int c); int mrb_toupper(int c); diff --git a/src/etc.c b/src/etc.c index 8c98700a3..865992566 100644 --- a/src/etc.c +++ b/src/etc.c @@ -1,5 +1,4 @@ #include "mruby.h" -#include "mdata.h" #include "mruby/string.h" #include "error.h" #include "mruby/numeric.h" diff --git a/src/gc.c b/src/gc.c index e4b1f82ba..f4186f6e3 100644 --- a/src/gc.c +++ b/src/gc.c @@ -10,7 +10,7 @@ #include #include "mruby/struct.h" #include "mruby/proc.h" -#include "mdata.h" +#include "mruby/data.h" #include "mruby/numeric.h" /* diff --git a/src/kernel.c b/src/kernel.c index e5b2cab04..7a4a13501 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -14,7 +14,6 @@ #include "ritehash.h" #include "error.h" #include "method.h" -#include "mdata.h" #ifdef INCLUDE_REGEXP #include "re.h" diff --git a/src/mdata.h b/src/mdata.h deleted file mode 100644 index 827f7c114..000000000 --- a/src/mdata.h +++ /dev/null @@ -1,53 +0,0 @@ -/********************************************************************** - - mdata.h - - - - Copyright (C) 2007 Yukihiro Matsumoto - -**********************************************************************/ - -#ifndef RUBY_DATA_H -#define RUBY_DATA_H 1 - -#if defined(__cplusplus) -extern "C" { -#endif - - -struct mrb_data_type { - const char *struct_name; - void (*dfree)(mrb_state *mrb, void*); -}; - -struct RData { - MRUBY_OBJECT_HEADER; - struct kh_iv *iv; - struct mrb_data_type *type; - void *data; -}; - -struct RData *mrb_data_object_alloc(mrb_state *mrb, struct RClass* klass, void *datap, const struct mrb_data_type *type); - -#define Data_Wrap_Struct(mrb,klass,type,ptr)\ - mrb_data_object_alloc(mrb,klass,ptr,type) - -#define Data_Make_Struct(mrb,klass,strct,type,sval) (\ - sval = mrb_malloc(mrb, sizeof(strct)),\ - memset(sval, 0, sizeof(strct)),\ - Data_Wrap_Struct(mrb,klass,type,sval)\ -) - -#define RDATA(obj) ((struct RData *)((obj).value.p)) -#define DATA_PTR(d) (RDATA(d)->data) -#define DATA_TYPE(d) (RDATA(d)->type) -void *mrb_check_datatype(mrb_state *mrb, mrb_value, const struct mrb_data_type*); -#define Data_Get_Struct(mrb,obj,type,sval) do {\ - sval = mrb_check_datatype(mrb, obj, type); \ -} while (0) - -#if defined(__cplusplus) -} /* extern "C" { */ -#endif - -#endif /* RUBY_DATA_H */ diff --git a/src/object.c b/src/object.c index c60c2fb7b..0a31fa108 100644 --- a/src/object.c +++ b/src/object.c @@ -5,7 +5,6 @@ #include "mruby/class.h" #include "method.h" #include "mruby/numeric.h" -#include "mdata.h" #ifdef INCLUDE_REGEXP #define mrb_usascii_str_new2 mrb_usascii_str_new_cstr -- cgit v1.2.3 From 3d034f52ddb878dc44c086d72da475c78f29ff9b Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Fri, 20 Apr 2012 15:10:46 +0200 Subject: assign will break under C++ even when included with extern C --- include/mruby.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/mruby.h b/include/mruby.h index 8084735bf..0097c397b 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -134,7 +134,7 @@ static inline mrb_value mrb_obj_value(void *p) { mrb_value v; - struct RBasic *b = p; + struct RBasic *b = (struct RBasic*) p; v.tt = b->tt; v.value.p = p; -- cgit v1.2.3 From 5622c977f441a91a7482d5956df96e60d71d90f9 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Fri, 20 Apr 2012 22:25:04 +0900 Subject: remove dependency to SIZEOF_VOIDP --- include/mrbconf.h | 1 - src/Makefile | 2 +- src/numeric.c | 95 +---------------------------- src/re.c | 49 --------------- src/st.h | 6 -- src/string.c | 177 +++--------------------------------------------------- 6 files changed, 11 insertions(+), 319 deletions(-) (limited to 'include') diff --git a/include/mrbconf.h b/include/mrbconf.h index d4802a5e7..81c19a121 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -27,7 +27,6 @@ typedef intptr_t mrb_sym; #define SIZEOF_LONG 4 #define SIZEOF_LONG_LONG 8 #define SIZEOF___INT64 0 -#define SIZEOF_VOIDP 4 #define SIZEOF_FLOAT 4 #define SIZEOF_DOUBLE 8 diff --git a/src/Makefile b/src/Makefile index ea3681dce..abb6f4c4b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -40,7 +40,7 @@ YACC = bison DEBUG_MODE = 1 ifeq ($(DEBUG_MODE),1) -CFLAGS = -g +CFLAGS = -g -O3 else CFLAGS = -O3 endif diff --git a/src/numeric.c b/src/numeric.c index f79369d90..ef4588f76 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -97,25 +97,9 @@ # define SIZEOF_LONG_LONG SIZEOF___INT64 #endif -#if defined HAVE_UINTPTR_T && 0 typedef uintptr_t VALUE; typedef uintptr_t ID; -# define SIGNED_VALUE intptr_t -# define SIZEOF_VALUE SIZEOF_UINTPTR_T -#elif SIZEOF_LONG == SIZEOF_VOIDP -//typedef unsigned long VALUE; -//typedef unsigned long ID; -# define SIGNED_VALUE long long -# define SIZEOF_VALUE SIZEOF_LONG -#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP -typedef unsigned LONG_LONG VALUE; -typedef unsigned LONG_LONG ID; -# define SIGNED_VALUE LONG_LONG -# define LONG_LONG_VALUE 1 -# define SIZEOF_VALUE SIZEOF_LONG_LONG -#else -# error ---->> ruby requires sizeof(void*) == sizeof(long) to be compiled. <<---- -#endif +#define SIGNED_VALUE intptr_t #ifdef HAVE_INFINITY #elif BYTE_ORDER == LITTLE_ENDIAN @@ -980,80 +964,6 @@ mrb_num2ulong(mrb_state *mrb, mrb_value val) } } -#if SIZEOF_INT < SIZEOF_VALUE -void -mrb_out_of_int(mrb_state *mrb, SIGNED_VALUE num) -{ - mrb_raise(mrb, E_RANGE_ERROR, "integer %"PRIdVALUE " too %s to convert to `int'", - num, num < 0 ? "small" : "big"); -} - -static void -check_int(SIGNED_VALUE num) -{ - if ((SIGNED_VALUE)(int)num != num) { - mrb_out_of_int(num); - } -} - -static void -check_uint(mrb_state *mrb, mrb_value num, mrb_value sign) -{ - static const mrb_value mask = ~(mrb_value)UINT_MAX; - - if (RTEST(sign)) { - /* minus */ - if ((num & mask) != mask || (num & ~mask) <= INT_MAX + 1UL) - mrb_raise(mrb, E_RANGE_ERROR, "integer %"PRIdVALUE " too small to convert to `unsigned int'", num); - } - else { - /* plus */ - if ((num & mask) != 0) - mrb_raise(mrb, E_RANGE_ERROR, "integer %"PRIuVALUE " too big to convert to `unsigned int'", num); - } -} - -long -mrb_num2int(mrb_value val) -{ - long num = mrb_num2long(mrb, val); - - check_int(num); - return num; -} - -long -mrb_fix2int(mrb_state *mrb, mrb_value val) -{ - long num = FIXNUM_P(val)?mrb_fixnum(val):mrb_num2long(mrb, val); - - check_int(num); - return num; -} - -unsigned long -mrb_num2uint(mrb_value val) -{ - unsigned long num = mrb_num2ulong(val); - - check_uint(num, mrb_funcall(mrb, val, "<", 1, mrb_fixnum_value(0))); - return num; -} - -unsigned long -mrb_fix2uint(mrb_state *mrb, mrb_value val) -{ - unsigned long num; - - if (!FIXNUM_P(val)) { - return mrb_num2uint(mrb, val); - } - num = FIX2ULONG(val); - - check_uint(num, mrb_funcall(mrb, val, "<", 1, mrb_fixnum_value(0))); - return num; -} -#else long mrb_num2int(mrb_state *mrb, mrb_value val) { @@ -1065,7 +975,6 @@ mrb_fix2int(mrb_value val) { return mrb_fixnum(val); } -#endif mrb_value mrb_num2fix(mrb_state *mrb, mrb_value val) @@ -1204,7 +1113,7 @@ mrb_value rb_fix2str(mrb_state *mrb, mrb_value x, int base) { extern const char ruby_digitmap[]; - char buf[SIZEOF_VALUE*CHAR_BIT + 2], *b = buf + sizeof buf; + char buf[sizeof(mrb_int)*CHAR_BIT + 2], *b = buf + sizeof buf; long val = mrb_fixnum(x); int neg = 0; diff --git a/src/re.c b/src/re.c index 645af6ba6..0cdf58e7a 100644 --- a/src/re.c +++ b/src/re.c @@ -1773,11 +1773,7 @@ static int pair_byte_cmp(const void *pair1, const void *pair2) { long diff = ((pair_t*)pair1)->byte_pos - ((pair_t*)pair2)->byte_pos; -#if SIZEOF_LONG > SIZEOF_INT return diff ? diff > 0 ? 1 : -1 : 0; -#else - return (int)diff; -#endif } static void @@ -2958,48 +2954,6 @@ mrb_backref_set(mrb_state *mrb, mrb_value val) #endif //INCLUDE_REGEXP #ifdef INCLUDE_ENCODING -static inline long -mrb_memsearch_ss(const unsigned char *xs, long m, const unsigned char *ys, long n) -{ - const unsigned char *x = xs, *xe = xs + m; - const unsigned char *y = ys, *ye = ys + n; -#define SIZEOF_VOIDP 4 -#define SIZEOF_LONG 4 - -#ifndef VALUE_MAX -# if SIZEOF_VALUE == 8 -# define VALUE_MAX 0xFFFFFFFFFFFFFFFFULL -# elif SIZEOF_VALUE == 4 -# define VALUE_MAX 0xFFFFFFFFUL -# elif SIZEOF_LONG == SIZEOF_VOIDP -# define SIZEOF_VALUE 4 -# define VALUE_MAX 0xFFFFFFFFUL -# endif -#endif - int hx, hy, mask = VALUE_MAX >> ((SIZEOF_VALUE - m) * CHAR_BIT); - - if (m > SIZEOF_VALUE) - mrb_bug("!!too long pattern string!!"); - - /* Prepare hash value */ - for (hx = *x++, hy = *y++; x < xe; ++x, ++y) { - hx <<= CHAR_BIT; - hy <<= CHAR_BIT; - hx |= *x; - hy |= *y; - } - /* Searching */ - while (hx != hy) { - if (y == ye) - return -1; - hy <<= CHAR_BIT; - hy |= *y; - hy &= mask; - y++; - } - return y - ys - m; -} - static inline long mrb_memsearch_qs(const unsigned char *xs, long m, const unsigned char *ys, long n) { @@ -3094,9 +3048,6 @@ mrb_memsearch(mrb_state *mrb, const void *x0, int m, const void *y0, int n, mrb_ } return -1; } - else if (m <= SIZEOF_VALUE) { - return mrb_memsearch_ss(x0, m, y0, n); - } else if (enc == mrb_utf8_encoding(mrb)) { return mrb_memsearch_qs_utf8(x0, m, y0, n); } diff --git a/src/st.h b/src/st.h index 7324e8da7..d7ec7eb38 100644 --- a/src/st.h +++ b/src/st.h @@ -64,12 +64,6 @@ struct st_table_entry { st_table_entry *fore, *back; }; -#ifndef SIZEOF_VOIDP -#define SIZEOF_VOIDP 4 -#endif - -#define SIZEOF_ST_INDEX_T SIZEOF_VOIDP - struct st_hash_type { int (*compare)(ANYARGS /*st_data_t, st_data_t*/); /* st_compare_func* */ st_index_t (*hash)(ANYARGS /*st_data_t*/); /* st_hash_func* */ diff --git a/src/string.c b/src/string.c index da52172f7..9556f93e8 100644 --- a/src/string.c +++ b/src/string.c @@ -211,38 +211,12 @@ single_byte_optimizable(mrb_state *mrb, mrb_value str) static inline const char * search_nonascii(const char *p, const char *e) { -#if SIZEOF_VALUE == 8 -# define NONASCII_MASK 0x8080808080808080ULL -#elif SIZEOF_VALUE == 4 -# define NONASCII_MASK 0x80808080UL -#endif -#ifdef NONASCII_MASK - if ((int)sizeof(intptr_t) * 2 < e - p) { - const intptr_t *s, *t; - const intptr_t lowbits = sizeof(intptr_t) - 1; - s = (const intptr_t*)(~lowbits & ((intptr_t)p + lowbits)); - while (p < (const char *)s) { - if (!ISASCII(*p)) - return p; - p++; - } - t = (const intptr_t*)(~lowbits & (intptr_t)e); - while (s < t) { - if (*s & (intptr_t)NONASCII_MASK) { - t = s; - break; - } - s++; - } - p = (const char *)t; - } -#endif - while (p < e) { - if (!ISASCII(*p)) - return p; - p++; - } - return NULL; + while (p < e) { + if (!ISASCII(*p)) + return p; + p++; + } + return NULL; } #endif //INCLUDE_ENCODING @@ -1167,63 +1141,6 @@ mrb_str_match(mrb_state *mrb, mrb_value self/* x */) } } /* ---------------------------------- */ -#ifdef INCLUDE_ENCODING -#ifdef NONASCII_MASK -#define is_utf8_lead_byte(c) (((c)&0xC0) != 0x80) -static inline int -count_utf8_lead_bytes_with_word(const intptr_t *s) -{ - int d = *s; - d |= ~(d>>1); - d >>= 6; - d &= NONASCII_MASK >> 7; - d += (d>>8); - d += (d>>16); -#if SIZEOF_VALUE == 8 - d += (d>>32); -#endif - return (d&0xF); -} -#endif - -#ifdef NONASCII_MASK -static char * -str_utf8_nth(const char *p, const char *e, long nth) -{ - if ((int)SIZEOF_VALUE < e - p && (int)SIZEOF_VALUE * 2 < nth) { - const intptr_t *s, *t; - const intptr_t lowbits = sizeof(int) - 1; - s = (const intptr_t*)(~lowbits & ((intptr_t)p + lowbits)); - t = (const intptr_t*)(~lowbits & (intptr_t)e); - while (p < (const char *)s) { - if (is_utf8_lead_byte(*p)) nth--; - p++; - } - do { - nth -= count_utf8_lead_bytes_with_word(s); - s++; - } while (s < t && (int)sizeof(intptr_t) <= nth); - p = (char *)s; - } - while (p < e) { - if (is_utf8_lead_byte(*p)) { - if (nth == 0) break; - nth--; - } - p++; - } - return (char *)p; -} - -static long -str_utf8_offset(const char *p, const char *e, long nth) -{ - const char *pp = str_utf8_nth(p, e, nth); - return pp - p; -} -#endif -#endif //INCLUDE_ENCODING - mrb_value mrb_str_substr(mrb_state *mrb, mrb_value str, mrb_int beg, int len) { @@ -1283,13 +1200,6 @@ mrb_str_substr(mrb_state *mrb, mrb_value str, mrb_int beg, int len) if (len == 0) { p = 0; } -#ifdef NONASCII_MASK - else if (ENC_CODERANGE(str) == ENC_CODERANGE_VALID && - enc == mrb_utf8_encoding(mrb)) { - p = str_utf8_nth(s, e, beg); - len = str_utf8_offset(p, e, len); - } -#endif else if (mrb_enc_mbmaxlen(enc) == mrb_enc_mbminlen(enc)) { int char_sz = mrb_enc_mbmaxlen(enc); @@ -1405,46 +1315,6 @@ mrb_enc_strlen_cr(mrb_state *mrb, const char *p, const char *e, mrb_encoding *en /* --- 1-8-7parse.c --< */ #ifndef INCLUDE_ENCODING -static inline long -mrb_memsearch_ss(const unsigned char *xs, long m, const unsigned char *ys, long n) -{ - const unsigned char *x = xs, *xe = xs + m; - const unsigned char *y = ys, *ye = ys + n; -//2011/06/30 #define SIZEOF_VALUE 4 -#ifndef VALUE_MAX -# if SIZEOF_VALUE == 8 -# define VALUE_MAX 0xFFFFFFFFFFFFFFFFULL -# elif SIZEOF_VALUE == 4 -# define VALUE_MAX 0xFFFFFFFFUL -# elif SIZEOF_LONG == SIZEOF_VOIDP -# define SIZEOF_VALUE 4 -# define VALUE_MAX 0xFFFFFFFFUL -# endif -#endif - int hx, hy, mask = VALUE_MAX >> ((SIZEOF_VALUE - m) * CHAR_BIT); - - if (m > SIZEOF_VALUE) - mrb_bug("!!too long pattern string!!"); - - /* Prepare hash value */ - for (hx = *x++, hy = *y++; x < xe; ++x, ++y) { - hx <<= CHAR_BIT; - hy <<= CHAR_BIT; - hx |= *x; - hy |= *y; - } - /* Searching */ - while (hx != hy) { - if (y == ye) - return -1; - hy <<= CHAR_BIT; - hy |= *y; - hy &= mask; - y++; - } - return y - ys - m; -} - static inline long mrb_memsearch_qs(const unsigned char *xs, long m, const unsigned char *ys, long n) { @@ -1464,6 +1334,7 @@ mrb_memsearch_qs(const unsigned char *xs, long m, const unsigned char *ys, long } return -1; } + int mrb_memsearch(const void *x0, int m, const void *y0, int n) { @@ -1484,12 +1355,7 @@ mrb_memsearch(const void *x0, int m, const void *y0, int n) } return -1; } - else if (m <= SIZEOF_VALUE) { - return mrb_memsearch_ss(x0, m, y0, n); - } - else { - return mrb_memsearch_qs(x0, m, y0, n); - } + return mrb_memsearch_qs(x0, m, y0, n); } #endif //INCLUDE_ENCODING @@ -1507,33 +1373,6 @@ str_strlen(mrb_state *mrb, mrb_value str, mrb_encoding *enc) p = RSTRING_PTR(str); e = RSTRING_END(str); cr = ENC_CODERANGE(str); -#ifdef NONASCII_MASK - if (ENC_CODERANGE(str) == ENC_CODERANGE_VALID && - enc == mrb_utf8_encoding(mrb)) { - - int len = 0; - if ((int)sizeof(intptr_t) * 2 < e - p) { - const intptr_t *s, *t; - const intptr_t lowbits = sizeof(int) - 1; - s = (const intptr_t*)(~lowbits & ((intptr_t)p + lowbits)); - t = (const intptr_t*)(~lowbits & (intptr_t)e); - while (p < (const char *)s) { - if (is_utf8_lead_byte(*p)) len++; - p++; - } - while (s < t) { - len += count_utf8_lead_bytes_with_word(s); - s++; - } - p = (const char *)s; - } - while (p < e) { - if (is_utf8_lead_byte(*p)) len++; - p++; - } - return (long)len; - } -#endif n = mrb_enc_strlen_cr(mrb, p, e, enc, &cr); if (cr) { ENC_CODERANGE_SET(str, cr); -- cgit v1.2.3 From 41bf311cd1997ad2d20d451fe627b241aed571d3 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Fri, 20 Apr 2012 22:31:58 +0900 Subject: remove dependency to SIZEOF_INT --- include/mrbconf.h | 1 - include/mruby.h | 54 ------------------------------------------------------ src/numeric.c | 2 +- src/string.c | 6 +++--- src/transcode.c | 8 ++++---- 5 files changed, 8 insertions(+), 63 deletions(-) (limited to 'include') diff --git a/include/mrbconf.h b/include/mrbconf.h index 81c19a121..bc54de420 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -22,7 +22,6 @@ typedef intptr_t mrb_sym; #undef HAVE_UNISTD_H /* WINDOWS */ #define HAVE_UNISTD_H /* LINUX */ -#define SIZEOF_INT 4 #define SIZEOF_SHORT 2 #define SIZEOF_LONG 4 #define SIZEOF_LONG_LONG 8 diff --git a/include/mruby.h b/include/mruby.h index 8084735bf..f1cf1ca01 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -560,60 +560,6 @@ void mrb_check_type(mrb_state *mrb, mrb_value x, enum mrb_vtype t); #define ruby_setjmp(env) RUBY_SETJMP(env) #define ruby_longjmp(env,val) RUBY_LONGJMP(env,val) -#if defined PRIdPTR && !defined PRI_VALUE_PREFIX -#define PRIdVALUE PRIdPTR -#define PRIiVALUE PRIiPTR -#define PRIoVALUE PRIoPTR -#define PRIuVALUE PRIuPTR -#define PRIxVALUE PRIxPTR -#define PRIXVALUE PRIXPTR -#else -#define PRIdVALUE PRI_VALUE_PREFIX"d" -#define PRIiVALUE PRI_VALUE_PREFIX"i" -#define PRIoVALUE PRI_VALUE_PREFIX"o" -#define PRIuVALUE PRI_VALUE_PREFIX"u" -#define PRIxVALUE PRI_VALUE_PREFIX"x" -#define PRIXVALUE PRI_VALUE_PREFIX"X" -#endif -#ifndef PRI_VALUE_PREFIX -# define PRI_VALUE_PREFIX "" -#endif - -#if defined PRIdPTR -# define PRI_PTRDIFF_PREFIX "t" -#elif SIZEOF_PTRDIFF_T == SIZEOF_INT -# define PRI_PTRDIFF_PREFIX -#elif SIZEOF_PTRDIFF_T == SIZEOF_LONG -# define PRI_PTRDIFF_PREFIX "l" -#elif SIZEOF_PTRDIFF_T == SIZEOF_LONG_LONG -# define PRI_PTRDIFF_PREFIX "ll" -#else -# define PRI_PTRDIFF_PREFIX -#endif -#define PRIdPTRDIFF PRI_PTRDIFF_PREFIX"d" -#define PRIiPTRDIFF PRI_PTRDIFF_PREFIX"i" -#define PRIoPTRDIFF PRI_PTRDIFF_PREFIX"o" -#define PRIuPTRDIFF PRI_PTRDIFF_PREFIX"u" -#define PRIxPTRDIFF PRI_PTRDIFF_PREFIX"x" -#define PRIXPTRDIFF PRI_PTRDIFF_PREFIX"X" - -#if defined PRIdPTR -# define PRI_SIZE_PREFIX "z" -#elif SIZEOF_SIZE_T == SIZEOF_INT -# define PRI_SIZE_PREFIX -#elif SIZEOF_SIZE_T == SIZEOF_LONG -# define PRI_SIZE_PREFIX "l" -#elif SIZEOF_SIZE_T == SIZEOF_LONG_LONG -# define PRI_SIZE_PREFIX "ll" -#endif -#define PRIdSIZE PRI_SIZE_PREFIX"d" -#define PRIiSIZE PRI_SIZE_PREFIX"i" -#define PRIoSIZE PRI_SIZE_PREFIX"o" -#define PRIuSIZE PRI_SIZE_PREFIX"u" -#define PRIxSIZE PRI_SIZE_PREFIX"x" -#define PRIXSIZE PRI_SIZE_PREFIX"X" -#define PRIdPTRDIFF PRI_PTRDIFF_PREFIX"d" - #define KHASH 0 #define STHASH 1 #define BASICHASH 2 diff --git a/src/numeric.c b/src/numeric.c index ef4588f76..b03e57ce6 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -985,7 +985,7 @@ mrb_num2fix(mrb_state *mrb, mrb_value val) v = mrb_num2long(mrb, val); if (!FIXABLE(v)) - mrb_raise(mrb, E_RANGE_ERROR, "integer %"PRIdVALUE " out of range of fixnum", v); + mrb_raise(mrb, E_RANGE_ERROR, "integer %ld out of range of fixnum", v); return mrb_fixnum_value(v); } diff --git a/src/string.c b/src/string.c index 9556f93e8..6b8861ace 100644 --- a/src/string.c +++ b/src/string.c @@ -4833,9 +4833,9 @@ mrb_str_buf_cat_escaped_char(mrb_state *mrb, mrb_value result, unsigned int c, i char buf[CHAR_ESC_LEN + 1]; int l; -#if SIZEOF_INT > 4 - c &= 0xffffffff; -#endif + if (sizeof(c) > 4) { + c &= 0xffffffff; + } if (unicode_p) { if (c < 0x7F && ISPRINT(c)) { snprintf(buf, CHAR_ESC_LEN, "%c", c); diff --git a/src/transcode.c b/src/transcode.c index 05d2b05b1..66a4d4e42 100644 --- a/src/transcode.c +++ b/src/transcode.c @@ -1770,9 +1770,9 @@ mrb_econv_putbackable(mrb_econv_t *ec) { if (ec->num_trans == 0) return 0; -#if SIZEOF_SIZE_T > SIZEOF_INT - if (ec->elems[0].tc->readagain_len > INT_MAX) return INT_MAX; -#endif + if (sizeof(size_t) > sizeof(int)) { + if (ec->elems[0].tc->readagain_len > INT_MAX) return INT_MAX; + } return (int)ec->elems[0].tc->readagain_len; } @@ -2625,7 +2625,7 @@ str_transcode0(mrb_state *mrb, int argc, mrb_value *argv, mrb_value *self, int e transcode_loop(mrb, &fromp, &bp, (sp+slen), (bp+blen), dest, str_transcoding_resize, sname, dname, ecflags, ecopts); if (fromp != sp+slen) { - mrb_raise(mrb, E_ARGUMENT_ERROR, "not fully converted, %"PRIdPTRDIFF" bytes left", sp+slen-fromp); + mrb_raise(mrb, E_ARGUMENT_ERROR, "not fully converted, %td bytes left", sp+slen-fromp); } buf = (unsigned char *)RSTRING_PTR(dest); *bp = '\0'; -- cgit v1.2.3 From 1f78ba77a2efb23f637e79a9b1120b5e316f870a Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Fri, 20 Apr 2012 22:37:21 +0900 Subject: remove SIZEOF_SHORT --- include/mrbconf.h | 1 - 1 file changed, 1 deletion(-) (limited to 'include') diff --git a/include/mrbconf.h b/include/mrbconf.h index bc54de420..6dccaccec 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -22,7 +22,6 @@ typedef intptr_t mrb_sym; #undef HAVE_UNISTD_H /* WINDOWS */ #define HAVE_UNISTD_H /* LINUX */ -#define SIZEOF_SHORT 2 #define SIZEOF_LONG 4 #define SIZEOF_LONG_LONG 8 #define SIZEOF___INT64 0 -- cgit v1.2.3 From 0f0ad36c5f4b00781b96e2cae595672aa84e57c7 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Fri, 20 Apr 2012 22:39:02 +0900 Subject: remove dependency to SIZEOF___INT64 --- include/mrbconf.h | 1 - src/numeric.c | 5 ----- 2 files changed, 6 deletions(-) (limited to 'include') diff --git a/include/mrbconf.h b/include/mrbconf.h index 6dccaccec..5d377e3e3 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -24,7 +24,6 @@ typedef intptr_t mrb_sym; #define SIZEOF_LONG 4 #define SIZEOF_LONG_LONG 8 -#define SIZEOF___INT64 0 #define SIZEOF_FLOAT 4 #define SIZEOF_DOUBLE 8 diff --git a/src/numeric.c b/src/numeric.c index b03e57ce6..113c9b062 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -90,11 +90,6 @@ #if SIZEOF_LONG_LONG > 0 # define LONG_LONG long long -#elif SIZEOF___INT64 > 0 -# define HAVE_LONG_LONG 1 -# define LONG_LONG __int64 -# undef SIZEOF_LONG_LONG -# define SIZEOF_LONG_LONG SIZEOF___INT64 #endif typedef uintptr_t VALUE; -- cgit v1.2.3 From 2c28d29cecaa1d007f89d3c233d0556345a8ff99 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Fri, 20 Apr 2012 22:39:22 +0900 Subject: remove SIZEOF_FLOAT/DOUBLE --- include/mrbconf.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'include') diff --git a/include/mrbconf.h b/include/mrbconf.h index 5d377e3e3..96214a30b 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -24,8 +24,6 @@ typedef intptr_t mrb_sym; #define SIZEOF_LONG 4 #define SIZEOF_LONG_LONG 8 -#define SIZEOF_FLOAT 4 -#define SIZEOF_DOUBLE 8 #ifndef FALSE # define FALSE 0 -- cgit v1.2.3 From 3c1b3478343a7618dac7ac16953e77f45511f505 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Fri, 20 Apr 2012 22:46:07 +0900 Subject: remove dependency to SIZEOF_LONG/LONG_LONG --- include/mrbconf.h | 3 --- src/numeric.c | 71 ++++--------------------------------------------------- src/regint.h | 4 ++-- 3 files changed, 6 insertions(+), 72 deletions(-) (limited to 'include') diff --git a/include/mrbconf.h b/include/mrbconf.h index 96214a30b..923558fd9 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -22,9 +22,6 @@ typedef intptr_t mrb_sym; #undef HAVE_UNISTD_H /* WINDOWS */ #define HAVE_UNISTD_H /* LINUX */ -#define SIZEOF_LONG 4 -#define SIZEOF_LONG_LONG 8 - #ifndef FALSE # define FALSE 0 #endif diff --git a/src/numeric.c b/src/numeric.c index 113c9b062..135691644 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -88,10 +88,6 @@ #define mrb_rational_raw1(x) mrb_rational_raw(x, INT2FIX(1)) -#if SIZEOF_LONG_LONG > 0 -# define LONG_LONG long long -#endif - typedef uintptr_t VALUE; typedef uintptr_t ID; #define SIGNED_VALUE intptr_t @@ -984,55 +980,6 @@ mrb_num2fix(mrb_state *mrb, mrb_value val) return mrb_fixnum_value(v); } -#if HAVE_LONG_LONG - -LONG_LONG -mrb_num2ll(mrb_state *mrb, mrb_value val) -{ - if (mrb_nil_p(val)) { - mrb_raise(mrb, E_TYPE_ERROR, "no implicit conversion from nil"); - } - - if (FIXNUM_P(val)) return (LONG_LONG)mrb_fixnum(val); - - switch (mrb_type(val)) { - case MRB_TT_FLOAT: - if (mrb_float(val) <= (double)LLONG_MAX - && mrb_float(val) >= (double)LLONG_MIN) { - return (LONG_LONG)(mrb_float(val)); - } - else { - char buf[24]; - char *s; - - snprintf(buf, sizeof(buf), "%-.10g", mrb_float(val)); - if ((s = strchr(buf, ' ')) != 0) *s = '\0'; - mrb_raise(mrb, E_RANGE_ERROR, "float %s out of range of long long", buf); - } - - case MRB_TT_STRING: - mrb_raise(mrb, E_TYPE_ERROR, "no implicit conversion from string"); - return mrb_nil_value(); /* not reached */ - - case MRB_TT_TRUE: - case MRB_TT_FALSE: - mrb_raise(mrb, E_TYPE_ERROR, "no implicit conversion from boolean"); - return mrb_nil_value(); /* not reached */ - - default: - val = mrb_to_int(mrb, val); - return NUM2LL(val); - } -} - -unsigned LONG_LONG -mrb_num2ull(mrb_state *mrb, mrb_value val) -{ - return (unsigned LONG_LONG)mrb_num2ll(mrb, val); -} - -#endif /* HAVE_LONG_LONG */ - /* * Document-class: Integer * @@ -1133,7 +1080,7 @@ rb_fix2str(mrb_state *mrb, mrb_value x, int base) return mrb_usascii_str_new2(mrb, b); } -#define SQRT_LONG_MAX ((SIGNED_VALUE)1<<((SIZEOF_LONG*CHAR_BIT-1)/2)) +#define SQRT_LONG_MAX ((SIGNED_VALUE)1<<((sizeof(intptr_t)*CHAR_BIT-1)/2)) /*tests if N*N would overflow*/ #define FIT_SQRT_LONG(n) (((n)=-SQRT_LONG_MAX)) @@ -1159,21 +1106,12 @@ fix_mul(mrb_state *mrb, mrb_value x) volatile #endif long a, b; -#if SIZEOF_LONG * 2 <= SIZEOF_LONG_LONG - LONG_LONG d; -#else long c; mrb_value r; -#endif a = mrb_fixnum(x); b = mrb_fixnum(y); -#if SIZEOF_LONG * 2 <= SIZEOF_LONG_LONG - d = (LONG_LONG)a * b; - if (FIXABLE(d)) return mrb_fixnum_value(d); - return mrb_nil_value();// rb_ll2inum(d); -#else if (FIT_SQRT_LONG(a) && FIT_SQRT_LONG(b)) return mrb_fixnum_value(a*b); c = a * b; @@ -1185,7 +1123,6 @@ fix_mul(mrb_state *mrb, mrb_value x) r = mrb_fixnum_value(a*b); } return r; -#endif } switch (mrb_type(y)) { case MRB_TT_FLOAT: @@ -1519,9 +1456,9 @@ mrb_fix_lshift(mrb_state *mrb, mrb_value x) static mrb_value fix_lshift(mrb_state *mrb, long val, unsigned long width) { - if (width > (SIZEOF_LONG*CHAR_BIT-1) - || ((unsigned long)abs(val))>>(SIZEOF_LONG*CHAR_BIT-1-width) > 0) { - mrb_raise(mrb, E_RANGE_ERROR, "width(%d) > (SIZEOF_LONG*CHAR_BIT-1)", width); + if (width > (sizeof(intptr_t)*CHAR_BIT-1) + || ((unsigned long)abs(val))>>(sizeof(intptr_t)*CHAR_BIT-1-width) > 0) { + mrb_raise(mrb, E_RANGE_ERROR, "width(%d) > (sizeof(intptr_t)*CHAR_BIT-1)", width); } val = val << width; return mrb_fixnum_value(val); diff --git a/src/regint.h b/src/regint.h index e86a95f27..bf19eee1a 100644 --- a/src/regint.h +++ b/src/regint.h @@ -246,11 +246,11 @@ } while(0) /* sizeof(OnigCodePoint) */ -#define WORD_ALIGNMENT_SIZE SIZEOF_LONG +#define WORD_ALIGNMENT_SIZE sizeof(uintptr_t) #define GET_ALIGNMENT_PAD_SIZE(addr,pad_size) do {\ (pad_size) = WORD_ALIGNMENT_SIZE \ - - ((uintptr_t )(addr) % WORD_ALIGNMENT_SIZE);\ + - ((uintptr_t)(addr) % WORD_ALIGNMENT_SIZE);\ if ((pad_size) == WORD_ALIGNMENT_SIZE) (pad_size) = 0;\ } while (0) -- cgit v1.2.3 From 4cb86f87a1d02ed2c9a659391f3817a930743a8f Mon Sep 17 00:00:00 2001 From: Patrick Hogan Date: Fri, 20 Apr 2012 09:32:35 -0500 Subject: #undef DEBUG for compatibility with environments that define DEBUG (like Xcode) Signed-off-by: Patrick Hogan --- include/mruby.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/mruby.h b/include/mruby.h index eb121c971..4fccfaa79 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -388,6 +388,10 @@ void mrb_write_barrier(mrb_state *, struct RBasic*); #define MRUBY_VERSION "Rite" +#ifdef DEBUG +#undef DEBUG +#endif + #if 0 #define DEBUG(x) x #else -- cgit v1.2.3 From 9e32b5152edc6d5935e4cdb0c44b7b138169027b Mon Sep 17 00:00:00 2001 From: Ranmocy Date: Fri, 20 Apr 2012 22:39:46 +0800 Subject: fixed statement alignment --- include/mruby.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/mruby.h b/include/mruby.h index 8084735bf..397885ac5 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -75,7 +75,7 @@ typedef struct mrb_value { #define mrb_test(o) ((o).tt != MRB_TT_FALSE) #define mrb_fixnum(o) (o).value.i #define mrb_float(o) (o).value.f -#define mrb_symbol(o) (o).value.sym +#define mrb_symbol(o) (o).value.sym #define mrb_object(o) (o).value.p #define FIXNUM_P(o) ((o).tt == MRB_TT_FIXNUM) #define UNDEF_P(o) ((o).tt == MRB_TT_UNDEF) -- cgit v1.2.3 From 748d762e851e1954b72b7bbd70408353518e0a9d Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Sat, 21 Apr 2012 12:42:43 +0900 Subject: object instance variable do not use st.c --- include/mruby.h | 1 - src/kernel.c | 138 +++++++++++--------------------------------------------- 2 files changed, 27 insertions(+), 112 deletions(-) (limited to 'include') diff --git a/include/mruby.h b/include/mruby.h index e2a497eb6..d0f8af90f 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -589,7 +589,6 @@ int mrb_cmpint(mrb_state *mrb, mrb_value val, mrb_value a, mrb_value b); # define ANYARGS # endif #endif -void st_foreach_safe(mrb_state *mrb, void *table, int (*func)(ANYARGS), void * a); void mrb_define_alias(mrb_state *mrb, struct RClass *klass, const char *name1, const char *name2); const char *mrb_class_name(mrb_state *mrb, struct RClass* klass); void mrb_define_global_const(mrb_state *mrb, const char *name, mrb_value val); diff --git a/src/kernel.c b/src/kernel.c index 7a4a13501..80b64c26a 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -31,85 +31,12 @@ KHASH_MAP_INIT_INT(iv, mrb_value); #define TRUE 1 #endif -static mrb_value tst_setconst(mrb_state *mrb, mrb_value obj); -int kiv_lookup(khash_t(iv) *table, mrb_sym key, mrb_value *value); - struct obj_ivar_tag { mrb_value obj; int (*func)(mrb_sym key, mrb_value val, void * arg); void * arg; }; -static int -obj_ivar_i(mrb_sym key, int index, struct obj_ivar_tag *arg) -{ - enum st_retval {ST_CONTINUE, ST_STOP, ST_DELETE, ST_CHECK}; - struct obj_ivar_tag *data = (struct obj_ivar_tag *)arg; - if ((long)index < ROBJECT_NUMIV(data->obj)) { - mrb_value val = ROBJECT_IVPTR(data->obj)->vals[(long)index]; - if (val.tt != MRB_TT_FREE) { - return (data->func)((mrb_sym)key, val, data->arg); - } - } - return ST_CONTINUE; -} - -void -mrb_ivar_foreach(mrb_state *mrb, mrb_value obj, int (*func)(ANYARGS), void* arg) -{ - struct obj_ivar_tag data; - switch (mrb_type(obj)) { - case MRB_TT_OBJECT: - //obj_ivar_each(mrb, obj, func, arg); - if (RCLASS_IV_TBL(obj)) { - data.obj = obj; - data.func = (int (*)(mrb_sym key, mrb_value val, void * arg))func; - data.arg = arg; - st_foreach_safe(mrb, RCLASS_IV_TBL(obj), obj_ivar_i, (void *)&data); - } - break; - case MRB_TT_CLASS: - case MRB_TT_MODULE: - if (RCLASS_IV_TBL(obj)) { - st_foreach_safe(mrb, RCLASS_IV_TBL(obj), func, arg); - } - break; - default: - if (!ROBJECT_IVPTR(obj)/*generic_iv_tbl*/) break; - if (/*FL_TEST(obj, FL_EXIVAR) ||*/ mrb_special_const_p(obj)) { - mrb_value *tbl=0; - if (kiv_lookup(ROBJECT_IVPTR(obj)/*generic_iv_tbl*/, SYM2ID(obj), tbl)) { - st_foreach_safe(mrb, (void *)tbl, func, arg); - } - } - break; - } -} - -static int -inspect_i(mrb_state *mrb, mrb_sym id, mrb_value value, mrb_value str) -{ - enum st_retval {ST_CONTINUE, ST_STOP, ST_DELETE, ST_CHECK}; - mrb_value str2; - const char *ivname; - /* need not to show internal data */ - if (RSTRING_PTR(str)[0] == '-') { /* first element */ - RSTRING_PTR(str)[0] = '#'; - mrb_str_cat2(mrb, str, " "); - } - else { - mrb_str_cat2(mrb, str, ", "); - } - ivname = mrb_sym2name(mrb, id); - mrb_str_cat2(mrb, str, ivname); - mrb_str_cat2(mrb, str, "="); - str2 = mrb_inspect(mrb, value); - mrb_str_append(mrb, str, str2); - //OBJ_INFECT(str, str2); - - return ST_CONTINUE; -} - static mrb_value inspect_obj(mrb_state *mrb, mrb_value obj, mrb_value str, int recur) { @@ -117,11 +44,32 @@ inspect_obj(mrb_state *mrb, mrb_value obj, mrb_value str, int recur) mrb_str_cat2(mrb, str, " ..."); } else { - mrb_ivar_foreach(mrb, obj, inspect_i, &str); + khiter_t k; + kh_iv_t *h = RCLASS_IV_TBL(obj); + + if (h) { + for (k = kh_begin(h); k != kh_end(h); k++) { + if (kh_exist(h, k)){ + mrb_sym id = kh_key(h, k); + mrb_value value = kh_value(h, k); + + /* need not to show internal data */ + if (RSTRING_PTR(str)[0] == '-') { /* first element */ + RSTRING_PTR(str)[0] = '#'; + mrb_str_cat2(mrb, str, " "); + } + else { + mrb_str_cat2(mrb, str, ", "); + } + mrb_str_cat2(mrb, str, mrb_sym2name(mrb, id)); + mrb_str_cat2(mrb, str, "="); + mrb_str_append(mrb, str, mrb_inspect(mrb, value)); + } + } + } } mrb_str_cat2(mrb, str, ">"); RSTRING_PTR(str)[0] = '#'; - //OBJ_INFECT(str, obj); return str; } @@ -156,19 +104,9 @@ mrb_value mrb_obj_inspect(mrb_state *mrb, mrb_value obj) { if ((mrb_type(obj) == MRB_TT_OBJECT) && mrb_obj_basic_to_s_p(mrb, obj)) { - int has_ivar = 0; - mrb_value *ptr = (mrb_value *)ROBJECT_IVPTR(obj); long len = ROBJECT_NUMIV(obj); - long i; - - for (i = 0; i < len; i++) { - if (ptr[i].tt != MRB_TT_FREE) { - has_ivar = 1; - break; - } - } - if (has_ivar) { + if (len > 0) { mrb_value str; const char *c = mrb_obj_classname(mrb, obj); @@ -423,7 +361,6 @@ mrb_singleton_class_clone(mrb_state *mrb, mrb_value obj) clone->super = klass->super; if (klass->iv) { - //clone->iv = st_copy(klass->iv); clone->iv = klass->iv; } clone->mt = kh_init(mt, mrb); @@ -449,11 +386,9 @@ init_copy(mrb_state *mrb, mrb_value dest, mrb_value obj) case MRB_TT_CLASS: case MRB_TT_MODULE: if (ROBJECT(dest)->iv) { - //st_free_table(ROBJECT(dest)->iv); ROBJECT(dest)->iv = 0; } if (ROBJECT(obj)->iv) { - //ROBJECT(dest)->iv = st_copy((st_table *)ROBJECT(obj)->iv); ROBJECT(dest)->iv = ROBJECT(obj)->iv; } } @@ -994,7 +929,6 @@ class_instance_method_list(mrb_state *mrb, int argc, mrb_value *argv, struct RCl { mrb_value ary; int recur; - //st_table *list; struct RClass* oldklass; if (argc == 0) { @@ -1006,25 +940,19 @@ class_instance_method_list(mrb_state *mrb, int argc, mrb_value *argv, struct RCl recur = mrb_test(r); } - //list = st_init_numtable(); ary = mrb_ary_new(mrb); - //for (; mod; mod = RCLASS_SUPER(mod)) { oldklass = 0; while (klass && (klass != oldklass)) { - //st_foreach(RCLASS_M_TBL(mod), method_entry, (st_data_t)list); method_entry_loop(mrb, klass, ary); if ((klass->tt == MRB_TT_ICLASS) || (klass->tt == MRB_TT_SCLASS)) { } - else - { + else { if (!recur) break; } oldklass = klass; klass = klass->super; } - //st_foreach(list, func, ary); - //st_free_table(list); return ary; } @@ -1033,7 +961,6 @@ mrb_value mrb_obj_singleton_methods(mrb_state *mrb, int argc, mrb_value *argv, mrb_value obj) { mrb_value recur, ary; - //st_table *list; struct RClass* klass; if (argc == 0) { @@ -1044,22 +971,17 @@ mrb_obj_singleton_methods(mrb_state *mrb, int argc, mrb_value *argv, mrb_value o recur = argv[0]; } klass = mrb_class(mrb, obj); - //list = st_init_numtable(); ary = mrb_ary_new(mrb); if (klass && (klass->tt == MRB_TT_SCLASS)) { - //st_foreach(RCLASS_M_TBL(klass), method_entry, (st_data_t)list); method_entry_loop(mrb, klass, ary); klass = klass->super; } if (RTEST(recur)) { while (klass && ((klass->tt == MRB_TT_SCLASS) || (klass->tt == MRB_TT_ICLASS))) { - //st_foreach(RCLASS_M_TBL(klass), method_entry, (st_data_t)list); method_entry_loop(mrb, klass, ary); klass = klass->super; } } - //st_foreach(list, ins_methods_i, ary); - //st_free_table(list); return ary; } @@ -1326,14 +1248,8 @@ mrb_obj_remove_instance_variable(mrb_state *mrb, mrb_value self) } } break; - //default: - // if (mrb_special_const_p(obj)) { - // v = val; - // if (generic_ivar_remove(obj, (st_data_t)id, &v)) { - // return (VALUE)v; - // } - // } - // break; + default: + break; } mrb_name_error(mrb, sym, "instance variable %s not defined", mrb_sym2name(mrb, sym)); return mrb_nil_value(); /* not reached */ -- cgit v1.2.3