mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	* io.c (argf_type): make typed data.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34055 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									2a5ddef59f
								
							
						
					
					
						commit
						73768d54d3
					
				
					 3 changed files with 32 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -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.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										17
									
								
								io.c
									
										
									
									
									
								
							
							
						
						
									
										17
									
								
								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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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))
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue