Scott T. Hildreth <[EMAIL PROTECTED]> writes: >Hello Nick, > > Sorry to send this to you directly, but I hopping to get a >explanation soon. I sent this to the perl-xs list, but my post >is not showing up. This happens with the DBI-users as well, I >will post a question or reply and it will show up hours later. >If I post to DBI-Dev, it shows right up...not sure what the problem >is. Anyway I would appreciate any help here. > > >On Thu, 2004-09-23 at 09:13, Scott T. Hildreth wrote: >> Hello, >> >> I've seen this posted before, but I'm not sure what the answer is. >> I have an XS interface to a 'C' library, which I used h2xs to create.
Personally I don't use h2xs. (I was writing XS before it existed and early versions were very weak, never got round to using it since.) >> One of the functions takes argc & argv parameters. The h2xs created >> argv as a char **, which is obviously correct. If you say so const char ** is possibly clearer about direction. >When I run make test >> which is loading the module, it dies because XS_unpack_PtrPtr() is >> undefined. I see the typemap file in ExtUtils is defining char ** as >> a T_PACKEDARRAY and so XS_unpack_$ntype($arg) gets created. Well $arg will become the SV that is being passed and $ntype has become PtrPtr apparently. >Where is >> this? Not in the perl sources for a start (I just grep'ed them). >>Is it a function or a macro? Do I need to implement it? I think h2xs expects you to implement it - but I wouldn't. >>I saw >> the posting to packing a char ** on to the stack. Do I need to do the >> opposite? I don't think going the route h2xs has suggested is the right way to go. It isn't very perlish to pack strings or even pass an array ref. For example perl's system() takes a list of strings. When faced with something taking argc/argv I usually code something to work like system() does; like this: int SomeFunc(...) CODE: { char **argv; int i; Newz(42,argv,items+1,char *); // one more than we need so terminating NULL for (i = 0; i < items; i++) { argv[i] = SvPV_nolen(ST(i)); // Init strings } RETVAL = SomeFunc(items,argv); // Call the C function Safefree(argv); // Free the array } OUTPUT: RETVAL You could do something similar that expected an incoming array ref and itterated over array elements rather that items/ST(i). Of course if char ** is for output parameters that is wrong, but in such a case I would probably want a list return so would do the PPCODE thing. If above doesn't help then I would like to see: - The C declaration of the function - the XS code from h2xs - The C code after xsubpp