Skip to content

Commit

Permalink
add structured exception handling to mmap_read_method
Browse files Browse the repository at this point in the history
  • Loading branch information
trend-jannis-weigend committed Apr 24, 2024
1 parent 7e87d30 commit d858720
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Modules/mmapmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,17 @@ mmap_read_line_method(mmap_object *self,
return result;
}

#if defined(MS_WIN32) && !defined(DONT_USE_SEH)
static DWORD HandlePageException(EXCEPTION_POINTERS *ptrs, EXCEPTION_RECORD *record)
{
*record = *ptrs->ExceptionRecord;
if (ptrs->ExceptionRecord->ExceptionCode == EXCEPTION_IN_PAGE_ERROR) {
return EXCEPTION_EXECUTE_HANDLER;
}
return EXCEPTION_CONTINUE_SEARCH;
}
#endif

static PyObject *
mmap_read_method(mmap_object *self,
PyObject *args)
Expand All @@ -307,8 +318,23 @@ mmap_read_method(mmap_object *self,
remaining = (self->pos < self->size) ? self->size - self->pos : 0;
if (num_bytes < 0 || num_bytes > remaining)
num_bytes = remaining;

#ifdef DONT_USE_SEH
result = PyBytes_FromStringAndSize(&self->data[self->pos], num_bytes);
self->pos += num_bytes;
#else
EXCEPTION_RECORD record;

Check failure on line 326 in Modules/mmapmodule.c

View workflow job for this annotation

GitHub Actions / Hypothesis tests on Ubuntu

unknown type name ‘EXCEPTION_RECORD’

Check warning on line 326 in Modules/mmapmodule.c

View workflow job for this annotation

GitHub Actions / Hypothesis tests on Ubuntu

unused variable ‘record’ [-Wunused-variable]

Check failure on line 326 in Modules/mmapmodule.c

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test

unknown type name ‘EXCEPTION_RECORD’

Check warning on line 326 in Modules/mmapmodule.c

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test

unused variable ‘record’ [-Wunused-variable]

Check failure on line 326 in Modules/mmapmodule.c

View workflow job for this annotation

GitHub Actions / Ubuntu SSL tests with OpenSSL (3.2.1)

unknown type name ‘EXCEPTION_RECORD’

Check warning on line 326 in Modules/mmapmodule.c

View workflow job for this annotation

GitHub Actions / Ubuntu SSL tests with OpenSSL (3.2.1)

unused variable ‘record’ [-Wunused-variable]

Check failure on line 326 in Modules/mmapmodule.c

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test

unknown type name ‘EXCEPTION_RECORD’

Check warning on line 326 in Modules/mmapmodule.c

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test

unused variable ‘record’ [-Wunused-variable]

Check failure on line 326 in Modules/mmapmodule.c

View workflow job for this annotation

GitHub Actions / Ubuntu SSL tests with OpenSSL (3.1.5)

unknown type name ‘EXCEPTION_RECORD’

Check warning on line 326 in Modules/mmapmodule.c

View workflow job for this annotation

GitHub Actions / Ubuntu SSL tests with OpenSSL (3.1.5)

unused variable ‘record’ [-Wunused-variable]

Check failure on line 326 in Modules/mmapmodule.c

View workflow job for this annotation

GitHub Actions / Ubuntu SSL tests with OpenSSL (1.1.1w)

unknown type name ‘EXCEPTION_RECORD’

Check warning on line 326 in Modules/mmapmodule.c

View workflow job for this annotation

GitHub Actions / Ubuntu SSL tests with OpenSSL (1.1.1w)

unused variable ‘record’ [-Wunused-variable]
__try {

Check failure on line 327 in Modules/mmapmodule.c

View workflow job for this annotation

GitHub Actions / Hypothesis tests on Ubuntu

‘__try’ undeclared (first use in this function)

Check failure on line 327 in Modules/mmapmodule.c

View workflow job for this annotation

GitHub Actions / Hypothesis tests on Ubuntu

expected ‘;’ before ‘{’ token

Check failure on line 327 in Modules/mmapmodule.c

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test

‘__try’ undeclared (first use in this function)

Check failure on line 327 in Modules/mmapmodule.c

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test

expected ‘;’ before ‘{’ token

Check failure on line 327 in Modules/mmapmodule.c

View workflow job for this annotation

GitHub Actions / Ubuntu SSL tests with OpenSSL (3.2.1)

‘__try’ undeclared (first use in this function)

Check failure on line 327 in Modules/mmapmodule.c

View workflow job for this annotation

GitHub Actions / Ubuntu SSL tests with OpenSSL (3.2.1)

expected ‘;’ before ‘{’ token

Check failure on line 327 in Modules/mmapmodule.c

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test

‘__try’ undeclared (first use in this function)

Check failure on line 327 in Modules/mmapmodule.c

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test

expected ‘;’ before ‘{’ token

Check failure on line 327 in Modules/mmapmodule.c

View workflow job for this annotation

GitHub Actions / Ubuntu SSL tests with OpenSSL (3.1.5)

‘__try’ undeclared (first use in this function)

Check failure on line 327 in Modules/mmapmodule.c

View workflow job for this annotation

GitHub Actions / Ubuntu SSL tests with OpenSSL (3.1.5)

expected ‘;’ before ‘{’ token

Check failure on line 327 in Modules/mmapmodule.c

View workflow job for this annotation

GitHub Actions / Ubuntu SSL tests with OpenSSL (1.1.1w)

‘__try’ undeclared (first use in this function)

Check failure on line 327 in Modules/mmapmodule.c

View workflow job for this annotation

GitHub Actions / Ubuntu SSL tests with OpenSSL (1.1.1w)

expected ‘;’ before ‘{’ token
result = PyBytes_FromStringAndSize(&self->data[self->pos], num_bytes);
self->pos += num_bytes;
}
__except (HandlePageException(GetExceptionInformation(), &record)) {
NTSTATUS code = record.ExceptionInformation[2];
PyErr_SetFromWindowsErr(code);
result = NULL;
}
#endif

return result;
}

Check warning on line 339 in Modules/mmapmodule.c

View workflow job for this annotation

GitHub Actions / Hypothesis tests on Ubuntu

control reaches end of non-void function [-Wreturn-type]

Check warning on line 339 in Modules/mmapmodule.c

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test

control reaches end of non-void function [-Wreturn-type]

Check warning on line 339 in Modules/mmapmodule.c

View workflow job for this annotation

GitHub Actions / Ubuntu SSL tests with OpenSSL (3.2.1)

control reaches end of non-void function [-Wreturn-type]

Check warning on line 339 in Modules/mmapmodule.c

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test

control reaches end of non-void function [-Wreturn-type]

Check warning on line 339 in Modules/mmapmodule.c

View workflow job for this annotation

GitHub Actions / Ubuntu SSL tests with OpenSSL (3.1.5)

control reaches end of non-void function [-Wreturn-type]

Check warning on line 339 in Modules/mmapmodule.c

View workflow job for this annotation

GitHub Actions / Ubuntu SSL tests with OpenSSL (1.1.1w)

control reaches end of non-void function [-Wreturn-type]

Expand Down

0 comments on commit d858720

Please sign in to comment.