Code Monkey home page Code Monkey logo

perl-trg's People

Contributors

gldrk avatar hirooih avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

perl-trg's Issues

function_of_keyseq() triggers fatal error when key sequence is not defined

I think this function should not require the user to parse function_dumper()
output to know which sequences are safe to query.

use v5.30;
use Term::ReadLine;
my $term = Term::ReadLine->new('keyboard code and custom dispatch test');
say $term->get_function_name(($term->function_of_keyseq("\e[A"))[0]);
my $function_object = $term->function_of_keyseq("\e");
say "got function object";
say $term->get_function_name(($term->function_of_keyseq("\e"))[0]);
say "got function name";
perl test-function-of-keyseq
previous-history
got function object
Term::ReadLine::Gnu::XS::rl_get_function_name: Expected function to be of type rl_command_func_tPtr; got Keymap=SCALAR(0x55f129e3fe38) instead at /home/jroth/.plenv/versions/5.38.0/lib/perl5/site_perl/5.38.0/x86_64-linux/Term/ReadLine/Gnu.pm line 886.

add_defun() can define 13 functions max.

The BUGS section of the manual says up to 16 functions may be defined using add_defun(). This test code fails after 13 functions are defined.

use v5.30;
use Term::ReadLine;
my $term = Term::ReadLine->new('custom function test');
my $coderef = sub { say "hello" };
my %escape_code;
read_esc_codes();
my $i = 0;
while ( my ($func_name,$seq) = each %escape_code) {
	$term->add_defun($func_name, $coderef);
	$term->bind_keyseq($seq, $func_name);
	say ++$i;
}


sub read_esc_codes {
%escape_code = qw(

  Escape  	\\e

  Insert  	\\e[2~
  Home  	\\e[1~
  PageUp  	\\e[5~

  Delete  	\\e[3~
  End  		\\e[4~
  PageDown  \\e[6~

  Up  		\\e[A
  Left  	\\e[D
  Down  	\\e[B
  Right  	\\e[C

  F1		\\eOP
  F2		\\eOQ
  F3		\\eOR
  F4		\\eOS
  F5		\\e[15~ 
  F6		\\e[17~ 
  F7		\\e[18~ 
  F8		\\e[19~ 
  F9		\\e[20~ 
  F10		\\e[21~ 
  F11		\\e[23~ 
  F12		\\e[24~ 

  Keypad/	\\eOo
  Keypad*	\\eOj
  Keypad-   \\eOm
  Keypad+   \\eOk
  Keypad7   \\eOw
  Keypad8   \\eOx
  Keypad9   \\eOy
  Keypad4   \\eOt
  Keypad5   \\eOu
  Keypad6   \\eOv
  Keypad1   \\eOq
  Keypad2   \\eOr
  Keypad3   \\eOs
  Keypad0   \\eOp
  Keypad.   \\eOn
  KeypadEnter   \\eOM
  
);
}

custom bindings remain in effect after changing the active keymap back to 'emacs' with set_keymap()

Description:

I am using multiple keymaps. I copy the
default 'emacs' keymap, rename it 'nama',
select keymap 'nama' and apply custom bindings.

Inputting arrow keys in the test code below
display the key codes.

When I return to 'emacs' keymap, the address
is different, and the bindings for 'nama'
are still in effect.

Results (with my comments):

git:master ~/build/nama/src $ perl test-readline-keymap2
emacs keymap address: Keymap=SCALAR(0x555bc647a150)
keymap name: emacs
nama keymap address: Keymap=SCALAR(0x555bc6440258)
keymap name: nama
rebinding arrow keys
prompt>Special key: Left, escape sequence: \e[D, decimal: 27 91 68 , hex: 1B 5B 44

Special key: Right, escape sequence: \e[C, decimal: 27 91 67 , hex: 1B 5B 43


got:
prompt>emacs
got: emacs
setting keymap: emacs
name: emacs, address: Keymap=SCALAR(0x555bc6340908)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# I expect the same memory address as emacs above

should be normal arrow keys
prompt>Special key: Up, escape sequence: \e[A, decimal: 27 91 65 , hex: 1B 5B 41
       ^^^^^^^^^^^^^^^
# I expect emacs keybindings

emacs
Special key: Down, escape sequence: \e[B, decimal: 27 91 66 , hex: 1B 5B 42
emacs
Special key: Up, escape sequence: \e[A, decimal: 27 91 65 , hex: 1B 5B 41
emacs
Special key: Down, escape sequence: \e[B, decimal: 27 91 66 , hex: 1B 5B 42
emacs

got:
prompt>nama
got: nama
setting keymap: nama
name: nama, address: Keymap=SCALAR(0x555bc6498b28)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# I expect same address as nama above.

should be magic arrow keys
prompt>Special key: Up, escape sequence: \e[A, decimal: 27 91 65 , hex: 1B 5B 41
nama
Special key: Down, escape sequence: \e[B, decimal: 27 91 66 , hex: 1B 5B 42
nama
Special key: Up, escape sequence: \e[A, decimal: 27 91 65 , hex: 1B 5B 41
nama
Special key: Down, escape sequence: \e[B, decimal: 27 91 66 , hex: 1B 5B 42
nama

got:
prompt>emacs
got: emacs
setting keymap: emacs
name: emacs, address: Keymap=SCALAR(0x555bc6340908)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# different address again

# try setting emacs keymap by eval:

should be normal arrow keys
prompt>eval $term->set_keymap($term->get_keymap_by_name('emacs'))
got: eval $term->set_keymap($term->get_keymap_by_name('emacs'))
eval'ing

prompt>Special key: Up, escape sequence: \e[A, decimal: 27 91 65 , hex: 1B 5B 41
       ^^^^^^^^^^^^^^^
# still getting custom bindings

eval $term->set_keymap($term->get_keymap_by_name('emacs'))
Special key: Down, escape sequence: \e[B, decimal: 27 91 66 , hex: 1B 5B 42
eval $term->set_keymap($term->get_keymap_by_name('emacs'))
Special key: Up, escape sequence: \e[A, decimal: 27 91 65 , hex: 1B 5B 41
eval $term->set_keymap($term->get_keymap_by_name('emacs'))

Code:


use v5.30;
use Term::ReadLine;
my $term = Term::ReadLine->new('keyboard code and custom dispatch test');
my $emacs = $term->get_keymap;
say "emacs keymap address: $emacs";
my $name = $term->get_keymap_name($emacs);
say "keymap name: $name";

my $nama = $term->copy_keymap($emacs);
$term->set_keymap_name('nama',$nama);
$term->set_keymap($nama);
$name = $term->get_keymap_name($term->get_keymap);
say "nama keymap address: $nama";
say "keymap name: $name";
say "rebinding arrow keys";

my %escape_code; # Insert -> \e[2~
my %keyname;     # \e[2~  -> Insert
read_esc_codes();
my $func_name = 'hotkey_dispatch';
my $coderef = \&hotkey_dispatch;
$term->add_defun($func_name, $coderef);
while ( my ($keyname,$seq) = each %escape_code) {
	$term->bind_keyseq($seq, $func_name);
}
sub hotkey_dispatch {                                                                          
	my ($seq, $decimal, $hex) = string_to_escape_code($term->Attribs->{executing_keyseq});
	my $name = $keyname{$seq};
	say "Special key: $name, escape sequence: $seq, decimal: $decimal, hex: $hex";
	say
}                                                                                              
sub string_to_escape_code {
    my ($string) = @_;                                                                         
    my $esc = '';
	my $decimal = '';
	my $hex = '';
    for my $char (split //, $string) {
		my $ord = ord($char);
		# It seems that readline intercepts control characters
		# so don't try to convert them.
        $char = '\e' if $ord == 27; 
        $decimal .= "$ord ";
        $esc .= $char;
		$hex .= sprintf("%02X ", $ord);
    }
    $esc, $decimal, $hex;
} 

sub read_esc_codes {

  %escape_code = qw(

  Escape  	\\e

  Insert  	\\e[2~
  Delete  	\\e[3~
  Home  	\\e[1~
  End  		\\e[4~
  PageUp  	\\e[5~
  PageDown  \\e[6~

  Up  		\\e[A
  Left  	\\e[D
  Down  	\\e[B
  Right  	\\e[C

  F1		\\eOP
  F2		\\eOQ
  F3		\\eOR
  F4		\\eOS
  F5		\\e[15~ 
  F6		\\e[17~ 
  F7		\\e[18~ 
  F8		\\e[19~ 
  F9		\\e[20~ 
  F10		\\e[21~ 
  F11		\\e[23~ 
  F12		\\e[24~ 

  Keypad/	\\eOo
  Keypad*	\\eOj
  Keypad-   \\eOm
  Keypad+   \\eOk
  Keypad7   \\eOw
  Keypad8   \\eOx
  Keypad9   \\eOy
  Keypad4   \\eOt
  Keypad5   \\eOu
  Keypad6   \\eOv
  Keypad1   \\eOq
  Keypad2   \\eOr
  Keypad3   \\eOs
  Keypad0   \\eOp
  Keypad.   \\eOn
  KeypadEnter   \\eOM
  
);
%keyname = ( reverse %escape_code );
}
while ( defined ($_ = $term->readline('prompt>')) ) {
	say "got: $_";
	if (/^eval/) {
		say "eval'ing";
		say eval($_);
		next	
	} 
	if (/nama|emacs/){
	say "setting keymap: $_" ;
	set_keymap($_);
	}
}

sub set_keymap {
	my $name = shift;
	my $keymap = $term->get_keymap_by_name($name);
	$term->set_keymap($keymap);
	$keymap = $term->get_keymap;
	$name = $term->get_keymap_name($keymap);
	say "name: $name, address: $keymap";
	say "should be normal arrow keys" if $name =~ /emacs/;
	say "should be magic arrow keys" if $name =~ /nama/;
}
__END__

Cannot find -ltinfo starting with release 1.38

I tried to build the package with Perl 5.32.1 however the build process doesn't work starting with the release 1.38.
I haven't changed the building procedure and have used the following commands:

$ tar xzf /home/apps/sources/p/Perl/extensions/Term-ReadLine-Gnu-1.40.tar.gz
$ perl Makefile.PL PREFIX=/home/apps/USE/easybuild/staging/2021.2/software/Perl/5.32.1-GCCcore-10.3.0

gcc  -D_REENTRANT -D_GNU_SOURCE -O2 -ftree-vectorize -march=native -fno-math-errno -fPIC -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2  -O rlver.c -o rlver    -fstack-protector-strong -L/usr/local/lib -lreadline -ltinfo
/home/apps/USE/easybuild/staging/2021.2/software/binutils/2.36.1-GCCcore-10.3.0/bin/ld.gold: error: cannot find -ltinfo
collect2: error: ld returned 1 exit status
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Could not compile rlver.c.

system(): Inappropriate ioctl for device

If you have installed the GNU Readline Library (libreadline.{a,so} and
readline/readline.h, etc.) on directories for which your perl is not
configured to search (refer the value of `ccflags' and `libpath' in
the output of `perl -V'), specify the paths as follows;

        perl Makefile.PL --includedir=/yourdir/include --libdir=/yourdir/lib
or
        perl Makefile.PL --prefix=/yourdir

Note that the GNU Readline Library version 2.0 and earlier causes error
here.  Update it to version 2.1 and/or later.

Read INSTALL for more details.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!```


Exactly the same process with 1.37 works flawlessly.

`cpanm Term::ReadLine::Gnu` fails under docker

Describe the bug
Can't install cpanm Term::ReadLine::Gnu under docker (TERM is not set).

To Reproduce
Steps to reproduce the behavior:

Dockerfile:

FROM alpine:3.16
RUN set -x \
    && apk add perl perl-app-cpanminus ncurses-dev readline-dev perl-dev build-base \
    && cpanm Term::ReadLine::Gnu || { r=$?; cat /root/.cpanm/work/*/build.log; exit $r; }
$ docker build -t i .
...
+ cpanm Term::ReadLine::Gnu
--> Working on Term::ReadLine::Gnu
Fetching https://www.cpan.org/authors/id/H/HA/HAYASHI/Term-ReadLine-Gnu-1.42.tar.gz ... OK
Configuring Term-ReadLine-Gnu-1.42 ... OK
Building and testing Term-ReadLine-Gnu-1.42 ... ! Installing Term::ReadLine::Gnu failed. See /root/.cpanm/work/1662628609.10/build.log for details. Retry with --force to force install it.
FAIL
+ r=1
+ cat /root/.cpanm/work/1662628609.10/build.log
cpanm (App::cpanminus) 1.7046 on perl 5.034001 built for x86_64-linux-thread-multi
Work directory is /root/.cpanm/work/1662628609.10
You have make /usr/bin/make
You have /usr/bin/wget
You have /bin/tar: tar (busybox) 1.35.0
You have /usr/bin/unzip
Searching Term::ReadLine::Gnu () on cpanmetadb ...
--> Working on Term::ReadLine::Gnu
Fetching https://www.cpan.org/authors/id/H/HA/HAYASHI/Term-ReadLine-Gnu-1.42.tar.gz
-> OK
Unpacking Term-ReadLine-Gnu-1.42.tar.gz
Entering Term-ReadLine-Gnu-1.42
Checking configure dependencies from META.json
Checking if you have ExtUtils::MakeMaker 6.58 ... Yes (7.62)
Configuring Term-ReadLine-Gnu-1.42
Running Makefile.PL
Warning (mostly harmless): No library found for -ltermcap
Warning (mostly harmless): No library found for -ltinfo
<<<It seems that you have the GNU Readline Library version 8.1.>>>
Checking if your kit is complete...
Looks good
Generating a Unix-style Makefile
Writing Makefile for Term::ReadLine::Gnu
Writing MYMETA.yml and MYMETA.json
-> OK
Checking dependencies from MYMETA.json ...
Checking if you have ExtUtils::MakeMaker 0 ... Yes (7.62)
Building and testing Term-ReadLine-Gnu-1.42
cp Gnu.pm blib/lib/Term/ReadLine/Gnu.pm
cp Gnu/XS.pm blib/lib/Term/ReadLine/Gnu/XS.pm
AutoSplitting blib/lib/Term/ReadLine/Gnu/XS.pm (blib/lib/auto/Term/ReadLine/Gnu/XS)
blib/lib/Term/ReadLine/Gnu/XS.pm: some names are not unique when truncated to 8 characters:
 directory blib/lib/auto/Term/ReadLine/Gnu/XS:
  rl_bind_key.al, rl_bind_key_if_unbound.al, rl_bind_keyseq.al, rl_bind_keyseq_if_unbound.al truncate to rl_bind_
  rl_set_keymap.al, rl_set_key.al truncate to rl_set_k
Running Mkbootstrap for Gnu ()
chmod 644 "Gnu.bs"
"/usr/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- Gnu.bs blib/arch/auto/Term/ReadLine/Gnu/Gnu.bs 644
"/usr/bin/perl" "/usr/share/perl5/core_perl/ExtUtils/xsubpp"  -typemap '/usr/share/perl5/core_perl/ExtUtils/typemap' -typemap '/root/.cpanm/work/1662628609.10/Term-ReadLine-Gnu-1.42/typemap'  Gnu.xs > Gnu.xsc
mv Gnu.xsc Gnu.c
cc -c   -D_REENTRANT -D_GNU_SOURCE -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -Os -fomit-frame-pointer   -DVERSION=\"1.42\" -DXS_VERSION=\"1.42\" -fPIC "-I/usr/lib/perl5/core_perl/CORE"  -DTRG_READLINE_VERSION=0x0801 Gnu.c
rm -f blib/arch/auto/Term/ReadLine/Gnu/Gnu.so
LD_RUN_PATH="/usr/lib" cc  -shared -Os -fomit-frame-pointer -L/usr/local/lib -fstack-protector-strong  Gnu.o  -o blib/arch/auto/Term/ReadLine/Gnu/Gnu.so  \
   -lreadline -lncurses   \
  
chmod 755 blib/arch/auto/Term/ReadLine/Gnu/Gnu.so
cp eg/perlsh blib/script/perlsh
"/usr/bin/perl" -MExtUtils::MY -e 'MY->fixin(shift)' -- blib/script/perlsh
Manifying 1 pod document
Manifying 1 pod document
"/usr/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- Gnu.bs blib/arch/auto/Term/ReadLine/Gnu/Gnu.bs 644
PERL_DL_NONLAZY=1 "/usr/bin/perl" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
Use of uninitialized value $Term::ReadLine::Gnu::VERSION in concatenation (.) or string at t/00checkver.t line 27.

#   Failed test 'An object of class 'Term::ReadLine::Stub' isa 'Term::ReadLine''
#   at t/00checkver.t line 30.
#     The object of class 'Term::ReadLine::Stub' isn't a 'Term::ReadLine'

#   Failed test ''Attribs' isa 'Term::ReadLine''
#   at t/00checkver.t line 32.
#     'Attribs' isn't a 'Term::ReadLine'
Use of uninitialized value in concatenation (.) or string at t/00checkver.t line 36.
Use of uninitialized value in printf at t/00checkver.t line 36.
Use of uninitialized value $ENV{"TERM"} in concatenation (.) or string at t/00checkver.t line 37.
# Looks like you failed 2 tests of 4.
t/00checkver.t ... 
Dubious, test returned 2 (wstat 512, 0x200)
Failed 2/4 subtests 
t/01test_use.t ... ok
t/02test_use.t ... ok

#   Failed test 'An object of class 'Term::ReadLine::Stub' isa 'Term::ReadLine''
#   at t/callback.t line 36.
#     The object of class 'Term::ReadLine::Stub' isn't a 'Term::ReadLine'

#   Failed test ''Attribs' isa 'Term::ReadLine''
#   at t/callback.t line 38.
#     'Attribs' isn't a 'Term::ReadLine'
Use of uninitialized value in pattern match (m//) at t/callback.t line 40.
# skipped since Tk is not available.
# Looks like you failed 2 tests of 8.
t/callback.t ..... 
Dubious, test returned 2 (wstat 512, 0x200)
Failed 2/8 subtests 
Use of uninitialized value $Term::ReadLine::Gnu::VERSION in concatenation (.) or string at t/history.t line 34.

#   Failed test 'An object of class 'Term::ReadLine::Stub' isa 'Term::ReadLine''
#   at t/history.t line 40.
#     The object of class 'Term::ReadLine::Stub' isn't a 'Term::ReadLine'

#   Failed test '$t->ReadLine'
#   at t/history.t line 46.

#   Failed test ''Attribs' isa 'Term::ReadLine''
#   at t/history.t line 53.
#     'Attribs' isn't a 'Term::ReadLine'
Use of uninitialized value in pattern match (m//) at t/history.t line 55.
Can't locate object method "using_history" via package "Term::ReadLine::Stub" at t/history.t line 62.
# Looks like your test exited with 255 just after 4.
t/history.t ...... 
Dubious, test returned 255 (wstat 65280, 0xff00)
Failed 87/88 subtests 
Bareword "ISKMAP" not allowed while "strict subs" in use at t/readline.t line 300.
Bareword "ISFUNC" not allowed while "strict subs" in use at t/readline.t line 303.
Bareword "ISMACR" not allowed while "strict subs" in use at t/readline.t line 307.
Bareword "RL_STATE_INITIALIZED" not allowed while "strict subs" in use at t/readline.t line 150.
Bareword "ISFUNC" not allowed while "strict subs" in use at t/readline.t line 220.
Bareword "ISFUNC" not allowed while "strict subs" in use at t/readline.t line 232.
Bareword "ISKMAP" not allowed while "strict subs" in use at t/readline.t line 316.
Bareword "ISMACR" not allowed while "strict subs" in use at t/readline.t line 320.
Bareword "prompt" not allowed while "strict subs" in use at t/readline.t line 657.
Bareword "prompt" not allowed while "strict subs" in use at t/readline.t line 661.
Bareword "prompt" not allowed while "strict subs" in use at t/readline.t line 663.
Bareword "prompt" not allowed while "strict subs" in use at t/readline.t line 667.
Bareword "prompt" not allowed while "strict subs" in use at t/readline.t line 669.
Bareword "ISFUNC" not allowed while "strict subs" in use at t/readline.t line 998.
Bareword "ISKMAP" not allowed while "strict subs" in use at t/readline.t line 998.
Bareword "ISMACR" not allowed while "strict subs" in use at t/readline.t line 998.
Bareword "prompt" not allowed while "strict subs" in use at t/readline.t line 1007.
Execution of t/readline.t aborted due to compilation errors.
# Looks like your test exited with 255 before it could output anything.
t/readline.t ..... 
Dubious, test returned 255 (wstat 65280, 0xff00)
Failed 148/148 subtests 
Use of uninitialized value $Term::ReadLine::Gnu::VERSION in concatenation (.) or string at t/utf8_binary.t line 41.

#   Failed test 'An object of class 'Term::ReadLine::Stub' isa 'Term::ReadLine''
#   at t/utf8_binary.t line 88.
#     The object of class 'Term::ReadLine::Stub' isn't a 'Term::ReadLine'

#   Failed test 'input layers after 'new''
#   at t/utf8_binary.t line 93.
#     Structures begin differing at:
#          $got->[2] = Does not exist
#     $expected->[2] = 'stdio'

#   Failed test 'output layers after 'new''
#   at t/utf8_binary.t line 96.
#     Structures begin differing at:
#          $got->[2] = Does not exist
#     $expected->[2] = 'stdio'
# Looks like you failed 3 tests of 13.
t/utf8_binary.t .. 
Dubious, test returned 3 (wstat 768, 0x300)
Failed 3/13 subtests 
Use of uninitialized value $Term::ReadLine::Gnu::VERSION in concatenation (.) or string at t/utf8_text.t line 46.

#   Failed test 'An object of class 'Term::ReadLine::Stub' isa 'Term::ReadLine''
#   at t/utf8_text.t line 114.
#     The object of class 'Term::ReadLine::Stub' isn't a 'Term::ReadLine'
# Looks like you failed 1 test of 14.
t/utf8_text.t .... 
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/14 subtests 

Test Summary Report
-------------------
t/00checkver.t (Wstat: 512 Tests: 4 Failed: 2)
  Failed tests:  2-3
  Non-zero exit status: 2
t/callback.t   (Wstat: 512 Tests: 8 Failed: 2)
  Failed tests:  2-3
  Non-zero exit status: 2
t/history.t    (Wstat: 65280 Tests: 4 Failed: 3)
  Failed tests:  2-4
  Non-zero exit status: 255
  Parse errors: Bad plan.  You planned 88 tests but ran 4.
t/readline.t   (Wstat: 65280 Tests: 0 Failed: 0)
  Non-zero exit status: 255
  Parse errors: Bad plan.  You planned 148 tests but ran 0.
t/utf8_binary.t (Wstat: 768 Tests: 13 Failed: 3)
  Failed tests:  6-8
  Non-zero exit status: 3
t/utf8_text.t  (Wstat: 256 Tests: 14 Failed: 1)
  Failed test:  7
  Non-zero exit status: 1
Files=8, Tests=47,  0 wallclock secs ( 0.04 usr  0.01 sys +  0.46 cusr  0.06 csys =  0.57 CPU)
Result: FAIL
Failed 6/8 test programs. 11/47 subtests failed.
make: *** [Makefile:1080: test_dynamic] Error 1
-> FAIL Installing Term::ReadLine::Gnu failed. See /root/.cpanm/work/1662628609.10/build.log for details. Retry with --force to force install it.
+ exit 1
The command '/bin/sh -c set -x     && apk add perl perl-mojolicious perl-app-cpanminus ncurses-dev readline-dev perl-dev build-base     && cpanm Term::ReadLine::Gnu || { r=$?; cat /root/.cpanm/work/*/build.log; exit $r; }' returned a non-zero code: 1

Expected behavior
It installs.

Workarounds
TERM=xterm cpanm Term::ReadLine::Gnu or cpanm --notest Term::ReadLine::Gnu

Please complete the following information:

  • Output of
    • perl -V
    • perl Makefile.PL verbose
    • make test TEST_VERBOSE=1
    • perl -Mblib t/00checkver.t
    • echo $TERM
  • terminal emulator which you are using
  • compiler which is used to compile the GNU Readline Library (libreadline.a) if you can know.

completion_suppress_append it doesn't seem to work

Describe the bug
I wanted to eliminate the space added after pressing the tab key, I set completion_suppress_append to 1 but it doesn't seem to work.

To Reproduce
Steps to reproduce the behavior:

use strict;
use warnings;
require Term::ReadLine;

my $term = Term::ReadLine->new("");
$term->ornaments(0);

sub pizza_completion{
	my ($text, $line, $start, $end) = @_;
	return "pizza" if "pizza" =~ /^$text/;
}

$term->Attribs->{completion_suppress_append} = 1;
#$term->Attribs->{attempted_completion_function} = \&pizza_completion;
$term->Attribs->{completion_function} = \&pizza_completion;

print "read: '" . $term->readline("> ") . "'\n";

output:

read: 'pizza '

Expected behavior
output without space:

read: 'pizza'

Please complete the following information:

  • perl v5.38
  • rxvt-unicode-256color

Additional context
I used prebuild version on arch linux called perl-term-readline-gnu v1.46

creating a second Term::ReadLine::Gnu leads to confusion

Describe the bug

Creating multiple Term::ReadLine instances, when Gnu is used, will call "Term::ReadLine::Gnu->new" more than once. This leads to problems. The same object is re-used, and partly reinitialized, but parts of the attributes from any previous configuration are kept.

This seems unavoidable: there can be only one readline instance anyway.

I have a program that moves between various activities, and each one got its own ReadLine. This led to problems with registering too many custom functions, because the same instance kept being used. (Gnu.xs:rl_add_defun: custom function table is full.)

Term::ReadLine::Perl refuses to construct a second instance, presumably for similar reasons. If new is called twice, I believe Gnu should at least warn. If it doesn't refuse (and create a Stub instead), I also think you should add a Term::ReadLine::Gnu->has_been_initialized method, which could check whether %Attribs was blessed.

I have worked around this problem by changing my application framework.

I see now that my production environment is out of date! I'm using v1.37. I will attempt to reproduce this on the latest Term::ReadLine::Gnu, but it may be difficult. I apologize if this report is redundant.

"panic: free from wrong pool, ... during global destruction." on threaded Perl [rt.cpan.org #129984]

Migrated from rt.cpan.org#129984 (status was 'open')

Requestors:

Attachments:

From [email protected] on 2019-07-05 07:15:27
:

Repro:

1. perl-5.30.0 brewed with -DDEBUGGING -Dusemorebits -Duseshrplib -Dusethreads -Accflags='-fPIC -DUSE_THREAD_SAFE_LOCALE'
2. run perl -mTerm::ReadLine -e'$0 = "trlg-debug"; $term = Term::ReadLine->new($0); while (defined ($_ = $term->readline("prompt>"))) {}'
3. while the prompt waits for input, resize terminal emulator window or run pkill -WINCH trlg-debug
4. ctrl+d to exit

Expect:

clean exit

Got:

panic: free from wrong pool, 70d000!=590260 during global destruction.

Terminal emulator is KDE Konsole 19.04. Other system information is attached.

From [email protected] on 2020-04-24 14:29:25
:

Hi,

I am sorry I overlooked your report.

I cannot reproduce your fail on my environment.

Do you still have the error?
Can you try any other programs which uses the same GNU Readline Library, ex bash?
My module does not care about the WINCH signal.  The GNU Readline cares it.

And your report says TERM is set to dumb.
Do you use the same value on KDE Konsole?

Any other clues are welcome.

Thank you.

On Fri, 5 Jul 2019 07:15:27 GMT, DAXIM wrote:
> Repro:
> 
> 1. perl-5.30.0 brewed with -DDEBUGGING -Dusemorebits -Duseshrplib
> -Dusethreads -Accflags='-fPIC -DUSE_THREAD_SAFE_LOCALE'
> 2. run perl -mTerm::ReadLine -e'$0 = "trlg-debug"; $term =
> Term::ReadLine->new($0); while (defined ($_ = $term-
> >readline("prompt>"))) {}'
> 3. while the prompt waits for input, resize terminal emulator window
> or run pkill -WINCH trlg-debug
> 4. ctrl+d to exit
> 
> Expect:
> 
> clean exit
> 
> Got:
> 
> panic: free from wrong pool, 70d000!=590260 during global destruction.
> 
> Terminal emulator is KDE Konsole 19.04. Other system information is
> attached.




From [email protected] on 2020-04-24 19:51:20
:

> Do you still have the error?

Yes. It also shows with perl-5.31.9.

> Can you try any other programs

I have tested a few programs depending on libreadline8: bash, bc, fdisk, gpg2, lftp, parted, python3, sqlite3, units, xfs_db, zypper. When they show a prompt:

1. I verify that I am on a readline prompt by using the Home key (does nothing on a readline prompt, but would print ^[[H on a non-readline prompt);
2. I send a WINCH signal to the program;
3. I press ctrl+d to exit the prompt.

They all behave normally. What I mean is: they exit the same way whether I send the signal or not.

It's only Perl programs with T::RL::G that panic, and only after receiving the signal.

> your report says TERM is set to dumb

That's in line 211 of the report file. This is because the test file t/02test_use.t sets TERM=dumb on purpose. My normal value is shown above in line 199: TERM=xterm-256color

From [email protected] on 2020-04-24 23:24:00
:

> Any other clues are welcome.

ilmari commented in IRC:

| it might be a -DDEBUGGING-only panic
| indeed, it's in an # ifdef PERL_TRACK_MEMPOOL, which is only defined under PERL_IMPLICIT_CONTEXT && DEBUGGING
| PERL_IMPLICIT_CONTEXT is only defined by default under MULTIPLICITY, so you need threads _and_ debugging to trigger that
| and I can reproduce it on 5.30.0-thr-dbg on debian stable
| that error is from perl's safesysfree(), not readline or libc
| so it's a value beeing freed by a different interpreter than the one that allocated it


From [email protected] on 2020-04-25 00:27:52
:

Hi,

Thank you for your info.  They help me a lot.

On Fri, 24 Apr 2020 23:24:00 GMT, DAXIM wrote:
> > Any other clues are welcome.
> 
> ilmari commented in IRC:
> 
> | it might be a -DDEBUGGING-only panic
> | indeed, it's in an # ifdef PERL_TRACK_MEMPOOL, which is only defined
> under PERL_IMPLICIT_CONTEXT && DEBUGGING
> | PERL_IMPLICIT_CONTEXT is only defined by default under MULTIPLICITY,
> so you need threads _and_ debugging to trigger that
> | and I can reproduce it on 5.30.0-thr-dbg on debian stable
> | that error is from perl's safesysfree(), not readline or libc
> | so it's a value beeing freed by a different interpreter than the one
> that allocated it

This makes sense to me.
T::RL::G has to handle strings which are allocated by Perl and GNU Readline Library.
They can be mixed.
I carefully choose Perl-free nor xfree (free used by GNU Readline Library).
And there are codes which frees strings when it received signal in the GNU Readline Library.
Strings allocated by perl may freed and may cause error by perl memory checker.

Does 5.30.0-thr-dbg mean perl-debug package?
https://packages.debian.org/search?lang=en&keywords=perl-debug

I am not sure I can fix, but I will try.


The shadow_redisplay function segfaults on GNU Readline v8.0

Describe the bug
Using the shadow_redisplay function on a server with libreadline v8 install will segfault after typing in the password prompt.

Also, I can't seem to locate the XS/Perl code that actually defines the shadow_redisplay function. Is it actually buried in the comments in Term::ReadLine::Gnu::XS?

To Reproduce

# /usr/bin/perl -MTerm::ReadLine -E 'my $term = Term::ReadLine->new("test"); my $attrs = $term->Attribs; $attrs->{redisplay_function} = $attrs->{shadow_redisplay}; warn "got=" . $term->readline(shift);' "test: "
test: ***Segmentation fault

Expected behavior
Not segfaulting

Please complete the following information:
TERM=xterm-256color

/usr/bin/perl -V
Summary of my perl5 (revision 5 version 30 subversion 0) configuration:

  Platform:
    osname=linux
    osvers=4.19.0
    archname=x86_64-linux-gnu-thread-multi
    uname='linux localhost 4.19.0 #1 smp debian 4.19.0 x86_64 gnulinux '
    config_args='-Dmksymlinks -Dusethreads -Duselargefiles -Dcc=x86_64-linux-gnu-gcc -Dcpp=x86_64-linux-gnu-cpp -Dld=x86_64-linux-gnu-gcc -Dccflags=-DDEBIAN -Wdate-time -D_FORTIFY_SOURCE=2 -g -O2 -fdebug-prefix-map=/build/perl-Ox33E8/perl-5.30.0=. -fstack-protector-strong -Wformat -Werror=format-security -Dldflags= -Wl,-Bsymbolic-functions -Wl,-z,relro -Dlddlflags=-shared -Wl,-Bsymbolic-functions -Wl,-z,relro -Dcccdlflags=-fPIC -Darchname=x86_64-linux-gnu -Dprefix=/usr -Dprivlib=/usr/share/perl/5.30 -Darchlib=/usr/lib/x86_64-linux-gnu/perl/5.30 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/x86_64-linux-gnu/perl5/5.30 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.30.0 -Dsitearch=/usr/local/lib/x86_64-linux-gnu/perl/5.30.0 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Dsiteman3dir=/usr/local/man/man3 -Duse64bitint -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Ud_ualarm -Uusesfio -Uusenm -Ui_libutil -Ui_xlocale -Uversiononly -DDEBUGGING=-g -Doptimize=-O2 -dEs -Duseshrplib -Dlibperl=libperl.so.5.30.0'
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=define
    usemultiplicity=define
    use64bitint=define
    use64bitall=define
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
    bincompat5005=undef
  Compiler:
    cc='x86_64-linux-gnu-gcc'
    ccflags ='-D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fwrapv -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
    optimize='-O2 -g'
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fwrapv -fno-strict-aliasing -pipe -I/usr/local/include'
    ccversion=''
    gccversion='9.4.0'
    gccosandvers=''
    intsize=4
    longsize=8
    ptrsize=8
    doublesize=8
    byteorder=12345678
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=16
    longdblkind=3
    ivtype='long'
    ivsize=8
    nvtype='double'
    nvsize=8
    Off_t='off_t'
    lseeksize=8
    alignbytes=8
    prototype=define
  Linker and Libraries:
    ld='x86_64-linux-gnu-gcc'
    ldflags =' -fstack-protector-strong -L/usr/local/lib'
    libpth=/usr/local/lib /usr/include/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib
    libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt
    perllibs=-ldl -lm -lpthread -lc -lcrypt
    libc=libc-2.31.so
    so=so
    useshrplib=true
    libperl=libperl.so.5.30
    gnulibc_version='2.31'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=so
    d_dlsymun=undef
    ccdlflags='-Wl,-E'
    cccdlflags='-fPIC'
    lddlflags='-shared -L/usr/local/lib -fstack-protector-strong'


Characteristics of this binary (from libperl):
  Compile-time options:
    HAS_TIMES
    MULTIPLICITY
    PERLIO_LAYERS
    PERL_COPY_ON_WRITE
    PERL_DONT_CREATE_GVSV
    PERL_IMPLICIT_CONTEXT
    PERL_MALLOC_WRAP
    PERL_OP_PARENT
    PERL_PRESERVE_IVUV
    USE_64_BIT_ALL
    USE_64_BIT_INT
    USE_ITHREADS
    USE_LARGE_FILES
    USE_LOCALE
    USE_LOCALE_COLLATE
    USE_LOCALE_CTYPE
    USE_LOCALE_NUMERIC
    USE_LOCALE_TIME
    USE_PERLIO
    USE_PERL_ATOF
    USE_REENTRANT_API
    USE_THREAD_SAFE_LOCALE
  Locally applied patches:
    DEBPKG:debian/cpan_definstalldirs - Provide a sensible INSTALLDIRS default for modules installed from CPAN.
    DEBPKG:debian/db_file_ver - https://bugs.debian.org/340047 Remove overly restrictive DB_File version check.
    DEBPKG:debian/doc_info - Replace generic man(1) instructions with Debian-specific information.
    DEBPKG:debian/enc2xs_inc - https://bugs.debian.org/290336 Tweak enc2xs to follow symlinks and ignore missing @INC directories.
    DEBPKG:debian/errno_ver - https://bugs.debian.org/343351 Remove Errno version check due to upgrade problems with long-running processes.
    DEBPKG:debian/libperl_embed_doc - https://bugs.debian.org/186778 Note that libperl-dev package is required for embedded linking
    DEBPKG:fixes/respect_umask - Respect umask during installation
    DEBPKG:debian/writable_site_dirs - Set umask approproately for site install directories
    DEBPKG:debian/extutils_set_libperl_path - EU:MM: set location of libperl.a under /usr/lib
    DEBPKG:debian/no_packlist_perllocal - Don't install .packlist or perllocal.pod for perl or vendor
    DEBPKG:debian/fakeroot - Postpone LD_LIBRARY_PATH evaluation to the binary targets.
    DEBPKG:debian/instmodsh_doc - Debian policy doesn't install .packlist files for core or vendor.
    DEBPKG:debian/ld_run_path - Remove standard libs from LD_RUN_PATH as per Debian policy.
    DEBPKG:debian/libnet_config_path - Set location of libnet.cfg to /etc/perl/Net as /usr may not be writable.
    DEBPKG:debian/perlivp - https://bugs.debian.org/510895 Make perlivp skip include directories in /usr/local
    DEBPKG:debian/squelch-locale-warnings - https://bugs.debian.org/508764 Squelch locale warnings in Debian package maintainer scripts
    DEBPKG:debian/patchlevel - https://bugs.debian.org/567489 List packaged patches for 5.30.0-9ubuntu0.3 in patchlevel.h
    DEBPKG:fixes/document_makemaker_ccflags - https://bugs.debian.org/628522 [rt.cpan.org #68613] Document that CCFLAGS should include $Config{ccflags}
    DEBPKG:debian/find_html2text - https://bugs.debian.org/640479 Configure CPAN::Distribution with correct name of html2text
    DEBPKG:debian/perl5db-x-terminal-emulator.patch - https://bugs.debian.org/668490 Invoke x-terminal-emulator rather than xterm in perl5db.pl
    DEBPKG:debian/cpan-missing-site-dirs - https://bugs.debian.org/688842 Fix CPAN::FirstTime defaults with nonexisting site dirs if a parent is writable
    DEBPKG:fixes/memoize_storable_nstore - [rt.cpan.org #77790] https://bugs.debian.org/587650 Memoize::Storable: respect 'nstore' option not respected
    DEBPKG:debian/makemaker-pasthru - https://bugs.debian.org/758471 Pass LD settings through to subdirectories
    DEBPKG:debian/makemaker-manext - https://bugs.debian.org/247370 Make EU::MakeMaker honour MANnEXT settings in generated manpage headers
    DEBPKG:debian/kfreebsd-softupdates - https://bugs.debian.org/796798 Work around Debian Bug#796798
    DEBPKG:fixes/autodie-scope - https://bugs.debian.org/798096 Fix a scoping issue with "no autodie" and the "system" sub
    DEBPKG:fixes/memoize-pod - [rt.cpan.org #89441] Fix POD errors in Memoize
    DEBPKG:debian/hurd-softupdates - https://bugs.debian.org/822735 Fix t/op/stat.t failures on hurd
    DEBPKG:fixes/math_complex_doc_great_circle - https://bugs.debian.org/697567 [rt.cpan.org #114104] Math::Trig: clarify definition of great_circle_midpoint
    DEBPKG:fixes/math_complex_doc_see_also - https://bugs.debian.org/697568 [rt.cpan.org #114105] Math::Trig: add missing SEE ALSO
    DEBPKG:fixes/math_complex_doc_angle_units - https://bugs.debian.org/731505 [rt.cpan.org #114106] Math::Trig: document angle units
    DEBPKG:fixes/cpan_web_link - https://bugs.debian.org/367291 CPAN: Add link to main CPAN web site
    DEBPKG:debian/hppa_op_optimize_workaround - https://bugs.debian.org/838613 Temporarily lower the optimization of op.c on hppa due to gcc-6 problems
    DEBPKG:debian/installman-utf8 - https://bugs.debian.org/840211 Generate man pages with UTF-8 characters
    DEBPKG:fixes/getopt-long-4 - https://bugs.debian.org/864544 [rt.cpan.org #122068] Fix issue #122068.
    DEBPKG:debian/hppa_opmini_optimize_workaround - https://bugs.debian.org/869122 Lower the optimization level of opmini.c on hppa
    DEBPKG:debian/sh4_op_optimize_workaround - https://bugs.debian.org/869373 Also lower the optimization level of op.c and opmini.c on sh4
    DEBPKG:debian/perldoc-pager - https://bugs.debian.org/870340 [rt.cpan.org #120229] Fix perldoc terminal escapes when sensible-pager is less
    DEBPKG:debian/prune_libs - https://bugs.debian.org/128355 Prune the list of libraries wanted to what we actually need.
    DEBPKG:debian/mod_paths - Tweak @INC ordering for Debian
    DEBPKG:debian/configure-regen - https://bugs.debian.org/762638 Regenerate Configure et al. after probe unit changes
    DEBPKG:debian/deprecate-with-apt - https://bugs.debian.org/747628 Point users to Debian packages of deprecated core modules
    DEBPKG:debian/disable-stack-check - https://bugs.debian.org/902779 [perl #133327] Disable debugperl stack extension checks for binary compatibility with perl
    DEBPKG:fixes/eumm-usrmerge - https://bugs.debian.org/913637 Avoid mangling /bin non-perl shebangs on merged-/usr systems
    DEBPKG:debian/perlbug-editor - https://bugs.debian.org/922609 Use "editor" as the default perlbug editor, as per Debian policy
    DEBPKG:fixes/gid-parsing - [79e302e] https://bugs.debian.org/941985 [perl #134169] (perl #134169) mg.c reset endptr after use
    DEBPKG:fixes/CVE-2020-10543.patch - [PATCH v530 1/4] regcomp.c: Prevent integer overflow from nested regex quantifiers.
    DEBPKG:fixes/CVE-2020-10878-1.patch - [PATCH v530 2/4] study_chunk: extract rck_elide_nothing
    DEBPKG:fixes/CVE-2020-10878-2.patch - [PATCH v530 3/4] regcomp: use long jumps if there is any possibility of overflow
    DEBPKG:fixes/CVE-2020-12723.patch - [PATCH v530 4/4] study_chunk: avoid mutating regexp program within GOSUB
    DEBPKG:CVE-2020-16156-1.patch - [PATCH] bugfix: signature verification type CANNOT_VERIFY was not recognized
    DEBPKG:CVE-2020-16156-2.patch - [PATCH] Add two new failure modes based on cpan_path
    DEBPKG:CVE-2020-16156-3.patch - [PATCH] use gpg --verify --output ... to disentangle data and signature
    DEBPKG:CVE-2020-16156-4.patch - [PATCH] replacing die with mydie in three spots
    DEBPKG:CVE-2020-16156-5.patch - [PATCH] disambiguate the call to gpg --output by adding --verify
    DEBPKG:CVE-2020-16156-6.patch - [PATCH] s/gpg/$gpg/ in system, add quotes where needed
    DEBPKG:CVE-2020-16156-7.patch - [PATCH] s,/dev/null,$devnull,
  Built under linux
  Compiled at Oct  5 2022 10:27:25
  %ENV:
    PERL_LOCAL_LIB_ROOT=""
    PERL_LWP_SSL_CA_FILE="/etc/ssl/certs/ca-certificates.crt"
    PERL_MB_OPT=""
    PERL_MM_OPT=""
  @INC:
    /etc/perl
    /usr/local/lib/x86_64-linux-gnu/perl/5.30.0
    /usr/local/share/perl/5.30.0
    /usr/lib/x86_64-linux-gnu/perl5/5.30
    /usr/share/perl5
    /usr/lib/x86_64-linux-gnu/perl/5.30
    /usr/share/perl/5.30
    /usr/local/lib/site_perl
    /usr/lib/x86_64-linux-gnu/perl-base

Additional context
gdb backtrace:

Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00007f5eca3faa20 in _rl_update_final () from /lib/x86_64-linux-gnu/libreadline.so.8
(gdb) bt
#0  0x00007f5eca3faa20 in _rl_update_final () from /lib/x86_64-linux-gnu/libreadline.so.8
#1  0x00007f5eca401695 in rl_newline () from /lib/x86_64-linux-gnu/libreadline.so.8
#2  0x00007f5eca3e3707 in _rl_dispatch_subseq () from /lib/x86_64-linux-gnu/libreadline.so.8
#3  0x00007f5eca3e3cc5 in readline_internal_char () from /lib/x86_64-linux-gnu/libreadline.so.8
#4  0x00007f5eca3e44ed in readline () from /lib/x86_64-linux-gnu/libreadline.so.8
#5  0x00007f5eca438f47 in ?? () from /usr/lib/x86_64-linux-gnu/perl5/5.30/auto/Term/ReadLine/Gnu/Gnu.so
#6  0x000055ab7889ba10 in Perl_pp_entersub ()
#7  0x000055ab78892166 in Perl_runops_standard ()
#8  0x000055ab7880591c in perl_run ()
#9  0x000055ab787db432 in main ()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.