Skip to content

Commit 8abea1b

Browse files
authoredMar 4, 2023
random: Convert php_random_(bytes|int)_(silent|throw) into inline functions (#10763)
Compared to macros, inline functions are more robust and easier to debug. Also, use true/false at the same time instead of 1 and 0.
1 parent 3310463 commit 8abea1b

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed
 

‎ext/random/php_random.h

+20-5
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,29 @@ static inline uint64_t php_random_pcgoneseq128xslrr64_rotr64(php_random_uint128_
195195
}
196196
# endif
197197

198-
# define php_random_bytes_throw(b, s) php_random_bytes((b), (s), 1)
199-
# define php_random_bytes_silent(b, s) php_random_bytes((b), (s), 0)
200-
# define php_random_int_throw(min, max, result) php_random_int((min), (max), (result), 1)
201-
# define php_random_int_silent(min, max, result) php_random_int((min), (max), (result), 0)
202-
203198
PHPAPI zend_result php_random_bytes(void *bytes, size_t size, bool should_throw);
204199
PHPAPI zend_result php_random_int(zend_long min, zend_long max, zend_long *result, bool should_throw);
205200

201+
static inline zend_result php_random_bytes_throw(void *bytes, size_t size)
202+
{
203+
return php_random_bytes(bytes, size, true);
204+
}
205+
206+
static inline zend_result php_random_bytes_silent(void *bytes, size_t size)
207+
{
208+
return php_random_bytes(bytes, size, false);
209+
}
210+
211+
static inline zend_result php_random_int_throw(zend_long min, zend_long max, zend_long *result)
212+
{
213+
return php_random_int(min, max, result, true);
214+
}
215+
216+
static inline zend_result php_random_int_silent(zend_long min, zend_long max, zend_long *result)
217+
{
218+
return php_random_int(min, max, result, false);
219+
}
220+
206221
typedef struct _php_random_status_ {
207222
size_t last_generated_size;
208223
void *state;

0 commit comments

Comments
 (0)