Simplify C error handling (#9021)

This commit is contained in:
Hugo van Kemenade 2025-06-16 13:01:46 +03:00 committed by GitHub
commit ef683e9d78
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 2 additions and 17 deletions

View File

@ -338,12 +338,6 @@ static const char *no_palette = "image has no palette";
static const char *readonly = "image is readonly"; static const char *readonly = "image is readonly";
/* static const char* no_content = "image has no content"; */ /* static const char* no_content = "image has no content"; */
void *
ImagingError_OSError(void) {
PyErr_SetString(PyExc_OSError, "error when accessing file");
return NULL;
}
void * void *
ImagingError_MemoryError(void) { ImagingError_MemoryError(void) {
return PyErr_NoMemory(); return PyErr_NoMemory();
@ -369,11 +363,6 @@ ImagingError_ValueError(const char *message) {
return NULL; return NULL;
} }
void
ImagingError_Clear(void) {
PyErr_Clear();
}
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* HELPERS */ /* HELPERS */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */

View File

@ -54,7 +54,7 @@ ImagingSavePPM(Imaging im, const char *outfile) {
fp = fopen(outfile, "wb"); fp = fopen(outfile, "wb");
if (!fp) { if (!fp) {
(void)ImagingError_OSError(); PyErr_SetString(PyExc_OSError, "error when accessing file");
return 0; return 0;
} }

View File

@ -270,8 +270,6 @@ ImagingSectionLeave(ImagingSectionCookie *cookie);
/* Exceptions */ /* Exceptions */
/* ---------- */ /* ---------- */
extern void *
ImagingError_OSError(void);
extern void * extern void *
ImagingError_MemoryError(void); ImagingError_MemoryError(void);
extern void * extern void *
@ -280,8 +278,6 @@ extern void *
ImagingError_Mismatch(void); /* maps to ValueError by default */ ImagingError_Mismatch(void); /* maps to ValueError by default */
extern void * extern void *
ImagingError_ValueError(const char *message); ImagingError_ValueError(const char *message);
extern void
ImagingError_Clear(void);
/* Transform callbacks */ /* Transform callbacks */
/* ------------------- */ /* ------------------- */

View File

@ -645,7 +645,7 @@ ImagingNewInternal(const char *mode, int xsize, int ysize, int dirty) {
return im; return im;
} }
ImagingError_Clear(); PyErr_Clear();
// Try to allocate the image once more with smallest possible block size // Try to allocate the image once more with smallest possible block size
MUTEX_LOCK(&ImagingDefaultArena.mutex); MUTEX_LOCK(&ImagingDefaultArena.mutex);