Acme-Ref
view release on metacpan or search on metacpan
63646566676869707172737475767778798081828384858687888990919293949596979899100101102/* 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
;
}
"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
) {
129130131132133134135136137138139140141142143144145146147148149150151152153foreach
$badmacro
(
keys
%badmacros
) {
if
(
$c
=~ /\b
$badmacro
\b/m) {
$changes
+= (
$c
=~ s/\b
$badmacro
\b/
$badmacros
{
$badmacro
}/gm);
"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
) {
"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 )