move ImagingNewEpilogue functionality to ImagingNewPrologueSubtype

doublechecked: no im->image or im->image8 or im->image32 access
between ImagingNewPrologue and ImagingNewEpilogue anywhere
This commit is contained in:
Alexander 2017-08-05 20:39:14 +03:00
parent fd9cf03d01
commit ab92adf7c9
3 changed files with 15 additions and 26 deletions

View File

@ -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);

View File

@ -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)
{
@ -314,7 +310,6 @@ ImagingNewArray(const char *mode, int xsize, int ysize)
}
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;
}

7
map.c
View File

@ -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);
}