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

Support system readline on OS X 10.6 #51121

Closed
mdickinson opened this issue Sep 9, 2009 · 12 comments
Closed

Support system readline on OS X 10.6 #51121

mdickinson opened this issue Sep 9, 2009 · 12 comments
Assignees
Labels
build The build process and cross-build extension-modules C modules in the Modules dir OS-mac type-feature A feature request or enhancement

Comments

@mdickinson
Copy link
Member

BPO 6872
Nosy @loewis, @ronaldoussoren, @mdickinson, @ericvsmith, @zvezdan
Files
  • snow_leopard_readline.patch
  • 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/ronaldoussoren'
    closed_at = <Date 2009-09-20.14:55:53.766>
    created_at = <Date 2009-09-09.19:03:27.071>
    labels = ['extension-modules', 'OS-mac', 'type-feature', 'build']
    title = 'Support system readline on OS X 10.6'
    updated_at = <Date 2009-09-24.20:18:12.463>
    user = 'https://github.com/mdickinson'

    bugs.python.org fields:

    activity = <Date 2009-09-24.20:18:12.463>
    actor = 'mark.dickinson'
    assignee = 'ronaldoussoren'
    closed = True
    closed_date = <Date 2009-09-20.14:55:53.766>
    closer = 'ronaldoussoren'
    components = ['Build', 'Extension Modules', 'macOS']
    creation = <Date 2009-09-09.19:03:27.071>
    creator = 'mark.dickinson'
    dependencies = []
    files = ['14868']
    hgrepos = []
    issue_num = 6872
    keywords = ['patch']
    message_count = 12.0
    messages = ['92457', '92458', '92460', '92463', '92475', '92485', '92486', '92492', '92653', '92655', '92896', '93093']
    nosy_count = 6.0
    nosy_names = ['loewis', 'ronaldoussoren', 'mark.dickinson', 'eric.smith', 'zvezdan', 'purpleidea']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = None
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue6872'
    versions = ['Python 2.6', 'Python 3.1', 'Python 2.7', 'Python 3.2']

    @mdickinson
    Copy link
    Member Author

    The readline library supplied in OS X 10.6 looks good enough to use in
    Python. It would be nice to enable building with this library, to avoid
    having to install GNU readline.

    There's a curious off-by-one difference between Apple's readline (which,
    as I understand it, is just libedit wrapped to look like libreadline)
    and GNU readline: with 'n' history items, the valid indices for Apple's
    readline are 0 through n-1; for GNU they're 1 through n.

    I was able to get Python trunk + system readline working on OS X 10.6
    using the attached patch (which obviously isn't suitable for applying,
    since it breaks the build with a non-system readline). A side effect of
    the patch is that readline.get_history_item and friends store the first
    history entry with index 0 rather than 1:

    Python 2.7a0 (trunk:74735M, Sep  9 2009, 19:40:25) 
    [GCC 4.2.1 (Apple Inc. build 5646)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import readline
    [39474 refs]
    >>> readline.get_history_item(0)
    'import readline'
    [39476 refs]
    >>> readline.get_history_item(2)
    'readline.get_history_item(2)'
    [39476 refs]

    Interestingly, the Apple-supplied Python also behaves this way:

    Mark-Dickinsons-MacBook-Pro:trunk dickinsm$ python
    Python 2.6.1 (r261:67515, Jul  7 2009, 23:51:51) 
    [GCC 4.2.1 (Apple Inc. build 5646)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import readline
    >>> readline.get_history_item(0)
    'import readline'
    >>> readline.get_history_item(2)
    'readline.get_history_item(2)'

    If people think this is worth pursuing, I'll put together a proper
    patch.

    @mdickinson mdickinson added build The build process and cross-build extension-modules C modules in the Modules dir OS-mac type-feature A feature request or enhancement labels Sep 9, 2009
    @mdickinson
    Copy link
    Member Author

    And here's the patch.

    @ronaldoussoren
    Copy link
    Contributor

    I wouldn't mind having a proper patch and doing away with the need for
    GNU's readline.

    IMHO the patch should try to stay as close to GNU readline's interface
    as possible, and should therefore fix the off-by-one difference you
    mention.

    BTW. I suppose the configuration (readline.parse_and_bind) needs to be
    in libedit format rather than readline format. If so, we should add
    something to the readline documentation about that and possibly add
    something to the readline library to make it possible to detect if
    readline is ultimately linked to libedit.

    BTW. If you want to push the Apple's readline to the limit you should
    try if it works properly with ipython. It used to cause hard crashes
    with Apple's python in 10.5.

    @mdickinson
    Copy link
    Member Author

    Hmm. This is looking like a bigger task than I bargained for. I notice
    that the readline library currently has no tests (or maybe I'm just
    failing to find them). I'm not even sure how to go about writing tests
    for readline.

    IMHO the patch should try to stay as close to GNU readline's interface
    as possible, and should therefore fix the off-by-one difference you
    mention.

    I suppose so. I'm a bit worried about subtle bugs occurring as a result
    of fixing off-by-one differences in some places and missing them in
    others; it seems safer to provide direct access to the library behaviour
    without trying to fix anything. Third-party stuff that wants to work with
    Apple's Python is also going to have to deal with zero-based history. So
    I guess I'd prefer not to fix the off-by-one difference; this would make
    it even more important to provide some way for users to tell whether
    they're using GNU readline or the wrapped libedit version.

    Thanks for the ipython suggestion; I've never used it before, but I'll
    see if I can play around with it a bit.

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Sep 10, 2009

    I also agree that this is desirable to have, and that the readline module
    should provide the GNU semantics even with a different implementation.

    @zvezdan
    Copy link
    Mannequin

    zvezdan mannequin commented Sep 10, 2009

    This patch could potentially break non-Mac OS X systems.
    Fortunately, I have a patch that works with systems that use GNU
    readline and systems that use editline emulation. See bpo-6877.

    Unfortunately, I was lingering for over a year with opening a tracker
    issue for it. Last night I did the last testing session with the trunk
    checkout and I did not notice that this issue has been opened in the
    meantime.

    Sorry for opening the double issue.
    I think that the patch from bpo-6877 should be used.

    @zvezdan
    Copy link
    Mannequin

    zvezdan mannequin commented Sep 10, 2009

    Also, the patch from bpo-6877 changes setup.py in a way that enables
    build of the readline module on Leopard as well.

    Such build is used for about two years already (Python 2.4) by several
    people in my company and nobody noticed any issues on Mac OS X Leopard.
    AFAICT, it works the same now on Snow Leopard.

    @purpleidea
    Copy link
    Mannequin

    purpleidea mannequin commented Sep 10, 2009

    it seems to me, that any and all readline interfaces should/could
    standardize to the indexing scheme as used by the language; maybe i'm
    wrong, but since python is zero based, so could the readline interfaces.

    it's definitely more logical for a python programmer to expect
    zero-based, and the code will match with the python code.

    i would propose that everything be zero-based;
    this is duplicate/similar of/to http://bugs.python.org/issue6786

    @ronaldoussoren
    Copy link
    Contributor

    purpleidea : Whether or not indexes should be 0-based in general is beyond
    the scope of this issue.

    @ronaldoussoren
    Copy link
    Contributor

    I've added an updated patch to bpo-6877 that implements the same 1-based
    indexing as GNU's readline and also adds a note to the documentation to
    warn users about the possibility of linking the readline module to
    libedit.

    That patch would, possibly with clearer documentation, IMHO fix this
    issue.

    @ronaldoussoren
    Copy link
    Contributor

    This is a duplicate of bpo-6877, I'm therefore closing this one.

    I've just committed a slightly updated patch from that issue to the trunk
    and 3.2.

    @mdickinson
    Copy link
    Member Author

    Thanks for working on this, Ronald.

    @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
    build The build process and cross-build extension-modules C modules in the Modules dir OS-mac type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants