Skip to content

Commit 638d580

Browse files
committed
Fix arm32 compiler warnings
1 parent 18b8927 commit 638d580

File tree

4 files changed

+48
-48
lines changed

4 files changed

+48
-48
lines changed

src_c/bitmask.c

Lines changed: 37 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -39,56 +39,48 @@
3939
static INLINE unsigned int
4040
bitcount(BITMASK_W n)
4141
{
42-
const int bitmask_len = BITMASK_W_LEN;
43-
if (bitmask_len == 32) {
42+
#if BITMASK_W_LEN == 32
4443
#ifdef GILLIES
45-
/* (C) Donald W. Gillies, 1992. All rights reserved. You may reuse
46-
this bitcount() function anywhere you please as long as you retain
47-
this Copyright Notice. */
48-
register unsigned long tmp;
49-
return (tmp = (n) - (((n) >> 1) & 033333333333) -
50-
(((n) >> 2) & 011111111111),
51-
tmp = ((tmp + (tmp >> 3)) & 030707070707),
52-
tmp = (tmp + (tmp >> 6)),
53-
tmp = (tmp + (tmp >> 12) + (tmp >> 24)) & 077);
44+
/* (C) Donald W. Gillies, 1992. All rights reserved. You may reuse
45+
this bitcount() function anywhere you please as long as you retain
46+
this Copyright Notice. */
47+
register unsigned long tmp;
48+
return (
49+
tmp = (n) - (((n) >> 1) & 033333333333) - (((n) >> 2) & 011111111111),
50+
tmp = ((tmp + (tmp >> 3)) & 030707070707), tmp = (tmp + (tmp >> 6)),
51+
tmp = (tmp + (tmp >> 12) + (tmp >> 24)) & 077);
5452
/* End of Donald W. Gillies bitcount code */
55-
#else
56-
/* This piece taken from Jorg Arndt's "Algorithms for Programmers" */
57-
n = ((n >> 1) & 0x55555555) + (n & 0x55555555); // 0-2 in 2 bits
58-
n = ((n >> 2) & 0x33333333) + (n & 0x33333333); // 0-4 in 4 bits
59-
n = ((n >> 4) + n) & 0x0f0f0f0f; // 0-8 in 4 bits
60-
n += n >> 8; // 0-16 in 8 bits
61-
n += n >> 16; // 0-32 in 8 bits
62-
return n & 0xff;
63-
#endif
64-
}
65-
else if (bitmask_len == 64) {
66-
n = ((n >> 1) & 0x5555555555555555) + (n & 0x5555555555555555);
67-
n = ((n >> 2) & 0x3333333333333333) + (n & 0x3333333333333333);
68-
n = ((n >> 4) + n) & 0x0f0f0f0f0f0f0f0f;
69-
n += n >> 8;
70-
n += n >> 16;
71-
#ifdef _WIN32
72-
/* Use explicit typecast to silence MSVC warning about large bitshift,
73-
* even though this part code does not run on windows */
74-
n += (long long)n >> 32;
75-
#else
76-
n += n >> 32;
77-
#endif
78-
return n & 0xff;
79-
}
80-
else {
81-
/* Handle non-32 or 64 bit case the slow way */
82-
unsigned int nbits = 0;
83-
while (n) {
84-
if (n & 1)
85-
nbits++;
86-
n = n >> 1;
87-
}
88-
return nbits;
53+
#else /* ~GILLIES */
54+
/* This piece taken from Jorg Arndt's "Algorithms for Programmers" */
55+
n = ((n >> 1) & 0x55555555) + (n & 0x55555555); // 0-2 in 2 bits
56+
n = ((n >> 2) & 0x33333333) + (n & 0x33333333); // 0-4 in 4 bits
57+
n = ((n >> 4) + n) & 0x0f0f0f0f; // 0-8 in 4 bits
58+
n += n >> 8; // 0-16 in 8 bits
59+
n += n >> 16; // 0-32 in 8 bits
60+
return n & 0xff;
61+
#endif /* ~GILLIES */
62+
#elif BITMASK_W_LEN == 64
63+
n = ((n >> 1) & 0x5555555555555555) + (n & 0x5555555555555555);
64+
n = ((n >> 2) & 0x3333333333333333) + (n & 0x3333333333333333);
65+
n = ((n >> 4) + n) & 0x0f0f0f0f0f0f0f0f;
66+
n += n >> 8;
67+
n += n >> 16;
68+
n += n >> 32;
69+
return n & 0xff;
70+
#else /* BITMASK_W_LEN */
71+
/* Handle non-32 or 64 bit case the slow way */
72+
unsigned int nbits = 0;
73+
while (n) {
74+
if (n & 1)
75+
nbits++;
76+
n = n >> 1;
8977
}
78+
return nbits;
79+
#endif /* BITMASK_W_LEN */
9080
}
9181

82+
__builtin__popcount
83+
9284
/* Positive modulo of the given dividend and divisor (dividend % divisor).
9385
*
9486
* Params:

src_c/color.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2356,9 +2356,14 @@ _pg_pylong_to_uint32(PyObject *val, Uint32 *color, int handle_negative)
23562356
* with most significant bit set could be incorrectly exposed as
23572357
* negative
23582358
*/
2359-
if (longval > 0xFFFFFFFF || (longval < 0 && !handle_negative)) {
2359+
if (longval < 0 && !handle_negative) {
23602360
goto error;
23612361
}
2362+
#if LONG_BIT > 32
2363+
if (longval > 0xFFFFFFFF) {
2364+
goto error;
2365+
}
2366+
#endif
23622367

23632368
*color = (Uint32)longval;
23642369
return 1;

src_c/include/bitmask.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ extern "C" {
2626
#endif
2727

2828
#include <limits.h>
29+
#include <Python.h>
30+
2931
/* Define INLINE for different compilers. If your compiler does not
3032
support inlining then there might be a performance hit in
3133
bitmask_overlap_area().
@@ -43,7 +45,7 @@ extern "C" {
4345
#endif
4446

4547
#define BITMASK_W unsigned long int
46-
#define BITMASK_W_LEN (sizeof(BITMASK_W) * CHAR_BIT)
48+
#define BITMASK_W_LEN LONG_BIT
4749
#define BITMASK_W_MASK (BITMASK_W_LEN - 1)
4850
#define BITMASK_N(n) ((BITMASK_W)1 << (n))
4951

src_c/mixer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ _format_view_to_audio(Py_buffer *view)
255255
view->format);
256256
return 0;
257257
}
258-
if (view->itemsize && PG_SAMPLE_SIZE(format) != view->itemsize) {
258+
if (view->itemsize &&
259+
PG_SAMPLE_SIZE(format) != (unsigned int)view->itemsize) {
259260
PyErr_Format(PyExc_ValueError,
260261
"Array item size %d does not match format '%s'",
261262
(int)view->itemsize, view->format);

0 commit comments

Comments
 (0)