From: Jared Richardson Date: 2006-03-23T21:48:54+09:00 Subject: Re: C extensions question My original code was written just like that but I cut it down for the newsgroup posting. :) Thanks! "Gerardo Santana G�mez Garrido" wrote in message news:b06e22130603222235r5db97687l@mail.gmail.com... Hello Jared. I'm not familiar with Ingres, but according to http://www.ingres.com/download/oapi.pdf and this http://www.rubycentral.com/book/ext_ruby.html I'd write it this way: -------------- >8 -------------- #include "ruby.h" #include static VALUE rb_cIngres; static void ingres_free(void *p) { IIAPI_RELENVPARM relEnvParm; IIAPI_TERMPARM termParm; relEnvParm.re_envHandle = p; IIapi_releaseEnv(&relEnvParm); /* test return status */ IIapi_terminate(&termParm); /* test return status */ } static VALUE ingres_alloc(VALUE klass) { IIAPI_INITPARM initParm; /* * initialize initParm structure here * before passing it along to IIapi_initialize */ IIapi_initialize(&initParm); if (initParm.in_status != IIAPI_ST_SUCCESS) { initParm.in_envHandle = NULL; /* do something else probably */ } return Data_Wrap_Struct(klass, 0, ingres_free, initParm.in_envHandle); } static VALUE ingres_init(VALUE self) { /* Initialization stuff */ return self; } void Init_ingres(void) { rb_cIngres = rb_define_class("Ingres", rb_cObject); rb_define_method(rb_cIngres, "initialize", ingres_init, 0); } -------------- 8< -------------- But I can't test it. 2006/3/22, Jared Richardson : > Hi all, > > I haven't done any "real" work in C in nearly 10 years and I'm still > learning Ruby, so it's quite possible that I'm just doing something dumb, > but I'm stuck here. I'm trying to call Ingres database code from Ruby, so > I'm writing some C extensions. > > I have Ruby calling into C code. Very easy and very nice. > > I have Ingres sample code (which is C) compiling and running fine. > > However, when I try to invoke Ingres code from any of my C code and run it > (from Ruby), I get a seg fault. > > It feels like Ruby can't see the Ingres libraries but the code samples > don't > seem to having any problems. I suspect I'm missing something simple... > > Do you need to do any special wrapping or declaring of code that isn't > touched from within your Ruby? I've been through the Pickaxe book and > several online samples/tutorials and I don't see that it's needed... but > then again, my code isn't running. :) > > Here's my code as it is now... any hints or clues? > > #include "ruby.h" > # include > # include > > static VALUE cIngres; > > static VALUE ii_exec(VALUE self) { > printf("\n\nExec was run from within the Ruby code \n\n"); > IIAPI_INITPARM initParm; > printf("one\n"); > IIapi_initialize( &initParm ); > printf("two\n"); > return Qnil; > } > > void Init_Ingres() { > cIngres = rb_define_class("Ingres", rb_cObject); > rb_define_method(cIngres, "exec", ii_exec, 0); > } > > > Thanks! > > Jared > http://jaredrichardson.net > > > > -- Gerardo Santana "Between individuals, as between nations, respect for the rights of others is peace" - Don Benito Ju�rez http://santanatechnotes.blogspot.com/