From ab92adf7c96f80790ee661d8a56c73bc63247f09 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sat, 5 Aug 2017 20:39:14 +0300 Subject: [PATCH] move ImagingNewEpilogue functionality to ImagingNewPrologueSubtype doublechecked: no im->image or im->image8 or im->image32 access between ImagingNewPrologue and ImagingNewEpilogue anywhere --- libImaging/Imaging.h | 1 - libImaging/Storage.c | 33 ++++++++++++++------------------- map.c | 7 +------ 3 files changed, 15 insertions(+), 26 deletions(-) diff --git a/libImaging/Imaging.h b/libImaging/Imaging.h index 086a7dc6d..ede35f74c 100644 --- a/libImaging/Imaging.h +++ b/libImaging/Imaging.h @@ -172,7 +172,6 @@ extern Imaging ImagingNewPrologue(const char *mode, extern Imaging ImagingNewPrologueSubtype(const char *mode, int xsize, int ysize, int structure_size); -extern void ImagingNewEpilogue(Imaging im); extern void ImagingCopyInfo(Imaging destination, Imaging source); diff --git a/libImaging/Storage.c b/libImaging/Storage.c index 640211e33..5cddfd66c 100644 --- a/libImaging/Storage.c +++ b/libImaging/Storage.c @@ -215,11 +215,21 @@ ImagingNewPrologueSubtype(const char *mode, int xsize, int ysize, int size) exceptions on platforms where calloc(0, x) returns NULL) */ im->image = (char **) calloc((ysize > 0) ? ysize : 1, sizeof(void *)); - if (!im->image) { + if ( ! im->image) { free(im); return (Imaging) ImagingError_MemoryError(); } + /* Initialize alias pointers to pixel data. */ + switch (im->pixelsize) { + case 1: case 2: case 3: + im->image8 = (UINT8 **) im->image; + break; + case 4: + im->image32 = (INT32 **) im->image; + break; + } + ImagingNewCount++; return im; @@ -232,20 +242,6 @@ ImagingNewPrologue(const char *mode, int xsize, int ysize) mode, xsize, ysize, sizeof(struct ImagingMemoryInstance)); } -void -ImagingNewEpilogue(Imaging im) -{ - /* Initialize alias pointers to pixel data. */ - switch (im->pixelsize) { - case 1: case 2: case 3: - im->image8 = (UINT8 **) im->image; - break; - case 4: - im->image32 = (INT32 **) im->image; - break; - } -} - void ImagingDelete(Imaging im) { @@ -312,9 +308,8 @@ ImagingNewArray(const char *mode, int xsize, int ysize) ImagingDelete(im); return (Imaging) ImagingError_MemoryError(); } - + im->destroy = ImagingDestroyArray; - ImagingNewEpilogue(im); return im; } @@ -338,8 +333,9 @@ ImagingNewBlock(const char *mode, int xsize, int ysize) Py_ssize_t y, i; im = ImagingNewPrologue(mode, xsize, ysize); - if (!im) + if ( ! im) { return NULL; + } /* We shouldn't overflow, since the threshold defined below says that we're only going to allocate max 4M @@ -372,7 +368,6 @@ ImagingNewBlock(const char *mode, int xsize, int ysize) } im->destroy = ImagingDestroyBlock; - ImagingNewEpilogue(im); return im; } diff --git a/map.c b/map.c index 8c36660d0..76b316012 100644 --- a/map.c +++ b/map.c @@ -229,8 +229,6 @@ mapping_readimage(ImagingMapperObject* mapper, PyObject* args) im->destroy = ImagingDestroyMap; - ImagingNewEpilogue(im); - mapper->offset += size; return PyImagingNew(im); @@ -367,8 +365,7 @@ PyImaging_MapBuffer(PyObject* self, PyObject* args) } im = ImagingNewPrologueSubtype( - mode, xsize, ysize, sizeof(ImagingBufferInstance) - ); + mode, xsize, ysize, sizeof(ImagingBufferInstance)); if (!im) return NULL; @@ -386,8 +383,6 @@ PyImaging_MapBuffer(PyObject* self, PyObject* args) ((ImagingBufferInstance*) im)->target = target; ((ImagingBufferInstance*) im)->view = view; - ImagingNewEpilogue(im); - return PyImagingNew(im); }