Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 10 additions & 4 deletions ext/bcmath/bcmath.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,16 @@ PHP_FUNCTION(bcpowmod)
php_str2num(&second, ZSTR_VAL(right));
php_str2num(&mod, ZSTR_VAL(modulus));

if (bc_raisemod(first, second, mod, &result, scale) != -1) {
RETVAL_STR(bc_num2str_ex(result, scale));
} else {
RETVAL_FALSE;
switch (bc_raisemod(first, second, mod, &result, scale)) {
case 0:
RETVAL_STR(bc_num2str_ex(result, scale));
break;
case -1:
zend_throw_exception_ex(zend_ce_division_by_zero_error, 0, "Modulo by zero");
break;
case -2:
zend_argument_value_error(2, "must be greater than 0");
break;
}

bc_free_num(&first);
Expand Down
2 changes: 1 addition & 1 deletion ext/bcmath/bcmath.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function bcdiv(string $dividend, string $divisor, ?int $scale = null): string {}

function bcmod(string $dividend, string $divisor, ?int $scale = null): string {}

function bcpowmod(string $base, string $exponent, string $modulus, ?int $scale = null): string|false {}
function bcpowmod(string $base, string $exponent, string $modulus, ?int $scale = null): string {}

function bcpow(string $base, string $exponent, ?int $scale = null): string {}

Expand Down
2 changes: 1 addition & 1 deletion ext/bcmath/bcmath_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ZEND_END_ARG_INFO()

#define arginfo_bcmod arginfo_bcdiv

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_bcpowmod, 0, 3, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bcpowmod, 0, 3, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, base, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, exponent, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, modulus, IS_STRING, 0)
Expand Down
2 changes: 1 addition & 1 deletion ext/bcmath/libbcmath/src/raisemod.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ bc_raisemod (bc_num base, bc_num expo, bc_num mod, bc_num *result, int scale)

/* Check for correct numbers. */
if (bc_is_zero(mod)) return -1;
if (bc_is_neg(expo)) return -1;
if (bc_is_neg(expo)) return -2;

/* Set initial values. */
power = bc_copy_num (base);
Expand Down
16 changes: 16 additions & 0 deletions ext/bcmath/tests/bcpowmod_negative_exponent.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
bc_raisemod's expo can't be negative
--CREDITS--
Gabriel Caruso (carusogabriel34@gmail.com)
--SKIPIF--
<?php if(!extension_loaded('bcmath')) die('skip bcmath extension not loaded'); ?>
--FILE--
<?php
try {
var_dump(bcpowmod('1', '-1', '2'));
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
?>
--EXPECT--
bcpowmod(): Argument #2 ($exponent) must be greater than 0
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
--TEST--
bc_raisemod's mod can't be zero and expo can't be negative
bc_raisemod's mod can't be zero
--CREDITS--
Gabriel Caruso (carusogabriel34@gmail.com)
--SKIPIF--
<?php if(!extension_loaded('bcmath')) die('skip bcmath extension not loaded'); ?>
--FILE--
<?php var_dump(bcpowmod('1', '-1', '0')); ?>
<?php
try {
var_dump(bcpowmod('1', '-1', '0'));
} catch (DivisionByZeroError $ex) {
echo $ex->getMessage(), PHP_EOL;
}
?>
--EXPECT--
bool(false)
Modulo by zero
15 changes: 8 additions & 7 deletions ext/hash/hash_joaat.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,22 @@ PHP_HASH_API void PHP_JOAATUpdate(PHP_JOAAT_CTX *context, const unsigned char *i

PHP_HASH_API void PHP_JOAATFinal(unsigned char digest[4], PHP_JOAAT_CTX * context)
{
uint32_t hval = context->state;
hval += (hval << 3);
hval ^= (hval >> 11);
hval += (hval << 15);

#ifdef WORDS_BIGENDIAN
memcpy(digest, &context->state, 4);
memcpy(digest, &hval, 4);
#else
int i = 0;
unsigned char *c = (unsigned char *) &context->state;
unsigned char *c = (unsigned char *) &hval;

for (i = 0; i < 4; i++) {
digest[i] = c[3 - i];
}
#endif
context->state = 0;
context->state = 0;
}

/*
Expand All @@ -79,9 +84,5 @@ joaat_buf(void *buf, size_t len, uint32_t hval)
hval ^= (hval >> 6);
}

hval += (hval << 3);
hval ^= (hval >> 11);
hval += (hval << 15);

return hval;
}
2 changes: 1 addition & 1 deletion ext/hash/tests/hash-clone.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ string(16) "bebc746a33b6ab62"
string(16) "893899e4415a920f"
string(5) "joaat"
string(8) "aaebf370"
string(8) "513479b4"
string(8) "836fb0e5"
string(10) "haval128,3"
string(32) "86362472c8895e68e223ef8b3711d8d9"
string(32) "ebeeeb05c18af1e53d2d127b561d5e0d"
Expand Down
2 changes: 1 addition & 1 deletion ext/hash/tests/hash_copy_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ string(16) "bebc746a33b6ab62"
string(16) "893899e4415a920f"
string(5) "joaat"
string(8) "aaebf370"
string(8) "513479b4"
string(8) "836fb0e5"
string(10) "haval128,3"
string(32) "86362472c8895e68e223ef8b3711d8d9"
string(32) "ebeeeb05c18af1e53d2d127b561d5e0d"
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/Optimizer/zend_func_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ static const func_info_t func_infos[] = {
F1("bcmul", MAY_BE_STRING),
F1("bcdiv", MAY_BE_STRING),
F1("bcmod", MAY_BE_STRING),
F1("bcpowmod", MAY_BE_FALSE | MAY_BE_STRING),
F1("bcpowmod", MAY_BE_STRING),
F1("bcpow", MAY_BE_STRING),
F1("bcsqrt", MAY_BE_STRING),

Expand Down
17 changes: 17 additions & 0 deletions ext/opcache/jit/zend_elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <sys/stat.h>
#if defined(__FreeBSD__)
#include <sys/sysctl.h>
#elif defined(__HAIKU__)
#include <kernel/image.h>
#endif
#include <fcntl.h>
#include <unistd.h>
Expand Down Expand Up @@ -64,6 +66,21 @@ void zend_elf_load_symbols(void)
#elif defined(__sun)
const char *path = getexecname();
int fd = open(path, O_RDONLY);
#elif defined(__HAIKU__)
image_info ii;
int32_t ic = 0;

while (get_next_image_info(0, &ic, &ii) == B_OK) {
if (ii.type == B_APP_IMAGE) {
break;
}
}

if (ii.type != B_APP_IMAGE) {
return;
}

int fd = open(ii.name, O_RDONLY);
#else
// To complete eventually for other ELF platforms.
// Otherwise APPLE is Mach-O
Expand Down
17 changes: 17 additions & 0 deletions ext/opcache/jit/zend_jit_perf_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#elif defined(__sun)
// avoiding thread.h inclusion as it conflicts with vtunes types.
extern unsigned int thr_self(void);
#elif defined(__HAIKU__)
#include <kernel/image.h>
#endif

#include "zend_elf.h"
Expand Down Expand Up @@ -133,6 +135,21 @@ static void zend_jit_perf_jitdump_open(void)
#elif defined(__sun)
const char *path = getexecname();
fd = open(path, O_RDONLY);
#elif defined(__HAIKU__)
image_info ii;
int32_t ic = 0;

while (get_next_image_info(0, &ic, &ii) == B_OK) {
if (ii.type == B_APP_IMAGE) {
break;
}
}

if (ii.type != B_APP_IMAGE) {
return;
}

fd = open(ii.name, O_RDONLY);
#else
fd = -1;
#endif
Expand Down