@@ -812,6 +812,10 @@ public void resize(long newsize) {
812812 if ( _handle . IsInvalid ) {
813813 throw PythonNT . GetOsError ( PythonErrno . EBADF ) ;
814814 }
815+ if ( _view . Capacity == newsize ) {
816+ // resizing to the same size
817+ return ;
818+ }
815819 if ( newsize == 0 ) {
816820 // resizing to an empty mapped region is not allowed
817821 throw PythonNT . GetOsError ( PythonErrno . EINVAL ) ;
@@ -844,14 +848,6 @@ public void resize(long newsize) {
844848 throw WindowsError ( PythonExceptions . _OSError . ERROR_INVALID_PARAMETER ) ;
845849 }
846850
847- if ( newsize == 0 ) {
848- // resizing to an empty mapped region is not allowed
849- throw WindowsError ( _offset != 0 && RuntimeInformation . IsOSPlatform ( OSPlatform . Windows )
850- ? PythonExceptions . _OSError . ERROR_ACCESS_DENIED
851- : PythonExceptions . _OSError . ERROR_FILE_INVALID
852- ) ;
853- }
854-
855851 if ( _view . Capacity == newsize ) {
856852 // resizing to the same size
857853 return ;
@@ -860,6 +856,14 @@ public void resize(long newsize) {
860856 long capacity = checked ( _offset + newsize ) ;
861857
862858 try {
859+ if ( newsize == 0 ) {
860+ // resizing to an empty mapped region is not allowed
861+ throw WindowsError ( _offset != 0 && RuntimeInformation . IsOSPlatform ( OSPlatform . Windows )
862+ ? PythonExceptions . _OSError . ERROR_ACCESS_DENIED
863+ : PythonExceptions . _OSError . ERROR_FILE_INVALID
864+ ) ;
865+ }
866+
863867 _view . Flush ( ) ;
864868 _view . Dispose ( ) ;
865869 _file . Dispose ( ) ;
@@ -1143,13 +1147,13 @@ private void EnsureOpen() {
11431147 }
11441148 }
11451149
1146- private struct MmapLocker : IDisposable {
1150+ private readonly struct MmapLocker : IDisposable {
11471151 private readonly MmapDefault _mmap ;
11481152
11491153 public MmapLocker ( MmapDefault mmap ) {
11501154 _mmap = mmap ;
1151- Interlocked . Increment ( ref _mmap . _refCount ) ;
11521155 _mmap . EnsureOpen ( ) ;
1156+ Interlocked . Increment ( ref _mmap . _refCount ) ;
11531157 }
11541158
11551159 #region IDisposable Members
0 commit comments