in reply to How to call Encode::decode from Perl XS
Bases on my experience, it could be something like (untested)
int encode_loaded = 0; SV *m_encode = newSVpvs ("decode"); /* Or "Encode::decode", I'm not su +re */ SV *sv_enc = newSVpvs ("cp1252"); my_foo (char *buffer) { int result; if (!encode_loaded) { ENTER; load_module (PERL_LOADMOD_NOIMPORT, newSVpvs ("Encode"), NULL, + NULL, NULL); LEAVE; encode_loaded = 1; } PUSHMARK (sp); EXTEND (sp, 2); PUSHs (sv_enc); PUSHs (newSVpv (buffer)); PUTBACK; result = call_sv (m_encode, G_SCALAR | G_METHOD); SPAGAIN; if (result) { SV *encoded = POPs; /* Do more */ } PUTBACK; }
And some mortalization might be needed to not leak.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to call Encode::decode from Perl XS
by Anonymous Monk on May 09, 2011 at 14:24 UTC | |
by Tux (Canon) on May 09, 2011 at 15:17 UTC | |
by ikegami (Patriarch) on May 09, 2011 at 15:43 UTC | |
by mje (Curate) on May 09, 2011 at 16:22 UTC | |
by ikegami (Patriarch) on May 09, 2011 at 16:29 UTC | |
|
Re^2: How to call Encode::decode from Perl XS
by mje (Curate) on May 09, 2011 at 14:40 UTC |