Hi,

I'm writing my first Ruby extension in C, which will be an interface
to libcrack for checking passwords.

Here's the code of ruby_crack.c:

#include "ruby.h"
#include "crack.h"

static VALUE passwd_init(VALUE self, VALUE passwd) {
  fprintf(stderr, "passwd = %s\n", STR2CSTR(passwd));
  return passwd;
}

static VALUE passwd_check(VALUE self, VALUE dict) {
  char *string;

  fprintf(stderr, "%s\n", STR2CSTR(self));
  string = FascistCheck(STR2CSTR(self), STR2CSTR(dict));
  return rb_str_new2(string);
}

VALUE cCrack;

void Init_Crack() {
  fprintf(stderr, "In Init_Crack()\n");
  cCrack = rb_define_class("Password", rb_cString);
  rb_define_method(cCrack, "initialize", passwd_init, 1);
  rb_define_method(cCrack, "check", passwd_check, 1);
  return;
}


However, when I call it from Ruby, the initialisation doesn't happen
properly:

[ianmacd / jiskefet]$ irb                                        ~/src/ruby-crack
irb(main):001:0> require 'Crack'
In Init_Crack()
true
irb(main):002:0> foo = Password.new("foobar")
passwd = foobar
""
irb(main):003:0> foo
""
irb(main):004:0> 


The extension is properly loaded and initialised, but when calling
passwd_init(), foo gets set to an empty string, not "foobar". I can't
figure out why this is. Password is supposed to be a subclass of
String.

I'm sure I'm overlooking something very basic here, but what?

Ian
-- 
Ian Macdonald               | I'd like to see the government get out of
ian / caliban.org             | war altogether and leave the whole field to
                            | private industry.   -- Joseph Heller 
                            | 
                            |