Xsub: doing $$var = Obj->new in C 
Author Message
 Xsub: doing $$var = Obj->new in C

I've got some code that I'm invoking as:

        $obj->get_global_pointer(\$gp)

where get_global_pointer is an xsub. I want to do the equivalent of

        $$gpref = GP->new()

I can generate the blessed reference for the rhs no problem, it's
just assigning to lhs that I'm having problems with.

What I'd like is the equivalent of sv_setrv() ... the equivalent routines
for returning strings & integers work fine with the likes of

        intvar = SvRV(intref);
        sv_setiv(intvar, ival);

Any suggestions?

thanks,
--bob



Fri, 18 Jul 1997 23:34:46 GMT  
 Xsub: doing $$var = Obj->new in C
: I've got some code that I'm invoking as:
:
:       $obj->get_global_pointer(\$gp)
:
: where get_global_pointer is an xsub. I want to do the equivalent of
:
:       $$gpref = GP->new()
:
: I can generate the blessed reference for the rhs no problem, it's
: just assigning to lhs that I'm having problems with.
:
: What I'd like is the equivalent of sv_setrv() ... the equivalent routines
: for returning strings & integers work fine with the likes of
:
:       intvar = SvRV(intref);
:       sv_setiv(intvar, ival);
:
: Any suggestions?

I think you just want this:

    refvar = SvRV(refref);
    sv_setsv(refvar, refval);

You should probably guarantee that SvROK(refref) is true somehow.

There's no need for a special sv_setrv() here because it's not doing any
extra type coercion above what is already implicit in SV assignment.

Larry



Mon, 21 Jul 1997 02:09:31 GMT  
 Xsub: doing $$var = Obj->new in C

   I've got some code that I'm invoking as:

           $obj->get_global_pointer(\$gp)

   where get_global_pointer is an xsub. I want to do the equivalent of

           $$gpref = GP->new()

   I can generate the blessed reference for the rhs no problem, it's
   just assigning to lhs that I'm having problems with.

Let me get this straight (if I can).  You have an XSUB which has a
prologue starting something like this:

        SV *
        get_global_pointer(foo)
                SV *    foo

And, you pass ``foo'' in as a scalar reference?

If that's so, then you should only need something like:

        SvSetSV(SvRV(foo), <generated SV* here>)

Or, if the generated version is a temp that you need to preserve,

        newSVsv(SvRV(foo), <generated SV* here>)

Was that all you needed, or did I misunderstand the problem?

--

speaking only for myself                        ...!decvax!orb!spider



Mon, 21 Jul 1997 15:28:07 GMT  
 Xsub: doing $$var = Obj->new in C

Quote:

>Was that all you needed, or did I misunderstand the problem?

I think you got it :-). After some more staring I found a much more concise
way to do what I was doing:

    sv = sv_setref_iv(SvRV(gpref), "Nexus::GlobalPointer", gp);

thanks for the code tho; I'm starting to actually understand this
stuff now :-).

--bob



Tue, 22 Jul 1997 22:53:55 GMT  
 Xsub: doing $$var = Obj->new in C

Quote:

>I think you just want this:

>    refvar = SvRV(refref);
>    sv_setsv(refvar, refval);

>You should probably guarantee that SvROK(refref) is true somehow.

>There's no need for a special sv_setrv() here because it's not doing any
>extra type coercion above what is already implicit in SV assignment.

Ahh, cool. Thanks for the info (my solution is in another post in this thread).

--bob



Tue, 22 Jul 1997 22:55:37 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. to use $obj->var or $obj->{'_var'}

2. $var->$method vs $var->$method()

3. -textvariable => \$obj->{key}

4. question re: sytanx for interpolation of obj->method in qq context

5. receiving variable from web page with <cgiscript>?<var>=x

6. XSUB: curcsv->wantarray in Perl5?

7. new Object() vs. Object->new()

8. newbie question regarding s/<old string>/<new string>/g

9. Apache::Request->new or ->instance..

10. Apache::Request->new or ->instance..

11. HTTPD::UserAdmin->new->encrypt question

12. Using ne operator on one var->multiple rvalues

 

 
Powered by phpBB® Forum Software