churchyard / rpms / python2

Forked from rpms/python2 6 years ago
Clone
2027616
From 898f93aa206e577dfe854c59bc62d0cea09cd5ed Mon Sep 17 00:00:00 2001
2027616
From: Tomas Orsava <torsava@redhat.com>
2027616
Date: Tue, 10 Jan 2017 16:19:50 +0100
2027616
Subject: [PATCH] Patch to support building both optimized vs debug stacks DSO
2027616
 ABIs,
2027616
2027616
sharing the same .py and .pyc files, using "_d.so" to signify a debug build of
2027616
an extension module.
2027616
---
2027616
 Lib/distutils/command/build_ext.py  |  7 ++++-
2027616
 Lib/distutils/sysconfig.py          |  5 ++--
2027616
 Lib/distutils/tests/test_install.py |  3 +-
2027616
 Makefile.pre.in                     | 56 ++++++++++++++++++++-----------------
2027616
 Misc/python-config.in               |  2 +-
2027616
 Modules/makesetup                   |  2 +-
2027616
 Python/dynload_shlib.c              | 11 ++++++--
2027616
 Python/sysmodule.c                  |  6 ++++
2027616
 configure.ac                        | 14 ++++++++--
2027616
 9 files changed, 69 insertions(+), 37 deletions(-)
2027616
31c5334
diff --git a/Lib/distutils/command/build_ext.py b/Lib/distutils/command/build_ext.py
2027616
index 2c68be3..029d144 100644
31c5334
--- a/Lib/distutils/command/build_ext.py
31c5334
+++ b/Lib/distutils/command/build_ext.py
2027616
@@ -677,7 +677,10 @@ class build_ext (Command):
f020abd
         so_ext = get_config_var('SO')
f020abd
         if os.name == 'nt' and self.debug:
c6247fd
             return os.path.join(*ext_path) + '_d' + so_ext
f020abd
-        return os.path.join(*ext_path) + so_ext
31c5334
+        
f020abd
+        # Similarly, extensions in debug mode are named 'module_d.so', to
f020abd
+        # avoid adding the _d to the SO config variable:
f020abd
+        return os.path.join(*ext_path) + (sys.pydebug and "_d" or "") + so_ext
f020abd
 
f020abd
     def get_export_symbols (self, ext):
f020abd
         """Return the list of symbols that a shared extension has to
2027616
@@ -762,6 +765,8 @@ class build_ext (Command):
f020abd
                 template = "python%d.%d"
f020abd
                 pythonlib = (template %
f020abd
                              (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
f020abd
+                if sys.pydebug:
f020abd
+                    pythonlib += '_d'
f020abd
                 return ext.libraries + [pythonlib]
f020abd
             else:
f020abd
                 return ext.libraries
31c5334
diff --git a/Lib/distutils/sysconfig.py b/Lib/distutils/sysconfig.py
2027616
index 3e7f077..ec5d584 100644
31c5334
--- a/Lib/distutils/sysconfig.py
31c5334
+++ b/Lib/distutils/sysconfig.py
31c5334
@@ -90,7 +90,8 @@ def get_python_inc(plat_specific=0, prefix=None):
c6247fd
                 # Include is located in the srcdir
c6247fd
                 inc_dir = os.path.join(srcdir, "Include")
f020abd
             return inc_dir
f020abd
-        return os.path.join(prefix, "include", "python" + get_python_version())
f020abd
+        return os.path.join(prefix, "include",
31c5334
+            "python" + get_python_version() + (sys.pydebug and '-debug' or ''))
f020abd
     elif os.name == "nt":
f020abd
         return os.path.join(prefix, "include")
c6247fd
     elif os.name == "os2":
2027616
@@ -248,7 +249,7 @@ def get_makefile_filename():
f020abd
     if python_build:
43e7c42
         return os.path.join(project_base, "Makefile")
f020abd
     lib_dir = get_python_lib(plat_specific=1, standard_lib=1)
f020abd
-    return os.path.join(lib_dir, "config", "Makefile")
f020abd
+    return os.path.join(lib_dir, "config" + (sys.pydebug and "-debug" or ""), "Makefile")
f020abd
 
f020abd
 
f020abd
 def parse_config_h(fp, g=None):
31c5334
diff --git a/Lib/distutils/tests/test_install.py b/Lib/distutils/tests/test_install.py
31c5334
index 78fac46..d1d0931 100644
31c5334
--- a/Lib/distutils/tests/test_install.py
31c5334
+++ b/Lib/distutils/tests/test_install.py
b0a6ae1
@@ -20,8 +20,9 @@ from distutils.tests import support
b0a6ae1
 
b0a6ae1
 
b0a6ae1
 def _make_ext_name(modname):
b0a6ae1
-    if os.name == 'nt' and sys.executable.endswith('_d.exe'):
b0a6ae1
+    if sys.pydebug:
b0a6ae1
         modname += '_d'
31c5334
+        
b0a6ae1
     return modname + sysconfig.get_config_var('SO')
b0a6ae1
 
b0a6ae1
 
31c5334
diff --git a/Makefile.pre.in b/Makefile.pre.in
2027616
index 997a2fc..467e782 100644
31c5334
--- a/Makefile.pre.in
31c5334
+++ b/Makefile.pre.in
2027616
@@ -116,8 +116,8 @@ SCRIPTDIR=	$(prefix)/lib64
f020abd
 # Detailed destination directories
f020abd
 BINLIBDEST=	$(LIBDIR)/python$(VERSION)
f020abd
 LIBDEST=	$(SCRIPTDIR)/python$(VERSION)
f020abd
-INCLUDEPY=	$(INCLUDEDIR)/python$(VERSION)
f020abd
-CONFINCLUDEPY=	$(CONFINCLUDEDIR)/python$(VERSION)
f020abd
+INCLUDEPY=	$(INCLUDEDIR)/python$(VERSION)$(DEBUG_SUFFIX)
f020abd
+CONFINCLUDEPY=	$(CONFINCLUDEDIR)/python$(VERSION)$(DEBUG_SUFFIX)
f020abd
 LIBP=		$(LIBDIR)/python$(VERSION)
f020abd
 
f020abd
 # Symbols used for using shared libraries
31c5334
@@ -131,6 +131,12 @@ DESTSHARED=	$(BINLIBDEST)/lib-dynload
f020abd
 EXE=		@EXEEXT@
f020abd
 BUILDEXE=	@BUILDEXEEXT@
f020abd
 
f020abd
+# DEBUG_EXT is used by ELF files (names and SONAMEs); it will be "_d" for a debug build
f020abd
+# DEBUG_SUFFIX is used by filesystem paths; it will be "-debug" for a debug build
f020abd
+# Both will be empty in an optimized build
f020abd
+DEBUG_EXT=	@DEBUG_EXT@
f020abd
+DEBUG_SUFFIX=	@DEBUG_SUFFIX@
f020abd
+
f020abd
 # Short name and location for Mac OS X Python framework
f020abd
 UNIVERSALSDK=@UNIVERSALSDK@
f020abd
 PYTHONFRAMEWORK=	@PYTHONFRAMEWORK@
31c5334
@@ -197,8 +203,8 @@ LIBOBJDIR=	Python/
f020abd
 LIBOBJS=	@LIBOBJS@
f020abd
 UNICODE_OBJS=   @UNICODE_OBJS@
f020abd
 
f020abd
-PYTHON=		python$(EXE)
f020abd
-BUILDPYTHON=	python$(BUILDEXE)
f020abd
+PYTHON=		python$(DEBUG_SUFFIX)$(EXE)
f020abd
+BUILDPYTHON=	python$(DEBUG_SUFFIX)$(BUILDEXE)
f020abd
 
Iryna Shcherbina 9db4c32
 PYTHON_FOR_REGEN=@PYTHON_FOR_REGEN@
43e7c42
 PYTHON_FOR_BUILD=@PYTHON_FOR_BUILD@
2027616
@@ -547,7 +553,7 @@ sharedmods: $(BUILDPYTHON) pybuilddir.txt Modules/_math.o
cc95a97
 		_TCLTK_INCLUDES='$(TCLTK_INCLUDES)' _TCLTK_LIBS='$(TCLTK_LIBS)' \
43e7c42
 		$(PYTHON_FOR_BUILD) $(srcdir)/setup.py $$quiet build
f020abd
 
f020abd
-libpython$(VERSION).so: $(LIBRARY_OBJS)
f020abd
+libpython$(VERSION)$(DEBUG_EXT).so: $(LIBRARY_OBJS)
f020abd
 	if test $(INSTSONAME) != $(LDLIBRARY); then \
b0a6ae1
 		$(BLDSHARED) -Wl,-h$(INSTSONAME) -o $(INSTSONAME) $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
f020abd
 		$(LN) -f $(INSTSONAME) $@; \
2027616
@@ -954,18 +960,18 @@ bininstall:	altbininstall
9345b0f
 	then rm -f $(DESTDIR)$(BINDIR)/$(PYTHON); \
9345b0f
 	else true; \
f020abd
 	fi
9345b0f
-	(cd $(DESTDIR)$(BINDIR); $(LN) -s python2$(EXE) $(PYTHON))
9345b0f
-	-rm -f $(DESTDIR)$(BINDIR)/python2$(EXE)
b0a6ae1
-	(cd $(DESTDIR)$(BINDIR); $(LN) -s python$(VERSION)$(EXE) python2$(EXE))
9345b0f
-	-rm -f $(DESTDIR)$(BINDIR)/python2-config
b0a6ae1
-	(cd $(DESTDIR)$(BINDIR); $(LN) -s python$(VERSION)-config python2-config)
b0a6ae1
-	-rm -f $(DESTDIR)$(BINDIR)/python-config
9345b0f
-	(cd $(DESTDIR)$(BINDIR); $(LN) -s python2-config python-config)
9345b0f
+	(cd $(DESTDIR)$(BINDIR); $(LN) -s python2$(DEBUG_SUFFIX)$(EXE) $(PYTHON))
9345b0f
+	-rm -f $(DESTDIR)$(BINDIR)/python2$(DEBUG_SUFFIX)$(EXE)
9345b0f
+	(cd $(DESTDIR)$(BINDIR); $(LN) -s python$(VERSION)$(DEBUG_SUFFIX)$(EXE) python2$(DEBUG_SUFFIX)$(EXE))
9345b0f
+	-rm -f $(DESTDIR)$(BINDIR)/python2$(DEBUG_SUFFIX)-config
9345b0f
+	(cd $(DESTDIR)$(BINDIR); $(LN) -s python$(VERSION)$(DEBUG_SUFFIX)-config python2$(DEBUG_SUFFIX)-config)
9345b0f
+	-rm -f $(DESTDIR)$(BINDIR)/python$(DEBUG_SUFFIX)-config
9345b0f
+	(cd $(DESTDIR)$(BINDIR); $(LN) -s python2$(DEBUG_SUFFIX)-config python$(DEBUG_SUFFIX)-config)
c6247fd
 	-test -d $(DESTDIR)$(LIBPC) || $(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$(LIBPC)
9345b0f
-	-rm -f $(DESTDIR)$(LIBPC)/python2.pc
9345b0f
-	(cd $(DESTDIR)$(LIBPC); $(LN) -s python-$(VERSION).pc python2.pc)
9345b0f
-	-rm -f $(DESTDIR)$(LIBPC)/python.pc
9345b0f
-	(cd $(DESTDIR)$(LIBPC); $(LN) -s python2.pc python.pc)
9345b0f
+	-rm -f $(DESTDIR)$(LIBPC)/python2$(DEBUG_SUFFIX).pc
9345b0f
+	(cd $(DESTDIR)$(LIBPC); $(LN) -s python-$(VERSION)$(DEBUG_SUFFIX).pc python2$(DEBUG_SUFFIX).pc)
9345b0f
+	-rm -f $(DESTDIR)$(LIBPC)/python$(DEBUG_SUFFIX).pc
9345b0f
+	(cd $(DESTDIR)$(LIBPC); $(LN) -s python2$(DEBUG_SUFFIX).pc python$(DEBUG_SUFFIX).pc)
9345b0f
 
9345b0f
 # Install the interpreter with $(VERSION) affixed
9345b0f
 # This goes into $(exec_prefix)
2027616
@@ -978,7 +984,7 @@ altbininstall:	$(BUILDPYTHON)
f020abd
 		else	true; \
f020abd
 		fi; \
f020abd
 	done
f020abd
-	$(INSTALL_PROGRAM) $(BUILDPYTHON) $(DESTDIR)$(BINDIR)/python$(VERSION)$(EXE)
f020abd
+	$(INSTALL_PROGRAM) $(BUILDPYTHON) $(DESTDIR)$(BINDIR)/python$(VERSION)$(DEBUG_SUFFIX)$(EXE)
f020abd
 	if test -f $(LDLIBRARY); then \
f020abd
 		if test -n "$(DLLLIBRARY)" ; then \
f020abd
 			$(INSTALL_SHARED) $(DLLLIBRARY) $(DESTDIR)$(BINDIR); \
2027616
@@ -1148,10 +1154,11 @@ $(srcdir)/Lib/$(PLATDIR):
43e7c42
 	fi; \
c6247fd
 	cd $(srcdir)/Lib/$(PLATDIR); $(RUNSHARED) ./regen
c6247fd
 
c6247fd
-python-config: $(srcdir)/Misc/python-config.in
c6247fd
+python$(DEBUG_SUFFIX)-config: $(srcdir)/Misc/python-config.in
c6247fd
 	# Substitution happens here, as the completely-expanded BINDIR
c6247fd
 	# is not available in configure
c6247fd
-	sed -e "s,@EXENAME@,$(BINDIR)/python$(VERSION)$(EXE)," < $(srcdir)/Misc/python-config.in >python-config
c6247fd
+	sed -e "s,@EXENAME@,$(BINDIR)/python$(VERSION)$(DEBUG_SUFFIX)$(EXE)," < $(srcdir)/Misc/python-config.in >python$(DEBUG_SUFFIX)-config
31c5334
+	
c6247fd
 
c6247fd
 # Install the include files
c6247fd
 INCLDIRSTOMAKE=$(INCLUDEDIR) $(CONFINCLUDEDIR) $(INCLUDEPY) $(CONFINCLUDEPY)
2027616
@@ -1172,13 +1179,13 @@ inclinstall:
f020abd
 	$(INSTALL_DATA) pyconfig.h $(DESTDIR)$(CONFINCLUDEPY)/pyconfig.h
f020abd
 
f020abd
 # Install the library and miscellaneous stuff needed for extending/embedding
f020abd
-# This goes into $(exec_prefix)
f020abd
-LIBPL=		$(LIBP)/config
f020abd
+# This goes into $(exec_prefix)$(DEBUG_SUFFIX)
f020abd
+LIBPL=		$(LIBP)/config$(DEBUG_SUFFIX)
c6247fd
 
c6247fd
 # pkgconfig directory
c6247fd
 LIBPC=		$(LIBDIR)/pkgconfig
c6247fd
 
Iryna Shcherbina 9db4c32
-libainstall:	@DEF_MAKE_RULE@ python-config
Iryna Shcherbina 9db4c32
+libainstall:	@DEF_MAKE_RULE@ python$(DEBUG_SUFFIX)-config
c6247fd
 	@for i in $(LIBDIR) $(LIBP) $(LIBPL) $(LIBPC); \
f020abd
 	do \
c6247fd
 		if test ! -d $(DESTDIR)$$i; then \
2027616
@@ -1194,11 +1201,10 @@ libainstall:	all python-config
9345b0f
 	$(INSTALL_DATA) Modules/Setup $(DESTDIR)$(LIBPL)/Setup
9345b0f
 	$(INSTALL_DATA) Modules/Setup.local $(DESTDIR)$(LIBPL)/Setup.local
9345b0f
 	$(INSTALL_DATA) Modules/Setup.config $(DESTDIR)$(LIBPL)/Setup.config
9345b0f
-	$(INSTALL_DATA) Misc/python.pc $(DESTDIR)$(LIBPC)/python-$(VERSION).pc
9345b0f
+	$(INSTALL_DATA) Misc/python.pc $(DESTDIR)$(LIBPC)/python-$(VERSION)$(DEBUG_SUFFIX).pc
c6247fd
 	$(INSTALL_SCRIPT) $(srcdir)/Modules/makesetup $(DESTDIR)$(LIBPL)/makesetup
f020abd
 	$(INSTALL_SCRIPT) $(srcdir)/install-sh $(DESTDIR)$(LIBPL)/install-sh
f020abd
-	$(INSTALL_SCRIPT) python-config $(DESTDIR)$(BINDIR)/python$(VERSION)-config
f020abd
-	rm python-config
f020abd
+	$(INSTALL_SCRIPT) python$(DEBUG_SUFFIX)-config $(DESTDIR)$(BINDIR)/python$(VERSION)$(DEBUG_SUFFIX)-config
f020abd
 	@if [ -s Modules/python.exp -a \
f020abd
 		"`echo $(MACHDEP) | sed 's/^\(...\).*/\1/'`" = "aix" ]; then \
f020abd
 		echo; echo "Installing support files for building shared extension modules on AIX:"; \
31c5334
diff --git a/Misc/python-config.in b/Misc/python-config.in
31c5334
index a09e07c..c1691ef 100644
31c5334
--- a/Misc/python-config.in
31c5334
+++ b/Misc/python-config.in
31c5334
@@ -44,7 +44,7 @@ for opt in opt_flags:
Matej Stuchlik b1e5a42
         print ' '.join(flags)
c6247fd
 
c6247fd
     elif opt in ('--libs', '--ldflags'):
Matej Stuchlik b1e5a42
-        libs = ['-lpython' + pyver]
Matej Stuchlik b1e5a42
+        libs = ['-lpython' + pyver + (sys.pydebug and "_d" or "")]
Matej Stuchlik b1e5a42
         libs += getvar('LIBS').split()
Matej Stuchlik b1e5a42
         libs += getvar('SYSLIBS').split()
c6247fd
         # add the prefix/lib/pythonX.Y/config dir, but only if there is no
31c5334
diff --git a/Modules/makesetup b/Modules/makesetup
2027616
index 1bffcbf..f0bc743 100755
31c5334
--- a/Modules/makesetup
31c5334
+++ b/Modules/makesetup
f020abd
@@ -233,7 +233,7 @@ sed -e 's/[ 	]*#.*//' -e '/^[ 	]*$/d' |
f020abd
 			*$mod.o*)	base=$mod;;
f020abd
 			*)		base=${mod}module;;
f020abd
 			esac
f020abd
-			file="$srcdir/$base\$(SO)"
f020abd
+			file="$srcdir/$base\$(DEBUG_EXT)\$(SO)"
f020abd
 			case $doconfig in
f020abd
 			no)	SHAREDMODS="$SHAREDMODS $file";;
f020abd
 			esac
31c5334
diff --git a/Python/dynload_shlib.c b/Python/dynload_shlib.c
31c5334
index 17ebab1..02a94aa 100644
31c5334
--- a/Python/dynload_shlib.c
31c5334
+++ b/Python/dynload_shlib.c
31c5334
@@ -46,11 +46,16 @@ const struct filedescr _PyImport_DynLoadFiletab[] = {
c6247fd
     {"module.exe", "rb", C_EXTENSION},
c6247fd
     {"MODULE.EXE", "rb", C_EXTENSION},
f020abd
 #else
f020abd
+#ifdef Py_DEBUG
c6247fd
+    {"_d.so", "rb", C_EXTENSION},
c6247fd
+    {"module_d.so", "rb", C_EXTENSION},
f020abd
+#else
c6247fd
     {".so", "rb", C_EXTENSION},
c6247fd
     {"module.so", "rb", C_EXTENSION},
f020abd
-#endif
f020abd
-#endif
f020abd
-#endif
f020abd
+#endif /* Py_DEBUG */
f020abd
+#endif /* __VMS */
f020abd
+#endif /* defined(PYOS_OS2) && defined(PYCC_GCC) */
f020abd
+#endif /* __CYGWIN__ */
c6247fd
     {0, 0}
f020abd
 };
f020abd
 
31c5334
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
2027616
index aeff38a..183e3cc 100644
31c5334
--- a/Python/sysmodule.c
31c5334
+++ b/Python/sysmodule.c
2027616
@@ -1524,6 +1524,12 @@ _PySys_Init(void)
c6247fd
                         PyString_FromString("legacy"));
c6247fd
 #endif
f020abd
 
f020abd
+#ifdef Py_DEBUG
31c5334
+    PyDict_SetItemString(sysdict, "pydebug", Py_True);
f020abd
+#else
31c5334
+    PyDict_SetItemString(sysdict, "pydebug", Py_False);
f020abd
+#endif
f020abd
+
f020abd
 #undef SET_SYS_FROM_STRING
c6247fd
     if (PyErr_Occurred())
c6247fd
         return NULL;
31c5334
diff --git a/configure.ac b/configure.ac
2027616
index 0a902c7..5caedb7 100644
31c5334
--- a/configure.ac
31c5334
+++ b/configure.ac
2027616
@@ -764,7 +764,7 @@ AC_SUBST(LIBRARY)
cc95a97
 AC_MSG_CHECKING(LIBRARY)
cc95a97
 if test -z "$LIBRARY"
cc95a97
 then
cc95a97
-	LIBRARY='libpython$(VERSION).a'
cc95a97
+	LIBRARY='libpython$(VERSION)$(DEBUG_EXT).a'
cc95a97
 fi
cc95a97
 AC_MSG_RESULT($LIBRARY)
cc95a97
 
2027616
@@ -910,8 +910,8 @@ if test $enable_shared = "yes"; then
cc95a97
 	  INSTSONAME="$LDLIBRARY".$SOVERSION
cc95a97
           ;;
cc95a97
     Linux*|GNU*|NetBSD*|FreeBSD*|DragonFly*|OpenBSD*)
cc95a97
-	  LDLIBRARY='libpython$(VERSION).so'
cc95a97
-	  BLDLIBRARY='-L. -lpython$(VERSION)'
cc95a97
+	  LDLIBRARY='libpython$(VERSION)$(DEBUG_EXT).so'
cc95a97
+	  BLDLIBRARY='-L. -lpython$(VERSION)$(DEBUG_EXT)'
Matej Stuchlik ebcba88
 	  RUNSHARED=LD_LIBRARY_PATH=`pwd`${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
cc95a97
 	  case $ac_sys_system in
cc95a97
 	      FreeBSD*)
2027616
@@ -1040,6 +1040,14 @@ else AC_MSG_RESULT(no); Py_DEBUG='false'
cc95a97
 fi],
cc95a97
 [AC_MSG_RESULT(no)])
cc95a97
 
cc95a97
+if test "$Py_DEBUG" = 'true'
cc95a97
+then
cc95a97
+	DEBUG_EXT=_d
cc95a97
+	DEBUG_SUFFIX=-debug
cc95a97
+fi
cc95a97
+AC_SUBST(DEBUG_EXT)
cc95a97
+AC_SUBST(DEBUG_SUFFIX)
cc95a97
+
cc95a97
 # XXX Shouldn't the code above that fiddles with BASECFLAGS and OPT be
cc95a97
 # merged with this chunk of code?
cc95a97
 
2027616
-- 
2027616
2.11.0
2027616