Fix errno handling

Issue #1961 resolved
Armin Rigo created an issue

The handling of errno (and GetLastError on Windows) is fragile. There are cases that can go wrong.

For example, cffi's getwinerror() on Windows tends to return 0 instead of the real error when the code in question happens to be traced. The issue is that in this case, a lot more occurs, and the LastError is overwritten with the value of some unrelated function call from the tracing. But the same problem can occur anywhere: a major GC for example could trigger it.

Instead, we should have a way to save the errno/LastError around a particular function call, which would work at a very low level --- in the section of code that is not protected by the GIL. It would either use some RPython global (thread-local) location, or maybe better, work with an explicitly-provided pointer to a structure containing the saved value(s).

Comments (1)

  1. Log in to comment