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

Hi!

I've embedded Perl in C. Everything goes well, except when I pass a string to eval_sv() that contains literal metacharacters, croak is being called.

So I tried to call quotemeta via the following C subroutine, but quotemeta never gets found. My next idea was to use the implementation of pp_quotemeta in B::Deparse, but that didn't work either.

I'd be grateful for some insight offered.

static void call_quotemeta(SV *string) { int count; SV *output; dSP; ENTER; SAVETMPS; PUSHMARK(SP); XPUSHs(sv_2mortal(string)); PUTBACK; count = call_pv("quotemeta", G_SCALAR); SPAGAIN; if (count != 1) croak("Big trouble\n"); output = POPs; PUTBACK; FREETMPS; LEAVE; return output; }

Replies are listed 'Best First'.
Re: embedding Perl in C / calling Perl core function from C
by Joost (Canon) on Dec 10, 2006 at 23:58 UTC
    I've embedded Perl in C. Everything goes well, except when I pass a string to eval_sv() that contains literal metacharacters, croak is being called.
    While I don't have an immediate solution except for doing the escaping yourself or calling a perl subroutine with the string as an argument, I'm wondering why you'd want to do this. eval_sv is equivalent to eval $string in perl. You don't want to put any random stuff in there. It's supposed to be code.