[Kst] extragear/graphics/kst/src/libkstmath

George Staikos staikos at kde.org
Mon Jan 22 08:13:44 CET 2007


SVN commit 626105 by staikos:

fix memory leaks and remove unnecessary strlen computations.


 M  +15 -4     enodes.cpp  
 M  +1 -1      enodes.h  


--- trunk/extragear/graphics/kst/src/libkstmath/enodes.cpp #626104:626105
@@ -36,6 +36,9 @@
 extern "C" int yyparse();
 extern "C" void *ParsedEquation;
 extern "C" struct yy_buffer_state *yy_scan_string(const char*);
+extern "C" struct yy_buffer_state *yy_scan_bytes(const char*, int);
+typedef struct yy_buffer_state *YY_BUFFER_STATE;
+extern "C" void yy_delete_buffer(YY_BUFFER_STATE);
 
 using namespace Equation;
 
@@ -46,7 +49,7 @@
 }
 
 
-double Equation::interpret(const char *txt, bool *ok) {
+double Equation::interpret(const char *txt, bool *ok, int len) {
   if (!txt || !*txt) {
     if (ok) {
       *ok = false;
@@ -55,8 +58,14 @@
   }
 
   mutex().lock();
-  yy_scan_string(txt);
+  YY_BUFFER_STATE b;
+  if (len > 0) {
+    b = yy_scan_bytes(txt, len);
+  } else {
+    b = yy_scan_string(txt);
+  }
   int rc = yyparse();
+  yy_delete_buffer(b);
   if (rc == 0) {
     Equation::Node *eq = static_cast<Equation::Node*>(ParsedEquation);
     ParsedEquation = 0L;
@@ -798,8 +807,9 @@
   if (_isEquation) {
     if (!_equation) {
       mutex().lock();
-      yy_scan_string(_tagName.latin1());
+      YY_BUFFER_STATE b = yy_scan_bytes(_tagName.latin1(), _tagName.length());
       int rc = yyparse();
+      yy_delete_buffer(b);
       if (rc == 0 && ParsedEquation) {
         _equation = static_cast<Equation::Node*>(ParsedEquation);
         ParsedEquation = 0L;
@@ -821,8 +831,9 @@
   } else if (_vector) {
     if (!_equation && !_vectorIndex.isEmpty()) {
       mutex().lock();
-      yy_scan_string(_vectorIndex.latin1());
+      YY_BUFFER_STATE b = yy_scan_bytes(_vectorIndex.latin1(), _vectorIndex.length());
       int rc = yyparse();
+      yy_delete_buffer(b);
       if (rc == 0 && ParsedEquation) {
         _equation = static_cast<Equation::Node*>(ParsedEquation);
         ParsedEquation = 0L;
--- trunk/extragear/graphics/kst/src/libkstmath/enodes.h #626104:626105
@@ -35,7 +35,7 @@
   /*    Evaluate the expression @p txt and returns the value as a double.
    *    Returns the value, or 0.0 and sets ok = false on error.
    */
-  KST_EXPORT double interpret(const char *txt, bool *ok = 0L);
+  KST_EXPORT double interpret(const char *txt, bool *ok = 0L, int len = -1);
 
   class Context {
     public:


More information about the Kst mailing list