ShInitialize/ShFinalize is designed to be called once per process, or it would crash at random locations. I changed ShFinalize() to properly cleanup and reset global variables so that they can be called multiple times. I think that the compiler setup is much more complicated than it needs to be. It unnecessarily uses global variables. A custom pool allocator is overkill too. 
Review URL: http://codereview.appspot.com/1238045

git-svn-id: https://angleproject.googlecode.com/svn/trunk@316 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/compiler/ShaderLang.cpp b/src/compiler/ShaderLang.cpp
index 2e0f15d..913a511 100644
--- a/src/compiler/ShaderLang.cpp
+++ b/src/compiler/ShaderLang.cpp
@@ -22,7 +22,7 @@
 // set of built-ins, and we want to preserve that from
 // compile to compile.
 //
-TSymbolTable SymbolTables[EShLangCount];
+TSymbolTable* SymbolTables[EShLangCount];
 
 
 TPoolAllocator* PerProcessGPA = 0;
@@ -59,8 +59,10 @@
         PerProcessGPA->push();
         SetGlobalPoolAllocatorPtr(PerProcessGPA);
 
-        SymbolTables[EShLangVertex].copyTable(symTables[EShLangVertex]);
-        SymbolTables[EShLangFragment].copyTable(symTables[EShLangFragment]);
+        SymbolTables[EShLangVertex] = new TSymbolTable;
+        SymbolTables[EShLangVertex]->copyTable(symTables[EShLangVertex]);
+        SymbolTables[EShLangFragment] = new TSymbolTable;
+        SymbolTables[EShLangFragment]->copyTable(symTables[EShLangFragment]);
 
         SetGlobalPoolAllocatorPtr(gPoolAllocator);
 
@@ -133,6 +135,11 @@
   if (PerProcessGPA) {
     PerProcessGPA->popAll();
     delete PerProcessGPA;
+    PerProcessGPA = 0;
+  }
+  for (int i = 0; i < EShLangCount; ++i) {
+    delete SymbolTables[i];
+    SymbolTables[i] = 0;
   }
   return 1;
 }
@@ -252,7 +259,7 @@
         return 1;
 
     TIntermediate intermediate(infoSink);
-    TSymbolTable symbolTable(SymbolTables[compiler->getLanguage()]);
+    TSymbolTable symbolTable(*SymbolTables[compiler->getLanguage()]);
     
     GenerateBuiltInSymbolTable(resources, infoSink, &symbolTable, compiler->getLanguage());