[Kst] kdeextragear-2/kst

George Staikos staikos at kde.org
Thu Oct 21 22:38:42 CEST 2004


CVS commit by staikos: 

- fix a recently introduced crash due to uninit var in some cases
- add support for localdata deletion as mentioned on the list


  M +12 -0     devel-docs/KstPlugins   1.7
  M +8 -4      kst/enodes.cpp   1.23
  M +11 -2     kst/kstplugin.cpp   1.71
  M +20 -9     kst/plugin.cpp   1.24
  M +3 -2      kst/plugin.h   1.30
  M +4 -0      kst/pluginloader.cpp   1.15


--- kdeextragear-2/kst/devel-docs/KstPlugins  #1.6:1.7
@@ -221,4 +221,16 @@
 realloc().
 
+If you allocate something more than a simple free() can cleanup, you must clean
+up the localdata yourself.  To do this, export a symbol:
+void freeLocalData(void**)
+that does the cleanup.  It will be called when the plugin is being destroyed.
+
+
+
+Parameter Names
+---------------
+Undocumented
+
+
 
 

--- kdeextragear-2/kst/kst/enodes.cpp  #1.22:1.23
@@ -267,4 +267,6 @@ Function::Function(char *name, ArgumentL
   _outputIndex = -424242;
   _localData = 0L;
+  _outputVectorCnt = 0;
+  _inputVectorCnt = 0;
   //printf("%p: New Function: %s - %p\n", (void*)this, name, (void*)args);
   if (strcasecmp("plugin", name) == 0) {
@@ -304,4 +306,10 @@ Function::~Function() {
   _args = 0L;
   _f = 0L;
+  if (_localData) {
+    if (!_plugin->freeLocalData(&_localData)) {
+      free(_localData);
+    }
+    _localData = 0L;
+  }
   _plugin = 0L;
   delete[] _inScalars;
@@ -314,8 +322,4 @@ Function::~Function() {
   delete[] _inArrayLens;
   delete[] _outArrayLens;
-  if (_localData) {
-    free(_localData);
-    _localData = 0L;
-  }
 }
 

--- kdeextragear-2/kst/kst/kstplugin.cpp  #1.70:1.71
@@ -128,5 +128,7 @@ void KstPlugin::commonConstructor() {
 KstPlugin::~KstPlugin() {
   if (_localData) {
+    if (!_plugin->freeLocalData(&_localData)) {
     free(_localData);
+    }
     _localData = 0L;
   }
@@ -345,5 +347,12 @@ bool KstPlugin::setPlugin(KstSharedPtr<P
   }
 
-  if (!plugin.data()) {
+  if (_plugin && _localData) {
+    if (!_plugin->freeLocalData(&_localData)) {
+      free(_localData);
+    }
+    _localData = 0L;
+  }
+
+  if (!plugin) {
     _inputVectors.clear();
     _inputScalars.clear();

--- kdeextragear-2/kst/kst/plugin.cpp  #1.23:1.24
@@ -29,4 +29,5 @@ Plugin::Plugin() : KstShared() {
   _lib = 0L;
   _symbol = 0L;
+  _freeSymbol = 0L;
   _parameterName = 0L;
   //kdDebug() << "Creating Plugin: " << long(this) << endl;
@@ -36,4 +37,5 @@ Plugin::Plugin() : KstShared() {
 Plugin::~Plugin() {
   _symbol = 0L;
+  _freeSymbol = 0L;
   _parameterName = 0L;
 
@@ -85,20 +87,20 @@ int Plugin::call(const double *const inA
 
 
-QString Plugin::parameterName(int iIndex) {
-  QString strParameter;
-  char* pName = 0L;
+QString Plugin::parameterName(int idx) const {
+  QString parameter;
+  char *name = 0L;
   
   if (_data._isFit && _parameterName) {
-    if (((int(*)(int, char**))_parameterName)(iIndex, &pName) && pName) {
-      strParameter = pName; // deep copy into QString
-      free(pName);
+    if (((int(*)(int, char**))_parameterName)(idx, &name) && name) {
+      parameter = name; // deep copy into QString
+      free(name);
     }
   }
 
-  if (strParameter.isEmpty()) {
-    strParameter = i18n("Param%1").arg(iIndex);
+  if (parameter.isEmpty()) {
+    parameter = i18n("Param%1").arg(idx);
   }
   
-  return strParameter;
+  return parameter;
 }
 
@@ -151,3 +153,12 @@ void Plugin::Data::clear() {
 }
 
+
+bool Plugin::freeLocalData(void **local) const {
+  if (_freeSymbol) {
+    ((void (*)(void**))_freeSymbol)(local);
+    return true;
+  }
+  return false;
+}
+
 // vim: ts=2 sw=2 et

--- kdeextragear-2/kst/kst/plugin.h  #1.29:1.30
@@ -45,5 +45,6 @@ class Plugin : public KstShared {
         double *outArrays[], int outArrayLens[],
         double outScalars[], void **local) const;
-    QString parameterName(int iIndex);
+    QString parameterName(int index) const;
+    bool freeLocalData(void **local) const;
 
     static const int CallError;
@@ -131,5 +132,5 @@ class Plugin : public KstShared {
     KLibrary *_lib;
 
-    void *_symbol;
+    void *_symbol, *_freeSymbol;
     void *_parameterName;
 

--- kdeextragear-2/kst/kst/pluginloader.cpp  #1.14:1.15
@@ -72,4 +72,8 @@ Plugin *PluginLoader::loadPlugin(const Q
   }
 
+  if (plug->_lib->hasSymbol("freeLocalData")) {
+    plug->_freeSymbol = plug->_lib->symbol("freeLocalData");
+  }
+
   if (!plug->_symbol) {
     KstDebug::self()->log(i18n("Could not find symbol '%1' in plugin %2.").arg(plug->_data._name).arg(object), KstDebug::Error);





More information about the Kst mailing list