Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nikratio mannequin opened this issue Jan 23, 2010 · 8 comments
Open

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

nikratio mannequin opened this issue Jan 23, 2010 · 8 comments
Assignees
Labels
3.11 only security fixes docs Documentation in the Doc dir easy topic-ctypes type-feature A feature request or enhancement

Comments

@nikratio
Copy link
Mannequin

nikratio mannequin commented Jan 23, 2010

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']

    @nikratio
    Copy link
    Mannequin Author

    nikratio mannequin commented Jan 23, 2010

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

    @nikratio nikratio mannequin added the type-bug An unexpected behavior, bug, or error label Jan 23, 2010
    @nikratio nikratio mannequin assigned theller Jan 23, 2010
    @nikratio nikratio mannequin added the topic-ctypes label Jan 23, 2010
    @marcinbachry
    Copy link
    Mannequin

    marcinbachry mannequin commented Jan 23, 2010

    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.

    @nikratio
    Copy link
    Mannequin Author

    nikratio mannequin commented Jan 23, 2010

    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.

    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented May 21, 2013

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

    @MattJones
    Copy link
    Mannequin

    MattJones mannequin commented May 22, 2013

    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?

    @nikratio
    Copy link
    Mannequin Author

    nikratio mannequin commented May 24, 2013

    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.

    @vstinner vstinner changed the title use_errno=True does not work ctypes: use_errno=True does not work May 25, 2013
    @iritkatriel
    Copy link
    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.

    @iritkatriel iritkatriel added easy 3.11 only security fixes docs Documentation in the Doc dir labels May 18, 2021
    @iritkatriel iritkatriel changed the title ctypes: use_errno=True does not work [doc] ctypes: use_errno=True does not work May 18, 2021
    @iritkatriel iritkatriel added type-feature A feature request or enhancement and removed type-bug An unexpected behavior, bug, or error labels May 18, 2021
    @eryksun
    Copy link
    Contributor

    eryksun commented May 18, 2021

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

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes docs Documentation in the Doc dir easy topic-ctypes type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants