Hi,
I have an object whose Devel::Peek::Dump() is as follows:
SV = RV(0xa88ae8) at 0xa88adc
REFCNT = 1
FLAGS = (TEMP,ROK)
RV = 0xa889bc
SV = PVMG(0x253aedc) at 0xa889bc
REFCNT = 1
FLAGS = (OBJECT,IOK,READONLY,OVERLOAD,pIOK)
IV = 41565372
NV = 0
PV = 0
STASH = 0x97dea4 "Math::MPFR"
Within XS code, how do I establish that the TEMP flag is there ? I had thought that
SvTEMP(sv) would return the numeric value of the TEMP flag, but it returns zero. I also checked
SvTEMP(SvRV(sv)) - which returned 0 (as I expected).
UPDATE: I now believe that what I was testing for the presence of the TEMP flag did, in fact *not* have the TEMP flag set at all - and that everything worked as it should have.
As a second question, what does the presence of that TEMP flag mean? Looking at the XSub that creates the object, I don't really see a reason for the TEMP flag to be there. That XSub is:
SV * Rmpc_realref(mpc_t *op) {
mpfr_t * mpfr_t_obj;
SV * obj_ref, * obj;
New(42, mpfr_t_obj, 1, mpfr_t);
if(mpfr_t_obj == NULL) croak("Failed to allocate memory in Rmpc_r
+ealref function");
obj_ref = newSV(0);
obj = newSVrv(obj_ref, "Math::MPFR");
mpfr_t_obj = mpc_realref(*op);
sv_setiv(obj, INT2PTR(IV,mpfr_t_obj));
SvREADONLY_on(obj);
return obj_ref;
}
where mpc_realref() is an mpc library function that returns a pointer to an mpfr library structure (mpfr_t).
UPDATE: The TEMP flag was *not* being set by the XSub - it was only being set because the XSub's return value was not being asigned to a variable.
I have other similar objects (where the only difference I can see is that the TEMP flag is absent). These other objects require a slightly different DESTROY() procedure - so I'm thinking that the solution is to have:
void DESTROY(mpfr_t * op) {
if(the TEMP flag is present) {do one thing}
else {do the other thing}
}
Hence my interest in being able to detect the presence of the TEMP flag.
Cheers,
Rob
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.