Skip Menu |

This queue is for tickets about the Tickit CPAN distribution.

Report information
The Basics
Id: 120630
Status: resolved
Priority: 0/
Queue: Tickit

People
Owner: Nobody in particular
Requestors: leonerd-cpan [...] leonerd.org.uk
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.62
Fixed in: 0.63



Subject: $rb->text( $SvIV ) sometimes fails
It seems that unreliably, the following code silently fails to output any text into the RenderBuffer $rb->text( $printed = $active->index + 1, $active->pen ); The following alteration seems to reliably print $rb->text( $printed = sprintf( "%d", $active->index + 1 ), $active->pen ); I suspect this may be because the XS code isn't properly handling purely numeric text arguments being passed in -- Paul Evans
On Wed Mar 15 13:28:06 2017, PEVANS wrote: Show quoted text
> I suspect this may be because the XS code isn't properly handling > purely numeric text arguments being passed in
Hm. There might be something more subtle going on, because the following unit test never seems to fail for me. -- Paul Evans
Subject: rt120630-test.patch
=== modified file 't/10renderbuffer-span.t' --- t/10renderbuffer-span.t 2015-03-26 18:15:14 +0000 +++ t/10renderbuffer-span.t 2017-03-15 17:37:06 +0000 @@ -96,6 +96,20 @@ 'RenderBuffer correctly gets MAGIC' ); } +# Conversion of numerical arguments - RT120630 +{ + my $cols = $rb->text_at( 0, 4, 12 + 34 ); + is( $cols, 2, "return from ->text_at on SvIV" ); + + $rb->goto( 1, 4 ); + $rb->text( 56 + 78 ); + + $rb->flush_to_term( $term ); + is_termlog( [ GOTO(0,4), SETPEN(), PRINT("46"), + GOTO(1,4), SETPEN(), PRINT("134") ], + 'RenderBuffer correctly converts SvIV' ); +} + # Span splitting { my $pen = Tickit::Pen->new;
Got it -- Paul Evans
Subject: rt120630.patch
=== modified file 'lib/Tickit.xs' --- lib/Tickit.xs 2017-02-15 14:55:28 +0000 +++ lib/Tickit.xs 2017-03-15 18:04:27 +0000 @@ -1547,15 +1547,15 @@ SV *text Tickit::Pen pen INIT: + char *bytes; STRLEN len; CODE: - SvGETMAGIC(text); - len = SvCUR(text); + bytes = SvPVutf8(text, len); if(pen) { tickit_renderbuffer_savepen(self); tickit_renderbuffer_setpen(self, pen); } - RETVAL = tickit_renderbuffer_textn_at(self, line, col, SvPVutf8_nolen(text), len); + RETVAL = tickit_renderbuffer_textn_at(self, line, col, bytes, len); if(pen) tickit_renderbuffer_restore(self); OUTPUT: @@ -1567,18 +1567,18 @@ SV *text Tickit::Pen pen INIT: + char *bytes; STRLEN len; CODE: if(!tickit_renderbuffer_has_cursorpos(self)) croak("Cannot ->text without a virtual cursor position"); - SvGETMAGIC(text); - len = SvCUR(text); + bytes = SvPVutf8(text, len); if(pen) { tickit_renderbuffer_savepen(self); tickit_renderbuffer_setpen(self, pen); } - RETVAL = tickit_renderbuffer_textn(self, SvPVutf8_nolen(text), len); + RETVAL = tickit_renderbuffer_textn(self, bytes, len); if(pen) tickit_renderbuffer_restore(self); OUTPUT: === modified file 't/10renderbuffer-span.t' --- t/10renderbuffer-span.t 2015-03-26 18:15:14 +0000 +++ t/10renderbuffer-span.t 2017-03-15 18:04:03 +0000 @@ -96,6 +96,30 @@ 'RenderBuffer correctly gets MAGIC' ); } +# Conversion of numerical arguments - RT120630 +{ + tie my $sv, "FetchCounter"; + my $count = 0; + { + package FetchCounter; + sub TIESCALAR { return bless [], shift } + sub FETCH { $count++; return "AB"; } + } + + my $cols = $rb->text_at( 0, 4, $sv ); + is( $cols, 2, "return from ->text_at on SvIV" ); + + $rb->goto( 1, 4 ); + $rb->text( $sv ); + + $rb->flush_to_term( $term ); + is_termlog( [ GOTO(0,4), SETPEN(), PRINT("AB"), + GOTO(1,4), SETPEN(), PRINT("AB") ], + 'RenderBuffer correctly converts SvIV' ); + + is( $count, 2, 'FETCH called only twice' ); +} + # Span splitting { my $pen = Tickit::Pen->new;