D22241: KModifierKeyInfo: we are sharing the internal implementation

Kai Uwe Broulik noreply at phabricator.kde.org
Thu Jul 4 10:19:18 BST 2019


broulik added a comment.


  > So why does KModifierKeyInfo::Private need to be shared?
  
  It needs to be refcounted. In 0fe2990dbad992a4925a7b7bee09b1cdfbe5a7a7 <https://phabricator.kde.org/R273:0fe2990dbad992a4925a7b7bee09b1cdfbe5a7a7> a plugin infrastructure was introduced. Unbeknownst to us the instances are shared internally by Qt.
  
    KModifierKeyInfoProvider* createProvider()
    {
        QPluginLoader loader(QStringLiteral("kf5/kguiaddons/kmodifierkey/kmodifierkey_")+qGuiApp->platformName());
        auto instance = dynamic_cast<KModifierKeyInfoProvider*>(loader.instance());
        if (instance)
            return instance;
    ...
     
     KModifierKeyInfo::KModifierKeyInfo(QObject *parent)
        : QObject(parent), p(createProvider())
  
  The `instance` returned is the same every time despite the `QPluginLoader` being on the stack.
  Now the destructor of `KModifierKeyInfo` cleans up `p` and if you have two instances of `KModifierKeyInfo`, which Kile does for instance, it crashes on double delete.

REPOSITORY
  R273 KGuiAddons

REVISION DETAIL
  https://phabricator.kde.org/D22241

To: apol, broulik
Cc: davidedmundson, kde-frameworks-devel, LeGast00n, michaelh, ngraham, bruns
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-frameworks-devel/attachments/20190704/f03025c1/attachment.html>


More information about the Kde-frameworks-devel mailing list