From: "Iñaki Baz Castillo" Date: 2011-02-07T19:49:03+09:00 Subject: Re: rb_raise() causes segmentfault on xxxxx_alloc() function 2011/2/7 Peter Zotov : > I'm not exactly sure how this mechanism works (and udns too), but I'd > suggest: > a) If a C library needs an one-time initialization, implement that as a > class method of your Resolver class and call either on library loading > or on first use of the library (by defining a flag). > b) If a C library needs an initialization for each instance of the > object, just define initialize function for the class and do all the > initialization there; if you strictly need to do that in *_alloc > function(), try returning Qnil (I am not quite sure it will work at > all, but at least it's worth trying), or set a flag in the structure > you are returning. Either way will let you to determine whether to > raise an exception or not in the place where it's perfectly safe to do > that (the initialize function). > > It looks to me that you need both approaches here. Thanks a lot. I just need second approach as initialization of the C library must occur for each instance. I already tryed returning Qnil, and gives an ugly error: `new': wrong instance allocation (TypeError) So I took your second suggestion, but instead I set an attribute @alloc_error during xxxx_alloc() function, and inspect it in normal initialize() method (by raising if it is not nil). Thanks a lot! -- Iñaki Baz Castillo