[#16113] Strange idea... exporting from a scope — "Hal E. Fulton" <hal9000@...>

Hello...

33 messages 2001/06/01

[#16364] Re: Garbage Collection? — Michael Davis <mdavis@...>

Windows 2000 and linux (RedHat 6.2). I have run these tests on both OSs.

12 messages 2001/06/09

[#16400] Symbolic Computation III — Mathieu Bouchard <matju@...>

14 messages 2001/06/11

[#16502] Playing with Ruby Syntax (was: Initial thoughts about Ruby From a Smalltalk Programmer) — jweirich@...

Michael> Hi Everyone, I have to say I'm utterly fascinated by Ruby

9 messages 2001/06/15

[#16661] Problem running irb with Ruby 1.6.4 under FreeBSD 4.0 — Bob Alexander <balexander@...>

I've installed Ruby 1.6.4 on a FreeBSD 4.0 machine, and get the

11 messages 2001/06/20

[#16686] opening db files made by apache dbmmanage — Fritz Heinrichmeyer <fritz.heinrichmeyer@...>

14 messages 2001/06/21

[#16801] rb_define_class() vs Class.new() — Kero van Gelder <kero@...4050.upc-d.chello.nl>

Hi,

18 messages 2001/06/23
[#16802] Re: rb_define_class() vs Class.new() — ts <decoux@...> 2001/06/23

>>>>> "K" == Kero van Gelder <kero@d4050.upc-d.chello.nl> writes:

[#16841] RE: national characters is strings — "Aleksei Guzev" <aleksei.guzev@...>

Next week I'll try to rebuild Ruby with Unicode strings. But it would be

15 messages 2001/06/25
[#16842] Re: national characters is strings — matz@... (Yukihiro Matsumoto) 2001/06/25

Hi,

[#16843] Re: national characters is strings — "Aleksei Guzev" <aleksei.guzev@...> 2001/06/25

That's good enough. But I'm afraid this could ( not would ) cause string

[#16868] Something strange with Ruby's inheritance mechanism — Eric Jacoboni <jaco@...>

As Ruby beginner, i try some "canonical" OO scripts. Doing so, I've

14 messages 2001/06/25
[#16873] RE: Something strange with Ruby's inheritance mechanism — "Aleksei Guzev" <aleksei.guzev@...> 2001/06/26

[#16879] Re: Something strange with Ruby's inheritance mechanism — Mathieu Bouchard <matju@...> 2001/06/26

On Tue, 26 Jun 2001, Aleksei Guzev wrote:

[#16869] Something strange with Ruby's inheritance mechanism — Eric Jacoboni <jaco@...>

As Ruby beginner, i try some "canonical" OO scripts. Doing so, I've

12 messages 2001/06/25

[#16881] — "Aleksei Guzev" <aleksei.guzev@...>

32 messages 2001/06/26
[#16916] Re: Method overloading (option) Was: Re: — "Wayne Blair" <wayne.blair@...> 2001/06/26

[#16920] Re: Method overloading (option) Was: Re: — matz@... (Yukihiro Matsumoto) 2001/06/26

Hi,

[#16888] finalizers, destructors and whatnot — "David Leal" <david@...>

Hi all,

16 messages 2001/06/26

[#17037] keeping an Exception object alive — David Alan Black <dblack@...>

Hello --

19 messages 2001/06/28
[#17055] Re: keeping an Exception object alive — matz@... (Yukihiro Matsumoto) 2001/06/29

Hi,

[#17066] RCR: Exception methods (was: Re: Re: keeping an Exception object alive) — David Alan Black <dblack@...> 2001/06/29

Hello --

[#17076] Re: RCR: Exception methods (was: Re: Re: keeping an Exception object alive) — matz@... (Yukihiro Matsumoto) 2001/06/29

Hi,

[#17079] Re: RCR: Exception methods (was: Re: Re: keeping an Exception object alive) — David Alan Black <dblack@...> 2001/06/29

Hello --

[#17138] Re: RCR: Exception methods (was: Re: Re: keeping an Exception object alive) — matz@... (Yukihiro Matsumoto) 2001/07/02

Hi,

[#17141] Re: RCR: Exception methods (was: Re: Re: keeping an Exception object alive) — David Alan Black <dblack@...> 2001/07/02

Hello --

[#17142] Re: RCR: Exception methods (was: Re: Re: keeping an Exception object alive) — ts <decoux@...> 2001/07/02

>>>>> "D" == David Alan Black <dblack@candle.superlink.net> writes:

[ruby-talk:16792] wrapping structures

From: Martin Chase <stillflame@...>
Date: 2001-06-23 07:37:49 UTC
List: ruby-talk #16792
hey ruby hackers,

i have a problem writing this ruby extension 'o mine, and i was wondering if anyone could help me figure out why. i've narrowed it down to me not knowing enough about how ruby is wrapping structures, and how i have to treat those objects. for starters, i'm not really a wiz in c - this may be more at the root of my problem than anything else. my current guesses point to somewhere in the memory allocation area or in the Data_(Get|Wrap)_Struct calls, but i don't really know.

(please note: i sorta feel like a jerk for doing this, but i keep reminding myself that the project i'm working on is by and large for the ruby community, and that anyone who does help me will be doing so of their own volition... i don't expect anyone to download and compile and debug anything, just to look at the general idea i'm trying for and point me towards the resources i need to solve this. if anyone feels like this question is too involved, please ignore it completely. i think of this list as an information desk, not a research and development team.) 

anyway, here's a piece of my c coding that should (hopefully) show where i'm having the problem. nothing in it will really be important except the "Data_(Wrap|Get)_Struct" parts and what they deal with, as the rest i have verified as functional with non-ruby-extending test programs that use the same fuctions (but i left it in to help describe the setting): 

#################### C code starts here 

VALUE cDictionary; 

static void LP_dict_delete(void *p) 
{ 
Dictionary *q; 
q = p; 
dictionary_delete(*q); 
/* int dictionary_delete(Dictionary) */ 
} 

VALUE LP_dict_new(VALUE class, VALUE dict_names) 
{ 
VALUE rb_dict; 
VALUE argv[1]; 
Dictionary *LP_dict; 
*LP_dict = dictionary_create( 
STR2CSTR(rb_ary_shift(dict_names)), 
STR2CSTR(rb_ary_shift(dict_names)), 
STR2CSTR(rb_ary_shift(dict_names)), 
STR2CSTR(rb_ary_shift(dict_names))); 
argv[0] = rb_dict = Data_Wrap_Struct(class, 0, LP_dict_delete, LP_dict); 
rb_obj_call_init(rb_dict, 1, argv); 
return rb_dict; 
} 

static VALUE LP_dict_init(VALUE self, VALUE dict_names) 
{ 
rb_iv_set(self, "@dict_names", dict_names); 
return self; 
} 

static VALUE LP_dict_get_max_cost(VALUE self) 
{ 
Dictionary *LP_dict; 
int cost; 
Data_Get_Struct(self, Dictionary, LP_dict); 
cost = dictionary_get_max_cost(*LP_dict); 
return INT2NUM(cost); 
} 

## then later, in the Init subroutine, this is the relevant part: 

cDictionary = rb_define_class_under(mLinkParsing, "Dictionary", rb_cObject); 
rb_define_singleton_method(cDictionary, "new", LP_dict_new, 1); 
rb_define_method(cDictionary, "initialize", LP_dict_init, 1); 
rb_define_method(cDictionary, "get_max_cost", LP_dict_get_max_cost, 0); 

#################### C code ends here 

in the test script: 
----------------------------- 
#'require's and stuff... 
dict = Dictionary.new(dict_names) 
dict.get_max_cost() 
test.rb:20: [BUG] Segmentation fault 
ruby 1.7.0 (2001-05-17) [i686-linux] 
Aborted 
----------------------------- 

and also: 
----------------------------- 
dict = Dictionary.new(dict_names) 
dict = nil 
GC.start 
test.rb:21: [bug] rb_gc_mark(): unknown data type 0x28(0x4034b690) corrupted object 
ruby 1.7.0 (2001-05-17) [i686-linux] 
Aborted 
----------------------------- 

i know - ruby version 1.7.0, but i tried it with 1.6.3 to the same effect, so that's not an issue. 

i don't know - if i knew how to debug c stuff better, i could probly figure this out on my own, but, as it is, i've hit a dead end as to how i should attack this problem. i've tried pre-ALLOC-ing the Dictionary struct, but dictionary_create does that for itself: 
--------------------------------------- 
static Dictionary internal_dictionary_create(char * dict_name, char * pp_name, char * cons_name, char * affix_name, char * path) { 
Dictionary dict; 
static int rand_table_inited=FALSE; 
Dict_node *dict_node; 
char * dictionary_path_name; 
dict = (Dictionary) xalloc(sizeof(struct Dictionary_s)); 
/* then fills that structure */ 
--------------------------------------- 
(note: in addition to 'xalloc', the program i'm wrapping also defines and uses an 'xfree'. this matters only because ruby.h has a macro that redefines 'xfree' to 'ruby_xfree' - i get errors unless i include the program's files before ruby's.) 

there's lots of other things i've tried, in fact i've came up with a few more ideas while writing this letter, but (...time passes) to no avail. all i think i'm asking for is suggestions on where i should look to solve this. 

thank you, anyone who takes the time to consider this, 

Martin Chase <stillflame AT faeriemud DOT org>
"If you think you are too small to make a difference, try sleeping in a closed room with a mosquito..." African Proverb
___________________________________________________
GO.com Mail                                    
Get Your Free, Private E-mail at http://mail.go.com


In This Thread

Prev Next