Skip to content

Commit f58cd7d

Browse files
committed
Use Py_RETURN_NONE macro when possible
1 parent e972962 commit f58cd7d

File tree

10 files changed

+83
-166
lines changed

10 files changed

+83
-166
lines changed

src/_imaging.c

Lines changed: 31 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,7 @@ getpixel(Imaging im, ImagingAccess access, int x, int y) {
441441
}
442442

443443
/* unknown type */
444-
Py_INCREF(Py_None);
445-
return Py_None;
444+
Py_RETURN_NONE;
446445
}
447446

448447
static char *
@@ -933,8 +932,7 @@ _convert2(ImagingObject *self, PyObject *args) {
933932
return NULL;
934933
}
935934

936-
Py_INCREF(Py_None);
937-
return Py_None;
935+
Py_RETURN_NONE;
938936
}
939937

940938
static PyObject *
@@ -1182,8 +1180,7 @@ _getpixel(ImagingObject *self, PyObject *args) {
11821180
}
11831181

11841182
if (self->access == NULL) {
1185-
Py_INCREF(Py_None);
1186-
return Py_None;
1183+
Py_RETURN_NONE;
11871184
}
11881185

11891186
return getpixel(self->image, self->access, x, y);
@@ -1385,8 +1382,7 @@ _paste(ImagingObject *self, PyObject *args) {
13851382
return NULL;
13861383
}
13871384

1388-
Py_INCREF(Py_None);
1389-
return Py_None;
1385+
Py_RETURN_NONE;
13901386
}
13911387

13921388
static PyObject *
@@ -1663,8 +1659,7 @@ _putdata(ImagingObject *self, PyObject *args) {
16631659

16641660
Py_XDECREF(seq);
16651661

1666-
Py_INCREF(Py_None);
1667-
return Py_None;
1662+
Py_RETURN_NONE;
16681663
}
16691664

16701665
static PyObject *
@@ -1724,8 +1719,7 @@ _putpalette(ImagingObject *self, PyObject *args) {
17241719
self->image->palette->size = palettesize * 8 / bits;
17251720
unpack(self->image->palette->palette, palette, self->image->palette->size);
17261721

1727-
Py_INCREF(Py_None);
1728-
return Py_None;
1722+
Py_RETURN_NONE;
17291723
}
17301724

17311725
static PyObject *
@@ -1749,8 +1743,7 @@ _putpalettealpha(ImagingObject *self, PyObject *args) {
17491743
strcpy(self->image->palette->mode, "RGBA");
17501744
self->image->palette->palette[index * 4 + 3] = (UINT8)alpha;
17511745

1752-
Py_INCREF(Py_None);
1753-
return Py_None;
1746+
Py_RETURN_NONE;
17541747
}
17551748

17561749
static PyObject *
@@ -1777,8 +1770,7 @@ _putpalettealphas(ImagingObject *self, PyObject *args) {
17771770
self->image->palette->palette[i * 4 + 3] = (UINT8)values[i];
17781771
}
17791772

1780-
Py_INCREF(Py_None);
1781-
return Py_None;
1773+
Py_RETURN_NONE;
17821774
}
17831775

17841776
static PyObject *
@@ -1814,8 +1806,7 @@ _putpixel(ImagingObject *self, PyObject *args) {
18141806
self->access->put_pixel(im, x, y, ink);
18151807
}
18161808

1817-
Py_INCREF(Py_None);
1818-
return Py_None;
1809+
Py_RETURN_NONE;
18191810
}
18201811

18211812
static PyObject *
@@ -1982,8 +1973,7 @@ im_setmode(ImagingObject *self, PyObject *args) {
19821973
}
19831974
self->access = ImagingAccessNew(im);
19841975

1985-
Py_INCREF(Py_None);
1986-
return Py_None;
1976+
Py_RETURN_NONE;
19871977
}
19881978

19891979
static PyObject *
@@ -2046,8 +2036,7 @@ _transform(ImagingObject *self, PyObject *args) {
20462036
return NULL;
20472037
}
20482038

2049-
Py_INCREF(Py_None);
2050-
return Py_None;
2039+
Py_RETURN_NONE;
20512040
}
20522041

20532042
static PyObject *
@@ -2174,8 +2163,7 @@ _getbbox(ImagingObject *self, PyObject *args) {
21742163
}
21752164

21762165
if (!ImagingGetBBox(self->image, bbox, alpha_only)) {
2177-
Py_INCREF(Py_None);
2178-
return Py_None;
2166+
Py_RETURN_NONE;
21792167
}
21802168

21812169
return Py_BuildValue("iiii", bbox[0], bbox[1], bbox[2], bbox[3]);
@@ -2255,8 +2243,7 @@ _getextrema(ImagingObject *self) {
22552243
}
22562244
}
22572245

2258-
Py_INCREF(Py_None);
2259-
return Py_None;
2246+
Py_RETURN_NONE;
22602247
}
22612248

22622249
static PyObject *
@@ -2319,8 +2306,7 @@ _fillband(ImagingObject *self, PyObject *args) {
23192306
return NULL;
23202307
}
23212308

2322-
Py_INCREF(Py_None);
2323-
return Py_None;
2309+
Py_RETURN_NONE;
23242310
}
23252311

23262312
static PyObject *
@@ -2335,8 +2321,7 @@ _putband(ImagingObject *self, PyObject *args) {
23352321
return NULL;
23362322
}
23372323

2338-
Py_INCREF(Py_None);
2339-
return Py_None;
2324+
Py_RETURN_NONE;
23402325
}
23412326

23422327
static PyObject *
@@ -2922,8 +2907,7 @@ _draw_arc(ImagingDrawObject *self, PyObject *args) {
29222907
return NULL;
29232908
}
29242909

2925-
Py_INCREF(Py_None);
2926-
return Py_None;
2910+
Py_RETURN_NONE;
29272911
}
29282912

29292913
static PyObject *
@@ -2960,8 +2944,7 @@ _draw_bitmap(ImagingDrawObject *self, PyObject *args) {
29602944
return NULL;
29612945
}
29622946

2963-
Py_INCREF(Py_None);
2964-
return Py_None;
2947+
Py_RETURN_NONE;
29652948
}
29662949

29672950
static PyObject *
@@ -3017,8 +3000,7 @@ _draw_chord(ImagingDrawObject *self, PyObject *args) {
30173000
return NULL;
30183001
}
30193002

3020-
Py_INCREF(Py_None);
3021-
return Py_None;
3003+
Py_RETURN_NONE;
30223004
}
30233005

30243006
static PyObject *
@@ -3072,8 +3054,7 @@ _draw_ellipse(ImagingDrawObject *self, PyObject *args) {
30723054
return NULL;
30733055
}
30743056

3075-
Py_INCREF(Py_None);
3076-
return Py_None;
3057+
Py_RETURN_NONE;
30773058
}
30783059

30793060
static PyObject *
@@ -3136,8 +3117,7 @@ _draw_lines(ImagingDrawObject *self, PyObject *args) {
31363117

31373118
free(xy);
31383119

3139-
Py_INCREF(Py_None);
3140-
return Py_None;
3120+
Py_RETURN_NONE;
31413121
}
31423122

31433123
static PyObject *
@@ -3168,8 +3148,7 @@ _draw_points(ImagingDrawObject *self, PyObject *args) {
31683148

31693149
free(xy);
31703150

3171-
Py_INCREF(Py_None);
3172-
return Py_None;
3151+
Py_RETURN_NONE;
31733152
}
31743153

31753154
/* from outline.c */
@@ -3197,8 +3176,7 @@ _draw_outline(ImagingDrawObject *self, PyObject *args) {
31973176
return NULL;
31983177
}
31993178

3200-
Py_INCREF(Py_None);
3201-
return Py_None;
3179+
Py_RETURN_NONE;
32023180
}
32033181

32043182
static PyObject *
@@ -3254,8 +3232,7 @@ _draw_pieslice(ImagingDrawObject *self, PyObject *args) {
32543232
return NULL;
32553233
}
32563234

3257-
Py_INCREF(Py_None);
3258-
return Py_None;
3235+
Py_RETURN_NONE;
32593236
}
32603237

32613238
static PyObject *
@@ -3306,8 +3283,7 @@ _draw_polygon(ImagingDrawObject *self, PyObject *args) {
33063283

33073284
free(ixy);
33083285

3309-
Py_INCREF(Py_None);
3310-
return Py_None;
3286+
Py_RETURN_NONE;
33113287
}
33123288

33133289
static PyObject *
@@ -3361,8 +3337,7 @@ _draw_rectangle(ImagingDrawObject *self, PyObject *args) {
33613337
return NULL;
33623338
}
33633339

3364-
Py_INCREF(Py_None);
3365-
return Py_None;
3340+
Py_RETURN_NONE;
33663341
}
33673342

33683343
static struct PyMethodDef _draw_methods[] = {
@@ -3567,8 +3542,7 @@ _save_ppm(ImagingObject *self, PyObject *args) {
35673542
return NULL;
35683543
}
35693544

3570-
Py_INCREF(Py_None);
3571-
return Py_None;
3545+
Py_RETURN_NONE;
35723546
}
35733547

35743548
/* -------------------------------------------------------------------- */
@@ -3935,8 +3909,7 @@ _reset_stats(PyObject *self, PyObject *args) {
39353909
arena->stats_freed_blocks = 0;
39363910
MUTEX_UNLOCK(&ImagingDefaultArena.mutex);
39373911

3938-
Py_INCREF(Py_None);
3939-
return Py_None;
3912+
Py_RETURN_NONE;
39403913
}
39413914

39423915
static PyObject *
@@ -3996,8 +3969,7 @@ _set_alignment(PyObject *self, PyObject *args) {
39963969
ImagingDefaultArena.alignment = alignment;
39973970
MUTEX_UNLOCK(&ImagingDefaultArena.mutex);
39983971

3999-
Py_INCREF(Py_None);
4000-
return Py_None;
3972+
Py_RETURN_NONE;
40013973
}
40023974

40033975
static PyObject *
@@ -4021,8 +3993,7 @@ _set_block_size(PyObject *self, PyObject *args) {
40213993
ImagingDefaultArena.block_size = block_size;
40223994
MUTEX_UNLOCK(&ImagingDefaultArena.mutex);
40233995

4024-
Py_INCREF(Py_None);
4025-
return Py_None;
3996+
Py_RETURN_NONE;
40263997
}
40273998

40283999
static PyObject *
@@ -4050,8 +4021,7 @@ _set_blocks_max(PyObject *self, PyObject *args) {
40504021
return ImagingError_MemoryError();
40514022
}
40524023

4053-
Py_INCREF(Py_None);
4054-
return Py_None;
4024+
Py_RETURN_NONE;
40554025
}
40564026

40574027
static PyObject *
@@ -4066,8 +4036,7 @@ _clear_cache(PyObject *self, PyObject *args) {
40664036
ImagingMemoryClearCache(&ImagingDefaultArena, i);
40674037
MUTEX_UNLOCK(&ImagingDefaultArena.mutex);
40684038

4069-
Py_INCREF(Py_None);
4070-
return Py_None;
4039+
Py_RETURN_NONE;
40714040
}
40724041

40734042
/* -------------------------------------------------------------------- */

0 commit comments

Comments
 (0)