summaryrefslogtreecommitdiffstats
path: root/package/python/python-2.7-012-correct-32bit-64bit-check.patch
blob: bfccbfd29273240bb988c270fc5ff31b0d5f7b3b (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.2/setup.py
===================================================================
--- Python-2.7.2.orig/setup.py
+++ Python-2.7.2/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'
@@ -628,7 +636,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:
@@ -1444,7 +1452,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']):
OpenPOWER on IntegriCloud