On Dec 6, 2004, at 4:21 AM, Reinhard Pagitsch wrote:

int
_baar(IN x, OUT y, perror)
   int x;
   SV* y;
   SV* perror;
PREINIT:
   char tmp1[256];
CODE:
{
        if(!foo(x))
        {
        sprintf(tmp1,"Wrong parameter!",);
        sv_setpvn(perror, tmp1, strlen(tmp1));
        XPUSHs(sv_2mortal(newSViv(-1)));
        XSRETURN_IV(-1);

since your xsub is defined as returning a single value, you shouldn't need to use XPUSHs to make stack space -- it will already be there.


also, as i understand, XSRETURN_* will return immediately and will do the stack work for you, so the XPUSHs shouldn't be necessary.

third, that's not a very perlish failure. wouldn't it make more sense to croak() on that error? e.g.:

  if (! foo (x))
     croak ("Wrong parameter %d", x);  /* does not return */


-- "the ternary operator makes it a bit less ugly." -- kaffee



Reply via email to