components/python/python27/patches/04-solaris-64-bit.patch
author John Beck <John.Beck@Oracle.COM>
Sat, 04 Oct 2014 14:50:43 -0700
branchs11-update
changeset 3367 ed5024e47b53
parent 458 2edc011b559e
permissions -rw-r--r--
PSARC 2014/183 Python 2.7.6 18251953 update Python 2.7 line to version 2.7.6 19004605 update Python 2.7 line to version 2.7.7 19308541 update Python 2.7 line to version 2.7.8 19284990 python 2.7.7 segfaults while under memory stress 17431625 64-bit python should use long rather than int for os.sysconf() return value 19164544 Python 2.7 test_tcl fails 19030238 Python 2.7 test_sysconfig fails - no module named _osx_support 19030198 Python 2.7 tests fail - import name error 19032456 more Python 2.7 tests failing with import errors 19022543 Python 2.7 test_lib2to3 fails

This patch ensures that 64-bit shared objects are in a subdirectory named
"64".  Note that changes to the Lib/distutils/tests/test_build.py and
Lib/distutils/tests/test_install.py avoid running tests that fail due to
this patch.  As this is Solaris-specific, it is not suitable for upstream.

--- Python-2.7.6/Lib/distutils/command/build_ext.py.~1~	2013-11-09 23:36:40.000000000 -0800
+++ Python-2.7.6/Lib/distutils/command/build_ext.py	2014-05-14 12:47:04.342901439 -0700
@@ -634,6 +634,10 @@
         filename = self.get_ext_filename(ext_name)
         filename = os.path.split(filename)[-1]
 
+        # on Solaris we put 64-bit python objects under .../64
+        if sys.maxint != 2147483647L:
+            filename = os.path.join("64", filename)
+
         if not self.inplace:
             # no further work needed
             # returning :
@@ -674,7 +678,14 @@
         so_ext = get_config_var('SO')
         if os.name == 'nt' and self.debug:
             return os.path.join(*ext_path) + '_d' + so_ext
-        return os.path.join(*ext_path) + so_ext
+        #return os.path.join(*ext_path) + so_ext
+	# .so extensions are word-size specific
+        path = apply(os.path.join, ext_path)
+        if sys.maxint == 2147483647L:
+            return path + so_ext
+        dirname = os.path.dirname(path);
+        basename = os.path.basename(path);
+        return os.path.join(dirname, "64", basename + so_ext)
 
     def get_export_symbols (self, ext):
         """Return the list of symbols that a shared extension has to
--- Python-2.7.6/Python/import.c.~1~	2013-11-09 23:36:41.000000000 -0800
+++ Python-2.7.6/Python/import.c	2014-05-14 12:53:34.233016586 -0700
@@ -1288,6 +1288,57 @@
 static int find_init_module(char *); /* Forward */
 static struct filedescr importhookdescr = {"", "", IMP_HOOK};
 
+#ifdef HAVE_STAT
+static char *
+insert_64dir(char *buf, size_t buflen)
+{
+       char *base;
+       char *cp;
+       size_t blen;
+
+       if ((blen = strlen(buf)) == 0)
+               return (NULL);
+
+       cp = &buf[blen - 1];
+       while (cp != buf && *cp != SEP)
+               cp--;
+
+       if (cp != buf)
+               cp++;
+
+       if (blen + strlen("64/") + 1 >= buflen)
+               return NULL;
+
+       base = strdup(cp);
+       sprintf(cp, "64%c%s", SEP, base);
+       free(base);
+
+       return buf;
+}
+
+/*
+ * If we're on a 64-bit platform, modify lookups for shared object files.
+ */
+static size_t modify_path(struct filedescr *fdp, char *buf, size_t buflen)
+{
+       struct stat statbuf;
+
+       if (sizeof(void *) != 8)
+               return 0;
+
+       if (stat(buf, &statbuf) == 0 && S_ISDIR(statbuf.st_mode))
+               return 0;
+
+       if (fdp->type != C_EXTENSION)
+               return 0;
+
+       if (insert_64dir(buf, buflen) == NULL)
+               return 0;
+
+       return strlen("64/");
+}
+#endif
+
 static struct filedescr *
 find_module(char *fullname, char *subname, PyObject *path, char *buf,
             size_t buflen, FILE **p_fp, PyObject **p_loader)
@@ -1302,11 +1353,10 @@
     static struct filedescr fd_builtin = {"", "", C_BUILTIN};
     static struct filedescr fd_package = {"", "", PKG_DIRECTORY};
     char *name;
-#if defined(PYOS_OS2)
     size_t saved_len;
     size_t saved_namelen;
     char *saved_buf = NULL;
-#endif
+
     if (p_loader != NULL)
         *p_loader = NULL;
 
@@ -1513,15 +1563,17 @@
                 }
             }
         }
-#if defined(PYOS_OS2)
         /* take a snapshot of the module spec for restoration
          * after the 8 character DLL hackery
          */
         saved_buf = strdup(buf);
         saved_len = len;
         saved_namelen = namelen;
-#endif /* PYOS_OS2 */
+
         for (fdp = _PyImport_Filetab; fdp->suffix != NULL; fdp++) {
+#ifdef HAVE_STAT
+            len += modify_path(fdp, buf, buflen);
+#endif
 #if defined(PYOS_OS2) && defined(HAVE_DYNAMIC_LOADING)
             /* OS/2 limits DLLs to 8 character names (w/o
                extension)
@@ -1562,21 +1614,20 @@
                     fp = NULL;
                 }
             }
-#if defined(PYOS_OS2)
+
             /* restore the saved snapshot */
             strcpy(buf, saved_buf);
             len = saved_len;
             namelen = saved_namelen;
-#endif
         }
-#if defined(PYOS_OS2)
+
         /* don't need/want the module name snapshot anymore */
         if (saved_buf)
         {
             free(saved_buf);
             saved_buf = NULL;
         }
-#endif
+
         Py_XDECREF(copy);
         if (fp != NULL)
             break;
--- Python-2.7.1/Python/importdl.h.orig	Fri Jul 15 15:48:16 2011
+++ Python-2.7.1/Python/importdl.h	Fri Jul 15 15:49:10 2011
@@ -31,8 +31,9 @@
 extern PyObject *_PyImport_LoadDynamicModule(char *name, char *pathname,
                                              FILE *);
 
-/* Max length of module suffix searched for -- accommodates "module.slb" */
-#define MAXSUFFIXSIZE 12
+/* Max length of module suffix searched for -- accommodates "module.slb"
+   and '64/' */
+#define MAXSUFFIXSIZE 15
 
 #ifdef MS_WINDOWS
 #include <windows.h>