Hiya,

Brian keeps encouraging me to get on the Inline train, so here I am. =)

I'm wondering whether there's a better way to embed C data structures
inside Perl data structures.  I don't need to access them from Perl
(I'm using Inline wrappers for that), so I don't think Inline::Struct
is the ticket.  So far I have this hacky method:

-----------------------------------------------------
  int create_struct (SV *self, double x, double y) {
    double *fooey;
    HV *datahash;
  
    fooey = malloc(10*sizeof(double));
    fooey[0] = x;
    fooey[1] = y;
  
    hv_store(SvRV(self), "the_struct", 10, newSViv((IV) fooey), 0);
  }
  
  double query_struct (SV *self) {
    HV *selfhash;
    double *fooey;
    SV **hashval;
  
    selfhash = SvRV(self);
    hashval = hv_fetch(selfhash, "the_struct", 10, 0);
    fooey = (double *) SvIV(*hashval);
  
    printf("IV is %u and %u and %u\n", fooey, &fooey, *fooey);
    return(fooey[0] + fooey[1]);
  }
-----------------------------------------------------

I call these methods from Perl, by doing $self->create_struct(3.3, 4.4)
and the like.  Anyone got a better idea for the embedding?  Eventually
it's going to have to take a large hash of hashes as input, and create
a large (unknown size) 2-dimensional array of doubles from it.

 -Ken

Reply via email to