From c7951e13c054a0d9ec65267dd9c4ee66ac62579b Mon Sep 17 00:00:00 2001 From: "Jason Shirk (POWERSHELL)" Date: Mon, 26 Sep 2016 15:16:35 -0700 Subject: [PATCH 1/3] Remove most Maximum* capacity variables MaximumErrorCount is fixed at 256 (we may want to consider an environment variable to make this bigger) MaximumAliasCount, MaximumDriveCount, MaximumFunctionCount, and MaximumVariableCount have been removed. --- .../engine/ExecutionContext.cs | 33 +-- .../engine/Modules/PSModuleInfo.cs | 3 +- .../engine/SessionStateCapacityVariable.cs | 175 ------------ .../engine/SessionStateDriveAPIs.cs | 8 - .../engine/SessionStateScope.cs | 262 +----------------- .../resources/SessionStateStrings.resx | 15 - 6 files changed, 3 insertions(+), 493 deletions(-) delete mode 100644 src/System.Management.Automation/engine/SessionStateCapacityVariable.cs diff --git a/src/System.Management.Automation/engine/ExecutionContext.cs b/src/System.Management.Automation/engine/ExecutionContext.cs index 40384111e8..4eb97effcc 100644 --- a/src/System.Management.Automation/engine/ExecutionContext.cs +++ b/src/System.Management.Automation/engine/ExecutionContext.cs @@ -802,39 +802,8 @@ namespace System.Management.Automation return; } - // 1045384-2004/12/14-JonN implementing $MaximumErrorCount - object maxcountobj = EngineSessionState.CurrentScope.ErrorCapacity.FastValue; - if (null != maxcountobj) - { - try - { - maxcountobj = LanguagePrimitives.ConvertTo(maxcountobj, typeof(int), CultureInfo.InvariantCulture); - } - catch (PSInvalidCastException) - { - } - catch (System.OverflowException) - { - } - catch (Exception e) - { - Diagnostics.Assert(false, - "Unexpected exception in LanguagePrimitives.ConvertTo: " - + e.GetType().FullName); - throw; - } - } - int maxErrorCount = (maxcountobj is int) ? (int)maxcountobj : 256; - if (0 > maxErrorCount) - maxErrorCount = 0; - else if (32768 < maxErrorCount) - maxErrorCount = 32768; + const int maxErrorCount = 256; - if (0 >= maxErrorCount) - { - arraylist.Clear(); - return; - } int numToErase = arraylist.Count - (maxErrorCount - 1); if (0 < numToErase) { diff --git a/src/System.Management.Automation/engine/Modules/PSModuleInfo.cs b/src/System.Management.Automation/engine/Modules/PSModuleInfo.cs index 01c6376a1c..3a0e9f4af1 100644 --- a/src/System.Management.Automation/engine/Modules/PSModuleInfo.cs +++ b/src/System.Management.Automation/engine/Modules/PSModuleInfo.cs @@ -1058,8 +1058,7 @@ namespace System.Management.Automation } internal static string[] _builtinVariables = new string[] { "_", "this", "input", "args", "true", "false", "null", - "MaximumErrorCount", "MaximumVariableCount", "MaximumFunctionCount","MaximumAliasCount", "PSDefaultParameterValues", - "MaximumDriveCount", "Error", "PSScriptRoot", "PSCommandPath", "MyInvocation", "ExecutionContext", "StackTrace" }; + "PSDefaultParameterValues", "Error", "PSScriptRoot", "PSCommandPath", "MyInvocation", "ExecutionContext", "StackTrace" }; /// /// Lists the variables exported by this module. diff --git a/src/System.Management.Automation/engine/SessionStateCapacityVariable.cs b/src/System.Management.Automation/engine/SessionStateCapacityVariable.cs deleted file mode 100644 index 5efa7b9e5e..0000000000 --- a/src/System.Management.Automation/engine/SessionStateCapacityVariable.cs +++ /dev/null @@ -1,175 +0,0 @@ -/********************************************************************++ -Copyright (c) Microsoft Corporation. All rights reserved. ---********************************************************************/ - -using System.Diagnostics.CodeAnalysis; // for fxcop -using System.Globalization; -using Dbg = System.Management.Automation; - -namespace System.Management.Automation -{ - /// - /// A variable that represents the maximum capacity for object types in a scope. - /// An separate instance is created for functions, aliases, variables, and drives. - /// - internal class SessionStateCapacityVariable : PSVariable - { - #region ctor - - /// - /// Constructs an instance of the variable with the specified name and - /// initial capacity. - /// - /// - /// - /// The name of the variable. - /// - /// - /// - /// The initial capacity - /// - /// - /// - /// The maximum capacity for the scope. - /// - /// - /// - /// The minimum capacity for the scope. - /// - /// - /// Scoped item options for this variable - internal SessionStateCapacityVariable( - string name, - int defaultCapacity, - int maxCapacity, - int minCapacity, - ScopedItemOptions options) - : base(name, defaultCapacity, options) - { - // Now add a range constraint to the variable so that - // it is discoverable... - - ValidateRangeAttribute validateRange = - new ValidateRangeAttribute(minCapacity, maxCapacity); - _minCapacity = minCapacity; - _maxCapacity = maxCapacity; - base.Attributes.Add(validateRange); - _fastValue = defaultCapacity; - } - - /// - /// Constructs an instance of the variable with the specified name and - /// initial capacity. - /// - /// - /// - /// The name of the variable. - /// - /// - /// - /// A reference to a SessionStateCapacityVariable in another scope. The value - /// will be shared in this scope unless the capacity gets set in this scope. - /// - /// - /// The scoped item options for this variable - [SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors", Justification = "This is internal code and is verified to behave correctly.")] - public SessionStateCapacityVariable( - string name, - SessionStateCapacityVariable sharedCapacityVariable, - ScopedItemOptions options) - : base(name, sharedCapacityVariable.Value, options) - { - // Now add range constraints to the variable. - - ValidateRangeAttribute validateRange = - new ValidateRangeAttribute(0, int.MaxValue); - base.Attributes.Add(validateRange); - - _sharedCapacityVariable = sharedCapacityVariable; - - // Also propagate the description to prevent re-fetching them from the - // resource manager. That causes a measurable performance degradation. - this.Description = sharedCapacityVariable.Description; - - // Initialize the fast value... - _fastValue = (int)sharedCapacityVariable.Value; - } - #endregion ctor - - /// - /// Gets or sets the value of the variable. - /// This class will always return an int from the getter. The value is - /// either inherited from a parent scope, or stored locally - /// - /// - public override object Value - { - get - { - object result; - - if (_sharedCapacityVariable != null) - { - result = _sharedCapacityVariable.Value; - } - else - { - result = base.Value; - } - return result; - } - - set - { - _sharedCapacityVariable = null; - base.Value = LanguagePrimitives.ConvertTo(value, typeof(int), CultureInfo.InvariantCulture); - _fastValue = (int)base.Value; - } - } - - /// - /// Provides fast access to the capacity variable as an int, eliminating the need - /// for casts... - /// - internal int FastValue - { - get { return _fastValue; } - } - private int _fastValue; - - /// - /// Overrides the base IsValidValue to ensure the value is an int. - /// - /// - /// - /// The value to test. - /// - /// - /// - /// true if the value is an int and the base class IsValidValue is true, otherwise - /// false. - /// - /// - /// - /// If the validation metadata throws an exception. - /// - /// - public override bool IsValidValue(object value) - { - int capacity = (int)value; - // If the value is within the limits, then return true - // otherwise call the base validator so we'll get the error - // from the validation attribute... - if (capacity >= _minCapacity && capacity <= _maxCapacity) - return true; - else - return base.IsValidValue(value); - } - - private int _minCapacity; - private int _maxCapacity = int.MaxValue; - - private SessionStateCapacityVariable _sharedCapacityVariable; - } // class SessionStateCapacityVariable -} - diff --git a/src/System.Management.Automation/engine/SessionStateDriveAPIs.cs b/src/System.Management.Automation/engine/SessionStateDriveAPIs.cs index c49d339f56..7f654562f8 100644 --- a/src/System.Management.Automation/engine/SessionStateDriveAPIs.cs +++ b/src/System.Management.Automation/engine/SessionStateDriveAPIs.cs @@ -71,10 +71,6 @@ namespace System.Management.Automation /// If the provider threw an exception or returned null. /// /// - /// - /// If creating the drive will overflow the MaximumDriveCount limit. - /// - /// internal PSDriveInfo NewDrive(PSDriveInfo drive, string scopeID) { if (drive == null) @@ -160,10 +156,6 @@ namespace System.Management.Automation /// If the provider threw an exception or returned null. /// /// - /// - /// If creating the drive will overflow the MaximumDriveCount limit. - /// - /// internal void NewDrive(PSDriveInfo drive, string scopeID, CmdletProviderContext context) { if (drive == null) diff --git a/src/System.Management.Automation/engine/SessionStateScope.cs b/src/System.Management.Automation/engine/SessionStateScope.cs index 6429ed71a8..f00b7ca485 100644 --- a/src/System.Management.Automation/engine/SessionStateScope.cs +++ b/src/System.Management.Automation/engine/SessionStateScope.cs @@ -41,56 +41,6 @@ namespace System.Management.Automation } } // SessionStateScope constructor - private SessionStateCapacityVariable CreateCapacityVariable( - string variableName, - int defaultCapacity, - int maxCapacity, - int minCapacity, - string descriptionResourceString - ) - { - // First do the lookup to see if a variable already exists. - - SessionStateCapacityVariable capacityVariable = null; - - if (Parent != null) - { - capacityVariable = - Parent.GetVariable(variableName) as SessionStateCapacityVariable; - } - - if (capacityVariable == null) - { - // Since we weren't able to find an existing one, create a new one - capacityVariable = - new SessionStateCapacityVariable( - variableName, - defaultCapacity, - maxCapacity, - minCapacity, - ScopedItemOptions.None); - } - else - { - // Since we did find one, create a local capacity variable with a reference - // to it. - - capacityVariable = - new SessionStateCapacityVariable( - variableName, - capacityVariable, - ScopedItemOptions.None); - } - - // Only initialize the description if it is null or empty. Initializing it every time - // causes a measurable performance degradation. - if (String.IsNullOrEmpty(capacityVariable.Description)) - { - capacityVariable.Description = descriptionResourceString; - } - return capacityVariable; - } - #endregion constructor #region Internal properties @@ -200,20 +150,6 @@ namespace System.Management.Automation throw e; } - if (!newDrive.IsAutoMounted && - driveInfos.Count > DriveCapacity.FastValue - 1) - { - SessionStateOverflowException e = - new SessionStateOverflowException( - newDrive.Name, - SessionStateCategory.Drive, - "DriveOverflow", - SessionStateStrings.DriveOverflow, - DriveCapacity.FastValue); - - throw e; - } - if (!newDrive.IsAutoMounted) { driveInfos.Add(newDrive.Name, newDrive); @@ -592,22 +528,6 @@ namespace System.Management.Automation variable = (LocalsTuple != null ? LocalsTuple.TrySetVariable(name, value) : null) ?? new PSVariable(name, value); } - // Now check to make sure we don't exceed the max variable count - // if this is a new variable. - - if (!varExists && _variables.Count > VariableCapacity.FastValue - 1) - { - SessionStateOverflowException e = - new SessionStateOverflowException( - name, - SessionStateCategory.Variable, - "VariableOverflow", - SessionStateStrings.VariableOverflow, - VariableCapacity.FastValue); - - throw e; - } - // Don't let people set AllScope variables in ConstrainedLanguage, // as they can be used to interfere with the session state of // trusted commands. @@ -727,22 +647,6 @@ namespace System.Management.Automation variable = newVariable; } - // Now check to make sure we don't exceed the max variable count - // if this is a new variable. - - if (!varExists && _variables.Count > VariableCapacity.FastValue - 1) - { - SessionStateOverflowException e = - new SessionStateOverflowException( - newVariable.Name, - SessionStateCategory.Variable, - "VariableOverflow", - SessionStateStrings.VariableOverflow, - VariableCapacity.FastValue); - - throw e; - } - // Don't let people set AllScope variables in ConstrainedLanguage, // as they can be used to interfere with the session state of // trusted commands. @@ -799,18 +703,6 @@ namespace System.Management.Automation throw e; } - if (variable is SessionStateCapacityVariable) - { - SessionStateUnauthorizedAccessException e = - new SessionStateUnauthorizedAccessException( - name, - SessionStateCategory.Variable, - "VariableNotRemovableSystem", - SessionStateStrings.VariableNotRemovableSystem); - - throw e; - } - if (variable is LocalVariable) { SessionStateUnauthorizedAccessException e = @@ -949,18 +841,6 @@ namespace System.Management.Automation AliasInfo aliasInfo; if (!aliasInfos.TryGetValue(name, out aliasInfo)) { - if (aliasInfos.Count > AliasCapacity.FastValue - 1) - { - SessionStateOverflowException e = - new SessionStateOverflowException( - name, - SessionStateCategory.Alias, - "AliasOverflow", - SessionStateStrings.AliasOverflow, - AliasCapacity.FastValue); - - throw e; - } aliasInfos[name] = new AliasInfo(name, value, context); } else @@ -1056,18 +936,6 @@ namespace System.Management.Automation AliasInfo result; if (!aliasInfos.TryGetValue(name, out aliasInfo)) { - if (aliasInfos.Count > AliasCapacity.FastValue - 1) - { - SessionStateOverflowException e = - new SessionStateOverflowException( - name, - SessionStateCategory.Alias, - "AliasOverflow", - SessionStateStrings.AliasOverflow, - AliasCapacity.FastValue); - - throw e; - } result = new AliasInfo(name, value, context, options); aliasInfos[name] = result; } @@ -1180,22 +1048,7 @@ namespace System.Management.Automation var aliasInfos = GetAliases(); AliasInfo aliasInfo; - if (!aliasInfos.TryGetValue(aliasToSet.Name, out aliasInfo)) - { - if (aliasInfos.Count > AliasCapacity.FastValue - 1) - { - SessionStateOverflowException e = - new SessionStateOverflowException( - aliasToSet.Name, - SessionStateCategory.Alias, - "AliasOverflow", - SessionStateStrings.AliasOverflow, - AliasCapacity.FastValue); - - throw e; - } - } - else + if (aliasInfos.TryGetValue(aliasToSet.Name, out aliasInfo)) { // An existing alias cannot be set if it is ReadOnly or Constant unless // force is specified, in which case an existing ReadOnly alias can @@ -1569,19 +1422,6 @@ namespace System.Management.Automation FunctionInfo result; if (!functionInfos.TryGetValue(name, out existingValue)) { - if (functionInfos.Count > FunctionCapacity.FastValue - 1) - { - SessionStateOverflowException e = - new SessionStateOverflowException( - name, - SessionStateCategory.Function, - "FunctionOverflow", - SessionStateStrings.FunctionOverflow, - FunctionCapacity.FastValue); - - throw e; - } - result = functionFactory(name, function, originalFunction, options, context, helpFile); functionInfos[name] = result; @@ -2123,55 +1963,6 @@ namespace System.Management.Automation _variables.Add(variable.Name, variable); } } - - - // Now create the capacity variables with a reference to a parent scope - // capacity variable if one exists. If not, the defaults will be used. - - string varName = "MaximumErrorCount"; - _errorCapacity = CreateCapacityVariable( - varName, - SessionStateConstants.DefaultErrorCapacity, - SessionStateConstants.MaxErrorCapacity, - SessionStateConstants.MinErrorCapacity, - SessionStateStrings.MaxErrorCountDescription); - _variables.Add(varName, _errorCapacity); - - varName = "MaximumVariableCount"; - _variableCapacity = CreateCapacityVariable( - varName, - SessionStateConstants.DefaultVariableCapacity, - SessionStateConstants.MaxVariablesCapacity, - SessionStateConstants.MinVariablesCapacity, - SessionStateStrings.MaxVariableCountDescription); - _variables.Add(varName, _variableCapacity); - - varName = "MaximumFunctionCount"; - _functionCapacity = CreateCapacityVariable( - varName, - SessionStateConstants.DefaultFunctionCapacity, - SessionStateConstants.MaxFunctionCapacity, - SessionStateConstants.MinFunctionCapacity, - SessionStateStrings.MaxFunctionCountDescription); - _variables.Add(varName, _functionCapacity); - - varName = "MaximumAliasCount"; - _aliasCapacity = CreateCapacityVariable( - varName, - SessionStateConstants.DefaultAliasCapacity, - SessionStateConstants.MaxAliasCapacity, - SessionStateConstants.MinAliasCapacity, - SessionStateStrings.MaxAliasCountDescription); - _variables.Add(varName, _aliasCapacity); - - varName = "MaximumDriveCount"; - _driveCapacity = CreateCapacityVariable( - varName, - SessionStateConstants.DefaultDriveCapacity, - SessionStateConstants.MaxDriveCapacity, - SessionStateConstants.MinDriveCapacity, - SessionStateStrings.MaxDriveCountDescription); - _variables.Add(varName, _driveCapacity); } /// @@ -2274,57 +2065,6 @@ namespace System.Management.Automation private readonly Dictionary> _allScopeCmdlets = new Dictionary>(StringComparer.OrdinalIgnoreCase); - - internal SessionStateCapacityVariable ErrorCapacity - { - get - { - GetPrivateVariables(); // Make sure that the variable table is initialized... - return _errorCapacity; - } - } - private SessionStateCapacityVariable _errorCapacity; - - internal SessionStateCapacityVariable VariableCapacity - { - get - { - GetPrivateVariables(); // Make sure that the variable table is initialized... - return _variableCapacity; - } - } - private SessionStateCapacityVariable _variableCapacity; - - private SessionStateCapacityVariable FunctionCapacity - { - get - { - GetPrivateVariables(); // Make sure that the variable table is initialized... - return _functionCapacity; - } - } - private SessionStateCapacityVariable _functionCapacity; - - private SessionStateCapacityVariable AliasCapacity - { - get - { - GetPrivateVariables(); // Make sure that the variable table is initialized... - return _aliasCapacity; - } - } - private SessionStateCapacityVariable _aliasCapacity; - - private SessionStateCapacityVariable DriveCapacity - { - get - { - GetPrivateVariables(); // Make sure that the variable table is initialized... - return _driveCapacity; - } - } - private SessionStateCapacityVariable _driveCapacity; - /// /// The variable that represents $true in the language. /// We don't need a new reference in each scope since it diff --git a/src/System.Management.Automation/resources/SessionStateStrings.resx b/src/System.Management.Automation/resources/SessionStateStrings.resx index 342358e46b..1197e300d0 100644 --- a/src/System.Management.Automation/resources/SessionStateStrings.resx +++ b/src/System.Management.Automation/resources/SessionStateStrings.resx @@ -369,21 +369,6 @@ Cannot remove variable {0} because it is constant or read-only. If the variable is read-only, try the operation again specifying the Force option. - - Cannot remove variable {0} because it is owned by the system. - - - Alias {0} cannot be created because alias capacity {1} has been exceeded for this scope. - - - Drive {0} cannot be created because drive capacity {1} has been exceeded for this scope. - - - Function {0} cannot be created because function capacity {1} has been exceeded for this scope. - - - Cannot create variable {0} because variable capacity {1} is exceeded for this scope. - Alias {0} cannot be modified because it is constant. From f252683e909515b39c6d2fb03c1f2c5f93802814 Mon Sep 17 00:00:00 2001 From: "Jason Shirk (POWERSHELL)" Date: Wed, 28 Sep 2016 15:47:08 -0700 Subject: [PATCH 2/3] Remove SessionStateOverflowException This exception is no longer used by PowerShell, so it has been removed. It is a public api, so removing it risks breaking somebody. Nobody has any reason to catch or throw this exception, so it seems safe to remove, but I decided to be conservative and keep it for Windows PowerShell. It seems safe enough to remove in Nano. --- .../commands/management/Navigation.cs | 5 --- .../engine/DriveInterfaces.cs | 9 ----- .../engine/InitialSessionState.cs | 1 - .../engine/InternalCommands.cs | 12 ------ .../engine/MshMemberInfo.cs | 16 -------- .../engine/SessionStateAliasAPIs.cs | 28 ------------- .../engine/SessionStateFunctionAPIs.cs | 28 ------------- .../engine/SessionStateProviderAPIs.cs | 5 --- .../engine/SessionStateScope.cs | 40 ------------------- .../engine/SessionStateVariableAPIs.cs | 32 --------------- .../engine/VariableInterfaces.cs | 7 ---- .../engine/lang/parserutils.cs | 1 - .../engine/lang/scriptblock.cs | 4 -- .../singleshell/Commands/ConsoleCommands.cs | 4 -- .../utils/SessionStateExceptions.cs | 3 ++ 15 files changed, 3 insertions(+), 192 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs index 4f93c63d8d..97a7481ebb 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs @@ -1732,11 +1732,6 @@ namespace Microsoft.PowerShell.Commands pathNotFound)); return; } - catch (SessionStateOverflowException) - { - // This is terminating condition - throw; - } catch (SessionStateException sessionStateException) { WriteError( diff --git a/src/System.Management.Automation/engine/DriveInterfaces.cs b/src/System.Management.Automation/engine/DriveInterfaces.cs index 7226a9657b..d3c8c43561 100644 --- a/src/System.Management.Automation/engine/DriveInterfaces.cs +++ b/src/System.Management.Automation/engine/DriveInterfaces.cs @@ -114,10 +114,6 @@ namespace System.Management.Automation /// /// If the provider threw an exception or returned null. /// - /// - /// - /// If creating the drive will overflow the MaximumDriveCount limit. - /// public PSDriveInfo New(PSDriveInfo drive, string scope) { Dbg.Diagnostics.Assert( @@ -173,11 +169,6 @@ namespace System.Management.Automation /// /// If the provider threw an exception or returned null. /// - /// - /// - /// If creating the drive will overflow the MaximumDriveCount limit. - /// - /// internal void New( PSDriveInfo drive, string scope, diff --git a/src/System.Management.Automation/engine/InitialSessionState.cs b/src/System.Management.Automation/engine/InitialSessionState.cs index f8c6ae7824..6d15f97a11 100644 --- a/src/System.Management.Automation/engine/InitialSessionState.cs +++ b/src/System.Management.Automation/engine/InitialSessionState.cs @@ -3138,7 +3138,6 @@ namespace System.Management.Automation.Runspaces catch (NotSupportedException e) { ex = e; } catch (ProviderNotFoundException e) { ex = e; } catch (ProviderInvocationException e) { ex = e; } - catch (SessionStateOverflowException e) { ex = e; } catch (KeyNotFoundException e) { ex = e; } catch (IOException e) { ex = e; } catch (UnauthorizedAccessException e) { ex = e; } diff --git a/src/System.Management.Automation/engine/InternalCommands.cs b/src/System.Management.Automation/engine/InternalCommands.cs index 65daebd1c8..9bbf60ea3f 100644 --- a/src/System.Management.Automation/engine/InternalCommands.cs +++ b/src/System.Management.Automation/engine/InternalCommands.cs @@ -158,9 +158,6 @@ namespace Microsoft.PowerShell.Commands /// /// Execute the begin scriptblock at the start of processing /// - /// - /// The maximum scope depth would be exceeded - /// /// could not parse script /// see Pipeline.Invoke /// see Pipeline.Invoke @@ -242,9 +239,6 @@ namespace Microsoft.PowerShell.Commands /// Execute the processing script blocks on the current pipeline object /// which is passed as it's only parameter. /// - /// - /// The maximum scope depth would be exceeded - /// /// could not parse script /// see Pipeline.Invoke /// see Pipeline.Invoke @@ -733,9 +727,6 @@ namespace Microsoft.PowerShell.Commands /// /// Execute the end scriptblock when the pipeline is complete /// - /// - /// The maximum scope depth would be exceeded - /// /// could not parse script /// see Pipeline.Invoke /// see Pipeline.Invoke @@ -1456,9 +1447,6 @@ namespace Microsoft.PowerShell.Commands /// Execute the script block passing in the current pipeline object as /// it's only parameter. /// - /// - /// The maximum scope depth would be exceeded - /// /// could not parse script /// see Pipeline.Invoke /// see Pipeline.Invoke diff --git a/src/System.Management.Automation/engine/MshMemberInfo.cs b/src/System.Management.Automation/engine/MshMemberInfo.cs index cb54fc1b96..a8a85c9e07 100644 --- a/src/System.Management.Automation/engine/MshMemberInfo.cs +++ b/src/System.Management.Automation/engine/MshMemberInfo.cs @@ -1846,10 +1846,6 @@ namespace System.Management.Automation args: new object[] { value }); return value; } - catch (SessionStateOverflowException e) - { - throw NewSetValueException(e, "ScriptSetValueSessionStateOverflowException"); - } catch (RuntimeException e) { throw NewSetValueException(e, "ScriptSetValueRuntimeException"); @@ -1881,10 +1877,6 @@ namespace System.Management.Automation scriptThis: scriptThis, args: Utils.EmptyArray()); } - catch (SessionStateOverflowException e) - { - throw NewGetValueException(e, "ScriptGetValueSessionStateOverflowException"); - } catch (RuntimeException e) { throw NewGetValueException(e, "ScriptGetValueRuntimeException"); @@ -2424,14 +2416,6 @@ namespace System.Management.Automation scriptThis: @this, args: arguments); } - catch (SessionStateOverflowException e) - { - throw new MethodInvocationException( - "ScriptMethodSessionStateOverflowException", - e, - ExtendedTypeSystem.MethodInvocationException, - methodName, arguments.Length, e.Message); - } catch (RuntimeException e) { throw new MethodInvocationException( diff --git a/src/System.Management.Automation/engine/SessionStateAliasAPIs.cs b/src/System.Management.Automation/engine/SessionStateAliasAPIs.cs index 9c9212a399..24206f6cec 100644 --- a/src/System.Management.Automation/engine/SessionStateAliasAPIs.cs +++ b/src/System.Management.Automation/engine/SessionStateAliasAPIs.cs @@ -277,10 +277,6 @@ namespace System.Management.Automation /// If the alias is read-only or constant. /// /// - /// - /// If the maximum number of aliases has been reached for this scope. - /// - /// internal AliasInfo SetAliasValue(string aliasName, string value, bool force, CommandOrigin origin) { if (String.IsNullOrEmpty(aliasName)) @@ -328,10 +324,6 @@ namespace System.Management.Automation /// If the alias is read-only or constant. /// /// - /// - /// If the maximum number of aliases has been reached for this scope. - /// - /// internal AliasInfo SetAliasValue(string aliasName, string value, bool force) { return SetAliasValue(aliasName, value, force, CommandOrigin.Internal); @@ -373,10 +365,6 @@ namespace System.Management.Automation /// If the alias is read-only or constant. /// /// - /// - /// If the maximum number of aliases has been reached for this scope. - /// - /// internal AliasInfo SetAliasValue( string aliasName, string value, @@ -432,10 +420,6 @@ namespace System.Management.Automation /// If the alias is read-only or constant. /// /// - /// - /// If the maximum number of aliases has been reached for this scope. - /// - /// internal AliasInfo SetAliasValue( string aliasName, string value, @@ -474,10 +458,6 @@ namespace System.Management.Automation /// If the alias is read-only or constant. /// /// - /// - /// If the maximum number of aliases has been reached for this scope. - /// - /// internal AliasInfo SetAliasItem(AliasInfo alias, bool force, CommandOrigin origin) { if (alias == null) @@ -535,10 +515,6 @@ namespace System.Management.Automation /// If the alias is read-only or constant. /// /// - /// - /// If the maximum number of aliases has been reached for this scope. - /// - /// internal AliasInfo SetAliasItemAtScope(AliasInfo alias, string scopeID, bool force, CommandOrigin origin) { if (alias == null) @@ -602,10 +578,6 @@ namespace System.Management.Automation /// If the alias is read-only or constant. /// /// - /// - /// If the maximum number of aliases has been reached for this scope. - /// - /// internal AliasInfo SetAliasItemAtScope(AliasInfo alias, string scopeID, bool force) { return SetAliasItemAtScope(alias, scopeID, force, CommandOrigin.Internal); diff --git a/src/System.Management.Automation/engine/SessionStateFunctionAPIs.cs b/src/System.Management.Automation/engine/SessionStateFunctionAPIs.cs index 8fcf3debce..d6d6304f40 100644 --- a/src/System.Management.Automation/engine/SessionStateFunctionAPIs.cs +++ b/src/System.Management.Automation/engine/SessionStateFunctionAPIs.cs @@ -245,10 +245,6 @@ namespace System.Management.Automation /// If the function is read-only or constant. /// /// - /// - /// If the maximum number of functions have been reached for this scope. - /// - /// internal FunctionInfo SetFunctionRaw( string name, ScriptBlock function, @@ -397,10 +393,6 @@ namespace System.Management.Automation /// If the function is read-only or constant. /// /// - /// - /// If the maximum number of functions have been reached for this scope. - /// - /// internal FunctionInfo SetFunction( string name, ScriptBlock function, @@ -456,10 +448,6 @@ namespace System.Management.Automation /// If the function is read-only or constant. /// /// - /// - /// If the maximum number of functions have been reached for this scope. - /// - /// internal FunctionInfo SetFunction( string name, ScriptBlock function, @@ -519,10 +507,6 @@ namespace System.Management.Automation /// If the function is read-only or constant. /// /// - /// - /// If the maximum number of functions have been reached for this scope. - /// - /// internal FunctionInfo SetFunction( string name, ScriptBlock function, @@ -588,10 +572,6 @@ namespace System.Management.Automation /// If the function is read-only or constant. /// /// - /// - /// If the maximum number of functions have been reached for this scope. - /// - /// internal FunctionInfo SetFunction( string name, ScriptBlock function, @@ -685,10 +665,6 @@ namespace System.Management.Automation /// If the function is read-only or constant. /// /// - /// - /// If the maximum number of functions have been reached for this scope. - /// - /// internal FunctionInfo SetFunction( string name, ScriptBlock function, @@ -806,10 +782,6 @@ namespace System.Management.Automation /// If the function is read-only or constant. /// /// - /// - /// If the maximum number of functions have been reached for this scope. - /// - /// internal FunctionInfo SetFunction(string name, ScriptBlock function, bool force) { return SetFunction(name, function, null, force, CommandOrigin.Internal); diff --git a/src/System.Management.Automation/engine/SessionStateProviderAPIs.cs b/src/System.Management.Automation/engine/SessionStateProviderAPIs.cs index baf262a58e..3ef80291a7 100644 --- a/src/System.Management.Automation/engine/SessionStateProviderAPIs.cs +++ b/src/System.Management.Automation/engine/SessionStateProviderAPIs.cs @@ -1135,11 +1135,6 @@ namespace System.Management.Automation /// provider tries to add. /// /// - /// - /// If the provider tries to add default drives which exceed the maximum - /// limit for the number of drives in the current scope. - /// - /// internal void InitializeProvider( Provider.CmdletProvider providerInstance, ProviderInfo provider, diff --git a/src/System.Management.Automation/engine/SessionStateScope.cs b/src/System.Management.Automation/engine/SessionStateScope.cs index f00b7ca485..8e1aff4fc8 100644 --- a/src/System.Management.Automation/engine/SessionStateScope.cs +++ b/src/System.Management.Automation/engine/SessionStateScope.cs @@ -122,10 +122,6 @@ namespace System.Management.Automation /// If a drive of the same name already exists in this scope. /// /// - /// - /// If the maximum drive count has been reached for this scope. - /// - /// internal void NewDrive(PSDriveInfo newDrive) { if (newDrive == null) @@ -427,10 +423,6 @@ namespace System.Management.Automation /// If the variable is read-only or constant. /// /// - /// - /// If the maximum number of variables has been reached for this scope. - /// - /// internal PSVariable SetVariable(string name, object value, bool asValue, bool force, SessionStateInternal sessionState, CommandOrigin origin = CommandOrigin.Internal, bool fastPath = false) { Diagnostics.Assert(name != null, "The caller should verify the name"); @@ -591,10 +583,6 @@ namespace System.Management.Automation /// If the variable is read-only or constant. /// /// - /// - /// If the maximum number of variables has been reached for this scope. - /// - /// internal PSVariable NewVariable(PSVariable newVariable, bool force, SessionStateInternal sessionState) { PSVariable variable; @@ -827,10 +815,6 @@ namespace System.Management.Automation /// if the alias is read-only or constant. /// /// - /// - /// If the maximum number of aliases has been reached for this scope. - /// - /// internal AliasInfo SetAliasValue(string name, string value, ExecutionContext context, bool force, CommandOrigin origin) { Diagnostics.Assert( @@ -915,10 +899,6 @@ namespace System.Management.Automation /// If the alias is read-only or constant. /// /// - /// - /// If the maximum number of aliases has been reached for this scope. - /// - /// internal AliasInfo SetAliasValue( string name, string value, @@ -1035,10 +1015,6 @@ namespace System.Management.Automation /// If the alias is read-only or constant. /// /// - /// - /// If the maximum number of aliases has been reached for this scope. - /// - /// internal AliasInfo SetAliasItem(AliasInfo aliasToSet, bool force, CommandOrigin origin = CommandOrigin.Internal) { Diagnostics.Assert( @@ -1214,10 +1190,6 @@ namespace System.Management.Automation /// If the function is read-only or constant. /// /// - /// - /// If the maximum number of functions have been reached for this scope. - /// - /// internal FunctionInfo SetFunction( string name, ScriptBlock function, @@ -1264,10 +1236,6 @@ namespace System.Management.Automation /// If the function is read-only or constant. /// /// - /// - /// If the maximum number of functions have been reached for this scope. - /// - /// internal FunctionInfo SetFunction( string name, ScriptBlock function, @@ -1320,10 +1288,6 @@ namespace System.Management.Automation /// If the function is read-only or constant. /// /// - /// - /// If the maximum number of functions have been reached for this scope. - /// - /// internal FunctionInfo SetFunction( string name, ScriptBlock function, @@ -1398,10 +1362,6 @@ namespace System.Management.Automation /// If the function is read-only or constant. /// /// - /// - /// If the maximum number of functions have been reached for this scope. - /// - /// internal FunctionInfo SetFunction( string name, ScriptBlock function, diff --git a/src/System.Management.Automation/engine/SessionStateVariableAPIs.cs b/src/System.Management.Automation/engine/SessionStateVariableAPIs.cs index 7bbb167912..3c07eb4a2c 100644 --- a/src/System.Management.Automation/engine/SessionStateVariableAPIs.cs +++ b/src/System.Management.Automation/engine/SessionStateVariableAPIs.cs @@ -1030,10 +1030,6 @@ namespace System.Management.Automation /// If the variable is read-only or constant. /// /// - /// - /// If the maximum number of variables has been reached for this scope. - /// - /// /// /// If the refers to a provider that could not be found. /// @@ -1089,10 +1085,6 @@ namespace System.Management.Automation /// If the variable is read-only or constant. /// /// - /// - /// If the maximum number of variables has been reached for this scope. - /// - /// /// /// If the refers to a provider that could not be found. /// @@ -1145,10 +1137,6 @@ namespace System.Management.Automation /// If the variable is read-only or constant. /// /// - /// - /// If the maximum number of variables has been reached for this scope. - /// - /// internal object SetVariable(PSVariable variable, bool force, CommandOrigin origin) { if (variable == null || String.IsNullOrEmpty(variable.Name)) @@ -1195,10 +1183,6 @@ namespace System.Management.Automation /// If the variable is read-only or constant. /// /// - /// - /// If the maximum number of variables has been reached for this scope. - /// - /// /// /// If the refers to a provider that could not be found. /// @@ -1263,10 +1247,6 @@ namespace System.Management.Automation /// If the variable is read-only or constant. /// /// - /// - /// If the maximum number of variables has been reached for this scope. - /// - /// /// /// If the refers to a provider that could not be found. /// @@ -1567,10 +1547,6 @@ namespace System.Management.Automation /// If the variable is read-only or constant. /// /// - /// - /// If the maximum number of variables has been reached for this scope. - /// - /// internal object SetVariableAtScope(PSVariable variable, string scopeID, bool force, CommandOrigin origin) { if (variable == null || String.IsNullOrEmpty(variable.Name)) @@ -1612,10 +1588,6 @@ namespace System.Management.Automation /// If the variable is read-only or constant. /// /// - /// - /// If the maximum number of variables has been reached for this scope. - /// - /// internal object NewVariable(PSVariable variable, bool force) { if (variable == null || String.IsNullOrEmpty(variable.Name)) @@ -1668,10 +1640,6 @@ namespace System.Management.Automation /// If the variable is read-only or constant. /// /// - /// - /// If the maximum number of variables has been reached for this scope. - /// - /// internal object NewVariableAtScope(PSVariable variable, string scopeID, bool force) { if (variable == null || String.IsNullOrEmpty(variable.Name)) diff --git a/src/System.Management.Automation/engine/VariableInterfaces.cs b/src/System.Management.Automation/engine/VariableInterfaces.cs index 84438d1125..ef83fa217f 100644 --- a/src/System.Management.Automation/engine/VariableInterfaces.cs +++ b/src/System.Management.Automation/engine/VariableInterfaces.cs @@ -305,10 +305,6 @@ namespace System.Management.Automation /// If the variable is read-only or constant. /// /// - /// - /// If the maximum number of variables has been reached for this scope. - /// - /// /// /// If the refers to a provider that could not be found. /// @@ -353,9 +349,6 @@ namespace System.Management.Automation /// If the variable is read-only or constant. /// /// - /// - /// If the maximum number of variables has been reached for this scope. - /// public void Set(PSVariable variable) { Dbg.Diagnostics.Assert( diff --git a/src/System.Management.Automation/engine/lang/parserutils.cs b/src/System.Management.Automation/engine/lang/parserutils.cs index ec8f6eddac..e562184340 100644 --- a/src/System.Management.Automation/engine/lang/parserutils.cs +++ b/src/System.Management.Automation/engine/lang/parserutils.cs @@ -1340,7 +1340,6 @@ namespace System.Management.Automation /// Set to true if you want to call a static method. /// If not automation null, then this must be a settable property /// Wraps the exception returned from the method call - /// The maximum scope depth would be exceeded /// Internal exception from a flow control statement /// internal static object CallMethod( diff --git a/src/System.Management.Automation/engine/lang/scriptblock.cs b/src/System.Management.Automation/engine/lang/scriptblock.cs index 1d7695d852..c919c9c35c 100644 --- a/src/System.Management.Automation/engine/lang/scriptblock.cs +++ b/src/System.Management.Automation/engine/lang/scriptblock.cs @@ -377,7 +377,6 @@ namespace System.Management.Automation /// The arguments to this script. /// The object(s) generated during the execution of /// the script block returned as a collection of PSObjects - /// Thrown if the maximum scope depth has been exceeded /// Thrown if a script runtime exceptionexception occurred /// An internal (non-public) exception from a flow control statement public Collection Invoke(params object[] args) @@ -499,7 +498,6 @@ namespace System.Management.Automation /// The arguments to pass to this scriptblock. /// The object(s) generated during the execution of the /// script block. They may or may not be wrapped in PSObject. It's up to the caller to check. - /// Thrown if the maximum scope depth has been exceeded /// Thrown if a script runtime exceptionexception occurred /// An internal (non-public) exception from a flow control statement public object InvokeReturnAsIs(params object[] args) @@ -833,7 +831,6 @@ namespace System.Management.Automation /// The arguments to this script. /// The object(s) generated during the execution of /// the script block returned as a collection of PSObjects - /// The maximum scope depth would be exceeded /// A script exception occurred /// Internal exception from a flow control statement internal Collection DoInvoke(object dollarUnder, object input, object[] args) @@ -893,7 +890,6 @@ namespace System.Management.Automation /// /// The object(s) generated during the execution of /// the script block returned as a collection of PSObjects - /// The maximum scope depth would be exceeded /// A script exception occurred /// Internal exception from a flow control statement internal object DoInvokeReturnAsIs(bool useLocalScope, diff --git a/src/System.Management.Automation/singleshell/Commands/ConsoleCommands.cs b/src/System.Management.Automation/singleshell/Commands/ConsoleCommands.cs index 764782f7b5..34e9a0bd73 100644 --- a/src/System.Management.Automation/singleshell/Commands/ConsoleCommands.cs +++ b/src/System.Management.Automation/singleshell/Commands/ConsoleCommands.cs @@ -275,10 +275,6 @@ namespace Microsoft.PowerShell.Commands { e = sue; } - catch (SessionStateOverflowException sof) - { - e = sof; - } catch (ProviderNotFoundException pnf) { e = pnf; diff --git a/src/System.Management.Automation/utils/SessionStateExceptions.cs b/src/System.Management.Automation/utils/SessionStateExceptions.cs index 1f3d66cd21..d116681942 100644 --- a/src/System.Management.Automation/utils/SessionStateExceptions.cs +++ b/src/System.Management.Automation/utils/SessionStateExceptions.cs @@ -582,6 +582,8 @@ namespace System.Management.Automation #endregion Private } // SessionStateException + // This class is no longer used, but kept in Windows PowerShell for backwards compatibility +#if !CORECLR /// /// SessionStateOverflowException occurs when the number of /// session state objects of this type in this scope @@ -678,6 +680,7 @@ namespace System.Management.Automation } #endregion Serialization } // SessionStateOverflowException +#endif // !CORECLR /// /// SessionStateUnauthorizedAccessException occurs when From 39db1ec4020dc3fd202af301e52d68b8772086f6 Mon Sep 17 00:00:00 2001 From: "Jason Shirk (POWERSHELL)" Date: Wed, 28 Sep 2016 16:54:31 -0700 Subject: [PATCH 3/3] Add capacity test for initialsessionstate --- .../engine/InitialSessionState.Tests.ps1 | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 test/powershell/engine/InitialSessionState.Tests.ps1 diff --git a/test/powershell/engine/InitialSessionState.Tests.ps1 b/test/powershell/engine/InitialSessionState.Tests.ps1 new file mode 100644 index 0000000000..85b1bec4fd --- /dev/null +++ b/test/powershell/engine/InitialSessionState.Tests.ps1 @@ -0,0 +1,57 @@ +Describe "InitialSessionState capacity" -Tags CI { + BeforeAll { + $iss = [initialsessionstate]::CreateDefault() + + for ($i = 0; $i -lt 5000; $i++) + { + $ssfe = [System.Management.Automation.Runspaces.SessionStateFunctionEntry]::new("f$i", "'fn f$i'") + $iss.Commands.Add($ssfe) + + $ssve = [System.Management.Automation.Runspaces.SessionStateVariableEntry]::new("v$i", "var v$i", $null) + $iss.Variables.Add($ssve) + + $ssae = [System.Management.Automation.Runspaces.SessionStateAliasEntry]::new("a$i", "f$i") + $iss.Commands.Add($ssae) + } + + $ps = [PowerShell]::Create($iss) + } + + AfterAll { + $ps.Dispose() + } + + BeforeEach { + $ps.Commands.Clear() + } + + It "function capacity in initial session state should not be limited" { + $ps.AddCommand('f4999').Invoke() | Should Be "fn f4999" + $ps.Streams.Error | Should Be $null + } + + It "alias capacity in initial session state should not be limited" { + $ps.AddCommand('a4999').Invoke() | Should Be "fn f4999" + $ps.Streams.Error | Should Be $null + } + + It "variable capacity in initial session state should not be limited" { + $ps.AddScript('$v4999').Invoke() | Should Be "var v4999" + $ps.Streams.Error | Should Be $null + } + + It "function capacity should not be limited after runspace is opened" { + $ps.AddScript('function f5000 { "in f5000" } f5000').Invoke() | Should Be "in f5000" + $ps.Streams.Error | Should Be $null + } + + It "variable capacity should not be limited after runspace is opened" { + $ps.AddScript('$v5000 = "var v5000"; $v5000').Invoke() | Should Be "var v5000" + $ps.Streams.Error | Should Be $null + } + + It "alias capacity should not be limited after runspace is opened" { + $ps.AddScript('New-Alias -Name a5000 -Value f1; a5000').Invoke() | Should Be "fn f1" + $ps.Streams.Error | Should Be $null + } +} \ No newline at end of file