Blame SOURCES/00112-2.7.13-debug-build.patch

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