classification
Title: use_errno=True does not work
Type: behavior Stage: needs patch
Components: ctypes Versions: Python 3.1, Python 2.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: theller Nosy List: Nikratio, marcin.bachry, theller
Priority: normal Keywords:

Created on 2010-01-23 00:18 by Nikratio, last changed 2010-01-23 19:37 by Nikratio.

Files
File name Uploaded Description Edit
test1.py Nikratio, 2010-01-23 00:18 Test case
Messages (3)
msg98171 - (view) Author: Nikolaus Rath (Nikratio) Date: 2010-01-23 00:18
On my system (Ubuntu Karmic, Python 2.6.4 (r264:75706, Dec  7 2009, 18:45:15), Kernel 2.6.31-17-generic, libc6 2.10.1-0ubuntu16) the attached test script produces the following output:

Traceback (most recent call last):
  File "test1.py", line 27, in <module>
    raise OSError(err, os.strerror(err), path)
OSError: [Errno 0] Success: '/does/not/exist'

So the function call failed, but the errno provided by ctypes is zero.

(There are two variants of construction the getxattr() foreign function in the script and both produce the same result).
msg98188 - (view) Author: Marcin Bachry (marcin.bachry) Date: 2010-01-23 16:58
In the libc case you shouldn't give absolute path in CDLL: CDLL('libc.so.6') is better. You use "/lib/libc.so.6" path, but Python (and ctypes.so) actually uses something like "/lib/tls/i686/cmov/libc.so.6" - these are two separate libraries with separate "errno" variables, mapped to different memory regions. Your call to getxattr modifies errno in the former library, but ctypes get_errno() fetches value from the latter library.

If I fix CDLL() call, the test works ok for me.
msg98195 - (view) Author: Nikolaus Rath (Nikratio) Date: 2010-01-23 19:37
I can confirm that without the path it works for me too.

But I have to admit that I don't really understand your explanation. Should I generally not use full paths with CDLL? Or just in the case of libc?

In either case, I think the ctypes dokumentation could be more explicit about this.
History
Date User Action Args
2010-01-23 19:37:51Nikratiosetmessages: + msg98195
2010-01-23 16:59:00marcin.bachrysetnosy: + marcin.bachry
messages: + msg98188
2010-01-23 00:23:04brian.curtinsetpriority: normal
stage: needs patch
2010-01-23 00:18:56Nikratiocreate