Generating a Storable file from C (was: Why Perl needs a VM)
Andy Wardley
abw at wardley.org
Thu Sep 6 09:06:51 BST 2007
Matt S Trout wrote:
> I am indeed, but unless I've missed something those traverse the optree and
> that's at least to some extent specialised to the interpreter. In any case,
> the intermediate layer I'm talking about would go to and from the optree since
> that's how I'm intending to get macros going. (and clkao's already working
> on something that's pretty much the intermediate layer I want for his decompile
> to JS stuff)
Bit of a tangent here, but it's on the same decompiling optrees theme...
I recently found myself wondering about the best way to export a data
structure from a C program into a Perl script. Speed was of the utmost
essence here, so any intermediate format that needed high-level parsing (e.g.
XML, YAML, etc) probably wasn't an option. And besides, my C program was a
parser in itself and it was the AST that I wanted to export. So it would be a
bit backwards to de-compile my parse tree back to a markup language.
I considered generating Perl code that could be evaluated, but it's
undesirable in this case because the environment is insecure. We don't want
to be evaluating Perl code from arbitrary files that could contains all sorts
of malicious nasties.
So I got to wondering if my C program could generate a Storable file that
could be thawed quickly into Perl. Glancing through Storable.xs it looks like
it should be fairly straightforward. And because it's data only, it neatly
side-steps the problem of evaluating executable code from untrusted sources.
Has anyone done anything similar, or can suggest an alternative approach? Is
there a formal description of the Storable format anywhere, or does the Open
Source Jedi Mantra[*] apply?
A
[*] Use the source, Luke.
More information about the london.pm
mailing list