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.

classification
Title: sanity check for readline remove/replace
Type: Stage:
Components: Extension Modules Versions:
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: dsm001, loewis, mdehoon
Priority: normal Keywords: patch

Created on 2004-12-31 02:22 by dsm001, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
fix_1086603.patch dsm001, 2004-12-31 02:22 patch against head
Messages (5)
msg47429 - (view) Author: DSM (dsm001) Date: 2004-12-31 02:22
Fix bug 1086603 (segfault in readline) by checking for
negative input indices in remove_history_item and
replace_history_item; GNU code doesn't always return NULL.
msg47430 - (view) Author: Michiel de Hoon (mdehoon) * Date: 2005-01-21 02:20
Logged In: YES 
user_id=488897

I have run the test suite after applying this patch, and I
found no problems with it. The bug does indeed originate in
the readline library, which does not return NULL if the
index is negative. I sent a patch to bug-readline@gnu.org,
so this will probably be fixed in future versions of
readline. But I agree that for now, we need a workaround in
Python.
Note that there is one more way to fix this bug, which is to
interpret negative indeces as counting from the end. So
remove_history_item(-1) removes the last item added to the
history etc. This would be more consistent with lists etc.
in Python, and users may even expect this behavior.
msg47431 - (view) Author: DSM (dsm001) Date: 2005-01-21 02:57
Logged In: YES 
user_id=1175690

You could do it, but it'd be a larger change: e.g.
get_history_item should change as well.  The API isn't very
listish.

Right now get_history_item(-1) returns None, which I left
alone because I didn't want to change any previously-working
behaviour of the code, though I doubt many people are
depending on that..  This comes at the cost of introducing
an arguable inconsistency: get_history_item(-1) simply
returns None but remove_history_item(-1) raises an error.

I wasn't sure to what degree py-gnu-readline is supposed to
hew to gnu-readline, so I left everything alone but the case
that was segfaulting my fuzz test. :-)
msg47432 - (view) Author: Michiel de Hoon (mdehoon) * Date: 2005-01-21 05:26
Logged In: YES 
user_id=488897

I think that both solutions would be good (certainly better
than segfaulting). I'll write a patch review to the
python-dev mailing list outlining the pros and cons, so
hopefully a developer will look at this patch (I don't have
CVS write access, so I can't apply the patch myself).
msg47433 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2005-02-27 20:34
Logged In: YES 
user_id=21627

Thanks for the patch. Applied as

NEWS 1.1246 and 1.1193.2.22
readline.c 2.80 and 2.79.2.1
History
Date User Action Args
2022-04-11 14:56:08adminsetgithub: 41381
2004-12-31 02:22:07dsm001create