E
Eugene Scripnik
I've written extension in C for ruby and created test case for it. When
I've run it ruby eat all memory. I've simplified code as I can and here
is what I get:
typedef struct test_info {
char *dummy;
} TestInfo;
static VALUE rb_cTest;
static VALUE test_free( TestInfo *info ) {
rb_warn( "this warning makes ruby mad when used with test/unit" );
if ( info ) free( info );
}
static VALUE test_s_allocate( VALUE klass ) {
return Data_Wrap_Struct( klass, 0, test_free, 0 );
}
static VALUE test_initialize( VALUE self ) {
DATA_PTR( self ) = ALLOC( TestInfo );
return self;
}
void Init_mytest() {
rb_cTest = rb_define_class( "MyTest", rb_cObject );
rb_define_alloc_func( rb_cTest, test_s_allocate );
rb_define_method( rb_cTest, "initialize", test_initialize, 0 );
}
create_makefile("mytest")
require 'test/unit'
require 'mytest'
t = MyTest.new
Note, if I remove "require 'test/unit'" line or rb_warn from extension
everything is ok.
--
Eugene Scripnik
IT Group
Software Architect
Tel./Fax +380 (372) 58-43-10
email: (e-mail address removed)
http://www.itgrp.net/
I've run it ruby eat all memory. I've simplified code as I can and here
is what I get:
#include "ruby.h"cat test.c
typedef struct test_info {
char *dummy;
} TestInfo;
static VALUE rb_cTest;
static VALUE test_free( TestInfo *info ) {
rb_warn( "this warning makes ruby mad when used with test/unit" );
if ( info ) free( info );
}
static VALUE test_s_allocate( VALUE klass ) {
return Data_Wrap_Struct( klass, 0, test_free, 0 );
}
static VALUE test_initialize( VALUE self ) {
DATA_PTR( self ) = ALLOC( TestInfo );
return self;
}
void Init_mytest() {
rb_cTest = rb_define_class( "MyTest", rb_cObject );
rb_define_alloc_func( rb_cTest, test_s_allocate );
rb_define_method( rb_cTest, "initialize", test_initialize, 0 );
}
require "mkmf"cat extconf.rb
create_makefile("mytest")
#!/usr/local/bin/ruby -wcat test.rb
require 'test/unit'
require 'mytest'
t = MyTest.new
ruby 1.8.0 (2003-06-20) [i386-freebsd5.1]ruby -v
Note, if I remove "require 'test/unit'" line or rb_warn from extension
everything is ok.
--
Eugene Scripnik
IT Group
Software Architect
Tel./Fax +380 (372) 58-43-10
email: (e-mail address removed)
http://www.itgrp.net/