Skip to content

Commit e296e3f

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent fdd8016 commit e296e3f

File tree

2 files changed

+36
-31
lines changed

2 files changed

+36
-31
lines changed

src/libImaging/Imaging.h

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@ extern "C" {
5252
*/
5353

5454
#ifdef Py_GIL_DISABLED
55-
#if defined(__cplusplus)
56-
#define IMAGING_TLS thread_local
57-
#elif defined(HAVE_THREAD_LOCAL)
58-
#define IMAGING_TLS thread_local
59-
#elif defined(HAVE__THREAD_LOCAL)
60-
#define IMAGING_TLS _Thread_local
61-
#elif defined(HAVE___THREAD)
62-
#define IMAGING_TLS __thread
63-
#elif defined(HAVE___DECLSPEC_THREAD_)
64-
#define IMAGING_TLS __declspec(thread)
65-
#endif
55+
#if defined(__cplusplus)
56+
#define IMAGING_TLS thread_local
57+
#elif defined(HAVE_THREAD_LOCAL)
58+
#define IMAGING_TLS thread_local
59+
#elif defined(HAVE__THREAD_LOCAL)
60+
#define IMAGING_TLS _Thread_local
61+
#elif defined(HAVE___THREAD)
62+
#define IMAGING_TLS __thread
63+
#elif defined(HAVE___DECLSPEC_THREAD_)
64+
#define IMAGING_TLS __declspec(thread)
65+
#endif
6666
#endif
6767

6868
/* Handles */
@@ -200,8 +200,9 @@ extern struct ImagingMemoryArena ImagingArenas[IMAGING_ARENAS_COUNT];
200200
/* Provide a macro that loops through each arena that has been
201201
* statically-allocated. This is necessary to properly handle stats.
202202
*/
203-
#define IMAGING_ARENAS_FOREACH(index, arena) \
204-
for (index = 0, (arena) = &ImagingArenas[index]; index < IMAGING_ARENAS_COUNT; (arena) = &ImagingArenas[++index])
203+
#define IMAGING_ARENAS_FOREACH(index, arena) \
204+
for (index = 0, (arena) = &ImagingArenas[index]; index < IMAGING_ARENAS_COUNT; \
205+
(arena) = &ImagingArenas[++index])
205206
#else
206207
/* In this case we either have the GIL or do not have thread-local storage, in
207208
* which case we will only allocate a single arena.
@@ -213,10 +214,11 @@ extern struct ImagingMemoryArena ImagingDefaultArena;
213214
* effectively a single block of code.
214215
*/
215216
#define IMAGING_ARENAS_FOREACH(index, arena) \
216-
for ((void) index, (arena) = &ImagingDefaultArena; (arena); (arena) = NULL)
217+
for ((void)index, (arena) = &ImagingDefaultArena; (arena); (arena) = NULL)
217218
#endif
218219

219-
ImagingMemoryArena ImagingGetArena(void);
220+
ImagingMemoryArena
221+
ImagingGetArena(void);
220222

221223
extern int
222224
ImagingMemorySetBlocksMax(ImagingMemoryArena arena, int blocks_max);

src/libImaging/Storage.c

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -274,31 +274,34 @@ static IMAGING_TLS uint64_t ImagingArenaThreadIndex = UINT64_MAX;
274274

275275
/* These are the statically-allocated arenas. */
276276
struct ImagingMemoryArena ImagingArenas[IMAGING_ARENAS_COUNT] = {
277-
{ 1, IMAGING_ARENA_BLOCK_SIZE, 0, 0, NULL, 0, 0, 0, 0, 0, 0, {0} },
278-
{ 1, IMAGING_ARENA_BLOCK_SIZE, 0, 0, NULL, 0, 0, 0, 0, 0, 1, {0} },
279-
{ 1, IMAGING_ARENA_BLOCK_SIZE, 0, 0, NULL, 0, 0, 0, 0, 0, 2, {0} },
280-
{ 1, IMAGING_ARENA_BLOCK_SIZE, 0, 0, NULL, 0, 0, 0, 0, 0, 3, {0} },
281-
{ 1, IMAGING_ARENA_BLOCK_SIZE, 0, 0, NULL, 0, 0, 0, 0, 0, 4, {0} },
282-
{ 1, IMAGING_ARENA_BLOCK_SIZE, 0, 0, NULL, 0, 0, 0, 0, 0, 5, {0} },
283-
{ 1, IMAGING_ARENA_BLOCK_SIZE, 0, 0, NULL, 0, 0, 0, 0, 0, 6, {0} },
284-
{ 1, IMAGING_ARENA_BLOCK_SIZE, 0, 0, NULL, 0, 0, 0, 0, 0, 7, {0} }
277+
{1, IMAGING_ARENA_BLOCK_SIZE, 0, 0, NULL, 0, 0, 0, 0, 0, 0, {0}},
278+
{1, IMAGING_ARENA_BLOCK_SIZE, 0, 0, NULL, 0, 0, 0, 0, 0, 1, {0}},
279+
{1, IMAGING_ARENA_BLOCK_SIZE, 0, 0, NULL, 0, 0, 0, 0, 0, 2, {0}},
280+
{1, IMAGING_ARENA_BLOCK_SIZE, 0, 0, NULL, 0, 0, 0, 0, 0, 3, {0}},
281+
{1, IMAGING_ARENA_BLOCK_SIZE, 0, 0, NULL, 0, 0, 0, 0, 0, 4, {0}},
282+
{1, IMAGING_ARENA_BLOCK_SIZE, 0, 0, NULL, 0, 0, 0, 0, 0, 5, {0}},
283+
{1, IMAGING_ARENA_BLOCK_SIZE, 0, 0, NULL, 0, 0, 0, 0, 0, 6, {0}},
284+
{1, IMAGING_ARENA_BLOCK_SIZE, 0, 0, NULL, 0, 0, 0, 0, 0, 7, {0}}
285285
};
286286

287287
/* Get a pointer to the correct arena for this context. In this case where we
288288
* are using a round-robin approach to the statically allocated arenas, we will
289289
* return the arena that is assigned to the thread on first use.
290290
*/
291-
ImagingMemoryArena ImagingGetArena(void) {
291+
ImagingMemoryArena
292+
ImagingGetArena(void) {
292293
if (ImagingArenaThreadIndex == UINT64_MAX) {
293-
ImagingArenaThreadIndex = _Py_atomic_add_uint64(&ImagingArenaIndex, 1) % IMAGING_ARENAS_COUNT;
294+
ImagingArenaThreadIndex =
295+
_Py_atomic_add_uint64(&ImagingArenaIndex, 1) % IMAGING_ARENAS_COUNT;
294296
}
295297
return &ImagingArenas[ImagingArenaThreadIndex];
296298
}
297299

298300
/* Return the arena associated with the given image. In this case the index of
299301
* the arena is stored on the image itself.
300302
*/
301-
ImagingMemoryArena ImagingGetArenaFromImaging(Imaging im) {
303+
ImagingMemoryArena
304+
ImagingGetArenaFromImaging(Imaging im) {
302305
int arenaindex = im->arenaindex;
303306
assert(arenaindex >= 0 && arenaindex < IMAGING_ARENAS_COUNT);
304307
return &ImagingArenas[arenaindex];
@@ -308,7 +311,8 @@ ImagingMemoryArena ImagingGetArenaFromImaging(Imaging im) {
308311
* is necessary in order to return the blocks to the correct arena when the
309312
* image is destroyed.
310313
*/
311-
static void ImagingSetArenaOnImaging(Imaging im, ImagingMemoryArena arena) {
314+
static void
315+
ImagingSetArenaOnImaging(Imaging im, ImagingMemoryArena arena) {
312316
im->arenaindex = arena->index;
313317
}
314318
#else
@@ -339,7 +343,8 @@ struct ImagingMemoryArena ImagingDefaultArena = {
339343
* either have the GIL or we do not have TLS, we will return only the default
340344
* arena.
341345
*/
342-
ImagingMemoryArena ImagingGetArena(void) {
346+
ImagingMemoryArena
347+
ImagingGetArena(void) {
343348
return &ImagingDefaultArena;
344349
}
345350

@@ -588,9 +593,7 @@ ImagingNewInternal(const char *mode, int xsize, int ysize, int dirty) {
588593
ImagingSetArenaOnImaging(im, arena);
589594

590595
MUTEX_LOCK(&arena->mutex);
591-
Imaging tmp = ImagingAllocateArray(
592-
im, arena, dirty, arena->block_size
593-
);
596+
Imaging tmp = ImagingAllocateArray(im, arena, dirty, arena->block_size);
594597
MUTEX_UNLOCK(&arena->mutex);
595598
if (tmp) {
596599
return im;

0 commit comments

Comments
 (0)