Browse Source

egg: Fix egg lexer state not being cleaned up after error

rdb 5 years ago
parent
commit
152d317c8c

+ 10 - 0
panda/src/egg/lexer.cxx.prebuilt

@@ -971,6 +971,7 @@ extern "C" int eggyywrap(void);  // declared below.
 
 static int yyinput(void);        // declared by flex.
 
+int eggyylex_destroy(void);
 
 ////////////////////////////////////////////////////////////////////
 // Static variables
@@ -1018,6 +1019,15 @@ egg_init_lexer(istream &in, const string &filename) {
   initial_token = START_EGG;
 }
 
+void
+egg_cleanup_lexer() {
+  // Reset the lexer state.
+  eggyylex_destroy();
+
+  input_p = nullptr;
+  egg_filename.clear();
+}
+
 void
 egg_start_group_body() {
   /* Set the initial state to begin within a group_body context,

+ 10 - 0
panda/src/egg/lexer.lxx

@@ -26,6 +26,7 @@ extern "C" int eggyywrap(void);  // declared below.
 
 static int yyinput(void);        // declared by flex.
 
+int eggyylex_destroy(void);
 
 ////////////////////////////////////////////////////////////////////
 // Static variables
@@ -73,6 +74,15 @@ egg_init_lexer(istream &in, const string &filename) {
   initial_token = START_EGG;
 }
 
+void
+egg_cleanup_lexer() {
+  // Reset the lexer state.
+  yylex_destroy();
+
+  input_p = nullptr;
+  egg_filename.clear();
+}
+
 void
 egg_start_group_body() {
   /* Set the initial state to begin within a group_body context,

+ 1 - 0
panda/src/egg/lexerDefs.h

@@ -21,6 +21,7 @@
 #include <string>
 
 void egg_init_lexer(std::istream &in, const std::string &filename);
+void egg_cleanup_lexer();
 void egg_start_group_body();
 void egg_start_texture_body();
 void egg_start_primitive_body();

+ 2 - 0
panda/src/egg/parser.cxx.prebuilt

@@ -223,6 +223,8 @@ egg_cleanup_parser() {
   textures.clear();
   materials.clear();
   groups.clear();
+
+  egg_cleanup_lexer();
 }
 
 

+ 2 - 0
panda/src/egg/parser.yxx

@@ -153,6 +153,8 @@ egg_cleanup_parser() {
   textures.clear();
   materials.clear();
   groups.clear();
+
+  egg_cleanup_lexer();
 }
 
 %}