Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2013-08

UTF8 string handling problem under linux

7 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Xiangrong Fang

Hi All,

I have the following program:

===============================================================
procedure TForm1.Button1Click(Sender: TObject);
begin
  if sd.Execute then begin
    if r.OpenKey('test_utf8', True) then begin
//      r.WriteString('path', UTF8ToSys(sd.FileName));
      r.WriteString('path', sd.FileName);
      r.CloseKey;
    end;
  end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
  if r.OpenKey('test_utf8', False) then begin
//    ShowMessage('path=' + SysToUTF8(r.ReadString('path')));
    ShowMessage('path=' + r.ReadString('path'));
    r.CloseKey;
  end;
end;
============================================================

It runs OK under windows whether I use SysToUTF8 or not, but on Linux, it crashes (SIGSEGV) on the line with r.ReadString.

I wonder what is the correct way to write a program that compile and run well under both Windows and Linux?

Thanks,
Shannon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130811/c7a5b99e/attachment.html>

Reply by email

Xiangrong Fang
to Xiangrong Fang

btw, the problem occur if the input string is CJK.

2013/8/11 Xiangrong Fang

Show quoted text 35 lines
Hi All, I have the following program: =============================================================== procedure TForm1.Button1Click(Sender: TObject); begin if sd.Execute then begin if r.OpenKey('test_utf8', True) then begin // r.WriteString('path', UTF8ToSys(sd.FileName)); r.WriteString('path', sd.FileName); r.CloseKey; end; end; end; procedure TForm1.Button2Click(Sender: TObject); begin if r.OpenKey('test_utf8', False) then begin // ShowMessage('path=' + SysToUTF8(r.ReadString('path'))); ShowMessage('path=' + r.ReadString('path')); r.CloseKey; end; end; ============================================================ It runs OK under windows whether I use SysToUTF8 or not, but on Linux, it crashes (SIGSEGV) on the line with r.ReadString. I wonder what is the correct way to write a program that compile and run well under both Windows and Linux? Thanks, Shannon

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130811/aee0eb60/attachment.html>

Reply by email

Mattias Gaertner
to Xiangrong Fang: I have the following program: ============================================================…
Show quoted text 28 lines
Hi All, I have the following program: =============================================================== procedure TForm1.Button1Click(Sender: TObject); begin if sd.Execute then begin if r.OpenKey('test_utf8', True) then begin // r.WriteString('path', UTF8ToSys(sd.FileName)); r.WriteString('path', sd.FileName); r.CloseKey; end; end; end; procedure TForm1.Button2Click(Sender: TObject); begin if r.OpenKey('test_utf8', False) then begin // ShowMessage('path=' + SysToUTF8(r.ReadString('path'))); ShowMessage('path=' + r.ReadString('path')); r.CloseKey; end; end; ============================================================ It runs OK under windows whether I use SysToUTF8 or not, but on Linux, it crashes (SIGSEGV) on the line with r.ReadString.

Please provide a backtrace.
What is r?
What compiler version?

I wonder what is the correct way to write a program that compile and run well under both Windows and Linux?

Usually Linux already has UTF8, so SysToUTF8 does no conversion.

Mattias

Reply by email

Xiangrong Fang
to Mattias Gaertner

There is no backtrace at all, the only info I get when starting from command line is:

xrfang at fxrmm:~/Desktop/testutf8$ ./project1
TApplication.HandleException Access violation
Stack trace:
$00007F2ACBF9DBD0

Please provide a backtrace.

What is r?

r is a TRegistry object, please see attached source code.

What compiler version?

FPC 2.6.2, Lazarus 1.0.10

I suspect this is a bug in related library code, because even if the result is not correct, it should not crash. Note that this error ONLY occur when I choose a directory with CJK character in its path. -------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130812/038c4235/attachment-0001.html> -------------- next part --------------
A non-text attachment was scrubbed...
Name: testutf8.tar.bz2
Type: application/x-bzip2
Size: 66229 bytes
Desc: not available
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130812/038c4235/attachment-0001.bin>

Reply by email

Xiangrong Fang
to Xiangrong Fang

Hi All,

Could anyone take a look at the problem? I would like to confirm if this is my problem or a bug in lazarus / fpc.

Thanks,
Shannon

2013/8/12 Xiangrong Fang

Show quoted text 26 lines
There is no backtrace at all, the only info I get when starting from command line is: xrfang at fxrmm:~/Desktop/testutf8$ ./project1 TApplication.HandleException Access violation Stack trace: $00007F2ACBF9DBD0 Please provide a backtrace. > What is r? > r is a TRegistry object, please see attached source code. > What compiler version? > FPC 2.6.2, Lazarus 1.0.10 I suspect this is a bug in related library code, because even if the result is not correct, it should not crash. Note that this error ONLY occur when I choose a directory with CJK character in its path.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130814/2764fc73/attachment.html>

Reply by email

Xiangrong Fang
to Xiangrong Fang

To help reproduce the problem, I altered the program a bit so that it does not look for a folder containing CJK path. To reproduce the problem:

1) compile and run this program under Linux (I am running Ubuntu 13.04 amd64).
2) Click the "Write" button and choose the included "test.txt" file.
3) Click the "Read" button, the program will crash.

Note: the test.txt file contains two lines, the program only read the first line, if that line contains CJK, it will crash.

Thanks,
Shannon

2013/8/14 Xiangrong Fang

Show quoted text 39 lines
Hi All, Could anyone take a look at the problem? I would like to confirm if this is my problem or a bug in lazarus / fpc. Thanks, Shannon 2013/8/12 Xiangrong Fang > There is no backtrace at all, the only info I get when starting from > command line is: > > xrfang at fxrmm:~/Desktop/testutf8$ ./project1 > TApplication.HandleException Access violation > Stack trace: > $00007F2ACBF9DBD0 > > > Please provide a backtrace. > >> What is r? >> > > r is a TRegistry object, please see attached source code. > > >> What compiler version? >> > > FPC 2.6.2, Lazarus 1.0.10 > > I suspect this is a bug in related library code, because even if the > result is not correct, it should not crash. Note that this error ONLY > occur when I choose a directory with CJK character in its path. >

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130814/7c7dfd08/attachment.html> -------------- next part --------------
A non-text attachment was scrubbed...
Name: testutf8.tar.gz
Type: application/x-gzip
Size: 2437 bytes
Desc: not available
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130814/7c7dfd08/attachment.bin>

Reply by email

Mattias Gaertner
to Xiangrong Fang
Show quoted text 10 lines
To help reproduce the problem, I altered the program a bit so that it does not look for a folder containing CJK path. To reproduce the problem: 1) compile and run this program under Linux (I am running Ubuntu 13.04 amd64). 2) Click the "Write" button and choose the included "test.txt" file. 3) Click the "Read" button, the program will crash. Note: the test.txt file contains two lines, the program only read the first line, if that line contains CJK, it will crash.

Bug is in TXmlRegistry.
TXmlRegistry.GetValueData computes in bytes, while TXMLRegistry.GetValueInfo returns length of widestring. So, you can only use ascii characters in string values.

Please report this bug in fpc bug tracker.

Mattias

Reply by email