Mercurial > vim
annotate src/if_perl.xs @ 3218:0f193ef0f429 v7.3.379
updated for version 7.3.379
Problem: C-indenting wrong for static enum.
Solution: Skip over "static". (Lech Lorens)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Wed, 14 Dec 2011 20:05:21 +0100 |
parents | 22550986c713 |
children | dec4338a7da2 |
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 | |
79 /* Compatibility hacks over */ | |
80 | |
81 static PerlInterpreter *perl_interp = NULL; | |
82 static void xs_init __ARGS((pTHX)); | |
83 static void VIM_init __ARGS((void)); | |
84 EXTERN_C void boot_DynaLoader __ARGS((pTHX_ CV*)); | |
85 | |
86 /* | |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
87 * For dynamic linked perl. |
7 | 88 */ |
89 #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
|
90 |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
91 #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
|
92 #ifdef WIN3264 |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
93 typedef int HANDLE; |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
94 #endif |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
95 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
|
96 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
|
97 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
|
98 #endif |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
99 |
2372
a42d19b78c93
Fix building with Perl on Windows with MingW. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2370
diff
changeset
|
100 #ifndef WIN3264 |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
101 #include <dlfcn.h> |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
102 #define HANDLE void* |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
103 #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
|
104 #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
|
105 #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
|
106 #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
|
107 #else |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
108 #define PERL_PROC FARPROC |
2612 | 109 #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
|
110 #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
|
111 #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
|
112 #endif |
7 | 113 /* |
114 * Wrapper defines | |
115 */ | |
116 # define perl_alloc dll_perl_alloc | |
117 # define perl_construct dll_perl_construct | |
118 # define perl_parse dll_perl_parse | |
119 # define perl_run dll_perl_run | |
120 # define perl_destruct dll_perl_destruct | |
121 # define perl_free dll_perl_free | |
122 # define Perl_get_context dll_Perl_get_context | |
123 # define Perl_croak dll_Perl_croak | |
2096
6510d834609f
updated for version 7.2.380
Bram Moolenaar <bram@zimbu.org>
parents:
2079
diff
changeset
|
124 # ifdef PERL5101_OR_LATER |
2079
5abd3e3c0085
updated for version 7.2.363
Bram Moolenaar <bram@zimbu.org>
parents:
1990
diff
changeset
|
125 # 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
|
126 # endif |
7 | 127 # ifndef PROTO |
128 # define Perl_croak_nocontext dll_Perl_croak_nocontext | |
129 # define Perl_call_argv dll_Perl_call_argv | |
130 # define Perl_call_pv dll_Perl_call_pv | |
131 # define Perl_eval_sv dll_Perl_eval_sv | |
132 # define Perl_get_sv dll_Perl_get_sv | |
133 # define Perl_eval_pv dll_Perl_eval_pv | |
134 # define Perl_call_method dll_Perl_call_method | |
135 # endif | |
136 # define Perl_dowantarray dll_Perl_dowantarray | |
137 # define Perl_free_tmps dll_Perl_free_tmps | |
138 # define Perl_gv_stashpv dll_Perl_gv_stashpv | |
139 # define Perl_markstack_grow dll_Perl_markstack_grow | |
140 # define Perl_mg_find dll_Perl_mg_find | |
141 # define Perl_newXS dll_Perl_newXS | |
142 # define Perl_newSV dll_Perl_newSV | |
143 # define Perl_newSViv dll_Perl_newSViv | |
144 # define Perl_newSVpv dll_Perl_newSVpv | |
145 # define Perl_pop_scope dll_Perl_pop_scope | |
146 # define Perl_push_scope dll_Perl_push_scope | |
147 # define Perl_save_int dll_Perl_save_int | |
148 # define Perl_stack_grow dll_Perl_stack_grow | |
149 # define Perl_set_context dll_Perl_set_context | |
3050 | 150 # if (PERL_REVISION == 5) && (PERL_VERSION >= 14) |
151 # define Perl_sv_2bool_flags dll_Perl_sv_2bool_flags | |
152 # define Perl_xs_apiversion_bootcheck dll_Perl_xs_apiversion_bootcheck | |
153 # else | |
7 | 154 # define Perl_sv_2bool dll_Perl_sv_2bool |
3050 | 155 # endif |
7 | 156 # define Perl_sv_2iv dll_Perl_sv_2iv |
157 # define Perl_sv_2mortal dll_Perl_sv_2mortal | |
158 # if (PERL_REVISION == 5) && (PERL_VERSION >= 8) | |
159 # define Perl_sv_2pv_flags dll_Perl_sv_2pv_flags | |
160 # define Perl_sv_2pv_nolen dll_Perl_sv_2pv_nolen | |
161 # else | |
162 # define Perl_sv_2pv dll_Perl_sv_2pv | |
163 # endif | |
164 # define Perl_sv_bless dll_Perl_sv_bless | |
165 # if (PERL_REVISION == 5) && (PERL_VERSION >= 8) | |
166 # define Perl_sv_catpvn_flags dll_Perl_sv_catpvn_flags | |
167 # else | |
168 # define Perl_sv_catpvn dll_Perl_sv_catpvn | |
169 # endif | |
1387 | 170 #ifdef PERL589_OR_LATER |
171 # define Perl_sv_2iv_flags dll_Perl_sv_2iv_flags | |
172 # define Perl_newXS_flags dll_Perl_newXS_flags | |
173 #endif | |
7 | 174 # define Perl_sv_free dll_Perl_sv_free |
1711 | 175 # if (PERL_REVISION == 5) && (PERL_VERSION >= 10) |
176 # define Perl_sv_free2 dll_Perl_sv_free2 | |
177 # endif | |
7 | 178 # define Perl_sv_isa dll_Perl_sv_isa |
179 # define Perl_sv_magic dll_Perl_sv_magic | |
180 # define Perl_sv_setiv dll_Perl_sv_setiv | |
181 # define Perl_sv_setpv dll_Perl_sv_setpv | |
182 # define Perl_sv_setpvn dll_Perl_sv_setpvn | |
183 # if (PERL_REVISION == 5) && (PERL_VERSION >= 8) | |
184 # define Perl_sv_setsv_flags dll_Perl_sv_setsv_flags | |
185 # else | |
186 # define Perl_sv_setsv dll_Perl_sv_setsv | |
187 # endif | |
188 # define Perl_sv_upgrade dll_Perl_sv_upgrade | |
189 # define Perl_Tstack_sp_ptr dll_Perl_Tstack_sp_ptr | |
190 # define Perl_Top_ptr dll_Perl_Top_ptr | |
191 # define Perl_Tstack_base_ptr dll_Perl_Tstack_base_ptr | |
192 # define Perl_Tstack_max_ptr dll_Perl_Tstack_max_ptr | |
193 # define Perl_Ttmps_ix_ptr dll_Perl_Ttmps_ix_ptr | |
194 # define Perl_Ttmps_floor_ptr dll_Perl_Ttmps_floor_ptr | |
195 # define Perl_Tmarkstack_ptr_ptr dll_Perl_Tmarkstack_ptr_ptr | |
196 # define Perl_Tmarkstack_max_ptr dll_Perl_Tmarkstack_max_ptr | |
197 # define Perl_TSv_ptr dll_Perl_TSv_ptr | |
198 # define Perl_TXpv_ptr dll_Perl_TXpv_ptr | |
199 # define Perl_Tna_ptr dll_Perl_Tna_ptr | |
200 # define Perl_Idefgv_ptr dll_Perl_Idefgv_ptr | |
201 # define Perl_Ierrgv_ptr dll_Perl_Ierrgv_ptr | |
202 # define Perl_Isv_yes_ptr dll_Perl_Isv_yes_ptr | |
203 # 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
|
204 # define Perl_Gthr_key_ptr dll_Perl_Gthr_key_ptr |
7 | 205 |
1765 | 206 # define Perl_sys_init dll_Perl_sys_init |
1668 | 207 # define Perl_sys_term dll_Perl_sys_term |
208 # define Perl_ISv_ptr dll_Perl_ISv_ptr | |
209 # define Perl_Istack_max_ptr dll_Perl_Istack_max_ptr | |
210 # define Perl_Istack_base_ptr dll_Perl_Istack_base_ptr | |
211 # define Perl_Itmps_ix_ptr dll_Perl_Itmps_ix_ptr | |
212 # define Perl_Itmps_floor_ptr dll_Perl_Itmps_floor_ptr | |
213 # define Perl_IXpv_ptr dll_Perl_IXpv_ptr | |
214 # define Perl_Ina_ptr dll_Perl_Ina_ptr | |
215 # define Perl_Imarkstack_ptr_ptr dll_Perl_Imarkstack_ptr_ptr | |
216 # define Perl_Imarkstack_max_ptr dll_Perl_Imarkstack_max_ptr | |
217 # define Perl_Istack_sp_ptr dll_Perl_Istack_sp_ptr | |
218 # define Perl_Iop_ptr dll_Perl_Iop_ptr | |
219 # define Perl_call_list dll_Perl_call_list | |
220 # define Perl_Iscopestack_ix_ptr dll_Perl_Iscopestack_ix_ptr | |
221 # define Perl_Iunitcheckav_ptr dll_Perl_Iunitcheckav_ptr | |
222 | |
7 | 223 /* |
224 * Declare HANDLE for perl.dll and function pointers. | |
225 */ | |
226 static HANDLE hPerlLib = NULL; | |
227 | |
228 static PerlInterpreter* (*perl_alloc)(); | |
229 static void (*perl_construct)(PerlInterpreter*); | |
230 static void (*perl_destruct)(PerlInterpreter*); | |
231 static void (*perl_free)(PerlInterpreter*); | |
232 static int (*perl_run)(PerlInterpreter*); | |
233 static int (*perl_parse)(PerlInterpreter*, XSINIT_t, int, char**, char**); | |
234 static void* (*Perl_get_context)(void); | |
933 | 235 static void (*Perl_croak)(pTHX_ const char*, ...); |
2096
6510d834609f
updated for version 7.2.380
Bram Moolenaar <bram@zimbu.org>
parents:
2079
diff
changeset
|
236 #ifdef PERL5101_OR_LATER |
2079
5abd3e3c0085
updated for version 7.2.363
Bram Moolenaar <bram@zimbu.org>
parents:
1990
diff
changeset
|
237 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
|
238 #endif |
933 | 239 static void (*Perl_croak_nocontext)(const char*, ...); |
7 | 240 static I32 (*Perl_dowantarray)(pTHX); |
241 static void (*Perl_free_tmps)(pTHX); | |
242 static HV* (*Perl_gv_stashpv)(pTHX_ const char*, I32); | |
243 static void (*Perl_markstack_grow)(pTHX); | |
244 static MAGIC* (*Perl_mg_find)(pTHX_ SV*, int); | |
245 static CV* (*Perl_newXS)(pTHX_ char*, XSUBADDR_t, char*); | |
246 static SV* (*Perl_newSV)(pTHX_ STRLEN); | |
247 static SV* (*Perl_newSViv)(pTHX_ IV); | |
248 static SV* (*Perl_newSVpv)(pTHX_ const char*, STRLEN); | |
249 static I32 (*Perl_call_argv)(pTHX_ const char*, I32, char**); | |
250 static I32 (*Perl_call_pv)(pTHX_ const char*, I32); | |
251 static I32 (*Perl_eval_sv)(pTHX_ SV*, I32); | |
252 static SV* (*Perl_get_sv)(pTHX_ const char*, I32); | |
253 static SV* (*Perl_eval_pv)(pTHX_ const char*, I32); | |
254 static SV* (*Perl_call_method)(pTHX_ const char*, I32); | |
255 static void (*Perl_pop_scope)(pTHX); | |
256 static void (*Perl_push_scope)(pTHX); | |
257 static void (*Perl_save_int)(pTHX_ int*); | |
258 static SV** (*Perl_stack_grow)(pTHX_ SV**, SV**p, int); | |
259 static SV** (*Perl_set_context)(void*); | |
3050 | 260 #if (PERL_REVISION == 5) && (PERL_VERSION >= 14) |
261 static bool (*Perl_sv_2bool_flags)(pTHX_ SV*, I32); | |
262 static void (*Perl_xs_apiversion_bootcheck)(pTHX_ SV *module, const char *api_p, STRLEN api_len); | |
263 #else | |
7 | 264 static bool (*Perl_sv_2bool)(pTHX_ SV*); |
3050 | 265 #endif |
7 | 266 static IV (*Perl_sv_2iv)(pTHX_ SV*); |
267 static SV* (*Perl_sv_2mortal)(pTHX_ SV*); | |
268 #if (PERL_REVISION == 5) && (PERL_VERSION >= 8) | |
269 static char* (*Perl_sv_2pv_flags)(pTHX_ SV*, STRLEN*, I32); | |
270 static char* (*Perl_sv_2pv_nolen)(pTHX_ SV*); | |
271 #else | |
272 static char* (*Perl_sv_2pv)(pTHX_ SV*, STRLEN*); | |
273 #endif | |
274 static SV* (*Perl_sv_bless)(pTHX_ SV*, HV*); | |
275 #if (PERL_REVISION == 5) && (PERL_VERSION >= 8) | |
276 static void (*Perl_sv_catpvn_flags)(pTHX_ SV* , const char*, STRLEN, I32); | |
277 #else | |
278 static void (*Perl_sv_catpvn)(pTHX_ SV*, const char*, STRLEN); | |
279 #endif | |
1387 | 280 #ifdef PERL589_OR_LATER |
281 static IV (*Perl_sv_2iv_flags)(pTHX_ SV* sv, I32 flags); | |
282 static CV * (*Perl_newXS_flags)(pTHX_ const char *name, XSUBADDR_t subaddr, const char *const filename, const char *const proto, U32 flags); | |
283 #endif | |
7 | 284 static void (*Perl_sv_free)(pTHX_ SV*); |
285 static int (*Perl_sv_isa)(pTHX_ SV*, const char*); | |
286 static void (*Perl_sv_magic)(pTHX_ SV*, SV*, int, const char*, I32); | |
287 static void (*Perl_sv_setiv)(pTHX_ SV*, IV); | |
288 static void (*Perl_sv_setpv)(pTHX_ SV*, const char*); | |
289 static void (*Perl_sv_setpvn)(pTHX_ SV*, const char*, STRLEN); | |
290 #if (PERL_REVISION == 5) && (PERL_VERSION >= 8) | |
291 static void (*Perl_sv_setsv_flags)(pTHX_ SV*, SV*, I32); | |
292 #else | |
293 static void (*Perl_sv_setsv)(pTHX_ SV*, SV*); | |
294 #endif | |
295 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
|
296 #if (PERL_REVISION == 5) && (PERL_VERSION < 10) |
7 | 297 static SV*** (*Perl_Tstack_sp_ptr)(register PerlInterpreter*); |
298 static OP** (*Perl_Top_ptr)(register PerlInterpreter*); | |
299 static SV*** (*Perl_Tstack_base_ptr)(register PerlInterpreter*); | |
300 static SV*** (*Perl_Tstack_max_ptr)(register PerlInterpreter*); | |
301 static I32* (*Perl_Ttmps_ix_ptr)(register PerlInterpreter*); | |
302 static I32* (*Perl_Ttmps_floor_ptr)(register PerlInterpreter*); | |
303 static I32** (*Perl_Tmarkstack_ptr_ptr)(register PerlInterpreter*); | |
304 static I32** (*Perl_Tmarkstack_max_ptr)(register PerlInterpreter*); | |
305 static SV** (*Perl_TSv_ptr)(register PerlInterpreter*); | |
306 static XPV** (*Perl_TXpv_ptr)(register PerlInterpreter*); | |
307 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
|
308 #else |
1711 | 309 static void (*Perl_sv_free2)(pTHX_ SV*); |
1765 | 310 static void (*Perl_sys_init)(int* argc, char*** argv); |
1668 | 311 static void (*Perl_sys_term)(void); |
312 static SV** (*Perl_ISv_ptr)(register PerlInterpreter*); | |
313 static SV*** (*Perl_Istack_max_ptr)(register PerlInterpreter*); | |
314 static SV*** (*Perl_Istack_base_ptr)(register PerlInterpreter*); | |
315 static XPV** (*Perl_IXpv_ptr)(register PerlInterpreter*); | |
316 static I32* (*Perl_Itmps_ix_ptr)(register PerlInterpreter*); | |
317 static I32* (*Perl_Itmps_floor_ptr)(register PerlInterpreter*); | |
318 static STRLEN* (*Perl_Ina_ptr)(register PerlInterpreter*); | |
319 static I32** (*Perl_Imarkstack_ptr_ptr)(register PerlInterpreter*); | |
320 static I32** (*Perl_Imarkstack_max_ptr)(register PerlInterpreter*); | |
321 static SV*** (*Perl_Istack_sp_ptr)(register PerlInterpreter*); | |
322 static OP** (*Perl_Iop_ptr)(register PerlInterpreter*); | |
323 static void (*Perl_call_list)(pTHX_ I32, AV*); | |
324 static I32* (*Perl_Iscopestack_ix_ptr)(register PerlInterpreter*); | |
325 static AV** (*Perl_Iunitcheckav_ptr)(register PerlInterpreter*); | |
326 #endif | |
7 | 327 |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
328 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
|
329 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
|
330 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
|
331 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
|
332 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
|
333 |
7 | 334 /* |
335 * Table of name to function pointer of perl. | |
336 */ | |
337 static struct { | |
338 char* name; | |
339 PERL_PROC* ptr; | |
340 } perl_funcname_table[] = { | |
341 {"perl_alloc", (PERL_PROC*)&perl_alloc}, | |
342 {"perl_construct", (PERL_PROC*)&perl_construct}, | |
343 {"perl_destruct", (PERL_PROC*)&perl_destruct}, | |
344 {"perl_free", (PERL_PROC*)&perl_free}, | |
345 {"perl_run", (PERL_PROC*)&perl_run}, | |
346 {"perl_parse", (PERL_PROC*)&perl_parse}, | |
347 {"Perl_get_context", (PERL_PROC*)&Perl_get_context}, | |
348 {"Perl_croak", (PERL_PROC*)&Perl_croak}, | |
2096
6510d834609f
updated for version 7.2.380
Bram Moolenaar <bram@zimbu.org>
parents:
2079
diff
changeset
|
349 #ifdef PERL5101_OR_LATER |
2079
5abd3e3c0085
updated for version 7.2.363
Bram Moolenaar <bram@zimbu.org>
parents:
1990
diff
changeset
|
350 {"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
|
351 #endif |
7 | 352 {"Perl_croak_nocontext", (PERL_PROC*)&Perl_croak_nocontext}, |
353 {"Perl_dowantarray", (PERL_PROC*)&Perl_dowantarray}, | |
354 {"Perl_free_tmps", (PERL_PROC*)&Perl_free_tmps}, | |
355 {"Perl_gv_stashpv", (PERL_PROC*)&Perl_gv_stashpv}, | |
356 {"Perl_markstack_grow", (PERL_PROC*)&Perl_markstack_grow}, | |
357 {"Perl_mg_find", (PERL_PROC*)&Perl_mg_find}, | |
358 {"Perl_newXS", (PERL_PROC*)&Perl_newXS}, | |
359 {"Perl_newSV", (PERL_PROC*)&Perl_newSV}, | |
360 {"Perl_newSViv", (PERL_PROC*)&Perl_newSViv}, | |
361 {"Perl_newSVpv", (PERL_PROC*)&Perl_newSVpv}, | |
362 {"Perl_call_argv", (PERL_PROC*)&Perl_call_argv}, | |
363 {"Perl_call_pv", (PERL_PROC*)&Perl_call_pv}, | |
364 {"Perl_eval_sv", (PERL_PROC*)&Perl_eval_sv}, | |
365 {"Perl_get_sv", (PERL_PROC*)&Perl_get_sv}, | |
366 {"Perl_eval_pv", (PERL_PROC*)&Perl_eval_pv}, | |
367 {"Perl_call_method", (PERL_PROC*)&Perl_call_method}, | |
368 {"Perl_pop_scope", (PERL_PROC*)&Perl_pop_scope}, | |
369 {"Perl_push_scope", (PERL_PROC*)&Perl_push_scope}, | |
370 {"Perl_save_int", (PERL_PROC*)&Perl_save_int}, | |
371 {"Perl_stack_grow", (PERL_PROC*)&Perl_stack_grow}, | |
372 {"Perl_set_context", (PERL_PROC*)&Perl_set_context}, | |
3050 | 373 #if (PERL_REVISION == 5) && (PERL_VERSION >= 14) |
374 {"Perl_sv_2bool_flags", (PERL_PROC*)&Perl_sv_2bool_flags}, | |
375 {"Perl_xs_apiversion_bootcheck",(PERL_PROC*)&Perl_xs_apiversion_bootcheck}, | |
376 #else | |
7 | 377 {"Perl_sv_2bool", (PERL_PROC*)&Perl_sv_2bool}, |
3050 | 378 #endif |
7 | 379 {"Perl_sv_2iv", (PERL_PROC*)&Perl_sv_2iv}, |
380 {"Perl_sv_2mortal", (PERL_PROC*)&Perl_sv_2mortal}, | |
381 #if (PERL_REVISION == 5) && (PERL_VERSION >= 8) | |
382 {"Perl_sv_2pv_flags", (PERL_PROC*)&Perl_sv_2pv_flags}, | |
383 {"Perl_sv_2pv_nolen", (PERL_PROC*)&Perl_sv_2pv_nolen}, | |
384 #else | |
385 {"Perl_sv_2pv", (PERL_PROC*)&Perl_sv_2pv}, | |
386 #endif | |
1387 | 387 #ifdef PERL589_OR_LATER |
388 {"Perl_sv_2iv_flags", (PERL_PROC*)&Perl_sv_2iv_flags}, | |
389 {"Perl_newXS_flags", (PERL_PROC*)&Perl_newXS_flags}, | |
390 #endif | |
7 | 391 {"Perl_sv_bless", (PERL_PROC*)&Perl_sv_bless}, |
392 #if (PERL_REVISION == 5) && (PERL_VERSION >= 8) | |
393 {"Perl_sv_catpvn_flags", (PERL_PROC*)&Perl_sv_catpvn_flags}, | |
394 #else | |
395 {"Perl_sv_catpvn", (PERL_PROC*)&Perl_sv_catpvn}, | |
396 #endif | |
397 {"Perl_sv_free", (PERL_PROC*)&Perl_sv_free}, | |
398 {"Perl_sv_isa", (PERL_PROC*)&Perl_sv_isa}, | |
399 {"Perl_sv_magic", (PERL_PROC*)&Perl_sv_magic}, | |
400 {"Perl_sv_setiv", (PERL_PROC*)&Perl_sv_setiv}, | |
401 {"Perl_sv_setpv", (PERL_PROC*)&Perl_sv_setpv}, | |
402 {"Perl_sv_setpvn", (PERL_PROC*)&Perl_sv_setpvn}, | |
403 #if (PERL_REVISION == 5) && (PERL_VERSION >= 8) | |
404 {"Perl_sv_setsv_flags", (PERL_PROC*)&Perl_sv_setsv_flags}, | |
405 #else | |
406 {"Perl_sv_setsv", (PERL_PROC*)&Perl_sv_setsv}, | |
407 #endif | |
408 {"Perl_sv_upgrade", (PERL_PROC*)&Perl_sv_upgrade}, | |
1668 | 409 #if (PERL_REVISION == 5) && (PERL_VERSION < 10) |
7 | 410 {"Perl_Tstack_sp_ptr", (PERL_PROC*)&Perl_Tstack_sp_ptr}, |
411 {"Perl_Top_ptr", (PERL_PROC*)&Perl_Top_ptr}, | |
412 {"Perl_Tstack_base_ptr", (PERL_PROC*)&Perl_Tstack_base_ptr}, | |
413 {"Perl_Tstack_max_ptr", (PERL_PROC*)&Perl_Tstack_max_ptr}, | |
414 {"Perl_Ttmps_ix_ptr", (PERL_PROC*)&Perl_Ttmps_ix_ptr}, | |
415 {"Perl_Ttmps_floor_ptr", (PERL_PROC*)&Perl_Ttmps_floor_ptr}, | |
416 {"Perl_Tmarkstack_ptr_ptr", (PERL_PROC*)&Perl_Tmarkstack_ptr_ptr}, | |
417 {"Perl_Tmarkstack_max_ptr", (PERL_PROC*)&Perl_Tmarkstack_max_ptr}, | |
418 {"Perl_TSv_ptr", (PERL_PROC*)&Perl_TSv_ptr}, | |
419 {"Perl_TXpv_ptr", (PERL_PROC*)&Perl_TXpv_ptr}, | |
420 {"Perl_Tna_ptr", (PERL_PROC*)&Perl_Tna_ptr}, | |
1668 | 421 #else |
1711 | 422 {"Perl_sv_free2", (PERL_PROC*)&Perl_sv_free2}, |
1765 | 423 {"Perl_sys_init", (PERL_PROC*)&Perl_sys_init}, |
1668 | 424 {"Perl_sys_term", (PERL_PROC*)&Perl_sys_term}, |
3050 | 425 {"Perl_call_list", (PERL_PROC*)&Perl_call_list}, |
426 # if (PERL_REVISION == 5) && (PERL_VERSION >= 14) | |
427 # else | |
1668 | 428 {"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
|
429 {"Perl_Istack_max_ptr", (PERL_PROC*)&Perl_Istack_max_ptr}, |
1668 | 430 {"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
|
431 {"Perl_IXpv_ptr", (PERL_PROC*)&Perl_IXpv_ptr}, |
1668 | 432 {"Perl_Itmps_ix_ptr", (PERL_PROC*)&Perl_Itmps_ix_ptr}, |
433 {"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
|
434 {"Perl_Ina_ptr", (PERL_PROC*)&Perl_Ina_ptr}, |
1668 | 435 {"Perl_Imarkstack_ptr_ptr", (PERL_PROC*)&Perl_Imarkstack_ptr_ptr}, |
436 {"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
|
437 {"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
|
438 {"Perl_Iop_ptr", (PERL_PROC*)&Perl_Iop_ptr}, |
1668 | 439 {"Perl_Iscopestack_ix_ptr", (PERL_PROC*)&Perl_Iscopestack_ix_ptr}, |
440 {"Perl_Iunitcheckav_ptr", (PERL_PROC*)&Perl_Iunitcheckav_ptr}, | |
3050 | 441 # endif |
1668 | 442 #endif |
3050 | 443 #if (PERL_REVISION == 5) && (PERL_VERSION >= 14) |
444 #else | |
7 | 445 {"Perl_Idefgv_ptr", (PERL_PROC*)&Perl_Idefgv_ptr}, |
446 {"Perl_Ierrgv_ptr", (PERL_PROC*)&Perl_Ierrgv_ptr}, | |
447 {"Perl_Isv_yes_ptr", (PERL_PROC*)&Perl_Isv_yes_ptr}, | |
3050 | 448 {"Perl_Gthr_key_ptr", (PERL_PROC*)&Perl_Gthr_key_ptr}, |
449 #endif | |
7 | 450 {"boot_DynaLoader", (PERL_PROC*)&boot_DynaLoader}, |
451 {"", NULL}, | |
452 }; | |
453 | |
454 /* | |
455 * Make all runtime-links of perl. | |
456 * | |
457 * 1. Get module handle using LoadLibraryEx. | |
458 * 2. Get pointer to perl function by GetProcAddress. | |
459 * 3. Repeat 2, until get all functions will be used. | |
460 * | |
461 * Parameter 'libname' provides name of DLL. | |
462 * Return OK or FAIL. | |
463 */ | |
464 static int | |
465 perl_runtime_link_init(char *libname, int verbose) | |
466 { | |
467 int i; | |
468 | |
469 if (hPerlLib != NULL) | |
470 return OK; | |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
471 if ((hPerlLib = load_dll(libname)) == NULL) |
7 | 472 { |
473 if (verbose) | |
474 EMSG2(_("E370: Could not load library %s"), libname); | |
475 return FAIL; | |
476 } | |
477 for (i = 0; perl_funcname_table[i].ptr; ++i) | |
478 { | |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
479 if (!(*perl_funcname_table[i].ptr = symbol_from_dll(hPerlLib, |
7 | 480 perl_funcname_table[i].name))) |
481 { | |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
482 close_dll(hPerlLib); |
7 | 483 hPerlLib = NULL; |
484 if (verbose) | |
485 EMSG2(_(e_loadfunc), perl_funcname_table[i].name); | |
486 return FAIL; | |
487 } | |
488 } | |
489 return OK; | |
490 } | |
491 | |
492 /* | |
493 * If runtime-link-perl(DLL) was loaded successfully, return TRUE. | |
494 * There were no DLL loaded, return FALSE. | |
495 */ | |
496 int | |
497 perl_enabled(verbose) | |
498 int verbose; | |
499 { | |
500 return perl_runtime_link_init(DYNAMIC_PERL_DLL, verbose) == OK; | |
501 } | |
502 #endif /* DYNAMIC_PERL */ | |
503 | |
504 /* | |
505 * perl_init(): initialize perl interpreter | |
506 * We have to call perl_parse to initialize some structures, | |
507 * there's nothing to actually parse. | |
508 */ | |
509 static void | |
510 perl_init() | |
511 { | |
1668 | 512 char *bootargs[] = { "VI", NULL }; |
513 int argc = 3; | |
514 static char *argv[] = { "", "-e", "" }; | |
7 | 515 |
1668 | 516 #if (PERL_REVISION == 5) && (PERL_VERSION >= 10) |
1765 | 517 Perl_sys_init(&argc, (char***)&argv); |
1668 | 518 #endif |
7 | 519 perl_interp = perl_alloc(); |
520 perl_construct(perl_interp); | |
1668 | 521 perl_parse(perl_interp, xs_init, argc, argv, 0); |
7 | 522 perl_call_argv("VIM::bootstrap", (long)G_DISCARD, bootargs); |
523 VIM_init(); | |
524 #ifdef USE_SFIO | |
525 sfdisc(PerlIO_stdout(), sfdcnewvim()); | |
526 sfdisc(PerlIO_stderr(), sfdcnewvim()); | |
527 sfsetbuf(PerlIO_stdout(), NULL, 0); | |
528 sfsetbuf(PerlIO_stderr(), NULL, 0); | |
529 #endif | |
530 } | |
531 | |
532 /* | |
533 * perl_end(): clean up after ourselves | |
534 */ | |
535 void | |
536 perl_end() | |
537 { | |
538 if (perl_interp) | |
539 { | |
540 perl_run(perl_interp); | |
541 perl_destruct(perl_interp); | |
542 perl_free(perl_interp); | |
543 perl_interp = NULL; | |
1668 | 544 #if (PERL_REVISION == 5) && (PERL_VERSION >= 10) |
545 Perl_sys_term(); | |
546 #endif | |
7 | 547 } |
548 #ifdef DYNAMIC_PERL | |
549 if (hPerlLib) | |
550 { | |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
551 close_dll(hPerlLib); |
7 | 552 hPerlLib = NULL; |
553 } | |
554 #endif | |
555 } | |
556 | |
557 /* | |
558 * msg_split(): send a message to the message handling routines | |
559 * split at '\n' first though. | |
560 */ | |
561 void | |
562 msg_split(s, attr) | |
563 char_u *s; | |
564 int attr; /* highlighting attributes */ | |
565 { | |
566 char *next; | |
567 char *token = (char *)s; | |
568 | |
1423 | 569 while ((next = strchr(token, '\n')) && !got_int) |
7 | 570 { |
571 *next++ = '\0'; /* replace \n with \0 */ | |
572 msg_attr((char_u *)token, attr); | |
573 token = next; | |
574 } | |
1423 | 575 if (*token && !got_int) |
7 | 576 msg_attr((char_u *)token, attr); |
577 } | |
578 | |
579 #ifndef FEAT_EVAL | |
580 /* | |
581 * This stub is needed because an "#ifdef FEAT_EVAL" around Eval() doesn't | |
582 * work properly. | |
583 */ | |
584 char_u * | |
714 | 585 eval_to_string(arg, nextcmd, dolist) |
7 | 586 char_u *arg; |
587 char_u **nextcmd; | |
714 | 588 int dolist; |
7 | 589 { |
590 return NULL; | |
591 } | |
592 #endif | |
593 | |
594 /* | |
595 * Create a new reference to an SV pointing to the SCR structure | |
502 | 596 * The b_perl_private/w_perl_private part of the SCR structure points to the |
597 * SV, so there can only be one such SV for a particular SCR structure. When | |
598 * the last reference has gone (DESTROY is called), | |
599 * b_perl_private/w_perl_private is reset; When the screen goes away before | |
7 | 600 * all references are gone, the value of the SV is reset; |
601 * any subsequent use of any of those reference will produce | |
602 * a warning. (see typemap) | |
603 */ | |
502 | 604 |
605 static SV * | |
606 newWINrv(rv, ptr) | |
607 SV *rv; | |
608 win_T *ptr; | |
609 { | |
610 sv_upgrade(rv, SVt_RV); | |
611 if (ptr->w_perl_private == NULL) | |
612 { | |
613 ptr->w_perl_private = newSV(0); | |
614 sv_setiv(ptr->w_perl_private, (IV)ptr); | |
615 } | |
616 else | |
617 SvREFCNT_inc(ptr->w_perl_private); | |
618 SvRV(rv) = ptr->w_perl_private; | |
619 SvROK_on(rv); | |
620 return sv_bless(rv, gv_stashpv("VIWIN", TRUE)); | |
7 | 621 } |
622 | |
502 | 623 static SV * |
624 newBUFrv(rv, ptr) | |
625 SV *rv; | |
626 buf_T *ptr; | |
627 { | |
628 sv_upgrade(rv, SVt_RV); | |
629 if (ptr->b_perl_private == NULL) | |
630 { | |
631 ptr->b_perl_private = newSV(0); | |
632 sv_setiv(ptr->b_perl_private, (IV)ptr); | |
633 } | |
634 else | |
635 SvREFCNT_inc(ptr->b_perl_private); | |
636 SvRV(rv) = ptr->b_perl_private; | |
637 SvROK_on(rv); | |
638 return sv_bless(rv, gv_stashpv("VIBUF", TRUE)); | |
639 } | |
7 | 640 |
641 /* | |
642 * perl_win_free | |
643 * Remove all refences to the window to be destroyed | |
644 */ | |
645 void | |
646 perl_win_free(wp) | |
647 win_T *wp; | |
648 { | |
502 | 649 if (wp->w_perl_private) |
650 sv_setiv((SV *)wp->w_perl_private, 0); | |
7 | 651 return; |
652 } | |
653 | |
654 void | |
655 perl_buf_free(bp) | |
656 buf_T *bp; | |
657 { | |
502 | 658 if (bp->b_perl_private) |
659 sv_setiv((SV *)bp->b_perl_private, 0); | |
7 | 660 return; |
661 } | |
662 | |
663 #ifndef PROTO | |
664 # if (PERL_REVISION == 5) && (PERL_VERSION >= 8) | |
665 I32 cur_val(pTHX_ IV iv, SV *sv); | |
666 # else | |
667 I32 cur_val(IV iv, SV *sv); | |
668 #endif | |
669 | |
670 /* | |
671 * Handler for the magic variables $main::curwin and $main::curbuf. | |
672 * The handler is put into the magic vtbl for these variables. | |
673 * (This is effectively a C-level equivalent of a tied variable). | |
674 * There is no "set" function as the variables are read-only. | |
675 */ | |
676 # if (PERL_REVISION == 5) && (PERL_VERSION >= 8) | |
677 I32 cur_val(pTHX_ IV iv, SV *sv) | |
678 # else | |
679 I32 cur_val(IV iv, SV *sv) | |
680 # endif | |
681 { | |
682 SV *rv; | |
683 if (iv == 0) | |
684 rv = newWINrv(newSV(0), curwin); | |
685 else | |
686 rv = newBUFrv(newSV(0), curbuf); | |
687 sv_setsv(sv, rv); | |
688 return 0; | |
689 } | |
690 #endif /* !PROTO */ | |
691 | |
692 struct ufuncs cw_funcs = { cur_val, 0, 0 }; | |
693 struct ufuncs cb_funcs = { cur_val, 0, 1 }; | |
694 | |
695 /* | |
696 * VIM_init(): Vim-specific initialisation. | |
697 * Make the magical main::curwin and main::curbuf variables | |
698 */ | |
699 static void | |
700 VIM_init() | |
701 { | |
702 static char cw[] = "main::curwin"; | |
703 static char cb[] = "main::curbuf"; | |
704 SV *sv; | |
705 | |
706 sv = perl_get_sv(cw, TRUE); | |
707 sv_magic(sv, NULL, 'U', (char *)&cw_funcs, sizeof(cw_funcs)); | |
708 SvREADONLY_on(sv); | |
709 | |
710 sv = perl_get_sv(cb, TRUE); | |
711 sv_magic(sv, NULL, 'U', (char *)&cb_funcs, sizeof(cb_funcs)); | |
712 SvREADONLY_on(sv); | |
713 | |
714 /* | |
715 * Setup the Safe compartment. | |
716 * It shouldn't be a fatal error if the Safe module is missing. | |
717 * XXX: Only shares the 'Msg' routine (which has to be called | |
718 * like 'Msg(...)'). | |
719 */ | |
720 (void)perl_eval_pv( "if ( eval( 'require Safe' ) ) { $VIM::safe = Safe->new(); $VIM::safe->share_from( 'VIM', ['Msg'] ); }", G_DISCARD | G_VOID ); | |
721 | |
722 } | |
723 | |
724 #ifdef DYNAMIC_PERL | |
725 static char *e_noperl = N_("Sorry, this command is disabled: the Perl library could not be loaded."); | |
726 #endif | |
727 | |
728 /* | |
729 * ":perl" | |
730 */ | |
731 void | |
732 ex_perl(eap) | |
733 exarg_T *eap; | |
734 { | |
735 char *err; | |
736 char *script; | |
737 STRLEN length; | |
738 SV *sv; | |
2255 | 739 #ifdef HAVE_SANDBOX |
7 | 740 SV *safe; |
2255 | 741 #endif |
7 | 742 |
743 script = (char *)script_get(eap, eap->arg); | |
744 if (eap->skip) | |
745 { | |
746 vim_free(script); | |
747 return; | |
748 } | |
749 | |
750 if (perl_interp == NULL) | |
751 { | |
752 #ifdef DYNAMIC_PERL | |
753 if (!perl_enabled(TRUE)) | |
754 { | |
755 EMSG(_(e_noperl)); | |
756 vim_free(script); | |
757 return; | |
758 } | |
759 #endif | |
760 perl_init(); | |
761 } | |
762 | |
763 { | |
764 dSP; | |
765 ENTER; | |
766 SAVETMPS; | |
767 | |
768 if (script == NULL) | |
769 sv = newSVpv((char *)eap->arg, 0); | |
770 else | |
771 { | |
772 sv = newSVpv(script, 0); | |
773 vim_free(script); | |
774 } | |
775 | |
776 #ifdef HAVE_SANDBOX | |
777 if (sandbox) | |
778 { | |
2982 | 779 safe = perl_get_sv("VIM::safe", FALSE); |
1934 | 780 # ifndef MAKE_TEST /* avoid a warning for unreachable code */ |
1990 | 781 if (safe == NULL || !SvTRUE(safe)) |
7 | 782 EMSG(_("E299: Perl evaluation forbidden in sandbox without the Safe module")); |
783 else | |
1934 | 784 # endif |
7 | 785 { |
786 PUSHMARK(SP); | |
787 XPUSHs(safe); | |
788 XPUSHs(sv); | |
789 PUTBACK; | |
790 perl_call_method("reval", G_DISCARD); | |
791 } | |
792 } | |
793 else | |
794 #endif | |
795 perl_eval_sv(sv, G_DISCARD | G_NOARGS); | |
796 | |
797 SvREFCNT_dec(sv); | |
798 | |
799 err = SvPV(GvSV(PL_errgv), length); | |
800 | |
801 FREETMPS; | |
802 LEAVE; | |
803 | |
804 if (!length) | |
805 return; | |
806 | |
807 msg_split((char_u *)err, highlight_attr[HLF_E]); | |
808 return; | |
809 } | |
810 } | |
811 | |
812 static int | |
813 replace_line(line, end) | |
814 linenr_T *line, *end; | |
815 { | |
816 char *str; | |
817 | |
818 if (SvOK(GvSV(PL_defgv))) | |
819 { | |
820 str = SvPV(GvSV(PL_defgv), PL_na); | |
821 ml_replace(*line, (char_u *)str, 1); | |
822 changed_bytes(*line, 0); | |
823 } | |
824 else | |
825 { | |
826 ml_delete(*line, FALSE); | |
827 deleted_lines_mark(*line, 1L); | |
828 --(*end); | |
829 --(*line); | |
830 } | |
831 return OK; | |
832 } | |
833 | |
834 /* | |
835 * ":perldo". | |
836 */ | |
837 void | |
838 ex_perldo(eap) | |
839 exarg_T *eap; | |
840 { | |
841 STRLEN length; | |
842 SV *sv; | |
843 char *str; | |
844 linenr_T i; | |
845 | |
846 if (bufempty()) | |
847 return; | |
848 | |
849 if (perl_interp == NULL) | |
850 { | |
851 #ifdef DYNAMIC_PERL | |
852 if (!perl_enabled(TRUE)) | |
853 { | |
854 EMSG(_(e_noperl)); | |
855 return; | |
856 } | |
857 #endif | |
858 perl_init(); | |
859 } | |
860 { | |
861 dSP; | |
862 length = strlen((char *)eap->arg); | |
129 | 863 sv = newSV(length + sizeof("sub VIM::perldo {") - 1 + 1); |
864 sv_setpvn(sv, "sub VIM::perldo {", sizeof("sub VIM::perldo {") - 1); | |
7 | 865 sv_catpvn(sv, (char *)eap->arg, length); |
866 sv_catpvn(sv, "}", 1); | |
867 perl_eval_sv(sv, G_DISCARD | G_NOARGS); | |
868 SvREFCNT_dec(sv); | |
869 str = SvPV(GvSV(PL_errgv), length); | |
870 if (length) | |
871 goto err; | |
872 | |
873 if (u_save(eap->line1 - 1, eap->line2 + 1) != OK) | |
874 return; | |
875 | |
876 ENTER; | |
877 SAVETMPS; | |
878 for (i = eap->line1; i <= eap->line2; i++) | |
879 { | |
129 | 880 sv_setpv(GvSV(PL_defgv), (char *)ml_get(i)); |
7 | 881 PUSHMARK(sp); |
882 perl_call_pv("VIM::perldo", G_SCALAR | G_EVAL); | |
883 str = SvPV(GvSV(PL_errgv), length); | |
884 if (length) | |
885 break; | |
886 SPAGAIN; | |
887 if (SvTRUEx(POPs)) | |
888 { | |
889 if (replace_line(&i, &eap->line2) != OK) | |
890 { | |
891 PUTBACK; | |
892 break; | |
893 } | |
894 } | |
895 PUTBACK; | |
896 } | |
897 FREETMPS; | |
898 LEAVE; | |
899 check_cursor(); | |
900 update_screen(NOT_VALID); | |
901 if (!length) | |
902 return; | |
903 | |
904 err: | |
905 msg_split((char_u *)str, highlight_attr[HLF_E]); | |
906 return; | |
907 } | |
908 } | |
909 | |
1681 | 910 #ifndef FEAT_WINDOWS |
911 int win_valid(win_T *w) { return TRUE; } | |
912 int win_count() { return 1; } | |
913 win_T *win_find_nr(int n) { return curwin; } | |
914 #endif | |
915 | |
7 | 916 XS(XS_VIM_Msg); |
917 XS(XS_VIM_SetOption); | |
918 XS(XS_VIM_DoCommand); | |
919 XS(XS_VIM_Eval); | |
920 XS(XS_VIM_Buffers); | |
921 XS(XS_VIM_Windows); | |
922 XS(XS_VIWIN_DESTROY); | |
923 XS(XS_VIWIN_Buffer); | |
924 XS(XS_VIWIN_SetHeight); | |
925 XS(XS_VIWIN_Cursor); | |
926 XS(XS_VIBUF_DESTROY); | |
927 XS(XS_VIBUF_Name); | |
928 XS(XS_VIBUF_Number); | |
929 XS(XS_VIBUF_Count); | |
930 XS(XS_VIBUF_Get); | |
931 XS(XS_VIBUF_Set); | |
932 XS(XS_VIBUF_Delete); | |
933 XS(XS_VIBUF_Append); | |
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 |