Skip to content

Commit

Permalink
Disable thread-local cleanup on 32-bit MacOS PPC with GCC. This will …
Browse files Browse the repository at this point in the history
…result in some test failures on that platform, but hopefully solves a crash we were never able to debug when using multiple threads. This is only tested on pre-release versions of an OS that was never released using a compiler available from MacPorts.
  • Loading branch information
jamadden committed Sep 20, 2024
1 parent e9db22a commit ab8d3bc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
<https://github.com/python-greenlet/greenlet/issues/422>`_.
- Remove unnecessary logging sometimes during interpreter shutdown.
See `issue 426 <https://github.com/python-greenlet/greenlet/issues/426>`_.
- Fix some crashes on 32-bit PPC MacOS. This is a very old platform,
and is only known to be tested on beta versions of an operating
system that was never released, using the GCC 14 only provided by
MacPorts; it may or may not work on the final MacOS X release that
supported 32-bit PowerPC. It has the known issue of leaking memory
when greenlets are used in multiple threads. Help debugging this
would be appreciated. See `PR 419
<https://github.com/python-greenlet/greenlet/pull/419>`_.

3.1.0 (2024-09-10)
==================
Expand Down
4 changes: 4 additions & 0 deletions src/greenlet/TThreadStateDestroy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "greenlet_thread_support.hpp"
#include "greenlet_cpython_add_pending.hpp"
#include "greenlet_compiler_compat.hpp"
#include "TGreenletGlobals.cpp"
#include "TThreadState.hpp"
#include "TThreadStateCreator.hpp"
Expand All @@ -32,6 +33,9 @@ struct ThreadState_DestroyNoGIL
static void
MarkGreenletDeadAndQueueCleanup(ThreadState* const state)
{
#if GREENLET_BROKEN_THREAD_LOCAL_CLEANUP_JUST_LEAK
return;
#endif
// We are *NOT* holding the GIL. Our thread is in the middle
// of its death throes and the Python thread state is already
// gone so we can't use most Python APIs. One that is safe is
Expand Down
11 changes: 11 additions & 0 deletions src/greenlet/greenlet_compiler_compat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,16 @@
# define G_NOEXCEPT_WIN32
#endif

#if defined(__GNUC__) && defined(__POWERPC__) && defined(__APPLE__)
// 32-bit PPC/MacOSX. Only known to be tested on unreleased versions
// of macOS 10.6 using a macports build gcc 14. It appears that
// running C++ destructors of thread-local variables is broken.

// See https://github.com/python-greenlet/greenlet/pull/419
# define GREENLET_BROKEN_THREAD_LOCAL_CLEANUP_JUST_LEAK 1
#else
# define GREENLET_BROKEN_THREAD_LOCAL_CLEANUP_JUST_LEAK 0
#endif


#endif
2 changes: 1 addition & 1 deletion src/greenlet/slp_platformselect.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extern "C" {
#elif defined(__GNUC__) && defined(__PPC__) && (defined(__linux__) || defined(__FreeBSD__))
# include "platform/switch_ppc_linux.h" /* gcc on PowerPC */
#elif defined(__GNUC__) && defined(__POWERPC__) && defined(__APPLE__)
# include "platform/switch_ppc_macosx.h" /* Apple MacOS X on PowerPC */
# include "platform/switch_ppc_macosx.h" /* Apple MacOS X on 32-bit PowerPC */
#elif defined(__GNUC__) && defined(__powerpc64__) && defined(_AIX)
# include "platform/switch_ppc64_aix.h" /* gcc on AIX/PowerPC 64-bit */
#elif defined(__GNUC__) && defined(_ARCH_PPC) && defined(_AIX)
Expand Down

0 comments on commit ab8d3bc

Please sign in to comment.