Re: XS: returning a 64-bit unsigned int?
by syphilis (Archbishop) on Sep 27, 2011 at 06:40 UTC
|
This works as desired for me:
void modSV( SV *ref ) {
SV *sv = SvRV( ref );
unsigned __int64 uv = 9223372036854775809ull;
sv_setuv(sv, uv);
}
Outputs:
SV = IV(0x381af90) at 0x381afa0
REFCNT = 1
FLAGS = (PADMY,IOK,pIOK)
IV = 123
SV = IV(0x381af90) at 0x381afa0
REFCNT = 1
FLAGS = (PADMY,IOK,pIOK,IsUV)
UV = 9223372036854775809
Haven't yet investigated why/where your approach falls down.
Cheers, Rob | [reply] [Watch: Dir/Any] [d/l] [select] |
|
| [reply] [Watch: Dir/Any] |
|
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
|
Re: XS: returning a 64-bit unsigned int?
by ikegami (Patriarch) on Sep 27, 2011 at 07:13 UTC
|
#define SvNOK_only(sv) \
(SvOK_off(sv), SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
#define SvIOK_only(sv) \
(SvOK_off(sv), SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
#define SvIOK_only_UV(sv) \
(assert_not_glob(sv) \
SvOK_off_exc_UV(sv), SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
| [reply] [Watch: Dir/Any] [d/l] |
|
| [reply] [Watch: Dir/Any] |
|
The UV version turns on IOK and *preserves* IsUV instead of turning on IOK and IsUV.
The other two don't preserve anything.
I don't know why the difference.
There is a SvIsUV_on(sv) that would have done the trick. Keep in mind that your original approach didn't converting the scalar to one that supports IVs (if possible) and you didn't handle magic. If it's just an internal scalar, you could get away with not doing those, though.
| [reply] [Watch: Dir/Any] [d/l] |
|
|
|
Re: XS: returning a 64-bit unsigned int?
by Anonymous Monk on Sep 27, 2011 at 06:49 UTC
|
SV*
bob()
PREINIT:
SV* temp;
//~ unsigned int uncle = 42;
unsigned long long uncle = 42;
CODE:
//~ temp = newSVuv( 42 );
temp = newSVuv( uncle );
SvIOK_only_UV( temp );
warn("we got em %p SvIOK_UV(%b)SvUVX(%u)", temp, SvIOK_UV(temp
+), SvUVX(temp) );
RETVAL = temp;
OUTPUT:
RETVAL
Always gives we got em 3f8d14 SvIOK_UV(0)SvUVX(42) at -e line 1.
SV = IV(0x3f8d10) at 0x3f8d14
REFCNT = 1
FLAGS = (TEMP,IOK,pIOK)
IV = 42
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
| [reply] [Watch: Dir/Any] |
|
Right, but shouldn't newSVuv make a UV and not an IV? Talk about false advertising :)
| [reply] [Watch: Dir/Any] |
|
|