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, theller
Date 2008-01-12.19:56:54
SpamBayes Score 0.003617879
Marked as misclassified No
Message-id <47891B83.9080306@ctypes.org>
In-reply-to <1200086872.52.0.872764863612.issue1798@psf.upfronthosting.co.za>
Content
> But this thread-local attribute on the function seems bizarre to me.
> I would prefer another way to get the errno. I can see two alternatives:
> - the function returns a tuple (normalresult, errno) on each call.
> - when errno is not zero, EnvironmentError (or WindowsError) is raised.

I'd stronly prefer NOT to add errno to the function return value.
Raising an Exception when errno or LastError != zero is wrong.
There are functions that set the errno or LastError value even
if they actually succeed.

The recommended way to check for errors that I had in mind is in
the 'errcheck' result checker:

  func = CDLL(..., errno=True)
  func.argtypes = [...]
  func.restype = ...
  def errcheck(result, func, args):
      if result == -1: # function failed
          raise EnvironmentError(func.errno)
  func.errcheck = errcheck

Of course, an alternative to a thread local storage
attribute would be to pass the error value to the errcheck
function. I just felt it would be better not to change
the signature, but maybe I was wrong.

Anyway, this patch should be extended so that it is also possible
to create a foreign function using the descibed calling convention
from a prototype created by CFUNCTYPE or WINFUNCTYPE.
History
Date User Action Args
2008-01-12 19:56:55thellersetspambayes_score: 0.00361788 -> 0.003617879
recipients: + theller, amaury.forgeotdarc
2008-01-12 19:56:54thellerlinkissue1798 messages
2008-01-12 19:56:54thellercreate