@@ -963,32 +963,39 @@ void IWeakReferenceable.SetFinalizer(WeakRefTracker value) {
963963
964964 #region IBufferProtocol Members
965965
966- IPythonBuffer IBufferProtocol . GetBuffer ( BufferFlags flags ) {
966+ IPythonBuffer ? IBufferProtocol . GetBuffer ( BufferFlags flags , bool throwOnError ) {
967967 CheckBuffer ( ) ;
968968
969969 if ( flags . HasFlag ( BufferFlags . Writable ) && _isReadOnly )
970- throw PythonOps . BufferError ( "memoryview: underlying buffer is not writable" ) ;
970+ return ReportError ( "memoryview: underlying buffer is not writable" ) ;
971971
972972 if ( flags . HasFlag ( BufferFlags . CContiguous ) && ! _isCContig )
973- throw PythonOps . BufferError ( "memoryview: underlying buffer is not C-contiguous" ) ;
973+ return ReportError ( "memoryview: underlying buffer is not C-contiguous" ) ;
974974
975975 if ( flags . HasFlag ( BufferFlags . FContiguous ) && ! _isFContig )
976- throw PythonOps . BufferError ( "memoryview: underlying buffer is not Fortran contiguous" ) ;
976+ return ReportError ( "memoryview: underlying buffer is not Fortran contiguous" ) ;
977977
978978 if ( flags . HasFlag ( BufferFlags . AnyContiguous ) && ! _isCContig && ! _isFContig )
979- throw PythonOps . BufferError ( "memoryview: underlying buffer is not contiguous" ) ;
979+ return ReportError ( "memoryview: underlying buffer is not contiguous" ) ;
980980
981981 // TODO: Support for suboffsets
982982 //if (!flags.HasFlag(!BufferFlags.Indirect) && _suboffsets != null)
983- // throw PythonOps.BufferError ("memoryview: underlying buffer requires suboffsets");
983+ // return ReportError ("memoryview: underlying buffer requires suboffsets");
984984
985985 if ( ! flags . HasFlag ( BufferFlags . Strides ) && ! _isCContig )
986- throw PythonOps . BufferError ( "memoryview: underlying buffer is not C-contiguous" ) ;
986+ return ReportError ( "memoryview: underlying buffer is not C-contiguous" ) ;
987987
988988 if ( ! flags . HasFlag ( BufferFlags . ND ) && flags . HasFlag ( BufferFlags . Format ) )
989- throw PythonOps . BufferError ( "memoryview: cannot cast to unsigned bytes if the format flag is present" ) ;
989+ return ReportError ( "memoryview: cannot cast to unsigned bytes if the format flag is present" ) ;
990990
991991 return new MemoryView ( this , flags ) ;
992+
993+ IPythonBuffer ? ReportError ( string msg ) {
994+ if ( throwOnError ) {
995+ throw PythonOps . BufferError ( msg ) ;
996+ }
997+ return null ;
998+ }
992999 }
9931000
9941001 #endregion
0 commit comments