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+ #ifdef DONT_USE_SEH
310323 result = PyBytes_FromStringAndSize (& self -> data [self -> pos ], num_bytes );
311324 self -> pos += num_bytes ;
325+ #else
326+ EXCEPTION_RECORD record ;
327+ __try {
328+ result = PyBytes_FromStringAndSize (& self -> data [self -> pos ], num_bytes );
329+ self -> pos += num_bytes ;
330+ }
331+ __except (HandlePageException (GetExceptionInformation (), & record )) {
332+ NTSTATUS code = record .ExceptionInformation [2 ];
333+ PyErr_SetFromWindowsErr (code );
334+ result = NULL ;
335+ }
336+ #endif
337+
312338 return result ;
313339}
314340
You can’t perform that action at this time.
0 commit comments