This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix h2xs enum handling with C++ comments
authorNiko Tyni <ntyni@debian.org>
Sun, 19 Oct 2008 20:21:30 +0000 (23:21 +0300)
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Mon, 19 Jan 2009 14:00:51 +0000 (15:00 +0100)
Contrary to the comment in the code, h2xs mishandles enums that
contain C++ style comments.

An example of a failing header:
enum {
    A = -1, // negative one
            // with more comments
    B = -2, // negative two
    C = -3 // negative two
};

which generates exported constants for 'A' and 'negative'.

The patch is slightly modified from the one by Daniel Burr in
http://bugs.debian.org/320286

utils/h2xs.PL

index c774d62..4bb7897 100644 (file)
@@ -901,6 +901,7 @@ if( @path_h ){
 
         # Remove C and C++ comments
         $src =~ s#/\*[^*]*\*+([^/*][^*]*\*+)*/|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#$2#gs;
+        $src =~ s#//.*$##gm;
 
        while ($src =~ /\benum\s*([\w_]*)\s*\{\s([^}]+)\}/gsc) {
            my ($enum_name, $enum_body) = ($1, $2);