J
J. Romano
Dear Perl community,
I have a problem here and I'm hoping that someone can help.
I am writing some XS code, and I need to detect whether a value
accessed through an SV pointer is defined or undefined. I read
"perldoc perlapi", and the closest I could find was this excerpt:
SvTRUE Returns a boolean indicating whether Perl would
evaluate the SV as true or false, defined or unde-
fined. Does not handle 'get' magic.
bool SvTRUE(SV* sv)
This is great for discovering a variable's boolean value, but I need
some way of knowing if an SV* was undefined when it was passed in. I
suppose I could always do this:
char *valueStr;
STRLEN valueLen;
valueStr = SvPV(*value, valueLen);
and then valueStr would be "" and valueLen would be 0 if *value
contains an undefined value. However, valueStr and valueLen would
both be the same thing if *value pointed to an empty string. The
line:
bool truthValue = SvTRUE(*value);
returns false for both undefined values and empty strings, which means
that it can't differentiate between them, either.
So I can't figure out how to check to see if an SV* value is
defined or not. Any test I perform (with SvPV, SvTRUE, or SvIV) gives
the same results when used with empty strings and undefined values.
This causes a problem if I need to know for sure which was passed in.
For those interested, I tried these commands:
REFCNT = 1
FLAGS = (POK,pPOK)
PV = 0x8102a70 ""\0
CUR = 0
LEN = 1
REFCNT = 1
FLAGS = ()
Unfortunately, I'm not too familiar with Devel:eek to really know
how to use its "Dump" output to my advantage. I see that with an
undefined value, SV equals NULL, but according to the debugger, it's
definitely set to some non-NULL value. Likewise, when I dump an empty
string, the "Dump" output says that LEN equals 1, but according when I
make the following call:
valueStr = SvPV(*value, valueLen);
valueLen gets set to zero (as it does with an undefined value).
Maybe the key to checking an undefined value is to check the FLAGS?
Or is there an easier way to do this that I'm not aware of?
Any help would be appreciated.
Thank you.
-- Jean-Luc
I have a problem here and I'm hoping that someone can help.
I am writing some XS code, and I need to detect whether a value
accessed through an SV pointer is defined or undefined. I read
"perldoc perlapi", and the closest I could find was this excerpt:
SvTRUE Returns a boolean indicating whether Perl would
evaluate the SV as true or false, defined or unde-
fined. Does not handle 'get' magic.
bool SvTRUE(SV* sv)
This is great for discovering a variable's boolean value, but I need
some way of knowing if an SV* was undefined when it was passed in. I
suppose I could always do this:
char *valueStr;
STRLEN valueLen;
valueStr = SvPV(*value, valueLen);
and then valueStr would be "" and valueLen would be 0 if *value
contains an undefined value. However, valueStr and valueLen would
both be the same thing if *value pointed to an empty string. The
line:
bool truthValue = SvTRUE(*value);
returns false for both undefined values and empty strings, which means
that it can't differentiate between them, either.
So I can't figure out how to check to see if an SV* value is
defined or not. Any test I perform (with SvPV, SvTRUE, or SvIV) gives
the same results when used with empty strings and undefined values.
This causes a problem if I need to know for sure which was passed in.
For those interested, I tried these commands:
SV = PV(0x80f5a84) at 0x80fc9f8perl -MDevel:eek -e '$a = ""; Dump($a)'
REFCNT = 1
FLAGS = (POK,pPOK)
PV = 0x8102a70 ""\0
CUR = 0
LEN = 1
SV = NULL(0x0) at 0x80fc9f8perl -MDevel:eek -e '$a = undef; Dump($a)'
REFCNT = 1
FLAGS = ()
Unfortunately, I'm not too familiar with Devel:eek to really know
how to use its "Dump" output to my advantage. I see that with an
undefined value, SV equals NULL, but according to the debugger, it's
definitely set to some non-NULL value. Likewise, when I dump an empty
string, the "Dump" output says that LEN equals 1, but according when I
make the following call:
valueStr = SvPV(*value, valueLen);
valueLen gets set to zero (as it does with an undefined value).
Maybe the key to checking an undefined value is to check the FLAGS?
Or is there an easier way to do this that I'm not aware of?
Any help would be appreciated.
Thank you.
-- Jean-Luc