Skip to content

Commit c78d5a7

Browse files
committed
Changed RANDOM_BSWAP64 to ZEND_BYTES_SWAP64
1 parent 7873e60 commit c78d5a7

File tree

2 files changed

+2
-28
lines changed

2 files changed

+2
-28
lines changed

ext/random/php_random.h

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -214,31 +214,4 @@ PHPAPI ZEND_EXTERN_MODULE_GLOBALS(random)
214214

215215
# define RANDOM_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(random, v)
216216

217-
/* Bytes swap */
218-
#ifdef _MSC_VER
219-
# include <stdlib.h>
220-
# define RANDOM_BSWAP64(u) _byteswap_uint64(u)
221-
#else
222-
# ifdef __GNUC__
223-
# define RANDOM_BSWAP64(u) __builtin_bswap64(u)
224-
# elif defined(__has_builtin)
225-
# if __has_builtin(__builtin_bswap64)
226-
# define RANDOM_BSWAP64(u) __builtin_bswap64(u)
227-
# endif // __has_builtin(__builtin_bswap64)
228-
# endif // __GNUC__
229-
#endif // _MSC_VER
230-
#ifndef RANDOM_BSWAP64
231-
static inline uint64_t RANDOM_BSWAP64(uint64_t u)
232-
{
233-
return (((u & 0xff00000000000000ULL) >> 56)
234-
| ((u & 0x00ff000000000000ULL) >> 40)
235-
| ((u & 0x0000ff0000000000ULL) >> 24)
236-
| ((u & 0x000000ff00000000ULL) >> 8)
237-
| ((u & 0x00000000ff000000ULL) << 8)
238-
| ((u & 0x0000000000ff0000ULL) << 24)
239-
| ((u & 0x000000000000ff00ULL) << 40)
240-
| ((u & 0x00000000000000ffULL) << 56));
241-
}
242-
#endif
243-
244217
#endif /* PHP_RANDOM_H */

ext/random/randomizer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "Zend/zend_enum.h"
2828
#include "Zend/zend_exceptions.h"
29+
#include "zend_portability.h"
2930

3031
static inline void randomizer_common_init(php_random_randomizer *randomizer, zend_object *engine_object) {
3132
if (engine_object->ce->type == ZEND_INTERNAL_CLASS) {
@@ -302,7 +303,7 @@ PHP_METHOD(Random_Randomizer, getBytes)
302303
uint64_t tmp_ret = result.result;
303304
if (to_read >= sizeof(uint64_t) && result.size == sizeof(uint64_t)) {
304305
#ifdef WORDS_BIGENDIAN
305-
tmp_ret = RANDOM_BSWAP64(tmp_ret);
306+
tmp_ret = ZEND_BYTES_SWAP64(tmp_ret);
306307
#endif
307308
memcpy(rptr, &tmp_ret, sizeof(uint64_t));
308309
to_read -= sizeof(uint64_t);

0 commit comments

Comments
 (0)