Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Calling perl builtins from C

by Cine (Friar)
on Aug 04, 2003 at 19:59 UTC ( #280776=perlquestion: print w/replies, xml ) Need Help??

Cine has asked for the wisdom of the Perl Monks concerning the following question:

How do I make a call to a builtin function from XS?
This doesnt work:
use Inline C => q{ void c_time() { SV* val = get_cv("localtime", FALSE); if (!val) croak("Name does not exists!"); call_sv(val,GIMME_V); } }; print scalar c_time();
This does
sub helper { localtime(); } use Inline C => q{ void c_time() { SV* val = get_cv("helper", FALSE); if (!val) croak("Name does not exists!"); call_sv(val,GIMME_V); } }; print scalar c_time();


T I M T O W T D I

Replies are listed 'Best First'.
Re: Calling perl builtins from C
by chromatic (Archbishop) on Aug 04, 2003 at 20:30 UTC

    localtime isn't implemented in Perl as a function. It's actually a pp code. As of Perl 5.8.0, see pp_sys.c. That actually won't help you, either, because it takes and returns internal Perl data structures.

    All of this is mostly academic, though, because there's already a C localtime call, if you really need it.

    I'm not good at XS, but I'd break my code into smaller chunks and do as little in C as possible; if you find yourself needing to call internal Perl pp codes, you could probably refactor your code down more sooner than you could figure out how to fake up what the pp code actually needs. (See again my disclaimer about not being good at XS, though.)

Re: Calling perl builtins from C
by revdiablo (Prior) on Aug 04, 2003 at 20:14 UTC
      Yes, just noticed it. Two of the same of this kind of questions on one day?

      T I M T O W T D I

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2022-10-07 15:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred way to holiday/vacation is:











    Results (30 votes). Check out past polls.

    Notices?