I'm trying to write a module that will allow one to access some mapping software I wrote ( http://www.reza.net/rmap/ ) via perl. I can get this to work if I make it a single function call that passes all the variables rmap code, however, I'de like a finer level of control over it. I basically want to be able to have 4 functions : Image::Rmap::newImageLayout() which generates an Image::Rmap::Scene that defines the viewing area of the image and contains a mapping of object->colors Image::Rmap::setColor() which takes an Image::Rmap::Scene object and does the color allocation for the above object. Image::Rmap::newOptions() which returns an Image::Rmap::Options object that contains various information such as longitude/latitude/zoom/etc. and finally, Image::Rmap::generate() which takes both an Image::Rmap::Scene object and an Image::Rmap::Options object as parameters and generates a gif/jpg/etc. as a result. This is the typemap that I'm using : TYPEMAP Image::Rmap::Options T_PTROBJ Image::Rmap::Scene T_PTROBJ I've gotten parts to work. I can create a new Image::Rmap::Scene, and set colors, and after I'm done, the test.pl code will segfault sometimes. Based on how I'm calling things and how many times I'm calling setColor(), as well as if I stick any ``print "foo\n";'' lines at the end. If I try calling newOptions, I get ``Can't locate auto/Image/Rmap/Options.al ...'' And generate() seems somewhat smart, as when I call it (withough the Image::Rmap::Options object, as I can't create it), it complains : ``options is not of type Image::Rmap::Options at t.pl line 7.'' I've read over most all of perlxs and perlxstut, but the example just seems to confuse me, and varying the 'PACKAGE' parameter seems to break things. This is what I've got so far (not long).. I'm obviously missing something, and I'm assuming it has to do with garbage collecting. I've looked at other people's .xs files and that's what I used to base this from. _any_ help would be greatly appreciated - even if it's just to point me to some documentaiton that I've missed. Thanks in advance, Reza p.s. please CC: [EMAIL PROTECTED] as well. ------------- Rmap.xs --------------- #ifdef __cplusplus extern "C" { #endif #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #ifdef __cplusplus } #endif #include "rgb.h" // this defines the color struct and // has a bunch of colors defined #define BIT32 int #define NOPRINT -1 struct imageLayout { int height; //y int width; //x short transparent; gdImagePtr im; int colormap[5][16]; }; struct options { int cities; int gridlines; double zoom; double xrot; double yrot; double zrot; char* mapfile; char* outfile; char* colorfile; BIT32 desired_categories; BIT32 desired_continents; }; /* some more stuff */ extern void generate(struct imageLayout *scene, struct options *o); extern struct color* get_color (char* c); typedef struct imageLayout* Image__Rmap__Scene; typedef struct options* Image__Rmap__Options; MODULE = Image::Rmap PACKAGE = Image::Rmap Image::Rmap::Scene newImageLayout(height, width, transparent) int height; int width; int transparent; CODE: RETVAL = safemalloc(sizeof(RETVAL)); RETVAL->height = height; RETVAL->width = width; RETVAL->transparent = transparent; RETVAL->im = gdImageCreate(width, height); OUTPUT: RETVAL void setColor(scene, catagory, type, color_name) Image::Rmap::Scene scene; int catagory; int type; char* color_name; CODE: { struct color *c; if (!strcmp(color_name, "none")) { scene->colormap[catagory][type] = NOPRINT; } else { if (catagory > 4 || type > 15 || catagory < 0 || type < 0) { croak("Declaration value out of range (%d,%d).", catagory,type); } else { c = get_color(color_name); if (c == NULL) { croak("The color %s was not found", color_name); } else { scene->colormap[catagory][type] = gdImageColorAllocate(scene->im, c->r, c->g, c->b); } } } } Image::Rmap::Options newOptions(cities, gridlines, zoom, xrot, yrot, zrot, mapfile, outfile, colorfile, des_cat, des_cont) int cities; int gridlines; double zoom; double xrot; double yrot; double zrot; char* mapfile; char* outfile; char* colorfile; int des_cat; int des_cont; CODE: { RETVAL = malloc(sizeof(RETVAL)); RETVAL->cities = cities; RETVAL->gridlines = gridlines; RETVAL->zoom = zoom; RETVAL->xrot = xrot; RETVAL->yrot = yrot; RETVAL->zrot = zrot; RETVAL->mapfile = mapfile; RETVAL->outfile = outfile; RETVAL->colorfile = colorfile; RETVAL->desired_categories = des_cat; RETVAL->desired_continents = des_cont; } OUTPUT: RETVAL void generate(scene, options) Image::Rmap::Scene scene; Image::Rmap::Options options; CODE: { generate(scene, options); }
