Thomas Heller <[EMAIL PROTECTED]> added the comment: >> AFAIU, set_errno/get_errno should provide a ctypes-private copy of the real >> errno. >> The copy is copied into the 'real' errno just before ffi_call (in >> Modules/_ctypes/callproc.c), >> and the real errno is copied in to ctypes copy right after the call. > > If you clear errno, anyway, you can also drop the set_errno call, and
My code sample did not intend to clear errno, it was intended to set errno to the last value that the ctypes-copy had before the call. > zero-initialize errno before each call. The point of set_errno would > be that you have the choice of *not* calling it, i.e. passing into > the function the errno value that was there before you made the API > call. If you fill something else into errno always, the application has > no way of not modifying errno before the API call. To make my point clear (in case is isn't already): In the code sample that Armin posted, it is impossible to guarantee that no stdlib function is called between the readdir() and the get_errno() call: dirent = linux_c_lib.readdir(byref(dir)) if not dirent: if ctypes.get_errno() == 0: Consider the garbage collector free some objects that release resources they have, in other words call functions different from free(3). Similarly for calling set_errno() or not calling it; other stdlib function calls in the meantime may have changed errno and that might not be what the Python programmer expects. Anyway, how can we proceed? Do you have a suggestion? Should set_errno() set a flag that is examined and consumed before call_function_pointer() is called? __________________________________ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1798> __________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com