1. carbonica
  2. amp_old

Commits

ed...@edgar  committed d84d0c2

fixed little endian for linux (ubuntu)

  • Participants
  • Parent commits 8c098da
  • Branches default

Comments (0)

Files changed (1)

File ext/amp/support/support.c

View file
 #include <stdlib.h>
 #include "ruby.h"
 
+static int little_endian = -1;
+
 // these defines are taken from the mercurial source. They're relatively standard for
 // byte-swapping, but credit goes where credit's due.
 #ifdef _WIN32
  */
 static VALUE amp_fixnum_byte_swap_64(VALUE self) {
     VALUE result = self;
-    #if __LITTLE_ENDIAN__
-    #if HAVE_LONG_LONG
-    unsigned long long val = (unsigned long long)FIX2ULONG(self);
+    if (little_endian) {
+    uint64_t val = (uint64_t)FIX2ULONG(self);
     val = (((val >> 56)) | ((val & 0x00FF000000000000ll) >> 40) |
          ((val & 0x0000FF0000000000ll) >> 24) | ((val & 0x000000FF00000000ll) >> 8)  |
          ((val & 0x00000000FF000000ll) << 8 ) | ((val & 0x0000000000FF0000ll) << 24) |
          ((val & 0x000000000000FF00ll) << 40) | ((val & 0x00000000000000FFll) << 56));
      result = rb_ull2inum(val);
-    #endif
-    #endif
+    }
     return result;
 }
 
  */
 static VALUE amp_bignum_byte_swap_64(VALUE self) {
     VALUE result = self;
-    #if __LITTLE_ENDIAN__
+    if (little_endian) {
     uint64_t val = rb_big2ull(self);
     val = (((val >> 56)) | ((val & 0x00FF000000000000ull) >> 40) |
          ((val & 0x0000FF0000000000ull) >> 24) | ((val & 0x000000FF00000000ull) >> 8)  |
          ((val & 0x00000000FF000000) << 8 ) | ((val & 0x0000000000FF0000) << 24) |
          ((val & 0x000000000000FF00) << 40) | ((val & 0x00000000000000FF) << 56));
      result = rb_ull2inum(val);
-    #endif
+    }
     return result;
 }
 
  * symbols for to_dirstate_symbol.
  */
 void Init_Support() {
+    if (little_endian == -1) little_endian = (ntohl(8) != 8);
+
     // methods added to String class
     rb_define_method(rb_cString, "unhexlify", amp_string_unhexlify, 0);
     
     
     // method added to the Integer class
     rb_define_method(rb_cInteger, "to_dirstate_symbol", amp_integer_to_dirstate_symbol, 0);
-}
+}