http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88959

Revision: 88959
Author:   tstarling
Date:     2011-05-27 06:25:21 +0000 (Fri, 27 May 2011)
Log Message:
-----------
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.

Modified Paths:
--------------
    trunk/phase3/includes/DefaultSettings.php
    trunk/phase3/includes/Init.php
    trunk/phase3/includes/Setup.php
    trunk/phase3/includes/filerepo/FileRepo.php
    trunk/phase3/includes/parser/Parser_LinkHooks.php
    trunk/phase3/includes/specials/SpecialUpload.php
    trunk/phase3/includes/upload/UploadBase.php
    trunk/phase3/index.php
    trunk/phase3/maintenance/hiphop/make
    trunk/phase3/maintenance/userDupes.inc

Modified: trunk/phase3/includes/DefaultSettings.php
===================================================================
--- trunk/phase3/includes/DefaultSettings.php   2011-05-27 03:42:15 UTC (rev 
88958)
+++ trunk/phase3/includes/DefaultSettings.php   2011-05-27 06:25:21 UTC (rev 
88959)
@@ -5309,6 +5309,25 @@
 /** @} */ # 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
  * @{
  */

Modified: trunk/phase3/includes/Init.php
===================================================================
--- trunk/phase3/includes/Init.php      2011-05-27 03:42:15 UTC (rev 88958)
+++ trunk/phase3/includes/Init.php      2011-05-27 06:25:21 UTC (rev 88959)
@@ -90,4 +90,13 @@
                }
                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 );
+       }
 }

Modified: trunk/phase3/includes/Setup.php
===================================================================
--- trunk/phase3/includes/Setup.php     2011-05-27 03:42:15 UTC (rev 88958)
+++ trunk/phase3/includes/Setup.php     2011-05-27 06:25:21 UTC (rev 88959)
@@ -337,9 +337,9 @@
        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' );
 

Modified: trunk/phase3/includes/filerepo/FileRepo.php
===================================================================
--- trunk/phase3/includes/filerepo/FileRepo.php 2011-05-27 03:42:15 UTC (rev 
88958)
+++ trunk/phase3/includes/filerepo/FileRepo.php 2011-05-27 06:25:21 UTC (rev 
88959)
@@ -606,7 +606,7 @@
        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 );
        }
 
        /**

Modified: trunk/phase3/includes/parser/Parser_LinkHooks.php
===================================================================
--- trunk/phase3/includes/parser/Parser_LinkHooks.php   2011-05-27 03:42:15 UTC 
(rev 88958)
+++ trunk/phase3/includes/parser/Parser_LinkHooks.php   2011-05-27 06:25:21 UTC 
(rev 88959)
@@ -254,8 +254,8 @@
                }
                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

Modified: trunk/phase3/includes/specials/SpecialUpload.php
===================================================================
--- trunk/phase3/includes/specials/SpecialUpload.php    2011-05-27 03:42:15 UTC 
(rev 88958)
+++ trunk/phase3/includes/specials/SpecialUpload.php    2011-05-27 06:25:21 UTC 
(rev 88959)
@@ -863,9 +863,13 @@
                        );
                }
 
-               $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',

Modified: trunk/phase3/includes/upload/UploadBase.php
===================================================================
--- trunk/phase3/includes/upload/UploadBase.php 2011-05-27 03:42:15 UTC (rev 
88958)
+++ trunk/phase3/includes/upload/UploadBase.php 2011-05-27 06:25:21 UTC (rev 
88959)
@@ -75,7 +75,7 @@
                }
 
                # Check php's file_uploads setting
-               if( !wfIniGetBool( 'file_uploads' ) ) {
+               if( !wfIsHipHop() && !wfIniGetBool( 'file_uploads' ) ) {
                        return false;
                }
                return true;

Modified: trunk/phase3/index.php
===================================================================
--- trunk/phase3/index.php      2011-05-27 03:42:15 UTC (rev 88958)
+++ trunk/phase3/index.php      2011-05-27 06:25:21 UTC (rev 88959)
@@ -66,7 +66,11 @@
 # 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;

Modified: trunk/phase3/maintenance/hiphop/make
===================================================================
--- trunk/phase3/maintenance/hiphop/make        2011-05-27 03:42:15 UTC (rev 
88958)
+++ trunk/phase3/maintenance/hiphop/make        2011-05-27 06:25:21 UTC (rev 
88959)
@@ -4,7 +4,6 @@
 require( dirname( __FILE__ ) . '/../Maintenance.php' );
 
 class MakeHipHop extends Maintenance {
-
        function execute() {
                $startTime = time();
 
@@ -63,13 +62,21 @@
                        ' --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 @@
                        }
 
                        $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 @@
 
                # 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 @@
                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';

Modified: trunk/phase3/maintenance/userDupes.inc
===================================================================
--- trunk/phase3/maintenance/userDupes.inc      2011-05-27 03:42:15 UTC (rev 
88958)
+++ trunk/phase3/maintenance/userDupes.inc      2011-05-27 06:25:21 UTC (rev 
88959)
@@ -174,7 +174,7 @@
         * @access private
         */
        function newSchema() {
-               return class_exists( 'Revision' );
+               return MWInit::classExists( 'Revision' );
        }
 
        /**


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to