duchain seems to be broken

Jakob Petsovits jpetso at gmx.at
Sat May 5 14:47:59 UTC 2007


On Saturday, 5. May 2007, Andreas Pakulat wrote:
> Hi,
>
> somehow the duchain seems to be broken, opening a .cpp file in KDevelop
> asserts in kateviewinternal:3180. According to Christoph Cullman its
> probably wrong locking and indeed the assert checks that isSmartLocked()
> is set.

Ah right. This was the crash I asked you about (which did not happen on your 
system at that time), approximately two weeks ago.

It's caused by a QMutexLocker which does not lock even if it really should,
in lib/editor/editorintegrator.cpp:190 and the following lines:

Range* newRange = data()->topRanges[currentUrl()][type] =
        createRange(currentDocument()->documentRange());
if (SmartInterface* iface = smart()) {
    QMutexLocker lock(iface->smartMutex());
    Q_ASSERT(newRange->isSmartRange());
    iface->addHighlightToDocument( newRange->toSmartRange(), false );
    newRange->toSmartRange()->addWatcher(data());
}

The line
    iface->addHighlightToDocument( newRange->toSmartRange(), false );
crashes, because the QMutexLocker two lines above DOES NOT LOCK the mutex.
Check it for yourself by adding the debug lines

bool smartLocked = true;
if (iface->smartMutex()->tryLock()) {
    iface->smartMutex()->unlock();
    smartLocked = false;
}
kDebug() << (smartLocked
                ? "topRange(): smartLocked == true"
                : "topRange(): smartLocked == false");

directly after the QMutexLocker creation.
(That's the code that Katepart uses to check if the mutex is locked.)

Either Qt has a grave bug, or we missed something blatantly wrong here.

Hoping for a good idea,
  Jakob




More information about the KDevelop-devel mailing list