Skip to content

Commit

Permalink
Remove [Out] by-value string parameter usage from System.Management. (d…
Browse files Browse the repository at this point in the history
…otnet/corefx#34091)

* Remove [Out] by-value string parameter usage from System.Management.

* Use char[] instead of StringBuilder.

* Add SizeParamIndex

* PR Feedback.

* Remove -1s

* Remove double semicolon

* Fix copy-paste error


Commit migrated from dotnet/corefx@2746a21
  • Loading branch information
jkoritzinsky committed Dec 19, 2018
1 parent 4533d7b commit 158c3fd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Threading;
using System.Security.Permissions;
using System.Runtime.Versioning;
using System.Text;

namespace WbemClient_v1 {}
namespace WbemUtilities_v1 {}
Expand Down Expand Up @@ -948,13 +949,13 @@ interface IWbemPathKeyList
[PreserveSig] int GetCount_([Out] out uint puKeyCount);
[PreserveSig] int SetKey_([In][MarshalAs(UnmanagedType.LPWStr)] string wszName, [In] uint uFlags, [In] uint uCimType, [In] IntPtr pKeyVal);
[PreserveSig] int SetKey2_([In][MarshalAs(UnmanagedType.LPWStr)] string wszName, [In] uint uFlags, [In] uint uCimType, [In] ref object pKeyVal);
[PreserveSig] int GetKey_([In] uint uKeyIx, [In] uint uFlags, [In][Out] ref uint puNameBufSize, [In][Out][MarshalAs(UnmanagedType.LPWStr)] string pszKeyName, [In][Out] ref uint puKeyValBufSize, [In][Out] IntPtr pKeyVal, [Out] out uint puApparentCimType);
[PreserveSig] int GetKey2_([In] uint uKeyIx, [In] uint uFlags, [In][Out] ref uint puNameBufSize, [In][Out][MarshalAs(UnmanagedType.LPWStr)] string pszKeyName, [In][Out] ref object pKeyValue, [Out] out uint puApparentCimType);
[PreserveSig] int GetKey_([In] uint uKeyIx, [In] uint uFlags, [In][Out] ref uint puNameBufSize, [Out][MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2, SizeParamIndex = 2)] char[] pszKeyName, [In][Out] ref uint puKeyValBufSize, [In][Out] IntPtr pKeyVal, [Out] out uint puApparentCimType);
[PreserveSig] int GetKey2_([In] uint uKeyIx, [In] uint uFlags, [In][Out] ref uint puNameBufSize, [Out][MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2, SizeParamIndex = 2)] char[] pszKeyName, [In][Out] ref object pKeyValue, [Out] out uint puApparentCimType);
[PreserveSig] int RemoveKey_([In][MarshalAs(UnmanagedType.LPWStr)] string wszName, [In] uint uFlags);
[PreserveSig] int RemoveAllKeys_([In] uint uFlags);
[PreserveSig] int MakeSingleton_([In] sbyte bSet);
[PreserveSig] int GetInfo_([In] uint uRequestedInfo, [Out] out ulong puResponse);
[PreserveSig] int GetText_([In] int lFlags, [In][Out] ref uint puBuffLength, [In][Out][MarshalAs(UnmanagedType.LPWStr)] string pszText);
[PreserveSig] int GetText_([In] int lFlags, [In][Out] ref uint puBuffLength, [Out][MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2, SizeParamIndex = 1)] char[] pszText);
}

[GuidAttribute("3BC15AF2-736C-477E-9E51-238AF8667DCC")]
Expand All @@ -963,24 +964,24 @@ interface IWbemPathKeyList
interface IWbemPath
{
[PreserveSig] int SetText_([In] uint uMode, [In][MarshalAs(UnmanagedType.LPWStr)] string pszPath);
[PreserveSig] int GetText_([In] int lFlags, [In][Out] ref uint puBuffLength, [In][Out][MarshalAs(UnmanagedType.LPWStr)] string pszText);
[PreserveSig] int GetText_([In] int lFlags, [In][Out] ref uint puBuffLength, [Out][MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2, SizeParamIndex = 1)] char[] pszText);
[PreserveSig] int GetInfo_([In] uint uRequestedInfo, [Out] out ulong puResponse);
[PreserveSig] int SetServer_([In][MarshalAs(UnmanagedType.LPWStr)] string Name);
[PreserveSig] int GetServer_([In][Out] ref uint puNameBufLength, [In][Out][MarshalAs(UnmanagedType.LPWStr)] string pName);
[PreserveSig] int GetServer_([In][Out] ref uint puNameBufLength, [Out][MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2, SizeParamIndex = 0)] char[] pName);
[PreserveSig] int GetNamespaceCount_([Out] out uint puCount);
[PreserveSig] int SetNamespaceAt_([In] uint uIndex, [In][MarshalAs(UnmanagedType.LPWStr)] string pszName);
[PreserveSig] int GetNamespaceAt_([In] uint uIndex, [In][Out] ref uint puNameBufLength, [In][Out][MarshalAs(UnmanagedType.LPWStr)] string pName);
[PreserveSig] int SetNamespaceAt_([In] uint uIndex, [In][MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2, SizeParamIndex = 0)] char[] pszName);
[PreserveSig] int GetNamespaceAt_([In] uint uIndex, [In][Out] ref uint puNameBufLength, [Out][MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2, SizeParamIndex = 1)] char[] pName);
[PreserveSig] int RemoveNamespaceAt_([In] uint uIndex);
[PreserveSig] int RemoveAllNamespaces_();
[PreserveSig] int GetScopeCount_([Out] out uint puCount);
[PreserveSig] int SetScope_([In] uint uIndex, [In][MarshalAs(UnmanagedType.LPWStr)] string pszClass);
[PreserveSig] int SetScopeFromText_([In] uint uIndex, [In][MarshalAs(UnmanagedType.LPWStr)] string pszText);
[PreserveSig] int GetScope_([In] uint uIndex, [In][Out] ref uint puClassNameBufSize, [In][Out][MarshalAs(UnmanagedType.LPWStr)] string pszClass, [Out][MarshalAs(UnmanagedType.Interface)] out IWbemPathKeyList pKeyList);
[PreserveSig] int GetScopeAsText_([In] uint uIndex, [In][Out] ref uint puTextBufSize, [In][Out][MarshalAs(UnmanagedType.LPWStr)] string pszText);
[PreserveSig] int GetScope_([In] uint uIndex, [In][Out] ref uint puClassNameBufSize, [Out][MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2, SizeParamIndex = 1)] char[] pszClass, [Out][MarshalAs(UnmanagedType.Interface)] out IWbemPathKeyList pKeyList);
[PreserveSig] int GetScopeAsText_([In] uint uIndex, [In][Out] ref uint puTextBufSize, [Out][MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2, SizeParamIndex = 1)] char[] pszText);
[PreserveSig] int RemoveScope_([In] uint uIndex);
[PreserveSig] int RemoveAllScopes_();
[PreserveSig] int SetClassName_([In][MarshalAs(UnmanagedType.LPWStr)] string Name);
[PreserveSig] int GetClassName_([In][Out] ref uint puBuffLength, [In][Out][MarshalAs(UnmanagedType.LPWStr)] string pszName);
[PreserveSig] int GetClassName_([In][Out] ref uint puBuffLength, [Out][MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2, SizeParamIndex = 0)] char[] pszName);
[PreserveSig] int GetKeyList_([Out][MarshalAs(UnmanagedType.Interface)] out IWbemPathKeyList pOut);
[PreserveSig] int CreateClassPart_([In] int lFlags, [In][MarshalAs(UnmanagedType.LPWStr)] string Name);
[PreserveSig] int DeleteClassPart_([In] int lFlags);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Globalization;
using System.Reflection;
using System.ComponentModel.Design.Serialization;
using System.Text;

namespace System.Management
{
Expand Down Expand Up @@ -321,8 +322,9 @@ private static string GetWbemPath(IWbemPath wbemPath)

if (status >= 0 && 0 < bufLen)
{
pathStr = new string ('0', (int) bufLen-1);
status = wbemPath.GetText_(flags, ref bufLen, pathStr);
char[] pathChars = new char[(int)bufLen];
status = wbemPath.GetText_(flags, ref bufLen, pathChars);
pathStr = new string(pathChars, 0, Array.IndexOf(pathChars, '\0'));
}
}

Expand Down Expand Up @@ -508,11 +510,12 @@ public string RelativePath

if (status >= 0 && 0 < bufLen)
{
pathStr = new string ('0', (int) bufLen-1);
char[] pathChars = new char[(int)bufLen];
status = wmiPath.GetText_(
(int) tag_WBEM_GET_TEXT_FLAGS.WBEMPATH_GET_RELATIVE_ONLY,
ref bufLen,
pathStr);
pathChars);
pathStr = new string(pathChars, 0, Array.IndexOf(pathChars, '\0'));
}

if (status < 0)
Expand Down Expand Up @@ -607,8 +610,9 @@ public string Server

if (status >= 0 && 0 < uLen)
{
pathStr = new string ('0', (int) uLen-1);
status = wmiPath.GetServer_(ref uLen, pathStr);
char[] pathChars = new char[(int)uLen];
status = wmiPath.GetServer_(ref uLen, pathChars);
pathStr = new string(pathChars, 0, Array.IndexOf(pathChars, '\0'));
}

if (status < 0)
Expand Down Expand Up @@ -706,11 +710,11 @@ internal string SetNamespacePath(string nsPath, out bool bChange)

if (status >= 0)
{
string nSpace = new string('0', (int) uLen-1);
status = wmiPathTmp.GetNamespaceAt_(i, ref uLen, nSpace);
char[] space = new char[(int)uLen];
status = wmiPathTmp.GetNamespaceAt_(i, ref uLen, space);
if (status >= 0)
{
status = wmiPath.SetNamespaceAt_(i, nSpace);
status = wmiPath.SetNamespaceAt_(i, space);

if (status < 0)
break;
Expand Down Expand Up @@ -738,8 +742,9 @@ internal string SetNamespacePath(string nsPath, out bool bChange)

if (status >= 0 && uLen > 0)
{
string serverNew = new string ('0', (int) uLen-1);
status = wmiPathTmp.GetServer_(ref uLen, serverNew);
char[] newServerChars = new char[(int)uLen];
status = wmiPathTmp.GetServer_(ref uLen, newServerChars);
string serverNew = new string(newServerChars, 0, Array.IndexOf(newServerChars, '\0'));

if (status >= 0)
{
Expand All @@ -750,8 +755,9 @@ internal string SetNamespacePath(string nsPath, out bool bChange)

if (status >= 0)
{
string serverOrg = new string('0', (int)uLen-1);
status = wmiPath.GetServer_(ref uLen, serverOrg);
char[] orgServerChars = new char[(int)uLen];
status = wmiPath.GetServer_(ref uLen, orgServerChars);
string serverOrg = new string(orgServerChars, 0, Array.IndexOf(orgServerChars, '\0'));

if (status >= 0 && !string.Equals(serverOrg, serverNew, StringComparison.OrdinalIgnoreCase))
status = wmiPath.SetServer_(serverNew);
Expand Down Expand Up @@ -808,8 +814,9 @@ internal static string GetNamespacePath(IWbemPath wbemPath, int flags)

if (status >= 0 && bufLen > 0)
{
pathStr = new string ('0', (int) bufLen-1);
status = wbemPath.GetText_(flags, ref bufLen, pathStr);
char[] pathChars = new char[(int)bufLen];
status = wbemPath.GetText_(flags, ref bufLen, pathChars);
pathStr = new string(pathChars, 0, Array.IndexOf(pathChars, '\0'));
}
}

Expand Down Expand Up @@ -905,8 +912,9 @@ internal string internalClassName

if (status >= 0 && 0 < bufLen)
{
pathStr = new string ('0', (int) bufLen-1);
status = wmiPath.GetClassName_(ref bufLen, pathStr);
char[] pathChars = new char[(int)bufLen];
status = wmiPath.GetClassName_(ref bufLen, pathChars);
pathStr = new string(pathChars, 0, Array.IndexOf(pathChars, '\0'));

if (status < 0)
pathStr = string.Empty;
Expand Down

0 comments on commit 158c3fd

Please sign in to comment.