python-2.7-012-correct-32bit-64bit-check.patch 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. Use correct mechanism to determine 32/64 bits
  2. Python setup.py builds certain extensions (dl and imageop) only on 32
  3. bits architecture. However, to test whether the architecture is 32
  4. bits or not, it was looking at the sys.maxint value of the host Python
  5. interpreter... which might run on a 64 bits architecture even though
  6. the target is 32 bits, or which might run on a 32 bits architecture
  7. even though the target is 64 bits.
  8. Therefore, we introduce a is_arch_64_bits() function, which looks at
  9. the pyconfig.h file generated by ./configure for the value of
  10. SIZEOF_LONG to determine if the architecture is 32 or 64 bits.
  11. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  12. ---
  13. setup.py | 12 ++++++++++--
  14. 1 file changed, 10 insertions(+), 2 deletions(-)
  15. Index: Python-2.7.1/setup.py
  16. ===================================================================
  17. --- Python-2.7.1.orig/setup.py
  18. +++ Python-2.7.1/setup.py
  19. @@ -29,6 +29,14 @@
  20. except KeyError:
  21. disabled_module_list = list()
  22. +def is_arch_64_bits():
  23. + data = open('pyconfig.h').read()
  24. + m = re.search(r"#s*define\s+SIZEOF_LONG\s+4\s*", data)
  25. + if m is None:
  26. + return True
  27. + else:
  28. + return False
  29. +
  30. def add_dir_to_list(dirlist, dir):
  31. """Add the directory 'dir' to the list 'dirlist' (at the front) if
  32. 1) 'dir' is not already in 'dirlist'
  33. @@ -608,7 +616,7 @@
  34. exts.append( Extension('audioop', ['audioop.c']) )
  35. # Disabled on 64-bit platforms
  36. - if sys.maxint != 9223372036854775807L:
  37. + if not is_arch_64_bits():
  38. # Operations on images
  39. exts.append( Extension('imageop', ['imageop.c']) )
  40. else:
  41. @@ -1424,7 +1432,7 @@
  42. missing.append('_codecs_%s' % loc)
  43. # Dynamic loading module
  44. - if sys.maxint == 0x7fffffff:
  45. + if not is_arch_64_bits():
  46. # This requires sizeof(int) == sizeof(long) == sizeof(char*)
  47. dl_inc = find_file('dlfcn.h', [], inc_dirs)
  48. if (dl_inc is not None) and (platform not in ['atheos']):