aboutsummaryrefslogtreecommitdiffstats
path: root/package/python/python-2.7-012-correct-32bit-64bit-check.patch
blob: 88006f02d80b57fb936acdd017310fec56cf4729 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Use correct mechanism to determine 32/64 bits

Python setup.py builds certain extensions (dl and imageop) only on 32
bits architecture. However, to test whether the architecture is 32
bits or not, it was looking at the sys.maxint value of the host Python
interpreter... which might run on a 64 bits architecture even though
the target is 32 bits, or which might run on a 32 bits architecture
even though the target is 64 bits.

Therefore, we introduce a is_arch_64_bits() function, which looks at
the pyconfig.h file generated by ./configure for the value of
SIZEOF_LONG to determine if the architecture is 32 or 64 bits.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
 setup.py |   12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Index: Python-2.7.1/setup.py
===================================================================
--- Python-2.7.1.orig/setup.py
+++ Python-2.7.1/setup.py
@@ -29,6 +29,14 @@
 except KeyError:
     disabled_module_list = list()
 
+def is_arch_64_bits():
+    data = open('pyconfig.h').read()
+    m = re.search(r"#s*define\s+SIZEOF_LONG\s+4\s*", data)
+    if m is None:
+        return True
+    else:
+        return False
+
 def add_dir_to_list(dirlist, dir):
     """Add the directory 'dir' to the list 'dirlist' (at the front) if
     1) 'dir' is not already in 'dirlist'
@@ -608,7 +616,7 @@
         exts.append( Extension('audioop', ['audioop.c']) )
 
         # Disabled on 64-bit platforms
-        if sys.maxint != 9223372036854775807L:
+        if not is_arch_64_bits():
             # Operations on images
             exts.append( Extension('imageop', ['imageop.c']) )
         else:
@@ -1424,7 +1432,7 @@
                 missing.append('_codecs_%s' % loc)
 
         # Dynamic loading module
-        if sys.maxint == 0x7fffffff:
+        if not is_arch_64_bits():
             # This requires sizeof(int) == sizeof(long) == sizeof(char*)
             dl_inc = find_file('dlfcn.h', [], inc_dirs)
             if (dl_inc is not None) and (platform not in ['atheos']):