File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -412,21 +412,23 @@ get_ulonglong(PyObject *v, unsigned long long *p)
412
412
#define NUM_BITS (x ) ((x) >> 16)
413
413
414
414
/* Doesn't work if NUM_BITS(size) == 0, but it never happens in SET() call. */
415
- #define BIT_MASK (type , size ) (((((type)1 << (NUM_BITS(size) - 1)) - 1) << 1) + 1)
415
+ #define BIT_MASK (type , size ) \
416
+ (assert(NUM_BITS(size) > 0), \
417
+ (((((type)1 << (NUM_BITS(size) - 1)) - 1) << 1) + 1))
416
418
417
419
/* This macro CHANGES the first parameter IN PLACE. For proper sign handling,
418
420
we must first shift left, then right.
419
421
*/
420
422
#define GET_BITFIELD (v , size ) \
421
423
if (NUM_BITS(size)) { \
422
- v <<= (sizeof(v)*8 - LOW_BIT(size) - NUM_BITS(size)); \
424
+ v *= 1ULL << (sizeof(v)*8 - LOW_BIT(size) - NUM_BITS(size)); \
423
425
v >>= (sizeof(v)*8 - NUM_BITS(size)); \
424
426
}
425
427
426
428
/* This macro RETURNS the first parameter with the bit field CHANGED. */
427
429
#define SET (type , x , v , size ) \
428
430
(NUM_BITS(size) ? \
429
- ( ( (type)x & ~(BIT_MASK(type, size) << LOW_BIT(size)) ) | ( ((type)v & BIT_MASK(type, size)) << LOW_BIT(size) ) ) \
431
+ ( ( (type)x & ~(BIT_MASK(type, size) * (1ULL << LOW_BIT(size))) ) | ( ((type)v & BIT_MASK(type, size)) * (1ULL << LOW_BIT(size) ) ) ) \
430
432
: (type)v)
431
433
432
434
#if SIZEOF_SHORT == 2
You can’t perform that action at this time.
0 commit comments