Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mingw32/64 support #20

Open
gabomdq opened this issue Sep 10, 2012 · 15 comments
Open

Mingw32/64 support #20

gabomdq opened this issue Sep 10, 2012 · 15 comments

Comments

@gabomdq
Copy link

gabomdq commented Sep 10, 2012

I'm using Greenlet in my project which cross compiles from Linux to Windows using Mingw. For Mingw in 32 bit mode it works almost out of the box, but I had to comment out the Visual Studio entries in slp_platformselect.h, so ideally a check for some MINGW flags in the first two entries would be needed, or perhaps a ! defined(_MSC_VER)

Anyway, in 32 bit mode, after commenting out the MSVC entries everything works, switch_x86_unix.h is used, and task switching is flawless AFAICT.

However, in 64 bit mode, when switch_amd64_unix.h is selected, a compilation error is produced:

/tmp/ccFWucFb.s: Assembler messages:
/tmp/ccFWucFb.s:1937: Error: operand type mismatch for add' /tmp/ccFWucFb.s:1938: Error: operand type mismatch foradd'

I've also noticed that switch_x86_unix.h has special ifdef'ed WIN32 sections that are not present in switch_amd64_unix.h, I'm not sure if these are required as well.

@snaury
Copy link
Contributor

snaury commented Sep 10, 2012

@gabomdq I'll check if there's anything broken with latest MinGW versions, but bear in mind that:

  1. 32-bit linux and windows have almost identical ABIs, so switch_x86_unix.h can be used
  2. greenlet was actually ported to MinGW

Unfortunately 64-bit Windows has ABI that is completely different from anything else, hence you'd need a separate port. We've done one for Microsoft Visual C++, but there's no MinGW port at the moment. In 64-bit Windows case you cannot just add features to switch_amd64_unix.h.

Another point is that it's not entirely clear how to setup 64-bit MinGW properly: it doesn't seem to be officially supported and there are several TDM versions, all of which were hard to setup and only half-working last time I tried (admittedly 1 or 2 years ago, so maybe something changed, I haven't rechecked since then).

@gabomdq
Copy link
Author

gabomdq commented Sep 10, 2012

Thanks for the reply. For what it's worth, I'm using Ubuntu's official packages for Mingw, which install through the meta package mingw-w64.

@snaury
Copy link
Contributor

snaury commented Sep 10, 2012

@gabomdq you could try using switch_x64_masm.obj (linking with it should probably work with MinGW, you may have to rename it as switch_x64_mask.o though), then force it to use switch_x64_msvc.h (there should be nothing msvc specific in there) and make sure both MS_WIN64 and _M_X64 are defined, which would probably work.

Also, could you share info on how to replicate your setup? Then I could make a VM here and try to work on it, but I need to know how do you cross-compile Python extensions (do you cross-compile Python, and how?), since I've never done that before.

@gabomdq
Copy link
Author

gabomdq commented Sep 10, 2012

Cool, I'll try it out.

As to my system, I'm using Greenlet in my Python/Cython engine, you can check out the code here: https://bitbucket.org/gabomdq/ignifuga

With a Ubuntu 12.04 64 bits VM, after checking out the code from Bitbucket, you can run (in tools)

./schafer -D

which will install the build dependencies, and then

./schafer -P win32

That will build a Python interpreter inside dist/bin for Win32, which will hold Greenlet among many other things. If you try to run

./schafer -P win64 you'll get an error I just added, but you can comment those lines (starting on line 863 in schafer.py) and it'll proceed until at the very end you get the errors I posted in my first message.

If you look at the external/greenlet sources in there you'll see I patched up the slp_platformselect.h header file to skip the MSVC parts.

@ghost
Copy link

ghost commented Oct 18, 2016

I don't know if my problem belongs to this issue but I am not able to install greenlet via mingw64. Windows shouldn't be the problem because I was able to install it via the Windows console.

I am getting the following messages:

$ pip3 install greenlet
Collecting greenlet
  Downloading http://debieks01.fft-it.de/nexus/repository/pypi/packages/67/62/ca2a95648666eaa2ffeb6a9b3964f21d419ae27f82f2e66b53da5b943fc4/greenlet-0.4.10.zip (82kB)
Installing collected packages: greenlet
  Running setup.py install for greenlet: started
    Running setup.py install for greenlet: finished with status 'error'
    Complete output from command C:/msys64/mingw64/bin/python3.exe -u -c "import setuptools, tokenize;__file__='C:/Users/bo32782/AppData/Local/Temp/pip-build-k0xxhy48/greenlet/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record C:/Users/bo32782/AppData/Local/Temp/pip-myk25fr1-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_ext
    building 'greenlet' extension
    creating build
    creating build/temp.mingw-3.5
    C:\msys64\mingw64\bin/x86_64-w64-mingw32-gcc.exe -Wno-unused-result -Wsign-compare -DNDEBUG -march=x86-64 -mtune=generic -O2 -pipe -fwrapv -D__USE_MINGW_ANSI_STDIO=1 -DNDEBUG -IC:/msys64/mingw64/include/python3.5m -c greenlet.c -o build/temp.mingw-3.5/greenlet.o
    {standard input}: Assembler messages:
    {standard input}:518: Error: operand type mismatch for `add'
    {standard input}:519: Error: operand type mismatch for `add'
    error: command 'C:\\msys64\\mingw64\\bin/x86_64-w64-mingw32-gcc.exe' failed with exit status 1

    ----------------------------------------
Command "C:/msys64/mingw64/bin/python3.exe -u -c "import setuptools, tokenize;__file__='C:/Users/bo32782/AppData/Local/Temp/pip-build-k0xxhy48/greenlet/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record C:/Users/bo32782/AppData/Local/Temp/pip-myk25fr1-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:/Users/bo32782/AppData/Local/Temp/pip-build-k0xxhy48/greenlet/

Seems to be a 64 bit problem to me... Any ideas ?

@snaury
Copy link
Contributor

snaury commented Oct 18, 2016

Sorry, I haven't been using Windows for many years now, and don't know what's currently new with mingw, nobody did a 64-bit mingw port as far as I now. However I'm not sure why you would use it with Python in this day and age anyway? There's Visual C++ for Python: https://www.microsoft.com/en-us/download/details.aspx?id=44266 if you're on 2.7, and latest Visual Studios have Express editions capable of compiling Python extensions. There are binary wheels on PyPI too if you don't want to setup a compiler.

@iongion
Copy link

iongion commented Oct 23, 2016

@snaury it is true it is a hard to see use case, probably will get solved once and for all with with https://msdn.microsoft.com/en-us/commandline/wsl/faq. Now to explain, I for one use Windows as primary workstation and there are some initiatives such as msys2 using pacman that really look promising in bringing the power of homebrew from the mac world to windows people. But there, the transition is much smoother due to their Unix nature. We all understand this is not for production time, this is only for development, that will do the job. I am trying to develop a python-socket-io app and having a lot of UI tools on screen for debugging is really helpful. Windows helps in this area as it is so generous in what exists on the market, you can find a tool for almost any task.

@snaury
Copy link
Contributor

snaury commented Oct 23, 2016

@iongion I'm not sure what you're saying, there are plenty of use cases for Windows and greenlet already works on Windows, both x86 and x64. It's just that there's no x64 port for mingw or cygwin/msys2, so people need to either use a native toolchain, or need to work on a port if it's pressing enough.

If there's a good quality pull request with the port I would gladly accept it. This issue is open for 4 years now and nobody stepped up yet.

@iongion
Copy link

iongion commented Dec 17, 2016

@snaury I would gladly do-it, it just came back for me :) but I have no idea where to start due to the fact that it requires advanced understanding of compilers, platforms and CPU architectures.

Investigating, it fails when running this:

gcc -v -fno-strict-aliasing -march=x86-64 -mtune=generic -O2 -pipe -fwrapv -D__USE_MINGW_ANSI_STDIO=1 -DNDEBUG -DNDEBUG -IW:/SDKs/msys2/mingw64/include/python2.7 -c greenlet.c -o build/temp.mingw-2.7/greenlet.o

with

 W:/SDKs/msys2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../x86_64-w64-mingw32/include
End of search list.
GNU C11 (Rev2, Built by MSYS2 project) version 6.2.0 (x86_64-w64-mingw32)
        compiled by GNU C version 6.2.0, GMP version 6.1.1, MPFR version 3.1.4-p3, MPC version 1.0.3, isl version 0.15
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 94423b12c802d0182374f038ff49eeb8
{standard input}: Assembler messages:
{standard input}:483: Error: operand type mismatch for `add'
{standard input}:484: Error: operand type mismatch for `add'

It seems an ASM issue for this case - but I am unable to identify from what source file

  • Python 2.7.12 64 bit
  • gcc 6.2.0
gcc -v
Using built-in specs.
COLLECT_GCC=W:\SDKs\msys2\mingw64\bin\gcc.exe
COLLECT_LTO_WRAPPER=W:/SDKs/msys2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../gcc-6.2.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include --libexecdir=/mingw64/lib --enable-bootstrap --with-arch=x86-64 --with-tune=generic --enable-languages=c,lto,c++,objc,obj-c++,fortran,ada --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-time=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --disable-isl-version-check --enable-lto --enable-libgomp --disable-multilib --enable-checking=release --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev2, Built by MSYS2 project' --with-bugurl=https://sourceforge.net/projects/msys2 --with-gnu-as --with-gnu-ld
Thread model: posix
gcc version 6.2.0 (Rev2, Built by MSYS2 project)

Any tips on where to start looking ?

@ghost
Copy link

ghost commented May 24, 2017

I met this issue while installing bpython via pip3 install bpython under msys2/mingw64. I built it, but no way sure I am that it really works (but tests passed OK).

For readers who try to install bpython: it's probably not worth it, since bpython requires fcntl and termios anyway. These are missing on windows by design, because of unability to port from unix.

I substituted fcntl via hack and could dig further, but lost all courage on the way. I had to go ahead or to write this comment. Sorry.


For other people who are curious about how to compile greenlet-0.4.12 under msys2/mingw64, here it is:

All following command go into your mingw64 shell:

$ cd ~
$ pip3 download greenlet
$ tar xzf greenlet-0.4.12.tar.gz

Apply this patch for greenlet-0.4.12/greenlet.c:

--- greenlet-0.4.12/greenlet.c  2017-02-01 22:43:08 +0300
+++ greenlet-0.4.12-n/greenlet.c        2017-05-24 05:01:49 +0300
@@ -1,5 +1,6 @@
 /* vim:set noet ts=8 sw=8 : */

+#define EXTERNAL_ASM
 #define GREENLET_MODULE

 #include "greenlet.h"

Apply this patch for greenlet-0.4.12/platform/switch_amd64_unix.h:

--- greenlet-0.4.12/platform/switch_amd64_unix.h        2016-12-11 02:52:06 +0300
+++ greenlet-0.4.12-n/platform/switch_amd64_unix.h      2017-05-24 05:02:03 +0300
@@ -44,7 +44,8 @@
     void* rbx;
     unsigned int csr;
     unsigned short cw;
-    register long *stackref, stsizediff;
+    register long *stackref;
+    register long long stsizediff;
     __asm__ volatile ("" : : : REGS_TO_SAVE);
     __asm__ volatile ("fstcw %0" : "=m" (cw));
     __asm__ volatile ("stmxcsr %0" : "=m" (csr));

Patches are trivial; if you don't know how to patch, edit sources by hand.

Let's test it (optional):

$ cd ~/greenlet-0.4.12
$ python3 setup.py test
...
Ran 63 tests in 0.791s

OK

Pack it back and install by hand:

$ cd ~
$ rm greenlet-0.4.12.tar.gz
$ tar czf greenlet-0.4.12.tar.gz greenlet-0.4.12
$ pip3 install greenlet-0.4.12.tar.gz              # we pass filename, not package name

To greenlet authors: the issue, if it resolved right, seems to be much simpler than...

In 64-bit Windows case you cannot just add features to switch_amd64_unix.h.

Another point is that it's not entirely clear how to setup 64-bit MinGW properly: it doesn't seem to be officially supported and there are several TDM versions, all of which were hard to setup and only half-working last time I tried (admittedly 1 or 2 years ago, so maybe something changed, I haven't rechecked since then).

Maybe I simply passed tests through scariest ABI UB ever, I can't tell. Changes were obvious:

  • It generated addq %eax, %rsp, probably because sizeof(long) is 32-bit. Implementation seems to set it stsizediff to ts_target->stack_start - (char*)stackref, and that is actually ptrdiff_t, not long, but maybe this was intended to build on ansi, idk. If not, ptrdiff_t is the right choice. grep -rn '\<long\>' . gives only platfrom/switch* files, so main source is probably safe in that regard.
  • It could not resolve slp_save_state_asm etc at link stage, so I enabled it right in the main source (it must be passed as -DEXTERNAL_ASM to the compiler, but I'm not familiar with setup.py, sorry).

Anyway, MSYS2 is definitely the current way to use MinGW (and real half of unix) on windows. Original MinGW & MSYS are dead for too long. Not sure about TDM.

I cannot reinstall MSYS2 only for this issue, but I think these MSYS shell commands reproduce it:

$ pacman -Syu                       # per msys2 installation manual
...close via [X] and restart this shell...
$ pacman -Su                        # per msys2 installation manual
# now msys2 is installed into c:/msys64, updated properly and is ready to work

$ pacman -S mingw-w64-x86_64-toolchain
$ pacman -S mingw-w64-x86_64-python3
$ pacman -S mingw-w64-x86_64-python3-pip

And then in mingw64 shell:

$ pip3 install greenlet

If you encapsulate these changes in production-ready form into a branch and link to it, I'll test it in few hours or a day after, no need for complex setups.

@snaury
Copy link
Contributor

snaury commented May 24, 2017

You seem to be both defining EXTERNAL_ASM (which is only needed if platform/switch_x64_masm.obj is being used) and changing switch_amd64_unix.h, which doesn't make a lot of sense. What's probably happening is that switch_amd64_unix.h is saving just enough registers to pass tests, but more subtle breakage may happen in real world usage, e.g. rdi and rsi are not among saved registers there, plus windows x64 abi has callee saved xmm registers, so floating point might lead to problems.

Does it work for you if you replace #include "slp_platformselect.h" with #include "platform/switch_x64_msvc.h"?

@ghost
Copy link

ghost commented May 27, 2017

Sorry for the late answer. It seems that build is likely misconfigured for mingw, because switch_x64_masm.obj is linked, but the assembler error appears in switch_amd64_unix.h. I didn't touch anything in build process. Maybe switch_amd64_unix.h is not used after compilation at all? But it is used too: adding ud2 to that asm chunk makes first test fail with "Illegal instruction" error.

Does it work for you if you replace #include "slp_platformselect.h" with #include "platform/switch_x64_msvc.h"?

One warning, tests ok.

$ python3 setup.py build
running build
running build_ext
building 'greenlet' extension
C:\msys64\mingw64\bin/x86_64-w64-mingw32-gcc.exe -Wno-unused-result -Wsign-compare -DNDEBUG -march=x86-64 -mtune=generic -O2 -pipe -fwrapv -D__USE_MINGW_ANSI_STDIO=1 -DNDEBUG -IC:/msys64/mingw64/include/python3.5m -c greenlet.c -o build/temp.mingw-3.5/greenlet.o
In file included from greenlet.c:328:0:
platform/switch_x64_msvc.h:25:0: warning: "alloca" redefined
 #define alloca _alloca

In file included from C:/msys64/mingw64/x86_64-w64-mingw32/include/stdlib.h:695:0,
                 from C:/msys64/mingw64/include/python3.5m/Python.h:34,
                 from greenlet.h:8,
                 from greenlet.c:5:
C:/msys64/mingw64/x86_64-w64-mingw32/include/malloc.h:183:0: note: this is the location of the previous definition
 #define alloca(x) __builtin_alloca((x))

writing build/temp.mingw-3.5/greenlet-cpython-35m.def
creating build/lib.mingw-3.5
C:\msys64\mingw64\bin/x86_64-w64-mingw32-gcc.exe -shared -Wl,--enable-auto-image-base -pipe -s -s build/temp.mingw-3.5/greenlet.o platform/switch_x64_masm.obj build/temp.mingw-3.5/greenlet-cpython-35m.def -LC:/msys64/mingw64/lib/python3.5/config-3.5m -L/mingw64/lib -lpython3.5m -lversion -o build/lib.mingw-3.5/greenlet-cpython-35m.dll
$ python3 setup.py test
running test
running egg_info
creating greenlet.egg-info
writing top-level names to greenlet.egg-info/top_level.txt
writing greenlet.egg-info/PKG-INFO
writing dependency_links to greenlet.egg-info/dependency_links.txt
writing manifest file 'greenlet.egg-info/SOURCES.txt'
reading manifest file 'greenlet.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'greenlet.egg-info/SOURCES.txt'
running build_ext
Linking C:/msys64/home/User/greenlet-0.4.12/build/lib.mingw-3.5/greenlet-cpython-35m.dll to C:/msys64/home/User/greenlet-0.4.12/greenlet-cpython-35m.dll
...
...
...
----------------------------------------------------------------------
Ran 63 tests in 0.735s

OK

@iongion
Copy link

iongion commented Dec 8, 2017

On latest msys usr/include/python3.6m/pyport.h:219:10: fatal error: sys/select.h: No such file or directory

pip3 install greenlet
Collecting greenlet
  Using cached greenlet-0.4.12.tar.gz
Installing collected packages: greenlet
  Running setup.py install for greenlet ... error
    Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-7itnv3p0/greenlet/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-zzzo6q_t-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_ext
    building 'greenlet' extension
    creating build
    creating build/temp.mingw64_nt-10.0-2.9.0(0.318
    creating build/temp.mingw64_nt-10.0-2.9.0(0.318/5
    creating build/temp.mingw64_nt-10.0-2.9.0(0.318/5/3)-x86_64-3.6
    x86_64-pc-msys-gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -march=x86-64 -mtune=generic -O2 -pipe -I/usr/include/python3.6m -c greenlet.c -o build/temp.mingw64_nt-10.0-2.9.0(0.318/5/3)-x86_64-3.6/greenlet.o
    In file included from W:/SDKs/msys2/usr/include/python3.6m/Python.h:50:0,
                     from greenlet.h:8,
                     from greenlet.c:5:
    W:/SDKs/msys2/usr/include/python3.6m/pyport.h:219:10: fatal error: sys/select.h: No such file or directory
     #include <sys/select.h>
              ^~~~~~~~~~~~~~
    compilation terminated.
    error: command 'x86_64-pc-msys-gcc' failed with exit status 1

    ----------------------------------------
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-7itnv3p0/greenlet/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-zzzo6q_t-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-7itnv3p0/greenlet/

@DancingQuanta
Copy link

I have been trying to install neovim in msys2 which depends on greenlet. I got a similar error as the previous post. Perhaps sys/select.h is not available for windows as suggested here?

@snaury
Copy link
Contributor

snaury commented Apr 14, 2018

Well, greenlet does not include sys/select.h, I would suggest reporting it to the project that is actually responsible for that include and which could maybe help you (I would assume that is either cpython directly or whoever is responsible for msys2 port of cpython).

navytux added a commit to navytux/greenlet that referenced this issue Jan 10, 2022
…opagate to another greenlet and corrupt memory

Hello up there. While working on Pygolang I've faced the following
problem: a C++ exception thrown in one greenlet, without any try/catch
block on that greenlet, might become propagated and "handled" by
try/catch block established at another greenlet that happened to switch to
the greenlet in question. "Handled" comes in quotes because the program
usually segfaults after that.

I've also observed segfaults before exception reaches user-level
try/catch block - internally in __cxa_throw. Both this issues are likely
of the same origin - due to the fact that C-level stack of a greenlet
does not start from scratch and starts from C-level stack of the program
state when the greenlet is switched to the first time.

We already have one test for C++ exception handling in test_cpp that
@snaury initially added in d9cb12a. However in that test all greenlets
that throw C++ exceptions also put try/catch at the top of their
C-stack.

In the problem, that I describe, and that added test reproduces, there is
no intended top-level try/catch block in C-stack of the greenlet in
question that throws. As the test shows the exception becomes propagated
to switcher's greenlet context and the program then dies with SIGSEGV:

    test_exception_switch_and_throw (greenlet.tests.test_cpp.CPPTests) ... terminate called after throwing an instance of 'exception_t'
    C++ exception unexpectedly caught in g1		<-- NOTE
    FAIL

    ======================================================================
    FAIL: test_exception_switch_and_throw (greenlet.tests.test_cpp.CPPTests)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/home/kirr/src/tools/py/gevent/greenlet/src/greenlet/tests/test_cpp.py", line 62, in test_exception_switch_and_throw
        (ret, sig, " (core dumped)" if core else ""))
    AssertionError: failed with ret=0 sig=11 (core dumped)

The C-level backtrace from the dumped core is attached in Appendix I. There the
program dies somehow after running the code from _test_extension_cpp.cpp
module. However with the following dirty-patch the situation becomes more clear:

    --- a/src/greenlet/tests/_test_extension_cpp.cpp
    +++ b/src/greenlet/tests/_test_extension_cpp.cpp
    @@ -70,6 +70,7 @@ test_exception_switch(PyObject* self, PyObject* args)
     static PyObject*
     py_test_exception_throw(PyObject* self, PyObject* args)
     {
    +    abort();
         if (!PyArg_ParseTuple(args, ""))
             return NULL;
         p_test_exception_throw(0);

The C-level backtrace of this abort when, run from under g2, shows that g2
C-stack starts from what was there before for first greenlet with try/catch block:

    #0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
    python-greenlet#1  0x00007f8be31e9537 in __GI_abort () at abort.c:79
    python-greenlet#2  0x00007f8be3529423 in py_test_exception_throw (self=0x0, args=0x7f8be317f050)
        at src/greenlet/tests/_test_extension_cpp.cpp:73
    python-greenlet#3  0x00005584d0389903 in PyObject_Call (func=0x7f8be2cdd690, arg=<optimized out>, kw=<optimized out>)
        at ../Objects/abstract.c:2544
    python-greenlet#4  0x00007f8be3530d63 in g_initialstub (mark=0x7ffe6d1b1c88) at src/greenlet/greenlet.c:931
    python-greenlet#5  0x00007f8be3530290 in g_switch (target=0x7f8be2cd6230, args=0x7f8be317f050, kwargs=0x0) at src/greenlet/greenlet.c:692
    python-greenlet#6  0x00007f8be35329e2 in PyGreenlet_Switch (g=0x7f8be2cd6230, args=0x7f8be317f050, kwargs=0x0) at src/greenlet/greenlet.c:1806     <- first switch to G2
    python-greenlet#7  0x00007f8be35294da in test_exception_switch_and_do_in_g2 (self=0x0, args=0x7f8be2ce33d0)                                        <- this code runs in G1
        at src/greenlet/tests/_test_extension_cpp.cpp:105
    python-greenlet#8  0x00005584d039de7a in call_function (oparg=<optimized out>, pp_stack=0x7ffe6d1b1e28) at ../Python/ceval.c:4376
    python-greenlet#9  PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3013
    python-greenlet#10 0x00005584d039c3cc in PyEval_EvalCodeEx (co=0x7f8be2cd9cb0, globals=<optimized out>, locals=<optimized out>,
        args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x0, defcount=0, closure=0x0)
        at ../Python/ceval.c:3608
    python-greenlet#11 0x00005584d03b6b9b in function_call (func=func@entry=0x7f8be2cde650, arg=0x7f8be317f050, kw=0x0)
        at ../Objects/funcobject.c:523
    python-greenlet#12 0x00005584d0389903 in PyObject_Call (func=0x7f8be2cde650, arg=<optimized out>, kw=<optimized out>)
        at ../Objects/abstract.c:2544
    python-greenlet#13 0x00007f8be3530d63 in g_initialstub (mark=0x7ffe6d1b20b8) at src/greenlet/greenlet.c:931
    python-greenlet#14 0x00007f8be3530290 in g_switch (target=0x7f8be2cd6410, args=0x7f8be317f050, kwargs=0x0) at src/greenlet/greenlet.c:692
    python-greenlet#15 0x00007f8be3531c4c in green_switch (self=0x7f8be2cd6410, args=0x7f8be317f050, kwargs=0x0) at src/greenlet/greenlet.c:1321       <- switch to G1
    ...

The problem might be worked-around with putting try/catch on C-stack for
every greenlet, but a more proper fix would be to unlink return address
and C-stack-frame of created greenlet from other greenlets completely
(i.e. rewrite first frame of C-stack for created greenlet to return to NULL).

Thanks beforehand,
Kirill

P.S. The problem described at
  python-greenlet#197 (comment) and
  python-greenlet#205 might be related
  to hereby issue (/cc @ThePrez, @kadler, @jamadden).

P.P.S. The test does not fail on master. I see there @jamadden switched
  the codebase to C++ almost completely and there is some explicit
  attempts to save/restore exception state added in
  python-greenlet@87edf955. However
  that exception save/restore is specific to Win32 and the test succeeds
  for me on Linux. I still see the following comment in
  UserGreenlet::inner_bootstrap

    // C++ exceptions cannot propagate to the parent greenlet from
    // here. (TODO: Do we need a catch(...) clause, perhaps on the
    // function itself? ALl we could do is terminate the program.)

    ( https://github.com/python-greenlet/greenlet/blob/3e534d6b/src/greenlet/greenlet.cpp#L1085-L1104 )

  probably this indeed works only by luck, or due to G_NOEXCEPT modifier
  of UserGreenlet::inner_bootstrap upon seeing which __cxa_throw stops
  unwinding C-stack and just calls std::terminate.

--------

Appendix I. C-level backtrace after the test died with SIGSEGV

  #0  0x0000556bdc30d394 in PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3351
  python-greenlet#1  0x0000556bdc30b3cc in PyEval_EvalCodeEx (co=0x7f0b8a03acb0, globals=<optimized out>, locals=<optimized out>,
      args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x0, defcount=0, closure=0x0)
      at ../Python/ceval.c:3608
  python-greenlet#2  0x0000556bdc325b9b in function_call (func=func@entry=0x7f0b8a03f650, arg=0x7f0b8a4e0050, kw=0x0)
      at ../Objects/funcobject.c:523
  python-greenlet#3  0x0000556bdc2f8903 in PyObject_Call (func=0x7f0b8a03f650, arg=<optimized out>, kw=<optimized out>)
      at ../Objects/abstract.c:2544
  python-greenlet#4  0x00007f0b8a891d63 in g_initialstub (mark=0x7ffc3ef97988) at src/greenlet/greenlet.c:931
  python-greenlet#5  0x00007f0b8a891290 in g_switch (target=0x7f0b8a037410, args=0x7f0b8a4e0050, kwargs=0x0) at src/greenlet/greenlet.c:692
  python-greenlet#6  0x00007f0b8a892c4c in green_switch (self=0x7f0b8a037410, args=0x7f0b8a4e0050, kwargs=0x0) at src/greenlet/greenlet.c:1321
  python-greenlet#7  0x0000556bdc30ce7a in call_function (oparg=<optimized out>, pp_stack=0x7ffc3ef97ac8) at ../Python/ceval.c:4376
  python-greenlet#8  PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3013
  python-greenlet#9  0x0000556bdc30b3cc in PyEval_EvalCodeEx (co=0x7f0b8a03ad30, globals=<optimized out>, locals=<optimized out>,
      args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x0, defcount=0, closure=0x0)
      at ../Python/ceval.c:3608
  python-greenlet#10 0x0000556bdc312953 in fast_function (nk=<optimized out>, na=<optimized out>, n=<optimized out>, pp_stack=0x7ffc3ef97ca8,
      func=0x7f0b8a03aed0) at ../Python/ceval.c:4471
  python-greenlet#11 call_function (oparg=<optimized out>, pp_stack=0x7ffc3ef97ca8) at ../Python/ceval.c:4396
  python-greenlet#12 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3013
  python-greenlet#13 0x0000556bdc30b3cc in PyEval_EvalCodeEx (co=0x7f0b8a03ac30, globals=<optimized out>, locals=<optimized out>,
      args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x0, defcount=0, closure=0x0)
      at ../Python/ceval.c:3608
  python-greenlet#14 0x0000556bdc312953 in fast_function (nk=<optimized out>, na=<optimized out>, n=<optimized out>, pp_stack=0x7ffc3ef97e88,
      func=0x7f0b8a03af50) at ../Python/ceval.c:4471
  python-greenlet#15 call_function (oparg=<optimized out>, pp_stack=0x7ffc3ef97e88) at ../Python/ceval.c:4396
  python-greenlet#16 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3013
  python-greenlet#17 0x0000556bdc30b3cc in PyEval_EvalCodeEx (co=0x7f0b8a03adb0, globals=<optimized out>, locals=<optimized out>,
      args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x0, defcount=0, closure=0x0)
      at ../Python/ceval.c:3608
  python-greenlet#18 0x0000556bdc312953 in fast_function (nk=<optimized out>, na=<optimized out>, n=<optimized out>, pp_stack=0x7ffc3ef98068,
      func=0x7f0b8a03f250) at ../Python/ceval.c:4471
  python-greenlet#19 call_function (oparg=<optimized out>, pp_stack=0x7ffc3ef98068) at ../Python/ceval.c:4396
  python-greenlet#20 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3013
  python-greenlet#21 0x0000556bdc30b3cc in PyEval_EvalCodeEx (co=0x7f0b8a04bd30, globals=<optimized out>, locals=<optimized out>,
      args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x7f0b8a0752a8, defcount=1,
      closure=0x0) at ../Python/ceval.c:3608
  python-greenlet#22 0x0000556bdc325cc2 in function_call (func=0x7f0b8a0771d0, arg=0x7f0b8a3bd5a0, kw=0x7f0b8a042dd0)
      at ../Objects/funcobject.c:523
  python-greenlet#23 0x0000556bdc30fa96 in PyObject_Call (kw=0x7f0b8a042dd0, arg=0x7f0b8a3bd5a0, func=0x7f0b8a0771d0)
      at ../Objects/abstract.c:2544
  python-greenlet#24 ext_do_call (nk=<optimized out>, na=1, flags=<optimized out>, pp_stack=0x7ffc3ef982a0, func=0x7f0b8a0771d0)
      at ../Python/ceval.c:4690
  python-greenlet#25 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3052
  python-greenlet#26 0x0000556bdc30b3cc in PyEval_EvalCodeEx (co=0x7f0b8a04bf30, globals=<optimized out>, locals=<optimized out>,
      args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x0, defcount=0, closure=0x0)
      at ../Python/ceval.c:3608
  python-greenlet#27 0x0000556bdc325b9b in function_call (func=0x7f0b8a0772d0, arg=arg@entry=0x7f0b8a3bd550, kw=kw@entry=0x0)
      at ../Objects/funcobject.c:523
  python-greenlet#28 0x0000556bdc33f553 in PyObject_Call (kw=0x0, arg=0x7f0b8a3bd550, func=<optimized out>) at ../Objects/abstract.c:2544
  python-greenlet#29 instancemethod_call (func=<optimized out>, func@entry=0x7f0b8a3c6a00, arg=0x7f0b8a3bd550, kw=0x0)
      at ../Objects/classobject.c:2600
  python-greenlet#30 0x0000556bdc2f8903 in PyObject_Call (func=0x7f0b8a3c6a00, arg=<optimized out>, kw=<optimized out>)
      at ../Objects/abstract.c:2544
  python-greenlet#31 0x0000556bdc37eff8 in slot_tp_call (self=self@entry=0x7f0b8a03cfd0, args=0x7f0b8a044210, kwds=0x0)
      at ../Objects/typeobject.c:5609
  python-greenlet#32 0x0000556bdc2f8903 in PyObject_Call (func=0x7f0b8a03cfd0, arg=<optimized out>, kw=<optimized out>)
      at ../Objects/abstract.c:2544
  python-greenlet#33 0x0000556bdc3128dd in do_call (nk=<optimized out>, na=<optimized out>, pp_stack=0x7ffc3ef98798, func=0x7f0b8a03cfd0)
      at ../Python/ceval.c:4593
  python-greenlet#34 call_function (oparg=<optimized out>, pp_stack=0x7ffc3ef98798) at ../Python/ceval.c:4398
  python-greenlet#35 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3013
  python-greenlet#36 0x0000556bdc30b3cc in PyEval_EvalCodeEx (co=0x7f0b8a07d530, globals=<optimized out>, locals=<optimized out>,
      args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x7f0b8a076ee8, defcount=1,
      closure=0x0) at ../Python/ceval.c:3608
  python-greenlet#37 0x0000556bdc325cc2 in function_call (func=0x7f0b8a07f950, arg=0x7f0b8a3bd780, kw=0x7f0b8a042cb0)
      at ../Objects/funcobject.c:523
  python-greenlet#38 0x0000556bdc30fa96 in PyObject_Call (kw=0x7f0b8a042cb0, arg=0x7f0b8a3bd780, func=0x7f0b8a07f950)
      at ../Objects/abstract.c:2544
  python-greenlet#39 ext_do_call (nk=<optimized out>, na=1, flags=<optimized out>, pp_stack=0x7ffc3ef989d0, func=0x7f0b8a07f950)
      at ../Python/ceval.c:4690
  python-greenlet#40 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3052
  python-greenlet#41 0x0000556bdc30b3cc in PyEval_EvalCodeEx (co=0x7f0b8a07d2b0, globals=<optimized out>, locals=<optimized out>,
      args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x0, defcount=0, closure=0x0)
      at ../Python/ceval.c:3608
  python-greenlet#42 0x0000556bdc325b9b in function_call (func=0x7f0b8a07f850, arg=arg@entry=0x7f0b8a3bd730, kw=kw@entry=0x0)
      at ../Objects/funcobject.c:523
  python-greenlet#43 0x0000556bdc33f553 in PyObject_Call (kw=0x0, arg=0x7f0b8a3bd730, func=<optimized out>) at ../Objects/abstract.c:2544
  python-greenlet#44 instancemethod_call (func=<optimized out>, func@entry=0x7f0b8a427190, arg=0x7f0b8a3bd730, kw=0x0)
      at ../Objects/classobject.c:2600
  python-greenlet#45 0x0000556bdc2f8903 in PyObject_Call (func=0x7f0b8a427190, arg=<optimized out>, kw=<optimized out>)
      at ../Objects/abstract.c:2544
  python-greenlet#46 0x0000556bdc37eff8 in slot_tp_call (self=self@entry=0x7f0b8a03cf90, args=0x7f0b8a044150, kwds=0x0)
      at ../Objects/typeobject.c:5609
  python-greenlet#47 0x0000556bdc2f8903 in PyObject_Call (func=0x7f0b8a03cf90, arg=<optimized out>, kw=<optimized out>)
      at ../Objects/abstract.c:2544
  python-greenlet#48 0x0000556bdc3128dd in do_call (nk=<optimized out>, na=<optimized out>, pp_stack=0x7ffc3ef98ec8, func=0x7f0b8a03cf90)
      at ../Python/ceval.c:4593
  python-greenlet#49 call_function (oparg=<optimized out>, pp_stack=0x7ffc3ef98ec8) at ../Python/ceval.c:4398
  python-greenlet#50 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3013
  python-greenlet#51 0x0000556bdc30b3cc in PyEval_EvalCodeEx (co=0x7f0b8a07d530, globals=<optimized out>, locals=<optimized out>,
      args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x7f0b8a076ee8, defcount=1,
      closure=0x0) at ../Python/ceval.c:3608
  python-greenlet#52 0x0000556bdc325cc2 in function_call (func=0x7f0b8a07f950, arg=0x7f0b8a3bdaf0, kw=0x7f0b8a042b90)
      at ../Objects/funcobject.c:523
  python-greenlet#53 0x0000556bdc30fa96 in PyObject_Call (kw=0x7f0b8a042b90, arg=0x7f0b8a3bdaf0, func=0x7f0b8a07f950)
      at ../Objects/abstract.c:2544
  python-greenlet#54 ext_do_call (nk=<optimized out>, na=1, flags=<optimized out>, pp_stack=0x7ffc3ef99100, func=0x7f0b8a07f950)
      at ../Python/ceval.c:4690
  python-greenlet#55 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3052
  python-greenlet#56 0x0000556bdc30b3cc in PyEval_EvalCodeEx (co=0x7f0b8a07d2b0, globals=<optimized out>, locals=<optimized out>,
      args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x0, defcount=0, closure=0x0)
      at ../Python/ceval.c:3608
  python-greenlet#57 0x0000556bdc325b9b in function_call (func=0x7f0b8a07f850, arg=arg@entry=0x7f0b8a3bdb40, kw=kw@entry=0x0)
      at ../Objects/funcobject.c:523
  python-greenlet#58 0x0000556bdc33f553 in PyObject_Call (kw=0x0, arg=0x7f0b8a3bdb40, func=<optimized out>) at ../Objects/abstract.c:2544
  python-greenlet#59 instancemethod_call (func=<optimized out>, func@entry=0x7f0b8a3c6820, arg=0x7f0b8a3bdb40, kw=0x0)
      at ../Objects/classobject.c:2600
  python-greenlet#60 0x0000556bdc2f8903 in PyObject_Call (func=0x7f0b8a3c6820, arg=<optimized out>, kw=<optimized out>)
      at ../Objects/abstract.c:2544
  python-greenlet#61 0x0000556bdc37eff8 in slot_tp_call (self=self@entry=0x7f0b8a033c50, args=0x7f0b8a03c0d0, kwds=0x0)
      at ../Objects/typeobject.c:5609
  python-greenlet#62 0x0000556bdc2f8903 in PyObject_Call (func=0x7f0b8a033c50, arg=<optimized out>, kw=<optimized out>)
      at ../Objects/abstract.c:2544
  python-greenlet#63 0x0000556bdc3128dd in do_call (nk=<optimized out>, na=<optimized out>, pp_stack=0x7ffc3ef995f8, func=0x7f0b8a033c50)
      at ../Python/ceval.c:4593
  python-greenlet#64 call_function (oparg=<optimized out>, pp_stack=0x7ffc3ef995f8) at ../Python/ceval.c:4398
  python-greenlet#65 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3013
  python-greenlet#66 0x0000556bdc30b3cc in PyEval_EvalCodeEx (co=0x7f0b8a07d530, globals=<optimized out>, locals=<optimized out>,
      args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x7f0b8a076ee8, defcount=1,
      closure=0x0) at ../Python/ceval.c:3608
  python-greenlet#67 0x0000556bdc325cc2 in function_call (func=0x7f0b8a07f950, arg=0x7f0b8a3bd500, kw=0x7f0b8a042a70)
      at ../Objects/funcobject.c:523
  python-greenlet#68 0x0000556bdc30fa96 in PyObject_Call (kw=0x7f0b8a042a70, arg=0x7f0b8a3bd500, func=0x7f0b8a07f950)
      at ../Objects/abstract.c:2544
  python-greenlet#69 ext_do_call (nk=<optimized out>, na=1, flags=<optimized out>, pp_stack=0x7ffc3ef99830, func=0x7f0b8a07f950)
      at ../Python/ceval.c:4690
  python-greenlet#70 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3052
  python-greenlet#71 0x0000556bdc30b3cc in PyEval_EvalCodeEx (co=0x7f0b8a07d2b0, globals=<optimized out>, locals=<optimized out>,
      args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x0, defcount=0, closure=0x0)
      at ../Python/ceval.c:3608
  python-greenlet#72 0x0000556bdc325b9b in function_call (func=0x7f0b8a07f850, arg=arg@entry=0x7f0b8a3bd9b0, kw=kw@entry=0x0)
      at ../Objects/funcobject.c:523
  python-greenlet#73 0x0000556bdc33f553 in PyObject_Call (kw=0x0, arg=0x7f0b8a3bd9b0, func=<optimized out>) at ../Objects/abstract.c:2544
  python-greenlet#74 instancemethod_call (func=<optimized out>, func@entry=0x7f0b8a4310a0, arg=0x7f0b8a3bd9b0, kw=0x0)
      at ../Objects/classobject.c:2600
  python-greenlet#75 0x0000556bdc2f8903 in PyObject_Call (func=0x7f0b8a4310a0, arg=<optimized out>, kw=<optimized out>)
      at ../Objects/abstract.c:2544
  python-greenlet#76 0x0000556bdc37eff8 in slot_tp_call (self=self@entry=0x7f0b8a033c10, args=0x7f0b8a033fd0, kwds=0x0)
      at ../Objects/typeobject.c:5609
  python-greenlet#77 0x0000556bdc2f8903 in PyObject_Call (func=0x7f0b8a033c10, arg=<optimized out>, kw=<optimized out>)
      at ../Objects/abstract.c:2544
  python-greenlet#78 0x0000556bdc3128dd in do_call (nk=<optimized out>, na=<optimized out>, pp_stack=0x7ffc3ef99d28, func=0x7f0b8a033c10)
      at ../Python/ceval.c:4593
  python-greenlet#79 call_function (oparg=<optimized out>, pp_stack=0x7ffc3ef99d28) at ../Python/ceval.c:4398
  python-greenlet#80 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3013
  python-greenlet#81 0x0000556bdc3125fe in fast_function (nk=<optimized out>, na=<optimized out>, n=<optimized out>, pp_stack=0x7ffc3ef99e38,
      func=0x7f0b8a01ecd0) at ../Python/ceval.c:4461
  python-greenlet#82 call_function (oparg=<optimized out>, pp_stack=0x7ffc3ef99e38) at ../Python/ceval.c:4396
  python-greenlet#83 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3013
  python-greenlet#84 0x0000556bdc3125fe in fast_function (nk=<optimized out>, na=<optimized out>, n=<optimized out>, pp_stack=0x7ffc3ef99f48,
      func=0x7f0b8a01edd0) at ../Python/ceval.c:4461
  python-greenlet#85 call_function (oparg=<optimized out>, pp_stack=0x7ffc3ef99f48) at ../Python/ceval.c:4396
  python-greenlet#86 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3013
  python-greenlet#87 0x0000556bdc30b3cc in PyEval_EvalCodeEx (co=0x7f0b8a081d30, globals=<optimized out>, locals=<optimized out>,
      args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=1, defs=0x7f0b8a008ba8, defcount=10,
      closure=0x0) at ../Python/ceval.c:3608
  python-greenlet#88 0x0000556bdc325cc2 in function_call (func=0x7f0b8a00ddd0, arg=arg@entry=0x7f0b8a033610, kw=kw@entry=0x7f0b8a014a70)
      at ../Objects/funcobject.c:523
  python-greenlet#89 0x0000556bdc33f553 in PyObject_Call (kw=0x7f0b8a014a70, arg=0x7f0b8a033610, func=<optimized out>)
      at ../Objects/abstract.c:2544
  python-greenlet#90 instancemethod_call (func=<optimized out>, func@entry=0x7f0b8a427140, arg=0x7f0b8a033610, arg@entry=0x7f0b8a4e0050,
      kw=kw@entry=0x7f0b8a014a70) at ../Objects/classobject.c:2600
  python-greenlet#91 0x0000556bdc33f10f in PyObject_Call (kw=0x7f0b8a014a70, arg=0x7f0b8a4e0050, func=0x7f0b8a427140)
      at ../Objects/abstract.c:2544
  python-greenlet#92 slot_tp_init (self=self@entry=0x7f0b8a3ebb10, args=args@entry=0x7f0b8a4e0050, kwds=kwds@entry=0x7f0b8a014a70)
      at ../Objects/typeobject.c:5869
  python-greenlet#93 0x0000556bdc2feb87 in type_call (type=<optimized out>, type@entry=0x556bdd2a85c0, args=0x7f0b8a4e0050, kwds=0x7f0b8a014a70)
      at ../Objects/typeobject.c:765
  python-greenlet#94 0x0000556bdc2f8903 in PyObject_Call (func=0x556bdd2a85c0, arg=<optimized out>, kw=<optimized out>)
      at ../Objects/abstract.c:2544
  python-greenlet#95 0x0000556bdc3128dd in do_call (nk=<optimized out>, na=<optimized out>, pp_stack=0x7ffc3ef9a458, func=0x556bdd2a85c0)
      at ../Python/ceval.c:4593
  python-greenlet#96 call_function (oparg=<optimized out>, pp_stack=0x7ffc3ef9a458) at ../Python/ceval.c:4398
  python-greenlet#97 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3013
  python-greenlet#98 0x0000556bdc30b3cc in PyEval_EvalCodeEx (co=0x7f0b8a37d830, globals=<optimized out>, locals=<optimized out>,
      args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x0, defcount=0, closure=0x0)
      at ../Python/ceval.c:3608
  python-greenlet#99 0x0000556bdc311886 in PyEval_EvalCode (locals=0x7f0b8a4ae170, globals=0x7f0b8a4ae170, co=<optimized out>)
      at ../Python/ceval.c:669
  python-greenlet#100 exec_statement (locals=0x7f0b8a4ae170, globals=0x7f0b8a4ae170, prog=<optimized out>, f=<optimized out>)
      at ../Python/ceval.c:5093
  python-greenlet#101 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:2122
  python-greenlet#102 0x0000556bdc30b3cc in PyEval_EvalCodeEx (co=0x7f0b8a3ea4b0, globals=<optimized out>, locals=<optimized out>,
      args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x7f0b8a381068, defcount=5,
      closure=0x0) at ../Python/ceval.c:3608
  python-greenlet#103 0x0000556bdc312953 in fast_function (nk=<optimized out>, na=<optimized out>, n=<optimized out>, pp_stack=0x7ffc3ef9a818,
      func=0x7f0b8a37d8d0) at ../Python/ceval.c:4471
  python-greenlet#104 call_function (oparg=<optimized out>, pp_stack=0x7ffc3ef9a818) at ../Python/ceval.c:4396
  python-greenlet#105 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3013
  python-greenlet#106 0x0000556bdc30b3cc in PyEval_EvalCodeEx (co=0x7f0b8a37d4b0, globals=<optimized out>, locals=<optimized out>,
      args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x7f0b8a379ce8, defcount=1,
      closure=0x0) at ../Python/ceval.c:3608
  python-greenlet#107 0x0000556bdc325b9b in function_call (func=func@entry=0x7f0b8a37de50, arg=0x7f0b8a3b5be0, kw=0x0)
      at ../Objects/funcobject.c:523
  python-greenlet#108 0x0000556bdc2f8903 in PyObject_Call (func=0x7f0b8a37de50, arg=<optimized out>, kw=<optimized out>)
      at ../Objects/abstract.c:2544
  python-greenlet#109 0x0000556bdc3b87e1 in RunModule (module=<optimized out>, set_argv0=1) at ../Modules/main.c:197
  python-greenlet#110 0x0000556bdc3a68ed in Py_Main (argc=<optimized out>, argv=<optimized out>) at ../Modules/main.c:592#111 0x00007f0b8a54bd0a in __libc_start_main (main=0x556bdc3a6530 <main>, argc=5, argv=0x7ffc3ef9ac08, init=<optimized out>,
      fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7ffc3ef9abf8) at ../csu/libc-start.c:308
  python-greenlet#112 0x0000556bdc3a646a in _start ()
jamadden pushed a commit that referenced this issue Jan 24, 2022
…opagate to another greenlet and corrupt memory

Hello up there. While working on Pygolang I've faced the following
problem: a C++ exception thrown in one greenlet, without any try/catch
block on that greenlet, might become propagated and "handled" by
try/catch block established at another greenlet that happened to switch to
the greenlet in question. "Handled" comes in quotes because the program
usually segfaults after that.

I've also observed segfaults before exception reaches user-level
try/catch block - internally in __cxa_throw. Both this issues are likely
of the same origin - due to the fact that C-level stack of a greenlet
does not start from scratch and starts from C-level stack of the program
state when the greenlet is switched to the first time.

We already have one test for C++ exception handling in test_cpp that
@snaury initially added in d9cb12a. However in that test all greenlets
that throw C++ exceptions also put try/catch at the top of their
C-stack.

In the problem, that I describe, and that added test reproduces, there is
no intended top-level try/catch block in C-stack of the greenlet in
question that throws. As the test shows the exception becomes propagated
to switcher's greenlet context and the program then dies with SIGSEGV:

    test_exception_switch_and_throw (greenlet.tests.test_cpp.CPPTests) ... terminate called after throwing an instance of 'exception_t'
    C++ exception unexpectedly caught in g1		<-- NOTE
    FAIL

    ======================================================================
    FAIL: test_exception_switch_and_throw (greenlet.tests.test_cpp.CPPTests)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/home/kirr/src/tools/py/gevent/greenlet/src/greenlet/tests/test_cpp.py", line 62, in test_exception_switch_and_throw
        (ret, sig, " (core dumped)" if core else ""))
    AssertionError: failed with ret=0 sig=11 (core dumped)

The C-level backtrace from the dumped core is attached in Appendix I. There the
program dies somehow after running the code from _test_extension_cpp.cpp
module. However with the following dirty-patch the situation becomes more clear:

    --- a/src/greenlet/tests/_test_extension_cpp.cpp
    +++ b/src/greenlet/tests/_test_extension_cpp.cpp
    @@ -70,6 +70,7 @@ test_exception_switch(PyObject* self, PyObject* args)
     static PyObject*
     py_test_exception_throw(PyObject* self, PyObject* args)
     {
    +    abort();
         if (!PyArg_ParseTuple(args, ""))
             return NULL;
         p_test_exception_throw(0);

The C-level backtrace of this abort when, run from under g2, shows that g2
C-stack starts from what was there before for first greenlet with try/catch block:

    #0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
    #1  0x00007f8be31e9537 in __GI_abort () at abort.c:79
    #2  0x00007f8be3529423 in py_test_exception_throw (self=0x0, args=0x7f8be317f050)
        at src/greenlet/tests/_test_extension_cpp.cpp:73
    #3  0x00005584d0389903 in PyObject_Call (func=0x7f8be2cdd690, arg=<optimized out>, kw=<optimized out>)
        at ../Objects/abstract.c:2544
    #4  0x00007f8be3530d63 in g_initialstub (mark=0x7ffe6d1b1c88) at src/greenlet/greenlet.c:931
    #5  0x00007f8be3530290 in g_switch (target=0x7f8be2cd6230, args=0x7f8be317f050, kwargs=0x0) at src/greenlet/greenlet.c:692
    #6  0x00007f8be35329e2 in PyGreenlet_Switch (g=0x7f8be2cd6230, args=0x7f8be317f050, kwargs=0x0) at src/greenlet/greenlet.c:1806     <- first switch to G2
    #7  0x00007f8be35294da in test_exception_switch_and_do_in_g2 (self=0x0, args=0x7f8be2ce33d0)                                        <- this code runs in G1
        at src/greenlet/tests/_test_extension_cpp.cpp:105
    #8  0x00005584d039de7a in call_function (oparg=<optimized out>, pp_stack=0x7ffe6d1b1e28) at ../Python/ceval.c:4376
    #9  PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3013
    #10 0x00005584d039c3cc in PyEval_EvalCodeEx (co=0x7f8be2cd9cb0, globals=<optimized out>, locals=<optimized out>,
        args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x0, defcount=0, closure=0x0)
        at ../Python/ceval.c:3608
    #11 0x00005584d03b6b9b in function_call (func=func@entry=0x7f8be2cde650, arg=0x7f8be317f050, kw=0x0)
        at ../Objects/funcobject.c:523
    #12 0x00005584d0389903 in PyObject_Call (func=0x7f8be2cde650, arg=<optimized out>, kw=<optimized out>)
        at ../Objects/abstract.c:2544
    #13 0x00007f8be3530d63 in g_initialstub (mark=0x7ffe6d1b20b8) at src/greenlet/greenlet.c:931
    #14 0x00007f8be3530290 in g_switch (target=0x7f8be2cd6410, args=0x7f8be317f050, kwargs=0x0) at src/greenlet/greenlet.c:692
    #15 0x00007f8be3531c4c in green_switch (self=0x7f8be2cd6410, args=0x7f8be317f050, kwargs=0x0) at src/greenlet/greenlet.c:1321       <- switch to G1
    ...

The problem might be worked-around with putting try/catch on C-stack for
every greenlet, but a more proper fix would be to unlink return address
and C-stack-frame of created greenlet from other greenlets completely
(i.e. rewrite first frame of C-stack for created greenlet to return to NULL).

Thanks beforehand,
Kirill

P.S. The problem described at
  #197 (comment) and
  #205 might be related
  to hereby issue (/cc @ThePrez, @kadler, @jamadden).

P.P.S. The test does not fail on master. I see there @jamadden switched
  the codebase to C++ almost completely and there is some explicit
  attempts to save/restore exception state added in
  87edf955. However
  that exception save/restore is specific to Win32 and the test succeeds
  for me on Linux. I still see the following comment in
  UserGreenlet::inner_bootstrap

    // C++ exceptions cannot propagate to the parent greenlet from
    // here. (TODO: Do we need a catch(...) clause, perhaps on the
    // function itself? ALl we could do is terminate the program.)

    ( https://github.com/python-greenlet/greenlet/blob/3e534d6b/src/greenlet/greenlet.cpp#L1085-L1104 )

  probably this indeed works only by luck, or due to G_NOEXCEPT modifier
  of UserGreenlet::inner_bootstrap upon seeing which __cxa_throw stops
  unwinding C-stack and just calls std::terminate.

--------

Appendix I. C-level backtrace after the test died with SIGSEGV

  #0  0x0000556bdc30d394 in PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3351
  #1  0x0000556bdc30b3cc in PyEval_EvalCodeEx (co=0x7f0b8a03acb0, globals=<optimized out>, locals=<optimized out>,
      args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x0, defcount=0, closure=0x0)
      at ../Python/ceval.c:3608
  #2  0x0000556bdc325b9b in function_call (func=func@entry=0x7f0b8a03f650, arg=0x7f0b8a4e0050, kw=0x0)
      at ../Objects/funcobject.c:523
  #3  0x0000556bdc2f8903 in PyObject_Call (func=0x7f0b8a03f650, arg=<optimized out>, kw=<optimized out>)
      at ../Objects/abstract.c:2544
  #4  0x00007f0b8a891d63 in g_initialstub (mark=0x7ffc3ef97988) at src/greenlet/greenlet.c:931
  #5  0x00007f0b8a891290 in g_switch (target=0x7f0b8a037410, args=0x7f0b8a4e0050, kwargs=0x0) at src/greenlet/greenlet.c:692
  #6  0x00007f0b8a892c4c in green_switch (self=0x7f0b8a037410, args=0x7f0b8a4e0050, kwargs=0x0) at src/greenlet/greenlet.c:1321
  #7  0x0000556bdc30ce7a in call_function (oparg=<optimized out>, pp_stack=0x7ffc3ef97ac8) at ../Python/ceval.c:4376
  #8  PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3013
  #9  0x0000556bdc30b3cc in PyEval_EvalCodeEx (co=0x7f0b8a03ad30, globals=<optimized out>, locals=<optimized out>,
      args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x0, defcount=0, closure=0x0)
      at ../Python/ceval.c:3608
  #10 0x0000556bdc312953 in fast_function (nk=<optimized out>, na=<optimized out>, n=<optimized out>, pp_stack=0x7ffc3ef97ca8,
      func=0x7f0b8a03aed0) at ../Python/ceval.c:4471
  #11 call_function (oparg=<optimized out>, pp_stack=0x7ffc3ef97ca8) at ../Python/ceval.c:4396
  #12 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3013
  #13 0x0000556bdc30b3cc in PyEval_EvalCodeEx (co=0x7f0b8a03ac30, globals=<optimized out>, locals=<optimized out>,
      args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x0, defcount=0, closure=0x0)
      at ../Python/ceval.c:3608
  #14 0x0000556bdc312953 in fast_function (nk=<optimized out>, na=<optimized out>, n=<optimized out>, pp_stack=0x7ffc3ef97e88,
      func=0x7f0b8a03af50) at ../Python/ceval.c:4471
  #15 call_function (oparg=<optimized out>, pp_stack=0x7ffc3ef97e88) at ../Python/ceval.c:4396
  #16 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3013
  #17 0x0000556bdc30b3cc in PyEval_EvalCodeEx (co=0x7f0b8a03adb0, globals=<optimized out>, locals=<optimized out>,
      args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x0, defcount=0, closure=0x0)
      at ../Python/ceval.c:3608
  #18 0x0000556bdc312953 in fast_function (nk=<optimized out>, na=<optimized out>, n=<optimized out>, pp_stack=0x7ffc3ef98068,
      func=0x7f0b8a03f250) at ../Python/ceval.c:4471
  #19 call_function (oparg=<optimized out>, pp_stack=0x7ffc3ef98068) at ../Python/ceval.c:4396
  #20 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3013
  #21 0x0000556bdc30b3cc in PyEval_EvalCodeEx (co=0x7f0b8a04bd30, globals=<optimized out>, locals=<optimized out>,
      args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x7f0b8a0752a8, defcount=1,
      closure=0x0) at ../Python/ceval.c:3608
  #22 0x0000556bdc325cc2 in function_call (func=0x7f0b8a0771d0, arg=0x7f0b8a3bd5a0, kw=0x7f0b8a042dd0)
      at ../Objects/funcobject.c:523
  #23 0x0000556bdc30fa96 in PyObject_Call (kw=0x7f0b8a042dd0, arg=0x7f0b8a3bd5a0, func=0x7f0b8a0771d0)
      at ../Objects/abstract.c:2544
  #24 ext_do_call (nk=<optimized out>, na=1, flags=<optimized out>, pp_stack=0x7ffc3ef982a0, func=0x7f0b8a0771d0)
      at ../Python/ceval.c:4690
  #25 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3052
  #26 0x0000556bdc30b3cc in PyEval_EvalCodeEx (co=0x7f0b8a04bf30, globals=<optimized out>, locals=<optimized out>,
      args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x0, defcount=0, closure=0x0)
      at ../Python/ceval.c:3608
  #27 0x0000556bdc325b9b in function_call (func=0x7f0b8a0772d0, arg=arg@entry=0x7f0b8a3bd550, kw=kw@entry=0x0)
      at ../Objects/funcobject.c:523
  #28 0x0000556bdc33f553 in PyObject_Call (kw=0x0, arg=0x7f0b8a3bd550, func=<optimized out>) at ../Objects/abstract.c:2544
  #29 instancemethod_call (func=<optimized out>, func@entry=0x7f0b8a3c6a00, arg=0x7f0b8a3bd550, kw=0x0)
      at ../Objects/classobject.c:2600
  #30 0x0000556bdc2f8903 in PyObject_Call (func=0x7f0b8a3c6a00, arg=<optimized out>, kw=<optimized out>)
      at ../Objects/abstract.c:2544
  #31 0x0000556bdc37eff8 in slot_tp_call (self=self@entry=0x7f0b8a03cfd0, args=0x7f0b8a044210, kwds=0x0)
      at ../Objects/typeobject.c:5609
  #32 0x0000556bdc2f8903 in PyObject_Call (func=0x7f0b8a03cfd0, arg=<optimized out>, kw=<optimized out>)
      at ../Objects/abstract.c:2544
  #33 0x0000556bdc3128dd in do_call (nk=<optimized out>, na=<optimized out>, pp_stack=0x7ffc3ef98798, func=0x7f0b8a03cfd0)
      at ../Python/ceval.c:4593
  #34 call_function (oparg=<optimized out>, pp_stack=0x7ffc3ef98798) at ../Python/ceval.c:4398
  #35 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3013
  #36 0x0000556bdc30b3cc in PyEval_EvalCodeEx (co=0x7f0b8a07d530, globals=<optimized out>, locals=<optimized out>,
      args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x7f0b8a076ee8, defcount=1,
      closure=0x0) at ../Python/ceval.c:3608
  #37 0x0000556bdc325cc2 in function_call (func=0x7f0b8a07f950, arg=0x7f0b8a3bd780, kw=0x7f0b8a042cb0)
      at ../Objects/funcobject.c:523
  #38 0x0000556bdc30fa96 in PyObject_Call (kw=0x7f0b8a042cb0, arg=0x7f0b8a3bd780, func=0x7f0b8a07f950)
      at ../Objects/abstract.c:2544
  #39 ext_do_call (nk=<optimized out>, na=1, flags=<optimized out>, pp_stack=0x7ffc3ef989d0, func=0x7f0b8a07f950)
      at ../Python/ceval.c:4690
  #40 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3052
  #41 0x0000556bdc30b3cc in PyEval_EvalCodeEx (co=0x7f0b8a07d2b0, globals=<optimized out>, locals=<optimized out>,
      args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x0, defcount=0, closure=0x0)
      at ../Python/ceval.c:3608
  #42 0x0000556bdc325b9b in function_call (func=0x7f0b8a07f850, arg=arg@entry=0x7f0b8a3bd730, kw=kw@entry=0x0)
      at ../Objects/funcobject.c:523
  #43 0x0000556bdc33f553 in PyObject_Call (kw=0x0, arg=0x7f0b8a3bd730, func=<optimized out>) at ../Objects/abstract.c:2544
  #44 instancemethod_call (func=<optimized out>, func@entry=0x7f0b8a427190, arg=0x7f0b8a3bd730, kw=0x0)
      at ../Objects/classobject.c:2600
  #45 0x0000556bdc2f8903 in PyObject_Call (func=0x7f0b8a427190, arg=<optimized out>, kw=<optimized out>)
      at ../Objects/abstract.c:2544
  #46 0x0000556bdc37eff8 in slot_tp_call (self=self@entry=0x7f0b8a03cf90, args=0x7f0b8a044150, kwds=0x0)
      at ../Objects/typeobject.c:5609
  #47 0x0000556bdc2f8903 in PyObject_Call (func=0x7f0b8a03cf90, arg=<optimized out>, kw=<optimized out>)
      at ../Objects/abstract.c:2544
  #48 0x0000556bdc3128dd in do_call (nk=<optimized out>, na=<optimized out>, pp_stack=0x7ffc3ef98ec8, func=0x7f0b8a03cf90)
      at ../Python/ceval.c:4593
  #49 call_function (oparg=<optimized out>, pp_stack=0x7ffc3ef98ec8) at ../Python/ceval.c:4398
  #50 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3013
  #51 0x0000556bdc30b3cc in PyEval_EvalCodeEx (co=0x7f0b8a07d530, globals=<optimized out>, locals=<optimized out>,
      args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x7f0b8a076ee8, defcount=1,
      closure=0x0) at ../Python/ceval.c:3608
  #52 0x0000556bdc325cc2 in function_call (func=0x7f0b8a07f950, arg=0x7f0b8a3bdaf0, kw=0x7f0b8a042b90)
      at ../Objects/funcobject.c:523
  #53 0x0000556bdc30fa96 in PyObject_Call (kw=0x7f0b8a042b90, arg=0x7f0b8a3bdaf0, func=0x7f0b8a07f950)
      at ../Objects/abstract.c:2544
  #54 ext_do_call (nk=<optimized out>, na=1, flags=<optimized out>, pp_stack=0x7ffc3ef99100, func=0x7f0b8a07f950)
      at ../Python/ceval.c:4690
  #55 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3052
  #56 0x0000556bdc30b3cc in PyEval_EvalCodeEx (co=0x7f0b8a07d2b0, globals=<optimized out>, locals=<optimized out>,
      args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x0, defcount=0, closure=0x0)
      at ../Python/ceval.c:3608
  #57 0x0000556bdc325b9b in function_call (func=0x7f0b8a07f850, arg=arg@entry=0x7f0b8a3bdb40, kw=kw@entry=0x0)
      at ../Objects/funcobject.c:523
  #58 0x0000556bdc33f553 in PyObject_Call (kw=0x0, arg=0x7f0b8a3bdb40, func=<optimized out>) at ../Objects/abstract.c:2544
  #59 instancemethod_call (func=<optimized out>, func@entry=0x7f0b8a3c6820, arg=0x7f0b8a3bdb40, kw=0x0)
      at ../Objects/classobject.c:2600
  #60 0x0000556bdc2f8903 in PyObject_Call (func=0x7f0b8a3c6820, arg=<optimized out>, kw=<optimized out>)
      at ../Objects/abstract.c:2544
  #61 0x0000556bdc37eff8 in slot_tp_call (self=self@entry=0x7f0b8a033c50, args=0x7f0b8a03c0d0, kwds=0x0)
      at ../Objects/typeobject.c:5609
  #62 0x0000556bdc2f8903 in PyObject_Call (func=0x7f0b8a033c50, arg=<optimized out>, kw=<optimized out>)
      at ../Objects/abstract.c:2544
  #63 0x0000556bdc3128dd in do_call (nk=<optimized out>, na=<optimized out>, pp_stack=0x7ffc3ef995f8, func=0x7f0b8a033c50)
      at ../Python/ceval.c:4593
  #64 call_function (oparg=<optimized out>, pp_stack=0x7ffc3ef995f8) at ../Python/ceval.c:4398
  #65 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3013
  #66 0x0000556bdc30b3cc in PyEval_EvalCodeEx (co=0x7f0b8a07d530, globals=<optimized out>, locals=<optimized out>,
      args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x7f0b8a076ee8, defcount=1,
      closure=0x0) at ../Python/ceval.c:3608
  #67 0x0000556bdc325cc2 in function_call (func=0x7f0b8a07f950, arg=0x7f0b8a3bd500, kw=0x7f0b8a042a70)
      at ../Objects/funcobject.c:523
  #68 0x0000556bdc30fa96 in PyObject_Call (kw=0x7f0b8a042a70, arg=0x7f0b8a3bd500, func=0x7f0b8a07f950)
      at ../Objects/abstract.c:2544
  #69 ext_do_call (nk=<optimized out>, na=1, flags=<optimized out>, pp_stack=0x7ffc3ef99830, func=0x7f0b8a07f950)
      at ../Python/ceval.c:4690
  #70 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3052
  #71 0x0000556bdc30b3cc in PyEval_EvalCodeEx (co=0x7f0b8a07d2b0, globals=<optimized out>, locals=<optimized out>,
      args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x0, defcount=0, closure=0x0)
      at ../Python/ceval.c:3608
  #72 0x0000556bdc325b9b in function_call (func=0x7f0b8a07f850, arg=arg@entry=0x7f0b8a3bd9b0, kw=kw@entry=0x0)
      at ../Objects/funcobject.c:523
  #73 0x0000556bdc33f553 in PyObject_Call (kw=0x0, arg=0x7f0b8a3bd9b0, func=<optimized out>) at ../Objects/abstract.c:2544
  #74 instancemethod_call (func=<optimized out>, func@entry=0x7f0b8a4310a0, arg=0x7f0b8a3bd9b0, kw=0x0)
      at ../Objects/classobject.c:2600
  #75 0x0000556bdc2f8903 in PyObject_Call (func=0x7f0b8a4310a0, arg=<optimized out>, kw=<optimized out>)
      at ../Objects/abstract.c:2544
  #76 0x0000556bdc37eff8 in slot_tp_call (self=self@entry=0x7f0b8a033c10, args=0x7f0b8a033fd0, kwds=0x0)
      at ../Objects/typeobject.c:5609
  #77 0x0000556bdc2f8903 in PyObject_Call (func=0x7f0b8a033c10, arg=<optimized out>, kw=<optimized out>)
      at ../Objects/abstract.c:2544
  #78 0x0000556bdc3128dd in do_call (nk=<optimized out>, na=<optimized out>, pp_stack=0x7ffc3ef99d28, func=0x7f0b8a033c10)
      at ../Python/ceval.c:4593
  #79 call_function (oparg=<optimized out>, pp_stack=0x7ffc3ef99d28) at ../Python/ceval.c:4398
  #80 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3013
  #81 0x0000556bdc3125fe in fast_function (nk=<optimized out>, na=<optimized out>, n=<optimized out>, pp_stack=0x7ffc3ef99e38,
      func=0x7f0b8a01ecd0) at ../Python/ceval.c:4461
  #82 call_function (oparg=<optimized out>, pp_stack=0x7ffc3ef99e38) at ../Python/ceval.c:4396
  #83 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3013
  #84 0x0000556bdc3125fe in fast_function (nk=<optimized out>, na=<optimized out>, n=<optimized out>, pp_stack=0x7ffc3ef99f48,
      func=0x7f0b8a01edd0) at ../Python/ceval.c:4461
  #85 call_function (oparg=<optimized out>, pp_stack=0x7ffc3ef99f48) at ../Python/ceval.c:4396
  #86 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3013
  #87 0x0000556bdc30b3cc in PyEval_EvalCodeEx (co=0x7f0b8a081d30, globals=<optimized out>, locals=<optimized out>,
      args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=1, defs=0x7f0b8a008ba8, defcount=10,
      closure=0x0) at ../Python/ceval.c:3608
  #88 0x0000556bdc325cc2 in function_call (func=0x7f0b8a00ddd0, arg=arg@entry=0x7f0b8a033610, kw=kw@entry=0x7f0b8a014a70)
      at ../Objects/funcobject.c:523
  #89 0x0000556bdc33f553 in PyObject_Call (kw=0x7f0b8a014a70, arg=0x7f0b8a033610, func=<optimized out>)
      at ../Objects/abstract.c:2544
  #90 instancemethod_call (func=<optimized out>, func@entry=0x7f0b8a427140, arg=0x7f0b8a033610, arg@entry=0x7f0b8a4e0050,
      kw=kw@entry=0x7f0b8a014a70) at ../Objects/classobject.c:2600
  #91 0x0000556bdc33f10f in PyObject_Call (kw=0x7f0b8a014a70, arg=0x7f0b8a4e0050, func=0x7f0b8a427140)
      at ../Objects/abstract.c:2544
  #92 slot_tp_init (self=self@entry=0x7f0b8a3ebb10, args=args@entry=0x7f0b8a4e0050, kwds=kwds@entry=0x7f0b8a014a70)
      at ../Objects/typeobject.c:5869
  #93 0x0000556bdc2feb87 in type_call (type=<optimized out>, type@entry=0x556bdd2a85c0, args=0x7f0b8a4e0050, kwds=0x7f0b8a014a70)
      at ../Objects/typeobject.c:765
  #94 0x0000556bdc2f8903 in PyObject_Call (func=0x556bdd2a85c0, arg=<optimized out>, kw=<optimized out>)
      at ../Objects/abstract.c:2544
  #95 0x0000556bdc3128dd in do_call (nk=<optimized out>, na=<optimized out>, pp_stack=0x7ffc3ef9a458, func=0x556bdd2a85c0)
      at ../Python/ceval.c:4593
  #96 call_function (oparg=<optimized out>, pp_stack=0x7ffc3ef9a458) at ../Python/ceval.c:4398
  #97 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3013
  #98 0x0000556bdc30b3cc in PyEval_EvalCodeEx (co=0x7f0b8a37d830, globals=<optimized out>, locals=<optimized out>,
      args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x0, defcount=0, closure=0x0)
      at ../Python/ceval.c:3608
  #99 0x0000556bdc311886 in PyEval_EvalCode (locals=0x7f0b8a4ae170, globals=0x7f0b8a4ae170, co=<optimized out>)
      at ../Python/ceval.c:669
  #100 exec_statement (locals=0x7f0b8a4ae170, globals=0x7f0b8a4ae170, prog=<optimized out>, f=<optimized out>)
      at ../Python/ceval.c:5093
  #101 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:2122
  #102 0x0000556bdc30b3cc in PyEval_EvalCodeEx (co=0x7f0b8a3ea4b0, globals=<optimized out>, locals=<optimized out>,
      args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x7f0b8a381068, defcount=5,
      closure=0x0) at ../Python/ceval.c:3608
  #103 0x0000556bdc312953 in fast_function (nk=<optimized out>, na=<optimized out>, n=<optimized out>, pp_stack=0x7ffc3ef9a818,
      func=0x7f0b8a37d8d0) at ../Python/ceval.c:4471
  #104 call_function (oparg=<optimized out>, pp_stack=0x7ffc3ef9a818) at ../Python/ceval.c:4396
  #105 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3013
  #106 0x0000556bdc30b3cc in PyEval_EvalCodeEx (co=0x7f0b8a37d4b0, globals=<optimized out>, locals=<optimized out>,
      args=<optimized out>, argcount=<optimized out>, kws=<optimized out>, kwcount=0, defs=0x7f0b8a379ce8, defcount=1,
      closure=0x0) at ../Python/ceval.c:3608
  #107 0x0000556bdc325b9b in function_call (func=func@entry=0x7f0b8a37de50, arg=0x7f0b8a3b5be0, kw=0x0)
      at ../Objects/funcobject.c:523
  #108 0x0000556bdc2f8903 in PyObject_Call (func=0x7f0b8a37de50, arg=<optimized out>, kw=<optimized out>)
      at ../Objects/abstract.c:2544
  #109 0x0000556bdc3b87e1 in RunModule (module=<optimized out>, set_argv0=1) at ../Modules/main.c:197
  #110 0x0000556bdc3a68ed in Py_Main (argc=<optimized out>, argv=<optimized out>) at ../Modules/main.c:592#111 0x00007f0b8a54bd0a in __libc_start_main (main=0x556bdc3a6530 <main>, argc=5, argv=0x7ffc3ef9ac08, init=<optimized out>,
      fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7ffc3ef9abf8) at ../csu/libc-start.c:308
  #112 0x0000556bdc3a646a in _start ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants