From 784c78925dead472a3d71025585ab5fd7944a49d Mon Sep 17 00:00:00 2001 From: CristinaCristescu Date: Wed, 12 Mar 2014 10:12:26 +0100 Subject: [PATCH 1/2] Migrate FunctionTemplate to be on demand. (ROOT-6139). --- core/base/inc/TROOT.h | 4 +- core/base/src/TROOT.cxx | 23 +- core/meta/inc/LinkDef.h | 1 + core/meta/inc/TClass.h | 4 +- core/meta/inc/TInterpreter.h | 1 + core/meta/inc/TListOfFunctionTemplates.h | 93 +++++ core/meta/src/TClass.cxx | 26 +- core/meta/src/TCling.cxx | 35 ++ core/meta/src/TCling.h | 1 + core/meta/src/TListOfFunctionTemplates.cxx | 392 +++++++++++++++++++++ 10 files changed, 556 insertions(+), 24 deletions(-) create mode 100644 core/meta/inc/TListOfFunctionTemplates.h create mode 100644 core/meta/src/TListOfFunctionTemplates.cxx diff --git a/core/base/inc/TROOT.h b/core/base/inc/TROOT.h index f884a784b2928..a361f97e55869 100644 --- a/core/base/inc/TROOT.h +++ b/core/base/inc/TROOT.h @@ -56,6 +56,7 @@ class TROOT; class TListOfDataMembers; class TListOfEnums; class TListOfFunctions; +class TListOfFunctionTemplates; class TFunctionTemplate; @@ -112,7 +113,7 @@ friend TROOT *ROOT::GetROOT2(); TVirtualPad *fSelectPad; //Currently selected pad TCollection *fClasses; //List of classes definition TCollection *fTypes; //List of data types definition - TCollection *fFuncTemplate; //List of global function templates + TListOfFunctionTemplates *fFuncTemplate; //List of global function templates TListOfDataMembers*fGlobals; //List of global variables TListOfFunctions*fGlobalFunctions; //List of global functions TSeqCollection *fClosedObjects; //List of closed objects from the list of files and sockets, so we can delete them if neededCl. @@ -223,6 +224,7 @@ friend TROOT *ROOT::GetROOT2(); TSeqCollection *GetClipboard() const { return fClipboard; } TSeqCollection *GetListOfDataSets() const { return fDataSets; } TCollection *GetListOfEnums(); + TCollection *GetListOfFunctionTemplates(); TList *GetListOfBrowsables() const { return fBrowsables; } TDataType *GetType(const char *name, Bool_t load = kFALSE) const; TFile *GetFile() const { if (gDirectory != this) return gDirectory->GetFile(); else return 0;} diff --git a/core/base/src/TROOT.cxx b/core/base/src/TROOT.cxx index 28a3f24981c40..ca5783837be4a 100644 --- a/core/base/src/TROOT.cxx +++ b/core/base/src/TROOT.cxx @@ -111,6 +111,7 @@ #include "TListOfDataMembers.h" #include "TListOfEnums.h" #include "TListOfFunctions.h" +#include "TListOfFunctionTemplates.h" #include "TFunctionTemplate.h" #include @@ -1225,18 +1226,9 @@ TFunctionTemplate *TROOT::GetFunctionTemplate(const char *name) { if (!gInterpreter) return 0; - if (!fFuncTemplate) fFuncTemplate = new TList(); + if (!fFuncTemplate) fFuncTemplate = new TListOfFunctionTemplates(0); - TFunctionTemplate *result; - result = (TFunctionTemplate*)fFuncTemplate->FindObject(name); - if (!result) { - TInterpreter::DeclId_t id = gInterpreter->GetFunctionTemplate(0,name); - if (id) { - FuncTempInfo_t *info = gInterpreter->FuncTempInfo_Factory(id); - result = new TFunctionTemplate(info, 0); - } - } - return result; + return (TFunctionTemplate*)fFuncTemplate->FindObject(name); } //______________________________________________________________________________ @@ -1368,6 +1360,15 @@ TCollection *TROOT::GetListOfEnums() return fEnums; } +//______________________________________________________________________________ +TCollection *TROOT::GetListOfFunctionTemplates() +{ + if(!fFuncTemplate) { + fFuncTemplate = new TListOfFunctionTemplates(0); + } + return fFuncTemplate; +} + //______________________________________________________________________________ TCollection *TROOT::GetListOfGlobals(Bool_t load) { diff --git a/core/meta/inc/LinkDef.h b/core/meta/inc/LinkDef.h index 451a616a5f937..a75748eeba5c0 100644 --- a/core/meta/inc/LinkDef.h +++ b/core/meta/inc/LinkDef.h @@ -63,6 +63,7 @@ #pragma link C++ class std::vector >+; #pragma link C++ class TFileMergeInfo; #pragma link C++ class TListOfFunctions+; +#pragma link C++ class TListOfFunctionTemplates+; #pragma link C++ class TListOfDataMembers; #pragma link C++ class TListOfEnums+; diff --git a/core/meta/inc/TClass.h b/core/meta/inc/TClass.h index 7dae25b7f3244..3394d400dd8a8 100644 --- a/core/meta/inc/TClass.h +++ b/core/meta/inc/TClass.h @@ -53,6 +53,7 @@ class TVirtualIsAProxy; class TVirtualRefProxy; class THashTable; class TListOfFunctions; +class TListOfFunctionTemplates; class TListOfDataMembers; class TListOfEnums; class TViewPubFunctions; @@ -116,7 +117,7 @@ friend class ROOT::TGenericClassInfo; TList *fBase; //linked list for base classes TListOfDataMembers*fData; //linked list for data members TListOfEnums *fEnums; //linked list for the enums - TList *fFuncTemplate; //linked list for function templates [Not public until implemented as active list] + TListOfFunctionTemplates *fFuncTemplate; //linked list for function templates [Not public until implemented as active list] TListOfFunctions *fMethod; //linked list for methods TViewPubDataMembers*fAllPubData; //all public data members (including from base classes) TViewPubFunctions *fAllPubMethod; //all public methods (including from base classes) @@ -298,6 +299,7 @@ friend class ROOT::TGenericClassInfo; } TList *GetListOfDataMembers(Bool_t load = kTRUE); TList *GetListOfEnums(Bool_t load = kTRUE); + TList *GetListOfFunctionTemplates(Bool_t load = kTRUE); TList *GetListOfBases(); TList *GetListOfMethods(Bool_t load = kTRUE); TCollection *GetListOfMethodOverloads(const char* name) const; diff --git a/core/meta/inc/TInterpreter.h b/core/meta/inc/TInterpreter.h index 57a3499a895a3..95d5c6a3230e4 100644 --- a/core/meta/inc/TInterpreter.h +++ b/core/meta/inc/TInterpreter.h @@ -235,6 +235,7 @@ class TInterpreter : public TNamed { virtual DeclId_t GetFunctionWithValues(ClassInfo_t *cl, const char* method, const char* params, Bool_t objectIsConst = kFALSE) = 0; virtual DeclId_t GetFunctionTemplate(ClassInfo_t *cl, const char *funcname) = 0; virtual void GetFunctionOverloads(ClassInfo_t *cl, const char *funcname, std::vector& res) const = 0; + virtual void LoadFunctionTemplates(TClass* cl) const = 0; // CallFunc interface virtual void CallFunc_Delete(CallFunc_t * /* func */) const {;} diff --git a/core/meta/inc/TListOfFunctionTemplates.h b/core/meta/inc/TListOfFunctionTemplates.h new file mode 100644 index 0000000000000..025ae44f097f9 --- /dev/null +++ b/core/meta/inc/TListOfFunctionTemplates.h @@ -0,0 +1,93 @@ +// @(#)root/cont +// Author: Philippe Canal Aug 2013 + +/************************************************************************* + * Copyright (C) 1995-2013, Rene Brun and Fons Rademakers. * + * All rights reserved. * + * * + * For the licensing terms see $ROOTSYS/LICENSE. * + * For the list of contributors see $ROOTSYS/README/CREDITS. * + *************************************************************************/ + +#ifndef ROOT_TListOfFunctionTemplates +#define ROOT_TListOfFunctionTemplates + +////////////////////////////////////////////////////////////////////////// +// // +// TListOfFunctionTemplates // +// // +// A collection of TFunctionTemplate objects designed for fast access // +// given a DeclId_t and for keep track of TFunctionTempalte that were // +// described unloaded function. // +// // +////////////////////////////////////////////////////////////////////////// + +#ifndef ROOT_THastList +#include "THashList.h" +#endif + +#ifndef ROOT_THastTable +#include "THashTable.h" +#endif + +#ifndef ROOT_TDictionary +#include "TDictionary.h" +#endif + +class TExMap; +class TFunctionTemplate; + +class TListOfFunctionTemplates : public THashList +{ +private: + typedef TDictionary::DeclId_t DeclId_t; + TClass *fClass; // Context of this list. Not owned. + + TExMap *fIds; // Map from DeclId_t to TFunction* + THashList *fUnloaded; // Holder of TFunction for unloaded functions. + THashTable fOverloads; // TLists of overloads. + + TListOfFunctionTemplates(const TListOfFunctionTemplates&); // not implemented + TListOfFunctionTemplates& operator=(const TListOfFunctionTemplates&); // not implemented + TList *GetListForObjectNonConst(const char* name); + + void MapObject(TObject *obj); + void UnmapObject(TObject *obj); + +public: + + TListOfFunctionTemplates(TClass *cl); + ~TListOfFunctionTemplates(); + + virtual void Clear(Option_t *option); + virtual void Delete(Option_t *option=""); + + using THashList::FindObject; + virtual TObject *FindObject(const char *name) const; + virtual TList *GetListForObject(const char* name) const; + virtual TList *GetListForObject(const TObject* obj) const; + + TFunctionTemplate *Get(DeclId_t id); + + void AddFirst(TObject *obj); + void AddFirst(TObject *obj, Option_t *opt); + void AddLast(TObject *obj); + void AddLast(TObject *obj, Option_t *opt); + void AddAt(TObject *obj, Int_t idx); + void AddAfter(const TObject *after, TObject *obj); + void AddAfter(TObjLink *after, TObject *obj); + void AddBefore(const TObject *before, TObject *obj); + void AddBefore(TObjLink *before, TObject *obj); + + void RecursiveRemove(TObject *obj); + TObject *Remove(TObject *obj); + TObject *Remove(TObjLink *lnk); + + void Load(); + void Unload(); + void Unload(TFunctionTemplate *func); + + ClassDef(TListOfFunctionTemplates,0); // List of TFunctions for a class +}; + +#endif // ROOT_TListOfFunctionTemplates diff --git a/core/meta/src/TClass.cxx b/core/meta/src/TClass.cxx index 10ee0734c49c8..12ecc0f2add56 100644 --- a/core/meta/src/TClass.cxx +++ b/core/meta/src/TClass.cxx @@ -77,6 +77,7 @@ #include "TListOfDataMembers.h" #include "TListOfFunctions.h" +#include "TListOfFunctionTemplates.h" #include "TListOfEnums.h" #include "TViewPubDataMembers.h" #include "TViewPubFunctions.h" @@ -3087,18 +3088,9 @@ TFunctionTemplate *TClass::GetFunctionTemplate(const char *name) if (!gInterpreter || !fClassInfo) return 0; // The following - if (!fFuncTemplate) fFuncTemplate = new TList(); + if (!fFuncTemplate) fFuncTemplate = new TListOfFunctionTemplates(this); - TFunctionTemplate *result; - result = (TFunctionTemplate*)fFuncTemplate->FindObject(name); - if (!result) { - DeclId_t id = gInterpreter->GetFunctionTemplate(fClassInfo,name); - if (id) { - FuncTempInfo_t *info = gInterpreter->FuncTempInfo_Factory(id); - result = new TFunctionTemplate(info,this); - } - } - return result; + return (TFunctionTemplate*)fFuncTemplate->FindObject(name); } //______________________________________________________________________________ @@ -3164,6 +3156,18 @@ TList *TClass::GetListOfDataMembers(Bool_t load /* = kTRUE */) return fData; } +//______________________________________________________________________________ +TList *TClass::GetListOfFunctionTemplates(Bool_t load /* = kTRUE */) +{ + // Return list containing the TEnums of a class. + + R__LOCKGUARD(gInterpreterMutex); + + if (!fFuncTemplate) fFuncTemplate = new TListOfFunctionTemplates(this); + if (load) fFuncTemplate->Load(); + return fFuncTemplate; +} + //______________________________________________________________________________ TList *TClass::GetListOfMethods(Bool_t load /* = kTRUE */) { diff --git a/core/meta/src/TCling.cxx b/core/meta/src/TCling.cxx index cc6e729975dc5..532c919c968d6 100644 --- a/core/meta/src/TCling.cxx +++ b/core/meta/src/TCling.cxx @@ -63,6 +63,7 @@ #include "TMetaUtils.h" #include "TVirtualCollectionProxy.h" #include "TListOfEnums.h" +#include "TListOfFunctionTemplates.h" #include "clang/AST/ASTContext.h" #include "clang/AST/Decl.h" @@ -2535,6 +2536,40 @@ void TCling::LoadEnums(TClass* cl) const } } +//______________________________________________________________________________ +void TCling::LoadFunctionTemplates(TClass* cl) const +{ + // Create list of pointers to function templates for TClass cl. + R__LOCKGUARD2(gInterpreterMutex); + + const Decl * D; + TListOfFunctionTemplates* funcTempList; + if (cl) { + D = ((TClingClassInfo*)cl->GetClassInfo())->GetDecl(); + funcTempList = (TListOfFunctionTemplates*)cl->GetListOfFunctionTemplates(false); + } + else { + D = fInterpreter->getCI()->getASTContext().getTranslationUnitDecl(); + funcTempList = (TListOfFunctionTemplates*)gROOT->GetListOfFunctionTemplates(); + } + // Iterate on the decl of the class and get the enums. + if (const clang::DeclContext* DC = dyn_cast(D)) { + cling::Interpreter::PushTransactionRAII deserRAII(fInterpreter); + // Collect all contexts of the namespace. + llvm::SmallVector< DeclContext *, 4> allDeclContexts; + const_cast< clang::DeclContext *>(DC)->collectAllContexts(allDeclContexts); + for (llvm::SmallVector::iterator declIter = allDeclContexts.begin(), + declEnd = allDeclContexts.end(); declIter != declEnd; ++declIter) { + // Iterate on all decls for each context. + for (clang::DeclContext::decl_iterator DI = (*declIter)->decls_begin(), + DE = (*declIter)->decls_end(); DI != DE; ++DI) { + if (const clang::FunctionTemplateDecl* FTD = dyn_cast(*DI)) { + funcTempList->Get(FTD); + } + } + } + } +} //______________________________________________________________________________ void TCling::CreateListOfDataMembers(TClass* cl) const { diff --git a/core/meta/src/TCling.h b/core/meta/src/TCling.h index ec76d3fddf63b..6dbfe460bf2de 100644 --- a/core/meta/src/TCling.h +++ b/core/meta/src/TCling.h @@ -227,6 +227,7 @@ class TCling : public TInterpreter { DeclId_t GetFunctionWithValues(ClassInfo_t *cl, const char* method, const char* params, Bool_t objectIsConst = kFALSE); DeclId_t GetFunctionTemplate(ClassInfo_t *cl, const char *funcname); void GetFunctionOverloads(ClassInfo_t *cl, const char *funcname, std::vector& res) const; + virtual void LoadFunctionTemplates(TClass* cl) const; void GetInterpreterTypeName(const char* name, std::string &output, Bool_t full = kFALSE); void Execute(const char* function, const char* params, int* error = 0); diff --git a/core/meta/src/TListOfFunctionTemplates.cxx b/core/meta/src/TListOfFunctionTemplates.cxx new file mode 100644 index 0000000000000..f7371819f086a --- /dev/null +++ b/core/meta/src/TListOfFunctionTemplates.cxx @@ -0,0 +1,392 @@ +// @(#)root/cont +// Author: Bianca-Cristina Cristescu March 2014 + +/************************************************************************* + * Copyright (C) 1995-2013, Rene Brun and Fons Rademakers. * + * All rights reserved. * + * * + * For the licensing terms see $ROOTSYS/LICENSE. * + * For the list of contributors see $ROOTSYS/README/CREDITS. * + *************************************************************************/ + +////////////////////////////////////////////////////////////////////////// +// // +// TListOfFunctionTemplates // +// // +// A collection of TFunction objects designed for fast access given a // +// DeclId_t and for keep track of TFunction that were described // +// unloaded function. // +// // +////////////////////////////////////////////////////////////////////////// + +#include "TListOfFunctionTemplates.h" +#include "TClass.h" +#include "TExMap.h" +#include "TFunction.h" +#include "TFunctionTemplate.h" +#include "TMethod.h" +#include "TInterpreter.h" +#include "TVirtualMutex.h" + +ClassImp(TListOfFunctionTemplates) + +//______________________________________________________________________________ +TListOfFunctionTemplates::TListOfFunctionTemplates(TClass *cl) : fClass(cl),fIds(0),fUnloaded(0) +{ + // Constructor. + + fIds = new TExMap; + fUnloaded = new THashList; +} + +//______________________________________________________________________________ +TListOfFunctionTemplates::~TListOfFunctionTemplates() +{ + // Destructor. + + THashList::Delete(); + delete fIds; + fUnloaded->Delete(); + delete fUnloaded; +} + +//______________________________________________________________________________ +void TListOfFunctionTemplates::MapObject(TObject *obj) +{ + // Add pair to the map of functions and their ids. + + TFunctionTemplate *f = dynamic_cast(obj); + if (f) { + fIds->Add((Long64_t)f->GetDeclId(),(Long64_t)f); + } +} + +//______________________________________________________________________________ +void TListOfFunctionTemplates::AddFirst(TObject *obj) +{ + // Add object at the beginning of the list. + + THashList::AddFirst(obj); + MapObject(obj); +} + +//______________________________________________________________________________ +void TListOfFunctionTemplates::AddFirst(TObject *obj, Option_t *opt) +{ + // Add object at the beginning of the list and also store option. + // Storing an option is useful when one wants to change the behaviour + // of an object a little without having to create a complete new + // copy of the object. This feature is used, for example, by the Draw() + // method. It allows the same object to be drawn in different ways. + + THashList::AddFirst(obj,opt); + MapObject(obj); +} + +//______________________________________________________________________________ +void TListOfFunctionTemplates::AddLast(TObject *obj) +{ + // Add object at the end of the list. + + THashList::AddLast(obj); + MapObject(obj); +} + +//______________________________________________________________________________ +void TListOfFunctionTemplates::AddLast(TObject *obj, Option_t *opt) +{ + // Add object at the end of the list and also store option. + // Storing an option is useful when one wants to change the behaviour + // of an object a little without having to create a complete new + // copy of the object. This feature is used, for example, by the Draw() + // method. It allows the same object to be drawn in different ways. + + THashList::AddLast(obj, opt); + MapObject(obj); +} + +//______________________________________________________________________________ +void TListOfFunctionTemplates::AddAt(TObject *obj, Int_t idx) +{ + // Insert object at location idx in the list. + + THashList::AddAt(obj, idx); + MapObject(obj); +} + +//______________________________________________________________________________ +void TListOfFunctionTemplates::AddAfter(const TObject *after, TObject *obj) +{ + // Insert object after object after in the list. + + THashList::AddAfter(after, obj); + MapObject(obj); +} + +//______________________________________________________________________________ +void TListOfFunctionTemplates::AddAfter(TObjLink *after, TObject *obj) +{ + // Insert object after object after in the list. + + THashList::AddAfter(after, obj); + MapObject(obj); +} + +//______________________________________________________________________________ +void TListOfFunctionTemplates::AddBefore(const TObject *before, TObject *obj) +{ + // Insert object before object before in the list. + + THashList::AddBefore(before, obj); + MapObject(obj); +} + +//______________________________________________________________________________ +void TListOfFunctionTemplates::AddBefore(TObjLink *before, TObject *obj) +{ + // Insert object before object before in the list. + + THashList::AddBefore(before, obj); + MapObject(obj); +} + +//______________________________________________________________________________ +void TListOfFunctionTemplates::Clear(Option_t *option) +{ + // Remove all objects from the list. Does not delete the objects unless + // the THashList is the owner (set via SetOwner()). + + fUnloaded->Clear(option); + fIds->Clear(); + THashList::Clear(option); +} + +//______________________________________________________________________________ +void TListOfFunctionTemplates::Delete(Option_t *option /* ="" */) +{ + // Delete all TFunction object files. + + fUnloaded->Delete(option); + fIds->Clear(); + THashList::Delete(option); +} + +//______________________________________________________________________________ +TObject *TListOfFunctionTemplates::FindObject(const char *name) const +{ + // Specialize FindObject to do search for the + // a function just by name or create it if its not already in the list + + TObject *result = THashList::FindObject(name); + if (!result) { + TInterpreter::DeclId_t decl; + if (fClass) decl = gInterpreter->GetFunctionTemplate(fClass->GetClassInfo(),name); + else decl = gInterpreter->GetFunctionTemplate(0,name); + if (decl) result = const_cast(this)->Get(decl); + } + return result; +} + +//______________________________________________________________________________ +TList* TListOfFunctionTemplates::GetListForObjectNonConst(const char* name) +{ + // Return the set of overloads for this name, collecting all available ones. + // Can construct and insert new TFunction-s. + TList* overloads = (TList*)fOverloads.FindObject(name); + TExMap overloadsSet; + Bool_t wasEmpty = true; + if (!overloads) { + overloads = new TList(); + overloads->SetName(name); + fOverloads.Add(overloads); + } else { + TIter iOverload(overloads); + while (TFunctionTemplate* over = (TFunctionTemplate*)iOverload()) { + wasEmpty = false; + overloadsSet.Add((Long64_t)(ULong64_t)over->GetDeclId(), + (Long64_t)(ULong64_t)over); + } + } + + // Update if needed. + std::vector overloadDecls; + ClassInfo_t* ci = fClass ? fClass->GetClassInfo() : 0; + gInterpreter->GetFunctionOverloads(ci, name, overloadDecls); + for (std::vector::const_iterator iD = overloadDecls.begin(), + eD = overloadDecls.end(); iD != eD; ++iD) { + TFunctionTemplate* over = Get(*iD); + if (wasEmpty || !overloadsSet.GetValue((Long64_t)(ULong64_t)over->GetDeclId())) { + overloads->Add(over); + } + } + + return overloads; +} + +//______________________________________________________________________________ +TList* TListOfFunctionTemplates::GetListForObject(const char* name) const +{ + // Return the set of overloads for this name, collecting all available ones. + // Can construct and insert new TFunction-s. + return const_cast(this)->GetListForObjectNonConst(name); +} + +//______________________________________________________________________________ +TList* TListOfFunctionTemplates::GetListForObject(const TObject* obj) const +{ + // Return the set of overloads for function obj, collecting all available ones. + // Can construct and insert new TFunction-s. + if (!obj) return 0; + return const_cast(this) + ->GetListForObjectNonConst(obj->GetName()); +} + +//______________________________________________________________________________ +TFunctionTemplate *TListOfFunctionTemplates::Get(DeclId_t id) +{ + // Return (after creating it if necessary) the TMethod or TFunction + // describing the function corresponding to the Decl 'id'. + + if (!id) return 0; + + TFunctionTemplate *f = (TFunctionTemplate*)fIds->GetValue((Long64_t)id); + if (!f) { + if (fClass) { + if (!gInterpreter->ClassInfo_Contains(fClass->GetClassInfo(),id)) return 0; + } else { + if (!gInterpreter->ClassInfo_Contains(0,id)) return 0; + } + FuncTempInfo_t *m = gInterpreter->FuncTempInfo_Factory(id); + + // Let's see if this is a reload ... + TString name; + gInterpreter->FuncTempInfo_Name(m, name); + TFunctionTemplate* update = (TFunctionTemplate*)fUnloaded->FindObject(name); + if (update) { + fUnloaded->Remove(update); + update->Update(m); + f = update; + } + if (!f) { + if (fClass) f = new TFunctionTemplate(m, fClass); + else f = new TFunctionTemplate(m, 0); + } + // Calling 'just' THahList::Add would turn around and call + // TListOfFunctionTemplates::AddLast which should *also* do the fIds->Add. + THashList::AddLast(f); + fIds->Add((Long64_t)id,(Long64_t)f); + } + return f; +} + +//______________________________________________________________________________ +void TListOfFunctionTemplates::UnmapObject(TObject *obj) +{ + // Remove a pair from the map of functions and their ids. + TFunctionTemplate *f = dynamic_cast(obj); + if (f) { + fIds->Remove((Long64_t)f->GetDeclId()); + } +} + +//______________________________________________________________________________ +void TListOfFunctionTemplates::RecursiveRemove(TObject *obj) +{ + // Remove object from this collection and recursively remove the object + // from all other objects (and collections). + // This function overrides TCollection::RecursiveRemove that calls + // the Remove function. THashList::Remove cannot be called because + // it uses the hash value of the hash table. This hash value + // is not available anymore when RecursiveRemove is called from + // the TObject destructor. + + if (!obj) return; + + THashList::RecursiveRemove(obj); + fUnloaded->RecursiveRemove(obj); + UnmapObject(obj); + +} + +//______________________________________________________________________________ +TObject* TListOfFunctionTemplates::Remove(TObject *obj) +{ + // Remove object from the list. + + Bool_t found; + + found = THashList::Remove(obj); + if (!found) { + found = fUnloaded->Remove(obj); + } + UnmapObject(obj); + if (found) return obj; + else return 0; +} + +//______________________________________________________________________________ +TObject* TListOfFunctionTemplates::Remove(TObjLink *lnk) +{ + // Remove object via its objlink from the list. + + if (!lnk) return 0; + + TObject *obj = lnk->GetObject(); + + THashList::Remove(lnk); + fUnloaded->Remove(obj); + + UnmapObject(obj); + return obj; +} + +//______________________________________________________________________________ +void TListOfFunctionTemplates::Load() +{ + // Load all the functions known to the intepreter for the scope 'fClass' + // into this collection. + + if (fClass && fClass->GetClassInfo() == 0) return; + + R__LOCKGUARD(gInterpreterMutex); + + gInterpreter->LoadFunctionTemplates(fClass); +} + +//______________________________________________________________________________ +void TListOfFunctionTemplates::Unload() +{ + // Mark 'all func' as being unloaded. + // After the unload, the function can no longer be found directly, + // until the decl can be found again in the interpreter (in which + // the func object will be reused. + + TObjLink *lnk = FirstLink(); + while (lnk) { + TFunctionTemplate *func = (TFunctionTemplate*)lnk->GetObject(); + + fIds->Remove((Long64_t)func->GetDeclId()); + fUnloaded->Add(func); + + lnk = lnk->Next(); + } + + THashList::Clear(); +} + +//______________________________________________________________________________ +void TListOfFunctionTemplates::Unload(TFunctionTemplate *func) +{ + // Mark 'func' as being unloaded. + // After the unload, the function can no longer be found directly, + // until the decl can be found again in the interpreter (in which + // the func object will be reused. + + if (THashList::Remove(func)) { + // We contains the object, let remove it from the other internal + // list and move it to the list of unloaded objects. + + fIds->Remove((Long64_t)func->GetDeclId()); + fUnloaded->Add(func); + } +} From 3bea698419d233c9e7b8a6362909fb2600255651 Mon Sep 17 00:00:00 2001 From: CristinaCristescu Date: Wed, 12 Mar 2014 12:09:06 +0100 Subject: [PATCH 2/2] Remove trailling spaces. --- core/meta/inc/TListOfFunctionTemplates.h | 10 +++++----- core/meta/src/TListOfFunctionTemplates.cxx | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/core/meta/inc/TListOfFunctionTemplates.h b/core/meta/inc/TListOfFunctionTemplates.h index 025ae44f097f9..9e99fcf4d74ed 100644 --- a/core/meta/inc/TListOfFunctionTemplates.h +++ b/core/meta/inc/TListOfFunctionTemplates.h @@ -42,20 +42,20 @@ class TListOfFunctionTemplates : public THashList private: typedef TDictionary::DeclId_t DeclId_t; TClass *fClass; // Context of this list. Not owned. - + TExMap *fIds; // Map from DeclId_t to TFunction* THashList *fUnloaded; // Holder of TFunction for unloaded functions. THashTable fOverloads; // TLists of overloads. - + TListOfFunctionTemplates(const TListOfFunctionTemplates&); // not implemented TListOfFunctionTemplates& operator=(const TListOfFunctionTemplates&); // not implemented TList *GetListForObjectNonConst(const char* name); void MapObject(TObject *obj); void UnmapObject(TObject *obj); - + public: - + TListOfFunctionTemplates(TClass *cl); ~TListOfFunctionTemplates(); @@ -86,7 +86,7 @@ class TListOfFunctionTemplates : public THashList void Load(); void Unload(); void Unload(TFunctionTemplate *func); - + ClassDef(TListOfFunctionTemplates,0); // List of TFunctions for a class }; diff --git a/core/meta/src/TListOfFunctionTemplates.cxx b/core/meta/src/TListOfFunctionTemplates.cxx index f7371819f086a..805085987f5f6 100644 --- a/core/meta/src/TListOfFunctionTemplates.cxx +++ b/core/meta/src/TListOfFunctionTemplates.cxx @@ -23,7 +23,7 @@ #include "TClass.h" #include "TExMap.h" #include "TFunction.h" -#include "TFunctionTemplate.h" +#include "TFunctionTemplate.h" #include "TMethod.h" #include "TInterpreter.h" #include "TVirtualMutex.h" @@ -78,7 +78,7 @@ void TListOfFunctionTemplates::AddFirst(TObject *obj, Option_t *opt) // of an object a little without having to create a complete new // copy of the object. This feature is used, for example, by the Draw() // method. It allows the same object to be drawn in different ways. - + THashList::AddFirst(obj,opt); MapObject(obj); } @@ -301,7 +301,7 @@ void TListOfFunctionTemplates::RecursiveRemove(TObject *obj) // the TObject destructor. if (!obj) return; - + THashList::RecursiveRemove(obj); fUnloaded->RecursiveRemove(obj); UnmapObject(obj); @@ -314,7 +314,7 @@ TObject* TListOfFunctionTemplates::Remove(TObject *obj) // Remove object from the list. Bool_t found; - + found = THashList::Remove(obj); if (!found) { found = fUnloaded->Remove(obj); @@ -328,11 +328,11 @@ TObject* TListOfFunctionTemplates::Remove(TObject *obj) TObject* TListOfFunctionTemplates::Remove(TObjLink *lnk) { // Remove object via its objlink from the list. - + if (!lnk) return 0; TObject *obj = lnk->GetObject(); - + THashList::Remove(lnk); fUnloaded->Remove(obj); @@ -347,7 +347,7 @@ void TListOfFunctionTemplates::Load() // into this collection. if (fClass && fClass->GetClassInfo() == 0) return; - + R__LOCKGUARD(gInterpreterMutex); gInterpreter->LoadFunctionTemplates(fClass); @@ -360,7 +360,7 @@ void TListOfFunctionTemplates::Unload() // After the unload, the function can no longer be found directly, // until the decl can be found again in the interpreter (in which // the func object will be reused. - + TObjLink *lnk = FirstLink(); while (lnk) { TFunctionTemplate *func = (TFunctionTemplate*)lnk->GetObject(); @@ -381,11 +381,11 @@ void TListOfFunctionTemplates::Unload(TFunctionTemplate *func) // After the unload, the function can no longer be found directly, // until the decl can be found again in the interpreter (in which // the func object will be reused. - + if (THashList::Remove(func)) { // We contains the object, let remove it from the other internal // list and move it to the list of unloaded objects. - + fIds->Remove((Long64_t)func->GetDeclId()); fUnloaded->Add(func); }