Drop support for 32 bit systems/PHP (#984)

* Cutting out 32-bit and minor improvements to bootstrap

* Byeeeeee

* Removing legacy code

* added note to the issue template
as suggested by @xxFlare
This commit is contained in:
Dylan K. Taylor 2017-06-10 16:11:28 +01:00 committed by GitHub
parent 3687b149b9
commit 4765242397
5 changed files with 143 additions and 356 deletions

View File

@ -16,9 +16,12 @@ Actual result: What actually happened?
### OS and versions ### OS and versions
<!--- use the 'version' command in PocketMine-MP <!--- use the 'version' command in PocketMine-MP
NOTE: LATEST is not a valid version.
PocketMine version should include Jenkins build number and/or git commit hash. NOTE: LATEST is not a valid version. PocketMine version should include Jenkins build number and/or git commit hash.
ALSO NOTE: NO support whatsoever will be provided for forks or spoons of PocketMine. Issues relating to non-official distributions will be closed as spam. Please send such issues to whoever is responsible for the fork or spoon you are using.
NO support whatsoever will be provided for forks or spoons of PocketMine. Issues relating to non-official distributions will be closed as spam. Please send such issues to whoever is responsible for the fork or spoon you are using.
Note that 32-bit platforms are no longer supported by PocketMine-MP and issues concerning 32-bit platforms will be closed.
--> -->
* PocketMine-MP: * PocketMine-MP:
* PHP: * PHP:

View File

@ -91,11 +91,6 @@ class MemoryManager{
$hardLimit = ((int) $this->server->getProperty("memory.main-hard-limit", $defaultMemory)); $hardLimit = ((int) $this->server->getProperty("memory.main-hard-limit", $defaultMemory));
if(PHP_INT_SIZE === 4 and $hardLimit >= 4096){
$this->server->getLogger()->warning("Cannot set memory limit higher than 4GB on 32-bit, defaulting to max 4095MB");
$hardLimit = 4095;
}
if($hardLimit <= 0){ if($hardLimit <= 0){
ini_set("memory_limit", -1); ini_set("memory_limit", -1);
}else{ }else{

View File

@ -401,8 +401,17 @@ namespace pocketmine {
return rtrim(str_replace(["\\", ".php", "phar://", rtrim(str_replace(["\\", "phar://"], ["/", ""], \pocketmine\PATH), "/"), rtrim(str_replace(["\\", "phar://"], ["/", ""], \pocketmine\PLUGIN_PATH), "/")], ["/", "", "", "", ""], $path), "/"); return rtrim(str_replace(["\\", ".php", "phar://", rtrim(str_replace(["\\", "phar://"], ["/", ""], \pocketmine\PATH), "/"), rtrim(str_replace(["\\", "phar://"], ["/", ""], \pocketmine\PLUGIN_PATH), "/")], ["/", "", "", "", ""], $path), "/");
} }
$exitCode = 0;
do{
$errors = 0; $errors = 0;
if(PHP_INT_SIZE < 8){
$logger->critical("Running PocketMine-MP with 32-bit systems/PHP is no longer supported. Please upgrade to a 64-bit system or use a 64-bit PHP binary.");
$exitCode = 1;
break;
}
if(php_sapi_name() !== "cli"){ if(php_sapi_name() !== "cli"){
$logger->critical("You must run PocketMine-MP using the CLI."); $logger->critical("You must run PocketMine-MP using the CLI.");
++$errors; ++$errors;
@ -428,12 +437,7 @@ namespace pocketmine {
} }
if(extension_loaded("xdebug")){ if(extension_loaded("xdebug")){
$logger->warning(" $logger->warning(PHP_EOL . PHP_EOL . PHP_EOL . "\tYou are running PocketMine with xdebug enabled. This has a major impact on performance." . PHP_EOL . PHP_EOL);
You are running PocketMine with xdebug enabled. This has a major impact on performance.
");
} }
$extensions = [ $extensions = [
@ -455,13 +459,8 @@ namespace pocketmine {
if($errors > 0){ if($errors > 0){
$logger->critical("Please use the installer provided on the homepage, or recompile PHP again."); $logger->critical("Please use the installer provided on the homepage, or recompile PHP again.");
$logger->shutdown(); $exitCode = 1;
$logger->join(); break;
exit(1); //Exit with error
}
if(PHP_INT_SIZE < 8){
$logger->warning("Running PocketMine-MP with 32-bit systems/PHP is deprecated. Support for 32-bit may be dropped in the future.");
} }
$gitHash = str_repeat("00", 20); $gitHash = str_repeat("00", 20);
@ -488,9 +487,8 @@ namespace pocketmine {
if(!file_exists(\pocketmine\DATA . "server.properties") and !isset($opts["no-wizard"])){ if(!file_exists(\pocketmine\DATA . "server.properties") and !isset($opts["no-wizard"])){
$installer = new SetupWizard(); $installer = new SetupWizard();
if(!$installer->run()){ if(!$installer->run()){
$logger->shutdown(); $exitCode = -1;
$logger->join(); break;
exit(-1);
} }
} }
@ -520,18 +518,18 @@ namespace pocketmine {
} }
} }
$logger->shutdown();
$logger->join();
echo Terminal::$FORMAT_RESET . PHP_EOL;
if($erroredThreads > 0){ if($erroredThreads > 0){
if(\pocketmine\DEBUG > 1){ if(\pocketmine\DEBUG > 1){
echo "Some threads could not be stopped, performing a force-kill" . PHP_EOL . PHP_EOL; echo "Some threads could not be stopped, performing a force-kill" . PHP_EOL . PHP_EOL;
} }
kill(getmypid()); kill(getmypid());
}else{
exit(0);
} }
}while(false);
$logger->shutdown();
$logger->join();
echo Terminal::$FORMAT_RESET . PHP_EOL;
exit($exitCode);
} }

View File

@ -265,24 +265,17 @@ class Level implements ChunkManager, Metadatable{
private $closed = false; private $closed = false;
public static function chunkHash(int $x, int $z){ public static function chunkHash(int $x, int $z){
return PHP_INT_SIZE === 8 ? (($x & 0xFFFFFFFF) << 32) | ($z & 0xFFFFFFFF) : $x . ":" . $z; return (($x & 0xFFFFFFFF) << 32) | ($z & 0xFFFFFFFF);
} }
public static function blockHash(int $x, int $y, int $z){ public static function blockHash(int $x, int $y, int $z){
return PHP_INT_SIZE === 8 ? (($x & 0xFFFFFFF) << 36) | (($y & Level::Y_MASK) << 28) | ($z & 0xFFFFFFF) : $x . ":" . $y . ":" . $z; return (($x & 0xFFFFFFF) << 36) | (($y & Level::Y_MASK) << 28) | ($z & 0xFFFFFFF);
} }
public static function getBlockXYZ($hash, &$x, &$y, &$z){ public static function getBlockXYZ($hash, &$x, &$y, &$z){
if(PHP_INT_SIZE === 8){
$x = $hash >> 36; $x = $hash >> 36;
$y = ($hash >> 28) & Level::Y_MASK; //it's always positive $y = ($hash >> 28) & Level::Y_MASK; //it's always positive
$z = ($hash & 0xFFFFFFF) << 36 >> 36; $z = ($hash & 0xFFFFFFF) << 36 >> 36;
}else{
$hash = explode(":", $hash);
$x = (int) $hash[0];
$y = (int) $hash[1];
$z = (int) $hash[2];
}
} }
/** /**
@ -291,14 +284,8 @@ class Level implements ChunkManager, Metadatable{
* @param int|null $z * @param int|null $z
*/ */
public static function getXZ($hash, &$x, &$z){ public static function getXZ($hash, &$x, &$z){
if(PHP_INT_SIZE === 8){
$x = $hash >> 32; $x = $hash >> 32;
$z = ($hash & 0xFFFFFFFF) << 32 >> 32; $z = ($hash & 0xFFFFFFFF) << 32 >> 32;
}else{
$hash = explode(":", $hash);
$x = (int) $hash[0];
$z = (int) $hash[1];
}
} }
public static function generateChunkLoaderId(ChunkLoader $loader) : int{ public static function generateChunkLoaderId(ChunkLoader $loader) : int{

View File

@ -73,7 +73,7 @@ class Binary{
* @return int * @return int
*/ */
public static function readSignedByte(string $c) : int{ public static function readSignedByte(string $c) : int{
return PHP_INT_SIZE === 8 ? (ord($c{0}) << 56 >> 56) : (ord($c{0}) << 24 >> 24); return ord($c{0}) << 56 >> 56;
} }
/** /**
@ -106,11 +106,7 @@ class Binary{
*/ */
public static function readSignedShort(string $str) : int{ public static function readSignedShort(string $str) : int{
self::checkLength($str, 2); self::checkLength($str, 2);
if(PHP_INT_SIZE === 8){
return unpack("n", $str)[1] << 48 >> 48; return unpack("n", $str)[1] << 48 >> 48;
}else{
return unpack("n", $str)[1] << 16 >> 16;
}
} }
/** /**
@ -145,11 +141,7 @@ class Binary{
*/ */
public static function readSignedLShort(string $str) : int{ public static function readSignedLShort(string $str) : int{
self::checkLength($str, 2); self::checkLength($str, 2);
if(PHP_INT_SIZE === 8){
return unpack("v", $str)[1] << 48 >> 48; return unpack("v", $str)[1] << 48 >> 48;
}else{
return unpack("v", $str)[1] << 16 >> 16;
}
} }
/** /**
@ -213,11 +205,7 @@ class Binary{
*/ */
public static function readInt(string $str) : int{ public static function readInt(string $str) : int{
self::checkLength($str, 4); self::checkLength($str, 4);
if(PHP_INT_SIZE === 8){
return unpack("N", $str)[1] << 32 >> 32; return unpack("N", $str)[1] << 32 >> 32;
}else{
return unpack("N", $str)[1];
}
} }
/** /**
@ -238,11 +226,7 @@ class Binary{
*/ */
public static function readLInt(string $str) : int{ public static function readLInt(string $str) : int{
self::checkLength($str, 4); self::checkLength($str, 4);
if(PHP_INT_SIZE === 8){
return unpack("V", $str)[1] << 32 >> 32; return unpack("V", $str)[1] << 32 >> 32;
}else{
return unpack("V", $str)[1];
}
} }
/** /**
@ -381,22 +365,8 @@ class Binary{
*/ */
public static function readLong(string $x){ public static function readLong(string $x){
self::checkLength($x, 8); self::checkLength($x, 8);
if(PHP_INT_SIZE === 8){
$int = unpack("N*", $x); $int = unpack("N*", $x);
return ($int[1] << 32) | $int[2]; return ($int[1] << 32) | $int[2];
}else{
$value = "0";
for($i = 0; $i < 8; $i += 2){
$value = bcmul($value, "65536", 0);
$value = bcadd($value, (string) self::readShort(substr($x, $i, 2)), 0);
}
if(bccomp($value, "9223372036854775807") == 1){
$value = bcadd($value, "-18446744073709551616");
}
return $value;
}
} }
/** /**
@ -406,23 +376,7 @@ class Binary{
* @return string * @return string
*/ */
public static function writeLong($value) : string{ public static function writeLong($value) : string{
if(PHP_INT_SIZE === 8){
return pack("NN", $value >> 32, $value & 0xFFFFFFFF); return pack("NN", $value >> 32, $value & 0xFFFFFFFF);
}else{
$x = "";
$value = (string) $value;
if(bccomp($value, "0") == -1){
$value = bcadd($value, "18446744073709551616");
}
$x .= self::writeShort((int) bcmod(bcdiv($value, "281474976710656"), "65536"));
$x .= self::writeShort((int) bcmod(bcdiv($value, "4294967296"), "65536"));
$x .= self::writeShort((int) bcmod(bcdiv($value, "65536"), "65536"));
$x .= self::writeShort((int) bcmod($value, "65536"));
return $x;
}
} }
/** /**
@ -455,10 +409,9 @@ class Binary{
* @return int * @return int
*/ */
public static function readVarInt(string $buffer, int &$offset) : int{ public static function readVarInt(string $buffer, int &$offset) : int{
$shift = PHP_INT_SIZE === 8 ? 63 : 31;
$raw = self::readUnsignedVarInt($buffer, $offset); $raw = self::readUnsignedVarInt($buffer, $offset);
$temp = ((($raw << $shift) >> $shift) ^ $raw) >> 1; $temp = ((($raw << 63) >> 63) ^ $raw) >> 1;
return $temp ^ ($raw & (1 << $shift)); return $temp ^ ($raw & (1 << 63));
} }
/** /**
@ -494,9 +447,7 @@ class Binary{
* @return string * @return string
*/ */
public static function writeVarInt(int $v) : string{ public static function writeVarInt(int $v) : string{
if(PHP_INT_SIZE === 8){
$v = ($v << 32 >> 32); $v = ($v << 32 >> 32);
}
return self::writeUnsignedVarInt(($v << 1) ^ ($v >> 31)); return self::writeUnsignedVarInt(($v << 1) ^ ($v >> 31));
} }
@ -525,103 +476,28 @@ class Binary{
/** /**
* Reads a 64-bit zigzag-encoded variable-length integer from the supplied stream. * Reads a 64-bit zigzag-encoded variable-length integer.
*
* @param string $buffer
* @param int &$offset
*
* @return int|string
*/
public static function readVarLong(string $buffer, int &$offset){
if(PHP_INT_SIZE === 8){
return self::readVarLong_64($buffer, $offset);
}else{
return self::readVarLong_32($buffer, $offset);
}
}
/**
* Legacy BC Math zigzag VarLong reader. Will work on 32-bit or 64-bit, but will be slower than the regular 64-bit method.
*
* @param string $buffer
* @param int &$offset
*
* @return string
*/
public static function readVarLong_32(string $buffer, int &$offset) : string{
/** @var string $raw */
$raw = self::readUnsignedVarLong_32($buffer, $offset);
$result = bcdiv($raw, "2");
if(bcmod($raw, "2") === "1"){
$result = bcsub(bcmul($result, "-1"), "1");
}
return $result;
}
/**
* 64-bit zizgag VarLong reader.
* *
* @param string $buffer * @param string $buffer
* @param int &$offset * @param int &$offset
* *
* @return int * @return int
*/ */
public static function readVarLong_64(string $buffer, int &$offset) : int{ public static function readVarLong(string $buffer, int &$offset) : int{
$raw = self::readUnsignedVarLong_64($buffer, $offset); $raw = self::readUnsignedVarLong($buffer, $offset);
$temp = ((($raw << 63) >> 63) ^ $raw) >> 1; $temp = ((($raw << 63) >> 63) ^ $raw) >> 1;
return $temp ^ ($raw & (1 << 63)); return $temp ^ ($raw & (1 << 63));
} }
/** /**
* Reads an unsigned VarLong from the supplied stream. * Reads a 64-bit unsigned variable-length integer.
*
* @param string $buffer
* @param int &$offset
*
* @return int|string
*/
public static function readUnsignedVarLong(string $buffer, int &$offset){
if(PHP_INT_SIZE === 8){
return self::readUnsignedVarLong_64($buffer, $offset);
}else{
return self::readUnsignedVarLong_32($buffer, $offset);
}
}
/**
* Legacy BC Math unsigned VarLong reader.
*
* @param string $buffer
* @param int &$offset
*
* @return string
*/
public static function readUnsignedVarLong_32(string $buffer, int &$offset) : string{
$value = "0";
for($i = 0; $i <= 63; $i += 7){
$b = ord($buffer{$offset++});
$value = bcadd($value, bcmul((string) ($b & 0x7f), bcpow("2", "$i")));
if(($b & 0x80) === 0){
return $value;
}elseif(!isset($buffer{$offset})){
throw new \UnexpectedValueException("Expected more bytes, none left to read");
}
}
throw new \InvalidArgumentException("VarLong did not terminate after 10 bytes!");
}
/**
* 64-bit unsigned VarLong reader.
* *
* @param string $buffer * @param string $buffer
* @param int &$offset * @param int &$offset
* *
* @return int * @return int
*/ */
public static function readUnsignedVarLong_64(string $buffer, int &$offset) : int{ public static function readUnsignedVarLong(string $buffer, int &$offset) : int{
$value = 0; $value = 0;
for($i = 0; $i <= 63; $i += 7){ for($i = 0; $i <= 63; $i += 7){
$b = ord($buffer{$offset++}); $b = ord($buffer{$offset++});
@ -637,95 +513,23 @@ class Binary{
throw new \InvalidArgumentException("VarLong did not terminate after 10 bytes!"); throw new \InvalidArgumentException("VarLong did not terminate after 10 bytes!");
} }
/** /**
* Writes a 64-bit integer as a variable-length long. * Writes a 64-bit integer as a zigzag-encoded variable-length long.
*
* @param int|string $v
* @return string up to 10 bytes
*/
public static function writeVarLong($v) : string{
if(PHP_INT_SIZE === 8){
return self::writeVarLong_64($v);
}else{
return self::writeVarLong_32((string) $v);
}
}
/**
* Legacy BC Math zigzag VarLong encoder.
*
* @param string $v
* @return string
*/
public static function writeVarLong_32(string $v) : string{
$v = bcmod(bcmul($v, "2"), "18446744073709551616");
if(bccomp($v, "0") == -1){
$v = bcsub(bcmul($v, "-1"), "1");
}
return self::writeUnsignedVarLong_32($v);
}
/**
* 64-bit VarLong encoder.
* *
* @param int $v * @param int $v
* @return string * @return string
*/ */
public static function writeVarLong_64(int $v) : string{ public static function writeVarLong(int $v) : string{
return self::writeUnsignedVarLong_64(($v << 1) ^ ($v >> 63)); return self::writeUnsignedVarLong(($v << 1) ^ ($v >> 63));
} }
/** /**
* Writes a 64-bit integer as a variable-length long * Writes a 64-bit unsigned integer as a variable-length long.
*
* @param int|string $v
* @return string up to 10 bytes
*/
public static function writeUnsignedVarLong($v) : string{
if(PHP_INT_SIZE === 8){
return self::writeUnsignedVarLong_64($v);
}else{
return self::writeUnsignedVarLong_32((string) $v);
}
}
/**
* Legacy BC Math unsigned VarLong encoder.
*
* @param string $value
* @return string
*/
public static function writeUnsignedVarLong_32(string $value) : string{
$buf = "";
if(bccomp($value, "0") == -1){
$value = bcadd($value, "18446744073709551616");
}
for($i = 0; $i < 10; ++$i){
$byte = (int) bcmod($value, "128");
$value = bcdiv($value, "128");
if($value !== "0"){
$buf .= chr($byte | 0x80);
}else{
$buf .= chr($byte);
return $buf;
}
}
throw new \InvalidArgumentException("Value too large to be encoded as a VarLong");
}
/**
* 64-bit unsigned VarLong encoder.
* @param int $value * @param int $value
* *
* @return string * @return string
*/ */
public static function writeUnsignedVarLong_64(int $value) : string{ public static function writeUnsignedVarLong(int $value) : string{
$buf = ""; $buf = "";
for($i = 0; $i < 10; ++$i){ for($i = 0; $i < 10; ++$i){
if(($value >> 7) !== 0){ if(($value >> 7) !== 0){