Skip to content

Commit b544057

Browse files
committed
Move ppport.h into individual distributions
1 parent ebb0efd commit b544057

File tree

3 files changed

+317
-1
lines changed

3 files changed

+317
-1
lines changed

MANIFEST

+1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ MANIFEST
33
Makefile.PL
44
NetAdmin.pm
55
NetAdmin.xs
6+
ppport.h
67
t/netadmin.t

NetAdmin.xs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
# define W2AHELPER(lpw, lpa, nChars) W2AHELPER_LEN(lpw, -1, lpa, nChars)
4646
#endif
4747

48-
#include "../ppport.h"
48+
#include "ppport.h"
4949

5050
#define RETURNRESULT(x) if ((x)){ XST_mYES(0); }\
5151
else { XST_mNO(0); }\

ppport.h

+315
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,315 @@
1+
2+
#ifndef _P_P_PORTABILITY_H_
3+
#define _P_P_PORTABILITY_H_
4+
5+
/* Perl/Pollution/Portability Version 1.0007-gsar-v3 */
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 retreive the Devel::PPPort
11+
module from CPAN, contact the author at <[email protected]>, or check
12+
with the Perl maintainers. */
13+
14+
/* If you needed to customize this file for your project, please mention
15+
your changes, and visible alter the version number. */
16+
17+
/* Additional macros added for 5.6.0 compatibility. --GSAR */
18+
19+
/*
20+
In order for a Perl extension module to be as portable as possible
21+
across differing versions of Perl itself, certain steps need to be taken.
22+
Including this header is the first major one, then using dTHR is all the
23+
appropriate places and using a PL_ prefix to refer to global Perl
24+
variables is the second.
25+
*/
26+
27+
28+
/* If you use one of a few functions that were not present in earlier
29+
versions of Perl, please add a define before the inclusion of ppport.h
30+
for a static include, or use the GLOBAL request in a single module to
31+
produce a global definition that can be referenced from the other
32+
modules.
33+
34+
Function: Static define: Extern define:
35+
newCONSTSUB() NEED_newCONSTSUB NEED_newCONSTSUB_GLOBAL
36+
37+
*/
38+
39+
40+
/* To verify whether ppport.h is needed for your module, and whether any
41+
special defines should be used, ppport.h can be run through Perl to check
42+
your source code. Simply say:
43+
44+
perl -x ppport.h *.c *.h *.xs foo/*.c [etc]
45+
46+
The result will be a list of patches suggesting changes that should at
47+
least be acceptable, if not necessarily the most efficient solution, or a
48+
fix for all possible problems. It won't catch where dTHR is needed, and
49+
doesn't attempt to account for global macro or function definitions,
50+
nested includes, typemaps, etc.
51+
52+
In order to test for the need of dTHR, please try your module under a
53+
recent version of Perl that has threading compiled-in.
54+
55+
*/
56+
57+
58+
/*
59+
#!/usr/bin/perl
60+
@ARGV = ("*.xs") if !@ARGV;
61+
%badmacros = %funcs = %macros = (); $replace = 0;
62+
foreach (<DATA>) {
63+
$funcs{$1} = 1 if /Provide:\s+(\S+)/;
64+
$macros{$1} = 1 if /^#\s*define\s+([a-zA-Z0-9_]+)/;
65+
$replace = $1 if /Replace:\s+(\d+)/;
66+
$badmacros{$2}=$1 if $replace and /^#\s*define\s+([a-zA-Z0-9_]+).*?\s+([a-zA-Z0-9_]+)/;
67+
$badmacros{$1}=$2 if /Replace (\S+) with (\S+)/;
68+
}
69+
foreach $filename (map(glob($_),@ARGV)) {
70+
unless (open(IN, "<$filename")) {
71+
warn "Unable to read from $file: $!\n";
72+
next;
73+
}
74+
print "Scanning $filename...\n";
75+
$c = ""; while (<IN>) { $c .= $_; } close(IN);
76+
$need_include = 0; %add_func = (); $changes = 0;
77+
$has_include = ($c =~ /#.*include.*ppport/m);
78+
79+
foreach $func (keys %funcs) {
80+
if ($c =~ /#.*define.*\bNEED_$func(_GLOBAL)?\b/m) {
81+
if ($c !~ /\b$func\b/m) {
82+
print "If $func isn't needed, you don't need to request it.\n" if
83+
$changes += ($c =~ s/^.*#.*define.*\bNEED_$func\b.*\n//m);
84+
} else {
85+
print "Uses $func\n";
86+
$need_include = 1;
87+
}
88+
} else {
89+
if ($c =~ /\b$func\b/m) {
90+
$add_func{$func} =1 ;
91+
print "Uses $func\n";
92+
$need_include = 1;
93+
}
94+
}
95+
}
96+
97+
if (not $need_include) {
98+
foreach $macro (keys %macros) {
99+
if ($c =~ /\b$macro\b/m) {
100+
print "Uses $macro\n";
101+
$need_include = 1;
102+
}
103+
}
104+
}
105+
106+
foreach $badmacro (keys %badmacros) {
107+
if ($c =~ /\b$badmacro\b/m) {
108+
$changes += ($c =~ s/\b$badmacro\b/$badmacros{$badmacro}/gm);
109+
print "Uses $badmacros{$badmacro} (instead of $badmacro)\n";
110+
$need_include = 1;
111+
}
112+
}
113+
114+
if (scalar(keys %add_func) or $need_include != $has_include) {
115+
if (!$has_include) {
116+
$inc = join('',map("#define NEED_$_\n", sort keys %add_func)).
117+
"#include \"ppport.h\"\n";
118+
$c = "$inc$c" unless $c =~ s/#.*include.*XSUB.*\n/$&$inc/m;
119+
} elsif (keys %add_func) {
120+
$inc = join('',map("#define NEED_$_\n", sort keys %add_func));
121+
$c = "$inc$c" unless $c =~ s/^.*#.*include.*ppport.*$/$inc$&/m;
122+
}
123+
if (!$need_include) {
124+
print "Doesn't seem to need ppport.h.\n";
125+
$c =~ s/^.*#.*include.*ppport.*\n//m;
126+
}
127+
$changes++;
128+
}
129+
130+
if ($changes) {
131+
open(OUT,">/tmp/ppport.h.$$");
132+
print OUT $c;
133+
close(OUT);
134+
open(DIFF, "diff -u $filename /tmp/ppport.h.$$|");
135+
while (<DIFF>) { s!/tmp/ppport\.h\.$$!$filename.patched!; print STDOUT; }
136+
close(DIFF);
137+
unlink("/tmp/ppport.h.$$");
138+
} else {
139+
print "Looks OK\n";
140+
}
141+
}
142+
__DATA__
143+
*/
144+
145+
#ifndef PERL_REVISION
146+
# ifndef __PATCHLEVEL_H_INCLUDED__
147+
# include "patchlevel.h"
148+
# endif
149+
# ifndef PERL_REVISION
150+
# define PERL_REVISION (5)
151+
/* Replace: 1 */
152+
# define PERL_VERSION PATCHLEVEL
153+
# define PERL_SUBVERSION SUBVERSION
154+
/* Replace PERL_PATCHLEVEL with PERL_VERSION */
155+
/* Replace: 0 */
156+
# endif
157+
#endif
158+
159+
#define PERL_BCDVERSION ((PERL_REVISION * 0x1000000L) + (PERL_VERSION * 0x1000L) + PERL_SUBVERSION)
160+
161+
#ifndef ERRSV
162+
# define ERRSV perl_get_sv("@",FALSE)
163+
#endif
164+
165+
#if (PERL_VERSION < 4) || ((PERL_VERSION == 4) && (PERL_SUBVERSION <= 5))
166+
/* Replace: 1 */
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+
# define PL_Sv Sv
177+
# define PL_dowarn dowarn
178+
/* Replace: 0 */
179+
#endif
180+
181+
#ifndef dNOOP
182+
# ifdef WIN32
183+
# define dNOOP extern int Perl___notused
184+
# else
185+
# define dNOOP extern int errno
186+
# endif
187+
#endif
188+
189+
#ifndef dTHR
190+
# define dTHR dNOOP
191+
#endif
192+
193+
#ifndef dTHX
194+
# define dTHX dNOOP
195+
# define dTHXa(x) dNOOP
196+
# define dTHXoa(x) dNOOP
197+
#endif
198+
199+
#ifndef pTHX
200+
# define pTHX void
201+
# define pTHX_
202+
# define aTHX
203+
# define aTHX_
204+
#endif
205+
206+
#ifndef USING_WIDE
207+
# define USING_WIDE() 0
208+
#endif
209+
210+
#ifndef A2WHELPER
211+
# define A2WHELPER(a,b,c) ((void)0)
212+
# define W2AHELPER(a,b,c) ((void)0)
213+
#endif
214+
215+
#ifndef A2WHELPER_LEN
216+
# define A2WHELPER_LEN(a,b,c,d) (0)
217+
# define W2AHELPER_LEN(a,b,c,d) (0)
218+
#endif
219+
220+
#ifndef boolSV
221+
# define boolSV(b) ((b) ? &PL_sv_yes : &PL_sv_no)
222+
#endif
223+
224+
#ifndef gv_stashpvn
225+
# define gv_stashpvn(str,len,flags) gv_stashpv(str,flags)
226+
#endif
227+
228+
#ifndef newSVpvn
229+
# define newSVpvn(data,len) ((len) ? newSVpv ((data), (len)) : newSVpv ("", 0))
230+
#endif
231+
232+
#ifndef newRV_inc
233+
/* Replace: 1 */
234+
# define newRV_inc(sv) newRV(sv)
235+
/* Replace: 0 */
236+
#endif
237+
238+
#ifndef newRV_noinc
239+
# ifdef __GNUC__
240+
# define newRV_noinc(sv) \
241+
({ \
242+
SV *nsv = (SV*)newRV(sv); \
243+
SvREFCNT_dec(sv); \
244+
nsv; \
245+
})
246+
# else
247+
# if defined(CRIPPLED_CC) || defined(USE_THREADS)
248+
static SV * newRV_noinc (SV * sv)
249+
{
250+
SV *nsv = (SV*)newRV(sv);
251+
SvREFCNT_dec(sv);
252+
return nsv;
253+
}
254+
# else
255+
# define newRV_noinc(sv) \
256+
((PL_Sv=(SV*)newRV(sv), SvREFCNT_dec(sv), (SV*)PL_Sv)
257+
# endif
258+
# endif
259+
#endif
260+
261+
/* Provide: newCONSTSUB */
262+
263+
/* newCONSTSUB from IO.xs is in the core starting with 5.004_63 */
264+
#if (PERL_VERSION < 4) || ((PERL_VERSION == 4) && (PERL_SUBVERSION < 63))
265+
266+
#if defined(NEED_newCONSTSUB)
267+
static
268+
#else
269+
extern void newCONSTSUB _((HV * stash, char * name, SV *sv));
270+
#endif
271+
272+
#if defined(NEED_newCONSTSUB) || defined(NEED_newCONSTSUB_GLOBAL)
273+
void
274+
newCONSTSUB( HV *stash, char *name, SV *sv )
275+
{
276+
U32 oldhints = PL_hints;
277+
HV *old_cop_stash = PL_curcop->cop_stash;
278+
HV *old_curstash = PL_curstash;
279+
line_t oldline = PL_curcop->cop_line;
280+
PL_curcop->cop_line = PL_copline;
281+
282+
PL_hints &= ~HINT_BLOCK_SCOPE;
283+
if (stash)
284+
PL_curstash = PL_curcop->cop_stash = stash;
285+
286+
newSUB(
287+
288+
#if (PERL_VERSION < 3) || ((PERL_VERSION == 3) && (PERL_SUBVERSION < 22))
289+
/* before 5.003_22 */
290+
start_subparse(),
291+
#else
292+
# if (PERL_VERSION == 3) && (PERL_SUBVERSION == 22)
293+
/* 5.003_22 */
294+
start_subparse(0),
295+
# else
296+
/* 5.003_23 onwards */
297+
start_subparse(FALSE, 0),
298+
# endif
299+
#endif
300+
301+
newSVOP(OP_CONST, 0, newSVpv(name,0)),
302+
newSVOP(OP_CONST, 0, &PL_sv_no), /* SvPV(&PL_sv_no) == "" -- GMB */
303+
newSTATEOP(0, Nullch, newSVOP(OP_CONST, 0, sv))
304+
);
305+
306+
PL_hints = oldhints;
307+
PL_curcop->cop_stash = old_cop_stash;
308+
PL_curstash = old_curstash;
309+
PL_curcop->cop_line = oldline;
310+
}
311+
#endif
312+
313+
#endif /* newCONSTSUB */
314+
315+
#endif /* _P_P_PORTABILITY_H_ */

0 commit comments

Comments
 (0)