Skip to content

Commit cd8bbfa

Browse files
committed
fixed bitset computing on win64 build
1 parent cb37fe1 commit cd8bbfa

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

Zend/zend_alloc.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@
131131
#endif
132132

133133
typedef uint32_t zend_mm_page_info; /* 4-byte integer */
134-
/* XXX temporary fix crash on bitset computing on win64 */
135-
typedef unsigned long zend_mm_bitset; /* 4-byte or 8-byte integer */
134+
typedef zend_ulong zend_mm_bitset; /* 4-byte or 8-byte integer */
136135

137136
#define ZEND_MM_ALIGNED_OFFSET(size, alignment) \
138137
(((size_t)(size)) & ((alignment) - 1))
@@ -459,9 +458,9 @@ static zend_always_inline int zend_mm_bitset_nts(zend_mm_bitset bitset)
459458
if (bitset == (zend_mm_bitset)-1) return ZEND_MM_BITSET_LEN;
460459

461460
n = 0;
462-
#if SIZEOF_LONG == 8
461+
#if SIZEOF_ZEND_LONG == 8
463462
if (sizeof(zend_mm_bitset) == 8) {
464-
if ((bitset & 0xffffffff) == 0xffffffff) {n += 32; bitset = bitset >> 32;}
463+
if ((bitset & 0xffffffff) == 0xffffffff) {n += 32; bitset = bitset >> Z_UL(32);}
465464
}
466465
#endif
467466
if ((bitset & 0x0000ffff) == 0x0000ffff) {n += 16; bitset = bitset >> 16;}
@@ -483,9 +482,9 @@ static zend_always_inline int zend_mm_bitset_ntz(zend_mm_bitset bitset)
483482
if (bitset == (zend_mm_bitset)0) return ZEND_MM_BITSET_LEN;
484483

485484
n = 1;
486-
#if SIZEOF_LONG == 8
485+
#if SIZEOF_ZEND_LONG == 8
487486
if (sizeof(zend_mm_bitset) == 8) {
488-
if ((bitset & 0xffffffff) == 0) {n += 32; bitset = bitset >> 32;}
487+
if ((bitset & 0xffffffff) == 0) {n += 32; bitset = bitset >> Z_UL(32);}
489488
}
490489
#endif
491490
if ((bitset & 0x0000ffff) == 0) {n += 16; bitset = bitset >> 16;}
@@ -532,7 +531,7 @@ static zend_always_inline int zend_mm_bitset_find_zero_and_set(zend_mm_bitset *b
532531
zend_mm_bitset tmp = bitset[i];
533532
if (tmp != (zend_mm_bitset)-1) {
534533
int n = zend_mm_bitset_nts(tmp);
535-
bitset[i] |= 1 << n;
534+
bitset[i] |= Z_UL(1) << n;
536535
return i * ZEND_MM_BITSET_LEN + n;
537536
}
538537
i++;
@@ -542,17 +541,17 @@ static zend_always_inline int zend_mm_bitset_find_zero_and_set(zend_mm_bitset *b
542541

543542
static zend_always_inline int zend_mm_bitset_is_set(zend_mm_bitset *bitset, int bit)
544543
{
545-
return (bitset[bit / ZEND_MM_BITSET_LEN] & (1L << (bit & (ZEND_MM_BITSET_LEN-1)))) != 0;
544+
return (bitset[bit / ZEND_MM_BITSET_LEN] & (Z_L(1) << (bit & (ZEND_MM_BITSET_LEN-1)))) != 0;
546545
}
547546

548547
static zend_always_inline void zend_mm_bitset_set_bit(zend_mm_bitset *bitset, int bit)
549548
{
550-
bitset[bit / ZEND_MM_BITSET_LEN] |= (1L << (bit & (ZEND_MM_BITSET_LEN-1)));
549+
bitset[bit / ZEND_MM_BITSET_LEN] |= (Z_L(1) << (bit & (ZEND_MM_BITSET_LEN-1)));
551550
}
552551

553552
static zend_always_inline void zend_mm_bitset_reset_bit(zend_mm_bitset *bitset, int bit)
554553
{
555-
bitset[bit / ZEND_MM_BITSET_LEN] &= ~(1L << (bit & (ZEND_MM_BITSET_LEN-1)));
554+
bitset[bit / ZEND_MM_BITSET_LEN] &= ~(Z_L(1) << (bit & (ZEND_MM_BITSET_LEN-1)));
556555
}
557556

558557
static zend_always_inline void zend_mm_bitset_set_range(zend_mm_bitset *bitset, int start, int len)
@@ -599,7 +598,7 @@ static zend_always_inline void zend_mm_bitset_reset_range(zend_mm_bitset *bitset
599598

600599
if (pos != end) {
601600
/* reset bits from "bit" to ZEND_MM_BITSET_LEN-1 */
602-
tmp = ~((1L << bit) - 1);
601+
tmp = ~((Z_L(1) << bit) - 1);
603602
bitset[pos++] &= ~tmp;
604603
while (pos != end) {
605604
/* set all bits */
@@ -1610,7 +1609,7 @@ zend_mm_heap *zend_mm_init(void)
16101609
chunk->free_pages = ZEND_MM_PAGES - ZEND_MM_FIRST_PAGE;
16111610
chunk->free_tail = ZEND_MM_FIRST_PAGE;
16121611
chunk->num = 0;
1613-
chunk->free_map[0] = (1L << ZEND_MM_FIRST_PAGE) - 1;
1612+
chunk->free_map[0] = (Z_L(1) << ZEND_MM_FIRST_PAGE) - 1;
16141613
chunk->map[0] = ZEND_MM_LRUN(ZEND_MM_FIRST_PAGE);
16151614
heap->main_chunk = chunk;
16161615
heap->cached_chunks = NULL;
@@ -1627,7 +1626,7 @@ zend_mm_heap *zend_mm_init(void)
16271626
heap->peak = 0;
16281627
#endif
16291628
#if ZEND_MM_LIMIT
1630-
heap->limit = (-1L >> 1);
1629+
heap->limit = (Z_L(-1) >> Z_L(1));
16311630
heap->overflow = 0;
16321631
#endif
16331632
#if ZEND_MM_CUSTOM

0 commit comments

Comments
 (0)