summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorKOBAYASHI Shuji <[email protected]>2019-11-21 19:21:35 +0900
committerKOBAYASHI Shuji <[email protected]>2019-11-21 19:34:02 +0900
commita2df247063453b82169788f09f6a413d44ce96f9 (patch)
tree5563095257c36541352d4d27f41703b23acb0311 /include
parent79e73dd86a72949e52a9eba0ea7abc294b40b16c (diff)
downloadmruby-a2df247063453b82169788f09f6a413d44ce96f9.tar.gz
mruby-a2df247063453b82169788f09f6a413d44ce96f9.zip
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.
Diffstat (limited to 'include')
-rw-r--r--include/mruby/array.h6
-rw-r--r--include/mruby/string.h6
-rw-r--r--include/mruby/value.h8
3 files changed, 14 insertions, 6 deletions
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