summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-12-15 08:57:01 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-12-15 08:57:01 +0000
commit73768d54d3af644dab3dc3a5fd12aa75961f3c28 (patch)
treef64b946659b54a76d59093e01895052ff2d294bc
parent2a5ddef59feb5b79e097e8b9de1b1f2b3b37b887 (diff)
* io.c (argf_type): make typed data.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34055 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog4
-rw-r--r--io.c17
-rw-r--r--test/objspace/test_objspace.rb12
3 files changed, 32 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 13e76d663f5..d18e0c0d9b6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Thu Dec 15 17:56:58 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * io.c (argf_type): make typed data.
+
Thu Dec 15 17:40:28 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
* error.c (rb_check_type): fix typo.
diff --git a/io.c b/io.c
index 3e184f29953..fc4fba7aa21 100644
--- a/io.c
+++ b/io.c
@@ -7133,6 +7133,21 @@ argf_free(void *ptr)
xfree(p);
}
+static size_t
+argf_memsize(const void *ptr)
+{
+ const struct argf *p = ptr;
+ size_t size = sizeof(*p);
+ if (!ptr) return 0;
+ if (p->inplace) size += strlen(p->inplace) + 1;
+ return size;
+}
+
+static const rb_data_type_t argf_type = {
+ "ARGF",
+ {argf_mark, argf_free, argf_memsize},
+};
+
static inline void
argf_init(struct argf *p, VALUE v)
{
@@ -7146,7 +7161,7 @@ static VALUE
argf_alloc(VALUE klass)
{
struct argf *p;
- VALUE argf = Data_Make_Struct(klass, struct argf, argf_mark, argf_free, p);
+ VALUE argf = TypedData_Make_Struct(klass, struct argf, &argf_type, p);
argf_init(p, Qnil);
return argf;
diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb
index 3c22dae551e..345b00f7370 100644
--- a/test/objspace/test_objspace.rb
+++ b/test/objspace/test_objspace.rb
@@ -1,5 +1,6 @@
require "test/unit"
require "objspace"
+require_relative "../ruby/envutil"
class TestObjSpace < Test::Unit::TestCase
def test_memsize_of
@@ -23,6 +24,17 @@ class TestObjSpace < Test::Unit::TestCase
ObjectSpace.memsize_of(//.match("")))
end
+ def test_argf_memsize
+ size = ObjectSpace.memsize_of(ARGF)
+ assert_kind_of(Integer, size)
+ assert_operator(size, :>, 0)
+ argf = ARGF.dup
+ argf.inplace_mode = nil
+ size = ObjectSpace.memsize_of(argf)
+ argf.inplace_mode = "inplace_mode_suffix"
+ assert_equal(size + 20, ObjectSpace.memsize_of(argf))
+ end
+
def test_memsize_of_all
assert_kind_of(Integer, a = ObjectSpace.memsize_of_all)
assert_kind_of(Integer, b = ObjectSpace.memsize_of_all(String))