home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2002 April / pcpro0402.iso / essentials / graphics / Gimp / gimp-src-20001226.exe / src / gimp / plug-ins / perl / gppport.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-09-14  |  8.1 KB  |  295 lines

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