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.17:47:18
SpamBayes Score 0.0034433613
Marked as misclassified No
Message-id <48370324.6060705@ctypes.org>
In-reply-to <4837001B.5010908@v.loewis.de>
Content
>> Using the native errno instead of a custom TLS value is bad because a
>> lot of things can occur
> 
> So what's the semantics of set_errno then? Set the real errno? If so,
> what if it gets changed between the call to set_errno, and the actual
> invocation of API function? Set the TLS errno? If so, when does it get
> copied into the real errno?

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.

Probably the real errno from before this action should be restored at the end.

Code that I have in mind:

__thread int _ctypes_errno; /* ctypes-private global error number in thread local storage */

static int _call_function_pointer(...)
{
   int old_errno;
   .
   .
   old_errno = errno;
   errno = _ctypes_errno;
   ffi_call(....);
   _ctypes_errno = errno;
   errno = old_errno;
   .
   .
}

static PyObject *
_ctypes_set_errno(PyObject *self, Pyobject *args)
{
    .
    _ctypes_errno = parsed_argument;
    .
}

static PyObject *
_ctypes_get_errno(PyObject *self, Pyobject *args)
{
    return PyInt_FromLong(_ctypes_errno);
}
History
Date User Action Args
2008-05-23 17:47:24thellersetspambayes_score: 0.00344336 -> 0.0034433613
recipients: + theller, loewis, arigo, amaury.forgeotdarc, fijal
2008-05-23 17:47:20thellerlinkissue1798 messages
2008-05-23 17:47:19thellercreate