components/python/python27/patches/04-solaris-64-bit.patch
author Rich Burridge <rich.burridge@oracle.com>
Tue, 02 May 2017 17:33:26 -0700
changeset 7964 d9801318ed3d
parent 7516 09c933391a1b
permissions -rw-r--r--
25981468 Build ilmbase and openexr with the GNU compilers

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
@@ -637,6 +637,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 :
@@ -677,7 +681,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.12/Python/import.c.~1~	2016-06-25 14:49:32.000000000 -0700
+++ Python-2.7.12/Python/import.c	2016-07-07 13:43:53.807164009 -0700
@@ -1310,6 +1310,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)
@@ -1324,11 +1375,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;
 
@@ -1535,15 +1585,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)
@@ -1584,21 +1636,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>