[svn:parrot] r38777 - trunk/config/gen

petdance at svn.parrot.org petdance at svn.parrot.org
Thu May 14 19:43:11 UTC 2009


Author: petdance
Date: Thu May 14 19:43:11 2009
New Revision: 38777
URL: https://trac.parrot.org/parrot/changeset/38777

Log:
Added error checks on close().  Made a standard read-only coda for the generated files.  Turned off unnecessary interpolation.

Modified:
   trunk/config/gen/core_pmcs.pm

Modified: trunk/config/gen/core_pmcs.pm
==============================================================================
--- trunk/config/gen/core_pmcs.pm	Thu May 14 18:39:04 2009	(r38776)
+++ trunk/config/gen/core_pmcs.pm	Thu May 14 19:43:11 2009	(r38777)
@@ -1,4 +1,4 @@
-# Copyright (C) 2001-2007, Parrot Foundation.
+# Copyright (C) 2001-2009, Parrot Foundation.
 # $Id$
 
 =head1 NAME
@@ -42,11 +42,11 @@
 sub generate_h {
     my ( $self, $conf ) = @_;
 
-    my $file = "include/parrot/core_pmcs.h";
+    my $file = 'include/parrot/core_pmcs.h';
     $conf->append_configure_log($file);
-    open( my $OUT, ">", "$file.tmp" );
+    open( my $OUT, '>', "$file.tmp" );
 
-    print {$OUT} <<"END_H";
+    print {$OUT} <<'END_H';
 /*
  * DO NOT EDIT THIS FILE
  *
@@ -56,33 +56,27 @@
 #ifndef PARROT_CORE_PMCS_H_GUARD
 #define PARROT_CORE_PMCS_H_GUARD
 
-/* &gen_from_enum(pmctypes.pasm) subst(s/enum_class_(\\w+)/\$1/e) */
+/* &gen_from_enum(pmctypes.pasm) subst(s/enum_class_(\w+)/$1/e) */
 enum {
 END_H
 
-    my @pmcs = split( / /, $conf->data->get('pmc_names') );
+    my @pmcs = split( qr/ /, $conf->data->get('pmc_names') );
     my $i = 0;
     foreach (@pmcs) {
         print {$OUT} "    enum_class_$_,\t/*  $i */\n";
         $i++;
     }
-    print {$OUT} <<"END_H";
+    print {$OUT} <<'END_H';
     enum_class_core_max
 };
 
 /* &end_gen */
 
 #endif /* PARROT_CORE_PMCS_H_GUARD */
-
-/*
- * Local variables:
- *   c-file-style: "parrot"
- * End:
- * vim: expandtab shiftwidth=4:
- */
 END_H
+    print {$OUT} coda();
 
-    close $OUT;
+    close $OUT or die "Can't close file: $!";;
 
     move_if_diff( "$file.tmp", $file );
 
@@ -93,12 +87,12 @@
     my ( $self, $conf ) = @_;
 
     my $file = "src/core_pmcs.c";
-    my @pmcs = split( / /, $conf->data->get('pmc_names') );
+    my @pmcs = split( qr/ /, $conf->data->get('pmc_names') );
 
     $conf->append_configure_log($file);
-    open( my $OUT, ">", "$file.tmp" );
+    open( my $OUT, '>', "$file.tmp" );
 
-    print {$OUT} <<"END_C";
+    print {$OUT} <<'END_C';
 /*
  * DO NOT EDIT THIS FILE
  *
@@ -114,7 +108,7 @@
 
     print {$OUT} "extern void Parrot_${_}_class_init(PARROT_INTERP, int, int);\n" foreach (@pmcs);
 
-    print {$OUT} <<"END_C";
+    print {$OUT} <<'END_C';
 
 /* This isn't strictly true, but the headerizer should not bother */
 
@@ -137,14 +131,14 @@
         foreach ( @pmcs[ -1 .. -1 ] );
     print {$OUT} "        Parrot_${_}_class_init(interp, enum_class_${_}, pass);\n"
         foreach ( @pmcs[ 0 .. $#pmcs - 1 ] );
-    print {$OUT} <<"END_C";
+    print {$OUT} <<'END_C';
         if (!pass) {
             parrot_global_setup_2(interp);
         }
     }
 }
 
-static void register_pmc(PARROT_INTERP, PMC *registry, int pmc_id)
+static void register_pmc(PARROT_INTERP, NOTNULL(PMC *registry), int pmc_id)
 {
     STRING * const key = interp->vtables[pmc_id]->whoami;
     VTABLE_set_integer_keyed_str(interp, registry, key, pmc_id);
@@ -159,15 +153,10 @@
     print {$OUT} <<'END_C';
 }
 
-/*
- * Local variables:
- *   c-file-style: "parrot"
- * End:
- * vim: expandtab shiftwidth=4:
- */
 END_C
+    print {$OUT} coda();
 
-    close $OUT;
+    close $OUT or die "Can't close file: $!";
 
     move_if_diff( "$file.tmp", $file );
 
@@ -178,10 +167,10 @@
     my ( $self, $conf ) = @_;
 
     my $file = "lib/Parrot/PMC.pm";
-    my @pmcs = split( / /, $conf->data->get('pmc_names') );
+    my @pmcs = split( qr/ /, $conf->data->get('pmc_names') );
 
     $conf->append_configure_log($file);
-    open( my $OUT, ">", "$file.tmp" );
+    open( my $OUT, '>', "$file.tmp" );
 
     print $OUT <<'END_PM';
 # DO NOT EDIT THIS FILE
@@ -203,22 +192,36 @@
 
     for my $num ( 0 .. $#pmcs ) {
         my $id = $num + 1;
-        print $OUT "\t$pmcs[$num] => $id,\n";
+        print {$OUT} "\t$pmcs[$num] => $id,\n";
     }
 
-    print $OUT <<'END_PM';
+    print {$OUT} <<'END_PM';
 );
 
 1;
 END_PM
 
-    close $OUT;
+    close $OUT or die "Can't close file: $!";
 
     move_if_diff( "$file.tmp", $file );
 
     return;
 }
 
+sub coda {
+    my $v = 'vim';
+
+    # Translate it in code so vim doesn't think this file itself is readonly
+    return <<"HERE"
+/*
+ * Local variables:
+ *   c-file-style: "parrot"
+ * End:
+ * ${v}: readonly expandtab shiftwidth=4:
+ */
+HERE
+}
+
 1;
 
 # Local Variables:


More information about the parrot-commits mailing list