File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -291,6 +291,17 @@ mmap_read_line_method(mmap_object *self,
291291 return result ;
292292}
293293
294+ #if defined(MS_WIN32 ) && !defined(DONT_USE_SEH )
295+ static DWORD HandlePageException (EXCEPTION_POINTERS * ptrs , EXCEPTION_RECORD * record )
296+ {
297+ * record = * ptrs -> ExceptionRecord ;
298+ if (ptrs -> ExceptionRecord -> ExceptionCode == EXCEPTION_IN_PAGE_ERROR ) {
299+ return EXCEPTION_EXECUTE_HANDLER ;
300+ }
301+ return EXCEPTION_CONTINUE_SEARCH ;
302+ }
303+ #endif
304+
294305static PyObject *
295306mmap_read_method (mmap_object * self ,
296307 PyObject * args )
@@ -307,8 +318,23 @@ mmap_read_method(mmap_object *self,
307318 remaining = (self -> pos < self -> size ) ? self -> size - self -> pos : 0 ;
308319 if (num_bytes < 0 || num_bytes > remaining )
309320 num_bytes = remaining ;
321+
322+ #if defined(MS_WIN32 ) && !defined(DONT_USE_SEH )
323+ EXCEPTION_RECORD record ;
324+ __try {
325+ result = PyBytes_FromStringAndSize (& self -> data [self -> pos ], num_bytes );
326+ self -> pos += num_bytes ;
327+ }
328+ __except (HandlePageException (GetExceptionInformation (), & record )) {
329+ NTSTATUS code = record .ExceptionInformation [2 ];
330+ PyErr_SetFromWindowsErr (code );
331+ result = NULL ;
332+ }
333+ #else
310334 result = PyBytes_FromStringAndSize (& self -> data [self -> pos ], num_bytes );
311335 self -> pos += num_bytes ;
336+ #endif
337+
312338 return result ;
313339}
314340
You can’t perform that action at this time.
0 commit comments