KSharedPtr breakage

David Faure faure at kde.org
Sun Oct 23 15:43:30 BST 2005


On Sunday 23 October 2005 18:05, Frerich Raabe wrote:
> On Sunday 23 October 2005 15:39, Frerich Raabe wrote:
> > On Sunday 23 October 2005 05:52, Hamish Rodda wrote:
> > > I tried to
> > > port it over to 100% shared pointers, but encountered a problem with
> > > covariant returns - KSharedPtr can't be used (in its current form) in a
> > > covariant return with different class types
> 
> This is a bit tricky, but looking at what KSycoca* is doing, maybe there's an 
> easy way out. Take KSycocaFactory::findServiceByName:
> 
>   virtual KServiceType * findServiceTypeByName(const QString &_name);
> 
> It returns a raw pointer, not a shared one, but doesn't document who's 
> supposed to call delete on the pointee. If we're lucky, the caller is 
> supposed to do so

Not at all, this pointer is only a cast of a KSharedPtr, i.e. a pointer that
kdelibs will delete all by itself.

The caller is NOT supposed to delete a KServiceType, ever.

A better API for this method would be to return a KServiceType::Ptr, I guess.

-- 
David Faure, faure at kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).





More information about the kde-core-devel mailing list