------=_Part_3566_13389642.1137239682825 Content-Type: multipart/alternative; boundary="----=_Part_3567_23708488.1137239682826" ------=_Part_3567_23708488.1137239682826 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi, I would like commit the attached patch (ksharedptr.h.diff). It does: - separate raw pointer operator from ksharedptr operators. - add a clear method to make the pointer null. - make the method attach only usable on raw pointer. (since it's a *low level* method and that the operator =3D handle all the cases) I still wonder if I should make that method a private/protected one. Other than that I would like to know the opinion of people if I make the main constructor an explicit one. Like that we could at least see while coding bugs like: void foo(KSharedPtr bar); Bar *foofoo() { Bar *bar =3D new Bar(); foo(bar); return bar; // bar is now a dandling pointer } One main disaventage of that is that we can't use the "KSharedPtr foo = =3D bar;" syntax. We must use the "KSharedPtr foo(bar);" syntax. I also attached the whole kdelibs kshared explicit constructor patch for reference to show that's it's quite simple to convert to explicit constructor. It adds some not pretty code at some place, but it's a private diff and I don't intend to commit it like this. Michel ------=_Part_3567_23708488.1137239682826 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi,
I would like commit the attached patch (ksharedptr.h.diff).
It do= es:
- separate raw pointer operator from ksharedptr operators.
- add = a clear method to make the pointer null.
- make the method attach only u= sable on raw pointer.
  (since it's a *low level* method and that the operator =3D handl= e all the cases)
  I still wonder if I should make that method a pr= ivate/protected one.

Other than that I would like to know the opinio= n of people if I make the main constructor an explicit one.
Like that we could at least see while coding bugs like:

void foo= (KSharedPtr<Bar> bar);

Bar *foofoo()
{
   = ; Bar *bar =3D new Bar();
    foo(bar);
  &n= bsp; return bar; // bar is now a dandling pointer
}

One main disaventage of that is that we can't use the "KS= haredPtr<Foo> foo =3D bar;" syntax.
We must use the "KSh= aredPtr<Foo> foo(bar);" syntax.

I also attached the whole= kdelibs kshared explicit constructor patch for reference to show that's it= 's quite simple to convert to explicit constructor.
It adds some not pretty code at some place, but it's a private diff and= I don't intend to commit it like this.

Michel
------=_Part_3567_23708488.1137239682826-- ------=_Part_3566_13389642.1137239682825 Content-Type: application/octet-stream; name=ksharedptr.h.diff Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="ksharedptr.h.diff" Index: ksharedptr.h =================================================================== --- ksharedptr.h (revision 496190) +++ ksharedptr.h (working copy) @@ -55,7 +55,7 @@ * Creates a new pointer. * @param p the pointer */ - inline KSharedPtr( T* p ) // TODO: Make explicit + inline /*explicit*/ KSharedPtr( T* p ) : d(p) { if(d) d->ref.ref(); } /** @@ -71,10 +71,11 @@ */ inline ~KSharedPtr() { if (d && !d->ref.deref()) delete d; } - inline KSharedPtr& operator= ( const KSharedPtr& o ) { attach(o); return *this; } - inline KSharedPtr& operator= ( T* p ) { attach(p); return *this; } + inline KSharedPtr& operator= ( const KSharedPtr& o ) { attach(o.d); return *this; } inline bool operator== ( const KSharedPtr& o ) const { return ( d == o.d ); } inline bool operator!= ( const KSharedPtr& o ) const { return ( d != o.d ); } + + inline KSharedPtr& operator= ( T* p ) { attach(p); return *this; } inline bool operator== ( const T* p ) const { return ( d == p ); } inline bool operator!= ( const T* p ) const { return ( d != p ); } @@ -106,17 +107,16 @@ inline T* operator->() { Q_ASSERT(d); return d; } /** - * Attach the given pointer to the KSharedPtr. + * Attach the given pointer to the current KSharedPtr. * If the previous shared pointer is not owned by any KSharedPtr, * it is deleted. */ - void attach(T *p); + void attach(T* p); /** - * Attach the given pointer to the KSharedPtr. - * @see KSharedPtr::attach(T *p) + * Clear the pointer, i.e. make it a null pointer. */ - inline void attach(const KSharedPtr& o) { attach(o.d); } + void clear(); /** * Returns the number of references. @@ -194,7 +194,7 @@ } template -Q_INLINE_TEMPLATE void KSharedPtr::attach(T *p) +Q_INLINE_TEMPLATE void KSharedPtr::attach(T* p) { if (d != p) { T *x = p; @@ -206,10 +206,17 @@ } template +Q_INLINE_TEMPLATE void KSharedPtr::clear() +{ + attach((T*)0); +} + +template Q_INLINE_TEMPLATE void KSharedPtr::detach() { - if (d && d->ref>1) + if (d && d->ref>1) { attach(new T(*d)); + } } #endif ------=_Part_3566_13389642.1137239682825 Content-Type: application/octet-stream; name=kdelibs-explicit_KSharedPtr.diff Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="kdelibs-explicit_KSharedPtr.diff" Index: kate/part/katelayoutcache.cpp =================================================================== --- kate/part/katelayoutcache.cpp (revision 497943) +++ kate/part/katelayoutcache.cpp (working copy) @@ -154,9 +154,9 @@ } if (realLine < 0 || realLine >= m_renderer->doc()->lines()) - return 0L; + return KateLineLayoutPtr(); - KateLineLayoutPtr l = new KateLineLayout(m_renderer->doc()); + KateLineLayoutPtr l(new KateLineLayout(m_renderer->doc())); l->setLine(realLine, virtualLine); m_renderer->layoutLine(l, wrap() ? m_viewWidth : -1, enableLayoutCache); Q_ASSERT(l->isValid()); Index: kate/part/katelinerange.cpp =================================================================== --- kate/part/katelinerange.cpp (revision 497943) +++ kate/part/katelinerange.cpp (working copy) @@ -171,7 +171,7 @@ viewLine += viewLineCount(); Q_ASSERT(isValid()); Q_ASSERT(viewLine >= 0 && viewLine < viewLineCount()); - return KateTextLayout(const_cast(this), viewLine); + return KateTextLayout(KateLineLayoutPtr(const_cast(this)), viewLine); } int KateLineLayout::width( ) const Index: kate/part/katebuffer.cpp =================================================================== --- kate/part/katebuffer.cpp (revision 497943) +++ kate/part/katebuffer.cpp (working copy) @@ -1024,7 +1024,7 @@ // get the previous line, if we start at the beginning of this block // take the last line of the previous block - KateTextLine::Ptr prevLine = 0; + KateTextLine::Ptr prevLine; if ((startLine == buf->startLine()) && buf->prev() && (buf->prev()->lines() > 0)) prevLine = buf->prev()->line (buf->prev()->lines() - 1); @@ -1322,7 +1322,7 @@ else // init the block if no stream given ! { // fill in one empty line ! - KateTextLine::Ptr textLine = new KateTextLine (); + KateTextLine::Ptr textLine (new KateTextLine ()); m_stringList.push_back (textLine); m_lines++; @@ -1414,7 +1414,7 @@ } else { - KateTextLine::Ptr textLine = new KateTextLine (); + KateTextLine::Ptr textLine (new KateTextLine ()); textLine->insertText (0, length, unicodeData); m_stringList.push_back (textLine); } @@ -1531,7 +1531,7 @@ char *buf = rawData.data(); for (int i=0; i < m_lines; i++) { - KateTextLine::Ptr textLine = new KateTextLine (); + KateTextLine::Ptr textLine (new KateTextLine ()); buf = textLine->restore (buf); m_stringList.push_back (textLine); } Index: kate/part/katedocument.cpp =================================================================== --- kate/part/katedocument.cpp (revision 497943) +++ kate/part/katedocument.cpp (working copy) @@ -1274,7 +1274,7 @@ if (!nextLine || newLine) { - KateTextLine::Ptr textLine = new KateTextLine(); + KateTextLine::Ptr textLine(new KateTextLine()); textLine->insertText (0, pos, l->text()+col); l->truncate(col); @@ -1415,7 +1415,7 @@ removeTrailingSpace( line ); // old line - KateTextLine::Ptr tl = new KateTextLine(); + KateTextLine::Ptr tl(new KateTextLine()); tl->insertText (0, s.length(), s.unicode()); m_buffer->insertLine(line, tl); m_buffer->changeLine(line); Index: kate/part/kateautoindent.cpp =================================================================== --- kate/part/kateautoindent.cpp (revision 497943) +++ kate/part/kateautoindent.cpp (working copy) @@ -1226,7 +1226,7 @@ { prevIndent = 0; int firstChar; - KateTextLine::Ptr prevLine = 0; + KateTextLine::Ptr prevLine; // get the indentation of the first non-empty line while(true) { Index: kate/part/katebuffer.h =================================================================== --- kate/part/katebuffer.h (revision 497943) +++ kate/part/katebuffer.h (working copy) @@ -486,7 +486,7 @@ { KateBufBlock *buf = findBlock(i); if (!buf) - return 0; + return KateTextLine::Ptr(); if (i < m_lineHighlighted) return buf->line (i - buf->startLine()); @@ -511,7 +511,7 @@ { KateBufBlock *buf = findBlock(i); if (!buf) - return 0; + return KateTextLine::Ptr(); return buf->line(i - buf->startLine()); } Index: kcmshell/main.cpp =================================================================== --- kcmshell/main.cpp (revision 497943) +++ kcmshell/main.cpp (working copy) @@ -101,13 +101,13 @@ if (!service) { kdWarning(780) << "Could not find module '" << module << "'." << endl; - return 0; + return KService::Ptr(); } if(!KCModuleLoader::testModule( module )) { kdDebug(780) << "According to \"" << module << "\"'s test function, it should Not be loaded." << endl; - return 0; + return KService::Ptr(); } return service; Index: kinit/klauncher.cpp =================================================================== --- kinit/klauncher.cpp (revision 497943) +++ kinit/klauncher.cpp (working copy) @@ -911,7 +911,7 @@ KLauncher::start_service_by_name(const QString &serviceName, const QStringList &urls, const DCOPCStringList &envs, const DCOPCString& startup_id, bool blind) { - KService::Ptr service = 0; + KService::Ptr service; // Find service service = KService::serviceByName(serviceName); if (!service) @@ -928,7 +928,7 @@ KLauncher::start_service_by_desktop_path(const QString &serviceName, const QStringList &urls, const DCOPCStringList &envs, const DCOPCString& startup_id, bool blind) { - KService::Ptr service = 0; + KService::Ptr service; // Find service if (serviceName[0] == '/') { Index: kio/kfile/kdiroperator.cpp =================================================================== --- kio/kfile/kdiroperator.cpp (revision 497943) +++ kio/kfile/kdiroperator.cpp (working copy) @@ -830,11 +830,10 @@ return true; } - KMimeType *mt = fac->findFromPattern( *it1 ); + KMimeType::Ptr mt = fac->findFromPattern( *it1 ); if ( !mt ) continue; QString mime = mt->name(); - delete mt; // the "mimetypes" we get from the PreviewJob can be "image/*" // so we need to check in wildcard mode Index: kio/kio/kservicefactory.cpp =================================================================== --- kio/kio/kservicefactory.cpp (revision 497943) +++ kio/kio/kservicefactory.cpp (working copy) @@ -90,22 +90,21 @@ KService::Ptr KServiceFactory::findServiceByName(const QString &_name) { - if (!m_sycocaDict) return 0; // Error! + if (!m_sycocaDict) return KService::Ptr(); // Error! // Warning : this assumes we're NOT building a database // But since findServiceByName isn't called in that case... // [ see KServiceTypeFactory for how to do it if needed ] int offset = m_sycocaDict->find_string( _name ); - if (!offset) return 0; // Not found + if (!offset) return KService::Ptr(); // Not found - KService * newService = createEntry(offset); + KService::Ptr newService(createEntry(offset)); // Check whether the dictionary was right. if (newService && (newService->name() != _name)) { // No it wasn't... - delete newService; newService = 0; // Not found } return newService; @@ -113,22 +112,21 @@ KService::Ptr KServiceFactory::findServiceByDesktopName(const QString &_name) { - if (!m_nameDict) return 0; // Error! + if (!m_nameDict) return KService::Ptr(); // Error! // Warning : this assumes we're NOT building a database // But since this method isn't called in that case, we should be fine. // [ see KServiceTypeFactory for how to do it if needed ] int offset = m_nameDict->find_string( _name ); - if (!offset) return 0; // Not found + if (!offset) return KService::Ptr(); // Not found - KService * newService = createEntry(offset); + KService::Ptr newService(createEntry(offset)); // Check whether the dictionary was right. if (newService && (newService->desktopEntryName() != _name)) { // No it wasn't... - delete newService; newService = 0; // Not found } return newService; @@ -136,7 +134,7 @@ KService::Ptr KServiceFactory::findServiceByDesktopPath(const QString &_name) { - if (!m_relNameDict) return 0; // Error! + if (!m_relNameDict) return KService::Ptr(); // Error! // Warning : this assumes we're NOT building a database // But since this method isn't called in that case, we should be fine. @@ -145,10 +143,10 @@ int offset = m_relNameDict->find_string( _name ); if (!offset) { qDebug( "findServiceByDesktopPath: %s not found", qPrintable( _name ) ); - return 0; // Not found + return KService::Ptr(); // Not found } - KService * newService = createEntry(offset); + KService::Ptr newService(createEntry(offset)); if ( !newService ) qDebug( "findServiceByDesktopPath: createEntry failed!" ); // Check whether the dictionary was right. @@ -156,7 +154,6 @@ { qDebug( "the dictionary was wrong. desktopEntryPath=%s, name=%s", qPrintable( newService->desktopEntryPath() ), qPrintable( _name ) ); // No it wasn't... - delete newService; newService = 0; // Not found } return newService; @@ -164,22 +161,21 @@ KService::Ptr KServiceFactory::findServiceByMenuId(const QString &_menuId) { - if (!m_menuIdDict) return 0; // Error! + if (!m_menuIdDict) return KService::Ptr(); // Error! // Warning : this assumes we're NOT building a database // But since this method isn't called in that case, we should be fine. // [ see KServiceTypeFactory for how to do it if needed ] int offset = m_menuIdDict->find_string( _menuId ); - if (!offset) return 0; // Not found + if (!offset) return KService::Ptr(); // Not found - KService * newService = createEntry(offset); + KService::Ptr newService(createEntry(offset)); // Check whether the dictionary was right. if (newService && (newService->menuId() != _menuId)) { // No it wasn't... - delete newService; newService = 0; // Not found } return newService; Index: kio/kio/kmimetype.cpp =================================================================== --- kio/kio/kmimetype.cpp (revision 497943) +++ kio/kio/kmimetype.cpp (working copy) @@ -62,7 +62,7 @@ template class KSharedPtr; -KMimeType::Ptr KMimeType::s_pDefaultType = 0L; +KMimeType::Ptr KMimeType::s_pDefaultType; bool KMimeType::s_bChecked = false; void KMimeType::buildDefaultType() Index: kio/kio/kuserprofile.cpp =================================================================== --- kio/kio/kuserprofile.cpp (revision 497943) +++ kio/kio/kuserprofile.cpp (working copy) @@ -312,7 +312,7 @@ return (*itOff).service(); //kdDebug(7014) << "No offers, or none allowed as default" << endl; - return 0L; + return KService::Ptr(); } /********************************************* Index: kio/kio/krun.cpp =================================================================== --- kio/kio/krun.cpp (revision 497943) +++ kio/kio/krun.cpp (working copy) @@ -735,7 +735,7 @@ pid_t KRun::run( const QString& _exec, const KURL::List& _urls, const QString& _name, const QString& _icon, const QString&, const QString&) { - KService::Ptr service = new KService(_name, _exec, _icon); + KService::Ptr service(new KService(_name, _exec, _icon)); return run(*service, _urls); } Index: kio/kio/kservicegroupfactory.cpp =================================================================== --- kio/kio/kservicegroupfactory.cpp (revision 497943) +++ kio/kio/kservicegroupfactory.cpp (working copy) @@ -68,44 +68,44 @@ KServiceGroup::Ptr KServiceGroupFactory::findGroupByDesktopPath(const QString &_name, bool deep) { - if (!m_sycocaDict) return 0; // Error! + if (!m_sycocaDict) return KServiceGroup::Ptr(); // Error! // Warning : this assumes we're NOT building a database // But since findServiceByName isn't called in that case... // [ see KServiceTypeFactory for how to do it if needed ] int offset = m_sycocaDict->find_string( _name ); - if (!offset) return 0; // Not found + if (!offset) return KServiceGroup::Ptr(); // Not found - KServiceGroup::Ptr newGroup = createGroup(offset, deep); + KServiceGroup::Ptr newGroup(createGroup(offset, deep)); // Check whether the dictionary was right. if (newGroup && (newGroup->relPath() != _name)) { // No it wasn't... - return 0; // Not found + newGroup = 0; // Not found } return newGroup; } KServiceGroup::Ptr KServiceGroupFactory::findBaseGroup(const QString &_baseGroupName, bool deep) { - if (!m_baseGroupDict) return 0; // Error! + if (!m_baseGroupDict) return KServiceGroup::Ptr(); // Error! // Warning : this assumes we're NOT building a database // But since findServiceByName isn't called in that case... // [ see KServiceTypeFactory for how to do it if needed ] int offset = m_baseGroupDict->find_string( _baseGroupName ); - if (!offset) return 0; // Not found + if (!offset) return KServiceGroup::Ptr(); // Not found - KServiceGroup::Ptr newGroup = createGroup(offset, deep); + KServiceGroup::Ptr newGroup(createGroup(offset, deep)); // Check whether the dictionary was right. if (newGroup && (newGroup->baseGroupName() != _baseGroupName)) { // No it wasn't... - return 0; // Not found + newGroup = 0; // Not found } return newGroup; } Index: kio/kio/kservicegroup.cpp =================================================================== --- kio/kio/kservicegroup.cpp (revision 497943) +++ kio/kio/kservicegroup.cpp (working copy) @@ -307,7 +307,7 @@ static void addItem(KServiceGroup::List &sorted, const KSycocaEntry::Ptr &p, bool &addSeparator) { if (addSeparator && !sorted.isEmpty()) - sorted.append(new KServiceSeparator()); + sorted.append(KSycocaEntry::Ptr(new KServiceSeparator())); sorted.append(p); addSeparator = false; } Index: kio/kio/kservicetypefactory.cpp =================================================================== --- kio/kio/kservicetypefactory.cpp (revision 497943) +++ kio/kio/kservicetypefactory.cpp (working copy) @@ -110,10 +110,10 @@ return QVariant::Invalid; } -KMimeType * KServiceTypeFactory::findFromPattern(const QString &_filename, QString *match) +KMimeType::Ptr KServiceTypeFactory::findFromPattern(const QString &_filename, QString *match) { // Assume we're NOT building a database - if (!m_str) return 0; + if (!m_str) return KMimeType::Ptr(); // Get stream to the header QDataStream *str = m_str; @@ -205,10 +205,10 @@ if ( matchingOffset ) { KServiceType *newServiceType = createEntry( matchingOffset ); assert (newServiceType && newServiceType->isType( KST_KMimeType )); - return (KMimeType *) newServiceType; + return KMimeType::Ptr(static_cast(newServiceType)); } else - return 0; + return KMimeType::Ptr(); } KMimeType::List KServiceTypeFactory::allMimeTypes() Index: kio/kio/kservice.cpp =================================================================== --- kio/kio/kservice.cpp (revision 497943) +++ kio/kio/kservice.cpp (working copy) @@ -626,7 +626,7 @@ return service; if (!QDir::isRelativePath(_storageId) && QFile::exists(_storageId)) - return new KService(_storageId); + return KService::Ptr(new KService(_storageId)); QString tmp = _storageId; tmp = tmp.mid(tmp.lastIndexOf('/')+1); // Strip dir Index: kio/kio/kservicetypefactory.h =================================================================== --- kio/kio/kservicetypefactory.h (revision 497943) +++ kio/kio/kservicetypefactory.h (working copy) @@ -74,7 +74,7 @@ * @param _filename filename to check. * @param match if provided, returns the pattern that matched. */ - KMimeType * findFromPattern(const QString &_filename, QString *match = 0); + KMimeType::Ptr findFromPattern(const QString &_filename, QString *match = 0); /** * @return all mimetypes Index: kdecore/kconfig.cpp =================================================================== --- kdecore/kconfig.cpp (revision 497943) +++ kdecore/kconfig.cpp (working copy) @@ -268,7 +268,7 @@ KLockFile::Ptr KConfig::lockFile(bool bGlobal) { KConfigINIBackEnd *aBackEnd = dynamic_cast(backEnd); - if (!aBackEnd) return 0; + if (!aBackEnd) return KLockFile::Ptr(); return aBackEnd->lockFile(bGlobal); } @@ -323,16 +323,15 @@ { if (s_list) { - for(QList::ConstIterator it = s_list->begin(); - it != s_list->end(); ++it) + foreach (KSharedConfig* config, *s_list) { - if ((*it)->backEnd->fileName() == fileName && - (*it)->backEnd->bFileImmutable == immutable && - (*it)->backEnd->useKDEGlobals == useKDEGlobals ) - return (*it); + if (config->backEnd->fileName() == fileName && + config->backEnd->bFileImmutable == immutable && + config->backEnd->useKDEGlobals == useKDEGlobals ) + return KSharedConfig::Ptr(config); } } - return new KSharedConfig(fileName, immutable, useKDEGlobals); + return KSharedConfig::Ptr(new KSharedConfig(fileName, immutable, useKDEGlobals)); } KSharedConfig::KSharedConfig( const QString& fileName, bool readonly, bool usekdeglobals) Index: kdecore/kmountpoint.cpp =================================================================== --- kdecore/kmountpoint.cpp (revision 497943) +++ kdecore/kmountpoint.cpp (working copy) @@ -134,7 +134,7 @@ STRUCT_MNTENT fe; while (GETMNTENT(fstab, fe)) { - KMountPoint *mp = new KMountPoint; + KMountPoint::Ptr mp(new KMountPoint); mp->m_mountedFrom = QFile::decodeName(FSNAME(fe)); mp->m_mountPoint = QFile::decodeName(MOUNTPOINT(fe)); @@ -335,7 +335,7 @@ STRUCT_MNTENT fe; while (GETMNTENT(mnttab, fe)) { - KMountPoint *mp = new KMountPoint; + KMountPoint::Ptr mp(new KMountPoint); mp->m_mountedFrom = QFile::decodeName(FSNAME(fe)); mp->m_mountPoint = QFile::decodeName(MOUNTPOINT(fe)); Index: kdecore/kprotocolinfofactory.cpp =================================================================== --- kdecore/kprotocolinfofactory.cpp (revision 497943) +++ kdecore/kprotocolinfofactory.cpp (working copy) @@ -83,7 +83,7 @@ KProtocolInfo::Ptr KProtocolInfoFactory::findProtocol(const QString &protocol) { - if (!m_sycocaDict) return 0; // Error! + if (!m_sycocaDict) return KProtocolInfo::Ptr(); // Error! QMap::iterator it = m_cache.find(protocol); if (it != m_cache.end()) @@ -93,14 +93,14 @@ offset = m_sycocaDict->find_string( protocol ); - if (!offset) return 0; // Not found; + if (!offset) return KProtocolInfo::Ptr(); // Not found; - KProtocolInfo::Ptr info = createEntry(offset); + KProtocolInfo::Ptr info(createEntry(offset)); if (info && (info->name() != protocol)) { // No it wasn't... - return 0; // Not found + return KProtocolInfo::Ptr(); // Not found } m_cache.insert(protocol,info); return info; Index: kdecore/kconfigbackend.cpp =================================================================== --- kdecore/kconfigbackend.cpp (revision 497943) +++ kdecore/kconfigbackend.cpp (working copy) @@ -273,7 +273,7 @@ return d->localLockFile; } } - return 0; + return KLockFile::Ptr(); } KConfigBackEnd::KConfigBackEnd(KConfigBase *_config, Index: kdecore/tests/ksharedptrtest.cpp =================================================================== --- kdecore/tests/ksharedptrtest.cpp (revision 497943) +++ kdecore/tests/ksharedptrtest.cpp (working copy) @@ -44,7 +44,7 @@ SharedString s2 = QString::fromLatin1( "Foo" ); SharedString s3 = QString::fromLatin1( "Bar" ); - KSharedPtr u = new SharedString( s ); + KSharedPtru(new SharedString( s )); QCOMPARE( *u, s ); QVERIFY( u.isUnique() ); @@ -123,7 +123,7 @@ dtor_called = 0; { Base* obj = new Base; - KSharedPtr ptrBase = obj; + KSharedPtr ptrBase(obj); QCOMPARE( ptrBase.data(), obj ); QCOMPARE( dtor_called, 0 ); // no dtor called yet } @@ -142,7 +142,7 @@ dtor_called = 0; { Derived* obj = new Derived; - KSharedPtr ptrBase = obj; + KSharedPtr ptrBase(obj); // then we call some method that takes a KSharedPtr as argument // and there we downcast again: KSharedPtr ptrDerived = KSharedPtr::staticCast( ptrBase ); Index: kdecore/ksharedptr.h =================================================================== --- kdecore/ksharedptr.h (revision 497943) +++ kdecore/ksharedptr.h (working copy) @@ -55,7 +55,7 @@ * Creates a new pointer. * @param p the pointer */ - inline KSharedPtr( T* p ) // TODO: Make explicit + inline explicit KSharedPtr( T* p ) : d(p) { if(d) d->ref.ref(); } /** @@ -71,10 +71,11 @@ */ inline ~KSharedPtr() { if (d && !d->ref.deref()) delete d; } - inline KSharedPtr& operator= ( const KSharedPtr& o ) { attach(o); return *this; } - inline KSharedPtr& operator= ( T* p ) { attach(p); return *this; } + inline KSharedPtr& operator= ( const KSharedPtr& o ) { attach(o.d); return *this; } inline bool operator== ( const KSharedPtr& o ) const { return ( d == o.d ); } inline bool operator!= ( const KSharedPtr& o ) const { return ( d != o.d ); } + + inline KSharedPtr& operator= ( T* p ) { attach(p); return *this; } inline bool operator== ( const T* p ) const { return ( d == p ); } inline bool operator!= ( const T* p ) const { return ( d != p ); } @@ -106,17 +107,16 @@ inline T* operator->() { Q_ASSERT(d); return d; } /** - * Attach the given pointer to the KSharedPtr. + * Attach the given pointer to the current KSharedPtr. * If the previous shared pointer is not owned by any KSharedPtr, * it is deleted. */ - void attach(T *p); + void attach(T* p); /** - * Attach the given pointer to the KSharedPtr. - * @see KSharedPtr::attach(T *p) + * Clear the pointer, i.e. make it a null pointer. */ - inline void attach(const KSharedPtr& o) { attach(o.d); } + void clear(); /** * Returns the number of references. @@ -194,7 +194,7 @@ } template -Q_INLINE_TEMPLATE void KSharedPtr::attach(T *p) +Q_INLINE_TEMPLATE void KSharedPtr::attach(T* p) { if (d != p) { T *x = p; @@ -206,10 +206,17 @@ } template +Q_INLINE_TEMPLATE void KSharedPtr::clear() +{ + attach((T*)0); +} + +template Q_INLINE_TEMPLATE void KSharedPtr::detach() { - if (d && d->ref>1) + if (d && d->ref>1) { attach(new T(*d)); + } } #endif Index: kdecore/kdeversion.h =================================================================== --- kdecore/kdeversion.h (revision 497943) +++ kdecore/kdeversion.h (working copy) @@ -22,7 +22,7 @@ #include "kdelibs_export.h" -#define KDE_VERSION_STRING "3.9.02 (>= 20050906 DONTPORT)" +#define KDE_VERSION_STRING "3.9.02 (>= 20050906)" #define KDE_VERSION_MAJOR 3 #define KDE_VERSION_MINOR 9 #define KDE_VERSION_RELEASE 02 Index: kded/kbuildservicegroupfactory.cpp =================================================================== --- kded/kbuildservicegroupfactory.cpp (revision 497943) +++ kded/kbuildservicegroupfactory.cpp (working copy) @@ -60,7 +60,7 @@ void KBuildServiceGroupFactory::addNewEntryTo( const QString &menuName, const KService::Ptr& newEntry) { KSycocaEntry::Ptr ptr = m_entryDict->value(menuName); - KServiceGroup::Ptr entry = 0; + KServiceGroup::Ptr entry; if (ptr && ptr->isType(KST_KServiceGroup)) entry = KServiceGroup::Ptr::staticCast( ptr ); @@ -102,7 +102,7 @@ } - KServiceGroup::Ptr parentEntry = 0; + KServiceGroup::Ptr parentEntry; ptr = m_entryDict->value(parent); if (ptr && ptr->isType(KST_KServiceGroup)) parentEntry = KServiceGroup::Ptr::staticCast( ptr ); @@ -124,7 +124,7 @@ { QString name = "#parent#"+parent; - KServiceGroup::Ptr entry = 0; + KServiceGroup::Ptr entry; KSycocaEntry::Ptr ptr = m_entryDict->value(name); if (ptr && ptr->isType(KST_KServiceGroup)) entry = KServiceGroup::Ptr::staticCast( ptr ); Index: kded/kbuildsycoca.cpp =================================================================== --- kded/kbuildsycoca.cpp (revision 497943) +++ kded/kbuildsycoca.cpp (working copy) @@ -192,7 +192,7 @@ { timeStamp = KGlobal::dirs()->calcResourceHash( g_resource, file, true); } - KSycocaEntry::Ptr entry = 0; + KSycocaEntry::Ptr entry; if (g_allEntries) { assert(g_ctimeDict); @@ -243,7 +243,7 @@ g_tempStorage.append(entry); return entry; } - return 0; + return KSycocaEntry::Ptr(); } // Callback for VFolderMenu @@ -384,7 +384,7 @@ VFolderMenu::SubMenu *kdeMenu = g_vfolder->parseMenu("applications.menu", true); - KServiceGroup::Ptr entry = g_bsgf->addNew("/", kdeMenu->directoryFile, 0, false); + KServiceGroup::Ptr entry = g_bsgf->addNew("/", kdeMenu->directoryFile, KServiceGroup::Ptr(), false); entry->setLayoutInfo(kdeMenu->layoutList); createMenu(QString(), QString(), kdeMenu); @@ -438,7 +438,7 @@ timeStamp = KGlobal::dirs()->calcResourceHash( g_resource, directoryFile, true); } - KServiceGroup::Ptr entry = 0; + KServiceGroup::Ptr entry; if (g_allEntries) { quint32 oldTimestamp = g_ctimeDict->value( directoryFile, 0 ); Index: kded/vfolder_menu.cpp =================================================================== --- kded/vfolder_menu.cpp (revision 497943) +++ kded/vfolder_menu.cpp (working copy) @@ -337,7 +337,7 @@ return s; } } - return 0; + return KService::Ptr(); } void @@ -973,7 +973,7 @@ if (!fn.endsWith(".desktop")) continue; - KService::Ptr service = 0; + KService::Ptr service; emit newService(pathfn, &service); if (service) addApplication(prefix+fn, service); @@ -1020,7 +1020,7 @@ if (files.indexIn(*it) != -1) { QString name = *it; - KService::Ptr service = 0; + KService::Ptr service; emit newService(name, &service); if (service && !m_forcedLegacyLoad) @@ -1092,7 +1092,7 @@ if (!fn.endsWith(".desktop")) continue; - KService::Ptr service = 0; + KService::Ptr service; emit newService(pathfn, &service); if (service) { Index: dnssd/servicebrowser.cpp =================================================================== --- dnssd/servicebrowser.cpp (revision 497943) +++ dnssd/servicebrowser.cpp (working copy) @@ -115,7 +115,7 @@ if (it != itEnd) { if (success) { d->m_services+=(*it); - emit serviceAdded(svr); + emit serviceAdded(RemoteService::Ptr(svr)); } d->m_duringResolve.remove(it); queryFinished(); Index: dnssd/query.cpp =================================================================== --- dnssd/query.cpp (revision 497943) +++ dnssd/query.cpp (working copy) @@ -100,8 +100,8 @@ if (event->type()==QEvent::User+SD_ADDREMOVE) { AddRemoveEvent *aev = static_cast(event); // m_type has useless trailing dot - RemoteService* svr = new RemoteService(aev->m_name+"."+ - aev->m_type.left(aev->m_type.length()-1)+"."+aev->m_domain); + RemoteService::Ptr svr(new RemoteService(aev->m_name+"."+ + aev->m_type.left(aev->m_type.length()-1)+"."+aev->m_domain)); if (aev->m_op==AddRemoveEvent::Add) emit serviceAdded(svr); else emit serviceRemoved(svr); d->m_finished = aev->m_last; ------=_Part_3566_13389642.1137239682825--