[edk2-devel] [PATCH] BaseTools:change some incorrect parameter defaults

Fan, ZhijuX posted 1 patch 4 years, 6 months ago
Failed in applying to current master (apply log)
BaseTools/Source/Python/AutoGen/BuildEngine.py         |  4 +++-
BaseTools/Source/Python/AutoGen/GenMake.py             |  6 ++++--
BaseTools/Source/Python/Common/RangeExpression.py      |  4 +++-
BaseTools/Source/Python/Common/StringUtils.py          | 10 +++++++---
BaseTools/Source/Python/GenFds/AprioriSection.py       |  4 +++-
BaseTools/Source/Python/GenFds/CompressSection.py      |  4 +++-
BaseTools/Source/Python/GenFds/DataSection.py          |  4 +++-
BaseTools/Source/Python/GenFds/EfiSection.py           |  4 +++-
BaseTools/Source/Python/GenFds/FfsFileStatement.py     |  5 ++++-
BaseTools/Source/Python/GenFds/FfsInfStatement.py      |  5 +++--
BaseTools/Source/Python/GenFds/Fv.py                   |  4 +++-
BaseTools/Source/Python/GenFds/FvImageSection.py       |  4 +++-
BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py |  2 +-
BaseTools/Source/Python/GenFds/GuidSection.py          |  4 +++-
BaseTools/Source/Python/GenFds/OptRomFileStatement.py  |  5 ++++-
BaseTools/Source/Python/GenFds/Region.py               |  4 +++-
BaseTools/Source/Python/GenFds/Section.py              |  2 +-
BaseTools/Source/Python/GenFds/UiSection.py            |  4 +++-
BaseTools/Source/Python/GenFds/VerSection.py           |  4 +++-
19 files changed, 60 insertions(+), 23 deletions(-)
[edk2-devel] [PATCH] BaseTools:change some incorrect parameter defaults
Posted by Fan, ZhijuX 4 years, 6 months ago
BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=1858

for Dict={},There are pitfalls in the way this default parameter is set
and Dict is not used in functions, other functions have these two cases,
I will change some incorrect parameter defaults

This patch is going to fix this issue

Cc: Liming Gao <liming.gao@intel.com>
Cc: Bob Feng <bob.c.feng@intel.com>
Signed-off-by: Zhiju.Fan <zhijux.fan@intel.com>
---
 BaseTools/Source/Python/AutoGen/BuildEngine.py         |  4 +++-
 BaseTools/Source/Python/AutoGen/GenMake.py             |  6 ++++--
 BaseTools/Source/Python/Common/RangeExpression.py      |  4 +++-
 BaseTools/Source/Python/Common/StringUtils.py          | 10 +++++++---
 BaseTools/Source/Python/GenFds/AprioriSection.py       |  4 +++-
 BaseTools/Source/Python/GenFds/CompressSection.py      |  4 +++-
 BaseTools/Source/Python/GenFds/DataSection.py          |  4 +++-
 BaseTools/Source/Python/GenFds/EfiSection.py           |  4 +++-
 BaseTools/Source/Python/GenFds/FfsFileStatement.py     |  5 ++++-
 BaseTools/Source/Python/GenFds/FfsInfStatement.py      |  5 +++--
 BaseTools/Source/Python/GenFds/Fv.py                   |  4 +++-
 BaseTools/Source/Python/GenFds/FvImageSection.py       |  4 +++-
 BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py |  2 +-
 BaseTools/Source/Python/GenFds/GuidSection.py          |  4 +++-
 BaseTools/Source/Python/GenFds/OptRomFileStatement.py  |  5 ++++-
 BaseTools/Source/Python/GenFds/Region.py               |  4 +++-
 BaseTools/Source/Python/GenFds/Section.py              |  2 +-
 BaseTools/Source/Python/GenFds/UiSection.py            |  4 +++-
 BaseTools/Source/Python/GenFds/VerSection.py           |  4 +++-
 19 files changed, 60 insertions(+), 23 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/BuildEngine.py b/BaseTools/Source/Python/AutoGen/BuildEngine.py
index bb91534477..069a3a1c9d 100644
--- a/BaseTools/Source/Python/AutoGen/BuildEngine.py
+++ b/BaseTools/Source/Python/AutoGen/BuildEngine.py
@@ -176,7 +176,9 @@ class FileBuildRule:
         CommandString = "\n\t".join(self.CommandList)
         return "%s : %s\n\t%s" % (DestString, SourceString, CommandString)
 
-    def Instantiate(self, Macros={}):
+    def Instantiate(self, Macros = None):
+        if Macros is None:
+            Macros = {}
         NewRuleObject = copy.copy(self)
         NewRuleObject.BuildTargets = {}
         NewRuleObject.DestFileList = []
diff --git a/BaseTools/Source/Python/AutoGen/GenMake.py b/BaseTools/Source/Python/AutoGen/GenMake.py
index 4f85a93055..3185ebe368 100755
--- a/BaseTools/Source/Python/AutoGen/GenMake.py
+++ b/BaseTools/Source/Python/AutoGen/GenMake.py
@@ -205,10 +205,12 @@ class BuildFile(object):
     def GetRemoveDirectoryCommand(self, DirList):
         return [self._RD_TEMPLATE_[self._FileType] % {'dir':Dir} for Dir in DirList]
 
-    def PlaceMacro(self, Path, MacroDefinitions={}):
+    def PlaceMacro(self, Path, MacroDefinitions=None):
         if Path.startswith("$("):
             return Path
         else:
+            if MacroDefinitions is None:
+                MacroDefinitions = {}
             PathLength = len(Path)
             for MacroName in MacroDefinitions:
                 MacroValue = MacroDefinitions[MacroName]
@@ -1762,4 +1764,4 @@ def GetDependencyList(AutoGenObject, FileCache, File, ForceList, SearchPathList)
 
 # This acts like the main() function for the script, unless it is 'import'ed into another script.
 if __name__ == '__main__':
-    pass
\ No newline at end of file
+    pass
diff --git a/BaseTools/Source/Python/Common/RangeExpression.py b/BaseTools/Source/Python/Common/RangeExpression.py
index e9296e03f6..039d281467 100644
--- a/BaseTools/Source/Python/Common/RangeExpression.py
+++ b/BaseTools/Source/Python/Common/RangeExpression.py
@@ -342,7 +342,9 @@ class RangeExpression(BaseExpression):
                 raise BadExpression(ERR_STRING_EXPR % Operator)
 
 
-    def __init__(self, Expression, PcdDataType, SymbolTable = {}):
+    def __init__(self, Expression, PcdDataType, SymbolTable = None):
+        if SymbolTable is None:
+            SymbolTable = {}
         super(RangeExpression, self).__init__(self, Expression, PcdDataType, SymbolTable)
         self._NoProcess = False
         if not isinstance(Expression, type('')):
diff --git a/BaseTools/Source/Python/Common/StringUtils.py b/BaseTools/Source/Python/Common/StringUtils.py
index 0febbc0034..73dafa797a 100644
--- a/BaseTools/Source/Python/Common/StringUtils.py
+++ b/BaseTools/Source/Python/Common/StringUtils.py
@@ -243,8 +243,10 @@ def SplitModuleType(Key):
 #
 # @retval NewList           A new string list whose macros are replaced
 #
-def ReplaceMacros(StringList, MacroDefinitions={}, SelfReplacement=False):
+def ReplaceMacros(StringList, MacroDefinitions=None, SelfReplacement=False):
     NewList = []
+    if MacroDefinitions is None:
+        MacroDefinitions = {}
     for String in StringList:
         if isinstance(String, type('')):
             NewList.append(ReplaceMacro(String, MacroDefinitions, SelfReplacement))
@@ -264,8 +266,10 @@ def ReplaceMacros(StringList, MacroDefinitions={}, SelfReplacement=False):
 #
 # @retval string            The string whose macros are replaced
 #
-def ReplaceMacro(String, MacroDefinitions={}, SelfReplacement=False, RaiseError=False):
+def ReplaceMacro(String, MacroDefinitions=None, SelfReplacement=False, RaiseError=False):
     LastString = String
+    if MacroDefinitions is None:
+        MacroDefinitions = {}
     while String and MacroDefinitions:
         MacroUsed = GlobalData.gMacroRefPattern.findall(String)
         # no macro found in String, stop replacing
@@ -298,7 +302,7 @@ def ReplaceMacro(String, MacroDefinitions={}, SelfReplacement=False, RaiseError=
 #
 # @retval Path Formatted path
 #
-def NormPath(Path, Defines={}):
+def NormPath(Path, Defines=None):
     IsRelativePath = False
     if Path:
         if Path[0] == '.':
diff --git a/BaseTools/Source/Python/GenFds/AprioriSection.py b/BaseTools/Source/Python/GenFds/AprioriSection.py
index be2d9f6de5..9f64c613eb 100644
--- a/BaseTools/Source/Python/GenFds/AprioriSection.py
+++ b/BaseTools/Source/Python/GenFds/AprioriSection.py
@@ -46,7 +46,9 @@ class AprioriSection (object):
     #   @param  Dict        dictionary contains macro and its value
     #   @retval string      Generated file name
     #
-    def GenFfs (self, FvName, Dict = {}, IsMakefile = False):
+    def GenFfs (self, FvName, Dict = None, IsMakefile = False):
+        if Dict is None:
+            Dict = {}
         Buffer = BytesIO()
         if self.AprioriType == "PEI":
             AprioriFileGuid = PEI_APRIORI_GUID
diff --git a/BaseTools/Source/Python/GenFds/CompressSection.py b/BaseTools/Source/Python/GenFds/CompressSection.py
index 4dae5dba35..e62280fc16 100644
--- a/BaseTools/Source/Python/GenFds/CompressSection.py
+++ b/BaseTools/Source/Python/GenFds/CompressSection.py
@@ -49,7 +49,7 @@ class CompressSection (CompressSectionClassObject) :
     #   @param  Dict        dictionary contains macro and its value
     #   @retval tuple       (Generated file name, section alignment)
     #
-    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}, IsMakefile = False):
+    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = None, IsMakefile = False):
 
         if FfsInf is not None:
             self.CompType = FfsInf.__ExtendMacro__(self.CompType)
@@ -59,6 +59,8 @@ class CompressSection (CompressSectionClassObject) :
         SectAlign = []
         Index = 0
         MaxAlign = None
+        if Dict is None:
+            Dict = {}
         for Sect in self.SectionList:
             Index = Index + 1
             SecIndex = '%s.%d' %(SecNum, Index)
diff --git a/BaseTools/Source/Python/GenFds/DataSection.py b/BaseTools/Source/Python/GenFds/DataSection.py
index 60b94fbe08..f20fd70225 100644
--- a/BaseTools/Source/Python/GenFds/DataSection.py
+++ b/BaseTools/Source/Python/GenFds/DataSection.py
@@ -44,10 +44,12 @@ class DataSection (DataSectionClassObject):
     #   @param  Dict        dictionary contains macro and its value
     #   @retval tuple       (Generated file name list, section alignment)
     #
-    def GenSection(self, OutputPath, ModuleName, SecNum, keyStringList, FfsFile = None, Dict = {}, IsMakefile = False):
+    def GenSection(self, OutputPath, ModuleName, SecNum, keyStringList, FfsFile = None, Dict = None, IsMakefile = False):
         #
         # Prepare the parameter of GenSection
         #
+        if Dict is None:
+            Dict = {}
         if FfsFile is not None:
             self.SectFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.SectFileName)
             self.SectFileName = GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict, FfsFile.CurrentArch)
diff --git a/BaseTools/Source/Python/GenFds/EfiSection.py b/BaseTools/Source/Python/GenFds/EfiSection.py
index 74f176cfef..db892df345 100644
--- a/BaseTools/Source/Python/GenFds/EfiSection.py
+++ b/BaseTools/Source/Python/GenFds/EfiSection.py
@@ -49,7 +49,7 @@ class EfiSection (EfiSectionClassObject):
     #   @param  Dict        dictionary contains macro and its value
     #   @retval tuple       (Generated file name list, section alignment)
     #
-    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}, IsMakefile = False) :
+    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = None, IsMakefile = False) :
 
         if self.FileName is not None and self.FileName.startswith('PCD('):
             self.FileName = GenFdsGlobalVariable.GetPcdValue(self.FileName)
@@ -76,6 +76,8 @@ class EfiSection (EfiSectionClassObject):
 
         """If the file name was pointed out, add it in FileList"""
         FileList = []
+        if Dict is None:
+            Dict = {}
         if Filename is not None:
             Filename = GenFdsGlobalVariable.MacroExtend(Filename, Dict)
             # check if the path is absolute or relative
diff --git a/BaseTools/Source/Python/GenFds/FfsFileStatement.py b/BaseTools/Source/Python/GenFds/FfsFileStatement.py
index 9250361d14..9fb62b0a91 100644
--- a/BaseTools/Source/Python/GenFds/FfsFileStatement.py
+++ b/BaseTools/Source/Python/GenFds/FfsFileStatement.py
@@ -48,7 +48,7 @@ class FileStatement (FileStatementClassObject):
     #   @param  FvParentAddr Parent Fv base address
     #   @retval string       Generated FFS file name
     #
-    def GenFfs(self, Dict = {}, FvChildAddr=[], FvParentAddr=None, IsMakefile=False, FvName=None):
+    def GenFfs(self, Dict = None, FvChildAddr=[], FvParentAddr=None, IsMakefile=False, FvName=None):
 
         if self.NameGuid and self.NameGuid.startswith('PCD('):
             PcdValue = GenFdsGlobalVariable.GetPcdValue(self.NameGuid)
@@ -70,6 +70,9 @@ class FileStatement (FileStatementClassObject):
         if not os.path.exists(OutputDir):
             os.makedirs(OutputDir)
 
+        if Dict is None:
+            Dict = {}
+
         Dict.update(self.DefineVarDict)
         SectionAlignments = None
         if self.FvName:
diff --git a/BaseTools/Source/Python/GenFds/FfsInfStatement.py b/BaseTools/Source/Python/GenFds/FfsInfStatement.py
index 43dbd0102f..20573ca28d 100644
--- a/BaseTools/Source/Python/GenFds/FfsInfStatement.py
+++ b/BaseTools/Source/Python/GenFds/FfsInfStatement.py
@@ -437,11 +437,12 @@ class FfsInfStatement(FfsInfStatementClassObject):
     #   @param  FvParentAddr Parent Fv base address
     #   @retval string       Generated FFS file name
     #
-    def GenFfs(self, Dict = {}, FvChildAddr = [], FvParentAddr=None, IsMakefile=False, FvName=None):
+    def GenFfs(self, Dict = None, FvChildAddr = [], FvParentAddr=None, IsMakefile=False, FvName=None):
         #
         # Parse Inf file get Module related information
         #
-
+        if Dict is None:
+            Dict = {}
         self.__InfParse__(Dict, IsGenFfs=True)
         Arch = self.GetCurrentArch()
         SrcFile = mws.join( GenFdsGlobalVariable.WorkSpaceDir, self.InfFileName);
diff --git a/BaseTools/Source/Python/GenFds/Fv.py b/BaseTools/Source/Python/GenFds/Fv.py
index 206bd02005..16c944a0bd 100644
--- a/BaseTools/Source/Python/GenFds/Fv.py
+++ b/BaseTools/Source/Python/GenFds/Fv.py
@@ -71,9 +71,11 @@ class FV (object):
     #   @param  MacroDict   macro value pair
     #   @retval string      Generated FV file path
     #
-    def AddToBuffer (self, Buffer, BaseAddress=None, BlockSize= None, BlockNum=None, ErasePloarity='1',  MacroDict = {}, Flag=False):
+    def AddToBuffer (self, Buffer, BaseAddress=None, BlockSize= None, BlockNum=None, ErasePloarity='1',  MacroDict = None, Flag=False):
         if BaseAddress is None and self.UiFvName.upper() + 'fv' in GenFdsGlobalVariable.ImageBinDict:
             return GenFdsGlobalVariable.ImageBinDict[self.UiFvName.upper() + 'fv']
+        if MacroDict is None:
+            MacroDict = {}
 
         #
         # Check whether FV in Capsule is in FD flash region.
diff --git a/BaseTools/Source/Python/GenFds/FvImageSection.py b/BaseTools/Source/Python/GenFds/FvImageSection.py
index b2953d822b..ff2d5ca3c0 100644
--- a/BaseTools/Source/Python/GenFds/FvImageSection.py
+++ b/BaseTools/Source/Python/GenFds/FvImageSection.py
@@ -47,9 +47,11 @@ class FvImageSection(FvImageSectionClassObject):
     #   @param  Dict        dictionary contains macro and its value
     #   @retval tuple       (Generated file name, section alignment)
     #
-    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}, IsMakefile = False):
+    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = None, IsMakefile = False):
 
         OutputFileList = []
+        if Dict is None:
+            Dict = {}
         if self.FvFileType is not None:
             FileList, IsSect = Section.Section.GetFileList(FfsInf, self.FvFileType, self.FvFileExtension)
             if IsSect :
diff --git a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
index 3dc73c8f61..4d8b2bdee2 100644
--- a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
+++ b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
@@ -742,7 +742,7 @@ class GenFdsGlobalVariable:
     #   @param  MacroDict     Dictionary that contains macro value pair
     #
     @staticmethod
-    def MacroExtend (Str, MacroDict={}, Arch=DataType.TAB_COMMON):
+    def MacroExtend (Str, MacroDict=None, Arch=DataType.TAB_COMMON):
         if Str is None:
             return None
 
diff --git a/BaseTools/Source/Python/GenFds/GuidSection.py b/BaseTools/Source/Python/GenFds/GuidSection.py
index 530e2b3957..8db6e2feb3 100644
--- a/BaseTools/Source/Python/GenFds/GuidSection.py
+++ b/BaseTools/Source/Python/GenFds/GuidSection.py
@@ -50,7 +50,7 @@ class GuidSection(GuidSectionClassObject) :
     #   @param  Dict        dictionary contains macro and its value
     #   @retval tuple       (Generated file name, section alignment)
     #
-    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf=None, Dict={}, IsMakefile=False):
+    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf=None, Dict=None, IsMakefile=False):
         #
         # Generate all section
         #
@@ -66,6 +66,8 @@ class GuidSection(GuidSectionClassObject) :
         SectAlign = []
         Index = 0
         MaxAlign = None
+        if Dict is None:
+            Dict = {}
         if self.FvAddr != []:
             FvAddrIsSet = True
         else:
diff --git a/BaseTools/Source/Python/GenFds/OptRomFileStatement.py b/BaseTools/Source/Python/GenFds/OptRomFileStatement.py
index 0c54f48da2..1bd4d4572a 100644
--- a/BaseTools/Source/Python/GenFds/OptRomFileStatement.py
+++ b/BaseTools/Source/Python/GenFds/OptRomFileStatement.py
@@ -34,7 +34,10 @@ class OptRomFileStatement:
     #   @param  Dict        dictionary contains macro and value pair
     #   @retval string      Generated FFS file name
     #
-    def GenFfs(self, Dict = {}, IsMakefile=False):
+    def GenFfs(self, Dict = None, IsMakefile=False):
+
+        if Dict is None:
+            Dict = {}
 
         if self.FileName is not None:
             self.FileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName)
diff --git a/BaseTools/Source/Python/GenFds/Region.py b/BaseTools/Source/Python/GenFds/Region.py
index 7d5a3ab173..e95cfcf965 100644
--- a/BaseTools/Source/Python/GenFds/Region.py
+++ b/BaseTools/Source/Python/GenFds/Region.py
@@ -73,8 +73,10 @@ class Region(object):
     #   @retval string      Generated FV file path
     #
 
-    def AddToBuffer(self, Buffer, BaseAddress, BlockSizeList, ErasePolarity, ImageBinDict,  MacroDict={}, Flag=False):
+    def AddToBuffer(self, Buffer, BaseAddress, BlockSizeList, ErasePolarity, ImageBinDict,  MacroDict=None, Flag=False):
         Size = self.Size
+        if MacroDict is None:
+            MacroDict = {}
         if not Flag:
             GenFdsGlobalVariable.InfLogger('\nGenerate Region at Offset 0x%X' % self.Offset)
             GenFdsGlobalVariable.InfLogger("   Region Size = 0x%X" % Size)
diff --git a/BaseTools/Source/Python/GenFds/Section.py b/BaseTools/Source/Python/GenFds/Section.py
index b238956634..2acb70f412 100644
--- a/BaseTools/Source/Python/GenFds/Section.py
+++ b/BaseTools/Source/Python/GenFds/Section.py
@@ -92,7 +92,7 @@ class Section (SectionClassObject):
     #   @param  FfsInf      FfsInfStatement object that contains this section data
     #   @param  Dict        dictionary contains macro and its value
     #
-    def GenSection(self, OutputPath, GuidName, SecNum, keyStringList, FfsInf = None, Dict = {}):
+    def GenSection(self, OutputPath, GuidName, SecNum, keyStringList, FfsInf = None, Dict = None):
         pass
 
     ## GetFileList() method
diff --git a/BaseTools/Source/Python/GenFds/UiSection.py b/BaseTools/Source/Python/GenFds/UiSection.py
index c9fc5997a1..f643058bd6 100644
--- a/BaseTools/Source/Python/GenFds/UiSection.py
+++ b/BaseTools/Source/Python/GenFds/UiSection.py
@@ -44,7 +44,7 @@ class UiSection (UiSectionClassObject):
     #   @param  Dict        dictionary contains macro and its value
     #   @retval tuple       (Generated file name, section alignment)
     #
-    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf=None, Dict={}, IsMakefile = False):
+    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf=None, Dict=None, IsMakefile = False):
         #
         # Prepare the parameter of GenSection
         #
@@ -58,6 +58,8 @@ class UiSection (UiSectionClassObject):
         if self.StringData is not None :
             NameString = self.StringData
         elif self.FileName is not None:
+            if Dict is None:
+                Dict = {}
             FileNameStr = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName)
             FileNameStr = GenFdsGlobalVariable.MacroExtend(FileNameStr, Dict)
             FileObj = open(FileNameStr, 'r')
diff --git a/BaseTools/Source/Python/GenFds/VerSection.py b/BaseTools/Source/Python/GenFds/VerSection.py
index 1e7b391412..7280e80cb4 100644
--- a/BaseTools/Source/Python/GenFds/VerSection.py
+++ b/BaseTools/Source/Python/GenFds/VerSection.py
@@ -42,7 +42,7 @@ class VerSection (VerSectionClassObject):
     #   @param  Dict        dictionary contains macro and its value
     #   @retval tuple       (Generated file name, section alignment)
     #
-    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf=None, Dict={}, IsMakefile = False):
+    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf=None, Dict=None, IsMakefile = False):
         #
         # Prepare the parameter of GenSection
         #
@@ -61,6 +61,8 @@ class VerSection (VerSectionClassObject):
         if self.StringData:
             StringData = self.StringData
         elif self.FileName:
+            if Dict is None:
+                Dict = {}
             FileNameStr = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName)
             FileNameStr = GenFdsGlobalVariable.MacroExtend(FileNameStr, Dict)
             FileObj = open(FileNameStr, 'r')
-- 
2.14.1.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#47178): https://edk2.groups.io/g/devel/message/47178
Mute This Topic: https://groups.io/mt/34112947/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [PATCH] BaseTools:change some incorrect parameter defaults
Posted by Bob Feng 4 years, 6 months ago
Reviewed-by: Bob Feng <bob.c.feng@intel.com>

-----Original Message-----
From: Fan, ZhijuX 
Sent: Thursday, September 12, 2019 4:18 PM
To: devel@edk2.groups.io
Cc: Gao, Liming <liming.gao@intel.com>; Feng, Bob C <bob.c.feng@intel.com>
Subject: [PATCH] BaseTools:change some incorrect parameter defaults

BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=1858

for Dict={},There are pitfalls in the way this default parameter is set and Dict is not used in functions, other functions have these two cases, I will change some incorrect parameter defaults

This patch is going to fix this issue

Cc: Liming Gao <liming.gao@intel.com>
Cc: Bob Feng <bob.c.feng@intel.com>
Signed-off-by: Zhiju.Fan <zhijux.fan@intel.com>
---
 BaseTools/Source/Python/AutoGen/BuildEngine.py         |  4 +++-
 BaseTools/Source/Python/AutoGen/GenMake.py             |  6 ++++--
 BaseTools/Source/Python/Common/RangeExpression.py      |  4 +++-
 BaseTools/Source/Python/Common/StringUtils.py          | 10 +++++++---
 BaseTools/Source/Python/GenFds/AprioriSection.py       |  4 +++-
 BaseTools/Source/Python/GenFds/CompressSection.py      |  4 +++-
 BaseTools/Source/Python/GenFds/DataSection.py          |  4 +++-
 BaseTools/Source/Python/GenFds/EfiSection.py           |  4 +++-
 BaseTools/Source/Python/GenFds/FfsFileStatement.py     |  5 ++++-
 BaseTools/Source/Python/GenFds/FfsInfStatement.py      |  5 +++--
 BaseTools/Source/Python/GenFds/Fv.py                   |  4 +++-
 BaseTools/Source/Python/GenFds/FvImageSection.py       |  4 +++-
 BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py |  2 +-
 BaseTools/Source/Python/GenFds/GuidSection.py          |  4 +++-
 BaseTools/Source/Python/GenFds/OptRomFileStatement.py  |  5 ++++-
 BaseTools/Source/Python/GenFds/Region.py               |  4 +++-
 BaseTools/Source/Python/GenFds/Section.py              |  2 +-
 BaseTools/Source/Python/GenFds/UiSection.py            |  4 +++-
 BaseTools/Source/Python/GenFds/VerSection.py           |  4 +++-
 19 files changed, 60 insertions(+), 23 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/BuildEngine.py b/BaseTools/Source/Python/AutoGen/BuildEngine.py
index bb91534477..069a3a1c9d 100644
--- a/BaseTools/Source/Python/AutoGen/BuildEngine.py
+++ b/BaseTools/Source/Python/AutoGen/BuildEngine.py
@@ -176,7 +176,9 @@ class FileBuildRule:
         CommandString = "\n\t".join(self.CommandList)
         return "%s : %s\n\t%s" % (DestString, SourceString, CommandString)
 
-    def Instantiate(self, Macros={}):
+    def Instantiate(self, Macros = None):
+        if Macros is None:
+            Macros = {}
         NewRuleObject = copy.copy(self)
         NewRuleObject.BuildTargets = {}
         NewRuleObject.DestFileList = [] diff --git a/BaseTools/Source/Python/AutoGen/GenMake.py b/BaseTools/Source/Python/AutoGen/GenMake.py
index 4f85a93055..3185ebe368 100755
--- a/BaseTools/Source/Python/AutoGen/GenMake.py
+++ b/BaseTools/Source/Python/AutoGen/GenMake.py
@@ -205,10 +205,12 @@ class BuildFile(object):
     def GetRemoveDirectoryCommand(self, DirList):
         return [self._RD_TEMPLATE_[self._FileType] % {'dir':Dir} for Dir in DirList]
 
-    def PlaceMacro(self, Path, MacroDefinitions={}):
+    def PlaceMacro(self, Path, MacroDefinitions=None):
         if Path.startswith("$("):
             return Path
         else:
+            if MacroDefinitions is None:
+                MacroDefinitions = {}
             PathLength = len(Path)
             for MacroName in MacroDefinitions:
                 MacroValue = MacroDefinitions[MacroName] @@ -1762,4 +1764,4 @@ def GetDependencyList(AutoGenObject, FileCache, File, ForceList, SearchPathList)
 
 # This acts like the main() function for the script, unless it is 'import'ed into another script.
 if __name__ == '__main__':
-    pass
\ No newline at end of file
+    pass
diff --git a/BaseTools/Source/Python/Common/RangeExpression.py b/BaseTools/Source/Python/Common/RangeExpression.py
index e9296e03f6..039d281467 100644
--- a/BaseTools/Source/Python/Common/RangeExpression.py
+++ b/BaseTools/Source/Python/Common/RangeExpression.py
@@ -342,7 +342,9 @@ class RangeExpression(BaseExpression):
                 raise BadExpression(ERR_STRING_EXPR % Operator)
 
 
-    def __init__(self, Expression, PcdDataType, SymbolTable = {}):
+    def __init__(self, Expression, PcdDataType, SymbolTable = None):
+        if SymbolTable is None:
+            SymbolTable = {}
         super(RangeExpression, self).__init__(self, Expression, PcdDataType, SymbolTable)
         self._NoProcess = False
         if not isinstance(Expression, type('')):
diff --git a/BaseTools/Source/Python/Common/StringUtils.py b/BaseTools/Source/Python/Common/StringUtils.py
index 0febbc0034..73dafa797a 100644
--- a/BaseTools/Source/Python/Common/StringUtils.py
+++ b/BaseTools/Source/Python/Common/StringUtils.py
@@ -243,8 +243,10 @@ def SplitModuleType(Key):
 #
 # @retval NewList           A new string list whose macros are replaced
 #
-def ReplaceMacros(StringList, MacroDefinitions={}, SelfReplacement=False):
+def ReplaceMacros(StringList, MacroDefinitions=None, SelfReplacement=False):
     NewList = []
+    if MacroDefinitions is None:
+        MacroDefinitions = {}
     for String in StringList:
         if isinstance(String, type('')):
             NewList.append(ReplaceMacro(String, MacroDefinitions, SelfReplacement)) @@ -264,8 +266,10 @@ def ReplaceMacros(StringList, MacroDefinitions={}, SelfReplacement=False):
 #
 # @retval string            The string whose macros are replaced
 #
-def ReplaceMacro(String, MacroDefinitions={}, SelfReplacement=False, RaiseError=False):
+def ReplaceMacro(String, MacroDefinitions=None, SelfReplacement=False, RaiseError=False):
     LastString = String
+    if MacroDefinitions is None:
+        MacroDefinitions = {}
     while String and MacroDefinitions:
         MacroUsed = GlobalData.gMacroRefPattern.findall(String)
         # no macro found in String, stop replacing @@ -298,7 +302,7 @@ def ReplaceMacro(String, MacroDefinitions={}, SelfReplacement=False, RaiseError=  #  # @retval Path Formatted path  # -def NormPath(Path, Defines={}):
+def NormPath(Path, Defines=None):
     IsRelativePath = False
     if Path:
         if Path[0] == '.':
diff --git a/BaseTools/Source/Python/GenFds/AprioriSection.py b/BaseTools/Source/Python/GenFds/AprioriSection.py
index be2d9f6de5..9f64c613eb 100644
--- a/BaseTools/Source/Python/GenFds/AprioriSection.py
+++ b/BaseTools/Source/Python/GenFds/AprioriSection.py
@@ -46,7 +46,9 @@ class AprioriSection (object):
     #   @param  Dict        dictionary contains macro and its value
     #   @retval string      Generated file name
     #
-    def GenFfs (self, FvName, Dict = {}, IsMakefile = False):
+    def GenFfs (self, FvName, Dict = None, IsMakefile = False):
+        if Dict is None:
+            Dict = {}
         Buffer = BytesIO()
         if self.AprioriType == "PEI":
             AprioriFileGuid = PEI_APRIORI_GUID diff --git a/BaseTools/Source/Python/GenFds/CompressSection.py b/BaseTools/Source/Python/GenFds/CompressSection.py
index 4dae5dba35..e62280fc16 100644
--- a/BaseTools/Source/Python/GenFds/CompressSection.py
+++ b/BaseTools/Source/Python/GenFds/CompressSection.py
@@ -49,7 +49,7 @@ class CompressSection (CompressSectionClassObject) :
     #   @param  Dict        dictionary contains macro and its value
     #   @retval tuple       (Generated file name, section alignment)
     #
-    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}, IsMakefile = False):
+    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = None, IsMakefile = False):
 
         if FfsInf is not None:
             self.CompType = FfsInf.__ExtendMacro__(self.CompType)
@@ -59,6 +59,8 @@ class CompressSection (CompressSectionClassObject) :
         SectAlign = []
         Index = 0
         MaxAlign = None
+        if Dict is None:
+            Dict = {}
         for Sect in self.SectionList:
             Index = Index + 1
             SecIndex = '%s.%d' %(SecNum, Index) diff --git a/BaseTools/Source/Python/GenFds/DataSection.py b/BaseTools/Source/Python/GenFds/DataSection.py
index 60b94fbe08..f20fd70225 100644
--- a/BaseTools/Source/Python/GenFds/DataSection.py
+++ b/BaseTools/Source/Python/GenFds/DataSection.py
@@ -44,10 +44,12 @@ class DataSection (DataSectionClassObject):
     #   @param  Dict        dictionary contains macro and its value
     #   @retval tuple       (Generated file name list, section alignment)
     #
-    def GenSection(self, OutputPath, ModuleName, SecNum, keyStringList, FfsFile = None, Dict = {}, IsMakefile = False):
+    def GenSection(self, OutputPath, ModuleName, SecNum, keyStringList, FfsFile = None, Dict = None, IsMakefile = False):
         #
         # Prepare the parameter of GenSection
         #
+        if Dict is None:
+            Dict = {}
         if FfsFile is not None:
             self.SectFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.SectFileName)
             self.SectFileName = GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict, FfsFile.CurrentArch) diff --git a/BaseTools/Source/Python/GenFds/EfiSection.py b/BaseTools/Source/Python/GenFds/EfiSection.py
index 74f176cfef..db892df345 100644
--- a/BaseTools/Source/Python/GenFds/EfiSection.py
+++ b/BaseTools/Source/Python/GenFds/EfiSection.py
@@ -49,7 +49,7 @@ class EfiSection (EfiSectionClassObject):
     #   @param  Dict        dictionary contains macro and its value
     #   @retval tuple       (Generated file name list, section alignment)
     #
-    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}, IsMakefile = False) :
+    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = None, IsMakefile = False) :
 
         if self.FileName is not None and self.FileName.startswith('PCD('):
             self.FileName = GenFdsGlobalVariable.GetPcdValue(self.FileName)
@@ -76,6 +76,8 @@ class EfiSection (EfiSectionClassObject):
 
         """If the file name was pointed out, add it in FileList"""
         FileList = []
+        if Dict is None:
+            Dict = {}
         if Filename is not None:
             Filename = GenFdsGlobalVariable.MacroExtend(Filename, Dict)
             # check if the path is absolute or relative diff --git a/BaseTools/Source/Python/GenFds/FfsFileStatement.py b/BaseTools/Source/Python/GenFds/FfsFileStatement.py
index 9250361d14..9fb62b0a91 100644
--- a/BaseTools/Source/Python/GenFds/FfsFileStatement.py
+++ b/BaseTools/Source/Python/GenFds/FfsFileStatement.py
@@ -48,7 +48,7 @@ class FileStatement (FileStatementClassObject):
     #   @param  FvParentAddr Parent Fv base address
     #   @retval string       Generated FFS file name
     #
-    def GenFfs(self, Dict = {}, FvChildAddr=[], FvParentAddr=None, IsMakefile=False, FvName=None):
+    def GenFfs(self, Dict = None, FvChildAddr=[], FvParentAddr=None, IsMakefile=False, FvName=None):
 
         if self.NameGuid and self.NameGuid.startswith('PCD('):
             PcdValue = GenFdsGlobalVariable.GetPcdValue(self.NameGuid)
@@ -70,6 +70,9 @@ class FileStatement (FileStatementClassObject):
         if not os.path.exists(OutputDir):
             os.makedirs(OutputDir)
 
+        if Dict is None:
+            Dict = {}
+
         Dict.update(self.DefineVarDict)
         SectionAlignments = None
         if self.FvName:
diff --git a/BaseTools/Source/Python/GenFds/FfsInfStatement.py b/BaseTools/Source/Python/GenFds/FfsInfStatement.py
index 43dbd0102f..20573ca28d 100644
--- a/BaseTools/Source/Python/GenFds/FfsInfStatement.py
+++ b/BaseTools/Source/Python/GenFds/FfsInfStatement.py
@@ -437,11 +437,12 @@ class FfsInfStatement(FfsInfStatementClassObject):
     #   @param  FvParentAddr Parent Fv base address
     #   @retval string       Generated FFS file name
     #
-    def GenFfs(self, Dict = {}, FvChildAddr = [], FvParentAddr=None, IsMakefile=False, FvName=None):
+    def GenFfs(self, Dict = None, FvChildAddr = [], FvParentAddr=None, IsMakefile=False, FvName=None):
         #
         # Parse Inf file get Module related information
         #
-
+        if Dict is None:
+            Dict = {}
         self.__InfParse__(Dict, IsGenFfs=True)
         Arch = self.GetCurrentArch()
         SrcFile = mws.join( GenFdsGlobalVariable.WorkSpaceDir, self.InfFileName); diff --git a/BaseTools/Source/Python/GenFds/Fv.py b/BaseTools/Source/Python/GenFds/Fv.py
index 206bd02005..16c944a0bd 100644
--- a/BaseTools/Source/Python/GenFds/Fv.py
+++ b/BaseTools/Source/Python/GenFds/Fv.py
@@ -71,9 +71,11 @@ class FV (object):
     #   @param  MacroDict   macro value pair
     #   @retval string      Generated FV file path
     #
-    def AddToBuffer (self, Buffer, BaseAddress=None, BlockSize= None, BlockNum=None, ErasePloarity='1',  MacroDict = {}, Flag=False):
+    def AddToBuffer (self, Buffer, BaseAddress=None, BlockSize= None, BlockNum=None, ErasePloarity='1',  MacroDict = None, Flag=False):
         if BaseAddress is None and self.UiFvName.upper() + 'fv' in GenFdsGlobalVariable.ImageBinDict:
             return GenFdsGlobalVariable.ImageBinDict[self.UiFvName.upper() + 'fv']
+        if MacroDict is None:
+            MacroDict = {}
 
         #
         # Check whether FV in Capsule is in FD flash region.
diff --git a/BaseTools/Source/Python/GenFds/FvImageSection.py b/BaseTools/Source/Python/GenFds/FvImageSection.py
index b2953d822b..ff2d5ca3c0 100644
--- a/BaseTools/Source/Python/GenFds/FvImageSection.py
+++ b/BaseTools/Source/Python/GenFds/FvImageSection.py
@@ -47,9 +47,11 @@ class FvImageSection(FvImageSectionClassObject):
     #   @param  Dict        dictionary contains macro and its value
     #   @retval tuple       (Generated file name, section alignment)
     #
-    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}, IsMakefile = False):
+    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = None, IsMakefile = False):
 
         OutputFileList = []
+        if Dict is None:
+            Dict = {}
         if self.FvFileType is not None:
             FileList, IsSect = Section.Section.GetFileList(FfsInf, self.FvFileType, self.FvFileExtension)
             if IsSect :
diff --git a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
index 3dc73c8f61..4d8b2bdee2 100644
--- a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
+++ b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
@@ -742,7 +742,7 @@ class GenFdsGlobalVariable:
     #   @param  MacroDict     Dictionary that contains macro value pair
     #
     @staticmethod
-    def MacroExtend (Str, MacroDict={}, Arch=DataType.TAB_COMMON):
+    def MacroExtend (Str, MacroDict=None, Arch=DataType.TAB_COMMON):
         if Str is None:
             return None
 
diff --git a/BaseTools/Source/Python/GenFds/GuidSection.py b/BaseTools/Source/Python/GenFds/GuidSection.py
index 530e2b3957..8db6e2feb3 100644
--- a/BaseTools/Source/Python/GenFds/GuidSection.py
+++ b/BaseTools/Source/Python/GenFds/GuidSection.py
@@ -50,7 +50,7 @@ class GuidSection(GuidSectionClassObject) :
     #   @param  Dict        dictionary contains macro and its value
     #   @retval tuple       (Generated file name, section alignment)
     #
-    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf=None, Dict={}, IsMakefile=False):
+    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf=None, Dict=None, IsMakefile=False):
         #
         # Generate all section
         #
@@ -66,6 +66,8 @@ class GuidSection(GuidSectionClassObject) :
         SectAlign = []
         Index = 0
         MaxAlign = None
+        if Dict is None:
+            Dict = {}
         if self.FvAddr != []:
             FvAddrIsSet = True
         else:
diff --git a/BaseTools/Source/Python/GenFds/OptRomFileStatement.py b/BaseTools/Source/Python/GenFds/OptRomFileStatement.py
index 0c54f48da2..1bd4d4572a 100644
--- a/BaseTools/Source/Python/GenFds/OptRomFileStatement.py
+++ b/BaseTools/Source/Python/GenFds/OptRomFileStatement.py
@@ -34,7 +34,10 @@ class OptRomFileStatement:
     #   @param  Dict        dictionary contains macro and value pair
     #   @retval string      Generated FFS file name
     #
-    def GenFfs(self, Dict = {}, IsMakefile=False):
+    def GenFfs(self, Dict = None, IsMakefile=False):
+
+        if Dict is None:
+            Dict = {}
 
         if self.FileName is not None:
             self.FileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName)
diff --git a/BaseTools/Source/Python/GenFds/Region.py b/BaseTools/Source/Python/GenFds/Region.py
index 7d5a3ab173..e95cfcf965 100644
--- a/BaseTools/Source/Python/GenFds/Region.py
+++ b/BaseTools/Source/Python/GenFds/Region.py
@@ -73,8 +73,10 @@ class Region(object):
     #   @retval string      Generated FV file path
     #
 
-    def AddToBuffer(self, Buffer, BaseAddress, BlockSizeList, ErasePolarity, ImageBinDict,  MacroDict={}, Flag=False):
+    def AddToBuffer(self, Buffer, BaseAddress, BlockSizeList, ErasePolarity, ImageBinDict,  MacroDict=None, Flag=False):
         Size = self.Size
+        if MacroDict is None:
+            MacroDict = {}
         if not Flag:
             GenFdsGlobalVariable.InfLogger('\nGenerate Region at Offset 0x%X' % self.Offset)
             GenFdsGlobalVariable.InfLogger("   Region Size = 0x%X" % Size)
diff --git a/BaseTools/Source/Python/GenFds/Section.py b/BaseTools/Source/Python/GenFds/Section.py
index b238956634..2acb70f412 100644
--- a/BaseTools/Source/Python/GenFds/Section.py
+++ b/BaseTools/Source/Python/GenFds/Section.py
@@ -92,7 +92,7 @@ class Section (SectionClassObject):
     #   @param  FfsInf      FfsInfStatement object that contains this section data
     #   @param  Dict        dictionary contains macro and its value
     #
-    def GenSection(self, OutputPath, GuidName, SecNum, keyStringList, FfsInf = None, Dict = {}):
+    def GenSection(self, OutputPath, GuidName, SecNum, keyStringList, FfsInf = None, Dict = None):
         pass
 
     ## GetFileList() method
diff --git a/BaseTools/Source/Python/GenFds/UiSection.py b/BaseTools/Source/Python/GenFds/UiSection.py
index c9fc5997a1..f643058bd6 100644
--- a/BaseTools/Source/Python/GenFds/UiSection.py
+++ b/BaseTools/Source/Python/GenFds/UiSection.py
@@ -44,7 +44,7 @@ class UiSection (UiSectionClassObject):
     #   @param  Dict        dictionary contains macro and its value
     #   @retval tuple       (Generated file name, section alignment)
     #
-    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf=None, Dict={}, IsMakefile = False):
+    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf=None, Dict=None, IsMakefile = False):
         #
         # Prepare the parameter of GenSection
         #
@@ -58,6 +58,8 @@ class UiSection (UiSectionClassObject):
         if self.StringData is not None :
             NameString = self.StringData
         elif self.FileName is not None:
+            if Dict is None:
+                Dict = {}
             FileNameStr = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName)
             FileNameStr = GenFdsGlobalVariable.MacroExtend(FileNameStr, Dict)
             FileObj = open(FileNameStr, 'r') diff --git a/BaseTools/Source/Python/GenFds/VerSection.py b/BaseTools/Source/Python/GenFds/VerSection.py
index 1e7b391412..7280e80cb4 100644
--- a/BaseTools/Source/Python/GenFds/VerSection.py
+++ b/BaseTools/Source/Python/GenFds/VerSection.py
@@ -42,7 +42,7 @@ class VerSection (VerSectionClassObject):
     #   @param  Dict        dictionary contains macro and its value
     #   @retval tuple       (Generated file name, section alignment)
     #
-    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf=None, Dict={}, IsMakefile = False):
+    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf=None, Dict=None, IsMakefile = False):
         #
         # Prepare the parameter of GenSection
         #
@@ -61,6 +61,8 @@ class VerSection (VerSectionClassObject):
         if self.StringData:
             StringData = self.StringData
         elif self.FileName:
+            if Dict is None:
+                Dict = {}
             FileNameStr = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName)
             FileNameStr = GenFdsGlobalVariable.MacroExtend(FileNameStr, Dict)
             FileObj = open(FileNameStr, 'r')
--
2.14.1.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#47245): https://edk2.groups.io/g/devel/message/47245
Mute This Topic: https://groups.io/mt/34112947/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-