Commit | Line | Data |
b295d113 |
1 | #include "EXTERN.h" |
2 | #include "perl.h" |
3 | #include "XSUB.h" |
4 | |
a6c40364 |
5 | #ifndef WIN32 |
6 | /* this is probably not needed manywhere */ |
7 | # include "byterun.c" |
8 | #endif |
b295d113 |
9 | |
10 | /* defgv must be accessed differently under threaded perl */ |
11 | /* DEFSV et al are in 5.004_56 */ |
12 | #ifndef DEFSV |
13 | #define DEFSV GvSV(defgv) |
14 | #endif |
15 | |
16 | static I32 |
17 | #ifdef PERL_OBJECT |
18 | byteloader_filter(CPerlObj *pPerl, int idx, SV *buf_sv, int maxlen) |
19 | #else |
20 | byteloader_filter(int idx, SV *buf_sv, int maxlen) |
21 | #endif |
22 | { |
a6c40364 |
23 | dTHR; |
b295d113 |
24 | OP *saveroot = PL_main_root; |
25 | OP *savestart = PL_main_start; |
26 | |
27 | #ifdef INDIRECT_BGET_MACROS |
28 | struct bytesream bs; |
29 | |
30 | bs.data = PL_rsfp; |
31 | bs.fgetc = (int(*) _((void*)))fgetc; |
32 | bs.fread = (int(*) _((char*,size_t,size_t,void*)))fread; |
33 | bs.freadpv = freadpv; |
34 | #else |
35 | byterun(PL_rsfp); |
36 | #endif |
37 | |
38 | if (PL_in_eval) { |
39 | OP *o; |
40 | |
41 | PL_eval_start = PL_main_start; |
42 | |
43 | o = newSVOP(OP_CONST, 0, newSViv(1)); |
44 | PL_eval_root = newLISTOP(OP_LINESEQ, 0, PL_main_root, o); |
45 | PL_main_root->op_next = o; |
46 | PL_eval_root = newUNOP(OP_LEAVEEVAL, 0, PL_eval_root); |
47 | o->op_next = PL_eval_root; |
48 | |
49 | PL_main_root = saveroot; |
50 | PL_main_start = savestart; |
51 | } |
52 | |
53 | return 0; |
54 | } |
55 | |
56 | MODULE = ByteLoader PACKAGE = ByteLoader |
57 | |
58 | PROTOTYPES: ENABLE |
59 | |
60 | void |
61 | import(...) |
62 | PPCODE: |
63 | filter_add(byteloader_filter, NULL); |
64 | |
65 | void |
66 | unimport(...) |
67 | PPCODE: |
68 | filter_del(byteloader_filter); |