summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authordearblue <[email protected]>2020-07-21 23:55:26 +0900
committerdearblue <[email protected]>2020-07-24 11:42:37 +0900
commit5c2b11d21581cf472929b21f28f1a388a16f0865 (patch)
tree516c537e872d644980b014dd8a4ac09cb597f06b
parentc9ba761b9e23e720da9200be1c4df103a04e51b2 (diff)
downloadmruby-5c2b11d21581cf472929b21f28f1a388a16f0865.tar.gz
mruby-5c2b11d21581cf472929b21f28f1a388a16f0865.zip
Avoid using FPU with `mruby-os-memsize`; ref #5032
And, in the calculation of the instance variable size, the fraction was always rounded down because of division of integers, so fix it. At the same time, test items that are no longer passed due to this change are deleted.
-rw-r--r--mrbgems/mruby-os-memsize/test/memsize.rb14
-rw-r--r--src/variable.c7
2 files changed, 3 insertions, 18 deletions
diff --git a/mrbgems/mruby-os-memsize/test/memsize.rb b/mrbgems/mruby-os-memsize/test/memsize.rb
index 9e8d41165..6be8f1b06 100644
--- a/mrbgems/mruby-os-memsize/test/memsize.rb
+++ b/mrbgems/mruby-os-memsize/test/memsize.rb
@@ -22,20 +22,6 @@ assert 'ObjectSpace.memsize_of' do
empty_class_def_size = ObjectSpace.memsize_of Class.new
assert_not_equal empty_class_def_size, 0, 'Class def not zero'
- class_without_methods = Class.new do
- @a = 1
- @b = 2
- end
- class_total_size = empty_class_def_size + (int_size * 2)
- assert_equal ObjectSpace.memsize_of(class_without_methods), class_total_size, 'class without methods size'
-
- module_without_methods = Module.new do
- @a = 1
- @b = 2
- end
- module_total_size = empty_class_def_size + (int_size * 2)
- assert_equal ObjectSpace.memsize_of(module_without_methods), module_total_size, 'module without methods size'
-
proc_size = ObjectSpace.memsize_of Proc.new { x = 1; x }
assert_not_equal proc_size, 0
diff --git a/src/variable.c b/src/variable.c
index 0755f7d92..8c16b2d4f 100644
--- a/src/variable.c
+++ b/src/variable.c
@@ -4,7 +4,6 @@
** See Copyright Notice in mruby.h
*/
-#include <math.h>
#include <mruby.h>
#include <mruby/array.h>
#include <mruby/class.h>
@@ -1132,9 +1131,9 @@ mrb_class_find_path(mrb_state *mrb, struct RClass *c)
mrb_int
mrb_obj_iv_tbl_memsize(mrb_state* mrb, mrb_value obj)
{
- return sizeof(iv_tbl) +
- (sizeof(segment) * ceil(iv_size(mrb, mrb_obj_ptr(obj)->iv)/
- MRB_IV_SEGMENT_SIZE));
+ size_t ivsize = iv_size(mrb, mrb_obj_ptr(obj)->iv);
+ size_t ivsegs = (ivsize + MRB_IV_SEGMENT_SIZE - 1) / MRB_IV_SEGMENT_SIZE;
+ return sizeof(iv_tbl) + (sizeof(segment) * ivsegs);
}
#define identchar(c) (ISALNUM(c) || (c) == '_' || !ISASCII(c))