From: Henry Maddocks Date: 2012-08-31T07:40:16+09:00 Subject: Re: Common Traps for C extensions On 30/08/2012, at 7:34 PM, Bernhard Brodowsky wrote: > > But now I am thinking of possible traps I might run into. For example, > the Ruby interpreter forces me to differentiate between allocation and > initialization and in my current implementation, the User could redefine > the initialize() method of my class and then call another method, which > results in undefined behaviour or possibly segfault. Someone might sub-class and not call super. If it's possible to seg fault your extension then you are doing it wrong. After calling the alloc function, your class might not be 'valid', but it must be 'safe'. This is the reason Ruby added the alloc hook. Remember, when you are writing an extension you are effectively writing Ruby and in Ruby implementing initialize is optional and nil (or Qnil) is a valid value. You should bare this in mind when designing your extension. Henry