Mercurial > vim
annotate src/if_perl.xs @ 3761:8187706695fc
Fix version.c, 638 was there twice.
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Thu, 23 Aug 2012 22:28:46 +0200 |
parents | a46a101bfddd |
children | cd36c0fed43e |
rev | line source |
---|---|
7 | 1 /* vi:set ts=8 sts=4 sw=4: |
2 * | |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 */ | |
8 /* | |
9 * if_perl.xs: Main code for Perl interface support. | |
10 * Mostly written by Sven Verdoolaege. | |
11 */ | |
12 | |
13 #define _memory_h /* avoid memset redeclaration */ | |
14 #define IN_PERL_FILE /* don't include if_perl.pro from proto.h */ | |
15 | |
16 #include "vim.h" | |
17 | |
18 | |
19 /* | |
20 * Work around clashes between Perl and Vim namespace. proto.h doesn't | |
21 * include if_perl.pro and perlsfio.pro when IN_PERL_FILE is defined, because | |
22 * we need the CV typedef. proto.h can't be moved to after including | |
23 * if_perl.h, because we get all sorts of name clashes then. | |
24 */ | |
25 #ifndef PROTO | |
26 #ifndef __MINGW32__ | |
27 # include "proto/if_perl.pro" | |
28 # include "proto/if_perlsfio.pro" | |
29 #endif | |
30 #endif | |
31 | |
32 /* Perl compatibility stuff. This should ensure compatibility with older | |
33 * versions of Perl. | |
34 */ | |
35 | |
36 #ifndef PERL_VERSION | |
37 # include <patchlevel.h> | |
38 # define PERL_REVISION 5 | |
39 # define PERL_VERSION PATCHLEVEL | |
40 # define PERL_SUBVERSION SUBVERSION | |
41 #endif | |
42 | |
1387 | 43 /* |
44 * Quoting Jan Dubois of Active State: | |
45 * ActivePerl build 822 still identifies itself as 5.8.8 but already | |
46 * contains many of the changes from the upcoming Perl 5.8.9 release. | |
47 * | |
48 * The changes include addition of two symbols (Perl_sv_2iv_flags, | |
49 * Perl_newXS_flags) not present in earlier releases. | |
50 * | |
1395 | 51 * Jan Dubois suggested the following guarding scheme. |
52 * | |
53 * Active State defined ACTIVEPERL_VERSION as a string in versions before | |
54 * 5.8.8; and so the comparison to 822 below needs to be guarded. | |
1387 | 55 */ |
1395 | 56 #if (PERL_REVISION == 5) && (PERL_VERSION == 8) && (PERL_SUBVERSION >= 8) |
57 # if (ACTIVEPERL_VERSION >= 822) || (PERL_SUBVERSION >= 9) | |
58 # define PERL589_OR_LATER | |
59 # endif | |
1387 | 60 #endif |
61 #if (PERL_REVISION == 5) && (PERL_VERSION >= 9) | |
62 # define PERL589_OR_LATER | |
63 #endif | |
64 | |
2096
6510d834609f
updated for version 7.2.380
Bram Moolenaar <bram@zimbu.org>
parents:
2079
diff
changeset
|
65 #if (PERL_REVISION == 5) && ((PERL_VERSION > 10) || \ |
6510d834609f
updated for version 7.2.380
Bram Moolenaar <bram@zimbu.org>
parents:
2079
diff
changeset
|
66 (PERL_VERSION == 10) && (PERL_SUBVERSION >= 1)) |
6510d834609f
updated for version 7.2.380
Bram Moolenaar <bram@zimbu.org>
parents:
2079
diff
changeset
|
67 # define PERL5101_OR_LATER |
6510d834609f
updated for version 7.2.380
Bram Moolenaar <bram@zimbu.org>
parents:
2079
diff
changeset
|
68 #endif |
6510d834609f
updated for version 7.2.380
Bram Moolenaar <bram@zimbu.org>
parents:
2079
diff
changeset
|
69 |
7 | 70 #ifndef pTHX |
71 # define pTHX void | |
72 # define pTHX_ | |
73 #endif | |
74 | |
75 #ifndef EXTERN_C | |
76 # define EXTERN_C | |
77 #endif | |
78 | |
3728 | 79 #if (PERL_REVISION == 5) && (PERL_VERSION >= 14) && defined(_MSC_VER) |
80 /* Using PL_errgv to get the error message after perl_eval_sv() causes a crash | |
81 * with MSVC and Perl version 5.14. */ | |
82 # define AVOID_PL_ERRGV | |
83 #endif | |
84 | |
7 | 85 /* Compatibility hacks over */ |
86 | |
87 static PerlInterpreter *perl_interp = NULL; | |
88 static void xs_init __ARGS((pTHX)); | |
89 static void VIM_init __ARGS((void)); | |
90 EXTERN_C void boot_DynaLoader __ARGS((pTHX_ CV*)); | |
91 | |
92 /* | |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
93 * For dynamic linked perl. |
7 | 94 */ |
95 #if defined(DYNAMIC_PERL) || defined(PROTO) | |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
96 |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
97 #ifndef DYNAMIC_PERL /* just generating prototypes */ |
2372
a42d19b78c93
Fix building with Perl on Windows with MingW. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2370
diff
changeset
|
98 #ifdef WIN3264 |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
99 typedef int HANDLE; |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
100 #endif |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
101 typedef int XSINIT_t; |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
102 typedef int XSUBADDR_t; |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
103 typedef int perl_key; |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
104 #endif |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
105 |
2372
a42d19b78c93
Fix building with Perl on Windows with MingW. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2370
diff
changeset
|
106 #ifndef WIN3264 |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
107 #include <dlfcn.h> |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
108 #define HANDLE void* |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
109 #define PERL_PROC void* |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
110 #define load_dll(n) dlopen((n), RTLD_LAZY|RTLD_GLOBAL) |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
111 #define symbol_from_dll dlsym |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
112 #define close_dll dlclose |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
113 #else |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
114 #define PERL_PROC FARPROC |
2612 | 115 #define load_dll vimLoadLib |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
116 #define symbol_from_dll GetProcAddress |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
117 #define close_dll FreeLibrary |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
118 #endif |
7 | 119 /* |
120 * Wrapper defines | |
121 */ | |
122 # define perl_alloc dll_perl_alloc | |
123 # define perl_construct dll_perl_construct | |
124 # define perl_parse dll_perl_parse | |
125 # define perl_run dll_perl_run | |
126 # define perl_destruct dll_perl_destruct | |
127 # define perl_free dll_perl_free | |
128 # define Perl_get_context dll_Perl_get_context | |
129 # define Perl_croak dll_Perl_croak | |
2096
6510d834609f
updated for version 7.2.380
Bram Moolenaar <bram@zimbu.org>
parents:
2079
diff
changeset
|
130 # ifdef PERL5101_OR_LATER |
2079
5abd3e3c0085
updated for version 7.2.363
Bram Moolenaar <bram@zimbu.org>
parents:
1990
diff
changeset
|
131 # define Perl_croak_xs_usage dll_Perl_croak_xs_usage |
5abd3e3c0085
updated for version 7.2.363
Bram Moolenaar <bram@zimbu.org>
parents:
1990
diff
changeset
|
132 # endif |
7 | 133 # ifndef PROTO |
134 # define Perl_croak_nocontext dll_Perl_croak_nocontext | |
135 # define Perl_call_argv dll_Perl_call_argv | |
136 # define Perl_call_pv dll_Perl_call_pv | |
137 # define Perl_eval_sv dll_Perl_eval_sv | |
138 # define Perl_get_sv dll_Perl_get_sv | |
139 # define Perl_eval_pv dll_Perl_eval_pv | |
140 # define Perl_call_method dll_Perl_call_method | |
141 # endif | |
142 # define Perl_dowantarray dll_Perl_dowantarray | |
143 # define Perl_free_tmps dll_Perl_free_tmps | |
144 # define Perl_gv_stashpv dll_Perl_gv_stashpv | |
145 # define Perl_markstack_grow dll_Perl_markstack_grow | |
146 # define Perl_mg_find dll_Perl_mg_find | |
147 # define Perl_newXS dll_Perl_newXS | |
148 # define Perl_newSV dll_Perl_newSV | |
149 # define Perl_newSViv dll_Perl_newSViv | |
150 # define Perl_newSVpv dll_Perl_newSVpv | |
151 # define Perl_pop_scope dll_Perl_pop_scope | |
152 # define Perl_push_scope dll_Perl_push_scope | |
153 # define Perl_save_int dll_Perl_save_int | |
154 # define Perl_stack_grow dll_Perl_stack_grow | |
155 # define Perl_set_context dll_Perl_set_context | |
3050 | 156 # if (PERL_REVISION == 5) && (PERL_VERSION >= 14) |
157 # define Perl_sv_2bool_flags dll_Perl_sv_2bool_flags | |
158 # define Perl_xs_apiversion_bootcheck dll_Perl_xs_apiversion_bootcheck | |
159 # else | |
7 | 160 # define Perl_sv_2bool dll_Perl_sv_2bool |
3050 | 161 # endif |
7 | 162 # define Perl_sv_2iv dll_Perl_sv_2iv |
163 # define Perl_sv_2mortal dll_Perl_sv_2mortal | |
164 # if (PERL_REVISION == 5) && (PERL_VERSION >= 8) | |
165 # define Perl_sv_2pv_flags dll_Perl_sv_2pv_flags | |
166 # define Perl_sv_2pv_nolen dll_Perl_sv_2pv_nolen | |
167 # else | |
168 # define Perl_sv_2pv dll_Perl_sv_2pv | |
169 # endif | |
170 # define Perl_sv_bless dll_Perl_sv_bless | |
171 # if (PERL_REVISION == 5) && (PERL_VERSION >= 8) | |
172 # define Perl_sv_catpvn_flags dll_Perl_sv_catpvn_flags | |
173 # else | |
174 # define Perl_sv_catpvn dll_Perl_sv_catpvn | |
175 # endif | |
1387 | 176 #ifdef PERL589_OR_LATER |
177 # define Perl_sv_2iv_flags dll_Perl_sv_2iv_flags | |
178 # define Perl_newXS_flags dll_Perl_newXS_flags | |
179 #endif | |
7 | 180 # define Perl_sv_free dll_Perl_sv_free |
1711 | 181 # if (PERL_REVISION == 5) && (PERL_VERSION >= 10) |
182 # define Perl_sv_free2 dll_Perl_sv_free2 | |
183 # endif | |
7 | 184 # define Perl_sv_isa dll_Perl_sv_isa |
185 # define Perl_sv_magic dll_Perl_sv_magic | |
186 # define Perl_sv_setiv dll_Perl_sv_setiv | |
187 # define Perl_sv_setpv dll_Perl_sv_setpv | |
188 # define Perl_sv_setpvn dll_Perl_sv_setpvn | |
189 # if (PERL_REVISION == 5) && (PERL_VERSION >= 8) | |
190 # define Perl_sv_setsv_flags dll_Perl_sv_setsv_flags | |
191 # else | |
192 # define Perl_sv_setsv dll_Perl_sv_setsv | |
193 # endif | |
194 # define Perl_sv_upgrade dll_Perl_sv_upgrade | |
195 # define Perl_Tstack_sp_ptr dll_Perl_Tstack_sp_ptr | |
196 # define Perl_Top_ptr dll_Perl_Top_ptr | |
197 # define Perl_Tstack_base_ptr dll_Perl_Tstack_base_ptr | |
198 # define Perl_Tstack_max_ptr dll_Perl_Tstack_max_ptr | |
199 # define Perl_Ttmps_ix_ptr dll_Perl_Ttmps_ix_ptr | |
200 # define Perl_Ttmps_floor_ptr dll_Perl_Ttmps_floor_ptr | |
201 # define Perl_Tmarkstack_ptr_ptr dll_Perl_Tmarkstack_ptr_ptr | |
202 # define Perl_Tmarkstack_max_ptr dll_Perl_Tmarkstack_max_ptr | |
203 # define Perl_TSv_ptr dll_Perl_TSv_ptr | |
204 # define Perl_TXpv_ptr dll_Perl_TXpv_ptr | |
205 # define Perl_Tna_ptr dll_Perl_Tna_ptr | |
206 # define Perl_Idefgv_ptr dll_Perl_Idefgv_ptr | |
207 # define Perl_Ierrgv_ptr dll_Perl_Ierrgv_ptr | |
208 # define Perl_Isv_yes_ptr dll_Perl_Isv_yes_ptr | |
209 # define boot_DynaLoader dll_boot_DynaLoader | |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
210 # define Perl_Gthr_key_ptr dll_Perl_Gthr_key_ptr |
7 | 211 |
1765 | 212 # define Perl_sys_init dll_Perl_sys_init |
1668 | 213 # define Perl_sys_term dll_Perl_sys_term |
214 # define Perl_ISv_ptr dll_Perl_ISv_ptr | |
215 # define Perl_Istack_max_ptr dll_Perl_Istack_max_ptr | |
216 # define Perl_Istack_base_ptr dll_Perl_Istack_base_ptr | |
217 # define Perl_Itmps_ix_ptr dll_Perl_Itmps_ix_ptr | |
218 # define Perl_Itmps_floor_ptr dll_Perl_Itmps_floor_ptr | |
219 # define Perl_IXpv_ptr dll_Perl_IXpv_ptr | |
220 # define Perl_Ina_ptr dll_Perl_Ina_ptr | |
221 # define Perl_Imarkstack_ptr_ptr dll_Perl_Imarkstack_ptr_ptr | |
222 # define Perl_Imarkstack_max_ptr dll_Perl_Imarkstack_max_ptr | |
223 # define Perl_Istack_sp_ptr dll_Perl_Istack_sp_ptr | |
224 # define Perl_Iop_ptr dll_Perl_Iop_ptr | |
225 # define Perl_call_list dll_Perl_call_list | |
226 # define Perl_Iscopestack_ix_ptr dll_Perl_Iscopestack_ix_ptr | |
227 # define Perl_Iunitcheckav_ptr dll_Perl_Iunitcheckav_ptr | |
228 | |
7 | 229 /* |
230 * Declare HANDLE for perl.dll and function pointers. | |
231 */ | |
232 static HANDLE hPerlLib = NULL; | |
233 | |
234 static PerlInterpreter* (*perl_alloc)(); | |
235 static void (*perl_construct)(PerlInterpreter*); | |
236 static void (*perl_destruct)(PerlInterpreter*); | |
237 static void (*perl_free)(PerlInterpreter*); | |
238 static int (*perl_run)(PerlInterpreter*); | |
239 static int (*perl_parse)(PerlInterpreter*, XSINIT_t, int, char**, char**); | |
240 static void* (*Perl_get_context)(void); | |
933 | 241 static void (*Perl_croak)(pTHX_ const char*, ...); |
2096
6510d834609f
updated for version 7.2.380
Bram Moolenaar <bram@zimbu.org>
parents:
2079
diff
changeset
|
242 #ifdef PERL5101_OR_LATER |
2079
5abd3e3c0085
updated for version 7.2.363
Bram Moolenaar <bram@zimbu.org>
parents:
1990
diff
changeset
|
243 static void (*Perl_croak_xs_usage)(pTHX_ const CV *const, const char *const params); |
5abd3e3c0085
updated for version 7.2.363
Bram Moolenaar <bram@zimbu.org>
parents:
1990
diff
changeset
|
244 #endif |
933 | 245 static void (*Perl_croak_nocontext)(const char*, ...); |
7 | 246 static I32 (*Perl_dowantarray)(pTHX); |
247 static void (*Perl_free_tmps)(pTHX); | |
248 static HV* (*Perl_gv_stashpv)(pTHX_ const char*, I32); | |
249 static void (*Perl_markstack_grow)(pTHX); | |
250 static MAGIC* (*Perl_mg_find)(pTHX_ SV*, int); | |
251 static CV* (*Perl_newXS)(pTHX_ char*, XSUBADDR_t, char*); | |
252 static SV* (*Perl_newSV)(pTHX_ STRLEN); | |
253 static SV* (*Perl_newSViv)(pTHX_ IV); | |
254 static SV* (*Perl_newSVpv)(pTHX_ const char*, STRLEN); | |
255 static I32 (*Perl_call_argv)(pTHX_ const char*, I32, char**); | |
256 static I32 (*Perl_call_pv)(pTHX_ const char*, I32); | |
257 static I32 (*Perl_eval_sv)(pTHX_ SV*, I32); | |
258 static SV* (*Perl_get_sv)(pTHX_ const char*, I32); | |
259 static SV* (*Perl_eval_pv)(pTHX_ const char*, I32); | |
260 static SV* (*Perl_call_method)(pTHX_ const char*, I32); | |
261 static void (*Perl_pop_scope)(pTHX); | |
262 static void (*Perl_push_scope)(pTHX); | |
263 static void (*Perl_save_int)(pTHX_ int*); | |
264 static SV** (*Perl_stack_grow)(pTHX_ SV**, SV**p, int); | |
265 static SV** (*Perl_set_context)(void*); | |
3050 | 266 #if (PERL_REVISION == 5) && (PERL_VERSION >= 14) |
267 static bool (*Perl_sv_2bool_flags)(pTHX_ SV*, I32); | |
268 static void (*Perl_xs_apiversion_bootcheck)(pTHX_ SV *module, const char *api_p, STRLEN api_len); | |
269 #else | |
7 | 270 static bool (*Perl_sv_2bool)(pTHX_ SV*); |
3050 | 271 #endif |
7 | 272 static IV (*Perl_sv_2iv)(pTHX_ SV*); |
273 static SV* (*Perl_sv_2mortal)(pTHX_ SV*); | |
274 #if (PERL_REVISION == 5) && (PERL_VERSION >= 8) | |
275 static char* (*Perl_sv_2pv_flags)(pTHX_ SV*, STRLEN*, I32); | |
276 static char* (*Perl_sv_2pv_nolen)(pTHX_ SV*); | |
277 #else | |
278 static char* (*Perl_sv_2pv)(pTHX_ SV*, STRLEN*); | |
279 #endif | |
280 static SV* (*Perl_sv_bless)(pTHX_ SV*, HV*); | |
281 #if (PERL_REVISION == 5) && (PERL_VERSION >= 8) | |
282 static void (*Perl_sv_catpvn_flags)(pTHX_ SV* , const char*, STRLEN, I32); | |
283 #else | |
284 static void (*Perl_sv_catpvn)(pTHX_ SV*, const char*, STRLEN); | |
285 #endif | |
1387 | 286 #ifdef PERL589_OR_LATER |
287 static IV (*Perl_sv_2iv_flags)(pTHX_ SV* sv, I32 flags); | |
288 static CV * (*Perl_newXS_flags)(pTHX_ const char *name, XSUBADDR_t subaddr, const char *const filename, const char *const proto, U32 flags); | |
289 #endif | |
7 | 290 static void (*Perl_sv_free)(pTHX_ SV*); |
291 static int (*Perl_sv_isa)(pTHX_ SV*, const char*); | |
292 static void (*Perl_sv_magic)(pTHX_ SV*, SV*, int, const char*, I32); | |
293 static void (*Perl_sv_setiv)(pTHX_ SV*, IV); | |
294 static void (*Perl_sv_setpv)(pTHX_ SV*, const char*); | |
295 static void (*Perl_sv_setpvn)(pTHX_ SV*, const char*, STRLEN); | |
296 #if (PERL_REVISION == 5) && (PERL_VERSION >= 8) | |
297 static void (*Perl_sv_setsv_flags)(pTHX_ SV*, SV*, I32); | |
298 #else | |
299 static void (*Perl_sv_setsv)(pTHX_ SV*, SV*); | |
300 #endif | |
301 static bool (*Perl_sv_upgrade)(pTHX_ SV*, U32); | |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
302 #if (PERL_REVISION == 5) && (PERL_VERSION < 10) |
7 | 303 static SV*** (*Perl_Tstack_sp_ptr)(register PerlInterpreter*); |
304 static OP** (*Perl_Top_ptr)(register PerlInterpreter*); | |
305 static SV*** (*Perl_Tstack_base_ptr)(register PerlInterpreter*); | |
306 static SV*** (*Perl_Tstack_max_ptr)(register PerlInterpreter*); | |
307 static I32* (*Perl_Ttmps_ix_ptr)(register PerlInterpreter*); | |
308 static I32* (*Perl_Ttmps_floor_ptr)(register PerlInterpreter*); | |
309 static I32** (*Perl_Tmarkstack_ptr_ptr)(register PerlInterpreter*); | |
310 static I32** (*Perl_Tmarkstack_max_ptr)(register PerlInterpreter*); | |
311 static SV** (*Perl_TSv_ptr)(register PerlInterpreter*); | |
312 static XPV** (*Perl_TXpv_ptr)(register PerlInterpreter*); | |
313 static STRLEN* (*Perl_Tna_ptr)(register PerlInterpreter*); | |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
314 #else |
1711 | 315 static void (*Perl_sv_free2)(pTHX_ SV*); |
1765 | 316 static void (*Perl_sys_init)(int* argc, char*** argv); |
1668 | 317 static void (*Perl_sys_term)(void); |
318 static SV** (*Perl_ISv_ptr)(register PerlInterpreter*); | |
319 static SV*** (*Perl_Istack_max_ptr)(register PerlInterpreter*); | |
320 static SV*** (*Perl_Istack_base_ptr)(register PerlInterpreter*); | |
321 static XPV** (*Perl_IXpv_ptr)(register PerlInterpreter*); | |
322 static I32* (*Perl_Itmps_ix_ptr)(register PerlInterpreter*); | |
323 static I32* (*Perl_Itmps_floor_ptr)(register PerlInterpreter*); | |
324 static STRLEN* (*Perl_Ina_ptr)(register PerlInterpreter*); | |
325 static I32** (*Perl_Imarkstack_ptr_ptr)(register PerlInterpreter*); | |
326 static I32** (*Perl_Imarkstack_max_ptr)(register PerlInterpreter*); | |
327 static SV*** (*Perl_Istack_sp_ptr)(register PerlInterpreter*); | |
328 static OP** (*Perl_Iop_ptr)(register PerlInterpreter*); | |
329 static void (*Perl_call_list)(pTHX_ I32, AV*); | |
330 static I32* (*Perl_Iscopestack_ix_ptr)(register PerlInterpreter*); | |
331 static AV** (*Perl_Iunitcheckav_ptr)(register PerlInterpreter*); | |
332 #endif | |
7 | 333 |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
334 static GV** (*Perl_Idefgv_ptr)(register PerlInterpreter*); |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
335 static GV** (*Perl_Ierrgv_ptr)(register PerlInterpreter*); |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
336 static SV* (*Perl_Isv_yes_ptr)(register PerlInterpreter*); |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
337 static void (*boot_DynaLoader)_((pTHX_ CV*)); |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
338 static perl_key* (*Perl_Gthr_key_ptr)_((pTHX)); |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
339 |
7 | 340 /* |
341 * Table of name to function pointer of perl. | |
342 */ | |
343 static struct { | |
344 char* name; | |
345 PERL_PROC* ptr; | |
346 } perl_funcname_table[] = { | |
347 {"perl_alloc", (PERL_PROC*)&perl_alloc}, | |
348 {"perl_construct", (PERL_PROC*)&perl_construct}, | |
349 {"perl_destruct", (PERL_PROC*)&perl_destruct}, | |
350 {"perl_free", (PERL_PROC*)&perl_free}, | |
351 {"perl_run", (PERL_PROC*)&perl_run}, | |
352 {"perl_parse", (PERL_PROC*)&perl_parse}, | |
353 {"Perl_get_context", (PERL_PROC*)&Perl_get_context}, | |
354 {"Perl_croak", (PERL_PROC*)&Perl_croak}, | |
2096
6510d834609f
updated for version 7.2.380
Bram Moolenaar <bram@zimbu.org>
parents:
2079
diff
changeset
|
355 #ifdef PERL5101_OR_LATER |
2079
5abd3e3c0085
updated for version 7.2.363
Bram Moolenaar <bram@zimbu.org>
parents:
1990
diff
changeset
|
356 {"Perl_croak_xs_usage", (PERL_PROC*)&Perl_croak_xs_usage}, |
5abd3e3c0085
updated for version 7.2.363
Bram Moolenaar <bram@zimbu.org>
parents:
1990
diff
changeset
|
357 #endif |
7 | 358 {"Perl_croak_nocontext", (PERL_PROC*)&Perl_croak_nocontext}, |
359 {"Perl_dowantarray", (PERL_PROC*)&Perl_dowantarray}, | |
360 {"Perl_free_tmps", (PERL_PROC*)&Perl_free_tmps}, | |
361 {"Perl_gv_stashpv", (PERL_PROC*)&Perl_gv_stashpv}, | |
362 {"Perl_markstack_grow", (PERL_PROC*)&Perl_markstack_grow}, | |
363 {"Perl_mg_find", (PERL_PROC*)&Perl_mg_find}, | |
364 {"Perl_newXS", (PERL_PROC*)&Perl_newXS}, | |
365 {"Perl_newSV", (PERL_PROC*)&Perl_newSV}, | |
366 {"Perl_newSViv", (PERL_PROC*)&Perl_newSViv}, | |
367 {"Perl_newSVpv", (PERL_PROC*)&Perl_newSVpv}, | |
368 {"Perl_call_argv", (PERL_PROC*)&Perl_call_argv}, | |
369 {"Perl_call_pv", (PERL_PROC*)&Perl_call_pv}, | |
370 {"Perl_eval_sv", (PERL_PROC*)&Perl_eval_sv}, | |
371 {"Perl_get_sv", (PERL_PROC*)&Perl_get_sv}, | |
372 {"Perl_eval_pv", (PERL_PROC*)&Perl_eval_pv}, | |
373 {"Perl_call_method", (PERL_PROC*)&Perl_call_method}, | |
374 {"Perl_pop_scope", (PERL_PROC*)&Perl_pop_scope}, | |
375 {"Perl_push_scope", (PERL_PROC*)&Perl_push_scope}, | |
376 {"Perl_save_int", (PERL_PROC*)&Perl_save_int}, | |
377 {"Perl_stack_grow", (PERL_PROC*)&Perl_stack_grow}, | |
378 {"Perl_set_context", (PERL_PROC*)&Perl_set_context}, | |
3050 | 379 #if (PERL_REVISION == 5) && (PERL_VERSION >= 14) |
380 {"Perl_sv_2bool_flags", (PERL_PROC*)&Perl_sv_2bool_flags}, | |
381 {"Perl_xs_apiversion_bootcheck",(PERL_PROC*)&Perl_xs_apiversion_bootcheck}, | |
382 #else | |
7 | 383 {"Perl_sv_2bool", (PERL_PROC*)&Perl_sv_2bool}, |
3050 | 384 #endif |
7 | 385 {"Perl_sv_2iv", (PERL_PROC*)&Perl_sv_2iv}, |
386 {"Perl_sv_2mortal", (PERL_PROC*)&Perl_sv_2mortal}, | |
387 #if (PERL_REVISION == 5) && (PERL_VERSION >= 8) | |
388 {"Perl_sv_2pv_flags", (PERL_PROC*)&Perl_sv_2pv_flags}, | |
389 {"Perl_sv_2pv_nolen", (PERL_PROC*)&Perl_sv_2pv_nolen}, | |
390 #else | |
391 {"Perl_sv_2pv", (PERL_PROC*)&Perl_sv_2pv}, | |
392 #endif | |
1387 | 393 #ifdef PERL589_OR_LATER |
394 {"Perl_sv_2iv_flags", (PERL_PROC*)&Perl_sv_2iv_flags}, | |
395 {"Perl_newXS_flags", (PERL_PROC*)&Perl_newXS_flags}, | |
396 #endif | |
7 | 397 {"Perl_sv_bless", (PERL_PROC*)&Perl_sv_bless}, |
398 #if (PERL_REVISION == 5) && (PERL_VERSION >= 8) | |
399 {"Perl_sv_catpvn_flags", (PERL_PROC*)&Perl_sv_catpvn_flags}, | |
400 #else | |
401 {"Perl_sv_catpvn", (PERL_PROC*)&Perl_sv_catpvn}, | |
402 #endif | |
403 {"Perl_sv_free", (PERL_PROC*)&Perl_sv_free}, | |
404 {"Perl_sv_isa", (PERL_PROC*)&Perl_sv_isa}, | |
405 {"Perl_sv_magic", (PERL_PROC*)&Perl_sv_magic}, | |
406 {"Perl_sv_setiv", (PERL_PROC*)&Perl_sv_setiv}, | |
407 {"Perl_sv_setpv", (PERL_PROC*)&Perl_sv_setpv}, | |
408 {"Perl_sv_setpvn", (PERL_PROC*)&Perl_sv_setpvn}, | |
409 #if (PERL_REVISION == 5) && (PERL_VERSION >= 8) | |
410 {"Perl_sv_setsv_flags", (PERL_PROC*)&Perl_sv_setsv_flags}, | |
411 #else | |
412 {"Perl_sv_setsv", (PERL_PROC*)&Perl_sv_setsv}, | |
413 #endif | |
414 {"Perl_sv_upgrade", (PERL_PROC*)&Perl_sv_upgrade}, | |
1668 | 415 #if (PERL_REVISION == 5) && (PERL_VERSION < 10) |
7 | 416 {"Perl_Tstack_sp_ptr", (PERL_PROC*)&Perl_Tstack_sp_ptr}, |
417 {"Perl_Top_ptr", (PERL_PROC*)&Perl_Top_ptr}, | |
418 {"Perl_Tstack_base_ptr", (PERL_PROC*)&Perl_Tstack_base_ptr}, | |
419 {"Perl_Tstack_max_ptr", (PERL_PROC*)&Perl_Tstack_max_ptr}, | |
420 {"Perl_Ttmps_ix_ptr", (PERL_PROC*)&Perl_Ttmps_ix_ptr}, | |
421 {"Perl_Ttmps_floor_ptr", (PERL_PROC*)&Perl_Ttmps_floor_ptr}, | |
422 {"Perl_Tmarkstack_ptr_ptr", (PERL_PROC*)&Perl_Tmarkstack_ptr_ptr}, | |
423 {"Perl_Tmarkstack_max_ptr", (PERL_PROC*)&Perl_Tmarkstack_max_ptr}, | |
424 {"Perl_TSv_ptr", (PERL_PROC*)&Perl_TSv_ptr}, | |
425 {"Perl_TXpv_ptr", (PERL_PROC*)&Perl_TXpv_ptr}, | |
426 {"Perl_Tna_ptr", (PERL_PROC*)&Perl_Tna_ptr}, | |
1668 | 427 #else |
1711 | 428 {"Perl_sv_free2", (PERL_PROC*)&Perl_sv_free2}, |
1765 | 429 {"Perl_sys_init", (PERL_PROC*)&Perl_sys_init}, |
1668 | 430 {"Perl_sys_term", (PERL_PROC*)&Perl_sys_term}, |
3050 | 431 {"Perl_call_list", (PERL_PROC*)&Perl_call_list}, |
432 # if (PERL_REVISION == 5) && (PERL_VERSION >= 14) | |
433 # else | |
1668 | 434 {"Perl_ISv_ptr", (PERL_PROC*)&Perl_ISv_ptr}, |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
435 {"Perl_Istack_max_ptr", (PERL_PROC*)&Perl_Istack_max_ptr}, |
1668 | 436 {"Perl_Istack_base_ptr", (PERL_PROC*)&Perl_Istack_base_ptr}, |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
437 {"Perl_IXpv_ptr", (PERL_PROC*)&Perl_IXpv_ptr}, |
1668 | 438 {"Perl_Itmps_ix_ptr", (PERL_PROC*)&Perl_Itmps_ix_ptr}, |
439 {"Perl_Itmps_floor_ptr", (PERL_PROC*)&Perl_Itmps_floor_ptr}, | |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
440 {"Perl_Ina_ptr", (PERL_PROC*)&Perl_Ina_ptr}, |
1668 | 441 {"Perl_Imarkstack_ptr_ptr", (PERL_PROC*)&Perl_Imarkstack_ptr_ptr}, |
442 {"Perl_Imarkstack_max_ptr", (PERL_PROC*)&Perl_Imarkstack_max_ptr}, | |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
443 {"Perl_Istack_sp_ptr", (PERL_PROC*)&Perl_Istack_sp_ptr}, |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
444 {"Perl_Iop_ptr", (PERL_PROC*)&Perl_Iop_ptr}, |
1668 | 445 {"Perl_Iscopestack_ix_ptr", (PERL_PROC*)&Perl_Iscopestack_ix_ptr}, |
446 {"Perl_Iunitcheckav_ptr", (PERL_PROC*)&Perl_Iunitcheckav_ptr}, | |
3050 | 447 # endif |
1668 | 448 #endif |
3050 | 449 #if (PERL_REVISION == 5) && (PERL_VERSION >= 14) |
450 #else | |
7 | 451 {"Perl_Idefgv_ptr", (PERL_PROC*)&Perl_Idefgv_ptr}, |
452 {"Perl_Ierrgv_ptr", (PERL_PROC*)&Perl_Ierrgv_ptr}, | |
453 {"Perl_Isv_yes_ptr", (PERL_PROC*)&Perl_Isv_yes_ptr}, | |
3050 | 454 {"Perl_Gthr_key_ptr", (PERL_PROC*)&Perl_Gthr_key_ptr}, |
455 #endif | |
7 | 456 {"boot_DynaLoader", (PERL_PROC*)&boot_DynaLoader}, |
457 {"", NULL}, | |
458 }; | |
459 | |
460 /* | |
461 * Make all runtime-links of perl. | |
462 * | |
463 * 1. Get module handle using LoadLibraryEx. | |
464 * 2. Get pointer to perl function by GetProcAddress. | |
465 * 3. Repeat 2, until get all functions will be used. | |
466 * | |
467 * Parameter 'libname' provides name of DLL. | |
468 * Return OK or FAIL. | |
469 */ | |
470 static int | |
471 perl_runtime_link_init(char *libname, int verbose) | |
472 { | |
473 int i; | |
474 | |
475 if (hPerlLib != NULL) | |
476 return OK; | |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
477 if ((hPerlLib = load_dll(libname)) == NULL) |
7 | 478 { |
479 if (verbose) | |
480 EMSG2(_("E370: Could not load library %s"), libname); | |
481 return FAIL; | |
482 } | |
483 for (i = 0; perl_funcname_table[i].ptr; ++i) | |
484 { | |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
485 if (!(*perl_funcname_table[i].ptr = symbol_from_dll(hPerlLib, |
7 | 486 perl_funcname_table[i].name))) |
487 { | |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
488 close_dll(hPerlLib); |
7 | 489 hPerlLib = NULL; |
490 if (verbose) | |
491 EMSG2(_(e_loadfunc), perl_funcname_table[i].name); | |
492 return FAIL; | |
493 } | |
494 } | |
495 return OK; | |
496 } | |
497 | |
498 /* | |
499 * If runtime-link-perl(DLL) was loaded successfully, return TRUE. | |
500 * There were no DLL loaded, return FALSE. | |
501 */ | |
502 int | |
503 perl_enabled(verbose) | |
504 int verbose; | |
505 { | |
506 return perl_runtime_link_init(DYNAMIC_PERL_DLL, verbose) == OK; | |
507 } | |
508 #endif /* DYNAMIC_PERL */ | |
509 | |
510 /* | |
511 * perl_init(): initialize perl interpreter | |
512 * We have to call perl_parse to initialize some structures, | |
513 * there's nothing to actually parse. | |
514 */ | |
515 static void | |
516 perl_init() | |
517 { | |
1668 | 518 char *bootargs[] = { "VI", NULL }; |
519 int argc = 3; | |
520 static char *argv[] = { "", "-e", "" }; | |
7 | 521 |
1668 | 522 #if (PERL_REVISION == 5) && (PERL_VERSION >= 10) |
1765 | 523 Perl_sys_init(&argc, (char***)&argv); |
1668 | 524 #endif |
7 | 525 perl_interp = perl_alloc(); |
526 perl_construct(perl_interp); | |
1668 | 527 perl_parse(perl_interp, xs_init, argc, argv, 0); |
7 | 528 perl_call_argv("VIM::bootstrap", (long)G_DISCARD, bootargs); |
529 VIM_init(); | |
530 #ifdef USE_SFIO | |
531 sfdisc(PerlIO_stdout(), sfdcnewvim()); | |
532 sfdisc(PerlIO_stderr(), sfdcnewvim()); | |
533 sfsetbuf(PerlIO_stdout(), NULL, 0); | |
534 sfsetbuf(PerlIO_stderr(), NULL, 0); | |
535 #endif | |
536 } | |
537 | |
538 /* | |
539 * perl_end(): clean up after ourselves | |
540 */ | |
541 void | |
542 perl_end() | |
543 { | |
544 if (perl_interp) | |
545 { | |
546 perl_run(perl_interp); | |
547 perl_destruct(perl_interp); | |
548 perl_free(perl_interp); | |
549 perl_interp = NULL; | |
1668 | 550 #if (PERL_REVISION == 5) && (PERL_VERSION >= 10) |
551 Perl_sys_term(); | |
552 #endif | |
7 | 553 } |
554 #ifdef DYNAMIC_PERL | |
555 if (hPerlLib) | |
556 { | |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
557 close_dll(hPerlLib); |
7 | 558 hPerlLib = NULL; |
559 } | |
560 #endif | |
561 } | |
562 | |
563 /* | |
564 * msg_split(): send a message to the message handling routines | |
565 * split at '\n' first though. | |
566 */ | |
567 void | |
568 msg_split(s, attr) | |
569 char_u *s; | |
570 int attr; /* highlighting attributes */ | |
571 { | |
572 char *next; | |
573 char *token = (char *)s; | |
574 | |
1423 | 575 while ((next = strchr(token, '\n')) && !got_int) |
7 | 576 { |
577 *next++ = '\0'; /* replace \n with \0 */ | |
578 msg_attr((char_u *)token, attr); | |
579 token = next; | |
580 } | |
1423 | 581 if (*token && !got_int) |
7 | 582 msg_attr((char_u *)token, attr); |
583 } | |
584 | |
585 #ifndef FEAT_EVAL | |
586 /* | |
587 * This stub is needed because an "#ifdef FEAT_EVAL" around Eval() doesn't | |
588 * work properly. | |
589 */ | |
590 char_u * | |
714 | 591 eval_to_string(arg, nextcmd, dolist) |
7 | 592 char_u *arg; |
593 char_u **nextcmd; | |
714 | 594 int dolist; |
7 | 595 { |
596 return NULL; | |
597 } | |
598 #endif | |
599 | |
600 /* | |
601 * Create a new reference to an SV pointing to the SCR structure | |
502 | 602 * The b_perl_private/w_perl_private part of the SCR structure points to the |
603 * SV, so there can only be one such SV for a particular SCR structure. When | |
604 * the last reference has gone (DESTROY is called), | |
605 * b_perl_private/w_perl_private is reset; When the screen goes away before | |
7 | 606 * all references are gone, the value of the SV is reset; |
607 * any subsequent use of any of those reference will produce | |
608 * a warning. (see typemap) | |
609 */ | |
502 | 610 |
611 static SV * | |
612 newWINrv(rv, ptr) | |
613 SV *rv; | |
614 win_T *ptr; | |
615 { | |
616 sv_upgrade(rv, SVt_RV); | |
617 if (ptr->w_perl_private == NULL) | |
618 { | |
619 ptr->w_perl_private = newSV(0); | |
3344 | 620 sv_setiv(ptr->w_perl_private, PTR2IV(ptr)); |
502 | 621 } |
622 else | |
623 SvREFCNT_inc(ptr->w_perl_private); | |
624 SvRV(rv) = ptr->w_perl_private; | |
625 SvROK_on(rv); | |
626 return sv_bless(rv, gv_stashpv("VIWIN", TRUE)); | |
7 | 627 } |
628 | |
502 | 629 static SV * |
630 newBUFrv(rv, ptr) | |
631 SV *rv; | |
632 buf_T *ptr; | |
633 { | |
634 sv_upgrade(rv, SVt_RV); | |
635 if (ptr->b_perl_private == NULL) | |
636 { | |
637 ptr->b_perl_private = newSV(0); | |
3344 | 638 sv_setiv(ptr->b_perl_private, PTR2IV(ptr)); |
502 | 639 } |
640 else | |
641 SvREFCNT_inc(ptr->b_perl_private); | |
642 SvRV(rv) = ptr->b_perl_private; | |
643 SvROK_on(rv); | |
644 return sv_bless(rv, gv_stashpv("VIBUF", TRUE)); | |
645 } | |
7 | 646 |
647 /* | |
648 * perl_win_free | |
649 * Remove all refences to the window to be destroyed | |
650 */ | |
651 void | |
652 perl_win_free(wp) | |
653 win_T *wp; | |
654 { | |
502 | 655 if (wp->w_perl_private) |
656 sv_setiv((SV *)wp->w_perl_private, 0); | |
7 | 657 return; |
658 } | |
659 | |
660 void | |
661 perl_buf_free(bp) | |
662 buf_T *bp; | |
663 { | |
502 | 664 if (bp->b_perl_private) |
665 sv_setiv((SV *)bp->b_perl_private, 0); | |
7 | 666 return; |
667 } | |
668 | |
669 #ifndef PROTO | |
670 # if (PERL_REVISION == 5) && (PERL_VERSION >= 8) | |
671 I32 cur_val(pTHX_ IV iv, SV *sv); | |
672 # else | |
673 I32 cur_val(IV iv, SV *sv); | |
674 #endif | |
675 | |
676 /* | |
677 * Handler for the magic variables $main::curwin and $main::curbuf. | |
678 * The handler is put into the magic vtbl for these variables. | |
679 * (This is effectively a C-level equivalent of a tied variable). | |
680 * There is no "set" function as the variables are read-only. | |
681 */ | |
682 # if (PERL_REVISION == 5) && (PERL_VERSION >= 8) | |
683 I32 cur_val(pTHX_ IV iv, SV *sv) | |
684 # else | |
685 I32 cur_val(IV iv, SV *sv) | |
686 # endif | |
687 { | |
688 SV *rv; | |
689 if (iv == 0) | |
690 rv = newWINrv(newSV(0), curwin); | |
691 else | |
692 rv = newBUFrv(newSV(0), curbuf); | |
693 sv_setsv(sv, rv); | |
694 return 0; | |
695 } | |
696 #endif /* !PROTO */ | |
697 | |
698 struct ufuncs cw_funcs = { cur_val, 0, 0 }; | |
699 struct ufuncs cb_funcs = { cur_val, 0, 1 }; | |
700 | |
701 /* | |
702 * VIM_init(): Vim-specific initialisation. | |
703 * Make the magical main::curwin and main::curbuf variables | |
704 */ | |
705 static void | |
706 VIM_init() | |
707 { | |
708 static char cw[] = "main::curwin"; | |
709 static char cb[] = "main::curbuf"; | |
710 SV *sv; | |
711 | |
712 sv = perl_get_sv(cw, TRUE); | |
713 sv_magic(sv, NULL, 'U', (char *)&cw_funcs, sizeof(cw_funcs)); | |
714 SvREADONLY_on(sv); | |
715 | |
716 sv = perl_get_sv(cb, TRUE); | |
717 sv_magic(sv, NULL, 'U', (char *)&cb_funcs, sizeof(cb_funcs)); | |
718 SvREADONLY_on(sv); | |
719 | |
720 /* | |
721 * Setup the Safe compartment. | |
722 * It shouldn't be a fatal error if the Safe module is missing. | |
723 * XXX: Only shares the 'Msg' routine (which has to be called | |
724 * like 'Msg(...)'). | |
725 */ | |
726 (void)perl_eval_pv( "if ( eval( 'require Safe' ) ) { $VIM::safe = Safe->new(); $VIM::safe->share_from( 'VIM', ['Msg'] ); }", G_DISCARD | G_VOID ); | |
727 | |
728 } | |
729 | |
730 #ifdef DYNAMIC_PERL | |
731 static char *e_noperl = N_("Sorry, this command is disabled: the Perl library could not be loaded."); | |
732 #endif | |
733 | |
734 /* | |
735 * ":perl" | |
736 */ | |
737 void | |
738 ex_perl(eap) | |
739 exarg_T *eap; | |
740 { | |
741 char *err; | |
742 char *script; | |
743 STRLEN length; | |
744 SV *sv; | |
2255 | 745 #ifdef HAVE_SANDBOX |
7 | 746 SV *safe; |
2255 | 747 #endif |
7 | 748 |
749 script = (char *)script_get(eap, eap->arg); | |
750 if (eap->skip) | |
751 { | |
752 vim_free(script); | |
753 return; | |
754 } | |
755 | |
756 if (perl_interp == NULL) | |
757 { | |
758 #ifdef DYNAMIC_PERL | |
759 if (!perl_enabled(TRUE)) | |
760 { | |
761 EMSG(_(e_noperl)); | |
762 vim_free(script); | |
763 return; | |
764 } | |
765 #endif | |
766 perl_init(); | |
767 } | |
768 | |
769 { | |
770 dSP; | |
771 ENTER; | |
772 SAVETMPS; | |
773 | |
774 if (script == NULL) | |
775 sv = newSVpv((char *)eap->arg, 0); | |
776 else | |
777 { | |
778 sv = newSVpv(script, 0); | |
779 vim_free(script); | |
780 } | |
781 | |
782 #ifdef HAVE_SANDBOX | |
783 if (sandbox) | |
784 { | |
2982 | 785 safe = perl_get_sv("VIM::safe", FALSE); |
1934 | 786 # ifndef MAKE_TEST /* avoid a warning for unreachable code */ |
1990 | 787 if (safe == NULL || !SvTRUE(safe)) |
7 | 788 EMSG(_("E299: Perl evaluation forbidden in sandbox without the Safe module")); |
789 else | |
1934 | 790 # endif |
7 | 791 { |
792 PUSHMARK(SP); | |
793 XPUSHs(safe); | |
794 XPUSHs(sv); | |
795 PUTBACK; | |
796 perl_call_method("reval", G_DISCARD); | |
797 } | |
798 } | |
799 else | |
800 #endif | |
801 perl_eval_sv(sv, G_DISCARD | G_NOARGS); | |
802 | |
803 SvREFCNT_dec(sv); | |
804 | |
3728 | 805 #ifdef AVOID_PL_ERRGV |
806 err = SvPV(perl_get_sv("@", GV_ADD), length); | |
807 #else | |
7 | 808 err = SvPV(GvSV(PL_errgv), length); |
3728 | 809 #endif |
7 | 810 |
811 FREETMPS; | |
812 LEAVE; | |
813 | |
814 if (!length) | |
815 return; | |
816 | |
817 msg_split((char_u *)err, highlight_attr[HLF_E]); | |
818 return; | |
819 } | |
820 } | |
821 | |
822 static int | |
823 replace_line(line, end) | |
824 linenr_T *line, *end; | |
825 { | |
826 char *str; | |
827 | |
828 if (SvOK(GvSV(PL_defgv))) | |
829 { | |
830 str = SvPV(GvSV(PL_defgv), PL_na); | |
831 ml_replace(*line, (char_u *)str, 1); | |
832 changed_bytes(*line, 0); | |
833 } | |
834 else | |
835 { | |
836 ml_delete(*line, FALSE); | |
837 deleted_lines_mark(*line, 1L); | |
838 --(*end); | |
839 --(*line); | |
840 } | |
841 return OK; | |
842 } | |
843 | |
844 /* | |
845 * ":perldo". | |
846 */ | |
847 void | |
848 ex_perldo(eap) | |
849 exarg_T *eap; | |
850 { | |
851 STRLEN length; | |
852 SV *sv; | |
853 char *str; | |
854 linenr_T i; | |
855 | |
856 if (bufempty()) | |
857 return; | |
858 | |
859 if (perl_interp == NULL) | |
860 { | |
861 #ifdef DYNAMIC_PERL | |
862 if (!perl_enabled(TRUE)) | |
863 { | |
864 EMSG(_(e_noperl)); | |
865 return; | |
866 } | |
867 #endif | |
868 perl_init(); | |
869 } | |
870 { | |
871 dSP; | |
872 length = strlen((char *)eap->arg); | |
129 | 873 sv = newSV(length + sizeof("sub VIM::perldo {") - 1 + 1); |
874 sv_setpvn(sv, "sub VIM::perldo {", sizeof("sub VIM::perldo {") - 1); | |
7 | 875 sv_catpvn(sv, (char *)eap->arg, length); |
876 sv_catpvn(sv, "}", 1); | |
877 perl_eval_sv(sv, G_DISCARD | G_NOARGS); | |
878 SvREFCNT_dec(sv); | |
3728 | 879 #ifdef AVOID_PL_ERRGV |
880 str = SvPV(perl_get_sv("@", GV_ADD), length); | |
881 #else | |
7 | 882 str = SvPV(GvSV(PL_errgv), length); |
3728 | 883 #endif |
7 | 884 if (length) |
885 goto err; | |
886 | |
887 if (u_save(eap->line1 - 1, eap->line2 + 1) != OK) | |
888 return; | |
889 | |
890 ENTER; | |
891 SAVETMPS; | |
892 for (i = eap->line1; i <= eap->line2; i++) | |
893 { | |
129 | 894 sv_setpv(GvSV(PL_defgv), (char *)ml_get(i)); |
7 | 895 PUSHMARK(sp); |
896 perl_call_pv("VIM::perldo", G_SCALAR | G_EVAL); | |
3728 | 897 #ifdef AVOID_PL_ERRGV |
898 str = SvPV(perl_get_sv("@", GV_ADD), length); | |
899 #else | |
7 | 900 str = SvPV(GvSV(PL_errgv), length); |
3728 | 901 #endif |
7 | 902 if (length) |
903 break; | |
904 SPAGAIN; | |
905 if (SvTRUEx(POPs)) | |
906 { | |
907 if (replace_line(&i, &eap->line2) != OK) | |
908 { | |
909 PUTBACK; | |
910 break; | |
911 } | |
912 } | |
913 PUTBACK; | |
914 } | |
915 FREETMPS; | |
916 LEAVE; | |
917 check_cursor(); | |
918 update_screen(NOT_VALID); | |
919 if (!length) | |
920 return; | |
921 | |
922 err: | |
923 msg_split((char_u *)str, highlight_attr[HLF_E]); | |
924 return; | |
925 } | |
926 } | |
927 | |
1681 | 928 #ifndef FEAT_WINDOWS |
929 int win_valid(win_T *w) { return TRUE; } | |
930 int win_count() { return 1; } | |
931 win_T *win_find_nr(int n) { return curwin; } | |
932 #endif | |
933 | |
7 | 934 XS(boot_VIM); |
935 | |
936 static void | |
937 xs_init(pTHX) | |
938 { | |
939 char *file = __FILE__; | |
940 | |
941 /* DynaLoader is a special case */ | |
942 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file); | |
943 newXS("VIM::bootstrap", boot_VIM, file); | |
944 } | |
945 | |
946 typedef win_T * VIWIN; | |
947 typedef buf_T * VIBUF; | |
948 | |
949 MODULE = VIM PACKAGE = VIM | |
950 | |
951 void | |
952 Msg(text, hl=NULL) | |
953 char *text; | |
954 char *hl; | |
955 | |
956 PREINIT: | |
957 int attr; | |
958 int id; | |
959 | |
960 PPCODE: | |
961 if (text != NULL) | |
962 { | |
963 attr = 0; | |
964 if (hl != NULL) | |
965 { | |
966 id = syn_name2id((char_u *)hl); | |
967 if (id != 0) | |
968 attr = syn_id2attr(id); | |
969 } | |
970 msg_split((char_u *)text, attr); | |
971 } | |
972 | |
973 void | |
974 SetOption(line) | |
975 char *line; | |
976 | |
977 PPCODE: | |
978 if (line != NULL) | |
979 do_set((char_u *)line, 0); | |
980 update_screen(NOT_VALID); | |
981 | |
982 void | |
983 DoCommand(line) | |
984 char *line; | |
985 | |
986 PPCODE: | |
987 if (line != NULL) | |
988 do_cmdline_cmd((char_u *)line); | |
989 | |
990 void | |
991 Eval(str) | |
992 char *str; | |
993 | |
994 PREINIT: | |
995 char_u *value; | |
996 PPCODE: | |
714 | 997 value = eval_to_string((char_u *)str, (char_u **)0, TRUE); |
7 | 998 if (value == NULL) |
999 { | |
1000 XPUSHs(sv_2mortal(newSViv(0))); | |
1001 XPUSHs(sv_2mortal(newSVpv("", 0))); | |
1002 } | |
1003 else | |
1004 { | |
1005 XPUSHs(sv_2mortal(newSViv(1))); | |
1006 XPUSHs(sv_2mortal(newSVpv((char *)value, 0))); | |
1007 vim_free(value); | |
1008 } | |
1009 | |
1010 void | |
1011 Buffers(...) | |
1012 | |
1013 PREINIT: | |
1014 buf_T *vimbuf; | |
1015 int i, b; | |
1016 | |
1017 PPCODE: | |
1018 if (items == 0) | |
1019 { | |
1020 if (GIMME == G_SCALAR) | |
1021 { | |
1022 i = 0; | |
1023 for (vimbuf = firstbuf; vimbuf; vimbuf = vimbuf->b_next) | |
1024 ++i; | |
1025 | |
1026 XPUSHs(sv_2mortal(newSViv(i))); | |
1027 } | |
1028 else | |
1029 { | |
1030 for (vimbuf = firstbuf; vimbuf; vimbuf = vimbuf->b_next) | |
1031 XPUSHs(newBUFrv(newSV(0), vimbuf)); | |
1032 } | |
1033 } | |
1034 else | |
1035 { | |
1036 for (i = 0; i < items; i++) | |
1037 { | |
1038 SV *sv = ST(i); | |
1039 if (SvIOK(sv)) | |
1040 b = SvIV(ST(i)); | |
1041 else | |
1042 { | |
1043 char_u *pat; | |
1044 STRLEN len; | |
1045 | |
1046 pat = (char_u *)SvPV(sv, len); | |
1047 ++emsg_off; | |
1048 b = buflist_findpat(pat, pat+len, FALSE, FALSE); | |
1049 --emsg_off; | |
1050 } | |
1051 | |
1052 if (b >= 0) | |
1053 { | |
1054 vimbuf = buflist_findnr(b); | |
1055 if (vimbuf) | |
1056 XPUSHs(newBUFrv(newSV(0), vimbuf)); | |
1057 } | |
1058 } | |
1059 } | |
1060 | |
1061 void | |
1062 Windows(...) | |
1063 | |
1064 PREINIT: | |
1065 win_T *vimwin; | |
1066 int i, w; | |
1067 | |
1068 PPCODE: | |
1069 if (items == 0) | |
1070 { | |
1071 if (GIMME == G_SCALAR) | |
1072 XPUSHs(sv_2mortal(newSViv(win_count()))); | |
1073 else | |
1074 { | |
1075 for (vimwin = firstwin; vimwin != NULL; vimwin = W_NEXT(vimwin)) | |
1076 XPUSHs(newWINrv(newSV(0), vimwin)); | |
1077 } | |
1078 } | |
1079 else | |
1080 { | |
1081 for (i = 0; i < items; i++) | |
1082 { | |
1083 w = SvIV(ST(i)); | |
1084 vimwin = win_find_nr(w); | |
1085 if (vimwin) | |
1086 XPUSHs(newWINrv(newSV(0), vimwin)); | |
1087 } | |
1088 } | |
1089 | |
1090 MODULE = VIM PACKAGE = VIWIN | |
1091 | |
1092 void | |
1093 DESTROY(win) | |
1094 VIWIN win | |
1095 | |
1096 CODE: | |
1097 if (win_valid(win)) | |
502 | 1098 win->w_perl_private = 0; |
7 | 1099 |
1100 SV * | |
1101 Buffer(win) | |
1102 VIWIN win | |
1103 | |
1104 CODE: | |
1105 if (!win_valid(win)) | |
1106 win = curwin; | |
1107 RETVAL = newBUFrv(newSV(0), win->w_buffer); | |
1108 OUTPUT: | |
1109 RETVAL | |
1110 | |
1111 void | |
1112 SetHeight(win, height) | |
1113 VIWIN win | |
1114 int height; | |
1115 | |
1116 PREINIT: | |
1117 win_T *savewin; | |
1118 | |
1119 PPCODE: | |
1120 if (!win_valid(win)) | |
1121 win = curwin; | |
1122 savewin = curwin; | |
1123 curwin = win; | |
1124 win_setheight(height); | |
1125 curwin = savewin; | |
1126 | |
1127 void | |
1128 Cursor(win, ...) | |
1129 VIWIN win | |
1130 | |
1131 PPCODE: | |
2982 | 1132 if (items == 1) |
7 | 1133 { |
1134 EXTEND(sp, 2); | |
1135 if (!win_valid(win)) | |
1136 win = curwin; | |
1137 PUSHs(sv_2mortal(newSViv(win->w_cursor.lnum))); | |
1138 PUSHs(sv_2mortal(newSViv(win->w_cursor.col))); | |
1139 } | |
2982 | 1140 else if (items == 3) |
7 | 1141 { |
1142 int lnum, col; | |
1143 | |
1144 if (!win_valid(win)) | |
1145 win = curwin; | |
1146 lnum = SvIV(ST(1)); | |
1147 col = SvIV(ST(2)); | |
1148 win->w_cursor.lnum = lnum; | |
1149 win->w_cursor.col = col; | |
1150 check_cursor(); /* put cursor on an existing line */ | |
1151 update_screen(NOT_VALID); | |
1152 } | |
1153 | |
1154 MODULE = VIM PACKAGE = VIBUF | |
1155 | |
1156 void | |
1157 DESTROY(vimbuf) | |
1158 VIBUF vimbuf; | |
1159 | |
1160 CODE: | |
1161 if (buf_valid(vimbuf)) | |
502 | 1162 vimbuf->b_perl_private = 0; |
7 | 1163 |
1164 void | |
1165 Name(vimbuf) | |
1166 VIBUF vimbuf; | |
1167 | |
1168 PPCODE: | |
1169 if (!buf_valid(vimbuf)) | |
1170 vimbuf = curbuf; | |
1171 /* No file name returns an empty string */ | |
1172 if (vimbuf->b_fname == NULL) | |
1173 XPUSHs(sv_2mortal(newSVpv("", 0))); | |
1174 else | |
1175 XPUSHs(sv_2mortal(newSVpv((char *)vimbuf->b_fname, 0))); | |
1176 | |
1177 void | |
1178 Number(vimbuf) | |
1179 VIBUF vimbuf; | |
1180 | |
1181 PPCODE: | |
1182 if (!buf_valid(vimbuf)) | |
1183 vimbuf = curbuf; | |
1184 XPUSHs(sv_2mortal(newSViv(vimbuf->b_fnum))); | |
1185 | |
1186 void | |
1187 Count(vimbuf) | |
1188 VIBUF vimbuf; | |
1189 | |
1190 PPCODE: | |
1191 if (!buf_valid(vimbuf)) | |
1192 vimbuf = curbuf; | |
1193 XPUSHs(sv_2mortal(newSViv(vimbuf->b_ml.ml_line_count))); | |
1194 | |
1195 void | |
1196 Get(vimbuf, ...) | |
1197 VIBUF vimbuf; | |
1198 | |
1199 PREINIT: | |
1200 char_u *line; | |
1201 int i; | |
1202 long lnum; | |
1203 PPCODE: | |
1204 if (buf_valid(vimbuf)) | |
1205 { | |
1206 for (i = 1; i < items; i++) | |
1207 { | |
1208 lnum = SvIV(ST(i)); | |
1209 if (lnum > 0 && lnum <= vimbuf->b_ml.ml_line_count) | |
1210 { | |
1211 line = ml_get_buf(vimbuf, lnum, FALSE); | |
1212 XPUSHs(sv_2mortal(newSVpv((char *)line, 0))); | |
1213 } | |
1214 } | |
1215 } | |
1216 | |
1217 void | |
1218 Set(vimbuf, ...) | |
1219 VIBUF vimbuf; | |
1220 | |
1221 PREINIT: | |
1222 int i; | |
1223 long lnum; | |
1224 char *line; | |
1225 PPCODE: | |
1226 if (buf_valid(vimbuf)) | |
1227 { | |
1228 if (items < 3) | |
1229 croak("Usage: VIBUF::Set(vimbuf, lnum, @lines)"); | |
1230 | |
1231 lnum = SvIV(ST(1)); | |
1232 for(i = 2; i < items; i++, lnum++) | |
1233 { | |
1234 line = SvPV(ST(i),PL_na); | |
1235 if (lnum > 0 && lnum <= vimbuf->b_ml.ml_line_count && line != NULL) | |
1236 { | |
918 | 1237 aco_save_T aco; |
1238 | |
1239 /* set curwin/curbuf for "vimbuf" and save some things */ | |
1240 aucmd_prepbuf(&aco, vimbuf); | |
1241 | |
7 | 1242 if (u_savesub(lnum) == OK) |
1243 { | |
1244 ml_replace(lnum, (char_u *)line, TRUE); | |
1245 changed_bytes(lnum, 0); | |
1246 } | |
934 | 1247 |
918 | 1248 /* restore curwin/curbuf and a few other things */ |
1249 aucmd_restbuf(&aco); | |
1250 /* Careful: autocommands may have made "vimbuf" invalid! */ | |
7 | 1251 } |
1252 } | |
1253 } | |
1254 | |
1255 void | |
1256 Delete(vimbuf, ...) | |
1257 VIBUF vimbuf; | |
1258 | |
1259 PREINIT: | |
1260 long i, lnum = 0, count = 0; | |
1261 PPCODE: | |
1262 if (buf_valid(vimbuf)) | |
1263 { | |
1264 if (items == 2) | |
1265 { | |
1266 lnum = SvIV(ST(1)); | |
1267 count = 1; | |
1268 } | |
1269 else if (items == 3) | |
1270 { | |
1271 lnum = SvIV(ST(1)); | |
1272 count = 1 + SvIV(ST(2)) - lnum; | |
2982 | 1273 if (count == 0) |
7 | 1274 count = 1; |
2982 | 1275 if (count < 0) |
7 | 1276 { |
1277 lnum -= count; | |
1278 count = -count; | |
1279 } | |
1280 } | |
1281 if (items >= 2) | |
1282 { | |
1283 for (i = 0; i < count; i++) | |
1284 { | |
1285 if (lnum > 0 && lnum <= vimbuf->b_ml.ml_line_count) | |
1286 { | |
918 | 1287 aco_save_T aco; |
1288 | |
1289 /* set curwin/curbuf for "vimbuf" and save some things */ | |
1290 aucmd_prepbuf(&aco, vimbuf); | |
934 | 1291 |
7 | 1292 if (u_savedel(lnum, 1) == OK) |
1293 { | |
1294 ml_delete(lnum, 0); | |
1929 | 1295 check_cursor(); |
7 | 1296 deleted_lines_mark(lnum, 1L); |
1297 } | |
934 | 1298 |
918 | 1299 /* restore curwin/curbuf and a few other things */ |
1300 aucmd_restbuf(&aco); | |
1301 /* Careful: autocommands may have made "vimbuf" invalid! */ | |
934 | 1302 |
7 | 1303 update_curbuf(VALID); |
1304 } | |
1305 } | |
1306 } | |
1307 } | |
1308 | |
1309 void | |
1310 Append(vimbuf, ...) | |
1311 VIBUF vimbuf; | |
1312 | |
1313 PREINIT: | |
1314 int i; | |
1315 long lnum; | |
1316 char *line; | |
1317 PPCODE: | |
1318 if (buf_valid(vimbuf)) | |
1319 { | |
1320 if (items < 3) | |
1321 croak("Usage: VIBUF::Append(vimbuf, lnum, @lines)"); | |
1322 | |
1323 lnum = SvIV(ST(1)); | |
1324 for (i = 2; i < items; i++, lnum++) | |
1325 { | |
1326 line = SvPV(ST(i),PL_na); | |
1327 if (lnum >= 0 && lnum <= vimbuf->b_ml.ml_line_count && line != NULL) | |
1328 { | |
918 | 1329 aco_save_T aco; |
1330 | |
1331 /* set curwin/curbuf for "vimbuf" and save some things */ | |
1332 aucmd_prepbuf(&aco, vimbuf); | |
1333 | |
7 | 1334 if (u_inssub(lnum + 1) == OK) |
1335 { | |
1336 ml_append(lnum, (char_u *)line, (colnr_T)0, FALSE); | |
1337 appended_lines_mark(lnum, 1L); | |
1338 } | |
934 | 1339 |
918 | 1340 /* restore curwin/curbuf and a few other things */ |
1341 aucmd_restbuf(&aco); | |
1342 /* Careful: autocommands may have made "vimbuf" invalid! */ | |
934 | 1343 |
7 | 1344 update_curbuf(VALID); |
1345 } | |
1346 } | |
1347 } | |
1348 |