This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add simple exception handling macros for XS writers.
[perl5.git] / ext / Devel / PPPort / parts / inc / misc
CommitLineData
adfe19db
MHM
1################################################################################
2##
a745474a 3## $Revision: 17 $
adfe19db 4## $Author: mhx $
a745474a 5## $Date: 2004/09/08 21:10:12 +0200 $
adfe19db
MHM
6##
7################################################################################
8##
9## Version 3.x, Copyright (C) 2004, Marcus Holland-Moritz.
10## Version 2.x, Copyright (C) 2001, Paul Marquess.
11## Version 1.x, Copyright (C) 1999, Kenneth Albanowski.
12##
13## This program is free software; you can redistribute it and/or
14## modify it under the same terms as Perl itself.
15##
16################################################################################
17
18=provides
19
20__UNDEFINED__
21PERL_UNUSED_DECL
a745474a 22PERL_GCC_BRACE_GROUPS_FORBIDDEN
adfe19db
MHM
23NVTYPE
24INT2PTR
25PTRV
26NUM2PTR
27PTR2IV
28PTR2UV
29PTR2NV
30PTR2ul
a745474a
MHM
31START_EXTERN_C
32END_EXTERN_C
33EXTERN_C
34STMT_START
35STMT_END
adfe19db
MHM
36/PL_\w+/
37
38=implementation
39
40#if (PERL_VERSION < 4) || ((PERL_VERSION == 4) && (PERL_SUBVERSION <= 5))
41/* Replace: 1 */
96ad942f
MHM
42# define PL_DBsingle DBsingle
43# define PL_DBsub DBsub
44# define PL_Sv Sv
45# define PL_compiling compiling
46# define PL_copline copline
47# define PL_curcop curcop
48# define PL_curstash curstash
49# define PL_debstash debstash
50# define PL_defgv defgv
51# define PL_diehook diehook
52# define PL_dirty dirty
53# define PL_dowarn dowarn
54# define PL_errgv errgv
55# define PL_hexdigit hexdigit
56# define PL_hints hints
57# define PL_na na
58# define PL_no_modify no_modify
59# define PL_perl_destruct_level perl_destruct_level
60# define PL_perldb perldb
61# define PL_ppaddr ppaddr
62# define PL_rsfp_filters rsfp_filters
63# define PL_rsfp rsfp
64# define PL_stack_base stack_base
65# define PL_stack_sp stack_sp
66# define PL_stdingv stdingv
67# define PL_sv_arenaroot sv_arenaroot
68# define PL_sv_no sv_no
69# define PL_sv_undef sv_undef
70# define PL_sv_yes sv_yes
71# define PL_tainted tainted
72# define PL_tainting tainting
adfe19db
MHM
73/* Replace: 0 */
74#endif
75
76#ifdef HASATTRIBUTE
77# if (defined(__GNUC__) && defined(__cplusplus)) || defined(__INTEL_COMPILER)
78# define PERL_UNUSED_DECL
79# else
80# define PERL_UNUSED_DECL __attribute__((unused))
81# endif
82#else
83# define PERL_UNUSED_DECL
84#endif
85
86__UNDEFINED__ NOOP (void)0
87__UNDEFINED__ dNOOP extern int Perl___notused PERL_UNUSED_DECL
88
89#ifndef NVTYPE
90# if defined(USE_LONG_DOUBLE) && defined(HAS_LONG_DOUBLE)
91# define NVTYPE long double
92# else
93# define NVTYPE double
94# endif
95typedef NVTYPE NV;
96#endif
97
98#ifndef INT2PTR
99
100# if (IVSIZE == PTRSIZE) && (UVSIZE == PTRSIZE)
101# define PTRV UV
102# define INT2PTR(any,d) (any)(d)
103# else
104# if PTRSIZE == LONGSIZE
105# define PTRV unsigned long
106# else
107# define PTRV unsigned
108# endif
109# define INT2PTR(any,d) (any)(PTRV)(d)
110# endif
111
112# define NUM2PTR(any,d) (any)(PTRV)(d)
113# define PTR2IV(p) INT2PTR(IV,p)
114# define PTR2UV(p) INT2PTR(UV,p)
115# define PTR2NV(p) NUM2PTR(NV,p)
116
117# if PTRSIZE == LONGSIZE
118# define PTR2ul(p) (unsigned long)(p)
119# else
120# define PTR2ul(p) INT2PTR(unsigned long,p)
121# endif
122
123#endif /* !INT2PTR */
124
a745474a
MHM
125#undef START_EXTERN_C
126#undef END_EXTERN_C
127#undef EXTERN_C
128#ifdef __cplusplus
129# define START_EXTERN_C extern "C" {
130# define END_EXTERN_C }
131# define EXTERN_C extern "C"
132#else
133# define START_EXTERN_C
134# define END_EXTERN_C
135# define EXTERN_C extern
136#endif
137
138#ifndef PERL_GCC_BRACE_GROUPS_FORBIDDEN
139# if defined(__STRICT_ANSI__) && defined(PERL_GCC_PEDANTIC)
140# define PERL_GCC_BRACE_GROUPS_FORBIDDEN
141# endif
142#endif
143
144#undef STMT_START
145#undef STMT_END
146#if defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN) && !defined(__cplusplus)
147# define STMT_START (void)( /* gcc supports ``({ STATEMENTS; })'' */
148# define STMT_END )
149#else
150# if defined(VOIDFLAGS) && (VOIDFLAGS) && (defined(sun) || defined(__sun__)) && !defined(__GNUC__)
151# define STMT_START if (1)
152# define STMT_END else (void)0
153# else
154# define STMT_START do
155# define STMT_END while (0)
156# endif
157#endif
158
adfe19db
MHM
159__UNDEFINED__ boolSV(b) ((b) ? &PL_sv_yes : &PL_sv_no)
160
161/* DEFSV appears first in 5.004_56 */
162__UNDEFINED__ DEFSV GvSV(PL_defgv)
163__UNDEFINED__ SAVE_DEFSV SAVESPTR(GvSV(PL_defgv))
164
165/* Older perls (<=5.003) lack AvFILLp */
166__UNDEFINED__ AvFILLp AvFILL
167
168__UNDEFINED__ ERRSV get_sv("@",FALSE)
169
170__UNDEFINED__ newSVpvn(data,len) ((data) \
171 ? ((len) ? newSVpv((data), (len)) : newSVpv("", 0)) \
172 : newSV(0))
173
174/* Hint: gv_stashpvn
175 * This function's backport doesn't support the length parameter, but
176 * rather ignores it. Portability can only be ensured if the length
177 * parameter is used for speed reasons, but the length can always be
178 * correctly computed from the string argument.
179 */
180
181__UNDEFINED__ gv_stashpvn(str,len,create) gv_stashpv(str,create)
182
183/* Replace: 1 */
184__UNDEFINED__ get_cv perl_get_cv
185__UNDEFINED__ get_sv perl_get_sv
186__UNDEFINED__ get_av perl_get_av
187__UNDEFINED__ get_hv perl_get_hv
188/* Replace: 0 */
189
190#ifdef HAS_MEMCMP
191__UNDEFINED__ memNE(s1,s2,l) (memcmp(s1,s2,l))
192__UNDEFINED__ memEQ(s1,s2,l) (!memcmp(s1,s2,l))
193#else
194__UNDEFINED__ memNE(s1,s2,l) (bcmp(s1,s2,l))
195__UNDEFINED__ memEQ(s1,s2,l) (!bcmp(s1,s2,l))
196#endif
197
198__UNDEFINED__ MoveD(s,d,n,t) memmove((char*)(d),(char*)(s), (n) * sizeof(t))
199__UNDEFINED__ CopyD(s,d,n,t) memcpy((char*)(d),(char*)(s), (n) * sizeof(t))
200#ifdef HAS_MEMSET
201__UNDEFINED__ ZeroD(d,n,t) memzero((char*)(d), (n) * sizeof(t))
202#else
203__UNDEFINED__ ZeroD(d,n,t) ((void)memzero((char*)(d), (n) * sizeof(t)),d)
204#endif
205
206__UNDEFINED__ Poison(d,n,t) (void)memset((char*)(d), 0xAB, (n) * sizeof(t))
207
208__UNDEFINED__ dUNDERBAR dNOOP
209__UNDEFINED__ UNDERBAR DEFSV
210
211__UNDEFINED__ dAX I32 ax = MARK - PL_stack_base + 1
212__UNDEFINED__ dITEMS I32 items = SP - MARK
213
214=xsubs
215
216int
217gv_stashpvn(name, create)
218 char *name
219 I32 create
220 CODE:
221 RETVAL = gv_stashpvn(name, strlen(name), create) != NULL;
222 OUTPUT:
223 RETVAL
224
225int
226get_sv(name, create)
227 char *name
228 I32 create
229 CODE:
230 RETVAL = get_sv(name, create) != NULL;
231 OUTPUT:
232 RETVAL
233
234int
235get_av(name, create)
236 char *name
237 I32 create
238 CODE:
239 RETVAL = get_av(name, create) != NULL;
240 OUTPUT:
241 RETVAL
242
243int
244get_hv(name, create)
245 char *name
246 I32 create
247 CODE:
248 RETVAL = get_hv(name, create) != NULL;
249 OUTPUT:
250 RETVAL
251
252int
253get_cv(name, create)
254 char *name
255 I32 create
256 CODE:
257 RETVAL = get_cv(name, create) != NULL;
258 OUTPUT:
259 RETVAL
260
261void
262newSVpvn()
263 PPCODE:
264 XPUSHs(newSVpvn("test", 4));
265 XPUSHs(newSVpvn("test", 2));
266 XPUSHs(newSVpvn("test", 0));
267 XPUSHs(newSVpvn(NULL, 2));
268 XPUSHs(newSVpvn(NULL, 0));
269 XSRETURN(5);
270
271SV *
272PL_sv_undef()
273 CODE:
274 RETVAL = newSVsv(&PL_sv_undef);
275 OUTPUT:
276 RETVAL
277
278SV *
279PL_sv_yes()
280 CODE:
281 RETVAL = newSVsv(&PL_sv_yes);
282 OUTPUT:
283 RETVAL
284
285SV *
286PL_sv_no()
287 CODE:
288 RETVAL = newSVsv(&PL_sv_no);
289 OUTPUT:
290 RETVAL
291
292int
293PL_na(string)
294 char *string
295 CODE:
296 PL_na = strlen(string);
297 RETVAL = PL_na;
298 OUTPUT:
299 RETVAL
300
301SV*
302boolSV(value)
303 int value
304 CODE:
305 RETVAL = newSVsv(boolSV(value));
306 OUTPUT:
307 RETVAL
308
309SV*
310DEFSV()
311 CODE:
312 RETVAL = newSVsv(DEFSV);
313 OUTPUT:
314 RETVAL
315
316int
317ERRSV()
318 CODE:
319 RETVAL = SvTRUE(ERRSV);
320 OUTPUT:
321 RETVAL
322
323SV*
324UNDERBAR()
325 CODE:
326 {
327 dUNDERBAR;
328 RETVAL = newSVsv(UNDERBAR);
329 }
330 OUTPUT:
331 RETVAL
332
333=tests plan => 31
334
335use vars qw($my_sv @my_av %my_hv);
336
337my @s = &Devel::PPPort::newSVpvn();
338ok(@s == 5);
339ok($s[0], "test");
340ok($s[1], "te");
341ok($s[2], "");
342ok(!defined($s[3]));
343ok(!defined($s[4]));
344
345ok(!defined(&Devel::PPPort::PL_sv_undef()));
346ok(&Devel::PPPort::PL_sv_yes());
347ok(!&Devel::PPPort::PL_sv_no());
348ok(&Devel::PPPort::PL_na("abcd"), 4);
349
350ok(&Devel::PPPort::boolSV(1));
351ok(!&Devel::PPPort::boolSV(0));
352
353$_ = "Fred";
354ok(&Devel::PPPort::DEFSV(), "Fred");
355ok(&Devel::PPPort::UNDERBAR(), "Fred");
356
357eval { 1 };
358ok(!&Devel::PPPort::ERRSV());
359eval { cannot_call_this_one() };
360ok(&Devel::PPPort::ERRSV());
361
362ok(&Devel::PPPort::gv_stashpvn('Devel::PPPort', 0));
363ok(!&Devel::PPPort::gv_stashpvn('does::not::exist', 0));
364ok(&Devel::PPPort::gv_stashpvn('does::not::exist', 1));
365
366$my_sv = 1;
367ok(&Devel::PPPort::get_sv('my_sv', 0));
368ok(!&Devel::PPPort::get_sv('not_my_sv', 0));
369ok(&Devel::PPPort::get_sv('not_my_sv', 1));
370
371@my_av = (1);
372ok(&Devel::PPPort::get_av('my_av', 0));
373ok(!&Devel::PPPort::get_av('not_my_av', 0));
374ok(&Devel::PPPort::get_av('not_my_av', 1));
375
376%my_hv = (a=>1);
377ok(&Devel::PPPort::get_hv('my_hv', 0));
378ok(!&Devel::PPPort::get_hv('not_my_hv', 0));
379ok(&Devel::PPPort::get_hv('not_my_hv', 1));
380
381sub my_cv { 1 };
382ok(&Devel::PPPort::get_cv('my_cv', 0));
383ok(!&Devel::PPPort::get_cv('not_my_cv', 0));
384ok(&Devel::PPPort::get_cv('not_my_cv', 1));
385