Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 128 lines (98 sloc) 2.239 kb
1e1a24e Pawel Murias Eval runs basic perl5 code. The Makefile needs review to check if it can
pmurias authored
1 #include <EXTERN.h>
2 #include <perl.h>
3
4 /* So that we can load XS using modules from our perl */
5 EXTERN_C void xs_init (pTHX);
6
7 EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);
8
9 EXTERN_C void
10 xs_init(pTHX)
11 {
12 char *file = __FILE__;
13 dXSUB_SYS;
14
15 /* DynaLoader is a special case */
16 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
17 }
18
19 static PerlInterpreter *my_perl;
20 void p5embed_initialize()
21 {
d468f8f Stefan O'Rear Pass non-null argc,argv to PERL_SYS_INIT
authored
22 int argc = 1;
23 char *argv0[] = { "perl", NULL, 0 };
24 char **argv = argv0;
25 PERL_SYS_INIT(&argc,&argv);
fd1e6d8 Pawel Murias fix segfault when eval perl5 code using a threaded perl
pmurias authored
26 my_perl = perl_alloc();
1e1a24e Pawel Murias Eval runs basic perl5 code. The Makefile needs review to check if it can
pmurias authored
27 perl_construct(my_perl);
28 char *embedding[] = { "", "-e", "0" };
29 perl_parse(my_perl, xs_init, 3, embedding, NULL);
30 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
bf4e20a Pawel Murias remove suspect PERL_SET_CONTEXT
pmurias authored
31 // eval_pv("use lib 'perl5';use Niecza::Interoperability",TRUE);
1e1a24e Pawel Murias Eval runs basic perl5 code. The Makefile needs review to check if it can
pmurias authored
32 }
33
4266b44 Pawel Murias Argumentless method call on perl5 objects.
pmurias authored
34 SV* p5embed_eval(char* code) {
bf4e20a Pawel Murias remove suspect PERL_SET_CONTEXT
pmurias authored
35 eval_pv("1",TRUE);
ee9b534 Pawel Murias Add debugging statements to p5 eval.
pmurias authored
36 SV* ret = eval_pv(code,TRUE);
37 return ret;
1e1a24e Pawel Murias Eval runs basic perl5 code. The Makefile needs review to check if it can
pmurias authored
38 }
39
40 void p5embed_dispose()
41 {
16ef0c8 Pawel Murias cleanup the perl5 interpreter in Perl5Interpreter destructor
pmurias authored
42 perl_destruct(my_perl);
43 perl_free(my_perl);
44 PERL_SYS_TERM();
1e1a24e Pawel Murias Eval runs basic perl5 code. The Makefile needs review to check if it can
pmurias authored
45 }
4266b44 Pawel Murias Argumentless method call on perl5 objects.
pmurias authored
46
47
2e3e4ba Pawel Murias Perl 5 methods can return a value.
pmurias authored
48 SV* p5method_call(char* name,SV** args,int args_count) {
49 dSP;
4266b44 Pawel Murias Argumentless method call on perl5 objects.
pmurias authored
50
51
52 PUSHMARK(SP);
a20956d Pawel Murias Arguments are passed to perl 5 methods.
pmurias authored
53 int i;
2e3e4ba Pawel Murias Perl 5 methods can return a value.
pmurias authored
54 for (i=0;i<args_count;i++) {
a20956d Pawel Murias Arguments are passed to perl 5 methods.
pmurias authored
55 XPUSHs(args[i]);
56 }
4266b44 Pawel Murias Argumentless method call on perl5 objects.
pmurias authored
57 PUTBACK;
58
2e3e4ba Pawel Murias Perl 5 methods can return a value.
pmurias authored
59
60 int count = call_method(name,G_SCALAR);
61 SPAGAIN;
62 if (count != 1) croak("Big trouble\n");
63
64 SV* ret = POPs;
65
66 /* TODO should i do that? */
67 SvREFCNT_inc(ret);
68
69 PUTBACK;
70
71 return ret;
4266b44 Pawel Murias Argumentless method call on perl5 objects.
pmurias authored
72
935bc30 Pawel Murias Perl 5 code refs are invokable.
pmurias authored
73 }
74
bf0cd86 Pawel Murias implement S01-perl-5-integration/context.t
pmurias authored
75 SV* p5embed_subcall(int context,SV** args,int args_count) {
935bc30 Pawel Murias Perl 5 code refs are invokable.
pmurias authored
76 dSP;
77
78
79 PUSHMARK(SP);
80 int i;
81 for (i=1;i<args_count;i++) {
82 XPUSHs(args[i]);
83 }
84 PUTBACK;
85
86
bf0cd86 Pawel Murias implement S01-perl-5-integration/context.t
pmurias authored
87 /* HACK - list context is NYI */
88 if (context == 1 || context == 0) {
89 int count = call_sv(args[0],G_SCALAR);
90 SPAGAIN;
91 if (count != 1) croak("Big trouble\n");
935bc30 Pawel Murias Perl 5 code refs are invokable.
pmurias authored
92
bf0cd86 Pawel Murias implement S01-perl-5-integration/context.t
pmurias authored
93 SV* ret = POPs;
935bc30 Pawel Murias Perl 5 code refs are invokable.
pmurias authored
94
bf0cd86 Pawel Murias implement S01-perl-5-integration/context.t
pmurias authored
95 /* TODO should i do that? */
96 SvREFCNT_inc(ret);
935bc30 Pawel Murias Perl 5 code refs are invokable.
pmurias authored
97
bf0cd86 Pawel Murias implement S01-perl-5-integration/context.t
pmurias authored
98 PUTBACK;
99 return ret;
100 } else if (context == 2) {
101 call_sv(args[0],G_VOID);
102 }
935bc30 Pawel Murias Perl 5 code refs are invokable.
pmurias authored
103
4266b44 Pawel Murias Argumentless method call on perl5 objects.
pmurias authored
104 }
18b719f Pawel Murias Perl5 integers are converted rather than wrapped.
pmurias authored
105
106 int p5embed_SvIOKp(SV* sv) {
107 return SvIOKp(sv);
108 }
109 int p5embed_SvNOKp(SV* sv) {
110 return SvNOKp(sv);
111 }
112 int p5embed_SvPOKp(SV* sv) {
113 return SvPOKp(sv);
114 }
115
116 int p5embed_SvIV(SV* sv) {
117 return SvIV(sv);
118 }
f20f832 Pawel Murias Perl5 NV values are converted.
pmurias authored
119 double p5embed_SvNV(SV* sv) {
120 return SvNV(sv);
121 }
c43c708 Pawel Murias Convert perl 5 string in an extremely naive fashion ignoring utf and nul...
pmurias authored
122 char* p5embed_SvPV_nolen(SV* sv) {
123 return SvPV_nolen(sv);
124 }
e1988ad Pawel Murias Perl 6 string can be converted to Perl 5 strings.
pmurias authored
125 SV* p5embed_newSVpvn(char* str,int len) {
126 return newSVpvn(str,len);
127 }
Something went wrong with that request. Please try again.