Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET Platform
runtime
提交
a38b50c3
R
runtime
项目概览
dotNET Platform
/
runtime
大约 1 年 前同步成功
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
runtime
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
a38b50c3
编写于
6月 27, 2022
作者:
S
Stephen Toub
提交者:
GitHub
6月 27, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove some unnecessary fixed blocks (#71317)
上级
aa06c896
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
41 addition
and
124 deletion
+41
-124
src/libraries/Common/src/Interop/Unix/System.Native/Interop.IPAddress.cs
...ommon/src/Interop/Unix/System.Native/Interop.IPAddress.cs
+3
-9
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.WIN32_FIND_DATA.cs
...n/src/Interop/Windows/Kernel32/Interop.WIN32_FIND_DATA.cs
+2
-4
src/libraries/Common/src/Interop/Windows/NtDll/Interop.FILE_FULL_DIR_INFORMATION.cs
...nterop/Windows/NtDll/Interop.FILE_FULL_DIR_INFORMATION.cs
+1
-1
src/libraries/Common/src/Interop/Windows/SChannel/Interop.SecPkgContext_ApplicationProtocol.cs
...ows/SChannel/Interop.SecPkgContext_ApplicationProtocol.cs
+2
-10
src/libraries/Common/src/Interop/Windows/User32/Interop.LOGFONT.cs
...ries/Common/src/Interop/Windows/User32/Interop.LOGFONT.cs
+1
-4
src/libraries/Common/src/Interop/Windows/WinMm/Interop.waveOutGetDevCaps.cs
...on/src/Interop/Windows/WinMm/Interop.waveOutGetDevCaps.cs
+12
-20
src/libraries/Common/src/Interop/Windows/WinSock/Interop.WinsockBSD.cs
.../Common/src/Interop/Windows/WinSock/Interop.WinsockBSD.cs
+2
-8
src/libraries/Common/src/System/Net/NTAuthentication.Managed.cs
...braries/Common/src/System/Net/NTAuthentication.Managed.cs
+4
-7
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/BsdIPGlobalProperties.cs
...rc/System/Net/NetworkInformation/BsdIPGlobalProperties.cs
+7
-34
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/BsdIpInterfaceProperties.cs
...System/Net/NetworkInformation/BsdIpInterfaceProperties.cs
+1
-1
src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemEntry.Unix.cs
...CoreLib/src/System/IO/Enumeration/FileSystemEntry.Unix.cs
+3
-5
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.Unix.cs
...oreLib/src/System/Runtime/InteropServices/Marshal.Unix.cs
+1
-7
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs
...ate.CoreLib/src/System/Runtime/InteropServices/Marshal.cs
+2
-14
未找到文件。
src/libraries/Common/src/Interop/Unix/System.Native/Interop.IPAddress.cs
浏览文件 @
a38b50c3
...
@@ -35,10 +35,7 @@ public bool IsIPv6
...
@@ -35,10 +35,7 @@ public bool IsIPv6
public
override
unsafe
int
GetHashCode
()
public
override
unsafe
int
GetHashCode
()
{
{
HashCode
h
=
default
;
HashCode
h
=
default
;
fixed
(
byte
*
ptr
=
Address
)
h
.
AddBytes
(
MemoryMarshal
.
CreateReadOnlySpan
(
ref
Address
[
0
],
IsIPv6
?
IPv6AddressBytes
:
IPv4AddressBytes
));
{
h
.
AddBytes
(
new
ReadOnlySpan
<
byte
>(
ptr
,
IsIPv6
?
IPv6AddressBytes
:
IPv4AddressBytes
));
}
return
h
.
ToHashCode
();
return
h
.
ToHashCode
();
}
}
...
@@ -71,11 +68,8 @@ public bool Equals(IPAddress other)
...
@@ -71,11 +68,8 @@ public bool Equals(IPAddress other)
addressByteCount
=
IPv4AddressBytes
;
addressByteCount
=
IPv4AddressBytes
;
}
}
fixed
(
byte
*
thisAddress
=
Address
)
return
MemoryMarshal
.
CreateReadOnlySpan
(
ref
Address
[
0
],
addressByteCount
).
SequenceEqual
(
{
new
ReadOnlySpan
<
byte
>(
other
.
Address
,
addressByteCount
));
return
new
ReadOnlySpan
<
byte
>(
thisAddress
,
addressByteCount
).
SequenceEqual
(
new
ReadOnlySpan
<
byte
>(
other
.
Address
,
addressByteCount
));
}
}
}
}
}
}
}
...
...
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.WIN32_FIND_DATA.cs
浏览文件 @
a38b50c3
...
@@ -22,10 +22,8 @@ internal unsafe struct WIN32_FIND_DATA
...
@@ -22,10 +22,8 @@ internal unsafe struct WIN32_FIND_DATA
private
fixed
char
_cFileName
[
MAX_PATH
];
private
fixed
char
_cFileName
[
MAX_PATH
];
private
fixed
char
_cAlternateFileName
[
14
];
private
fixed
char
_cAlternateFileName
[
14
];
internal
ReadOnlySpan
<
char
>
cFileName
internal
ReadOnlySpan
<
char
>
cFileName
=>
{
MemoryMarshal
.
CreateReadOnlySpan
(
ref
_cFileName
[
0
],
MAX_PATH
);
get
{
fixed
(
char
*
c
=
_cFileName
)
return
new
ReadOnlySpan
<
char
>(
c
,
MAX_PATH
);
}
}
}
}
}
}
}
}
src/libraries/Common/src/Interop/Windows/NtDll/Interop.FILE_FULL_DIR_INFORMATION.cs
浏览文件 @
a38b50c3
...
@@ -54,7 +54,7 @@ public struct FILE_FULL_DIR_INFORMATION
...
@@ -54,7 +54,7 @@ public struct FILE_FULL_DIR_INFORMATION
public
uint
EaSize
;
public
uint
EaSize
;
private
char
_fileName
;
private
char
_fileName
;
public
unsafe
ReadOnlySpan
<
char
>
FileName
{
get
{
fixed
(
char
*
c
=
&
_fileName
)
{
return
new
ReadOnlySpan
<
char
>(
c
,
(
int
)
FileNameLength
/
sizeof
(
char
));
}
}
}
public
unsafe
ReadOnlySpan
<
char
>
FileName
=>
MemoryMarshal
.
CreateReadOnlySpan
(
ref
_fileName
,
(
int
)
FileNameLength
/
sizeof
(
char
));
/// <summary>
/// <summary>
/// Gets the next info pointer or null if there are no more.
/// Gets the next info pointer or null if there are no more.
...
...
src/libraries/Common/src/Interop/Windows/SChannel/Interop.SecPkgContext_ApplicationProtocol.cs
浏览文件 @
a38b50c3
...
@@ -29,15 +29,7 @@ internal unsafe struct SecPkgContext_ApplicationProtocol
...
@@ -29,15 +29,7 @@ internal unsafe struct SecPkgContext_ApplicationProtocol
public
ApplicationProtocolNegotiationExt
ProtoNegoExt
;
public
ApplicationProtocolNegotiationExt
ProtoNegoExt
;
public
byte
ProtocolIdSize
;
public
byte
ProtocolIdSize
;
public
fixed
byte
ProtocolId
[
MaxProtocolIdSize
];
public
fixed
byte
ProtocolId
[
MaxProtocolIdSize
];
public
ReadOnlySpan
<
byte
>
Protocol
public
ReadOnlySpan
<
byte
>
Protocol
=>
{
MemoryMarshal
.
CreateReadOnlySpan
(
ref
ProtocolId
[
0
],
ProtocolIdSize
);
get
{
fixed
(
byte
*
pid
=
ProtocolId
)
{
return
new
ReadOnlySpan
<
byte
>(
pid
,
ProtocolIdSize
);
}
}
}
}
}
}
}
src/libraries/Common/src/Interop/Windows/User32/Interop.LOGFONT.cs
浏览文件 @
a38b50c3
...
@@ -27,10 +27,7 @@ public unsafe struct LOGFONT
...
@@ -27,10 +27,7 @@ public unsafe struct LOGFONT
public
byte
lfQuality
;
public
byte
lfQuality
;
public
byte
lfPitchAndFamily
;
public
byte
lfPitchAndFamily
;
private
fixed
char
_lfFaceName
[
LF_FACESIZE
];
private
fixed
char
_lfFaceName
[
LF_FACESIZE
];
public
Span
<
char
>
lfFaceName
public
Span
<
char
>
lfFaceName
=>
MemoryMarshal
.
CreateSpan
(
ref
_lfFaceName
[
0
],
LF_FACESIZE
);
{
get
{
fixed
(
char
*
c
=
_lfFaceName
)
{
return
new
Span
<
char
>(
c
,
LF_FACESIZE
);
}
}
}
public
override
string
ToString
()
public
override
string
ToString
()
{
{
...
...
src/libraries/Common/src/Interop/Windows/WinMm/Interop.waveOutGetDevCaps.cs
浏览文件 @
a38b50c3
...
@@ -50,33 +50,25 @@ public Native(WAVEOUTCAPS managed)
...
@@ -50,33 +50,25 @@ public Native(WAVEOUTCAPS managed)
wMid
=
managed
.
wMid
;
wMid
=
managed
.
wMid
;
wPid
=
managed
.
wPid
;
wPid
=
managed
.
wPid
;
vDriverVersion
=
managed
.
vDriverVersion
;
vDriverVersion
=
managed
.
vDriverVersion
;
fixed
(
char
*
pszPname
=
szPname
)
managed
.
szPname
.
CopyTo
(
MemoryMarshal
.
CreateSpan
(
ref
szPname
[
0
],
szPnameLength
));
{
managed
.
szPname
.
AsSpan
().
CopyTo
(
new
Span
<
char
>(
pszPname
,
szPnameLength
));
}
dwFormats
=
managed
.
dwFormats
;
dwFormats
=
managed
.
dwFormats
;
wChannels
=
managed
.
wChannels
;
wChannels
=
managed
.
wChannels
;
wReserved1
=
managed
.
wReserved1
;
wReserved1
=
managed
.
wReserved1
;
dwSupport
=
managed
.
dwSupport
;
dwSupport
=
managed
.
dwSupport
;
}
}
public
WAVEOUTCAPS
ToManaged
()
public
WAVEOUTCAPS
ToManaged
()
=>
{
new
WAVEOUTCAPS
fixed
(
char
*
pszPname
=
szPname
)
{
{
return
new
WAVEOUTCAPS
wMid
=
wMid
,
{
wPid
=
wPid
,
wMid
=
wMid
,
vDriverVersion
=
vDriverVersion
,
wPid
=
wPid
,
szPname
=
MemoryMarshal
.
CreateReadOnlySpan
(
ref
szPname
[
0
],
szPnameLength
).
ToString
(),
vDriverVersion
=
vDriverVersion
,
dwFormats
=
dwFormats
,
szPname
=
new
Span
<
char
>(
pszPname
,
szPnameLength
).
ToString
(),
wChannels
=
wChannels
,
dwFormats
=
dwFormats
,
wReserved1
=
wReserved1
,
wChannels
=
wChannels
,
dwSupport
=
dwSupport
,
wReserved1
=
wReserved1
,
};
dwSupport
=
dwSupport
,
};
}
}
}
}
}
}
#endif
#endif
...
...
src/libraries/Common/src/Interop/Windows/WinSock/Interop.WinsockBSD.cs
浏览文件 @
a38b50c3
...
@@ -89,10 +89,7 @@ public unsafe struct Native
...
@@ -89,10 +89,7 @@ public unsafe struct Native
public
Native
(
IPv6MulticastRequest
managed
)
public
Native
(
IPv6MulticastRequest
managed
)
{
{
Debug
.
Assert
(
managed
.
MulticastAddress
.
Length
==
MulticastAddressLength
);
Debug
.
Assert
(
managed
.
MulticastAddress
.
Length
==
MulticastAddressLength
);
fixed
(
void
*
dest
=
_multicastAddress
)
managed
.
MulticastAddress
.
CopyTo
(
MemoryMarshal
.
CreateSpan
(
ref
_multicastAddress
[
0
],
MulticastAddressLength
));
{
managed
.
MulticastAddress
.
CopyTo
(
new
Span
<
byte
>(
dest
,
MulticastAddressLength
));
}
_interfaceIndex
=
managed
.
InterfaceIndex
;
_interfaceIndex
=
managed
.
InterfaceIndex
;
}
}
...
@@ -103,10 +100,7 @@ public IPv6MulticastRequest ToManaged()
...
@@ -103,10 +100,7 @@ public IPv6MulticastRequest ToManaged()
MulticastAddress
=
new
byte
[
MulticastAddressLength
],
MulticastAddress
=
new
byte
[
MulticastAddressLength
],
InterfaceIndex
=
_interfaceIndex
InterfaceIndex
=
_interfaceIndex
};
};
fixed
(
void
*
src
=
_multicastAddress
)
MemoryMarshal
.
CreateReadOnlySpan
(
ref
_multicastAddress
[
0
],
MulticastAddressLength
).
CopyTo
(
managed
.
MulticastAddress
);
{
new
Span
<
byte
>(
src
,
16
).
CopyTo
(
managed
.
MulticastAddress
);
}
return
managed
;
return
managed
;
}
}
}
}
...
...
src/libraries/Common/src/System/Net/NTAuthentication.Managed.cs
浏览文件 @
a38b50c3
...
@@ -424,13 +424,10 @@ private static unsafe void SetField(ref MessageField field, int length, int offs
...
@@ -424,13 +424,10 @@ private static unsafe void SetField(ref MessageField field, int length, int offs
throw
new
Win32Exception
(
NTE_FAIL
);
throw
new
Win32Exception
(
NTE_FAIL
);
}
}
fixed
(
void
*
ptr
=
&
field
)
Span
<
byte
>
span
=
MemoryMarshal
.
AsBytes
(
MemoryMarshal
.
CreateSpan
(
ref
field
,
1
));
{
BinaryPrimitives
.
WriteInt16LittleEndian
(
span
,
(
short
)
length
);
Span
<
byte
>
span
=
new
Span
<
byte
>(
ptr
,
sizeof
(
MessageField
));
BinaryPrimitives
.
WriteInt16LittleEndian
(
span
.
Slice
(
2
),
(
short
)
length
);
BinaryPrimitives
.
WriteInt16LittleEndian
(
span
,
(
short
)
length
);
BinaryPrimitives
.
WriteInt32LittleEndian
(
span
.
Slice
(
4
),
offset
);
BinaryPrimitives
.
WriteInt16LittleEndian
(
span
.
Slice
(
2
),
(
short
)
length
);
BinaryPrimitives
.
WriteInt32LittleEndian
(
span
.
Slice
(
4
),
offset
);
}
}
}
private
static
void
AddToPayload
(
ref
MessageField
field
,
ReadOnlySpan
<
byte
>
data
,
Span
<
byte
>
payload
,
ref
int
offset
)
private
static
void
AddToPayload
(
ref
MessageField
field
,
ReadOnlySpan
<
byte
>
data
,
Span
<
byte
>
payload
,
ref
int
offset
)
...
...
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/BsdIPGlobalProperties.cs
浏览文件 @
a38b50c3
...
@@ -32,28 +32,12 @@ private unsafe TcpConnectionInformation[] GetTcpConnections(bool listeners)
...
@@ -32,28 +32,12 @@ private unsafe TcpConnectionInformation[] GetTcpConnections(bool listeners)
continue
;
continue
;
}
}
byte
[]
localBytes
=
new
byte
[
nativeInfo
.
LocalEndPoint
.
NumAddressBytes
];
IPAddress
localIPAddress
=
new
IPAddress
(
new
ReadOnlySpan
<
byte
>(
nativeInfo
.
LocalEndPoint
.
AddressBytes
,
checked
((
int
)
nativeInfo
.
LocalEndPoint
.
NumAddressBytes
)));
fixed
(
byte
*
localBytesPtr
=
localBytes
)
{
Buffer
.
MemoryCopy
(
nativeInfo
.
LocalEndPoint
.
AddressBytes
,
localBytesPtr
,
localBytes
.
Length
,
localBytes
.
Length
);
}
IPAddress
localIPAddress
=
new
IPAddress
(
localBytes
);
IPEndPoint
local
=
new
IPEndPoint
(
localIPAddress
,
(
int
)
nativeInfo
.
LocalEndPoint
.
Port
);
IPEndPoint
local
=
new
IPEndPoint
(
localIPAddress
,
(
int
)
nativeInfo
.
LocalEndPoint
.
Port
);
IPAddress
remoteIPAddress
;
IPAddress
remoteIPAddress
=
nativeInfo
.
RemoteEndPoint
.
NumAddressBytes
==
0
?
if
(
nativeInfo
.
RemoteEndPoint
.
NumAddressBytes
==
0
)
IPAddress
.
Any
:
{
new
IPAddress
(
new
ReadOnlySpan
<
byte
>(
nativeInfo
.
RemoteEndPoint
.
AddressBytes
,
checked
((
int
)
nativeInfo
.
RemoteEndPoint
.
NumAddressBytes
)));
remoteIPAddress
=
IPAddress
.
Any
;
}
else
{
byte
[]
remoteBytes
=
new
byte
[
nativeInfo
.
RemoteEndPoint
.
NumAddressBytes
];
fixed
(
byte
*
remoteBytesPtr
=
&
remoteBytes
[
0
])
{
Buffer
.
MemoryCopy
(
nativeInfo
.
RemoteEndPoint
.
AddressBytes
,
remoteBytesPtr
,
remoteBytes
.
Length
,
remoteBytes
.
Length
);
}
remoteIPAddress
=
new
IPAddress
(
remoteBytes
);
}
IPEndPoint
remote
=
new
IPEndPoint
(
remoteIPAddress
,
(
int
)
nativeInfo
.
RemoteEndPoint
.
Port
);
IPEndPoint
remote
=
new
IPEndPoint
(
remoteIPAddress
,
(
int
)
nativeInfo
.
RemoteEndPoint
.
Port
);
connectionInformations
[
nextResultIndex
++]
=
new
SimpleTcpConnectionInformation
(
local
,
remote
,
state
);
connectionInformations
[
nextResultIndex
++]
=
new
SimpleTcpConnectionInformation
(
local
,
remote
,
state
);
...
@@ -101,20 +85,9 @@ public override unsafe IPEndPoint[] GetActiveUdpListeners()
...
@@ -101,20 +85,9 @@ public override unsafe IPEndPoint[] GetActiveUdpListeners()
{
{
Interop
.
Sys
.
IPEndPointInfo
endPointInfo
=
infos
[
i
];
Interop
.
Sys
.
IPEndPointInfo
endPointInfo
=
infos
[
i
];
int
port
=
(
int
)
endPointInfo
.
Port
;
int
port
=
(
int
)
endPointInfo
.
Port
;
IPAddress
ipAddress
;
IPAddress
ipAddress
=
endPointInfo
.
NumAddressBytes
==
0
?
if
(
endPointInfo
.
NumAddressBytes
==
0
)
IPAddress
.
Any
:
{
new
IPAddress
(
new
ReadOnlySpan
<
byte
>(
endPointInfo
.
AddressBytes
,
checked
((
int
)
endPointInfo
.
NumAddressBytes
)));
ipAddress
=
IPAddress
.
Any
;
}
else
{
byte
[]
bytes
=
new
byte
[
endPointInfo
.
NumAddressBytes
];
fixed
(
byte
*
bytesPtr
=
&
bytes
[
0
])
{
Buffer
.
MemoryCopy
(
endPointInfo
.
AddressBytes
,
bytesPtr
,
bytes
.
Length
,
bytes
.
Length
);
}
ipAddress
=
new
IPAddress
(
bytes
);
}
endPoints
[
i
]
=
new
IPEndPoint
(
ipAddress
,
port
);
endPoints
[
i
]
=
new
IPEndPoint
(
ipAddress
,
port
);
}
}
...
...
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/BsdIpInterfaceProperties.cs
浏览文件 @
a38b50c3
...
@@ -93,7 +93,7 @@ private static unsafe void OnGatewayFound(void* pContext, Interop.Sys.IpAddressI
...
@@ -93,7 +93,7 @@ private static unsafe void OnGatewayFound(void* pContext, Interop.Sys.IpAddressI
{
{
ref
Context
context
=
ref
Unsafe
.
As
<
byte
,
Context
>(
ref
*(
byte
*)
pContext
);
ref
Context
context
=
ref
Unsafe
.
As
<
byte
,
Context
>(
ref
*(
byte
*)
pContext
);
IPAddress
ipAddress
=
new
IPAddress
(
new
Span
<
byte
>(
gatewayAddressInfo
->
AddressBytes
,
gatewayAddressInfo
->
NumAddressBytes
).
ToArray
(
));
IPAddress
ipAddress
=
new
IPAddress
(
new
ReadOnlySpan
<
byte
>(
gatewayAddressInfo
->
AddressBytes
,
gatewayAddressInfo
->
NumAddressBytes
));
if
(
ipAddress
.
IsIPv6LinkLocal
)
if
(
ipAddress
.
IsIPv6LinkLocal
)
{
{
// For Link-Local addresses add ScopeId as that is not part of the route entry.
// For Link-Local addresses add ScopeId as that is not part of the route entry.
...
...
src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemEntry.Unix.cs
浏览文件 @
a38b50c3
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// The .NET Foundation licenses this file to you under the MIT license.
using
System.Diagnostics
;
using
System.Diagnostics
;
using
System.Runtime.InteropServices
;
namespace
System.IO.Enumeration
namespace
System.IO.Enumeration
{
{
...
@@ -88,11 +89,8 @@ public ReadOnlySpan<char> FileName
...
@@ -88,11 +89,8 @@ public ReadOnlySpan<char> FileName
{
{
if
(
_directoryEntry
.
NameLength
!=
0
&&
_fileName
.
Length
==
0
)
if
(
_directoryEntry
.
NameLength
!=
0
&&
_fileName
.
Length
==
0
)
{
{
fixed
(
char
*
c
=
_fileNameBuffer
)
Span
<
char
>
buffer
=
MemoryMarshal
.
CreateSpan
(
ref
_fileNameBuffer
[
0
],
Interop
.
Sys
.
DirectoryEntry
.
NameBufferSize
);
{
_fileName
=
_directoryEntry
.
GetName
(
buffer
);
Span
<
char
>
buffer
=
new
Span
<
char
>(
c
,
Interop
.
Sys
.
DirectoryEntry
.
NameBufferSize
);
_fileName
=
_directoryEntry
.
GetName
(
buffer
);
}
}
}
return
_fileName
;
return
_fileName
;
...
...
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.Unix.cs
浏览文件 @
a38b50c3
...
@@ -36,13 +36,7 @@ internal static unsafe int StringToAnsiString(string s, byte* buffer, int buffer
...
@@ -36,13 +36,7 @@ internal static unsafe int StringToAnsiString(string s, byte* buffer, int buffer
{
{
Debug
.
Assert
(
bufferLength
>=
(
s
.
Length
+
1
)
*
SystemMaxDBCSCharSize
,
"Insufficient buffer length passed to StringToAnsiString"
);
Debug
.
Assert
(
bufferLength
>=
(
s
.
Length
+
1
)
*
SystemMaxDBCSCharSize
,
"Insufficient buffer length passed to StringToAnsiString"
);
int
convertedBytes
;
int
convertedBytes
=
Encoding
.
UTF8
.
GetBytes
(
s
,
new
Span
<
byte
>(
buffer
,
bufferLength
));
fixed
(
char
*
pChar
=
s
)
{
convertedBytes
=
Encoding
.
UTF8
.
GetBytes
(
pChar
,
s
.
Length
,
buffer
,
bufferLength
);
}
buffer
[
convertedBytes
]
=
0
;
buffer
[
convertedBytes
]
=
0
;
return
convertedBytes
;
return
convertedBytes
;
...
...
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs
浏览文件 @
a38b50c3
...
@@ -995,14 +995,8 @@ private static unsafe IntPtr StringToHGlobalUTF8(string? s)
...
@@ -995,14 +995,8 @@ private static unsafe IntPtr StringToHGlobalUTF8(string? s)
IntPtr
ptr
=
AllocHGlobal
(
checked
(
nb
+
1
));
IntPtr
ptr
=
AllocHGlobal
(
checked
(
nb
+
1
));
int
nbWritten
;
byte
*
pbMem
=
(
byte
*)
ptr
;
byte
*
pbMem
=
(
byte
*)
ptr
;
int
nbWritten
=
Encoding
.
UTF8
.
GetBytes
(
s
,
new
Span
<
byte
>(
pbMem
,
nb
));
fixed
(
char
*
firstChar
=
s
)
{
nbWritten
=
Encoding
.
UTF8
.
GetBytes
(
firstChar
,
s
.
Length
,
pbMem
,
nb
);
}
pbMem
[
nbWritten
]
=
0
;
pbMem
[
nbWritten
]
=
0
;
return
ptr
;
return
ptr
;
...
@@ -1042,14 +1036,8 @@ public static unsafe IntPtr StringToCoTaskMemUTF8(string? s)
...
@@ -1042,14 +1036,8 @@ public static unsafe IntPtr StringToCoTaskMemUTF8(string? s)
IntPtr
ptr
=
AllocCoTaskMem
(
checked
(
nb
+
1
));
IntPtr
ptr
=
AllocCoTaskMem
(
checked
(
nb
+
1
));
int
nbWritten
;
byte
*
pbMem
=
(
byte
*)
ptr
;
byte
*
pbMem
=
(
byte
*)
ptr
;
int
nbWritten
=
Encoding
.
UTF8
.
GetBytes
(
s
,
new
Span
<
byte
>(
pbMem
,
nb
));
fixed
(
char
*
firstChar
=
s
)
{
nbWritten
=
Encoding
.
UTF8
.
GetBytes
(
firstChar
,
s
.
Length
,
pbMem
,
nb
);
}
pbMem
[
nbWritten
]
=
0
;
pbMem
[
nbWritten
]
=
0
;
return
ptr
;
return
ptr
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录