From a2df247063453b82169788f09f6a413d44ce96f9 Mon Sep 17 00:00:00 2001 From: KOBAYASHI Shuji Date: Thu, 21 Nov 2019 19:21:35 +0900 Subject: Introduce `mrb_ssize` type for buffer size on memory; ref #4483 Previously, `mrb_int` was used as the type that represents the buffer size on memory, but the sizes of `RString` and `RArray` exceed 6 words when `MRB_INT64` is enabled on 32-bit CPU. I don't think it is necessary to be able to represent the buffer size on memory that exceeds the virtual address space. Therefore, for this purpose, introduce `mrb_ssize` which doesn't exceed the sizes of `mrb_int` and pointer. I think all `mrb_int` used for this purpose should be changed to `mrb_ssize`, but currently only the members of the structures (`RString`, `mrb_shared_string`, `RArray` and `mrb_shared_array`) are changed. --- include/mruby/array.h | 6 +++--- include/mruby/string.h | 6 +++--- include/mruby/value.h | 8 ++++++++ 3 files changed, 14 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/mruby/array.h b/include/mruby/array.h index 9664214d6..e2dd9bb1c 100644 --- a/include/mruby/array.h +++ b/include/mruby/array.h @@ -17,7 +17,7 @@ MRB_BEGIN_DECL typedef struct mrb_shared_array { int refcnt; - mrb_int len; + mrb_ssize len; mrb_value *ptr; } mrb_shared_array; @@ -26,9 +26,9 @@ struct RArray { MRB_OBJECT_HEADER; union { struct { - mrb_int len; + mrb_ssize len; union { - mrb_int capa; + mrb_ssize capa; mrb_shared_array *shared; } aux; mrb_value *ptr; diff --git a/include/mruby/string.h b/include/mruby/string.h index 9039aaab3..e5a046073 100644 --- a/include/mruby/string.h +++ b/include/mruby/string.h @@ -23,9 +23,9 @@ struct RString { MRB_OBJECT_HEADER; union { struct { - mrb_int len; + mrb_ssize len; union { - mrb_int capa; + mrb_ssize capa; struct mrb_shared_string *shared; struct RString *fshared; } aux; @@ -54,7 +54,7 @@ struct RStringEmbed { RSTR_SET_EMBED_LEN((s),(n));\ }\ else {\ - (s)->as.heap.len = (mrb_int)(n);\ + (s)->as.heap.len = (mrb_ssize)(n);\ }\ } while (0) #define RSTR_EMBED_PTR(s) (((struct RStringEmbed*)(s))->ary) diff --git a/include/mruby/value.h b/include/mruby/value.h index 84ea7fb0a..5a909a5cf 100644 --- a/include/mruby/value.h +++ b/include/mruby/value.h @@ -174,6 +174,14 @@ typedef void mrb_value; #define MRB_SYMBOL_MAX UINT32_MAX #endif +#if INTPTR_MAX < MRB_INT_MAX + typedef intptr_t mrb_ssize; +# define MRB_SSIZE_MAX (INTPTR_MAX>>MRB_FIXNUM_SHIFT) +#else + typedef mrb_int mrb_ssize; +# define MRB_SSIZE_MAX MRB_INT_MAX +#endif + #ifndef mrb_immediate_p #define mrb_immediate_p(o) (mrb_type(o) < MRB_TT_FREE) #endif -- cgit v1.2.3