Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

(tye)Re: overload and XS

by tye (Sage)
on May 18, 2001 at 09:10 UTC ( #81434=note: print w/replies, xml ) Need Help??


in reply to overload and XS

Why rewrite your Perl code in C?? Just because you have some XS code doesn't mean you have to do every single thing for that module in XS code!

Do in C, only the stuff that is easy in C. Use a wrapper subroutine written in Perl to do stuff like what you are trying above. The code you have above is the kind of code that breaks when a new version of Perl comes out (or doesn't work when someone tries to use it on an older version of Perl than the one you developed it on).

I've done this quite a bit and have been extremely happy with the results. I find I can make modules with much nicer, Perlish interfaces than I see in other XS modules. Plus the code ends up being much easier to understand, maintain, enhance, and debug.

        - tye (but my friends call me "Tye")

Replies are listed 'Best First'.
Re: (tye)Re: overload and XS
by kmacleod (Initiate) on May 18, 2001 at 16:56 UTC

    This module is a bridge between C code and Perl code (similar to Inline), the 'value' above is a C pointer to the structure that is tied, that I want to be able to stringify. 'xml_attribute_stash' is the Perl wrapper package for that particular class, which has 'use overload' with '""' and 'fallback' specified.

    I found that I needed to use SvAMAGIC_on to enable overload on that tied C-structure so that the wrapper would see it as overloaded, but 'fallback' still isn't enabled. I'm guessing there's deeper magic to turn on fallback, since the perl wrapper isn't.

      What I am saying is: Move all of that code out of the C part of the module/XS. Have the C part just return the 'value' as an IV or UV in an orinary Perl scalar and do all of the hash creation, taking of references, tieing, overloading, and magic in Perl code.

              - tye (but my friends call me "Tye")

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://81434]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2023-02-08 10:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (41 votes). Check out past polls.

    Notices?