• Kirill Smelkov's avatar
    bigfile/py: Teach storeblk() how to correctly propagate traceback on error · 6da5172e
    Kirill Smelkov authored
    Previously we were limited to printing traceback starting down from just
    storeblk() via explicit PyErr_PrintEx() - because pybuf was attached to
    memory which could go away right after return from C function - so we
    had to destroy that object for sure, not letting any traceback to hold a
    reference to it.
    
    This turned out to be too limiting and not showing full context where
    errors happen.
    
    So do the following trick: before returning, reattach pybuf to empty
    region at NULL, and this way we don't need to worry about pybuf pointing
    to memory which can go away -> thus instead of printing exception locally
    - just return it the usual way it is done with C api in Python.
    
    NOTE In contrast to PyMemoryViewObject, PyBufferObject definition is not
    public, so to support Python2 - had to copy its definition to PY2 compat
    header.
    
    NOTE2 loadblk() is not touched - the loading is done from sighandler
    context, which simulates as if it work in separate python thread, so it
    is leaved as is for now.
    6da5172e
compat_py2.h 1.21 KB