Nick,

Thank you for the suggestions.  I think I have made my 'get' functions safe now.  

However, the external C library still behaves unstably on the data I pass it from perl.
It will sometimes core dump with SEGV, sometimes give unexpected output.
Is there something wrong in the way I am using New or in my MakeAanimal function?
There seems to be some memory problem, since the library behavior can be altered by 
seemingly irrelevant changes such as adding printf's.

Any suggestions would be appreciated.

thanks,
Tamar

_____________________________________________________________________

The 1st thing to notice is that return from hv_fetch can be NULL if field
does not exist in the hash. So SvOK(*sv) will core dump, also you go on 
to de-ref the thing even if your test said SV was not okay.

So you want something like this - you can provide "safe" values for 
not-there and undef cases - I have used NULL and "" as examples.
  SV **svp = hv_fetch(...)
  if (*svp) {
     if (SvOK(*svp)) {
       /* defined value of some kind (but may not be a string, but SvPV will
          force that for us). In perl5.6+ you may need to consider case 
          of string being in UTF-8
        */ 
       return SvPV_nolen(*svp);
     }
     else
      {
       /* undef value */
       return "";
      }
  }
  else {
    /* No such member */
    return NULL;
  }

-- 
Nick Ing-Simmons
http://www.ni-s.u-net.com/

Reply via email to