KLibLoader + KPartFactory + loading oneself problem.

Luis Pedro Coelho luis_pedro at netcabo.pt
Sat Jun 7 16:55:02 BST 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

{see http://bugs.kde.org/show_bug.cgi?id=58904 }

I have been looking into bug 58904.

I have one solution below (not yet commited). I still don't know if it is a 
good one or whether this should be fixed elsewhere (kdecore), so I am posting 
to ask for opinions.

It comes down to the following:

kghostview, the app, is a simple shell dynamically linked to the part. At run 
time, when a print preview window gets called, the same part is loaded (since 
the print preview wants to display postscript as well) and the corresponding 
factory object is constructed. When the preview is finished, the lib is 
unloaded and the factory destroyed.

The problem is that destroying the factory, destroys  KGVFactory::s_instance 
which is still in use by the main application! This leads to crashes later.

Here is my simple fix (attached is full patch against HEAD - works with BRANCH 
even though it doesn't apply directly): In the shell, instead of constructing 
the object directly, do:

- -    m_gvpart = new KGVPart( this, "kgvpart", this, "kgvpart" );
+    m_gvpart = dynamic_cast<KGVPart*>( KLibLoader::self()->factory( 
"libkghostviewpart" )->create( this, "kgvpart", "KGVPart" ) );

This increments the reference count and prevents the library from being 
unloaded and everything seems to work.

Is this a good solution or a hack?
Is there anything else I should be doing? 
Can one consider this a KLibLoader + Factory bug? Or is it a plain old 
kghostview bug?

Regards,
- -- 
Luis Pedro Coelho

The carrot tax, see:
http://luispedro.journalspace.com/

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE+4grWGpBAvyRwXdgRAqdkAJ4y6Ob9QKXXszXBX6ONS7iyvavlaACeKOW4
SFQUzF+K61pWi+w5pGJAwVI=
=rRiW
-----END PGP SIGNATURE-----
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kmail-attach.3mwDZe
Type: text/x-diff
Size: 942 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20030607/52166b46/attachment.diff>


More information about the kde-core-devel mailing list