@@ -920,6 +920,8 @@ public void resize(long newsize) {
920
920
throw PythonOps . ValueError ( "new size out of range" ) ;
921
921
}
922
922
923
+ long capacity = checked ( _offset + newsize ) ;
924
+
923
925
if ( _handle is not null
924
926
&& ( RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) || RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) ) ) {
925
927
// resize on Posix platforms
@@ -941,14 +943,14 @@ public void resize(long newsize) {
941
943
942
944
// Resize the underlying file as needed.
943
945
int fd = unchecked ( ( int ) _handle . DangerousGetHandle ( ) ) ;
944
- PythonNT . ftruncateUnix ( fd , newsize ) ;
946
+ PythonNT . ftruncateUnix ( fd , capacity ) ;
945
947
946
948
#if NET8_0_OR_GREATER
947
- _file = MemoryMappedFile . CreateFromFile ( _handle , _mapName , newsize , _fileAccess , HandleInheritability . None , leaveOpen : true ) ;
949
+ _file = MemoryMappedFile . CreateFromFile ( _handle , _mapName , capacity , _fileAccess , HandleInheritability . None , leaveOpen : true ) ;
948
950
#else
949
951
_sourceStream ? . Dispose ( ) ;
950
952
_sourceStream = new FileStream ( new SafeFileHandle ( ( IntPtr ) fd , ownsHandle : false ) , FileAccess . ReadWrite ) ;
951
- _file = CreateFromFile ( _sourceStream , _mapName , newsize , _fileAccess , HandleInheritability . None , leaveOpen : true ) ;
953
+ _file = CreateFromFile ( _sourceStream , _mapName , capacity , _fileAccess , HandleInheritability . None , leaveOpen : true ) ;
952
954
#endif
953
955
_view = _file . CreateViewAccessor ( _offset , newsize , _fileAccess ) ;
954
956
return ;
@@ -968,8 +970,6 @@ public void resize(long newsize) {
968
970
return ;
969
971
}
970
972
971
- long capacity = checked ( _offset + newsize ) ;
972
-
973
973
try {
974
974
if ( newsize == 0 ) {
975
975
// resizing to an empty mapped region is not allowed
@@ -1401,17 +1401,18 @@ private struct SYSTEM_INFO {
1401
1401
internal short wProcessorRevision ;
1402
1402
}
1403
1403
1404
+ [ SupportedOSPlatform ( "windows" ) ]
1404
1405
[ DllImport ( "kernel32" , SetLastError = true ) ]
1405
1406
private static extern void GetSystemInfo ( ref SYSTEM_INFO lpSystemInfo ) ;
1406
1407
1407
1408
private static int GetAllocationGranularity ( ) {
1408
- try {
1409
+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ) {
1409
1410
return GetAllocationGranularityWorker ( ) ;
1410
- } catch {
1411
- return System . Environment . SystemPageSize ;
1412
1411
}
1412
+ return System . Environment . SystemPageSize ;
1413
1413
}
1414
1414
1415
+ [ SupportedOSPlatform ( "windows" ) ]
1415
1416
[ MethodImpl ( MethodImplOptions . NoInlining ) ]
1416
1417
private static int GetAllocationGranularityWorker ( ) {
1417
1418
SYSTEM_INFO info = new SYSTEM_INFO ( ) ;
0 commit comments