In an extension, doing a Data_Make_Struct and getting value back

I have done Data_Make_Struct(klass, c-type, 0, free(), c_var*) and now I
want to get the data back so I do a Data_Get_Struct( ruby_Var, c-type,
c_var*) and it says that its the wrong type it's "klass" and should be
"Data".

I know I'm missing a very important (probably simple) step here, but I can't
figure out what it is.

Anyone have a clue?

Scott Walton

In article <Gczaf.1562$p37.1202@newssvr17.news.prodigy.com>,

I have done Data_Make_Struct(klass, c-type, 0, free(), c_var*) and now I
want to get the data back so I do a Data_Get_Struct( ruby_Var, c-type,
c_var*) and it says that its the wrong type it's "klass" and should be
"Data".

I know I'm missing a very important (probably simple) step here, but I can't
figure out what it is.

Anyone have a clue?

Could you post the actual code?

I notice above that you have:
Data_Make_Struct(klass, c-type, 0, free(), c_var*)

Whereas the pickaxe says it should be:
  Data_Make_Struct(klass, c-type, 0, free(), c_type*)

Not sure if that's an issue or not...

Phil

···

JSW <jsw@abc.com> wrote:

Hi,

At Fri, 4 Nov 2005 14:37:08 +0900,
Phil Tomson wrote in [ruby-talk:164095]:

I notice above that you have:
Data_Make_Struct(klass, c-type, 0, free(), c_var*)

Whereas the pickaxe says it should be:
  Data_Make_Struct(klass, c-type, 0, free(), c_type*)

Parentheses after free should not be there.

···

--
Nobu Nakada

A snippet of the code around the Get and Make parts:
.....
    SQLHANDLE hDb;
    VALUE retVal;
    handle hCon;
    VALUE conRet;
    sConnect *sC;

    conRet = Data_Make_Struct(cDB2Conn, sConnect, 0, free, sC);
    sC->connection = hDb;
    return conRet;

and the later part where it's used:

    handle *hCon;
    Data_Get_Struct( conHandle, handle, hCon );

This is where it fails with "incorrect class - Data expected"

Does this give anyone an additional thought?

Scott Walton

"Phil Tomson" <ptkwt@aracnet.com> wrote in message
news:dkeqlq018mr@enews2.newsguy.com...

···

In article <Gczaf.1562$p37.1202@newssvr17.news.prodigy.com>,
JSW <jsw@abc.com> wrote:

I have done Data_Make_Struct(klass, c-type, 0, free(), c_var*) and now I
want to get the data back so I do a Data_Get_Struct( ruby_Var, c-type,
c_var*) and it says that its the wrong type it's "klass" and should be
"Data".

I know I'm missing a very important (probably simple) step here, but I
can't
figure out what it is.

Anyone have a clue?

Could you post the actual code?

I notice above that you have:
Data_Make_Struct(klass, c-type, 0, free(), c_var*)

Whereas the pickaxe says it should be:
Data_Make_Struct(klass, c-type, 0, free(), c_type*)

Not sure if that's an issue or not...

Phil

In article <B7Raf.6263$Kv.5852@newssvr22.news.prodigy.net>,

A snippet of the code around the Get and Make parts:
....
   SQLHANDLE hDb;
   VALUE retVal;
   handle hCon;
   VALUE conRet;
   sConnect *sC;

   conRet = Data_Make_Struct(cDB2Conn, sConnect, 0, free, sC);
   sC->connection = hDb;
   return conRet;

and the later part where it's used:

   handle *hCon;
   Data_Get_Struct( conHandle, handle, hCon );

(What type is conHandle? It should be a VALUE holding a Class)
OK, so you the 'c-type' you gave to Data_Make_Struct was sConnect, but
you're asking for something with a type of handle back, wouldn't you want:

     sConnect *hCon;
     Data_Get_Struct( conHandle, sConnect, hCon);

instead?

This is where it fails with "incorrect class - Data expected"

Well, I didn't use Data_Make_Struct, but here's an example from my code
using Data_Wrap_Struct, maybe it'll help:

/*begin point.c code*/
typedef struct {
        double x;
        double y;
        double z;
} ACO_3DPoint_Struct;

//allocator
static VALUE aco_point_alloc(VALUE klass) {
  VALUE object;
  ACO_3DPoint_Struct* point = (ACO_3DPoint_Struct*)malloc(sizeof(
ACO_3DPoint_Struct));
  object = Data_Wrap_Struct(klass,0,aco_point_free,point);
  return object;
}

//initialize
static VALUE aco_point_init(VALUE self, VALUE x, VALUE y, VALUE z){
  ACO_3DPoint_Struct* _self ;
  //double x, y;
  Data_Get_Struct(self, ACO_3DPoint_Struct, _self);
  _self->x = NUM2DBL(x);
  _self->y = NUM2DBL(y);
  _self->z = NUM2DBL(z);
  return self;
}

static VALUE aco_point_getx(VALUE self){
  ACO_3DPoint_Struct *_self;
  Data_Get_Struct(self, ACO_3DPoint_Struct, _self);
  return rb_float_new(_self->x);
}

static VALUE aco_point_setx(VALUE self, VALUE x){
  ACO_3DPoint_Struct* _self;
  Data_Get_Struct(self, ACO_3DPoint_Struct, _self);
  _self->x = NUM2DBL(x);
}
//skip a lot of stuff...

VALUE cACOMod;
VALUE cACOPoint3D;

void Init_aco_point3d() {
  printf("ACO_Ext initializing...\n");
  cACOMod = rb_define_module("ACO");

  cACOPoint3D = rb_define_class_under(cACOMod,"Point3D",rb_cObject);
  //cACOPoint3D = rb_define_class_under(cACOMod,"Point3D",rb_cObject);
  cACOGraph = rb_define_class_under(cACOMod,"Graph",rb_cObject);
  rb_define_alloc_func(cACOPoint3D, aco_point_alloc);
  rb_define_method(cACOPoint3D,"initialize",aco_point_init,3);
  //skip a lot of operators
}
/*end point.c */

Phil

···

JSW <jsw@abc.com> wrote: