Sign in Join

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

Mailing lists / fpc-pascal / 2013-10

use cwstring or fpwidestring on linux

8 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

ko paka

Hello,

Are there some practical differences which one to use on linux ? When I will use only fpwidestring, then when use functions CompareUnicodeString / CompareWideString and current_Collation is nil, then routine is recalled on OldManager, where those functions are not implemented. Because of that I need to add cwstring before fpwidestring. Will be those functions implemented into fpwidestring later or correct way is to add and register collation I need (cz) into fpc ?

tomas

Reply by email

Sven Barth
to ko paka
ko paka wrote 9 lines
Hello, Are there some practical differences which one to use on linux ? When I will use only fpwidestring, then when use functions CompareUnicodeString / CompareWideString and current_Collation is nil, then routine is recalled on OldManager, where those functions are not implemented. Because of that I need to add cwstring before fpwidestring. Will be those functions implemented into fpwidestring later or correct way is to add and register collation I need (cz) into fpc ?

Correct way is to register the collation you need. AFAIK it's also possible to register that at runtime, but I have to admit that I haven't followed the discussion of the features of fpwidestring that closely, so someone else will need to definitely answer that...

The main difference is that cwstring uses the Widestring manager of the system's C library while fpwidestring is a full Pascal Widestring manager.

Regards,
Sven

Reply by email

stdreamer
to Sven Barth
Sven Barth wrote
The main difference is that cwstring uses the Widestring manager of the system's C library while fpwidestring is a full Pascal Widestring manager.

So by using cwstring instead of fpwidestring am I safe to assume that the widestrings used and returned by DLLs/SOs will work correctly even when they are used as results in functions (taking in to account that widestrings are not ref counted in the first place of course)?

Reply by email

Sven Barth
to stdreamer
stdreamer wrote 11 lines
On 04/10/2013 9:08 μμ, Sven Barth wrote: > The main difference is that cwstring uses the Widestring manager of the > system's C library while fpwidestring is a full Pascal Widestring > manager. > So by using cwstring instead of fpwidestring am I safe to assume that the widestrings used and returned by DLLs/SOs will work correctly even when they are used as results in functions (taking in to account that widestrings are not ref counted in the first place of course)?

No. That one has nothing to do with any Widestring manager, but with the memory manager. The purpose of the widestring manager is to convert from strings of one encoding to another encoding.

Please note that on Windows WideStrings will work across DLL boundaries, because they are managed by Windows. This is not the case on other targets though as there WideString = UnicodeString and UnicodeStrings have the same restrictions as AnsiString.

Regards,
Sven

Reply by email

stdreamer
to Sven Barth
Sven Barth wrote 24 lines
On 04.10.2013 21:15, stdreamer wrote: > On 04/10/2013 9:08 μμ, Sven Barth wrote: > >> The main difference is that cwstring uses the Widestring manager of the >> system's C library while fpwidestring is a full Pascal Widestring >> manager. >> > > So by using cwstring instead of fpwidestring am I safe to assume that > the widestrings used and returned by DLLs/SOs will work correctly even > when they are used as results in functions (taking in to account that > widestrings are not ref counted in the first place of course)? No. That one has nothing to do with any Widestring manager, but with the memory manager. The purpose of the widestring manager is to convert from strings of one encoding to another encoding. Please note that on Windows WideStrings will work across DLL boundaries, because they are managed by Windows. This is not the case on other targets though as there WideString = UnicodeString and UnicodeStrings have the same restrictions as AnsiString. Regards, Sven

Oh well I was kind of hopping that a cwstrings will have its own memory manager as well but it was to good to be true in the first place thanks for the input.

Reply by email

Sven Barth
to stdreamer
stdreamer wrote 29 lines
On 04/10/2013 10:44 μμ, Sven Barth wrote: > On 04.10.2013 21:15, stdreamer wrote: >> On 04/10/2013 9:08 μμ, Sven Barth wrote: >> >>> The main difference is that cwstring uses the Widestring manager of the >>> system's C library while fpwidestring is a full Pascal Widestring >>> manager. >>> >> >> So by using cwstring instead of fpwidestring am I safe to assume that >> the widestrings used and returned by DLLs/SOs will work correctly even >> when they are used as results in functions (taking in to account that >> widestrings are not ref counted in the first place of course)? > > No. That one has nothing to do with any Widestring manager, but with the > memory manager. The purpose of the widestring manager is to convert from > strings of one encoding to another encoding. > > Please note that on Windows WideStrings will work across DLL boundaries, > because they are managed by Windows. This is not the case on other > targets though as there WideString = UnicodeString and UnicodeStrings > have the same restrictions as AnsiString. > > Regards, > Sven Oh well I was kind of hopping that a cwstrings will have its own memory manager as well but it was to good to be true in the first place thanks for the input.

If you want to share Unicode- or AnsiStrings between library and application you need to use a common memory manager. For example you could use unit "cmem" as one of the first units of both programs. It will work on Unix based systems and *should* work on Windows ones as well.

Regards,
Sven

Reply by email

Michael Schnell
to Sven Barth
Sven Barth wrote 5 lines
If you want to share Unicode- or AnsiStrings between library and application you need to use a common memory manager. For example you could use unit "cmem" as one of the first units of both programs. It will work on Unix based systems and *should* work on Windows ones as well.

BTW.:

For my embedded C projects, I use different memory managers, dependent on the complexity of the project. Either a straight forward one, that just allocates blocks in a linked list or a more sophisticated one that uses different strategies for different block sizes (small: allocate equally sized blocks, medium: use a linked list within a preoccupied area, large: one area for each block.

AFAIK the fpc RTL memory manager is similarly "sophisticated", no Idea what cmem does.

I do know that for Delphi a third-party memory manager exists that works similar and on top oft hat allows for unifying the memory management of a program and the dlls called (which Delphi also does out of the box with dynamic packages).

Can "cmem" (or some other fpc aware memory manager) also unify the memory management of a program and dlls (e.g. in order to allow for "plugins to fpc programs) ?

-Michael

Reply by email

ko paka
to Michael Schnell

When I used both managers, like in example, program doesnt work as expected. Should I report it as error ? For now I will stay with cwstring manager, but good to know that there is native implementation(first I need to study something about unicode and collation though) . In fpc sources I found fpwidestring used only in windows builds.

regards tomas

Example - linux i386, fpc 2.7.1 r25610

program fpwidestring_stringlist;

uses

// 3 possible combination of cwstring, fpwidestring
// 1) only cwstring - program works as expected and writes 4
// 2) only fpwidestring - error, because compareunicodestring function is
not implemented
// (current_Collation is nil in my case in
fpwidestrign.CompareUnicodeString)
// 3) both units - program writes -1 - which si really not expected
  cwstring,
  fpwidestring,
  classes;
var
  m: TStringList;
begin
  m := TStringList.Create;
  try
    m.Add('{E13ABA32-1328-4AFA-B21D-438AD054C0A5}');
    m.Add('{019D0AA0-915E-41CA-9145-05E6FC2D967C}');
    m.Add('{02591FA7-202B-4D63-BEC7-636B00BA1A8C}');
    m.Add('{23884961-80F8-4130-B60C-A5CF540A67C1}');
    m.Add('{3B3C9C24-0E23-44ED-8466-3024DF24011F}');
    m.Add('{398F240E-8809-4CE7-9175-983B96189526}');
    m.Add('{661979DB-C38D-4348-A617-59DD28D3327B}');
    m.Add('{87AC64E0-87FF-4CA5-B81C-AD494942703D}');
    Writeln('IndexOf {3B3C9C24-0E23-44ED-8466-3024DF24011F} is ',
m.IndexOf('{3B3C9C24-0E23-44ED-8466-3024DF24011F}'));
  finally
    m.Free;
  end;
end.
Michael Schnell wrote 36 lines
On 10/04/2013 11:02 PM, Sven Barth wrote: > > If you want to share Unicode- or AnsiStrings between library and > application you need to use a common memory manager. For example you could > use unit "cmem" as one of the first units of both programs. It will work on > Unix based systems and *should* work on Windows ones as well. > BTW.: For my embedded C projects, I use different memory managers, dependent on the complexity of the project. Either a straight forward one, that just allocates blocks in a linked list or a more sophisticated one that uses different strategies for different block sizes (small: allocate equally sized blocks, medium: use a linked list within a preoccupied area, large: one area for each block. AFAIK the fpc RTL memory manager is similarly "sophisticated", no Idea what cmem does. I do know that for Delphi a third-party memory manager exists that works similar and on top oft hat allows for unifying the memory management of a program and the dlls called (which Delphi also does out of the box with dynamic packages). Can "cmem" (or some other fpc aware memory manager) also unify the memory management of a program and dlls (e.g. in order to allow for "plugins to fpc programs) ? -Michael ______________________________**_________________ fpc-pascal maillist - http://lists.freepascal.org/**mailman/listinfo/fpc-pascal<http://lists.freepascal.org/mailman/listinfo/fpc-pascal>

Reply by email