summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-12-15 04:15:54 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-12-15 04:15:54 +0000
commit84dcc38273665cba3f3756a454697edf11ab168a (patch)
treedbfd3e77fe3ffa4f26efea788f02279d66af9d60
parent15f26afdf0cf3f188a20456512c829290187b68d (diff)
* regcomp.c (onig_region_memsize): implemented for memsize_of().
* ext/objspace/objspace.c (memsize_of): use it. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34050 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--ext/objspace/objspace.c2
-rw-r--r--regcomp.c10
-rw-r--r--regint.h1
-rw-r--r--test/objspace/test_objspace.rb4
5 files changed, 22 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 15f164e..dd05994 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Thu Dec 15 13:15:51 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * regcomp.c (onig_region_memsize): implemented for memsize_of().
+
+ * ext/objspace/objspace.c (memsize_of): use it.
+
Thu Dec 15 10:44:54 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
* array.c (rb_ary_reject_bang, rb_ary_delete_if): update rdoc.
diff --git a/ext/objspace/objspace.c b/ext/objspace/objspace.c
index 66e33a3..f37499f 100644
--- a/ext/objspace/objspace.c
+++ b/ext/objspace/objspace.c
@@ -97,7 +97,7 @@ memsize_of(VALUE obj)
case T_MATCH:
if (RMATCH(obj)->rmatch) {
struct rmatch *rm = RMATCH(obj)->rmatch;
- size += sizeof(struct re_registers); /* TODO: onig_region_memsize(&rm->regs); */
+ size += onig_region_memsize(&rm->regs);
size += sizeof(struct rmatch_offset) * rm->char_offset_num_allocated;
size += sizeof(struct rmatch);
}
diff --git a/regcomp.c b/regcomp.c
index 98ecbe8..d81334a 100644
--- a/regcomp.c
+++ b/regcomp.c
@@ -5244,6 +5244,7 @@ size_t
onig_memsize(const regex_t *reg)
{
size_t size = sizeof(regex_t);
+ if (!reg) return 0;
if (IS_NOT_NULL(reg->p)) size += reg->alloc;
if (IS_NOT_NULL(reg->exact)) size += reg->exact_end - reg->exact;
if (IS_NOT_NULL(reg->int_map)) size += sizeof(int) * ONIG_CHAR_TABLE_SIZE;
@@ -5254,6 +5255,15 @@ onig_memsize(const regex_t *reg)
return size;
}
+size_t
+onig_region_memsize(const OnigRegion *regs)
+{
+ size_t size = sizeof(*regs);
+ if (!regs) return 0;
+ size += regs->allocated * (sizeof(*regs->beg) + sizeof(*regs->end));
+ return size;
+}
+
#define REGEX_TRANSFER(to,from) do {\
(to)->state = ONIG_STATE_MODIFY;\
onig_free_body(to);\
diff --git a/regint.h b/regint.h
index cd3c2a1..ca293ed 100644
--- a/regint.h
+++ b/regint.h
@@ -842,6 +842,7 @@ typedef int (*ONIGENC_INIT_PROPERTY_LIST_FUNC_TYPE)(void);
extern int onigenc_property_list_init P_((ONIGENC_INIT_PROPERTY_LIST_FUNC_TYPE));
extern size_t onig_memsize P_((const regex_t *reg));
+extern size_t onig_region_memsize P_((const struct re_registers *regs));
#if defined __GNUC__ && __GNUC__ >= 4
#pragma GCC visibility pop
diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb
index 04a3381..3c22dae 100644
--- a/test/objspace/test_objspace.rb
+++ b/test/objspace/test_objspace.rb
@@ -17,6 +17,10 @@ class TestObjSpace < Test::Unit::TestCase
f.close
assert_kind_of(Integer, ObjectSpace.memsize_of(/a/.match("a")))
assert_kind_of(Integer, ObjectSpace.memsize_of(Struct.new(:a)))
+
+ assert_operator(ObjectSpace.memsize_of(Regexp.new("(a)"*1000).match("a"*1000)),
+ :>,
+ ObjectSpace.memsize_of(//.match("")))
end
def test_memsize_of_all