Removed GMP dependency, using bundled BCMath

This commit is contained in:
Shoghi Cervantes Pueyo
2013-04-08 20:23:44 +02:00
parent 20694f2c77
commit b66e784a12
4 changed files with 40 additions and 62 deletions

View File

@@ -48,9 +48,7 @@ if(version_compare("5.4.0", PHP_VERSION) > 0){
if(version_compare(CURRENT_PHP_VERSION, PHP_VERSION) > 0){
console("[NOTICE] This PocketMine-MP version has not been tested with PHP < ".CURRENT_PHP_VERSION, true, true, 0);
}/*elseif(version_compare(CURRENT_PHP_VERSION, PHP_VERSION) < 0){
console("[NOTICE] This PocketMine-MP version has not been tested with PHP > ".CURRENT_PHP_VERSION, true, true, 0);
}*/
}
if(php_sapi_name() !== "cli"){
console("[ERROR] You must run PocketMine-MP using the CLI.", true, true, 0);
@@ -82,11 +80,6 @@ if(!extension_loaded("zlib") and @dl((PHP_SHLIB_SUFFIX === "dll" ? "php_":"") .
++$errors;
}
if(!extension_loaded("gmp") and @dl((PHP_SHLIB_SUFFIX === "dll" ? "php_":"") . "gmp." . PHP_SHLIB_SUFFIX) === false){
console("[ERROR] Unable to find the GMP extension.", true, true, 0);
++$errors;
}
if($errors > 0){
console("[ERROR] Please use the installer provided on the homepage.", true, true, 0);
exit(1); //Exit with error

View File

@@ -529,19 +529,45 @@ class Utils extends Thread{
return ENDIANNESS === BIG_ENDIAN ? strrev(pack("d", $value)):pack("d", $value);
}
public static function readLong($str){
$n = gmp_init(Utils::strToHex($str), 16);
if(gmp_testbit($n, "63")){
$n = gmp_xor($n, "0xffffffffffffffff"); //flip the bits
$n = gmp_neg(gmp_add($n, "1")); // add one and negate
public static function readLong($x, $signed = true){
$value = "0";
if($signed === true){
$negative = ((ord($x{0}) & 0x80) === 0x80) ? true:false;
if($negative){
$x = ~$x;
}
}else{
$negative = false;
}
return gmp_strval($n);
for($i = 0; $i < 8; $i += 4){
$value = bcmul($value, "4294967296", 0); //4294967296 == 2^32
$value = bcadd($value, 0x1000000 * ord($x{$i}) + ((ord($x{$i + 1}) << 16) | (ord($x{$i + 2}) << 8) | ord($x{$i + 3})), 0);
}
return ($negative === true ? "-".$value:$value);
}
public static function writeLong($value){
$long = gmp_init($value, 10);
$long = gmp_and($long, "0xffffffffffffffff");
return Utils::hexToStr(str_pad(gmp_strval($long, -16), 16, "00", STR_PAD_LEFT));
$x = "";
if($value{0} === "-"){
$negative = true;
$value = bcadd($value, "1");
if($value{0} === "-"){
$value = substr($value, 1);
}
}else{
$negative = false;
}
while(bccomp($value, '0', 0) > 0){
$temp = bcmod($value, "16777216");
$x = chr($temp >> 16) . chr($temp >> 8) . chr($temp) . $x;
$value = bcdiv($value, "16777216", 0);
}
$x = str_pad(substr($x, 0, 8), 8, "\x00", STR_PAD_LEFT);
if($negative === true){
$x = ~$x;
}
return $x;
}
public static function readLLong($str){