Acme-Ref

 view release on metacpan or  search on metacpan

ppport.h  view on Meta::CPAN

63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* To verify whether ppport.h is needed for your module, and whether any
 * special defines should be used, ppport.h can be run through Perl to check
 * your source code. Simply say:
 *
 *      perl -x ppport.h *.c *.h *.xs foo/bar*.c [etc]
 *
 * The result will be a list of patches suggesting changes that should at
 * least be acceptable, if not necessarily the most efficient solution, or a
 * fix for all possible problems. It won't catch where dTHR is needed, and
 * doesn't attempt to account for global macro or function definitions,
 * nested includes, typemaps, etc.
 *
 * In order to test for the need of dTHR, please try your module under a
 * recent version of Perl that has threading compiled-in.
 *
 */
 
 
/*
#!/usr/bin/perl
@ARGV = ("*.xs") if !@ARGV;
%badmacros = %funcs = %macros = (); $replace = 0;
foreach (<DATA>) {
        $funcs{$1} = 1 if /Provide:\s+(\S+)/;
        $macros{$1} = 1 if /^#\s*define\s+([a-zA-Z0-9_]+)/;
        $replace = $1 if /Replace:\s+(\d+)/;
        $badmacros{$2}=$1 if $replace and /^#\s*define\s+([a-zA-Z0-9_]+).*?\s+([a-zA-Z0-9_]+)/;
        $badmacros{$1}=$2 if /Replace (\S+) with (\S+)/;
}
foreach $filename (map(glob($_),@ARGV)) {
        unless (open(IN, "<$filename")) {
                warn "Unable to read from $file: $!\n";
                next;
        }
        print "Scanning $filename...\n";
        $c = ""; while (<IN>) { $c .= $_; } close(IN);
        $need_include = 0; %add_func = (); $changes = 0;
        $has_include = ($c =~ /#.*include.*ppport/m);
 
        foreach $func (keys %funcs) {

ppport.h  view on Meta::CPAN

129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
foreach $badmacro (keys %badmacros) {
        if ($c =~ /\b$badmacro\b/m) {
                $changes += ($c =~ s/\b$badmacro\b/$badmacros{$badmacro}/gm);
                print "Uses $badmacros{$badmacro} (instead of $badmacro)\n";
                $need_include = 1;
        }
}
 
if (scalar(keys %add_func) or $need_include != $has_include) {
        if (!$has_include) {
                $inc = join('',map("#define NEED_$_\n", sort keys %add_func)).
                       "#include \"ppport.h\"\n";
                $c = "$inc$c" unless $c =~ s/#.*include.*XSUB.*\n/$&$inc/m;
        } elsif (keys %add_func) {
                $inc = join('',map("#define NEED_$_\n", sort keys %add_func));
                $c = "$inc$c" unless $c =~ s/^.*#.*include.*ppport.*$/$inc$&/m;
        }
        if (!$need_include) {
                print "Doesn't seem to need ppport.h.\n";
                $c =~ s/^.*#.*include.*ppport.*\n//m;
        }
        $changes++;
}
 
if ($changes) {



( run in 0.438 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )