For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > December 2005 > Solution [ Perl/Tk: 'selection conversion left too many bytes unconverted' error on l









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Solution [ Perl/Tk: 'selection conversion left too many bytes unconverted' error on l
coyote.frank@gmx.net

2005-12-14, 7:02 pm

After I got bitten enough by this error and found no solution on the
web I had to debug it myself. For me it looks like the following:

- text get selected from Tk::Text

- TkSelPropProc in ./pTk/mTk/unix/tkUnixSelect.c gets called to handle
the selection which determines that the display supports utf-8 and
thus gets Encoding::utf8 as the responsable encoder (see
Encode::Encoding for the interface)

- then it calls Tcl_UtfToExternal to convert the selection from
internal format to utf8, this function is defined in encGlue.c and
just calls CallEncode in the same file.

- callEncode calls the perl Method 'encode' on the encoding object,
e.g. Encode::utf8->encode( $string, $check ). According to the
interface this method should in-place modify $string, delete the
converted chars from $string and return the converted string. So
callEncode checks if $string is empty at the end, e.g. that
everything got converted fine. If not it will set the error code to

TCL_CONVERT_UNKNOWN which will be the cause of the PANIC.
According to the example program below encode fails to convert
everything and thus the panic gets triggered. But if you set the
variable $check at the call to encode everything will be fine.
Setting the variable is easy and this is the simple solution which
works for me:

$Tk::encodeFallback=1

Example code to trigger the problem in Encode::utf8

use Encode;
my $text = (( '1234456789 ' x 10 )."\n" ) x 1000;
for my $check ( 0,1 ) {
my $t = $text;
my $v = Encode::utf8->encode( $t,$check );
printf "encode with check=$check %s\n",
length($t) ? 'failed':'succeeded';
}

which gives

encode with check=0 failed
encode with check=1 succeeded

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com