2 ################################################################################
4 # apicheck.pl -- generate C source for automated API check
6 ################################################################################
10 # $Date: 2010/03/07 13:15:43 +0100 $
12 ################################################################################
14 # Version 3.x, Copyright (C) 2004-2010, Marcus Holland-Moritz.
15 # Version 2.x, Copyright (C) 2001, Paul Marquess.
16 # Version 1.x, Copyright (C) 1999, Kenneth Albanowski.
18 # This program is free software; you can redistribute it and/or
19 # modify it under the same terms as Perl itself.
21 ################################################################################
24 require 'parts/ppptools.pl';
28 open OUT, ">$file" or die "$file: $!\n";
34 my @f = parse_embed(qw( parts/embed.fnc parts/apidoc.fnc parts/ppport.fnc ));
36 my %todo = %{&parse_todo};
89 ORIGMARK => ['dORIGMARK;'],
90 POPpx => ['STRLEN n_a;'],
91 POPpbytex => ['STRLEN n_a;'],
100 UNDERBAR => ['dUNDERBAR;'],
101 XCPT_TRY_START => ['dXCPT;'],
102 XCPT_TRY_END => ['dXCPT;'],
103 XCPT_CATCH => ['dXCPT;'],
104 XCPT_RETHROW => ['dXCPT;'],
108 map { ($_ => 1) } qw(
123 * !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
124 * This file is built by $0.
125 * Any changes made here will be lost!
134 #ifdef DPPP_APICHECK_NO_PPPORT_H
136 /* This is just to avoid too many baseline failures with perls < 5.6.0 */
139 # define dTHX extern int Perl___notused
144 #define NEED_PL_signals
145 #define NEED_PL_parser
147 #define NEED_grok_bin
148 #define NEED_grok_hex
149 #define NEED_grok_number
150 #define NEED_grok_numeric_radix
151 #define NEED_grok_oct
152 #define NEED_load_module
153 #define NEED_my_snprintf
154 #define NEED_my_sprintf
155 #define NEED_my_strlcat
156 #define NEED_my_strlcpy
157 #define NEED_newCONSTSUB
158 #define NEED_newRV_noinc
159 #define NEED_newSV_type
160 #define NEED_newSVpvn_share
161 #define NEED_pv_display
162 #define NEED_pv_escape
163 #define NEED_pv_pretty
164 #define NEED_sv_2pv_flags
165 #define NEED_sv_2pvbyte
166 #define NEED_sv_catpvf_mg
167 #define NEED_sv_catpvf_mg_nocontext
168 #define NEED_sv_pvn_force_flags
169 #define NEED_sv_setpvf_mg
170 #define NEED_sv_setpvf_mg_nocontext
171 #define NEED_vload_module
172 #define NEED_vnewSVpvf
174 #define NEED_newSVpvn_flags
181 static char *VARarg2;
182 static double VARarg3;
187 my %want = map { ($_ => 0) } @ARGV;
188 @f = grep { exists $want{$_->{name}} } @f;
189 for (@f) { $want{$_->{name}}++ }
191 die "nothing found for '$_'\n" unless $want{$_};
197 $ignore{$f->{name}} and next;
198 $f->{flags}{A} or next; # only public API members
200 $ignore{$f->{name}} = 1; # ignore duplicates
202 my $Perl_ = $f->{flags}{p} ? 'Perl_' : '';
211 for $ca (@{$f->{args}}) {
215 push @arg, qw(VARarg1 VARarg2 VARarg3);
218 my($n, $p, $d) = $a =~ /^ (\w+(?:\s+\w+)*)\s* # type name => $n
219 (\**) # pointer => $p
220 (?:\s*const\s*)? # const
221 ((?:\[[^\]]*\])*) # dimension => $d
223 or die "$0 - cannot parse argument: [$a]\n";
224 if (exists $amap{$n}) {
225 push @arg, $amap{$n};
228 $n = $tmap{$n} || $n;
229 if ($n eq 'const char' and $p eq '*' and !$f->{flags}{f}) {
233 my $v = 'arg' . $i++;
235 $stack .= " static $n $p$v$d;\n";
239 unless ($f->{flags}{n} || $f->{flags}{'m'}) {
240 $stack = " dTHX;\n$stack";
241 $aTHX = @arg ? 'aTHX_ ' : 'aTHX';
244 if ($stack{$f->{name}}) {
246 for (@{$stack{$f->{name}}}) {
252 my $args = join ', ', @arg;
253 my $rvt = $f->{ret} || 'void';
256 $ret = $castvoid{$f->{name}} ? '(void) ' : '';
259 $stack .= " $rvt rval;\n";
260 $ret = $ignorerv{$f->{name}} ? '(void) ' : "rval = ";
262 my $aTHX_args = "$aTHX$args";
264 if (!$f->{flags}{'m'} or $f->{flags}{'b'} or @arg > 0) {
266 $aTHX_args = "($aTHX_args)";
270 /******************************************************************************
274 ******************************************************************************/
278 if ($todo{$f->{name}}) {
279 my($ver,$sub) = $todo{$f->{name}} =~ /^5\.(\d{3})(\d{3})$/ or die;
283 if ($ver < 6 && $sub > 0) {
284 $sub =~ s/0$// or die;
286 print OUT "#if PERL_VERSION > $ver || (PERL_VERSION == $ver && PERL_SUBVERSION >= $sub) /* TODO */\n";
290 ? "$Perl_$f->{name}$aTHX_args"
293 $f->{cond} and print OUT "#if $f->{cond}\n";
296 void _DPPP_test_$f->{name} (void)
310 $ret$Perl_$f->{name}$aTHX_args;
316 $f->{cond} and print OUT "#endif\n";
317 $todo{$f->{name}} and print OUT "#endif\n";