how does ByteLoader work?

X

Xavier Noria

Normally you see source filters explained as modules that intercept
source code before it's feed to the tokener. Nevertheless ByteLoader
looks like something that would load somehow the bytecodes directly
into the interpreter, bypassing any parsing. Is that guess right? If it
is, how can the module bypass the parser?

-- fxn
 
T

Tassilo v. Parseval

Also sprach Xavier Noria:
Normally you see source filters explained as modules that intercept
source code before it's feed to the tokener. Nevertheless ByteLoader
looks like something that would load somehow the bytecodes directly
into the interpreter, bypassing any parsing. Is that guess right? If it
is, how can the module bypass the parser?

It uses a source-filter. Source filters are hooked into the optree
building process before the parser and lexer start their work.

Unlike most other source-filters, DynaLoader does not rewrite the
source. Instead, it creates an optree from it and nulls out the source
code so that the parser afterwards gets an empty token stream.

Tassilo
 
X

Xavier Noria

So the question then is: how can ByteLoader (I guess DynaLoader was
ByteLoader in your post) tell perl to use the optree it builds and
ignore the output of the parser, which is empty? Does perl offer in the
C side something like

disable_parser_for_this_source_stream();
load_optree(*my_hand_made_optree);

so to speak?

-- fxn
 
T

Tassilo v. Parseval

Also sprach Xavier Noria:
So the question then is: how can ByteLoader (I guess DynaLoader was
ByteLoader in your post) tell perl to use the optree it builds and
ignore the output of the parser, which is empty? Does perl offer in the
C side something like

disable_parser_for_this_source_stream();
load_optree(*my_hand_made_optree);

so to speak?

The pointer to the main optree is kept in two global variables,
PL_main_root and PL_main_start, I think. ByteLoader's source filter
simply modifies this global optree so there is no separate
'my_hand_made_optree'. It re-assembles the serialized bytecode and
fiddles it into the real optree.

Disabling the parser isn't necessary either. The parser will still be
invoked but it wont see the original source (i.e. the serialized
bytecode). ByteLoader does that by setting PL_rsfp (the file-pointer of
the source-file) to NULL.

Tassilo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,901
Members
47,439
Latest member
elif2sghost

Latest Threads

Top