From b82c72089aae180ed4bd639c7c64d04869423bab Mon Sep 17 00:00:00 2001 From: Philippe Canal Date: Wed, 23 Apr 2025 15:46:16 -0500 Subject: [PATCH 1/6] [format] Use AlignFunctionDeclarations from clang-format 20.1.0 --- .clang-format | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.clang-format b/.clang-format index 1d342e0ba7900..5b7ace22e5533 100644 --- a/.clang-format +++ b/.clang-format @@ -3,7 +3,11 @@ AccessModifierOffset: -3 AlignAfterOpenBracket: Align AlignConsecutiveAssignments: None # This would be nice to have but seems to also (mis)align function parameters -AlignConsecutiveDeclarations: None +# AlignFunctionDeclarations: true +AlignConsecutiveDeclarations: + Enabled: true + # Part of clang-format 20.1.0 + AlignFunctionDeclarations: true AlignEscapedNewlines: Left AlignOperands: true AlignTrailingComments: true From 257db7d4b68b9d0df7d95685834d2febfae327b1 Mon Sep 17 00:00:00 2001 From: Philippe Canal Date: Tue, 26 Aug 2025 15:55:30 -0500 Subject: [PATCH 2/6] DO NOT MERGE: spurrious change to trigger clang-format of TObject --- core/base/inc/TObject.h | 1 - core/base/src/TObject.cxx | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/core/base/inc/TObject.h b/core/base/inc/TObject.h index c81a3a0944fef..3119ed5a1449a 100644 --- a/core/base/inc/TObject.h +++ b/core/base/inc/TObject.h @@ -12,7 +12,6 @@ #ifndef ROOT_TObject #define ROOT_TObject - // #include "RConfigure.h" // included via Rtypes.h #include "Rtypes.h" #include "TStorage.h" diff --git a/core/base/src/TObject.cxx b/core/base/src/TObject.cxx index a00fbea945dc1..e8d657324f40f 100644 --- a/core/base/src/TObject.cxx +++ b/core/base/src/TObject.cxx @@ -37,6 +37,7 @@ class hierarchies (watch out for overlaps). that the object was allocated on the heap). */ + #include #if !defined(WIN32) && !defined(__MWERKS__) && !defined(R__SOLARIS) #include From a020a4627a64b609213d1707d0400faf88a20773 Mon Sep 17 00:00:00 2001 From: Philippe Canal Date: Tue, 26 Aug 2025 16:32:07 -0500 Subject: [PATCH 3/6] [ci] install and use clang-format 20 --- .github/workflows/code_analysis.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/code_analysis.yml b/.github/workflows/code_analysis.yml index 7bc220ab60088..c43b1d5adae13 100644 --- a/.github/workflows/code_analysis.yml +++ b/.github/workflows/code_analysis.yml @@ -37,7 +37,11 @@ jobs: - name: Determine merge base run: echo "MERGE_BASE=$(git merge-base ${{ github.event.pull_request.base.sha }} HEAD)" >> $GITHUB_ENV - name: install clang-format - run: sudo apt-get install -y clang-format + run: | + wget https://apt.llvm.org/llvm.sh + chmod u+x ./llvm.sh + sudo ./llvm.sh 20 + sudo apt-get install -y clang-format-20 - name: run clang-format script run: .ci/format_script.sh From bd18b80575c7af10068d074746e1150d80ccac59 Mon Sep 17 00:00:00 2001 From: Philippe Canal Date: Tue, 26 Aug 2025 17:06:12 -0500 Subject: [PATCH 4/6] [ci] use git-clang-format 20 --- .github/workflows/code_analysis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/code_analysis.yml b/.github/workflows/code_analysis.yml index c43b1d5adae13..39fc061e99722 100644 --- a/.github/workflows/code_analysis.yml +++ b/.github/workflows/code_analysis.yml @@ -42,6 +42,7 @@ jobs: chmod u+x ./llvm.sh sudo ./llvm.sh 20 sudo apt-get install -y clang-format-20 + PATH=/usr/lib/llvm-20/bin:${PATH} - name: run clang-format script run: .ci/format_script.sh From 7a970a7404b5f341d928f343c85dec4be698255e Mon Sep 17 00:00:00 2001 From: Philippe Canal Date: Tue, 26 Aug 2025 17:12:49 -0500 Subject: [PATCH 5/6] [ci] use git-clang-format 20 --- .github/workflows/code_analysis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/code_analysis.yml b/.github/workflows/code_analysis.yml index 39fc061e99722..1b3b93cf9390a 100644 --- a/.github/workflows/code_analysis.yml +++ b/.github/workflows/code_analysis.yml @@ -44,7 +44,9 @@ jobs: sudo apt-get install -y clang-format-20 PATH=/usr/lib/llvm-20/bin:${PATH} - name: run clang-format script - run: .ci/format_script.sh + run: | + PATH=/usr/lib/llvm-20/bin:${PATH} + .ci/format_script.sh ruff: if: | From d1ebb0a0378cee298fd4f0911bb05cd9358347c0 Mon Sep 17 00:00:00 2001 From: Philippe Canal Date: Tue, 26 Aug 2025 17:17:23 -0500 Subject: [PATCH 6/6] [NFC] clang-format-20 TObject.cxx and .h --- core/base/inc/TObject.h | 220 ++++++++++++++++++++------------------ core/base/src/TObject.cxx | 208 ++++++++++++++++++----------------- 2 files changed, 220 insertions(+), 208 deletions(-) diff --git a/core/base/inc/TObject.h b/core/base/inc/TObject.h index 3119ed5a1449a..be4b00901ab59 100644 --- a/core/base/inc/TObject.h +++ b/core/base/inc/TObject.h @@ -34,27 +34,30 @@ class TTimer; namespace ROOT { namespace Internal { - bool DeleteChangesMemoryImpl(); -}} +bool DeleteChangesMemoryImpl(); +} +} // namespace ROOT class TObject { private: - UInt_t fUniqueID; ///< object unique identifier - UInt_t fBits; ///< bit field status word + UInt_t fUniqueID; ///< object unique identifier + UInt_t fBits; ///< bit field status word - static Longptr_t fgDtorOnly; ///< object for which to call dtor only (i.e. no delete) - static Bool_t fgObjectStat; ///< if true keep track of objects in TObjectTable + static Longptr_t fgDtorOnly; ///< object for which to call dtor only (i.e. no delete) + static Bool_t fgObjectStat; ///< if true keep track of objects in TObjectTable static void AddToTObjectTable(TObject *); protected: - void MakeZombie() { fBits |= kZombie; } + void MakeZombie() { fBits |= kZombie; } virtual void DoError(int level, const char *location, const char *fmt, va_list va) const; - static void SavePrimitiveConstructor(std::ostream &out, TClass *cl, const char *variable_name, const char *constructor_agrs = "", Bool_t empty_line = kTRUE); + static void SavePrimitiveConstructor(std::ostream &out, TClass *cl, const char *variable_name, + const char *constructor_agrs = "", Bool_t empty_line = kTRUE); - static TString SavePrimitiveVector(std::ostream &out, const char *prefix, Int_t len, Double_t *arr, Bool_t empty_line = kFALSE); + static TString + SavePrimitiveVector(std::ostream &out, const char *prefix, Int_t len, Double_t *arr, Bool_t empty_line = kFALSE); static void SavePrimitiveDraw(std::ostream &out, const char *variable_name, Option_t *option = nullptr); @@ -64,38 +67,38 @@ class TObject { //----- in different class hierarchies (make sure there is no overlap in //----- any given hierarchy). enum EStatusBits { - kCanDelete = BIT(0), ///< if object in a list can be deleted + kCanDelete = BIT(0), ///< if object in a list can be deleted // 2 is taken by TDataMember - kMustCleanup = BIT(3), ///< if object destructor must call RecursiveRemove() - kIsReferenced = BIT(4), ///< if object is referenced by a TRef or TRefArray - kHasUUID = BIT(5), ///< if object has a TUUID (its fUniqueID=UUIDNumber) - kCannotPick = BIT(6), ///< if object in a pad cannot be picked + kMustCleanup = BIT(3), ///< if object destructor must call RecursiveRemove() + kIsReferenced = BIT(4), ///< if object is referenced by a TRef or TRefArray + kHasUUID = BIT(5), ///< if object has a TUUID (its fUniqueID=UUIDNumber) + kCannotPick = BIT(6), ///< if object in a pad cannot be picked // 7 is taken by TAxis and TClass. - kNoContextMenu = BIT(8), ///< if object does not want context menu + kNoContextMenu = BIT(8), ///< if object does not want context menu // 9, 10 are taken by TH1, TF1, TAxis and a few others // 12 is taken by TAxis - kInvalidObject = BIT(13) ///< if object ctor succeeded but object should not be used + kInvalidObject = BIT(13) ///< if object ctor succeeded but object should not be used }; enum EDeprecatedStatusBits { - kObjInCanvas = BIT(3) ///< for backward compatibility only, use kMustCleanup + kObjInCanvas = BIT(3) ///< for backward compatibility only, use kMustCleanup }; //----- Private bits, clients can only test but not change them enum { - kIsOnHeap = 0x01000000, ///< object is on heap - kNotDeleted = 0x02000000, ///< object has not been deleted - kZombie = 0x04000000, ///< object ctor failed - kInconsistent = 0x08000000, ///< class overload Hash but does call RecursiveRemove in destructor - // kCheckedHash = 0x10000000, ///< CheckedHash has check for the consistency of Hash/RecursiveRemove - kBitMask = 0x00ffffff + kIsOnHeap = 0x01000000, ///< object is on heap + kNotDeleted = 0x02000000, ///< object has not been deleted + kZombie = 0x04000000, ///< object ctor failed + kInconsistent = 0x08000000, ///< class overload Hash but does call RecursiveRemove in destructor + // kCheckedHash = 0x10000000, ///< CheckedHash has check for the consistency of Hash/RecursiveRemove + kBitMask = 0x00ffffff }; //----- Write() options enum { - kSingleKey = BIT(0), ///< write collection with single key - kOverwrite = BIT(1), ///< overwrite existing object with same name - kWriteDelete = BIT(2), ///< write object, then delete previous key with same name + kSingleKey = BIT(0), ///< write collection with single key + kOverwrite = BIT(1), ///< overwrite existing object with same name + kWriteDelete = BIT(2), ///< write object, then delete previous key with same name }; protected: @@ -108,31 +111,30 @@ class TObject { ///< To take advantage of this feature the class needs to overload `TObject::Write` ///< and use this enum value accordingly. (See `TTree::Write` and `TObject::Write`) ///< Do not use, this feature will be migrate to the Merge function (See TClass and TTree::Merge) - kOnlyPrepStep = BIT(3) + kOnlyPrepStep = BIT(3) }; public: - TObject(); TObject(const TObject &object) noexcept; TObject &operator=(const TObject &rhs) noexcept; virtual ~TObject(); - virtual void AppendPad(Option_t *option=""); + virtual void AppendPad(Option_t *option = ""); virtual void Browse(TBrowser *b); virtual const char *ClassName() const; - virtual void Clear(Option_t * /*option*/ ="") { } - ULong_t CheckedHash(); // Not virtual - virtual TObject *Clone(const char *newname="") const; + virtual void Clear(Option_t */*option*/ = "") {} + ULong_t CheckedHash(); // Not virtual + virtual TObject *Clone(const char *newname = "") const; virtual Int_t Compare(const TObject *obj) const; virtual void Copy(TObject &object) const; - virtual void Delete(Option_t *option=""); // *MENU* + virtual void Delete(Option_t *option = ""); // *MENU* virtual Int_t DistancetoPrimitive(Int_t px, Int_t py); - virtual void Draw(Option_t *option=""); - virtual void DrawClass() const; // *MENU* - virtual TObject *DrawClone(Option_t *option="") const; // *MENU* - virtual void Dump() const; // *MENU* - virtual void Execute(const char *method, const char *params, Int_t *error = nullptr); + virtual void Draw(Option_t *option = ""); + virtual void DrawClass() const; // *MENU* + virtual TObject *DrawClone(Option_t *option = "") const; // *MENU* + virtual void Dump() const; // *MENU* + virtual void Execute(const char *method, const char *params, Int_t *error = nullptr); virtual void Execute(TMethod *method, TObjArray *params, Int_t *error = nullptr); virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py); virtual TObject *FindObject(const char *name) const; @@ -145,7 +147,7 @@ class TObject { virtual char *GetObjectInfo(Int_t px, Int_t py) const; virtual const char *GetTitle() const; virtual Bool_t HandleTimer(TTimer *timer); - Bool_t HasInconsistentHash() const; + Bool_t HasInconsistentHash() const; virtual ULong_t Hash() const; virtual Bool_t InheritsFrom(const char *classname) const; virtual Bool_t InheritsFrom(const TClass *cl) const; @@ -157,20 +159,20 @@ class TObject { R__ALWAYS_INLINE Bool_t IsOnHeap() const { return TestBit(kIsOnHeap); } R__ALWAYS_INLINE Bool_t IsZombie() const { return TestBit(kZombie); } - virtual Bool_t Notify(); - virtual void ls(Option_t *option="") const; - virtual void Paint(Option_t *option=""); - virtual void Pop(); - virtual void Print(Option_t *option="") const; - virtual Int_t Read(const char *name); - virtual void RecursiveRemove(TObject *obj); - virtual void SaveAs(const char *filename="",Option_t *option="") const; // *MENU* - virtual void SavePrimitive(std::ostream &out, Option_t *option = ""); - virtual void SetDrawOption(Option_t *option=""); // *MENU* - virtual void SetUniqueID(UInt_t uid); - virtual void UseCurrentStyle(); - virtual Int_t Write(const char *name = nullptr, Int_t option = 0, Int_t bufsize = 0); - virtual Int_t Write(const char *name = nullptr, Int_t option = 0, Int_t bufsize = 0) const; + virtual Bool_t Notify(); + virtual void ls(Option_t *option = "") const; + virtual void Paint(Option_t *option = ""); + virtual void Pop(); + virtual void Print(Option_t *option = "") const; + virtual Int_t Read(const char *name); + virtual void RecursiveRemove(TObject *obj); + virtual void SaveAs(const char *filename = "", Option_t *option = "") const; // *MENU* + virtual void SavePrimitive(std::ostream &out, Option_t *option = ""); + virtual void SetDrawOption(Option_t *option = ""); // *MENU* + virtual void SetUniqueID(UInt_t uid); + virtual void UseCurrentStyle(); + virtual Int_t Write(const char *name = nullptr, Int_t option = 0, Int_t bufsize = 0); + virtual Int_t Write(const char *name = nullptr, Int_t option = 0, Int_t bufsize = 0) const; /// IsDestructed /// @@ -183,55 +185,55 @@ class TObject { Bool_t IsDestructed() const { return !TestBit(kNotDeleted); } //----- operators - void *operator new(size_t sz) { return TStorage::ObjectAlloc(sz); } - void *operator new[](size_t sz) { return TStorage::ObjectAllocArray(sz); } - void *operator new(size_t sz, void *vp) { return TStorage::ObjectAlloc(sz, vp); } - void *operator new[](size_t sz, void *vp) { return TStorage::ObjectAlloc(sz, vp); } - void operator delete(void *ptr); - void operator delete[](void *ptr); - void operator delete(void*, size_t); - void operator delete[](void*, size_t); - void operator delete(void *ptr, void *vp); - void operator delete[](void *ptr, void *vp); + void *operator new(size_t sz) { return TStorage::ObjectAlloc(sz); } + void *operator new[](size_t sz) { return TStorage::ObjectAllocArray(sz); } + void *operator new(size_t sz, void *vp) { return TStorage::ObjectAlloc(sz, vp); } + void *operator new[](size_t sz, void *vp) { return TStorage::ObjectAlloc(sz, vp); } + void operator delete(void *ptr); + void operator delete[](void *ptr); + void operator delete(void *, size_t); + void operator delete[](void *, size_t); + void operator delete(void *ptr, void *vp); + void operator delete[](void *ptr, void *vp); //----- bit manipulation - void SetBit(UInt_t f, Bool_t set); - void SetBit(UInt_t f) { fBits |= f & kBitMask; } - void ResetBit(UInt_t f) { fBits &= ~(f & kBitMask); } - R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const { return (Bool_t) ((fBits & f) != 0); } - Int_t TestBits(UInt_t f) const { return (Int_t) (fBits & f); } - void InvertBit(UInt_t f) { fBits ^= f & kBitMask; } + void SetBit(UInt_t f, Bool_t set); + void SetBit(UInt_t f) { fBits |= f & kBitMask; } + void ResetBit(UInt_t f) { fBits &= ~(f & kBitMask); } + R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const { return (Bool_t)((fBits & f) != 0); } + Int_t TestBits(UInt_t f) const { return (Int_t)(fBits & f); } + void InvertBit(UInt_t f) { fBits ^= f & kBitMask; } //---- error handling - virtual void Info(const char *method, const char *msgfmt, ...) const + virtual void Info(const char *method, const char *msgfmt, ...) const #if defined(__GNUC__) - __attribute__((format(printf, 3, 4))) /* 1 is the this pointer */ + __attribute__((format(printf, 3, 4))) /* 1 is the this pointer */ #endif - ; - virtual void Warning(const char *method, const char *msgfmt, ...) const + ; + virtual void Warning(const char *method, const char *msgfmt, ...) const #if defined(__GNUC__) - __attribute__((format(printf, 3, 4))) /* 1 is the this pointer */ + __attribute__((format(printf, 3, 4))) /* 1 is the this pointer */ #endif - ; - virtual void Error(const char *method, const char *msgfmt, ...) const + ; + virtual void Error(const char *method, const char *msgfmt, ...) const #if defined(__GNUC__) - __attribute__((format(printf, 3, 4))) /* 1 is the this pointer */ + __attribute__((format(printf, 3, 4))) /* 1 is the this pointer */ #endif - ; - virtual void SysError(const char *method, const char *msgfmt, ...) const + ; + virtual void SysError(const char *method, const char *msgfmt, ...) const #if defined(__GNUC__) - __attribute__((format(printf, 3, 4))) /* 1 is the this pointer */ + __attribute__((format(printf, 3, 4))) /* 1 is the this pointer */ #endif - ; - virtual void Fatal(const char *method, const char *msgfmt, ...) const + ; + virtual void Fatal(const char *method, const char *msgfmt, ...) const #if defined(__GNUC__) - __attribute__((format(printf, 3, 4))) /* 1 is the this pointer */ + __attribute__((format(printf, 3, 4))) /* 1 is the this pointer */ #endif - ; + ; - void AbstractMethod(const char *method) const; - void MayNotUse(const char *method) const; - void Obsolete(const char *method, const char *asOfVers, const char *removedFromVers) const; + void AbstractMethod(const char *method) const; + void MayNotUse(const char *method) const; + void Obsolete(const char *method, const char *asOfVers, const char *removedFromVers) const; //---- static functions static Longptr_t GetDtorOnly(); @@ -242,7 +244,7 @@ class TObject { friend class TClonesArray; // needs to reset kNotDeleted in fBits friend bool ROOT::Internal::DeleteChangesMemoryImpl(); - ClassDef(TObject,1) //Basic ROOT object + ClassDef(TObject, 1) // Basic ROOT object }; //////////////////////////////////////////////////////////////////////////////// @@ -262,9 +264,11 @@ inline TObject::TObject() : fBits(kNotDeleted) // Need to leave fUniqueID unset fUniqueID = 0; #ifdef R__WIN32 - if (R__unlikely(GetObjectStat())) TObject::AddToTObjectTable(this); + if (R__unlikely(GetObjectStat())) + TObject::AddToTObjectTable(this); #else - if (R__unlikely(fgObjectStat)) TObject::AddToTObjectTable(this); + if (R__unlikely(fgObjectStat)) + TObject::AddToTObjectTable(this); #endif } @@ -286,9 +290,11 @@ inline TObject::TObject(const TObject &obj) noexcept fUniqueID = obj.fUniqueID; // when really unique don't copy #ifdef R__WIN32 - if (R__unlikely(GetObjectStat())) TObject::AddToTObjectTable(this); + if (R__unlikely(GetObjectStat())) + TObject::AddToTObjectTable(this); #else - if (R__unlikely(fgObjectStat)) TObject::AddToTObjectTable(this); + if (R__unlikely(fgObjectStat)) + TObject::AddToTObjectTable(this); #endif } @@ -312,7 +318,6 @@ inline TObject &TObject::operator=(const TObject &rhs) noexcept return *this; } - //////////////////////////////////////////////////////////////////////////////// /// @brief Check and record whether this class has a consistent /// Hash/RecursiveRemove setup (*) and then return the regular Hash value for @@ -366,29 +371,28 @@ inline Bool_t TObject::HasInconsistentHash() const // Only here for backward compatibility reasons. // For detailed description see TObject::EStatusBits above. enum EObjBits { - kCanDelete = TObject::kCanDelete, - kMustCleanup = TObject::kMustCleanup, - kObjInCanvas = TObject::kObjInCanvas, - kIsReferenced = TObject::kIsReferenced, - kHasUUID = TObject::kHasUUID, - kCannotPick = TObject::kCannotPick, - kNoContextMenu = TObject::kNoContextMenu, - kInvalidObject = TObject::kInvalidObject + kCanDelete = TObject::kCanDelete, + kMustCleanup = TObject::kMustCleanup, + kObjInCanvas = TObject::kObjInCanvas, + kIsReferenced = TObject::kIsReferenced, + kHasUUID = TObject::kHasUUID, + kCannotPick = TObject::kCannotPick, + kNoContextMenu = TObject::kNoContextMenu, + kInvalidObject = TObject::kInvalidObject }; namespace cling { - std::string printValue(TObject *val); +std::string printValue(TObject *val); } namespace ROOT { namespace Internal { - bool DeleteChangesMemory(); -} // Internal +bool DeleteChangesMemory(); +} // namespace Internal namespace Detail { - /// @brief Check if the TObject's memory has been deleted. /// @warning This should be only used for error mitigation as the answer is only /// sometimes correct. It actually just checks whether the object has been @@ -401,10 +405,12 @@ namespace Detail { /// always returns false as the marker left by ~TObject will be overwritten. /// @param obj The memory to check /// @return true if the object has been destructed and it can be inferred that it has been deleted -R__ALWAYS_INLINE bool HasBeenDeleted(const TObject *obj) { +R__ALWAYS_INLINE bool HasBeenDeleted(const TObject *obj) +{ return !ROOT::Internal::DeleteChangesMemory() && obj->IsDestructed(); } -}} // ROOT::Details +} // namespace Detail +} // namespace ROOT #endif diff --git a/core/base/src/TObject.cxx b/core/base/src/TObject.cxx index e8d657324f40f..f15bea8d4bf53 100644 --- a/core/base/src/TObject.cxx +++ b/core/base/src/TObject.cxx @@ -37,7 +37,6 @@ class hierarchies (watch out for overlaps). that the object was allocated on the heap). */ - #include #if !defined(WIN32) && !defined(__MWERKS__) && !defined(R__SOLARIS) #include @@ -67,14 +66,14 @@ class hierarchies (watch out for overlaps). #include "TProcessID.h" Longptr_t TObject::fgDtorOnly = 0; -Bool_t TObject::fgObjectStat = kTRUE; +Bool_t TObject::fgObjectStat = kTRUE; ClassImp(TObject); -#if defined(__clang__) || defined (__GNUC__) -# define ATTRIBUTE_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address)) +#if defined(__clang__) || defined(__GNUC__) +#define ATTRIBUTE_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address)) #else -# define ATTRIBUTE_NO_SANITIZE_ADDRESS +#define ATTRIBUTE_NO_SANITIZE_ADDRESS #endif namespace ROOT { @@ -99,18 +98,16 @@ bool DeleteChangesMemoryImpl() UInt_t *o_fbits = &(o->fBits); if (*o_fuid != kGoldenUUID) { - Error("CheckingDeleteSideEffects", - "fUniqueID is not as expected, we got 0x%.8x instead of 0x%.8x", - *o_fuid, kGoldenUUID); + Error("CheckingDeleteSideEffects", "fUniqueID is not as expected, we got 0x%.8x instead of 0x%.8x", *o_fuid, + kGoldenUUID); } if (*o_fbits != kGoldenbits) { - Error("CheckingDeleteSideEffects", - "fBits is not as expected, we got 0x%.8x instead of 0x%.8x", - *o_fbits, kGoldenbits); + Error("CheckingDeleteSideEffects", "fBits is not as expected, we got 0x%.8x instead of 0x%.8x", *o_fbits, + kGoldenbits); } if (gDebug >= 9) { unsigned char *oc = reinterpret_cast(o); // for address calculations - unsigned char references[sizeof(TObject)]; + unsigned char references[sizeof(TObject)]; memcpy(references, oc, sizeof(TObject)); // The effective part of this code (the else statement is just that without @@ -119,13 +116,12 @@ bool DeleteChangesMemoryImpl() // Not using the error logger, as there routine is meant to be called // during library initialization/loading. - fprintf(stderr, - "DEBUG: Checking before and after delete the content of a TObject with uniqueID 0x21\n"); - for(size_t i = 0; i < sizeof(TObject); i += 4) { - fprintf(stderr, "DEBUG: 0x%.8x vs 0x%.8x\n", *(int*)(references +i), *(int*)(oc + i)); + fprintf(stderr, "DEBUG: Checking before and after delete the content of a TObject with uniqueID 0x21\n"); + for (size_t i = 0; i < sizeof(TObject); i += 4) { + fprintf(stderr, "DEBUG: 0x%.8x vs 0x%.8x\n", *(int *)(references + i), *(int *)(oc + i)); } } else - delete o; // the 'if' part is that surrounded by the debug code. + delete o; // the 'if' part is that surrounded by the debug code. // Intentionally accessing the deleted memory to check whether it has been changed as // a consequence (side effect) of executing operator delete. If there no change, we @@ -138,7 +134,7 @@ bool DeleteChangesMemoryImpl() // so don't even try return true; #endif - if ( *o_fbits != 0x01000000 ) { + if (*o_fbits != 0x01000000) { // operator delete tainted the memory, we can not rely on TestBit(kNotDeleted) return true; } @@ -153,19 +149,20 @@ bool DeleteChangesMemory() return value; } -}} // ROOT::Detail +} // namespace Internal +} // namespace ROOT //////////////////////////////////////////////////////////////////////////////// /// Copy this to obj. void TObject::Copy(TObject &obj) const { - obj.fUniqueID = fUniqueID; // when really unique don't copy - if (obj.IsOnHeap()) { // test uses fBits so don't move next line - obj.fBits = fBits; + obj.fUniqueID = fUniqueID; // when really unique don't copy + if (obj.IsOnHeap()) { // test uses fBits so don't move next line + obj.fBits = fBits; obj.fBits |= kIsOnHeap; } else { - obj.fBits = fBits; + obj.fBits = fBits; obj.fBits &= ~kIsOnHeap; } obj.fBits &= ~kIsReferenced; @@ -185,7 +182,8 @@ TObject::~TObject() fBits &= ~kNotDeleted; - if (fgObjectStat && gObjectTable) gObjectTable->RemoveQuietly(this); + if (fgObjectStat && gObjectTable) + gObjectTable->RemoveQuietly(this); } //////////////////////////////////////////////////////////////////////////////// @@ -218,8 +216,8 @@ void TObject::AppendPad(Option_t *option) void TObject::Browse(TBrowser *b) { - //Inspect(); - TClass::AutoBrowse(this,b); + // Inspect(); + TClass::AutoBrowse(this, b); } //////////////////////////////////////////////////////////////////////////////// @@ -244,10 +242,10 @@ const char *TObject::ClassName() const TObject *TObject::Clone(const char *) const { if (gDirectory) { - return gDirectory->CloneObject(this); + return gDirectory->CloneObject(this); } else { - // Some of the streamer (eg. roofit's) expect(ed?) a valid gDirectory during streaming. - return gROOT->CloneObject(this); + // Some of the streamer (eg. roofit's) expect(ed?) a valid gDirectory during streaming. + return gROOT->CloneObject(this); } } @@ -277,7 +275,6 @@ void TObject::Delete(Option_t *) } } - //////////////////////////////////////////////////////////////////////////////// /// Computes distance from point (px,py) to the object. /// This member function must be implemented for each graphics primitive. @@ -320,7 +317,7 @@ void TObject::DrawClass() const TObject *TObject::DrawClone(Option_t *option) const { TVirtualPad::TContext ctxt(true); - auto pad = gROOT->GetSelectedPad(); + auto pad = gROOT->GetSelectedPad(); if (pad) pad->cd(); @@ -368,7 +365,7 @@ TObject *TObject::DrawClone(Option_t *option) const void TObject::Dump() const { // Get the actual address of the object. - const void *actual = IsA()->DynamicCast(TObject::Class(),this,kFALSE); + const void *actual = IsA()->DynamicCast(TObject::Class(), this, kFALSE); IsA()->Dump(actual); } @@ -378,13 +375,15 @@ void TObject::Dump() const void TObject::Execute(const char *method, const char *params, Int_t *error) { - if (!IsA()) return; + if (!IsA()) + return; Bool_t must_cleanup = TestBit(kMustCleanup); gInterpreter->Execute(this, IsA(), method, params, error); - if (gPad && must_cleanup) gPad->Modified(); + if (gPad && must_cleanup) + gPad->Modified(); } //////////////////////////////////////////////////////////////////////////////// @@ -396,16 +395,17 @@ void TObject::Execute(const char *method, const char *params, Int_t *error) void TObject::Execute(TMethod *method, TObjArray *params, Int_t *error) { - if (!IsA()) return; + if (!IsA()) + return; Bool_t must_cleanup = TestBit(kMustCleanup); gInterpreter->Execute(this, IsA(), method, params, error); - if (gPad && must_cleanup) gPad->Modified(); + if (gPad && must_cleanup) + gPad->Modified(); } - //////////////////////////////////////////////////////////////////////////////// /// Execute action corresponding to an event at (px,py). This method /// must be overridden if an object can react to graphics events. @@ -442,7 +442,8 @@ TObject *TObject::FindObject(const TObject *) const Option_t *TObject::GetDrawOption() const { - if (!gPad) return ""; + if (!gPad) + return ""; TListIter next(gPad->GetListOfPrimitives()); while (auto obj = next()) { @@ -487,11 +488,12 @@ UInt_t TObject::GetUniqueID() const char *TObject::GetObjectInfo(Int_t px, Int_t py) const { - if (!gPad) return (char*)""; + if (!gPad) + return (char *)""; static char info[64]; - Float_t x = gPad->AbsPixeltoX(px); - Float_t y = gPad->AbsPixeltoY(py); - snprintf(info,64,"x=%g, y=%g",gPad->PadtoX(x),gPad->PadtoY(y)); + Float_t x = gPad->AbsPixeltoX(px); + Float_t y = gPad->AbsPixeltoY(py); + snprintf(info, 64, "x=%g, y=%g", gPad->PadtoX(x), gPad->PadtoY(y)); return info; } @@ -505,7 +507,6 @@ const char *TObject::GetTitle() const return IsA()->GetTitle(); } - //////////////////////////////////////////////////////////////////////////////// /// Execute action in response of a timer timing out. This method /// must be overridden if an object has to react to timers. @@ -528,15 +529,16 @@ Bool_t TObject::HandleTimer(TTimer *) /// will have to be done without call Hash (and hence be linear rather than /// logarithmic complexity). You will also see warnings like /// ~~~ -/// Error in : The class SomeName overrides TObject::Hash but does not call TROOT::RecursiveRemove in its destructor. +/// Error in : The class SomeName overrides +/// TObject::Hash but does not call TROOT::RecursiveRemove in its destructor. /// ~~~ /// ULong_t TObject::Hash() const { - //return (ULong_t) this >> 2; + // return (ULong_t) this >> 2; const void *ptr = this; - return TString::Hash(&ptr, sizeof(void*)); + return TString::Hash(&ptr, sizeof(void *)); } //////////////////////////////////////////////////////////////////////////////// @@ -594,10 +596,10 @@ Bool_t TObject::IsEqual(const TObject *obj) const void TObject::ls(Option_t *option) const { TROOT::IndentLevel(); - std::cout <<"OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << " : "; + std::cout << "OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << " : "; std::cout << Int_t(TestBit(kCanDelete)); - if (option && strstr(option,"noaddr")==nullptr) { - std::cout <<" at: "<< this ; + if (option && strstr(option, "noaddr") == nullptr) { + std::cout << " at: " << this; } std::cout << std::endl; } @@ -656,7 +658,7 @@ void TObject::Pop() void TObject::Print(Option_t *) const { - std::cout <<"OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << std::endl; + std::cout << "OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << std::endl; } //////////////////////////////////////////////////////////////////////////////// @@ -669,7 +671,7 @@ void TObject::Print(Option_t *) const Int_t TObject::Read(const char *name) { if (gDirectory) - return gDirectory->ReadTObject(this,name); + return gDirectory->ReadTObject(this, name); return 0; } @@ -677,10 +679,7 @@ Int_t TObject::Read(const char *name) /// Recursively remove this object from a list. Typically implemented /// by classes that can contain multiple references to a same object. -void TObject::RecursiveRemove(TObject *) -{ -} - +void TObject::RecursiveRemove(TObject *) {} //////////////////////////////////////////////////////////////////////////////// /// Save this object in the file specified by filename. @@ -707,25 +706,28 @@ void TObject::RecursiveRemove(TObject *) void TObject::SaveAs(const char *filename, Option_t *option) const { //==============Save object as a root file=================================== - if (filename && strstr(filename,".root")) { - if (gDirectory) gDirectory->SaveObjectAs(this,filename,""); + if (filename && strstr(filename, ".root")) { + if (gDirectory) + gDirectory->SaveObjectAs(this, filename, ""); return; } //==============Save object as a XML file==================================== - if (filename && strstr(filename,".xml")) { - if (gDirectory) gDirectory->SaveObjectAs(this,filename,""); + if (filename && strstr(filename, ".xml")) { + if (gDirectory) + gDirectory->SaveObjectAs(this, filename, ""); return; } //==============Save object as a JSON file================================ - if (filename && strstr(filename,".json")) { - if (gDirectory) gDirectory->SaveObjectAs(this,filename,option); + if (filename && strstr(filename, ".json")) { + if (gDirectory) + gDirectory->SaveObjectAs(this, filename, option); return; } //==============Save object as a C, ROOT independant, file=================== - if (filename && strstr(filename,".cc")) { + if (filename && strstr(filename, ".cc")) { TString fname; if (filename && strlen(filename) > 0) { fname = filename; @@ -734,11 +736,11 @@ void TObject::SaveAs(const char *filename, Option_t *option) const } std::ofstream out; out.open(fname.Data(), std::ios::out); - if (!out.good ()) { + if (!out.good()) { Error("SaveAs", "cannot open file: %s", fname.Data()); return; } - ((TObject*)this)->SavePrimitive(out,"cc"); + ((TObject *)this)->SavePrimitive(out, "cc"); out.close(); Info("SaveAs", "cc file: %s has been generated", fname.Data()); return; @@ -753,15 +755,15 @@ void TObject::SaveAs(const char *filename, Option_t *option) const } std::ofstream out; out.open(fname.Data(), std::ios::out); - if (!out.good ()) { + if (!out.good()) { Error("SaveAs", "cannot open file: %s", fname.Data()); return; } - out <<"{"<GetVersion()<SavePrimitive(out,option); - out <<"}"<GetVersion() << std::endl; + ((TObject *)this)->SavePrimitive(out, option); + out << "}" << std::endl; out.close(); Info("SaveAs", "C++ Macro file: %s has been generated", fname.Data()); } @@ -770,7 +772,8 @@ void TObject::SaveAs(const char *filename, Option_t *option) const /// Save object constructor in the output stream "out". /// Can be used as first statement when implementing SavePrimitive() method for the object -void TObject::SavePrimitiveConstructor(std::ostream &out, TClass *cl, const char *variable_name, const char *constructor_agrs, Bool_t empty_line) +void TObject::SavePrimitiveConstructor(std::ostream &out, TClass *cl, const char *variable_name, + const char *constructor_agrs, Bool_t empty_line) { if (empty_line) out << " \n"; @@ -781,7 +784,6 @@ void TObject::SavePrimitiveConstructor(std::ostream &out, TClass *cl, const char out << variable_name << " = new " << cl->GetName() << "(" << constructor_agrs << ");\n"; } - //////////////////////////////////////////////////////////////////////////////// /// Save array in the output stream "out" as vector. /// Create unique variable name based on prefix value @@ -798,7 +800,7 @@ TString TObject::SavePrimitiveVector(std::ostream &out, const char *prefix, Int_ out << " std::vector " << vectame; if (len > 0) { - const auto old_precision{out.precision()}; + const auto old_precision{out.precision()}; constexpr auto max_precision{std::numeric_limits::digits10 + 1}; out << std::setprecision(max_precision); Bool_t use_new_lines = len > 15; @@ -836,8 +838,8 @@ void TObject::SavePrimitiveDraw(std::ostream &out, const char *variable_name, Op void TObject::SavePrimitive(std::ostream &out, Option_t * /*= ""*/) { - out << "//Primitive: " << GetName() << "/" << GetTitle() - <<". You must implement " << ClassName() << "::SavePrimitive" << std::endl; + out << "//Primitive: " << GetName() << "/" << GetTitle() << ". You must implement " << ClassName() + << "::SavePrimitive" << std::endl; } //////////////////////////////////////////////////////////////////////////////// @@ -849,7 +851,8 @@ void TObject::SavePrimitive(std::ostream &out, Option_t * /*= ""*/) void TObject::SetDrawOption(Option_t *option) { - if (!gPad || !option) return; + if (!gPad || !option) + return; TListIter next(gPad->GetListOfPrimitives()); delete gPad->FindObject("Tframe"); @@ -884,9 +887,7 @@ void TObject::SetUniqueID(UInt_t uid) /// This function is called when either TCanvas::UseCurrentStyle /// or TROOT::ForceStyle have been invoked. -void TObject::UseCurrentStyle() -{ -} +void TObject::UseCurrentStyle() {} //////////////////////////////////////////////////////////////////////////////// /// Write this object to the current directory. @@ -947,15 +948,18 @@ Int_t TObject::Write(const char *name, Int_t option, Int_t bufsize) const return 0; TString opt = ""; - if (option & kSingleKey) opt += "SingleKey"; - if (option & kOverwrite) opt += "OverWrite"; - if (option & kWriteDelete) opt += "WriteDelete"; + if (option & kSingleKey) + opt += "SingleKey"; + if (option & kOverwrite) + opt += "OverWrite"; + if (option & kWriteDelete) + opt += "WriteDelete"; if (gDirectory) - return gDirectory->WriteTObject(this,name,opt.Data(),bufsize); + return gDirectory->WriteTObject(this, name, opt.Data(), bufsize); const char *objname = name ? name : GetName(); - Error("Write","The current directory (gDirectory) is null. The object (%s) has not been written.",objname); + Error("Write", "The current directory (gDirectory) is null. The object (%s) has not been written.", objname); return 0; } @@ -965,7 +969,7 @@ Int_t TObject::Write(const char *name, Int_t option, Int_t bufsize) const Int_t TObject::Write(const char *name, Int_t option, Int_t bufsize) { - return ((const TObject*)this)->Write(name, option, bufsize); + return ((const TObject *)this)->Write(name, option, bufsize); } //////////////////////////////////////////////////////////////////////////////// @@ -973,26 +977,27 @@ Int_t TObject::Write(const char *name, Int_t option, Int_t bufsize) void TObject::Streamer(TBuffer &R__b) { - if (IsA()->CanIgnoreTObjectStreamer()) return; + if (IsA()->CanIgnoreTObjectStreamer()) + return; UShort_t pidf; if (R__b.IsReading()) { R__b.SkipVersion(); // Version_t R__v = R__b.ReadVersion(); if (R__v) { } R__b >> fUniqueID; const UInt_t isonheap = fBits & kIsOnHeap; // Record how this instance was actually allocated. R__b >> fBits; - fBits |= isonheap | kNotDeleted; // by definition de-serialized object are not yet deleted. + fBits |= isonheap | kNotDeleted; // by definition de-serialized object are not yet deleted. if (TestBit(kIsReferenced)) { - //if the object is referenced, we must read its old address - //and store it in the ProcessID map in gROOT + // if the object is referenced, we must read its old address + // and store it in the ProcessID map in gROOT R__b >> pidf; pidf += R__b.GetPidOffset(); TProcessID *pid = R__b.ReadProcessID(pidf); if (pid) { UInt_t gpid = pid->GetUniqueID(); - if (gpid>=0xff) { + if (gpid >= 0xff) { fUniqueID = fUniqueID | 0xff000000; } else { - fUniqueID = ( fUniqueID & 0xffffff) + (gpid<<24); + fUniqueID = (fUniqueID & 0xffffff) + (gpid << 24); } pid->PutObjectWithID(this); } @@ -1003,7 +1008,7 @@ void TObject::Streamer(TBuffer &R__b) // simply hard-coding this value. // This **must** be equal to TFile::k630forwardCompatibility constexpr int TFile__k630forwardCompatibility = BIT(2); - const auto parent = R__b.GetParent(); + const auto parent = R__b.GetParent(); if (!TestBit(kIsReferenced)) { R__b << fUniqueID; if (R__unlikely(parent && parent->TestBit(TFile__k630forwardCompatibility))) @@ -1011,17 +1016,18 @@ void TObject::Streamer(TBuffer &R__b) else R__b << (fBits & (~kIsOnHeap & ~kNotDeleted)); } else { - //if the object is referenced, we must save its address/file_pid + // if the object is referenced, we must save its address/file_pid UInt_t uid = fUniqueID & 0xffffff; R__b << uid; if (R__unlikely(parent && parent->TestBit(TFile__k630forwardCompatibility))) R__b << fBits; else R__b << (fBits & (~kIsOnHeap & ~kNotDeleted)); - TProcessID *pid = TProcessID::GetProcessWithUID(fUniqueID,this); - //add uid to the TRefTable if there is one + TProcessID *pid = TProcessID::GetProcessWithUID(fUniqueID, this); + // add uid to the TRefTable if there is one TRefTable *table = TRefTable::GetRefTable(); - if(table) table->Add(uid, pid); + if (table) + table->Add(uid, pid); pidf = R__b.WriteProcessID(pid); R__b << pidf; } @@ -1178,7 +1184,7 @@ Longptr_t TObject::GetDtorOnly() void TObject::SetDtorOnly(void *obj) { - fgDtorOnly = (Longptr_t) obj; + fgDtorOnly = (Longptr_t)obj; } //////////////////////////////////////////////////////////////////////////////// @@ -1186,7 +1192,7 @@ void TObject::SetDtorOnly(void *obj) void TObject::operator delete(void *ptr) { - if ((Longptr_t) ptr != fgDtorOnly) + if ((Longptr_t)ptr != fgDtorOnly) TStorage::ObjectDealloc(ptr); else fgDtorOnly = 0; @@ -1197,7 +1203,7 @@ void TObject::operator delete(void *ptr) void TObject::operator delete[](void *ptr) { - if ((Longptr_t) ptr != fgDtorOnly) + if ((Longptr_t)ptr != fgDtorOnly) TStorage::ObjectDealloc(ptr); else fgDtorOnly = 0; @@ -1208,7 +1214,7 @@ void TObject::operator delete[](void *ptr) void TObject::operator delete(void *ptr, size_t size) { - if ((Longptr_t) ptr != fgDtorOnly) + if ((Longptr_t)ptr != fgDtorOnly) TStorage::ObjectDealloc(ptr, size); else fgDtorOnly = 0; @@ -1219,7 +1225,7 @@ void TObject::operator delete(void *ptr, size_t size) void TObject::operator delete[](void *ptr, size_t size) { - if ((Longptr_t) ptr != fgDtorOnly) + if ((Longptr_t)ptr != fgDtorOnly) TStorage::ObjectDealloc(ptr, size); else fgDtorOnly = 0;