Blame SOURCES/python-2.7.3-debug-build.patch

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