diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/mruby.h | 17 | ||||
| -rw-r--r-- | include/mruby/error.h | 1 | ||||
| -rw-r--r-- | include/mruby/string.h | 53 | ||||
| -rw-r--r-- | include/mruby/value.h | 4 |
4 files changed, 55 insertions, 20 deletions
diff --git a/include/mruby.h b/include/mruby.h index c1f45bf0b..dcc01b2dd 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -102,6 +102,8 @@ enum gc_state { struct mrb_jmpbuf; +typedef void (*mrb_atexit_func)(struct mrb_state*); + typedef struct mrb_state { struct mrb_jmpbuf *jmp; @@ -167,8 +169,12 @@ typedef struct mrb_state { struct RClass *eException_class; struct RClass *eStandardError_class; + struct RObject *nomem_err; /* pre-allocated NoMemoryError */ void *ud; /* auxiliary data */ + + mrb_atexit_func *atexit_stack; + mrb_int atexit_stack_len; } mrb_state; #if __STDC_VERSION__ >= 201112L @@ -328,8 +334,7 @@ mrb_value mrb_obj_clone(mrb_state *mrb, mrb_value self); /* need to include <ctype.h> to use these macros */ #ifndef ISPRINT -/* #define ISASCII(c) isascii((int)(unsigned char)(c)) */ -#define ISASCII(c) 1 +#define ISASCII(c) (!(((int)(unsigned char)(c)) & ~0x7f)) #define ISPRINT(c) (ISASCII(c) && isprint((int)(unsigned char)(c))) #define ISSPACE(c) (ISASCII(c) && isspace((int)(unsigned char)(c))) #define ISUPPER(c) (ISASCII(c) && isupper((int)(unsigned char)(c))) @@ -413,6 +418,8 @@ void* mrb_pool_realloc(struct mrb_pool*, void*, size_t oldlen, size_t newlen); mrb_bool mrb_pool_can_realloc(struct mrb_pool*, void*, size_t); void* mrb_alloca(mrb_state *mrb, size_t); +void mrb_state_atexit(mrb_state *mrb, mrb_atexit_func func); + #ifdef MRB_DEBUG #include <assert.h> #define mrb_assert(p) assert(p) @@ -422,6 +429,12 @@ void* mrb_alloca(mrb_state *mrb, size_t); #define mrb_assert_int_fit(t1,n,t2,max) ((void)0) #endif +#if __STDC_VERSION__ >= 201112L +#define mrb_static_assert(exp, str) _Static_assert(exp, str) +#else +#define mrb_static_assert(exp, str) mrb_assert(exp) +#endif + mrb_value mrb_format(mrb_state *mrb, const char *format, ...); #if defined(__cplusplus) diff --git a/include/mruby/error.h b/include/mruby/error.h index 7ae2d4348..4d37f1701 100644 --- a/include/mruby/error.h +++ b/include/mruby/error.h @@ -19,6 +19,7 @@ void mrb_exc_print(mrb_state *mrb, struct RObject *exc); void mrb_print_backtrace(mrb_state *mrb); mrb_value mrb_exc_backtrace(mrb_state *mrb, mrb_value exc); mrb_value mrb_get_backtrace(mrb_state *mrb); +mrb_noreturn void mrb_no_method_error(mrb_state *mrb, mrb_sym id, mrb_int argc, const mrb_value *argv, const char *fmt, ...); /* declaration for fail method */ mrb_value mrb_f_raise(mrb_state*, mrb_value); diff --git a/include/mruby/string.h b/include/mruby/string.h index dd73f5f1e..f8a1fa7bd 100644 --- a/include/mruby/string.h +++ b/include/mruby/string.h @@ -11,8 +11,6 @@ extern "C" { #endif -#define IS_EVSTR(p,e) ((p) < (e) && (*(p) == '$' || *(p) == '@' || *(p) == '{')) - extern const char mrb_digitmap[]; #define RSTRING_EMBED_LEN_MAX ((mrb_int)(sizeof(void*) * 3 - 1)) @@ -32,21 +30,42 @@ struct RString { } as; }; -#define mrb_str_ptr(s) ((struct RString*)(mrb_ptr(s))) -#define RSTRING(s) ((struct RString*)(mrb_ptr(s))) -#define RSTRING_PTR(s)\ - ((RSTRING(s)->flags & MRB_STR_EMBED) ?\ - RSTRING(s)->as.ary :\ - RSTRING(s)->as.heap.ptr) -#define RSTRING_LEN(s)\ - ((RSTRING(s)->flags & MRB_STR_EMBED) ?\ - (mrb_int)((RSTRING(s)->flags & MRB_STR_EMBED_LEN_MASK) >> MRB_STR_EMBED_LEN_SHIFT) :\ - RSTRING(s)->as.heap.len) -#define RSTRING_CAPA(s)\ - ((RSTRING(s)->flags & MRB_STR_EMBED) ?\ - RSTRING_EMBED_LEN_MAX :\ - RSTRING(s)->as.heap.aux.capa) -#define RSTRING_END(s) (RSTRING_PTR(s) + RSTRING_LEN(s)) +#define RSTR_EMBED_P(s) ((s)->flags & MRB_STR_EMBED) +#define RSTR_SET_EMBED_FLAG(s) ((s)->flags |= MRB_STR_EMBED) +#define RSTR_UNSET_EMBED_FLAG(s) ((s)->flags &= ~(MRB_STR_EMBED|MRB_STR_EMBED_LEN_MASK)) +#define RSTR_SET_EMBED_LEN(s, n) do {\ + size_t tmp_n = (n);\ + s->flags &= ~MRB_STR_EMBED_LEN_MASK;\ + s->flags |= (tmp_n) << MRB_STR_EMBED_LEN_SHIFT;\ +} while (0) +#define RSTR_SET_LEN(s, n) do {\ + if (RSTR_EMBED_P(s)) {\ + RSTR_SET_EMBED_LEN((s),(n));\ + } else {\ + s->as.heap.len = (mrb_int)(n);\ + }\ +} while (0) +#define RSTR_EMBED_LEN(s)\ + (mrb_int)(((s)->flags & MRB_STR_EMBED_LEN_MASK) >> MRB_STR_EMBED_LEN_SHIFT) +#define RSTR_PTR(s) ((RSTR_EMBED_P(s)) ? (s)->as.ary : (s)->as.heap.ptr) +#define RSTR_LEN(s) ((RSTR_EMBED_P(s)) ? RSTR_EMBED_LEN(s) : (s)->as.heap.len) +#define RSTR_CAPA(s) (RSTR_EMBED_P(s) ? RSTRING_EMBED_LEN_MAX : (s)->as.heap.aux.capa) + +#define RSTR_SHARED_P(s) ((s)->flags & MRB_STR_SHARED) +#define RSTR_SET_SHARED_FLAG(s) ((s)->flags |= MRB_STR_SHARED) +#define RSTR_UNSET_SHARED_FLAG(s) ((s)->flags &= ~MRB_STR_SHARED) + +#define RSTR_NOFREE_P(s) ((s)->flags & MRB_STR_NOFREE) +#define RSTR_SET_NOFREE_FLAG(s) ((s)->flags |= MRB_STR_NOFREE) +#define RSTR_UNSET_NOFREE_FLAG(s) ((s)->flags &= ~MRB_STR_NOFREE) + +#define mrb_str_ptr(s) ((struct RString*)(mrb_ptr(s))) +#define RSTRING(s) mrb_str_ptr(s) +#define RSTRING_PTR(s) RSTR_PTR(RSTRING(s)) +#define RSTRING_EMBED_LEN(s) RSTR_ENBED_LEN(RSTRING(s)) +#define RSTRING_LEN(s) RSTR_LEN(RSTRING(s)) +#define RSTRING_CAPA(s) RSTR_CAPA(RSTRING(s)) +#define RSTRING_END(s) (RSTRING_PTR(s) + RSTRING_LEN(s)) mrb_int mrb_str_strlen(mrb_state*, struct RString*); #define MRB_STR_SHARED 1 diff --git a/include/mruby/value.h b/include/mruby/value.h index 83696715d..98af9626d 100644 --- a/include/mruby/value.h +++ b/include/mruby/value.h @@ -70,7 +70,9 @@ typedef short mrb_sym; # ifndef __cplusplus # define inline __inline # endif -# define snprintf _snprintf +# if _MSC_VER < 1900 +# define snprintf _snprintf +# endif # if _MSC_VER < 1800 # include <float.h> # define isfinite(n) _finite(n) |
