Skip to content

[doc] ctypes: use_errno=True does not work #52008

Closed

Description

@nikratio
mannequin
BPO 7760
Nosy @amauryfa, @abalkin, @meadori, @eryksun, @iritkatriel
Files
  • test1.py: Test case
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/theller'
    closed_at = None
    created_at = <Date 2010-01-23.00:18:56.292>
    labels = ['easy', 'ctypes', 'type-feature', '3.11', 'docs']
    title = '[doc] ctypes: use_errno=True does not work'
    updated_at = <Date 2021-05-18.20:36:39.807>
    user = 'https://bugs.python.org/nikratio'

    bugs.python.org fields:

    activity = <Date 2021-05-18.20:36:39.807>
    actor = 'eryksun'
    assignee = 'theller'
    closed = False
    closed_date = None
    closer = None
    components = ['Documentation', 'ctypes']
    creation = <Date 2010-01-23.00:18:56.292>
    creator = 'nikratio'
    dependencies = []
    files = ['15976']
    hgrepos = []
    issue_num = 7760
    keywords = ['easy']
    message_count = 8.0
    messages = ['98171', '98188', '98195', '189784', '189807', '189886', '393894', '393906']
    nosy_count = 8.0
    nosy_names = ['amaury.forgeotdarc', 'belopolsky', 'marcin.bachry', 'nikratio', 'meador.inge', 'eryksun', 'Matt.Jones', 'iritkatriel']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'needs patch'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue7760'
    versions = ['Python 3.11']

    Linked PRs

    Activity

    1. nikratio commented on Jan 23, 2010

      nikratiomannequin
      MannequinAuthor

      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).

    2. marcinbachry commented on Jan 23, 2010

      marcinbachrymannequin
      Mannequin

      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.

    3. nikratio commented on Jan 23, 2010

      nikratiomannequin
      MannequinAuthor

      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.

    4. BreamoreBoy commented on May 21, 2013

      BreamoreBoymannequin
      Mannequin

      Would someone like to propose a documentation patch that clarifies this situation.

    5. MattJones commented on May 22, 2013

      MattJonesmannequin
      Mannequin

      Is this really a documentation issue? Is it not generally understood that using absolute paths to libraries is a bad idea due to the amount of PATH/symlink spaghetti that the average file system contains?

    6. nikratio commented on May 24, 2013

      nikratiomannequin
      MannequinAuthor

      Matt, I believe in that case it's still a documentation issue, because then the documentation probably should say that using absolute paths to libraries is a bad idea in general.

    7. changed the title [-]use_errno=True does not work[/-] [+]ctypes: use_errno=True does not work[/+] on May 25, 2013
    8. iritkatriel commented on May 18, 2021

      @iritkatriel
      Member

      The recommendation not to use absolute paths in CDLL is still not mentioned in the docs:
      https://docs.python.org/3/library/ctypes.html#ctypes.CDLL

      Adding the (active) ctypes experts to nosy.

    9. changed the title [-]ctypes: use_errno=True does not work[/-] [+][doc] ctypes: use_errno=True does not work[/+] on May 18, 2021
    10. 1 remaining item

    11. eryksun commented on May 18, 2021

      @eryksun
      Contributor

      The recommendation not to use absolute paths in CDLL is still
      not mentioned in the docs:

      It's not generally the case. Load just a base filename only if the shared library is in the loader's search path. Otherwise use a qualified path that contains at least one path separator (e.g. "./library.dll").

    12. transferred this issue fromon Apr 10, 2022
    13. added 3 commits that reference this issue on Mar 27, 2026
    14. added a commit that references this issue on Oct 12, 2026
    15. ZeroIntensity commented on Oct 12, 2026

      @ZeroIntensity
      Member

      The issue described here is obsolete since Ubuntu doesn't have multiple libc versions anymore, but I did add a note to the docs saying that the library must use the same errno as ctypes for it to work. Backports are on auto-merge.

    16. added 2 commits that reference this issue on Oct 12, 2026
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions