Steve Hay <[EMAIL PROTECTED]> writes:
>Shinar, Tamar wrote:
>
>>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.
>>_____________________________________________________________________
>>
>>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) {
>>
>I think the above line should have been
>
> if (svp) {
>
>The point of the check is to ensure that you don't de-ref svp (i.e.
>don't use *svp) if svp is NULL.
>
>This could explain your continued core dumps.
Whoops - you are of course correct Steve - thanks for spotting that.
>
>Steve
>
>> 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/