Skip to content

Error scope constructor causes access violation in ~error_already_set() #1779

@AndreasSchoenle

Description

@AndreasSchoenle

When using error_already_set() in code that is called from a C++ program, the error_scope constructor crashes due to non-existent thread state. The C++ Code acquires the thread state through PyGILState_Ensure(), when throwing the error_already_set() PyGILState_Release() is called during thread exit.

It seems to me that when the destructor is called, the crash occurs because the current thread does not hold the GIL.

About the destructor:

error_scope scope;

Could it be that the two calls:

error_scope scope;
gil_scoped_acquire gil;

have to be reversed? Also, why is error_scope needed - as I understand we just need the GIL to decrease the ref count on the held error objects?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions