Skip Menu |

This queue is for tickets about the Curses CPAN distribution.

Report information
The Basics
Id: 57608
Status: resolved
Priority: 0/
Queue: Curses

People
Owner: Nobody in particular
Requestors: gentoo [...] greatships.com
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 1.28
Fixed in: (no value)



Subject: field_buffer does not return all data from multi-row fields
Curses-1.28 Perl 5.8.8 Gentoo Linux ncurses ncurses-5.7-r3 The field buffer function does not return all data from multi-row fields. The field is displayed properly, can be edited, and the value can be set using set_field_buffer($field, 0, $value). However, when data is retrieved, only the first row of the field is returned. Please see attached simple test case for a 2 row, 13 column field set to the letters of the alphabet. The retrieved value is truncated at letter "m". Output of test case: Set value: abcdefghijklmnopqrstuvwxyz Retrieved value: abcdefghijklm
Subject: test.pl
#!/usr/bin/perl use strict; use Curses; initscr; my $data = "abcdefghijklmnopqrstuvwxyz"; my $field = new_field(2, 13, 0, 0, 0, 1); set_field_buffer($field, 0, $data); my $result = field_buffer($field, 0); endwin; print "Set value: $data\n"; print "Retrieved value: $result\n";
Works for me. This is probably due to the same behavior from the C curses library on the subject system. Curses.pm just takes the result of field_buffer() in that library and turns it into a Perl string, so if the C library returns only the first line, Curses.pm will as well.
On Thu May 20 16:45:14 2010, GIRAFFED wrote: Show quoted text
> Works for me. > > This is probably due to the same behavior from the C curses library on > the subject system. Curses.pm just takes the result of field_buffer() > in that library and turns it into a Perl string, so if the C library > returns only the first line, Curses.pm will as well.
Yes, this was my first thought. So before opening this bug report, I created the equivalent C-language test case, which worked fine (as have all my other C-language curses programs). I compiled my test as follows: # gcc -o test test.c -lform -lcurses and the output is (correct): # ./test Set value: abcdefghijklmnopqrstuvwxyz Retrieved value: abcdefghijklmnopqrstuvwxyz However, if I look at the Curses.so (built from the Perl Curses package) on my system: # ldd /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux/auto/Curses/Curses.so linux-vdso.so.1 => (0x00007fff33fff000) libpanelw.so.5 => /usr/lib/libpanelw.so.5 (0x00007f2ac7d02000) libmenuw.so.5 => /usr/lib/libmenuw.so.5 (0x00007f2ac7afa000) libformw.so.5 => /usr/lib/libformw.so.5 (0x00007f2ac78e9000) libncursesw.so.5 => /lib/libncursesw.so.5 (0x00007f2ac768c000) libc.so.6 => /lib/libc.so.6 (0x00007f2ac7333000) libdl.so.2 => /lib/libdl.so.2 (0x00007f2ac712e000) /lib64/ld-linux-x86-64.so.2 (0x00007f2ac8165000) and compare that to my C test case: # ldd test linux-vdso.so.1 => (0x00007fffa98e0000) libform.so.5 => /usr/lib/libform.so.5 (0x00007f065b28b000) libncurses.so.5 => /lib/libncurses.so.5 (0x00007f065b03a000) libc.so.6 => /lib/libc.so.6 (0x00007f065ace1000) libdl.so.2 => /lib/libdl.so.2 (0x00007f065aadd000) /lib64/ld-linux-x86-64.so.2 (0x00007f065b49a000) it seems that Curses and my test case are using different libraries. (Note the "w" suffix after each library name, which I presume is the difference between a 32 and 64 bit version of the ncurses libraries - my system is AMD64). If I force my C test case to use these libraries: # gcc -o test test.c -lformw -lncursesw # ./test Set value: abcdefghijklmnopqrstuvwxyz Retrieved value: abcdefghijklm Now I see the same (incorrect) behavior that happens in Perl, and you are, of course, correct that it's a problem with the libraries on my system. I'm not sure what the "w" versions of the libraries are - again I'm presuming 64-bit versions of the libraries. However, both the regular and "w" versions of the libraries are built from the same ncurses-5.7 package, which is a recent release, and reinstalling does not help. I'll try to track down the package maintainers for ncurses and report the bug there. I'm documenting here in case someone else has a similar problem.
Subject: test.c
#include <form.h> /* Compiled with gcc -o test test.c -lcurses -lform */ main() { initscr(); static char *data = "abcdefghijklmnopqrstuvwxyz"; FIELD *field = new_field(2, 13, 0, 0, 0, 1); set_field_buffer(field, 0, data); char *result = field_buffer(field, 0); endwin(); printf("Set value: %s\n", data); printf("Retrieved value: %s\n", result); }
It seems my additional information has automatically reopened the bug. My apologies - the bug should be marked closed/resolved. Sorry for your trouble.
Subject: Re: [rt.cpan.org #57608] field_buffer does not return all data from multi-row fields
Date: 21 May 2010 02:47:20 +0000
To: bug-Curses [...] rt.cpan.org
From: bryanh [...] giraffe-data.com (Bryan Henderson)
The W libraries are ones that understand wide characters (I.e. character sets with more than 128 characters, which use more than one byte to represent a character. The W libraries are fairly recent, and Curses.pm interoperability with them even newer. AFAIR, the only changes that have been made to Perl Curses to work with the W libraries were in the building. How sure are you that the splitting happens at a line boundary? What if there are 3 lines? I'm wondering if it's a length problem, e.g. there are 26 one-byte characters and something thinks there are 2 bytes per character and thus concludes the string length is 13. Note that it's not hard to build Curses.so with the more primitive (and more tested) non-W versions. It's just not what the automatic configurator prefers. -- Bryan Henderson San Jose, California
On Thu May 20 22:58:54 2010, bryanh@giraffe-data.com wrote: Show quoted text
> The W libraries are ones that understand wide characters (I.e. character > sets with more than 128 characters, which use more than one byte to > represent a character. > > The W libraries are fairly recent, and Curses.pm interoperability with
them Show quoted text
> even newer. AFAIR, the only changes that have been made to Perl Curses to > work with the W libraries were in the building. > > How sure are you that the splitting happens at a line boundary? What if > there are 3 lines? I'm wondering if it's a length problem, e.g. there > are 26 one-byte characters and something thinks there are 2 bytes per > character and thus concludes the string length is 13. > > Note that it's not hard to build Curses.so with the more primitive
(and more Show quoted text
> tested) non-W versions. It's just not what the automatic configurator > prefers. >
Greetings Bryan - thank you also for taking the time to reply. I know this is not a Perl Curses issue, and I'm sure you have many other demands on your time! It is very kind of you to reply here to help me and anybody else who may encounter this issue. Yes, after making my last post, I went off in search of bugs in the ncurses libraries and did notice in the notes on the distribution that the W libraries are for the the multi-byte characters. It now makes perfect sense why the problem is seen there and not in the original libraries. Although there have been other bugs relating to field_buffer, it seems most of these had to do with "wide" characters, and I could find none that seemed to have issues with a row boundary. So I've emailed a report to the ncurses maintainer, and perhaps he may be able to quickly find the problem. Once I realized that the libraries were for "wide" characters and had nothing to do with 32 vs 64-bit, I investigated build options on Gentoo for the Curses Perl module. Fortunately, the Gentoo package maintainer has conveniently included a "unicode" build option. So I rebuilt the package without unicode support for this specific module. On Gentoo this is easily done as follows: USE=-unicode emerge ncurses The above sets environment variable "USE" to no unicode ("-unicode") and then rebuild the package ("emerge ncurses"). This rebuilds the package without unicode support - in other words, linking to the "narrow" libraries, and thus giving me a workaround. While this is an effective workaround in my specific case this, of course, will not work for somebody who really needs "wide" character support. In that case, it seems there is no other option but to wait for a bug fix for the ncurses library. As far as my certainty that this always occurs at a row boundary, I did fairly extensive "testing" trying to coax a multi-row value out of a multi-row field. My application is a database app, and I ran into the problem when trying to support 255 character database fields by using 4x64 byte (multi-row) fields. My database was already populated with data of various sizes, but I also tried various combinations of options such as changing the number of rows, the number of off-screen rows, the column width, and then examining the number and type of return values, and even examining the additional (user defined) buffers in the field. The only thing that seems to hold constant is the size of the return value is always the number of columns (width - it should be width*(rows + offscreen rows)). As far as my test case, I chose the letters of the alphabet and two 13 character rows just because it conveniently breaks at the halfway point, and I don't introduce any questions about parsing trailing spaces as the cause of the problem. However, your question points out that a better test case might be a 3 or 4 row example, so that it is clear that only the first row of a multi-row field is returned, and that it doesn't appear to be a halving or doubling issue associated with multi-byte characters.