Skip to content
Permalink
Browse files

Prevent crashes under PHP 7.3 on macs in Language server mode

  • Loading branch information
muglug committed Jan 13, 2020
1 parent eb7c3dc commit 6c771e5dd380865c5d2e7d37381e761dad580b48
@@ -320,13 +320,21 @@ public function server($address = '127.0.0.1:12345', bool $socket_server_mode =
$this->file_reference_provider->loadReferenceCache();
$this->codebase->enterServerMode();

$cpu_count = self::getCpuCount();
if (ini_get('pcre.jit') === '1'
&& PHP_OS === 'Darwin'
&& version_compare(PHP_VERSION, '7.3.0') >= 0
&& version_compare(PHP_VERSION, '7.4.0') < 0
) {
// do nothing
} else {
$cpu_count = self::getCpuCount();

// let's not go crazy
$usable_cpus = $cpu_count - 2;
// let's not go crazy
$usable_cpus = $cpu_count - 2;

if ($usable_cpus > 1) {
$this->threads = $usable_cpus;
if ($usable_cpus > 1) {
$this->threads = $usable_cpus;
}
}

$this->config->initializePlugins($this);
@@ -72,7 +72,7 @@ class Pool
public const MAC_PCRE_MESSAGE = 'Mac users: pcre.jit is set to 1 in your PHP config.' . PHP_EOL
. 'The pcre jit is known to cause segfaults in PHP 7.3 on Macs, and Psalm' . PHP_EOL
. 'will not execute in threaded mode to avoid indecipherable errors.' . PHP_EOL
. 'Consider adding pcre.jit=0 to your PHP config.' . PHP_EOL
. 'Consider adding pcre.jit=0 to your PHP config, or upgrade to PHP 7.4.' . PHP_EOL
. 'Relevant info: https://bugs.php.net/bug.php?id=77260';

/**
@@ -185,14 +185,6 @@ function ($arg) use ($valid_long_options, $valid_short_options) {
exit;
}

if (ini_get('pcre.jit') === '1'
&& PHP_OS === 'Darwin'
&& version_compare(PHP_VERSION, '7.3.0') >= 0
&& version_compare(PHP_VERSION, '7.4.0') < 0
) {
die(\Psalm\Internal\Fork\Pool::MAC_PCRE_MESSAGE . PHP_EOL . PHP_EOL);
}

$ini_handler = new \Psalm\Internal\Fork\PsalmRestarter('PSALM');

$ini_handler->disableExtension('grpc');

0 comments on commit 6c771e5

Please sign in to comment.
You can’t perform that action at this time.