Skip to content

Commit

Permalink
* regcomp.c (onig_region_memsize): implemented for memsize_of().
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nobu committed Dec 15, 2011
1 parent 15f26af commit 84dcc38
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion ext/objspace/objspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 10 additions & 0 deletions regcomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);\
Expand Down
1 change: 1 addition & 0 deletions regint.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions test/objspace/test_objspace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def test_memsize_of
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
Expand Down

0 comments on commit 84dcc38

Please sign in to comment.