You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ja...@apache.org on 2001/06/14 07:33:29 UTC

cvs commit: xml-xerces/perl postSource.pl

jasons      01/06/13 22:33:29

  Modified:    perl     postSource.pl
  Log:
  	* postSource.pl (Repository):
  	Changed the temporary file code to use $$
  	Added fix for PerlExceptionHandler::setExceptionHandler
  	All new() methods for InputSource's now catch exceptions
  	Need to do two-phase parse to wipe out first occurrence of
  	   SWIG_TypeCheck()
  
  Revision  Changes    Path
  1.4       +147 -28   xml-xerces/perl/postSource.pl
  
  Index: postSource.pl
  ===================================================================
  RCS file: /home/cvs/xml-xerces/perl/postSource.pl,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- postSource.pl	2001/04/16 18:02:28	1.3
  +++ postSource.pl	2001/06/14 05:33:29	1.4
  @@ -1,7 +1,5 @@
   #!/usr/bin/perl
   
  -my($progname) = $0 =~ m"\/([^/]*)";
  -
   %operator_symbols = (
     'addition'                  => '+',
     'addition_assignment'       => '+=',
  @@ -36,41 +34,162 @@
     'decrement'                 => '--'  
   );
   
  +my $file = shift @ARGV;
  +my $PRINTED = 0;
  +my $temp_file = "$file.$$";
  +
  +open(FILE, $file)
  +  or die "Couldn't open $file for reading";
  +open(TEMP, ">$temp_file")
  +  or die "Couldn't open $temp_file for writing";
  +
  +while(<FILE>) {
  +  # SWIG only knows about the non PL_ version of these variables.
  +  s/\bsv_undef\b/PL_sv_undef/g if /\bsv_undef\b/;
  +  s/\bsv_yes\b/PL_sv_yes/g if /\bsv_yes\b/;
  +  s/\bna\b/PL_na/g if /\bna\b/;
   
  -my $num = 0;
  -++$num while -e "$progname.$num.tmp";
  +  for $key (keys %operator_symbols) {
  +    s/\b$key\b/ operator$operator_symbols{$key} /
  +  }
   
  -for $file (@ARGV) {
  -  next unless open FILE, $file;
  -  open TEMP, ">$progname.$num.tmp";
  -
  -  while(<FILE>) {
  -    # SWIG only knows about the non PL_ version of these variables.
  -    s/\bsv_undef\b/PL_sv_undef/g if /\bsv_undef\b/;
  -    s/\bsv_yes\b/PL_sv_yes/g if /\bsv_yes\b/;
  -    s/\bna\b/PL_na/g if /\bna\b/;
  +  # force SWIG 1.1p5 to make the namespace XML::Xerces
  +  s/swig_setiv\("(?!XML::Xercesc::)/swig_setiv("XML::Xercesc::/;
  +  s/SWIG_GetPtr(.*?)"(?!XML::Xerces::)(\w+)"/SWIG_GetPtr$1"XML::Xerces::$2"/;
  +  s/SWIG_RegisterMapping\("(?!XML::Xerces::)(\w+)","(?!XML::Xerces::)(\w+)",Swig/SWIG_RegisterMapping\("XML::Xerces::$1","XML::Xerces::$2",Swig/; 
  +  s/sv_setref_pv\(ST\(argvi\+\+\),"(?!XML::Xerces::)/sv_setref_pv(ST(argvi++),"XML::Xerces::/;
  +  s/boot_Xerces/boot_XML__Xerces/g;
  +
  +  # force SWIG to handle overloaded functions
  +  s/(result\s+=.*)__overload__\d+/$1/;
  +
  +  # fix the PerlExceptionHandler::setExceptionHandler method
  +  if (/XS\(_wrap_PerlExceptionHandler_setExceptionHandler/) {
  +#  if (0) {
  +    print TEMP;
   
  -    for $key (keys %operator_symbols) {
  -      s/\b$key\b/ operator$operator_symbols{$key} /
  +    skip_to_closing_brace(\*FILE);
  +    print TEMP <<"EOT";
  +    char *arg0 ;
  +    SV *arg1 ;
  +    SV *result;
  +    int argvi = 0;
  +    dXSARGS;
  +    
  +    if ((items < 2) || (items > 2)) 
  +    croak("Usage: PerlExceptionHandler_setExceptionHandler(class,function);");
  +    {
  +        arg1 = ST(1);
       }
  -
  -    # force SWIG 1.1p5 to make the namespace XML::Xerces
  -    s/swig_setiv\("(?!XML::Xercesc::)/swig_setiv("XML::Xercesc::/;
  -    s/SWIG_GetPtr(.*?)"(?!XML::Xerces::)(\w+)"/SWIG_GetPtr$1"XML::Xerces::$2"/;
  -    s/SWIG_RegisterMapping\("(?!XML::Xerces::)(\w+)","(?!XML::Xerces::)(\w+)",Swig/SWIG_RegisterMapping\("XML::Xerces::$1","XML::Xerces::$2",Swig/; 
  -    s/sv_setref_pv\(ST\(argvi\+\+\),"(?!XML::Xerces::)/sv_setref_pv(ST(argvi++),"XML::Xerces::/;
  -    s/boot_Xerces/boot_XML__Xerces/g;
  +    ST(argvi) = PerlExceptionHandler::setExceptionHandler(arg1);
  +    argvi++;
  +    XSRETURN(argvi);
  +}
  +EOT
  +    next;
  +  }
   
  +  # Creating InputSource's can raise XMLExceptions
  +  if (/new .*InputSource\(/) {
  +    print TEMP <<"EOT";
  +    try {
  +$_
  +    } 
  +    catch (const XMLException& e)
  +        {
  +            PerlExceptionHandler::catchException(e);
  +        }
  +    catch (...)
  +        {
  +            cerr << "Handling Unknown exception" << endl;
  +            XMLPlatformUtils::Terminate();
  +            exit(4);
  +        }
  +EOT
  +    next;
  +  }
   
  -    # force SWIG to handle overloaded functions
  -    s/(result\s+=.*)__overload__\d+/$1/;
  +  # we need to move the new SWIG_TypeCheck() *after* the perl
  +  # header includes, because we now use sv_derived_from()
  +  if (!$PRINTED && /\#ifdef\s+PERL_OBJECT/) {
  +    $PRINTED = 1;
  +    print TEMP <<'EOT';
  +/* Check the typename */
  +SWIGRUNTIME(swig_type_info *) 
  +SWIG_TypeCheck(SV *sv, swig_type_info *ty)
  +{
  +  swig_type_info *s;
  +  if (!ty) return 0;        /* Void pointer */
  +  s = ty->next;             /* First element always just a name */
  +  while (s) {
  +    if (sv_derived_from(sv,s->name)) {
  +      if (s == ty->next) return s;
  +      /* Move s to the top of the linked list */
  +      s->prev->next = s->next;
  +      if (s->next) {
  +	s->next->prev = s->prev;
  +      }
  +      /* Insert s as second element in the list */
  +      s->next = ty->next;
  +      if (ty->next) ty->next->prev = s;
  +      ty->next = s;
  +      return s;
  +    }
  +    s = s->next;
  +  }
  +  return 0;
  +}
   
  -    print TEMP;
  +EOT
  +  }
  +  # now we substitute the line in SWIG_ConvertPTR()that 
  +  # calls SWIG_TypeCheck()
  +  if(/tc = SWIG_TypeCheck\(_c,_t\)/) {
  +    print TEMP<<"EOT";
  +    tc = SWIG_TypeCheck(sv,_t);
  +EOT
  +    next;
     }
   
  -  close FILE;
  -  close TEMP;
  +  print TEMP;
  +}
   
  -  rename "$progname.$num.tmp", $file;
  +close FILE;
  +close TEMP;
  +
  +open(TEMP, "$temp_file")
  +  or die "Couldn't open $temp_file for reading";
  +open(FILE, ">$file")
  +  or die "Couldn't open $file for writing";
  +
  +# put Perl in paragraph mode so that we read in entire blocks
  +# separated by blank lines
  +$/ = '';
  +$PRINTED = 0;
  +while(<TEMP>) {
  +  # we cut out the first occurrence of the SWIG_TypeCheck
  +  # and print everything else
  +  if (!$PRINTED && /SWIG_TypeCheck\(char \*c, swig_type_info \*ty\)/) {
  +    $PRINTED = 1;
  +    next;
  +  }
  +  print FILE;
   }
  +close FILE;
  +close TEMP;
   
  +unlink $temp_file;
  +
  +
  +sub skip_to_closing_brace {
  +  my $fh = shift;
  +  my $braces = 1;
  +  while ($braces && ! eof($fh)) {
  +    $_ = <$fh>;
  +    $braces-- if /\}/;
  +    $braces++ if /\{/;
  +  }
  +  if ($braces) {
  +    print STDERR "skip_closing_brace exited with positive brace count";
  +  }
  +}
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org