File tree 1 file changed +26
-0
lines changed
Filter options
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,
291
291
return result ;
292
292
}
293
293
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
+
294
305
static PyObject *
295
306
mmap_read_method (mmap_object * self ,
296
307
PyObject * args )
@@ -307,8 +318,23 @@ mmap_read_method(mmap_object *self,
307
318
remaining = (self -> pos < self -> size ) ? self -> size - self -> pos : 0 ;
308
319
if (num_bytes < 0 || num_bytes > remaining )
309
320
num_bytes = remaining ;
321
+
322
+ #ifdef DONT_USE_SEH
310
323
result = PyBytes_FromStringAndSize (& self -> data [self -> pos ], num_bytes );
311
324
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
+
312
338
return result ;
313
339
}
314
340
You can’t perform that action at this time.
0 commit comments