• Kirill Smelkov's avatar
    golang_str: Fix pybstr/pyustr .tp_dealloc wrt upcoming str=bstr and unicode=ustr · b724d3ee
    Kirill Smelkov authored
    For pybstr/pyustr cython generates .tp_dealloc that refer to
    bytes/unicode types directly. That works ok in normal circumstances, but
    will lead to crash when gpython will start patching builtin str and
    unicode types with bstr and ustr:
    
        (py39.venv) kirr@deca:~/src/tools/go/pygolang-master$ gpython
        Ошибка сегментирования (образ памяти сброшен на диск)
    
        (py39.venv) kirr@deca:~/src/tools/go/pygolang-master$ gdb python core
        ...
        Core was generated by `/home/kirr/src/tools/go/py39.venv/bin/python3.9 /home/kirr/src/tools/go/py39.ve'.
        Program terminated with signal SIGSEGV, Segmentation fault.
        #0  0x00007f2edb247d5c in PyType_HasFeature (type=<error reading variable: Cannot access memory at address 0x7ffc6ca1bff8>,
            feature=<error reading variable: Cannot access memory at address 0x7ffc6ca1bff0>)
            at /home/kirr/local/py3.9/include/python3.9/object.h:622
        622     {
        (gdb) bt
        #0  0x00007f2edb247d5c in PyType_HasFeature (type=<error reading variable: Cannot access memory at address 0x7ffc6ca1bff8>,
            feature=<error reading variable: Cannot access memory at address 0x7ffc6ca1bff0>)
            at /home/kirr/local/py3.9/include/python3.9/object.h:622
        #1  0x00007f2edb2f4b28 in __pyx_tp_dealloc_6golang_7_golang__pyustr (o=0x7f2edae99030) at golang/_golang.cpp:88982
        #2  0x00007f2edb2f4bc8 in __pyx_tp_dealloc_6golang_7_golang__pyustr (o=0x7f2edae99030) at golang/_golang.cpp:88986
        #3  0x00007f2edb2f4bc8 in __pyx_tp_dealloc_6golang_7_golang__pyustr (o=0x7f2edae99030) at golang/_golang.cpp:88986
        #4  0x00007f2edb2f4bc8 in __pyx_tp_dealloc_6golang_7_golang__pyustr (o=0x7f2edae99030) at golang/_golang.cpp:88986
        #5  0x00007f2edb2f4bc8 in __pyx_tp_dealloc_6golang_7_golang__pyustr (o=0x7f2edae99030) at golang/_golang.cpp:88986
        #6  0x00007f2edb2f4bc8 in __pyx_tp_dealloc_6golang_7_golang__pyustr (o=0x7f2edae99030) at golang/_golang.cpp:88986
        #7  0x00007f2edb2f4bc8 in __pyx_tp_dealloc_6golang_7_golang__pyustr (o=0x7f2edae99030) at golang/_golang.cpp:88986
        #8  0x00007f2edb2f4bc8 in __pyx_tp_dealloc_6golang_7_golang__pyustr (o=0x7f2edae99030) at golang/_golang.cpp:88986
        #9  0x00007f2edb2f4bc8 in __pyx_tp_dealloc_6golang_7_golang__pyustr (o=0x7f2edae99030) at golang/_golang.cpp:88986
        #10 0x00007f2edb2f4bc8 in __pyx_tp_dealloc_6golang_7_golang__pyustr (o=0x7f2edae99030) at golang/_golang.cpp:88986
        ...
    
    -> Fix that crash by manually repointing .tp_dealloc of bstr/ustr to
    .tp_dealloc of original bytes and unicode.
    b724d3ee
_golang_str.pyx 82.3 KB