warning in ruby extension eats memory

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:
cat test.c
#include "ruby.h"

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 );
}
cat extconf.rb
require "mkmf"

create_makefile("mytest")
cat test.rb
#!/usr/local/bin/ruby -w

require 'test/unit'
require 'mytest'

t = MyTest.new
ruby 1.8.0 (2003-06-20) [i386-freebsd5.1]

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/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top