]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools:change some incorrect parameter defaults
authorFan, ZhijuX <zhijux.fan@intel.com>
Thu, 12 Sep 2019 08:18:27 +0000 (16:18 +0800)
committerFeng, Bob C <bob.c.feng@intel.com>
Tue, 17 Sep 2019 02:18:51 +0000 (10:18 +0800)
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>
Reviewed-by: Bob Feng <bob.c.feng@intel.com>
19 files changed:
BaseTools/Source/Python/AutoGen/BuildEngine.py
BaseTools/Source/Python/AutoGen/GenMake.py
BaseTools/Source/Python/Common/RangeExpression.py
BaseTools/Source/Python/Common/StringUtils.py
BaseTools/Source/Python/GenFds/AprioriSection.py
BaseTools/Source/Python/GenFds/CompressSection.py
BaseTools/Source/Python/GenFds/DataSection.py
BaseTools/Source/Python/GenFds/EfiSection.py
BaseTools/Source/Python/GenFds/FfsFileStatement.py
BaseTools/Source/Python/GenFds/FfsInfStatement.py
BaseTools/Source/Python/GenFds/Fv.py
BaseTools/Source/Python/GenFds/FvImageSection.py
BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
BaseTools/Source/Python/GenFds/GuidSection.py
BaseTools/Source/Python/GenFds/OptRomFileStatement.py
BaseTools/Source/Python/GenFds/Region.py
BaseTools/Source/Python/GenFds/Section.py
BaseTools/Source/Python/GenFds/UiSection.py
BaseTools/Source/Python/GenFds/VerSection.py

index bb915344779338541949dec4ae80c7233daf920a..069a3a1c9db3ab8da91a97f53a5a5350c4c078f2 100644 (file)
@@ -176,7 +176,9 @@ class FileBuildRule:
         CommandString = "\n\t".join(self.CommandList)\r
         return "%s : %s\n\t%s" % (DestString, SourceString, CommandString)\r
 \r
-    def Instantiate(self, Macros={}):\r
+    def Instantiate(self, Macros = None):\r
+        if Macros is None:\r
+            Macros = {}\r
         NewRuleObject = copy.copy(self)\r
         NewRuleObject.BuildTargets = {}\r
         NewRuleObject.DestFileList = []\r
index 4f85a93055abb6e09d6c988d269224b372d888e8..3185ebe36816fffb1f2e12cda09f5d4cd3d3ca82 100755 (executable)
@@ -205,10 +205,12 @@ class BuildFile(object):
     def GetRemoveDirectoryCommand(self, DirList):\r
         return [self._RD_TEMPLATE_[self._FileType] % {'dir':Dir} for Dir in DirList]\r
 \r
-    def PlaceMacro(self, Path, MacroDefinitions={}):\r
+    def PlaceMacro(self, Path, MacroDefinitions=None):\r
         if Path.startswith("$("):\r
             return Path\r
         else:\r
+            if MacroDefinitions is None:\r
+                MacroDefinitions = {}\r
             PathLength = len(Path)\r
             for MacroName in MacroDefinitions:\r
                 MacroValue = MacroDefinitions[MacroName]\r
@@ -1762,4 +1764,4 @@ def GetDependencyList(AutoGenObject, FileCache, File, ForceList, SearchPathList)
 \r
 # This acts like the main() function for the script, unless it is 'import'ed into another script.\r
 if __name__ == '__main__':\r
-    pass\r
\ No newline at end of file
+    pass\r
index e9296e03f6a1d7101714634d13eb65bd7df3dea8..039d2814670fc4b0a9f754bbe7b409cc79989db3 100644 (file)
@@ -342,7 +342,9 @@ class RangeExpression(BaseExpression):
                 raise BadExpression(ERR_STRING_EXPR % Operator)\r
 \r
 \r
-    def __init__(self, Expression, PcdDataType, SymbolTable = {}):\r
+    def __init__(self, Expression, PcdDataType, SymbolTable = None):\r
+        if SymbolTable is None:\r
+            SymbolTable = {}\r
         super(RangeExpression, self).__init__(self, Expression, PcdDataType, SymbolTable)\r
         self._NoProcess = False\r
         if not isinstance(Expression, type('')):\r
index 0febbc0034a4d5690ffae959614489570dce9a95..73dafa797a525daf9c2a5ebb35fa020ecf7030a9 100644 (file)
@@ -243,8 +243,10 @@ def SplitModuleType(Key):
 #\r
 # @retval NewList           A new string list whose macros are replaced\r
 #\r
-def ReplaceMacros(StringList, MacroDefinitions={}, SelfReplacement=False):\r
+def ReplaceMacros(StringList, MacroDefinitions=None, SelfReplacement=False):\r
     NewList = []\r
+    if MacroDefinitions is None:\r
+        MacroDefinitions = {}\r
     for String in StringList:\r
         if isinstance(String, type('')):\r
             NewList.append(ReplaceMacro(String, MacroDefinitions, SelfReplacement))\r
@@ -264,8 +266,10 @@ def ReplaceMacros(StringList, MacroDefinitions={}, SelfReplacement=False):
 #\r
 # @retval string            The string whose macros are replaced\r
 #\r
-def ReplaceMacro(String, MacroDefinitions={}, SelfReplacement=False, RaiseError=False):\r
+def ReplaceMacro(String, MacroDefinitions=None, SelfReplacement=False, RaiseError=False):\r
     LastString = String\r
+    if MacroDefinitions is None:\r
+        MacroDefinitions = {}\r
     while String and MacroDefinitions:\r
         MacroUsed = GlobalData.gMacroRefPattern.findall(String)\r
         # no macro found in String, stop replacing\r
@@ -298,7 +302,7 @@ def ReplaceMacro(String, MacroDefinitions={}, SelfReplacement=False, RaiseError=
 #\r
 # @retval Path Formatted path\r
 #\r
-def NormPath(Path, Defines={}):\r
+def NormPath(Path, Defines=None):\r
     IsRelativePath = False\r
     if Path:\r
         if Path[0] == '.':\r
index be2d9f6de58222752f8e4b6b1b961987158be7f2..9f64c613eb8ff61a80fe1c898b52f2c3cdc36281 100644 (file)
@@ -46,7 +46,9 @@ class AprioriSection (object):
     #   @param  Dict        dictionary contains macro and its value\r
     #   @retval string      Generated file name\r
     #\r
-    def GenFfs (self, FvName, Dict = {}, IsMakefile = False):\r
+    def GenFfs (self, FvName, Dict = None, IsMakefile = False):\r
+        if Dict is None:\r
+            Dict = {}\r
         Buffer = BytesIO()\r
         if self.AprioriType == "PEI":\r
             AprioriFileGuid = PEI_APRIORI_GUID\r
index 4dae5dba352481d777a7b6b4a8ae7d1570aa66c1..e62280fc16c28db7dd249bb41b6bd3ee5750bc78 100644 (file)
@@ -49,7 +49,7 @@ class CompressSection (CompressSectionClassObject) :
     #   @param  Dict        dictionary contains macro and its value\r
     #   @retval tuple       (Generated file name, section alignment)\r
     #\r
-    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}, IsMakefile = False):\r
+    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = None, IsMakefile = False):\r
 \r
         if FfsInf is not None:\r
             self.CompType = FfsInf.__ExtendMacro__(self.CompType)\r
@@ -59,6 +59,8 @@ class CompressSection (CompressSectionClassObject) :
         SectAlign = []\r
         Index = 0\r
         MaxAlign = None\r
+        if Dict is None:\r
+            Dict = {}\r
         for Sect in self.SectionList:\r
             Index = Index + 1\r
             SecIndex = '%s.%d' %(SecNum, Index)\r
index 60b94fbe08cc8e8ccc89eedc4698df7e9d03832a..f20fd702254ae48454bc814a1b981034136a5bba 100644 (file)
@@ -44,10 +44,12 @@ class DataSection (DataSectionClassObject):
     #   @param  Dict        dictionary contains macro and its value\r
     #   @retval tuple       (Generated file name list, section alignment)\r
     #\r
-    def GenSection(self, OutputPath, ModuleName, SecNum, keyStringList, FfsFile = None, Dict = {}, IsMakefile = False):\r
+    def GenSection(self, OutputPath, ModuleName, SecNum, keyStringList, FfsFile = None, Dict = None, IsMakefile = False):\r
         #\r
         # Prepare the parameter of GenSection\r
         #\r
+        if Dict is None:\r
+            Dict = {}\r
         if FfsFile is not None:\r
             self.SectFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.SectFileName)\r
             self.SectFileName = GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict, FfsFile.CurrentArch)\r
index 74f176cfef2f9833169f1c2b7994ee1c2385ff71..db892df3451515d0f48bc90106ad8fe1cca36d59 100644 (file)
@@ -49,7 +49,7 @@ class EfiSection (EfiSectionClassObject):
     #   @param  Dict        dictionary contains macro and its value\r
     #   @retval tuple       (Generated file name list, section alignment)\r
     #\r
-    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}, IsMakefile = False) :\r
+    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = None, IsMakefile = False) :\r
 \r
         if self.FileName is not None and self.FileName.startswith('PCD('):\r
             self.FileName = GenFdsGlobalVariable.GetPcdValue(self.FileName)\r
@@ -76,6 +76,8 @@ class EfiSection (EfiSectionClassObject):
 \r
         """If the file name was pointed out, add it in FileList"""\r
         FileList = []\r
+        if Dict is None:\r
+            Dict = {}\r
         if Filename is not None:\r
             Filename = GenFdsGlobalVariable.MacroExtend(Filename, Dict)\r
             # check if the path is absolute or relative\r
index 9250361d1415fa4ce0ef9388f6f404ef22235b56..9fb62b0a9143a0022ba04370b7fc35a536aa6723 100644 (file)
@@ -48,7 +48,7 @@ class FileStatement (FileStatementClassObject):
     #   @param  FvParentAddr Parent Fv base address\r
     #   @retval string       Generated FFS file name\r
     #\r
-    def GenFfs(self, Dict = {}, FvChildAddr=[], FvParentAddr=None, IsMakefile=False, FvName=None):\r
+    def GenFfs(self, Dict = None, FvChildAddr=[], FvParentAddr=None, IsMakefile=False, FvName=None):\r
 \r
         if self.NameGuid and self.NameGuid.startswith('PCD('):\r
             PcdValue = GenFdsGlobalVariable.GetPcdValue(self.NameGuid)\r
@@ -70,6 +70,9 @@ class FileStatement (FileStatementClassObject):
         if not os.path.exists(OutputDir):\r
             os.makedirs(OutputDir)\r
 \r
+        if Dict is None:\r
+            Dict = {}\r
+\r
         Dict.update(self.DefineVarDict)\r
         SectionAlignments = None\r
         if self.FvName:\r
index 43dbd0102f5eeea631f34580c6860b098d39cbd8..20573ca28d2f2c24a950d68de7ca733122d7eec3 100644 (file)
@@ -437,11 +437,12 @@ class FfsInfStatement(FfsInfStatementClassObject):
     #   @param  FvParentAddr Parent Fv base address\r
     #   @retval string       Generated FFS file name\r
     #\r
-    def GenFfs(self, Dict = {}, FvChildAddr = [], FvParentAddr=None, IsMakefile=False, FvName=None):\r
+    def GenFfs(self, Dict = None, FvChildAddr = [], FvParentAddr=None, IsMakefile=False, FvName=None):\r
         #\r
         # Parse Inf file get Module related information\r
         #\r
-\r
+        if Dict is None:\r
+            Dict = {}\r
         self.__InfParse__(Dict, IsGenFfs=True)\r
         Arch = self.GetCurrentArch()\r
         SrcFile = mws.join( GenFdsGlobalVariable.WorkSpaceDir, self.InfFileName);\r
index 206bd02005977d29e276d429fff532eb2aa016f7..16c944a0bd79c76c5f764199409831787ed80315 100644 (file)
@@ -71,9 +71,11 @@ class FV (object):
     #   @param  MacroDict   macro value pair\r
     #   @retval string      Generated FV file path\r
     #\r
-    def AddToBuffer (self, Buffer, BaseAddress=None, BlockSize= None, BlockNum=None, ErasePloarity='1',  MacroDict = {}, Flag=False):\r
+    def AddToBuffer (self, Buffer, BaseAddress=None, BlockSize= None, BlockNum=None, ErasePloarity='1',  MacroDict = None, Flag=False):\r
         if BaseAddress is None and self.UiFvName.upper() + 'fv' in GenFdsGlobalVariable.ImageBinDict:\r
             return GenFdsGlobalVariable.ImageBinDict[self.UiFvName.upper() + 'fv']\r
+        if MacroDict is None:\r
+            MacroDict = {}\r
 \r
         #\r
         # Check whether FV in Capsule is in FD flash region.\r
index b2953d822bba6415424ae2f9847943a16b237339..ff2d5ca3c05354099f7926094fa9410c4916c19a 100644 (file)
@@ -47,9 +47,11 @@ class FvImageSection(FvImageSectionClassObject):
     #   @param  Dict        dictionary contains macro and its value\r
     #   @retval tuple       (Generated file name, section alignment)\r
     #\r
-    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}, IsMakefile = False):\r
+    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = None, IsMakefile = False):\r
 \r
         OutputFileList = []\r
+        if Dict is None:\r
+            Dict = {}\r
         if self.FvFileType is not None:\r
             FileList, IsSect = Section.Section.GetFileList(FfsInf, self.FvFileType, self.FvFileExtension)\r
             if IsSect :\r
index 3dc73c8f61f9bd068778cbf7dca4fbeb7b81aade..4d8b2bdee2991907c16f20e5c94eab8be759ae45 100644 (file)
@@ -742,7 +742,7 @@ class GenFdsGlobalVariable:
     #   @param  MacroDict     Dictionary that contains macro value pair\r
     #\r
     @staticmethod\r
-    def MacroExtend (Str, MacroDict={}, Arch=DataType.TAB_COMMON):\r
+    def MacroExtend (Str, MacroDict=None, Arch=DataType.TAB_COMMON):\r
         if Str is None:\r
             return None\r
 \r
index 530e2b3957c0b5477f714e56fd3788d7bfe969a5..8db6e2feb3e4efee41a7183c0cad9028a99ffe1f 100644 (file)
@@ -50,7 +50,7 @@ class GuidSection(GuidSectionClassObject) :
     #   @param  Dict        dictionary contains macro and its value\r
     #   @retval tuple       (Generated file name, section alignment)\r
     #\r
-    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf=None, Dict={}, IsMakefile=False):\r
+    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf=None, Dict=None, IsMakefile=False):\r
         #\r
         # Generate all section\r
         #\r
@@ -66,6 +66,8 @@ class GuidSection(GuidSectionClassObject) :
         SectAlign = []\r
         Index = 0\r
         MaxAlign = None\r
+        if Dict is None:\r
+            Dict = {}\r
         if self.FvAddr != []:\r
             FvAddrIsSet = True\r
         else:\r
index 0c54f48da22d5b040a00a37045902772aeb9a0ff..1bd4d4572a17e4d55c7795f2047074c85ba2d18f 100644 (file)
@@ -34,7 +34,10 @@ class OptRomFileStatement:
     #   @param  Dict        dictionary contains macro and value pair\r
     #   @retval string      Generated FFS file name\r
     #\r
-    def GenFfs(self, Dict = {}, IsMakefile=False):\r
+    def GenFfs(self, Dict = None, IsMakefile=False):\r
+\r
+        if Dict is None:\r
+            Dict = {}\r
 \r
         if self.FileName is not None:\r
             self.FileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName)\r
index 7d5a3ab1737a52f77d0bf465df1073ef80cc4a3f..e95cfcf965d2f21990cff7fadcd491077abc2e16 100644 (file)
@@ -73,8 +73,10 @@ class Region(object):
     #   @retval string      Generated FV file path\r
     #\r
 \r
-    def AddToBuffer(self, Buffer, BaseAddress, BlockSizeList, ErasePolarity, ImageBinDict,  MacroDict={}, Flag=False):\r
+    def AddToBuffer(self, Buffer, BaseAddress, BlockSizeList, ErasePolarity, ImageBinDict,  MacroDict=None, Flag=False):\r
         Size = self.Size\r
+        if MacroDict is None:\r
+            MacroDict = {}\r
         if not Flag:\r
             GenFdsGlobalVariable.InfLogger('\nGenerate Region at Offset 0x%X' % self.Offset)\r
             GenFdsGlobalVariable.InfLogger("   Region Size = 0x%X" % Size)\r
index b2389566349855b8bedb9f22d5dbfa99c9ba968d..2acb70f4129c9f203ea200187b6ce88d2bf717af 100644 (file)
@@ -92,7 +92,7 @@ class Section (SectionClassObject):
     #   @param  FfsInf      FfsInfStatement object that contains this section data\r
     #   @param  Dict        dictionary contains macro and its value\r
     #\r
-    def GenSection(self, OutputPath, GuidName, SecNum, keyStringList, FfsInf = None, Dict = {}):\r
+    def GenSection(self, OutputPath, GuidName, SecNum, keyStringList, FfsInf = None, Dict = None):\r
         pass\r
 \r
     ## GetFileList() method\r
index c9fc5997a1f080bbe6c7b1feca9c56c96b75dad3..f643058bd637f11a8cc8538221127b5eadf59c13 100644 (file)
@@ -44,7 +44,7 @@ class UiSection (UiSectionClassObject):
     #   @param  Dict        dictionary contains macro and its value\r
     #   @retval tuple       (Generated file name, section alignment)\r
     #\r
-    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf=None, Dict={}, IsMakefile = False):\r
+    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf=None, Dict=None, IsMakefile = False):\r
         #\r
         # Prepare the parameter of GenSection\r
         #\r
@@ -58,6 +58,8 @@ class UiSection (UiSectionClassObject):
         if self.StringData is not None :\r
             NameString = self.StringData\r
         elif self.FileName is not None:\r
+            if Dict is None:\r
+                Dict = {}\r
             FileNameStr = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName)\r
             FileNameStr = GenFdsGlobalVariable.MacroExtend(FileNameStr, Dict)\r
             FileObj = open(FileNameStr, 'r')\r
index 1e7b3914127ef33456d50d6b09eeae51a0032031..7280e80cb4ef7ce47524af2de67a3c2e84cf5a33 100644 (file)
@@ -42,7 +42,7 @@ class VerSection (VerSectionClassObject):
     #   @param  Dict        dictionary contains macro and its value\r
     #   @retval tuple       (Generated file name, section alignment)\r
     #\r
-    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf=None, Dict={}, IsMakefile = False):\r
+    def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf=None, Dict=None, IsMakefile = False):\r
         #\r
         # Prepare the parameter of GenSection\r
         #\r
@@ -61,6 +61,8 @@ class VerSection (VerSectionClassObject):
         if self.StringData:\r
             StringData = self.StringData\r
         elif self.FileName:\r
+            if Dict is None:\r
+                Dict = {}\r
             FileNameStr = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName)\r
             FileNameStr = GenFdsGlobalVariable.MacroExtend(FileNameStr, Dict)\r
             FileObj = open(FileNameStr, 'r')\r