Change BObjectList to take "owning" as a template parameter and adjust all consumers.

Since BObjectList is a template class, this only breaks ABI where
BObjectList was exposed in public methods, and even then it's only
a name mangling break and we should be able to add compatibility
methods if necessary.

(The old "bool owning" member variable is left intact for ABI
compatibility, for the moment, though it's otherwise unused now.)

Tracker's PoseList is the only remaining type that has a "bool owning"
switch in the constructor rather than template parameters.

This should significantly improve the output of static code analysis
tools that previously detected list operations as causing use-after-frees
and double-frees, as well as make code maintenance easier by making it
easier to determine what list owns (or does not own) an object.
It should also be a minor performance optimization, since the branches
for calls to delete/free should now be optimized out altogether.

Still boots to desktop and Tracker, Deskbar, Debugger all tested
and verified as working.

Change-Id: If2a24a6f0d22e7a506ef554fcfdd328907279ed4
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8915
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
Augustin Cavalier
2025-02-06 00:06:32 +00:00
committed by waddlesplash
parent 007126ed6f
commit cbfbbf6d4d
247 changed files with 761 additions and 705 deletions
@@ -42,7 +42,7 @@ public:
virtual ~SpecificImageDebugInfo();
virtual status_t GetFunctions(
const BObjectList<SymbolInfo>& symbols,
const BObjectList<SymbolInfo, true>& symbols,
BObjectList<FunctionDebugInfo>& functions)
= 0;
// returns references
@@ -93,7 +93,7 @@ public:
protected:
static status_t GetFunctionsFromSymbols(
const BObjectList<SymbolInfo>& symbols,
const BObjectList<SymbolInfo, true>& symbols,
BObjectList<FunctionDebugInfo>& functions,
DebuggerInterface* interface,
const ImageInfo& imageInfo,
@@ -96,7 +96,7 @@ private:
struct SourceFileEntry;
struct SourceFileHashDefinition;
typedef BObjectList<SpecificTeamDebugInfo> SpecificInfoList;
typedef BObjectList<SpecificTeamDebugInfo, true> SpecificInfoList;
typedef BObjectList<ImageDebugInfo> ImageList;
typedef BOpenHashTable<FunctionHashDefinition> FunctionTable;
typedef BOpenHashTable<SourceFileHashDefinition> SourceFileTable;
+2 -2
View File
@@ -164,8 +164,8 @@ public:
private:
struct SymbolLookupSource;
typedef BObjectList<ElfSection> SectionList;
typedef BObjectList<ElfSegment> SegmentList;
typedef BObjectList<ElfSection, true> SectionList;
typedef BObjectList<ElfSegment, true> SegmentList;
private:
template<typename ElfClass>
@@ -52,7 +52,7 @@ public:
private:
struct Line;
typedef BObjectList<Line> LineList;
typedef BObjectList<Line, true> LineList;
typedef BObjectList<ContiguousStatement> StatementList;
private:
@@ -138,7 +138,7 @@ public:
{ return !(*this == other); }
private:
typedef BObjectList<TypeComponent> ComponentList;
typedef BObjectList<TypeComponent, true> ComponentList;
private:
ComponentList fComponents;
+1 -1
View File
@@ -30,7 +30,7 @@ struct Range {
};
class RangeList : private BObjectList<Range>
class RangeList : private BObjectList<Range, true>
{
public:
RangeList();
+1 -1
View File
@@ -43,7 +43,7 @@ public:
uint32 which, uint32 flags, BIcon*& _icon);
private:
typedef BObjectList<BBitmap> BitmapList;
typedef BObjectList<BBitmap, true> BitmapList;
private:
static BBitmap* _ConvertToRGB32(const BBitmap* bitmap,
+1 -1
View File
@@ -89,7 +89,7 @@ public:
uint32 BytesPerRow();
private:
friend class BObjectList<BPrivateScreen>;
friend class BObjectList<BPrivateScreen, true>;
BPrivateScreen(int32 id);
~BPrivateScreen();
+1 -1
View File
@@ -46,7 +46,7 @@ private:
private:
BNetworkCookieJar fCookieJar;
BHttpAuthenticationMap* fAuthenticationMap;
typedef BObjectList<const BCertificate> BCertificateSet;
typedef BObjectList<const BCertificate, true> BCertificateSet;
BCertificateSet fCertificates;
BString fProxyHost;
@@ -116,10 +116,8 @@ protected:
const BPackageVersion& version,
BHPKGAttributeID attributeID
= kDefaultVersionAttributeID);
void RegisterPackageResolvableExpressionList(
PackageAttributeList& attributeList,
const BObjectList<
BPackageResolvableExpression>& list,
void RegisterPackageResolvableExpressionList(PackageAttributeList& attributeList,
const BObjectList<BPackageResolvableExpression, true>& list,
uint8 id);
PackageAttribute* AddStringAttribute(BHPKGAttributeID id,
@@ -53,10 +53,10 @@ public:
class ClientInstallationInterface;
class UserInteractionHandler;
typedef BObjectList<RemoteRepository> RemoteRepositoryList;
typedef BObjectList<RemoteRepository, true> RemoteRepositoryList;
typedef BObjectList<InstalledRepository> InstalledRepositoryList;
typedef BObjectList<BSolverPackage> PackageList;
typedef BObjectList<Transaction> TransactionList;
typedef BObjectList<Transaction, true> TransactionList;
enum {
B_ADD_INSTALLED_REPOSITORIES = 0x01,
@@ -245,7 +245,7 @@ public:
void ApplyChanges();
private:
PackageList fDisabledPackages;
BObjectList<BSolverPackage, true> fDisabledPackages;
PackageList fPackagesToActivate;
PackageList fPackagesToDeactivate;
const char* fInitialName;
+2 -2
View File
@@ -44,8 +44,8 @@ public:
const void* pointer);
private:
BObjectList<BMessage> fStack;
BObjectList<BString> fNameStack;
BObjectList<BMessage> fStack;
BObjectList<BString, true> fNameStack;
BMessage* fCurrentMessage;
};
+2 -2
View File
@@ -33,8 +33,8 @@ public:
private:
struct Column;
typedef BObjectList<Column> ColumnList;
typedef BObjectList<BStringList> RowList;
typedef BObjectList<Column, true> ColumnList;
typedef BObjectList<BStringList, true> RowList;
private:
ColumnList fColumns;
+4 -4
View File
@@ -81,17 +81,17 @@ private:
class ThreadSequence : private SimpleThread {
public:
static void Launch(BObjectList<FunctionObject>*, bool async = true,
static void Launch(BObjectList<FunctionObject, true>*, bool async = true,
int32 priority = B_LOW_PRIORITY);
private:
ThreadSequence(BObjectList<FunctionObject>*, int32 priority);
ThreadSequence(BObjectList<FunctionObject, true>*, int32 priority);
~ThreadSequence();
virtual void Run();
static void Run(BObjectList<FunctionObject>*list);
static void Run(BObjectList<FunctionObject, true>* list);
BObjectList<FunctionObject>* fFunctorList;
BObjectList<FunctionObject, true>* fFunctorList;
};
+1 -1
View File
@@ -85,7 +85,7 @@ private:
private:
BLocker *fLocker;
BObjectList<BDiskDevice> fDevices;
BObjectList<BDiskDevice, true> fDevices;
bool fSubscribed;
};
+1 -1
View File
@@ -55,7 +55,7 @@ protected:
// always invoked with index1 < index2
private:
typedef BObjectList<BDirectory> DirectoryList;
typedef BObjectList<BDirectory, true> DirectoryList;
struct EntryNameSet;
private:
+3 -3
View File
@@ -19,7 +19,7 @@ class BPartitionParameterEditor;
class BDiskDeviceVisitor;
class BDiskSystem;
class BMutablePartition;
template <class T> class BObjectList;
template <class T, bool O> class BObjectList;
class BPartitioningInfo;
class BPath;
class BVolume;
@@ -106,9 +106,9 @@ public:
status_t ValidateResize(off_t* size) const;
status_t Resize(off_t size);
bool CanMove(BObjectList<BPartition>*
bool CanMove(BObjectList<BPartition, false>*
unmovableDescendants = NULL,
BObjectList<BPartition>*
BObjectList<BPartition, false>*
movableOnlyIfUnmounted = NULL) const;
status_t ValidateMove(off_t* newOffset) const;
status_t Move(off_t newOffset);
+3 -3
View File
@@ -9,10 +9,10 @@
#include <ObjectList.h>
template<class T>
class BObjectList<T>::Private {
template<class T, bool O>
class BObjectList<T, O>::Private {
public:
Private(BObjectList<T>* objectList)
Private(BObjectList<T, O>* objectList)
:
fObjectList(objectList)
{
+2 -2
View File
@@ -46,7 +46,7 @@ All rights reserved.
#include "SlowMenu.h"
template<class T> class BObjectList;
template<class T, bool O> class BObjectList;
class BMenuItem;
@@ -139,7 +139,7 @@ protected:
// menu building state
uint8 fFlags;
BObjectList<BMenuItem>* fItemList;
BObjectList<BMenuItem, false>* fItemList;
EntryListBase* fContainer;
bool fIteratingDesktop;