Skip to content

random: Convert php_random_(bytes|int)_(silent|throw) into inline functions #10763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions ext/random/php_random.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,29 @@ static inline uint64_t php_random_pcgoneseq128xslrr64_rotr64(php_random_uint128_
}
# endif

# define php_random_bytes_throw(b, s) php_random_bytes((b), (s), 1)
# define php_random_bytes_silent(b, s) php_random_bytes((b), (s), 0)
# define php_random_int_throw(min, max, result) php_random_int((min), (max), (result), 1)
# define php_random_int_silent(min, max, result) php_random_int((min), (max), (result), 0)

PHPAPI zend_result php_random_bytes(void *bytes, size_t size, bool should_throw);
PHPAPI zend_result php_random_int(zend_long min, zend_long max, zend_long *result, bool should_throw);

static inline zend_result php_random_bytes_throw(void *bytes, size_t size)
{
return php_random_bytes(bytes, size, true);
}

static inline zend_result php_random_bytes_silent(void *bytes, size_t size)
{
return php_random_bytes(bytes, size, false);
}

static inline zend_result php_random_int_throw(zend_long min, zend_long max, zend_long *result)
{
return php_random_int(min, max, result, true);
}

static inline zend_result php_random_int_silent(zend_long min, zend_long max, zend_long *result)
{
return php_random_int(min, max, result, false);
}

typedef struct _php_random_status_ {
size_t last_generated_size;
void *state;
Expand Down