Browse Source

When exposing the CustomSQLexer to scripts we've been segfaulting when closing the vm due to the order of creation, the _keywords table was created before (inside the script SQLexer constructor) the lexer was inserted in the vm, this seems to fix it for now, probably a more general fix need to be done.

mingodad 5 years ago
parent
commit
d1c3869e7c
2 changed files with 11 additions and 3 deletions
  1. 10 2
      SquiLu/squirrel/sq_lexer.cpp
  2. 1 1
      SquiLu/squirrel/sqlexer.h

+ 10 - 2
SquiLu/squirrel/sq_lexer.cpp

@@ -25,15 +25,23 @@ public:
     CustomSQLexer(HSQUIRRELVM vm, SQInteger kw_idx):
         _vm(vm), _kw_idx(kw_idx){}
 
+    ~CustomSQLexer() {--this->_keywords->_uiRef;}
     virtual SQTable * GetKeywords()
     {
+        SQTable *tbl;
         if(_vm && _kw_idx)
         {
             SQObjectPtr &tbl_var = stack_get(_vm, _kw_idx);
-            SQTable *tbl = _table(tbl_var)->Clone();
+            tbl = _table(tbl_var)->Clone();
             return tbl;
         }
-        return SQLexer::GetKeywords();
+        else tbl = SQLexer::GetKeywords();
+        //due cleanup at the vm closing,
+        //it was segfaulting due to the order
+        //of constructing the keywords table before
+        //the CustomSQLexer (inside it's constructor)
+        ++tbl->_uiRef;
+        return tbl;
     }
     virtual void DummyPinVtable();
 };

+ 1 - 1
SquiLu/squirrel/sqlexer.h

@@ -87,7 +87,7 @@ struct SQLexer
 	SQInteger LookaheadLex();
 	const SQChar *Tok2Str(SQInteger tok);
 	const SQChar *GetTokenName(SQInteger tk_code);
-private:
+protected:
 	SQInteger GetIDType(const SQChar *s,SQInteger len);
 	SQInteger ReadString(SQInteger ndelim,bool verbatim);
 	SQInteger ReadNumber(SQInteger startChar=0, bool dontThrowIntegerOverflow=false);