Project

General

Profile

Actions

Bug #17629

closed

macOS, readline compiled with libedit: adding entries to history doesn't work unless Readline.readline is called before populating it

Added by radarek (Radosław Bułat) almost 4 years ago. Updated almost 3 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.1.0dev (2021-02-13T02:51:33Z master 813fe4c256) [arm64-darwin20]
[ruby-core:102487]

Description

Description

If Ruby's readline extension is linked with libedit library and readline history is populated before Readline.readline method is called then items are not available via history navigation mechanism (up/down arrows).

How to reproduce

bug.rb (also attached to this issue)

require 'readline'

# calling below code before populating history will make it work
Readline.readline('press enter to continue', false) if ENV['WORKAROUND'] == '1'

Readline::HISTORY << 'Line1'
puts "History: #{Readline::HISTORY.to_a}"
Readline.readline('> ', true)
$ ~/opt/ruby/bin/ruby -v bug.rb
ruby 3.1.0dev (2021-02-13T02:51:33Z master 813fe4c256) [arm64-darwin20]
History: ["Line1"]
> # pressing up arrow doesn't show entries from history

$ WORKAROUND=1 ~/opt/ruby/bin/ruby -v bug.rb
ruby 3.1.0dev (2021-02-13T02:51:33Z master 813fe4c256) [arm64-darwin20]
press enter to continue
History: ["Line1"]
> Line1 # up arrow was pressed here and entry from history was shown up

Bug affects for example pry gem (history doesn't work).

My setup

macOS 11.2.1 Big Sur
architecture: arm64 (apple M1 processor)
ruby -v: ruby 3.1.0dev (2021-02-13T02:51:33Z master 813fe4c256) [arm64-darwin20]

readline extension linkage:
otool -L /Users/radarek/opt/ruby/lib/ruby/3.1.0/arm64-darwin20/readline.bundle
/Users/radarek/opt/ruby/lib/ruby/3.1.0/arm64-darwin20/readline.bundle:
	/usr/lib/libedit.3.dylib (compatibility version 2.0.0, current version 3.0.0)
	/usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1292.60.1)

Files

bug.rb (271 Bytes) bug.rb radarek (Radosław Bułat), 02/14/2021 01:28 PM
Dockerfile (340 Bytes) Dockerfile radarek (Radosław Bułat), 02/14/2021 02:53 PM

Updated by radarek (Radosław Bułat) almost 4 years ago

I added Dockerfile with instructions to build ruby with libedit library to reproduce this bug more easily.

docker docker build -t readline-bug . # run inside directory with Dockerfile and bug.rb files

To reproduce bug:

docker run --rm -it -v $PWD:/app readline-bug /opt/bin/ruby /app/bug.rb
docker run --rm -it -v $PWD:/app -e WORKAROUND=1 readline-bug /opt/bin/ruby /app/bug.rb
Actions #2

Updated by nobu (Nobuyoshi Nakada) almost 4 years ago

Seems libedit needs to be initialized before managing the history.

diff --git a/ext/readline/readline.c b/ext/readline/readline.c
index 9f76f90e41a..b804ae6ae24 100644
--- a/ext/readline/readline.c
+++ b/ext/readline/readline.c
@@ -2088,6 +2088,7 @@ Init_readline(void)
 #if defined HAVE_CLEAR_HISTORY || defined HAVE_REMOVE_HISTORY
     if (strncmp(rl_library_version, EDIT_LINE_LIBRARY_VERSION,
                 strlen(EDIT_LINE_LIBRARY_VERSION)) == 0) {
+        prepare_readline();
         add_history("1");
         if (history_get(history_get_offset_func(0)) == NULL) {
             history_get_offset_func = history_get_offset_0;

Updated by radarek (Radosław Bułat) about 3 years ago

I believe this ticket can be closed as it is fixed in master branch. @nobu (Nobuyoshi Nakada), Thank you for fixing this!

Updated by nobu (Nobuyoshi Nakada) about 3 years ago

  • Backport changed from 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN to 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN

The auto close didn’t seem to work somehow.

Updated by radarek (Radosław Bułat) almost 3 years ago

Can someone close this ticket? I don't see a possibility to do it myself.

Actions #6

Updated by jeremyevans0 (Jeremy Evans) almost 3 years ago

  • Status changed from Open to Closed
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0