@@ -920,6 +920,8 @@ public void resize(long newsize) {
920920 throw PythonOps . ValueError ( "new size out of range" ) ;
921921 }
922922
923+ long capacity = checked ( _offset + newsize ) ;
924+
923925 if ( _handle is not null
924926 && ( RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) || RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) ) ) {
925927 // resize on Posix platforms
@@ -941,14 +943,14 @@ public void resize(long newsize) {
941943
942944 // Resize the underlying file as needed.
943945 int fd = unchecked ( ( int ) _handle . DangerousGetHandle ( ) ) ;
944- PythonNT . ftruncateUnix ( fd , newsize ) ;
946+ PythonNT . ftruncateUnix ( fd , capacity ) ;
945947
946948#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 ) ;
948950#else
949951 _sourceStream ? . Dispose ( ) ;
950952 _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 ) ;
952954#endif
953955 _view = _file . CreateViewAccessor ( _offset , newsize , _fileAccess ) ;
954956 return ;
@@ -968,8 +970,6 @@ public void resize(long newsize) {
968970 return ;
969971 }
970972
971- long capacity = checked ( _offset + newsize ) ;
972-
973973 try {
974974 if ( newsize == 0 ) {
975975 // resizing to an empty mapped region is not allowed
@@ -1401,17 +1401,18 @@ private struct SYSTEM_INFO {
14011401 internal short wProcessorRevision ;
14021402 }
14031403
1404+ [ SupportedOSPlatform ( "windows" ) ]
14041405 [ DllImport ( "kernel32" , SetLastError = true ) ]
14051406 private static extern void GetSystemInfo ( ref SYSTEM_INFO lpSystemInfo ) ;
14061407
14071408 private static int GetAllocationGranularity ( ) {
1408- try {
1409+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ) {
14091410 return GetAllocationGranularityWorker ( ) ;
1410- } catch {
1411- return System . Environment . SystemPageSize ;
14121411 }
1412+ return System . Environment . SystemPageSize ;
14131413 }
14141414
1415+ [ SupportedOSPlatform ( "windows" ) ]
14151416 [ MethodImpl ( MethodImplOptions . NoInlining ) ]
14161417 private static int GetAllocationGranularityWorker ( ) {
14171418 SYSTEM_INFO info = new SYSTEM_INFO ( ) ;
0 commit comments