chiark / gitweb /
Add __oop-read-copy.c
[inn-innduct.git] / include / ppport.h
1
2 #ifndef PPPORT_H
3 #define PPPORT_H 1
4
5 /* Perl/Pollution/Portability Version 1.0003 */
6
7 /* Copyright (C) 1999, Kenneth Albanowski. This code may be used and
8    distributed under the same license as any version of Perl. */
9    
10 /* For the latest version of this code, please contact the author at
11    <kjahds@kjahds.com>, or check with the Perl maintainers. */
12    
13 /* If you needed to customize this file for your project, please mention
14    your changes. */
15
16 /*
17    Modified for Perl 5.6.0 by Russ Allbery (use PERL_VERSION instead of
18    PERL_PATCHLEVEL).
19 */
20
21
22 /*
23    In order for a Perl extension module to be as portable as possible
24    across differing versions of Perl itself, certain steps need to be taken.
25    Including this header is the first major one, then using dTHR is all the
26    appropriate places and using a PL_ prefix to refer to global Perl
27    variables is the second.
28 */
29
30
31 /* If you use one of a few functions that were not present in earlier
32    versions of Perl, please add a define before the inclusion of ppport.h
33    for a static include, or use the GLOBAL request in a single module to
34    produce a global definition that can be referenced from the other
35    modules.
36    
37    Function:            Static define:           Extern define:
38    newCONSTSUB()        NEED_newCONSTSUB         NEED_newCONSTSUB_GLOBAL
39
40 */
41  
42
43 /* To verify whether ppport.h is needed for your module, and whether any
44    special defines should be used, ppport.h can be run through Perl to check
45    your source code. Simply say:
46    
47         perl -x ppport.h *.c *.h *.xs foo/perl.c [etc]
48    
49    The result will be a list of patches suggesting changes that should at
50    least be acceptable, if not necessarily the most efficient solution, or a
51    fix for all possible problems. It won't catch where dTHR is needed, and
52    doesn't attempt to account for global macro or function definitions,
53    nested includes, typemaps, etc.
54    
55    In order to test for the need of dTHR, please try your module under a
56    recent version of Perl that has threading compiled-in.
57  
58 */ 
59
60
61 /*
62 #!/usr/bin/perl
63 @ARGV = ("*.xs") if !@ARGV;
64 %badmacros = %funcs = %macros = ();
65 foreach (<DATA>) {
66         $funcs{$1} = 1 if /Provide:\s+(\S+)/;
67         $macros{$1} = 1 if /^#\s*define\s+([a-zA-Z0-9_]+)/;
68         $badmacros{$2}=$1 if /^#\s*define\s+(PL_\S+)\s+(\S+)/;
69 }
70 foreach $filename (map(glob($_),@ARGV)) {
71         unless (open(IN, "<$filename")) {
72                 warn "Unable to read from $file: $!\n";
73                 next;
74         }
75         print "Scanning $filename...\n";
76         $c = ""; while (<IN>) { $c .= $_; } close(IN);
77         $need_include = 0; %add_func = (); $changes = 0;
78         $has_include = ($c =~ /#.*include.*ppport/m);
79
80         foreach $func (keys %funcs) {
81                 if ($c =~ /#.*define.*\bNEED_$func(_GLOBAL)?\b/m) {
82                         if ($c !~ /\b$func\b/m) {
83                                 print "If $func isn't needed, you don't need to request it.\n" if
84                                 $changes += ($c =~ s/^.*#.*define.*\bNEED_$func\b.*\n//m);
85                         } else {
86                                 print "Uses $func\n";
87                                 $need_include = 1;
88                         }
89                 } else {
90                         if ($c =~ /\b$func\b/m) {
91                                 $add_func{$func} =1 ;
92                                 print "Uses $func\n";
93                                 $need_include = 1;
94                         }
95                 }
96         }
97
98         if (not $need_include) {
99                 foreach $macro (keys %macros) {
100                         if ($c =~ /\b$macro\b/m) {
101                                 print "Uses $macro\n";
102                                 $need_include = 1;
103                         }
104                 }
105         }
106
107         foreach $badmacro (keys %badmacros) {
108                 if ($c =~ /\b$badmacro\b/m) {
109                         $changes += ($c =~ s/\b$badmacro\b/$badmacros{$badmacro}/gm);
110                         print "Uses $badmacros{$badmacro} (instead of $badmacro)\n";
111                         $need_include = 1;
112                 }
113         }
114         
115         if (scalar(keys %add_func) or $need_include != $has_include) {
116                 if (!$has_include) {
117                         $inc = join('',map("#define NEED_$_\n", sort keys %add_func)).
118                                "#include \"ppport.h\"\n";
119                         $c = "$inc$c" unless $c =~ s/#.*include.*XSUB.*\n/$&$inc/m;
120                 } elsif (keys %add_func) {
121                         $inc = join('',map("#define NEED_$_\n", sort keys %add_func));
122                         $c = "$inc$c" unless $c =~ s/^.*#.*include.*ppport.*$/$inc$&/m;
123                 }
124                 if (!$need_include) {
125                         print "Doesn't seem to need ppport.h.\n";
126                         $c =~ s/^.*#.*include.*ppport.*\n//m;
127                 }
128                 $changes++;
129         }
130         
131         if ($changes) {
132                 open(OUT,">/tmp/ppport.h.$$");
133                 print OUT $c;
134                 close(OUT);
135                 open(DIFF, "diff -u $filename /tmp/ppport.h.$$|");
136                 while (<DIFF>) { s!/tmp/ppport\.h\.$$!$filename.patched!; print STDOUT; }
137                 close(DIFF);
138                 unlink("/tmp/ppport.h.$$");
139         } else {
140                 print "Looks OK\n";
141         }
142 }
143 __DATA__
144 */
145
146
147 #if !defined(PERL_VERSION) && !defined(PERL_PATCHLEVEL)
148 #       ifndef __PATCHLEVEL_H_INCLUDED__
149 #               include <patchlevel.h>
150 #       endif
151 #endif
152 #ifndef PERL_VERSION
153 #       define PERL_REVISION (5)
154 #       ifdef PERL_PATCHLEVEL
155 #               define PERL_VERSION    PERL_PATCHLEVEL
156 #       else
157 #               define PERL_VERSION    PATCHLEVEL
158 #               define PERL_SUBVERSION SUBVERSION
159 #       endif
160 #endif
161
162 #ifndef ERRSV
163 #       define ERRSV perl_get_sv("@",false)
164 #endif
165
166 #if (PERL_REVISION == 5) && ((PERL_VERSION < 4) || ((PERL_VERSION == 4) && (PERL_SUBVERSION <= 4)))
167 #       define PL_sv_undef      sv_undef
168 #       define PL_sv_yes        sv_yes
169 #       define PL_sv_no         sv_no
170 #       define PL_na            na
171 #       define PL_stdingv       stdingv
172 #       define PL_hints         hints
173 #       define PL_curcop        curcop
174 #       define PL_curstash      curstash
175 #       define PL_copline       copline
176 #endif
177
178 #if (PERL_REVISION == 5) && (PERL_VERSION < 5)
179 #       undef dTHR
180 #       ifdef WIN32
181 #               define dTHR extern int Perl___notused
182 #       else
183 #               define dTHR extern int errno
184 #       endif
185 #endif
186
187 #ifndef boolSV
188 #       define boolSV(b) ((b) ? &PL_sv_yes : &PL_sv_no)
189 #endif
190
191 /* Perl tries to export a bunch of its own functions.  Mutter. */
192 #undef die
193 #undef list
194 #undef warn
195
196 #endif /* !PPPORT_H */