This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author theller
Recipients amaury.forgeotdarc, arigo, fijal, loewis, theller
Date 2008-05-23.19:34:25
SpamBayes Score 0.0012965105
Marked as misclassified No
Message-id <48371C37.4070701@ctypes.org>
In-reply-to <4837129C.60002@v.loewis.de>
Content
>> 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?
History
Date User Action Args
2008-05-23 19:34:30thellersetspambayes_score: 0.00129651 -> 0.0012965105
recipients: + theller, loewis, arigo, amaury.forgeotdarc, fijal
2008-05-23 19:34:27thellerlinkissue1798 messages
2008-05-23 19:34:25thellercreate