Skip to content

Commit 416b7a8

Browse files
authored
PySequence_Fast raises its own TypeError (#9921)
2 parents c761a6b + 2d82017 commit 416b7a8

11 files changed

Lines changed: 21 additions & 35 deletions

File tree

Tests/test_image_access.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def test_embeddable(self) -> None:
283283
with open("embed_pil.c", "w", encoding="utf-8") as fh:
284284
home = sys.prefix.replace("\\", "\\\\")
285285
fh.write(f"""
286-
#include "Python.h"
286+
#include <Python.h>
287287
288288
int main(int argc, char* argv[])
289289
{{

src/_imaging.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ _radial_gradient(PyObject *self, PyObject *args) {
787787
}
788788

789789
static PyObject *
790-
_alpha_composite(ImagingObject *self, PyObject *args) {
790+
_alpha_composite(PyObject *self, PyObject *args) {
791791
ImagingObject *imagep1;
792792
ImagingObject *imagep2;
793793

@@ -801,7 +801,7 @@ _alpha_composite(ImagingObject *self, PyObject *args) {
801801
}
802802

803803
static PyObject *
804-
_blend(ImagingObject *self, PyObject *args) {
804+
_blend(PyObject *self, PyObject *args) {
805805
ImagingObject *imagep1;
806806
ImagingObject *imagep2;
807807
double alpha;
@@ -1670,7 +1670,6 @@ _putdata(ImagingObject *self, PyObject *args) {
16701670
} else {
16711671
seq = PySequence_Fast(data, must_be_sequence);
16721672
if (!seq) {
1673-
PyErr_SetString(PyExc_TypeError, must_be_sequence);
16741673
return NULL;
16751674
}
16761675
double value;
@@ -1708,7 +1707,6 @@ _putdata(ImagingObject *self, PyObject *args) {
17081707
/* 32-bit images */
17091708
seq = PySequence_Fast(data, must_be_sequence);
17101709
if (!seq) {
1711-
PyErr_SetString(PyExc_TypeError, must_be_sequence);
17121710
return NULL;
17131711
}
17141712
switch (image->type) {

src/_imagingcms.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ kevin@cazabon.com\n\
3434
#include <lcms2.h>
3535
#include "libImaging/Imaging.h"
3636

37-
#define PYCMSVERSION "1.0.0 pil"
38-
3937
/* version history */
4038

4139
/*

src/_imagingmath.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363
#define SUB(type, v1, v2) (v1) - (v2)
6464
#define MUL(type, v1, v2) (v1) * (v2)
6565

66-
#define MIN(type, v1, v2) ((v1) < (v2)) ? (v1) : (v2)
67-
#define MAX(type, v1, v2) ((v1) > (v2)) ? (v1) : (v2)
66+
#define MINOP(type, v1, v2) ((v1) < (v2)) ? (v1) : (v2)
67+
#define MAXOP(type, v1, v2) ((v1) > (v2)) ? (v1) : (v2)
6868

6969
#define AND(type, v1, v2) (v1) & (v2)
7070
#define OR(type, v1, v2) (v1) | (v2)
@@ -134,8 +134,8 @@ BINOP(xor_I, XOR, INT32)
134134
BINOP(lshift_I, LSHIFT, INT32)
135135
BINOP(rshift_I, RSHIFT, INT32)
136136

137-
BINOP(min_I, MIN, INT32)
138-
BINOP(max_I, MAX, INT32)
137+
BINOP(min_I, MINOP, INT32)
138+
BINOP(max_I, MAXOP, INT32)
139139

140140
BINOP(eq_I, EQ, INT32)
141141
BINOP(ne_I, NE, INT32)
@@ -155,8 +155,8 @@ BINOP(mod_F, MOD_F, FLOAT32)
155155
BINOP(pow_F, POW_F, FLOAT32)
156156
BINOP(diff_F, DIFF_F, FLOAT32)
157157

158-
BINOP(min_F, MIN, FLOAT32)
159-
BINOP(max_F, MAX, FLOAT32)
158+
BINOP(min_F, MINOP, FLOAT32)
159+
BINOP(max_F, MAXOP, FLOAT32)
160160

161161
BINOP(eq_F, EQ, FLOAT32)
162162
BINOP(ne_F, NE, FLOAT32)

src/libImaging/BoxBlur.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#include "Imaging.h"
22

3-
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
4-
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
5-
63
typedef UINT8 pixel[4];
74

85
void static inline ImagingLineBoxBlur32(

src/libImaging/Convert.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@
3434

3535
#include "Imaging.h"
3636

37-
#define MAX(a, b) (a) > (b) ? (a) : (b)
38-
#define MIN(a, b) (a) < (b) ? (a) : (b)
39-
4037
/* ITU-R Recommendation 601-2 (assuming nonlinear RGB) */
4138
#define L(rgb) ((INT32)(rgb)[0] * 299 + (INT32)(rgb)[1] * 587 + (INT32)(rgb)[2] * 114)
4239
#define L24(rgb) ((rgb)[0] * 19595 + (rgb)[1] * 38470 + (rgb)[2] * 7471 + 0x8000)

src/libImaging/ImagingUtils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
#define MASK_UINT32_CHANNEL_3 0xff000000
1515
#endif
1616

17+
#define MAX(a, b) (a > b ? a : b)
18+
#define MIN(a, b) (a < b ? a : b)
19+
1720
#define SHIFTFORDIV255(a) ((((a) >> 8) + a) >> 8)
1821

1922
/* like (a * b + 127) / 255), but much faster on most platforms */

src/libImaging/QuantOctree.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ typedef struct _ColorCube {
4949
ColorBucket buckets;
5050
} *ColorCube;
5151

52-
#define MAX(a, b) (a) > (b) ? (a) : (b)
53-
5452
static ColorCube
5553
new_color_cube(int r, int g, int b, int a) {
5654
ColorCube cube;

src/libImaging/QuantPngQuant.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "QuantPngQuant.h"
1616

1717
#ifdef HAVE_LIBIMAGEQUANT
18-
#include "libimagequant.h"
18+
#include <libimagequant.h>
1919

2020
int
2121
quantize_pngquant(

src/libImaging/TiffDecode.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ _tiffReadProc(thandle_t hdata, tdata_t buf, tsize_t size) {
6969
);
7070
return 0;
7171
}
72-
to_read = min(size, min(state->size, (tsize_t)state->eof) - (tsize_t)state->loc);
72+
to_read = MIN(size, MIN(state->size, (tsize_t)state->eof) - (tsize_t)state->loc);
7373
TRACE(("to_read: %d\n", (int)to_read));
7474

7575
_TIFFmemcpy(buf, (UINT8 *)state->data + state->loc, to_read);
@@ -87,7 +87,7 @@ _tiffWriteProc(thandle_t hdata, tdata_t buf, tsize_t size) {
8787
TRACE(("_tiffWriteProc: %d \n", (int)size));
8888
dump_state(state);
8989

90-
to_write = min(size, state->size - (tsize_t)state->loc);
90+
to_write = MIN(size, state->size - (tsize_t)state->loc);
9191
if (state->flrealloc && size > to_write) {
9292
tdata_t new_data;
9393
tsize_t newsize = state->size;
@@ -114,7 +114,7 @@ _tiffWriteProc(thandle_t hdata, tdata_t buf, tsize_t size) {
114114

115115
_TIFFmemcpy((UINT8 *)state->data + state->loc, buf, to_write);
116116
state->loc += (toff_t)to_write;
117-
state->eof = max(state->loc, state->eof);
117+
state->eof = MAX(state->loc, state->eof);
118118

119119
dump_state(state);
120120
return to_write;
@@ -346,7 +346,7 @@ _decodeAsRGBA(Imaging im, ImagingCodecState state, TIFF *tiff) {
346346

347347
for (; state->y < state->ysize; state->y += rows_per_block) {
348348
img.row_offset = state->y;
349-
rows_to_read = min(rows_per_block, img.height - state->y);
349+
rows_to_read = MIN(rows_per_block, img.height - state->y);
350350

351351
if (!TIFFRGBAImageGet(&img, (UINT32 *)state->buffer, img.width, rows_to_read)) {
352352
TRACE(("Decode Error, y: %d\n", state->y));
@@ -362,7 +362,7 @@ _decodeAsRGBA(Imaging im, ImagingCodecState state, TIFF *tiff) {
362362

363363
// iterate over each row in the strip and stuff data into image
364364
for (current_row = 0;
365-
current_row < min((INT32)rows_per_block, state->ysize - state->y);
365+
current_row < MIN((INT32)rows_per_block, state->ysize - state->y);
366366
current_row++) {
367367
TRACE(("Writing data into line %d ; \n", state->y + current_row));
368368

@@ -465,8 +465,8 @@ _decodeTile(
465465

466466
TRACE(("Read tile at %dx%d; \n\n", x, y));
467467

468-
current_tile_width = min((INT32)tile_width, state->xsize - x);
469-
current_tile_length = min((INT32)tile_length, state->ysize - y);
468+
current_tile_width = MIN((INT32)tile_width, state->xsize - x);
469+
current_tile_length = MIN((INT32)tile_length, state->ysize - y);
470470
// iterate over each line in the tile and stuff data into image
471471
for (tile_y = 0; tile_y < current_tile_length; tile_y++) {
472472
TRACE(
@@ -580,7 +580,7 @@ _decodeStrip(
580580

581581
// iterate over each row in the strip and stuff data into image
582582
for (strip_row = 0;
583-
strip_row < min((INT32)rows_per_strip, state->ysize - state->y);
583+
strip_row < MIN((INT32)rows_per_strip, state->ysize - state->y);
584584
strip_row++) {
585585
TRACE(("Writing data into line %d ; \n", state->y + strip_row));
586586

0 commit comments

Comments
 (0)