[wp-trac] Re: [WordPress Trac] #3780: gettext fails to determine byteorder on 64bit systems with php5.2.1

WordPress Trac wp-trac at lists.automattic.com
Sun Jun 3 16:25:43 GMT 2007


#3780: gettext fails to determine byteorder on 64bit systems with php5.2.1
----------------------+-----------------------------------------------------
 Reporter:  abtime    |        Owner:  anonymous
     Type:  defect    |       Status:  new      
 Priority:  normal    |    Milestone:  2.2.2    
Component:  i18n      |      Version:  2.2      
 Severity:  critical  |   Resolution:           
 Keywords:            |  
----------------------+-----------------------------------------------------
Comment (by marcinkk):

 I have the same problem. FreeBSD 6.2 on AMD64 with PHP5.2.1, WordPress
 localization with 2.2 original code doesn't work :(

 Known code from gettext.php in WordPress 2.2:

 {{{
 // $MAGIC1 = (int)0x950412de; //bug in PHP 5.0.2, see
 https://savannah.nongnu.org/bugs/?func=detailitem&item_id=10565
 $MAGIC1 = (int) - 1794895138;
 // $MAGIC2 = (int)0xde120495; //bug
 $MAGIC2 = (int) - 569244523;
 // 64-bit fix
 $MAGIC3 = (int) 2500072158;

 $magic = $this->readint();
 }}}

 Results on my system:

 {{{
 echo $magic;                            Result: -1794895138
 echo $MAGIC1;                                   -1794895138
 echo $MAGIC2;                                   -569244523
 echo $MAGIC3;                                   2500072158
 echo $MAGIC1 & 0xFFFFFFFF;                      2500072158
 echo $MAGIC2 & 0xFFFFFFFF;                      3725722773
 echo $MAGIC3 & 0xFFFFFFFF;                      2500072158
 echo (int)0x950412de;                           2500072158
 echo (int)0xde120495;                           3725722773
 }}}

 So the results on all comparisons was 0, so I modified functions:

 {{{
 if ($magic == ($MAGIC1 & 0xFFFFFFFF) || ($magic == ($MAGIC3 & 0xFFFFFFFF))
 { // to make sure it works for 64-bit platforms
     $this->BYTEORDER = 0;
 } elseif ($magic == ($MAGIC2 & 0xFFFFFFFF)) {
     $this->BYTEORDER = 1;
 } else {
     $this->BYTEORDER = 0;
     //$this->error = 1; // not MO file
     //return false;
 }
 }}}

 And localization worked properly. In above code magic value is not checked
 but I was sure that BYTEORDER should be 0. So next I made:

 {{{
 if (($magic & 0xFFFFFFFF) == ($MAGIC1 & 0xFFFFFFFF) || ($magic &
 0xFFFFFFFF) == ($MAGIC3 & 0xFFFFFFFF)) { // to make sure it works for
 64-bit platforms
     $this->BYTEORDER = 0;
 } elseif (($magic & 0xFFFFFFFF) == ($MAGIC2 & 0xFFFFFFFF)) {
     $this->BYTEORDER = 1;
 } else {
     $this->error = 1; // not MO file
     return false;
 }
 }}}

 It works too and something is checked ... but I don'y know what this magic
 numbers do, so somebody better than me should check the results...

-- 
Ticket URL: <http://trac.wordpress.org/ticket/3780#comment:10>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list