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

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