From: Tim Starling Date: Fri, 27 May 2011 06:25:21 +0000 (+0000) Subject: Some HipHop fixes: X-Git-Tag: 1.31.0-rc.0~29915 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/operations/recherche.php?a=commitdiff_plain;h=4c63ef444a996215b51a6ddafdb0028d80faefd7;p=lhc%2Fweb%2Fwiklou.git Some HipHop fixes: * Scan the C++ for volatile classes and show a warning with a list of them * Fixed volatile classes Revision, CoreLinkFunctions and FileRepoStatus, made them non-volatile by patching the referring code * Added some configuration for the build process to DefaultSettings.php. * Split a few functions off MakeHipHop::execute() * Only include UtfNormalDefines.php in interpreted mode, since in compiled mode, the constants exist from startup * Apparently HipHop does not support set_exception_handler(). Added a try/catch block around the main part of index.php instead. * Fixed ini_get() dependencies in Special:Upload. Upload now works, if you disable ZipDirectoryReader. --- diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 7047bfb6d7..012ac5f6f6 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -5308,6 +5308,25 @@ $wgUpdateRowsPerQuery = 100; /** @} */ # End job queue } +/************************************************************************//** + * @name HipHop compilation + * @{ + */ + +/** + * The HipHop build type. Can be either "Debug" or "Release". + */ +$wgHipHopBuildType = 'Debug'; + +/** + * Number of parallel processes to use during HipHop compilation, or "detect" + * to guess from system properties. + */ +$wgHipHopCompilerProcs = 'detect'; + +/** @} */ # End of HipHop compilation } + + /************************************************************************//** * @name Miscellaneous * @{ diff --git a/includes/Init.php b/includes/Init.php index 4c84b9aa31..7f1449fb54 100644 --- a/includes/Init.php +++ b/includes/Init.php @@ -90,4 +90,13 @@ class MWInit { } return $r !== false; } + + /** + * Call a static method of a class with variable arguments without causing + * it to become volatile. + */ + static function callStaticMethod( $className, $methodName, $args ) { + $r = new ReflectionMethod( $className, $methodName ); + return $r->invokeArgs( null, $args ); + } } diff --git a/includes/Setup.php b/includes/Setup.php index f343c49765..e70868a6ac 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -337,9 +337,9 @@ if ( !defined( 'MW_COMPILED' ) ) { require_once( "$IP/includes/Hooks.php" ); require_once( "$IP/includes/ProxyTools.php" ); require_once( "$IP/includes/ImageFunctions.php" ); + require_once( "$IP/includes/normal/UtfNormalDefines.php" ); wfProfileOut( $fname . '-includes' ); } -require_once( MWInit::compiledPath( 'includes/normal/UtfNormalDefines.php' ) ); wfProfileIn( $fname . '-misc1' ); diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php index 7fe8e81316..6b87f63034 100644 --- a/includes/filerepo/FileRepo.php +++ b/includes/filerepo/FileRepo.php @@ -606,7 +606,7 @@ abstract class FileRepo { function newFatal( $message /*, parameters...*/ ) { $params = func_get_args(); array_unshift( $params, $this ); - return call_user_func_array( array( 'FileRepoStatus', 'newFatal' ), $params ); + return MWInit::callStaticMethod( 'FileRepoStatus', 'newFatal', $params ); } /** diff --git a/includes/parser/Parser_LinkHooks.php b/includes/parser/Parser_LinkHooks.php index e3fab9dcfa..90e449435d 100644 --- a/includes/parser/Parser_LinkHooks.php +++ b/includes/parser/Parser_LinkHooks.php @@ -254,8 +254,8 @@ class Parser_LinkHooks extends Parser { } if( $return === true ) { # True (treat as plain link) was returned, call the defaultLinkHook - $args = array( $parser, $holders, $markers, $title, $titleText, &$paramText, &$leadingColon ); - $return = call_user_func_array( array( 'CoreLinkFunctions', 'defaultLinkHook' ), $args ); + $return = CoreLinkFunctions::defaultLinkHook( $parser, $holders, $markers, $title, + $titleText, $paramText, $leadingColon ); } if( $return === false ) { # False (no link) was returned, output plain wikitext diff --git a/includes/specials/SpecialUpload.php b/includes/specials/SpecialUpload.php index f793b41963..bb5c91f61e 100644 --- a/includes/specials/SpecialUpload.php +++ b/includes/specials/SpecialUpload.php @@ -863,9 +863,13 @@ class UploadForm extends HTMLForm { ); } - $this->mMaxUploadSize['file'] = min( - wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ), - UploadBase::getMaxUploadSize( 'file' ) ); + $this->mMaxUploadSize['file'] = UploadBase::getMaxUploadSize( 'file' ); + # Limit to upload_max_filesize unless we are running under HipHop and + # that setting doesn't exist + if ( !wfIsHipHop() ) { + $this->mMaxUploadSize['file'] = min( $this->mMaxUploadSize['file'], + wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ) ); + } $descriptor['UploadFile'] = array( 'class' => 'UploadSourceField', diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index a8243080b5..967c8ad7ae 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -75,7 +75,7 @@ abstract class UploadBase { } # Check php's file_uploads setting - if( !wfIniGetBool( 'file_uploads' ) ) { + if( !wfIsHipHop() && !wfIniGetBool( 'file_uploads' ) ) { return false; } return true; diff --git a/index.php b/index.php index 4fed9b8f10..9caed7a989 100644 --- a/index.php +++ b/index.php @@ -66,7 +66,11 @@ ENDL; # does *not* load $wgTitle require ( dirname( __FILE__ ) . '/includes/WebStart.php' ); -wfIndexMain(); +try { + wfIndexMain(); +} catch ( Exception $e ) { + wfExceptionHandler( $e ); +} function wfIndexMain() { global $wgRequest, $wgShowHostnames, $mediaWiki, $wgTitle, $wgUseAjax, $wgUseFileCache; diff --git a/maintenance/hiphop/make b/maintenance/hiphop/make index 60388ac081..bfeb960a59 100755 --- a/maintenance/hiphop/make +++ b/maintenance/hiphop/make @@ -4,7 +4,6 @@ require( dirname( __FILE__ ) . '/../Maintenance.php' ); class MakeHipHop extends Maintenance { - function execute() { $startTime = time(); @@ -63,13 +62,21 @@ class MakeHipHop extends Maintenance { ' --parse-on-demand=false' . ' --program=mediawiki-hphp' . ' --output-dir=' . wfEscapeShellArg( $outDir ) . - ' --log=3' ); + ' --log=3', $ret ); + + if ( $ret ) { + $this->error( "hphp hit an error. Stopping build.\n" ); + exit( 1 ); + } # Sanity check, quickly make sure we've got an output directory if( !is_dir( $outDir ) ) { $this->error( "No output directory", true ); } + # Warn about volatile classes + $this->checkVolatileClasses( $outDir ); + # Copy the generated C++ files into the source directory for cmake $iter = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $outDir ), @@ -140,7 +147,7 @@ class MakeHipHop extends Maintenance { } $cmd = 'cmake' . - ' -D CMAKE_BUILD_TYPE:string=Debug' . + " -D CMAKE_BUILD_TYPE:string=" . wfEscapeShellArg( $GLOBALS['wgHipHopBuildType'] ) . ' -D PROGRAM_NAME:string=mediawiki-hphp'; if ( file_exists( '/usr/bin/ccache' ) ) { @@ -155,19 +162,7 @@ class MakeHipHop extends Maintenance { # Determine appropriate make concurrency # Compilation can take a lot of memory, let's assume that that is limiting. - $mem = false; - foreach ( file( '/proc/meminfo' ) as $line ) { - if ( preg_match( '/^MemTotal:\s+(\d+)\s+kB/', $line, $m ) ) { - $mem = intval( $m[1] ); - break; - } - } - if ( $mem ) { - $procs = floor( $mem / 1000000 ); - $procs = $procs >= 1 ? $procs : 1; // No less than 1 - } else { - $procs = 1; - } + $procs = $this->getNumProcs(); # Run make. This is the slow step. passthru( 'make -j' . wfEscapeShellArg( $procs ) ); @@ -188,6 +183,47 @@ class MakeHipHop extends Maintenance { echo $elapsed . "s\n"; echo "The MediaWiki executable is at build/persistent/mediawiki-hphp\n"; } + + function checkVolatileClasses( $dir ) { + $lines = file( "$dir/sys/dynamic_table_class.cpp" ); + $classes = array(); + foreach ( $lines as $line ) { + if ( preg_match( '/^\s+\(const char \*\)"([^"]*)", \(const char \*\)-1/', $line, $m ) ) { + $classes[] = $m[1]; + } + } + if ( !count( $classes ) ) { + print "No volatile classes found\n"; + return; + } + sort( $classes ); + $classes = array_unique( $classes ); + print "WARNING: The following classes are volatile: " . implode( ', ', $classes ) . "\n"; + } + + function getNumProcs() { + global $wgHipHopCompilerProcs; + if ( $wgHipHopCompilerProcs !== 'detect' ) { + return intval( $wgHipHopCompilerProcs ); + } + + if ( !file_exists( '/proc/meminfo' ) ) { + return 1; + } + $mem = false; + foreach ( file( '/proc/meminfo' ) as $line ) { + if ( preg_match( '/^MemTotal:\s+(\d+)\s+kB/', $line, $m ) ) { + $mem = intval( $m[1] ); + break; + } + } + if ( $mem ) { + // At least one process + return max( 1, floor( $mem / 1000000 ) ); + } else { + return 1; + } + } } $maintClass = 'MakeHipHop'; diff --git a/maintenance/userDupes.inc b/maintenance/userDupes.inc index 49fd309a88..31bae8ed0b 100644 --- a/maintenance/userDupes.inc +++ b/maintenance/userDupes.inc @@ -174,7 +174,7 @@ class UserDupes { * @access private */ function newSchema() { - return class_exists( 'Revision' ); + return MWInit::classExists( 'Revision' ); } /**