[Kst] extragear/graphics/kst/src/libkstapp
Eli Fidler
eli at staikos.net
Wed Feb 7 22:02:16 CET 2007
SVN commit 631375 by fidler:
fixed several related error-handling and locking bugs
This should fix bug 141349
M +5 -9 kstbasicdialog_i.cpp
M +20 -10 kstfilterdialog_i.cpp
M +6 -7 kstfitdialog_i.cpp
M +11 -15 kstplugindialog_i.cpp
--- trunk/extragear/graphics/kst/src/libkstapp/kstbasicdialog_i.cpp #631374:631375
@@ -220,6 +220,7 @@
Q_ASSERT(ptr); //should never happen...
ptr->writeLock();
+ KstWriteLocker pl(ptr);
QString tagName = _tagName->text();
@@ -233,8 +234,6 @@
}
ptr->setTagName(KstObjectTag::fromString(tagName));
- ptr->unlock();
-
// Save the vectors and scalars
if (!editSingleObject(ptr) || !ptr->isValid()) {
KMessageBox::sorry(this, i18n("There is an error in the values you entered."));
@@ -342,9 +341,9 @@
bool KstBasicDialogI::editSingleObject(KstBasicPluginPtr ptr) {
- KST::vectorList.lock().readLock();
- KST::scalarList.lock().writeLock();
- KST::stringList.lock().readLock();
+ KstReadLocker vl(&KST::vectorList.lock());
+ KstWriteLocker scl(&KST::scalarList.lock());
+ KstReadLocker stl(&KST::stringList.lock());
{ // leave this scope here to destroy the iterators
@@ -360,7 +359,6 @@
}
}
}
- KST::vectorList.lock().unlock();
//input scalars...
KstScalarList::Iterator s;
@@ -379,12 +377,11 @@
KstScalarPtr sp = new KstScalar(KstObjectTag::fromString(w->_scalar->currentText()), 0L, val, true, false, false); // FIXME: should this be a global-context scalar?
ptr->setInputScalar(*isI, sp);
} else {
- //deal with error...
+ return false;
}
}
}
}
- KST::scalarList.lock().unlock();
//input strings...
KstStringList::Iterator str;
@@ -398,7 +395,6 @@
}
}
}
- KST::stringList.lock().unlock();
}
--- trunk/extragear/graphics/kst/src/libkstapp/kstfilterdialog_i.cpp #631374:631375
@@ -117,20 +117,26 @@
bool KstFilterDialogI::saveInputs(KstCPluginPtr plugin, KstSharedPtr<Plugin> p) {
- KST::vectorList.lock().readLock();
- KST::scalarList.lock().writeLock();
- KST::stringList.lock().writeLock();
+ KstReadLocker vl(&KST::vectorList.lock());
+ KstWriteLocker scl(&KST::scalarList.lock());
+ KstWriteLocker stl(&KST::stringList.lock());
const QValueList<Plugin::Data::IOValue>& itable = p->data()._inputs;
for (QValueList<Plugin::Data::IOValue>::ConstIterator it = itable.begin(); it != itable.end(); ++it) {
if ((*it)._type == Plugin::Data::IOValue::TableType) {
if ((*it)._name == p->data()._filterInputVector) {
KstVectorPtr v = *KST::vectorList.findTag(_yvector);
+ if (!v) {
+ return false;
+ }
plugin->inputVectors().insert((*it)._name, v);
} else {
QObject *field = _w->_pluginInputOutputFrame->child((*it)._name.latin1(), "VectorSelector");
if (field) {
VectorSelector *vs = static_cast<VectorSelector*>(field);
KstVectorPtr v = *KST::vectorList.findTag(vs->selectedVector());
+ if (!v) {
+ return false;
+ }
plugin->inputVectors().insert((*it)._name, v);
}
}
@@ -145,7 +151,7 @@
KstStringPtr newString = new KstString(KstObjectTag(ss->_string->currentText(), KstObjectTag::orphanTagContext), 0L, val, true);
plugin->inputStrings().insert((*it)._name, newString);
} else {
- plugin->inputStrings().insert((*it)._name, s);
+ return false;
}
}
} else if ((*it)._type == Plugin::Data::IOValue::PidType) {
@@ -164,7 +170,7 @@
KstScalarPtr newScalar = new KstScalar(KstObjectTag(ss->_scalar->currentText(), KstObjectTag::orphanTagContext), 0L, val, true, false);
plugin->inputScalars().insert((*it)._name, newScalar);
} else {
- plugin->inputScalars().insert((*it)._name, s);
+ return false;
}
} else {
plugin->inputScalars().insert((*it)._name, s);
@@ -172,9 +178,6 @@
}
}
}
- KST::stringList.lock().unlock();
- KST::scalarList.lock().unlock();
- KST::vectorList.lock().unlock();
return true;
}
@@ -240,7 +243,7 @@
if (pPtr) {
KstCPluginPtr plugin = new KstCPlugin;
- plugin->writeLock();
+ KstWriteLocker pl(plugin);
plugin->setDirty();
if (saveInputs(plugin, pPtr)) {
if (tagName == plugin_defaultTag) {
@@ -255,6 +258,7 @@
if (plugin->isValid()) {
if (!createCurve(plugin)) {
KMessageBox::sorry(this, i18n("There is an error in the plugin you entered."));
+ return false;
} else {
KST::dataObjectList.lock().writeLock();
KST::dataObjectList.append(plugin.data());
@@ -262,10 +266,16 @@
}
} else {
KMessageBox::sorry(this, i18n("There is an error in the plugin you entered."));
+ return false;
}
+ } else {
+ KMessageBox::sorry(this, i18n("There is an error in the outputs you entered."));
+ return false;
}
+ } else {
+ KMessageBox::sorry(this, i18n("There is an error in the inputs you entered."));
+ return false;
}
- plugin->unlock();
}
}
emit modified();
--- trunk/extragear/graphics/kst/src/libkstapp/kstfitdialog_i.cpp #631374:631375
@@ -194,7 +194,7 @@
if (pPtr) {
KstCPluginPtr plugin = new KstCPlugin;
- plugin->writeLock();
+ KstWriteLocker pl(plugin);
plugin->setDirty();
if (saveInputs(plugin, pPtr)) {
if (tagName == plugin_defaultTag) {
@@ -209,23 +209,22 @@
if (plugin->isValid()) {
if (!createCurve(plugin)) {
KMessageBox::sorry(this, i18n("Could not create curve from fit, possibly due to a bad plugin."));
- plugin->unlock();
return false;
}
- plugin->unlock();
KST::dataObjectList.lock().writeLock();
KST::dataObjectList.append(plugin.data());
KST::dataObjectList.lock().unlock();
} else {
KMessageBox::sorry(this, i18n("There is something wrong (i.e, there is a bug) with the creation of the fit plugin."));
- plugin->unlock();
return false;
}
} else {
- plugin->unlock();
+ KMessageBox::sorry(this, i18n("There is an error in the outputs you entered."));
+ return false;
}
} else {
- plugin->unlock();
+ KMessageBox::sorry(this, i18n("There is an error in the inputs you entered."));
+ return false;
}
} else {
KMessageBox::sorry(this, i18n("There is something wrong (i.e, there is a bug) with"
@@ -421,7 +420,7 @@
KstScalarPtr newScalar = new KstScalar(KstObjectTag(ss->_scalar->currentText(), KstObjectTag::orphanTagContext), 0L, val, true, false);
plugin->inputScalars().insert((*it)._name, newScalar);
} else {
- plugin->inputScalars().insert((*it)._name, s);
+ rc = false;
}
} else {
plugin->inputScalars().insert((*it)._name, s);
--- trunk/extragear/graphics/kst/src/libkstapp/kstplugindialog_i.cpp #631374:631375
@@ -409,6 +409,9 @@
if (s == *KST::stringList.end()) {
QString val = ss->_string->currentText();
KstStringPtr newString = new KstString(KstObjectTag::fromString(ss->_string->currentText()), 0L, val, true);
+ if (!newString) {
+ rc = false;
+ }
plugin->inputStrings().insert((*it)._name, newString);
} else {
plugin->inputStrings().insert((*it)._name, s);
@@ -429,7 +432,7 @@
KstScalarPtr newScalar = new KstScalar(KstObjectTag::fromString(ss->_scalar->currentText()), 0L, val, true, false);
plugin->inputScalars().insert((*it)._name, newScalar);
} else {
- plugin->inputScalars().insert((*it)._name, s);
+ rc = false;
}
} else {
plugin->inputScalars().insert((*it)._name, s);
@@ -555,7 +558,7 @@
KstSharedPtr<Plugin> pPtr = PluginCollection::self()->plugin(_pluginList[pitem]);
if (pPtr) {
plugin = new KstCPlugin;
- plugin->writeLock();
+ KstWriteLocker pl(plugin);
// set the tag name before any dependents are created
if (tagName == plugin_defaultTag) {
@@ -564,8 +567,7 @@
plugin->setTagName(KstObjectTag(tagName, KstObjectTag::globalTagContext));
if (!saveInputs(plugin, pPtr)) {
- KMessageBox::sorry(this, i18n("One or more of the inputs was undefined."));
- plugin->unlock();
+ KMessageBox::sorry(this, i18n("There is an error in the inputs you entered."));
plugin = 0L;
return false;
}
@@ -573,12 +575,10 @@
plugin->setPlugin(pPtr);
if (!saveOutputs(plugin, pPtr)) {
- KMessageBox::sorry(this, i18n("One or more of the outputs was undefined."));
- plugin->unlock();
+ KMessageBox::sorry(this, i18n("There is an error in the outputs you entered."));
plugin = 0L;
return false;
}
- plugin->unlock();
}
}
@@ -604,10 +604,10 @@
return false;
}
- pp->writeLock();
+ KstWriteLocker pl(pp);
+
if (_tagName->text() != pp->tagName() && KstData::self()->dataTagNameNotUnique(_tagName->text())) {
_tagName->setFocus();
- pp->unlock();
return false;
}
@@ -622,8 +622,7 @@
// Save the vectors and scalars
if (!saveInputs(pp, pPtr)) {
- KMessageBox::sorry(this, i18n("There is an error in the plugin you entered."));
- pp->unlock();
+ KMessageBox::sorry(this, i18n("There is an error in the inputs you entered."));
return false;
}
@@ -632,18 +631,15 @@
}
if (!saveOutputs(pp, pPtr)) {
- KMessageBox::sorry(this, i18n("There is an error in the plugin you entered."));
- pp->unlock();
+ KMessageBox::sorry(this, i18n("There is an error in the outputs you entered."));
return false;
}
if (!pp->isValid()) {
KMessageBox::sorry(this, i18n("There is an error in the plugin you entered."));
- pp->unlock();
return false;
}
pp->setDirty();
- pp->unlock();
emit modified();
return true;
More information about the Kst
mailing list