Skip to content

Commit

Permalink
bpo-36465: Make release and debug ABI compatible (GH-12615)
Browse files Browse the repository at this point in the history
Release build and debug build are now ABI compatible: the Py_DEBUG
define no longer implies Py_TRACE_REFS define which introduces the
only ABI incompatibility.

A new "./configure --with-trace-refs" build option is now required to
get Py_TRACE_REFS define which adds sys.getobjects() function and
PYTHONDUMPREFS environment variable.

Changes:

* Add ./configure --with-trace-refs
* Py_DEBUG no longer implies Py_TRACE_REFS
  • Loading branch information
vstinner authored Apr 24, 2019
1 parent 888f37b commit f4e4703
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 14 deletions.
7 changes: 5 additions & 2 deletions Doc/using/cmdline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -922,15 +922,18 @@ conflict.
Debug-mode variables
~~~~~~~~~~~~~~~~~~~~

Setting these variables only has an effect in a debug build of Python, that is,
if Python was configured with the ``--with-pydebug`` build option.
Setting these variables only has an effect in a debug build of Python.

.. envvar:: PYTHONTHREADDEBUG

If set, Python will print threading debug info.

Need Python configured with the ``--with-pydebug`` build option.


.. envvar:: PYTHONDUMPREFS

If set, Python will dump objects and reference counts still alive after
shutting down the interpreter.

Need Python configured with the ``--with-trace-refs`` build option.
9 changes: 2 additions & 7 deletions Include/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,8 @@ A standard interface exists for objects that contain an array of items
whose size is determined when the object is allocated.
*/

/* Py_DEBUG implies Py_TRACE_REFS. */
#if defined(Py_DEBUG) && !defined(Py_TRACE_REFS)
#define Py_TRACE_REFS
#endif

/* Py_TRACE_REFS implies Py_REF_DEBUG. */
#if defined(Py_TRACE_REFS) && !defined(Py_REF_DEBUG)
/* Py_DEBUG implies Py_REF_DEBUG. */
#if defined(Py_DEBUG) && !defined(Py_REF_DEBUG)
#define Py_REF_DEBUG
#endif

Expand Down
2 changes: 1 addition & 1 deletion Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1653,7 +1653,7 @@ def python_is_optimized():

_header = 'nP'
_align = '0n'
if hasattr(sys, "gettotalrefcount"):
if hasattr(sys, "getobjects"):
_header = '2P' + _header
_align = '0P'
_vheader = _header + 'n'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Release build and debug build are now ABI compatible: the ``Py_DEBUG`` define
no longer implies ``Py_TRACE_REFS`` define which introduces the only ABI
incompatibility. A new ``./configure --with-trace-refs`` build option is now
required to get ``Py_TRACE_REFS`` define which adds :func:`sys.getobjects`
function and ``PYTHONDUMPREFS`` environment variable.
28 changes: 26 additions & 2 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,7 @@ with_suffix
enable_shared
enable_profiling
with_pydebug
with_trace_refs
with_assertions
enable_optimizations
with_lto
Expand Down Expand Up @@ -1500,6 +1501,7 @@ Optional Packages:
compiler
--with-suffix=.exe set executable suffix
--with-pydebug build with Py_DEBUG defined
--with-trace-refs enable tracing references for debugging purpose
--with-assertions build with C assertions enabled
--with-lto Enable Link Time Optimization in any build. Disabled
by default.
Expand Down Expand Up @@ -6333,8 +6335,30 @@ $as_echo "no" >&6; }
fi


# Check for --with-assertions. Py_DEBUG implies assertions, but also changes
# the ABI. This allows enabling assertions without changing the ABI.
# Check for --with-trace-refs
# --with-trace-refs
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-trace-refs" >&5
$as_echo_n "checking for --with-trace-refs... " >&6; }

# Check whether --with-trace-refs was given.
if test "${with_trace_refs+set}" = set; then :
withval=$with_trace_refs;
else
with_trace_refs=no
fi

{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_trace_refs" >&5
$as_echo "$with_trace_refs" >&6; }

if test "$with_trace_refs" = "yes"
then

$as_echo "#define Py_TRACE_REFS 1" >>confdefs.h

fi

# Check for --with-assertions.
# This allows enabling assertions without Py_DEBUG.
assertions='false'
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-assertions" >&5
$as_echo_n "checking for --with-assertions... " >&6; }
Expand Down
17 changes: 15 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1228,8 +1228,21 @@ else AC_MSG_RESULT(no); Py_DEBUG='false'
fi],
[AC_MSG_RESULT(no)])

# Check for --with-assertions. Py_DEBUG implies assertions, but also changes
# the ABI. This allows enabling assertions without changing the ABI.
# Check for --with-trace-refs
# --with-trace-refs
AC_MSG_CHECKING(for --with-trace-refs)
AC_ARG_WITH(trace-refs,
AS_HELP_STRING([--with-trace-refs],[enable tracing references for debugging purpose]),,
with_trace_refs=no)
AC_MSG_RESULT($with_trace_refs)

if test "$with_trace_refs" = "yes"
then
AC_DEFINE(Py_TRACE_REFS, 1, [Define if you want to enable tracing references for debugging purpose])
fi

# Check for --with-assertions.
# This allows enabling assertions without Py_DEBUG.
assertions='false'
AC_MSG_CHECKING(for --with-assertions)
AC_ARG_WITH(assertions,
Expand Down
3 changes: 3 additions & 0 deletions pyconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,9 @@
externally defined: 0 */
#undef Py_HASH_ALGORITHM

/* Define if you want to enable tracing references for debugging purpose */
#undef Py_TRACE_REFS

/* assume C89 semantics that RETSIGTYPE is always void */
#undef RETSIGTYPE

Expand Down

0 comments on commit f4e4703

Please sign in to comment.