12 # Export everything since these functions are only used by a test script
13 # Export subpackages too - in effect, export all their routines into us, then
14 # export everything from us.
17 croak ("Can't export for '$package'") unless $package eq __PACKAGE__;
19 @{$exports}{@_} = () if @_;
23 my @stashes = ('XS::APItest::', \%XS::APItest::);
24 while (my ($stash_name, $stash) = splice @stashes, 0, 2) {
25 while (my ($sym_name, $glob) = each %$stash) {
26 if ($sym_name =~ /::$/) {
27 # Skip any subpackages that are clearly OO
28 next if *{$glob}{HASH}{'new'};
29 # and any that have AUTOLOAD
30 next if *{$glob}{HASH}{AUTOLOAD};
31 push @stashes, "$stash_name$sym_name", *{$glob}{HASH};
32 } elsif (ref $glob eq 'SCALAR' || *{$glob}{CODE}) {
34 next if !exists $exports->{$sym_name};
35 delete $exports->{$sym_name};
38 *{"$callpkg\::$sym_name"} = \&{"$stash_name$sym_name"};
42 foreach (keys %{$exports||{}}) {
43 next unless /\A(?:rpn|calcrpn|stufftest|swaptwostmts|looprest|scopelessblock|stmtasexpr|stmtsasexpr|loopblock|blockasexpr|swaplabel|labelconst|arrayfullexpr|arraylistexpr|arraytermexpr|arrayarithexpr|arrayexprflags)\z/;
44 $^H{"XS::APItest/$_"} = 1;
45 delete $exports->{$_};
48 my @carp = keys %$exports;
51 (map "\"$_\" is not exported by the $package module\n", sort @carp),
52 "Can't continue after import errors");
57 use vars '$WARNINGS_ON_BOOTSTRAP';
58 use vars map "\$${_}_called_PP", qw(BEGIN UNITCHECK CHECK INIT END);
61 # This is arguably a hack, but it disposes of the UNITCHECK block without
62 # needing to preprocess the source code
64 eval 'sub UNITCHECK (&) {}; 1' or die $@;
68 # Do these here to verify that XS code and Perl code get called at the same
74 $UNITCHECK_called_PP++;
77 # Need $W false by default, as some tests run under -w, and under -w we
78 # can get warnings about "Too late to run CHECK" block (and INIT block)
91 if ($WARNINGS_ON_BOOTSTRAP) {
94 # More CHECK and INIT blocks that could warn:
99 # This XS function needs the lvalue attr applied.
100 eval 'use attributes __PACKAGE__, \\&lv_temp_object, "lvalue"; 1' or die;
107 XS::APItest - Test the perl C API
114 use XS::APItest qw(rpn calcrpn);
115 $triangle = rpn($n $n 1 + * 2 /);
116 calcrpn $triangle { $n $n 1 + * 2 / }
120 This module tests the perl C API. Also exposes various bit of the perl
121 internals for the use of core test scripts.
125 This module can be used to check that the perl C API is behaving
126 correctly. This module provides test functions and an associated
127 test script that verifies the output.
129 This module is not meant to be installed.
133 Exports all the test functions:
137 =item B<print_double>
139 Test that a double-precision floating point number is formatted
140 correctly by C<printf>.
142 print_double( $val );
144 Output is sent to STDOUT.
146 =item B<print_long_double>
148 Test that a C<long double> is formatted correctly by
149 C<printf>. Takes no arguments - the test value is hard-wired
150 into the function (as "7").
154 Output is sent to STDOUT.
156 =item B<have_long_double>
158 Determine whether a C<long double> is supported by Perl. This should
159 be used to determine whether to test C<print_long_double>.
161 print_long_double() if have_long_double;
165 Test that an C<NV> is formatted correctly by
170 Output is sent to STDOUT.
174 Test that an C<IV> is formatted correctly by
179 Output is sent to STDOUT.
183 Test that an C<UV> is formatted correctly by
188 Output is sent to STDOUT.
192 Test that an C<int> is formatted correctly by
197 Output is sent to STDOUT.
201 Test that an C<long> is formatted correctly by
206 Output is sent to STDOUT.
210 Test that a single-precision floating point number is formatted
211 correctly by C<printf>.
215 Output is sent to STDOUT.
219 Installs a source filter that substitutes "e" for "o" (witheut regard fer
220 what it might be medifying).
222 =item B<call_sv>, B<call_pv>, B<call_method>
224 These exercise the C calls of the same names. Everything after the flags
225 arg is passed as the the args to the called function. They return whatever
226 the C function itself pushed onto the stack, plus the return value from
227 the function; for example
229 call_sv( sub { @_, 'c' }, G_ARRAY, 'a', 'b'); # returns 'a', 'b', 'c', 3
230 call_sv( sub { @_ }, G_SCALAR, 'a', 'b'); # returns 'b', 1
234 Evaluates the passed SV. Result handling is done the same as for
239 Exercises the C function of the same name in scalar context. Returns the
240 same SV that the C function returns.
244 Exercises the C function of the same name. Returns nothing.
250 These are not supplied by default, but must be explicitly imported.
251 They are lexically scoped.
255 =item rpn(EXPRESSION)
257 This construct is a Perl expression. I<EXPRESSION> must be an RPN
258 arithmetic expression, as described below. The RPN expression is
259 evaluated, and its value is returned as the value of the Perl expression.
261 =item calcrpn VARIABLE { EXPRESSION }
263 This construct is a complete Perl statement. (No semicolon should
264 follow the closing brace.) I<VARIABLE> must be a Perl scalar C<my>
265 variable, and I<EXPRESSION> must be an RPN arithmetic expression as
266 described below. The RPN expression is evaluated, and its value is
267 assigned to the variable.
271 =head2 RPN expression syntax
273 Tokens of an RPN expression may be separated by whitespace, but such
274 separation is usually not required. It is required only where unseparated
275 tokens would look like a longer token. For example, C<12 34 +> can be
276 written as C<12 34+>, but not as C<1234 +>.
278 An RPN expression may be any of:
284 A sequence of digits is an unsigned decimal literal number.
288 An alphanumeric name preceded by dollar sign refers to a Perl scalar
289 variable. Only variables declared with C<my> or C<state> are supported.
290 If the variable's value is not a native integer, it will be converted
291 to an integer, by Perl's usual mechanisms, at the time it is evaluated.
295 Sum of I<A> and I<B>.
299 Difference of I<A> and I<B>, the result of subtracting I<B> from I<A>.
303 Product of I<A> and I<B>.
307 Quotient when I<A> is divided by I<B>, rounded towards zero.
308 Division by zero generates an exception.
312 Remainder when I<A> is divided by I<B> with the quotient rounded towards zero.
313 Division by zero generates an exception.
317 Because the arithmetic operators all have fixed arity and are postfixed,
318 there is no need for operator precedence, nor for a grouping operator
319 to override precedence. This is half of the point of RPN.
321 An RPN expression can also be interpreted in another way, as a sequence
322 of operations on a stack, one operation per token. A literal or variable
323 token pushes a value onto the stack. A binary operator pulls two items
324 off the stack, performs a calculation with them, and pushes the result
325 back onto the stack. The stack starts out empty, and at the end of the
326 expression there must be exactly one value left on the stack.
330 L<XS::Typemap>, L<perlapi>.
334 Tim Jenness, E<lt>t.jenness@jach.hawaii.eduE<gt>,
335 Christian Soeller, E<lt>csoelle@mph.auckland.ac.nzE<gt>,
336 Hugo van der Sanden E<lt>hv@crypt.compulink.co.ukE<gt>,
337 Andrew Main (Zefram) <zefram@fysh.org>
339 =head1 COPYRIGHT AND LICENSE
341 Copyright (C) 2002,2004 Tim Jenness, Christian Soeller, Hugo van der Sanden.
344 Copyright (C) 2009 Andrew Main (Zefram) <zefram@fysh.org>
346 This library is free software; you can redistribute it and/or modify
347 it under the same terms as Perl itself.