Sign in Join

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

Mailing lists / lazarus / 2013-06

Unicode branch

94 messages · 16 people · –

Reply by email Subscribe to this list Your subscription

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

Marco van de Voort

During the recent FPC hackathon, Michael van Canneyt and I created a branch to switch some RTL routines to unicode. (to be exact, rawbytestring and unicodestring versions). This scheme is compatible with all dynamic string types as long as the encoding is properly set. Be careful with pointers (pchar), since they don't have encoding.

It is still all very simple, but people wanting to explore the 2-byte Windows API can find it in FPC svn fpc/branches/unicode.

However, and this is the main reason of this post, that branch also changes the windows unit to 2-byte "W" mode on Windows. Some Winunits-base units will also flip.

I tried to compile Lazarus with it, but that fails because Lazarus uses "general" functions (no -A and -W) but passes them p(ansi)char. IOW when the default changes to -W this breaks on errors like:

graphic.inc(155,66) Error: Incompatible type for arg no. 3: Got "PChar",
expected "PWideChar"

since the units are compiled in objfpc mode, and not in mode delphiunicode

Probably for now, it is best to change those issues all by appending a -A.

To build a 2-byte windows unit (and the new RTL),

1) checkout fpc/branches/unicode
2) do a make cycle to get a fresh 2.7.1
3) compile the snapshot (make all in toplevel) with -dFPC_UNICODE_RTL and FPC_OS_UNICODE (and OVERRIDEVERSIONCHECK=1 obviously)

4) compile Lazarus with the resulting snapshot.

Patches to improve 2-byte compatibility of the windows unit are welcome too.

Reply by email

Paul Ishenin
to Marco van de Voort

08.06.2013 21:53, Marco van de Voort ?????:

graphic.inc(155,66) Error: Incompatible type for arg no. 3: Got "PChar", expected "PWideChar"
Stream := TResourceStream.CreateFromID(Instance, ResID, ResType);

ResType is of type TResourceType which is declared in lcltype.pp as

   {$ifdef UNICODE}
   TResourceType = PWideChar;
   {$else}
   TResourceType = PChar;
   {$endif}
since the units are compiled in objfpc mode, and not in mode delphiunicode Probably for now, it is best to change those issues all by appending a -A.

This particular issue will not be solved this way.

Best regards,
Paul Ishenin

Reply by email

Michael Van Canneyt
to Paul Ishenin
Paul Ishenin wrote 14 lines
08.06.2013 21:53, Marco van de Voort ?????: > graphic.inc(155,66) Error: Incompatible type for arg no. 3: Got "PChar", > expected "PWideChar" Stream := TResourceStream.CreateFromID(Instance, ResID, ResType); ResType is of type TResourceType which is declared in lcltype.pp as {$ifdef UNICODE} TResourceType = PWideChar; {$else} TResourceType = PChar; {$endif}

Where is UNICODE defined ?

Because the RTL is compiled with the FPC_UNICODE_RTL define.

Michael.

Reply by email

Paul Ishenin
to Michael Van Canneyt

10.06.2013 14:55, Michael Van Canneyt ?????:

Show quoted text 9 lines
> {$ifdef UNICODE} > TResourceType = PWideChar; > {$else} > TResourceType = PChar; > {$endif} Where is UNICODE defined ? Because the RTL is compiled with the FPC_UNICODE_RTL define.

That define was made in FPC RTL for windows CE. I think now we simple need to replace it with something new.

Best regards,
Paul Ishenin

Reply by email

Michael Van Canneyt
to Paul Ishenin
Paul Ishenin wrote 7 lines
08.06.2013 21:53, Marco van de Voort ?????: > > During the recent FPC hackathon, Michael van Canneyt and I created a branch > to switch some RTL routines to unicode. (to be exact, rawbytestring and > unicodestring versions). Does your branch also includes Jonas cpstrrtl branch?

Yes, we used his patches as a start.

Michael.

Reply by email

Marco van de Voort
to Paul Ishenin: 10.06.2013 14:55, Michael Van Canneyt ?????: That define was made in FPC RTL for windows…
Paul Ishenin wrote 12 lines
>> {$ifdef UNICODE} >> TResourceType = PWideChar; >> {$else} >> TResourceType = PChar; >> {$endif} > > Where is UNICODE defined ? > > Because the RTL is compiled with the FPC_UNICODE_RTL define. That define was made in FPC RTL for windows CE. I think now we simple need to replace it with something new.

UNICODE is now reserved for Delphiunicode mode afaik. So we use FPC_OS_UNICODE as global define to signal that FPC expects API units in two-byte value. (because there is simply more Delphi code that tests for 2009+ with unicode than 3rd party API units)

In headers that already have unicode we've added
{$IFDEF FPC_OS_UNICODE}{$define unicode} {$endif}
to the top, since that is local only.

This will get hard in places where FPC/Lazarus redefines API structures for own purposes. E.g. if you fix this, further down it redefines wndclass.

Reply by email

Sven Barth
to Paul Ishenin: 10.06.2013 14:55, Michael Van Canneyt ?????: That define was made in FPC RTL for windows…
"Paul Ishenin" wrote 17 lines
10.06.2013 14:55, Michael Van Canneyt ?????: >> {$ifdef UNICODE} >> TResourceType = PWideChar; >> {$else} >> TResourceType = PChar; >> {$endif} > > > Where is UNICODE defined ? > > Because the RTL is compiled with the FPC_UNICODE_RTL define. That define was made in FPC RTL for windows CE. I think now we simple

need to replace it with something new.

Nope, WinCE uses FPC_OS_UNICODE ;)

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130610/4a611139/attachment.html>

Reply by email

Sven Barth
to Paul Ishenin
"Paul Ishenin" wrote 10 lines
10.06.13, 23:20, Sven Barth ?????: > Nope, WinCE uses FPC_OS_UNICODE ;) Not in FPC 2.6.2 which must be supported by Lazarus too.

Of course not, because the WinCE target was only broken a few weeks ago. There the define wasn't FPC_UNICODE_RTL either, but plain UNICODE (which WinCE used to define by default to switch Windows unitvto -W imports).

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130611/579e29ae/attachment.html>

Reply by email

Michael Van Canneyt
to Michael Schnell: Isn't the define "UNICODE" a heritage from Delphi (> version xyz) ? I suppose FPC and…
Michael Schnell wrote 6 lines
On 06/10/2013 08:55 AM, Michael Van Canneyt wrote: > > Where is UNICODE defined ? > Isn't the define "UNICODE" a heritage from Delphi (> version xyz) ?

It has a different meaning.

I suppose FPC and Lazarus need to stay compatible on that behalf.

Not necessarily. Compatible concerning Language/rtl functions, yes. Defines, this is debatable.

Michael.

Reply by email

Michael Schnell
to Michael Van Canneyt
Michael Van Canneyt wrote
Not necessarily. Compatible concerning Language/rtl functions, yes. Defines, this is debatable.

I do know that my colleagues use "UNICODE" a lot when porting their (huge) code-base from pre-Unicode Delphi to Unicode aware Delphi versions.

So yes it is absolutely essential to them that this define stays in it's inherited meaning when they one port their code to Lazarus / FPC to make it run on Linux.

-Michael

Reply by email

Michael Van Canneyt
to Michael Schnell
Michael Schnell wrote 10 lines
On 06/12/2013 11:10 AM, Michael Van Canneyt wrote: > > Not necessarily. Compatible concerning Language/rtl functions, yes. > Defines, this is debatable. I do know that my colleagues use "UNICODE" a lot when porting their (huge) code-base from pre-Unicode Delphi to Unicode aware Delphi versions. So yes it is absolutely essential to them that this define stays in it's inherited meaning when they one port their code to Lazarus / FPC to make it run on Linux.

Simple:

Add

{$IFDEF FPC}
{$DEFINE UNICODE}
{$ENDIF}

to your source, or, alternatively, fpc -dUNICODE

Both do the trick.

Michael.

Reply by email

Michael Schnell
to Michael Van Canneyt
Michael Van Canneyt wrote 13 lines
Add {$IFDEF FPC} {$DEFINE UNICODE} {$ENDIF} to your source, or, alternatively, fpc -dUNICODE Both do the trick.

I'm not sure if this is the trick requested, as the target is to automatically modify their source code in a way that it works on the compiler used.

Of course there are many workarounds, but the porting of course should be as straight forward as possible.

They can compile their source files both on pre-Unicode Delphi (UNICODE not defined) and on Unicode aware Delphi (UNICODE is defined).

In fact they use 8 Bit characters when UNICODE is not defined and 16 Bit characters when it is.

Thus with the currently released fpc they would need UNICODE undefined.

With the upcoming fpc they supposedly would need UNICODE defined (in case that "String" now is 16 Bit coded on default.

-Michael

Reply by email

Michael Van Canneyt
to Michael Schnell
Michael Schnell wrote 18 lines
On 06/12/2013 01:35 PM, Michael Van Canneyt wrote: > > > > Add > > {$IFDEF FPC} > {$DEFINE UNICODE} > {$ENDIF} > > to your source, or, alternatively, fpc -dUNICODE > > Both do the trick. > I'm not sure if this is the trick requested, as the target is to automatically modify their source code in a way that it works on the compiler used.

It is bad practice to rely in code on the defines defined by the compiler.

Most component suites have an include file that creates a set of defines based on more or less known version defines.

{$IFDEF VERXYZ}
{$DEFINE THISORTHATFEATURE}
{$ENDIF}

The code then uses THISORTHATFEATURE in code to distinguish between various 'features'.

Your programmers should do the same.

In each case, FPC will not define the same defines as Delphi.

Michael.

Reply by email

Michael Schnell
to Michael Van Canneyt
Michael Van Canneyt wrote
It is bad practice to rely in code on the defines defined by the compiler.

Of course I do know this (and many more similar portability-paradigms). But my colleagues do coding only with Delphi (and thus Windows) in mind. I can't help this. But now "suddenly" (since some 5 years) the company wishes to support Linux.

I do research on that but I can't force them to to modify their hundred thousands of code lines on that behalf (_Again_ after they needed to do this because of the move of Delphi to Unicode). If it's to difficult they will just say the move towards Linux is impossible.

In each case, FPC will not define the same defines as Delphi.

Of course not, but there are instances like this that are rather obvious and limited, thus supposedly doable.

-Michael

Reply by email

Michael Van Canneyt
to Michael Schnell
Michael Schnell wrote 7 lines
On 06/12/2013 02:18 PM, Michael Van Canneyt wrote: > > It is bad practice to rely in code on the defines defined by the compiler. Of course I do know this (and many more similar portability-paradigms). But my colleagues do coding only with Delphi (and thus Windows) in mind. I can't help this. But now "suddenly" (since some 5 years) the company wishes to support Linux.

The issue exists even if you only code for Delphi. See the example of component suites.

I do research on that but I can't force them to to modify their hundred thousands of code lines on that behalf (_Again_ after they needed to do this because of the move of Delphi to Unicode). If it's to difficult they will just say the move towards Linux is impossible.

Adding -dUNICODE on the fpc commandline is difficult ?

Let's be serious.

> In each case, FPC will not define the same defines as Delphi. Of course not, but there are instances like this that are rather obvious and limited, thus supposedly doable.

Anything is doable. Doesn't mean we should. In this case: I don't think so. The scope of the UNICODE define is not "well defined".

Michael.

Reply by email

Michael Schnell
to Michael Van Canneyt
Michael Van Canneyt wrote
Adding -dUNICODE on the fpc commandline is difficult ?

problem would arise, if fpc or Lazarus would define UNICODE in _a_different_ way than Delphi does, and thus simply doing " -dUNICODE" would be not allowed or not possible.

Show quoted text 5 lines
Anything is doable. Doesn't mean we should. In this case: I don't think so. The scope of the UNICODE define is not "well defined".

I agree. The problem is even deeper.

As I was told by my colleagues the implementation of the quasi-dynamically coded strings in Delphi is far from perfect (it seems to be at least decently usable as of XE2).

So I suppose (and hope) fpc and Lazarus will do significant enhancements to the concept, concerning usability and flexibility (we already discussed some of them here and in the fpc-dev group). Of course for m<y colleagues they would need to be fully compatible to Delphi, as they need to compile their projects on both systems without too much additional effort. (They claim to be 150 % busy anyway, and the Linux stuff is added on top of this.)

-Michael

Reply by email

Michael Van Canneyt
to Marco van de Voort: Yes, and if you chose the explicit compatibility mode for that version, $mode…
Marco van de Voort wrote 10 lines
On Wed, Jun 12, 2013 at 10:55:24AM +0200, Michael Schnell wrote: > On 06/10/2013 08:55 AM, Michael Van Canneyt wrote: >> >> Where is UNICODE defined ? >> > > Isn't the define "UNICODE" a heritage from Delphi (> version xyz) ? Yes, and if you chose the explicit compatibility mode for that version, $mode delphiunicode, it _is_ defined.

Now why on earth would we do that ?
We don't define VERXYZ either in mode delphi ??

Michael.

Reply by email

Michael Schnell
to Marco van de Voort: No. This is part of that, but only the most initial level. Much is not yet decided. ...…
Marco van de Voort wrote 7 lines
No. This is part of that, but only the most initial level. Much is not yet decided. ... including how compatible it will be. (and more importantly, how portable the compatibility will be)

As I followed (an took part in) several discussions on the move to (quasi-) dynamically encoded Strings. I perfectly do understand this. l always stated that it is not a good idea to just do "some" implementation before decently agreed definitions have been nailed down. The final product needs to fulfill some contradicting needs such as
- "easy to use even for beginners" i.e. providing automatic conversions when necessary,
- "architecture independent",
- "decent performance" at least when used appropriately thoughtful: avoiding unnecessary automatic conversions by not mixing different subtypes..
- "backwards compatibility" not breaking legacy fpc / Lazarus user code
- "Delphi compatibility" at least when an appropriate mode is set. This includes Delphi XE and pre-Unicode Delphi versions
- Unicode Details like handling of ambiguous code points and code-point combinations in "=" compare. "Upcase". Also case insensitive compare, "<" / ">" compare which seems to be language depending even for Unicode.
- "versatility" maybe extended vs. Delphi. Here I would like to see String-Sub-Types like non-encoded ( never auto-converted / "RAW") Byte, Word, DWord and QWord Strings and fully dynamically coded (not forcing a conversion when assigned to) Strings.
- "extensibility": it should be doable - even for the end-user - and appropriately documented, to create an additional (auto converting) String Subtype for propriety encoding schemes (e.g. html entity) by providing appropriate conversion functions.
- ...

For me. a big question still is, what to do with the ambiguous MyString[n] notation. I am sure that Mr Wirth meant it like "take the n the printable character from the string", which with the Unicode-driven support for non-western languages does not make too much sense any more. (Maybe someone should ask him ?!?!?!). But as (western) beginners never will accept that MyString[n] works in terms of sub-code (which works rather well for them with UTF-16, but usually not with UTF-8), I vote for dropping it altogether, unless enabled by a "take care" $mode setting.

-Michael

Reply by email

Sven Barth
to Michael Van Canneyt: Now why on earth would we do that ? We don't define VERXYZ either in mode delphi ??…
Michael Van Canneyt wrote 17 lines
On Wed, 12 Jun 2013, Marco van de Voort wrote: > On Wed, Jun 12, 2013 at 10:55:24AM +0200, Michael Schnell wrote: >> On 06/10/2013 08:55 AM, Michael Van Canneyt wrote: >>> >>> Where is UNICODE defined ? >>> >> >> Isn't the define "UNICODE" a heritage from Delphi (> version xyz) ? > > Yes, and if you chose the explicit compatibility mode for that version, > $mode delphiunicode, it _is_ defined. Now why on earth would we do that ? We don't define VERXYZ either in mode delphi ??

The motivation was exactly the point that Delphi versions where String=UnicodeString define "Unicode" while former versions do not, so the definition of the UNICODE switch was linked to modeswitch unicodestrings (and thus to mode delphiunicode). This was also the reason why WinCE compilation got broken (it defines UNICODE by default which got undefined after mode ObjFPC was encountered) and I added the FPC_OS_UNICODE define.

Regards,
Sven

Reply by email

Michael Van Canneyt
to Sven Barth
Sven Barth wrote 24 lines
Am 12.06.2013 17:36, schrieb Michael Van Canneyt: > > > On Wed, 12 Jun 2013, Marco van de Voort wrote: > >> On Wed, Jun 12, 2013 at 10:55:24AM +0200, Michael Schnell wrote: >>> On 06/10/2013 08:55 AM, Michael Van Canneyt wrote: >>>> >>>> Where is UNICODE defined ? >>>> >>> >>> Isn't the define "UNICODE" a heritage from Delphi (> version xyz) ? >> >> Yes, and if you chose the explicit compatibility mode for that version, >> $mode delphiunicode, it _is_ defined. > > Now why on earth would we do that ? We don't define VERXYZ either in mode > delphi ?? The motivation was exactly the point that Delphi versions where String=UnicodeString define "Unicode" while former versions do not, so the definition of the UNICODE switch was linked to modeswitch unicodestrings (and thus to mode delphiunicode). This was also the reason why WinCE compilation got broken (it defines UNICODE by default which got undefined after mode ObjFPC was encountered) and I added the FPC_OS_UNICODE define.

All the more reason not to try to emulate Delphi defines.

Currently the following can be found:
FPC_HAS_UNICODESTRING
FPC_WIDESTRING_EQUAL_UNICODESTRING
FPC_UNICODESTRINGS
UNICODE

The UNICODE define is simply superfluous. Those that need it can do a

{$IFDEF FPC_UNICODESTRINGS}
{$DEFINE UNICODE}
{$ENDIF}

And they'll need defines anyway because widestring unicodestring on windows.

But it is all water under the bridge.

Michael.

Reply by email

Michael Van Canneyt
to Michael Schnell
Michael Schnell wrote 6 lines
On 06/13/2013 11:32 AM, Michael Van Canneyt wrote: > > And they'll need defines anyway because widestring unicodestring on > windows. > The compiler does know whether it compiles for Windows or not. Doesn't it ?

The problem is not in the compiler.
The problem is that IF your code assumes that WideString=UnicodeString then you will need to differentiate the 2 cases.

You can do this based on the OS define (bad practice, because it encompasses an implicit assumption) or introduce a new define (as FPC did).

You can set this new define based on the OS, but this is secondary.

Michael.

Reply by email

Sven Barth
to Michael Van Canneyt: All the more reason not to try to emulate Delphi defines. Currently the following can be…
Michael Van Canneyt wrote 35 lines
On Thu, 13 Jun 2013, Sven Barth wrote: > Am 12.06.2013 17:36, schrieb Michael Van Canneyt: >> >> >> On Wed, 12 Jun 2013, Marco van de Voort wrote: >> >>> On Wed, Jun 12, 2013 at 10:55:24AM +0200, Michael Schnell wrote: >>>> On 06/10/2013 08:55 AM, Michael Van Canneyt wrote: >>>>> >>>>> Where is UNICODE defined ? >>>>> >>>> >>>> Isn't the define "UNICODE" a heritage from Delphi (> version xyz) ? >>> >>> Yes, and if you chose the explicit compatibility mode for that >>> version, >>> $mode delphiunicode, it _is_ defined. >> >> Now why on earth would we do that ? We don't define VERXYZ either in >> mode delphi ?? > The motivation was exactly the point that Delphi versions where > String=UnicodeString define "Unicode" while former versions do not, > so the definition of the UNICODE switch was linked to modeswitch > unicodestrings (and thus to mode delphiunicode). This was also the > reason why WinCE compilation got broken (it defines UNICODE by > default which got undefined after mode ObjFPC was encountered) and I > added the FPC_OS_UNICODE define. All the more reason not to try to emulate Delphi defines. Currently the following can be found: FPC_HAS_UNICODESTRING FPC_WIDESTRING_EQUAL_UNICODESTRING FPC_UNICODESTRINGS UNICODE

FPC_HAS_UNICODESTRING can be removed, because that was needed for bootstrapping after the introduction of UnicodeString which was either in 2.2 or 2.4 series, so long gone already.

Regards,
Sven

Reply by email

Michael Schnell
to Michael Van Canneyt: The problem is not in the compiler. The problem is that IF your code assumes that…
Michael Van Canneyt wrote
The problem is not in the compiler. The problem is that IF your code assumes that WideString=UnicodeString then you will need to differentiate the 2 cases.

I suppose you are correct. But if I understand correctly what my Delphi addicted colleagues state: Delphi-User use just "String" as their string type, as they never learned to be careful about the code. Delphi is assumed to be Windows only, and thus if a Unicode version of Delphi is used (i.e. "UNICODE" is set) "String" is Unicode with UTF16 coding and for non-Unicode Delphi (i.e. "UNICODE" is not set) "String" is 8 bit ANSI code in the local language variant. If anybody uses "Widestring" (not ref-counted in Delphi AFAIR) he should know what he does.

This is what Lazarus / fpc should not break (of course no problem to have the user select an appropriate mode in the project setting).

-Michael

Reply by email

Marco van de Voort
to Michael Van Canneyt: All the more reason not to try to emulate Delphi defines. Currently the following can be…
Michael Van Canneyt wrote
> ObjFPC was encountered) and I added the FPC_OS_UNICODE define. All the more reason not to try to emulate Delphi defines.

Why? We define "Windows" and "MSWindows" too?
Maybe not use "linux" because Kylix does ? :-)

Show quoted text 7 lines
UNICODE The UNICODE define is simply superfluous. Those that need it can do a {$IFDEF FPC_UNICODESTRINGS} {$DEFINE UNICODE} {$ENDIF}

Yes. And anybody wanting Delphi compatibility can just use {$mode objfpc} and start subsituting.

I don't see a problem whatsoever defining a Delphi define in a delphi compatibility mode.

And they'll need defines anyway because widestring unicodestring on windows.

No. Since on Delphi those are different too. They don't need additional defines for that.

Reply by email

Michael Van Canneyt
to Marco van de Voort: Why? We define "Windows" and "MSWindows" too? Maybe not use "linux" because Kylix does ?…
Marco van de Voort wrote 7 lines
On Thu, Jun 13, 2013 at 11:32:36AM +0200, Michael Van Canneyt wrote: >> ObjFPC was encountered) and I added the FPC_OS_UNICODE define. > > All the more reason not to try to emulate Delphi defines. Why? We define "Windows" and "MSWindows" too? Maybe not use "linux" because Kylix does ? :-)

Those represent the OS, using the name of the OS is natural.

Whereas UNICODE indicates an internal compiler feature. We use FPC_XYZ for those.

But as I said, it's all water under the bridge.

Michael.

Reply by email

Marco van de Voort
to Michael Van Canneyt
Michael Van Canneyt wrote 7 lines
>> The problem is not in the compiler. >> The problem is that IF your code assumes that WideString=UnicodeString > > That is Delphi incompatble. Simply don't enable Delphi compatibility mode > then. Which Delphi version ?

Any D2009+, the Delphi versions that $mode delphiunicode supports?!?!

Reply by email

Sven Barth
to Michael Van Canneyt: Which Delphi version ? Michael.
Michael Van Canneyt wrote 14 lines
On Thu, 13 Jun 2013, Marco van de Voort wrote: > On Thu, Jun 13, 2013 at 11:51:38AM +0200, Michael Van Canneyt wrote: >> >> The problem is not in the compiler. >> The problem is that IF your code assumes that WideString=UnicodeString > > That is Delphi incompatble. Simply don't enable Delphi compatibility > mode > then. Which Delphi version ?

UnicodeString was introduced in Delphi 2009 and already there UnicodeString WideString was the case (because Delphi was still Windows only at that time and thus the seperate WideString type managed by Windows was needed).

Regards,
Sven

Reply by email

Vincent Snijders
to Marco van de Voort: During the recent FPC hackathon, Michael van Canneyt and I created a branch to switch…

2013/6/8 Marco van de Voort

Show quoted text 6 lines
To build a 2-byte windows unit (and the new RTL), 1) checkout fpc/branches/unicode 2) do a make cycle to get a fresh 2.7.1

I did a make all at the top level directory, which ignores my fpc.cfg (good) and calls make cycle in the compiler dir (good). It fails.

C:/FPC/2.6.2/bin/i386-Win32/ppc386.exe -Ur -Xs -O2 -n -Fi../inc -Fi../i386 -Fi..
/win -FE.
-FUC:/lazarus/jenkins/workspace/buildfpc_branch/platform/i386-win32/fp c/branches/unicode/rtl/units/i386-win32 -di386 -dRELEASE -Us -Sg system.pp -Fi..
/win
astrings.inc(1429,11) Error: overloaded functions have the same parameter list
astrings.inc(1435,11) Error: overloaded functions have the same parameter list
system.pp(709) Fatal: There were 2 errors compiling module, stopping Fatal: Compilation aborted

http://svn.freepascal.org/cgi-bin/viewvc.cgi/branches/unicode/rtl/inc/astrings.inc?r1=24715&r2=24885&diff_format=lseems an unnecesary change which I suspect breaks compilation

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

Reply by email

Michael Schnell
to Marco van de Voort: During the recent FPC hackathon, Michael van Canneyt and I created a branch to switch…

I just have been told that Embarcadero plans to do away with the stuff fpc is just implementing in the "Unicode branch" and is on the verge to change to a completely new String type that is
- UTF-16-only,
- Zero-Based, and
- immutable.
And thus completely incompatible with any "String" Type ever known in Pascal.

So
- why do we discuss compatibility at all ?
- do we like this (rather complex and not at all "straight forward") String type that much that it is viable to implement, debug and decently document this library ?

-Michael

Reply by email

Hans-Peter Diettrich
to Michael Schnell
Show quoted text 8 lines
I just have been told that Embarcadero plans to do away with the stuff fpc is just implementing in the "Unicode branch" and is on the verge to change to a completely new String type that is - UTF-16-only, - Zero-Based, and - immutable. And thus completely incompatible with any "String" Type ever known in Pascal.

They also make TObject reference counted...

Show quoted text 5 lines
So - why do we discuss compatibility at all ? - do we like this (rather complex and not at all "straight forward") String type that much that it is viable to implement, debug and decently document this library ?

UnicodeString has been introduced in D2009, i.e. we are a couple of years behind with compatibility.

Once this has been implemented, we can spend some more years with updating the RTL and LCL - or continue using UTF-8 instead of UTF-16.

When we can start implementing further changes, we should look whether Delphi exists at all, at that time. I wouldn't hold my breath ;-)

DoDi

Reply by email

Curt Carpenter
to Hans-Peter Diettrich

For the very little that it's worth, I abandoned Delphi (10) because I was sick of Embarcadero's approach to strings at that time, which forced a rework of *a lot* of my old code and components.

Adopted Lazarus and never looked back.

Hans-Peter Diettrich wrote 37 lines
Michael Schnell schrieb: > I just have been told that Embarcadero plans to do away with the > stuff fpc is just implementing in the "Unicode branch" and is on the > verge to change to a completely new String type that is > - UTF-16-only, > - Zero-Based, and > - immutable. > And thus completely incompatible with any "String" Type ever known in > Pascal. They also make TObject reference counted... > So > - why do we discuss compatibility at all ? > - do we like this (rather complex and not at all "straight forward") > String type that much that it is viable to implement, debug and > decently document this library ? UnicodeString has been introduced in D2009, i.e. we are a couple of years behind with compatibility. Once this has been implemented, we can spend some more years with updating the RTL and LCL - or continue using UTF-8 instead of UTF-16. When we can start implementing further changes, we should look whether Delphi exists at all, at that time. I wouldn't hold my breath ;-) DoDi -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

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

Reply by email

Florian Klämpfl
to Michael Schnell: I just have been told that Embarcadero plans to do away with the stuff fpc is just…
Michael Schnell wrote 11 lines
I just have been told that Embarcadero plans to do away with the stuff fpc is just implementing in the "Unicode branch" and is on the verge to change to a completely new String type that is - UTF-16-only, - Zero-Based, and - immutable. And thus completely incompatible with any "String" Type ever known in Pascal. So - why do we discuss compatibility at all ?

FPC is a community approach so compatibility is implemented by those being interested in it.

Show quoted text 12 lines
- do we like this (rather complex and not at all "straight forward") String type that much that it is viable to implement, debug and decently document this library ? -Michael -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Michael Van Canneyt
to Michael Schnell: I just have been told that Embarcadero plans to do away with the stuff fpc is just…
Michael Schnell wrote 7 lines
I just have been told that Embarcadero plans to do away with the stuff fpc is just implementing in the "Unicode branch" and is on the verge to change to a completely new String type that is - UTF-16-only, - Zero-Based, and - immutable. And thus completely incompatible with any "String" Type ever known in Pascal.

AFAIK This is only for the new nextgen compiler, for the Win32 target, nothing changes.

Michael.

Reply by email

Felipe Monteiro de Carvalho
to Hans-Peter Diettrich: They also make TObject reference counted... UnicodeString has been introduced in D2009,…
Hans-Peter Diettrich wrote 9 lines
> I just have been told that Embarcadero plans to do away with the stuff fpc > is just implementing in the "Unicode branch" and is on the verge to change > to a completely new String type that is > - UTF-16-only, > - Zero-Based, and > - immutable. > And thus completely incompatible with any "String" Type ever known in > Pascal. They also make TObject reference counted...

lol! That's ridiculous ... they will just keep changing and changing? And expect people to rewrite their codebases every 4 years?

And for me a key advantage of Pascal was always that it is (was?) so backwards compatible...

Michael Van Canneyt wrote
AFAIK This is only for the new nextgen compiler, for the Win32 target, nothing changes.

the win32 platform is already de-facto deprecated, so I don't think this makes it any better.

Florian Kl?mpfl wrote
FPC is a community approach so compatibility is implemented by those being interested in it.

Yes, but such backwards incompatible changes such as changing the string type, changing TObject, they cannot be added as simply another feature which exists in parallel with the rest ... everyone has to migrate into the new thing. For very large codebases the change might not be
Felipe Monteiro de Carvalho

Reply by email

Michael Schnell
to Hans-Peter Diettrich: They also make TObject reference counted... UnicodeString has been introduced in D2009,…
Hans-Peter Diettrich wrote
They also make TObject reference counted...

I did read about this. So ".Free" is going to be obsolete ?

When we can start implementing further changes, we should look whether Delphi exists at all, at that time. I wouldn't hold my breath ;-)

Regarding the changes they are tying to force to their customers (yet another string paradigm, Firemonkey), instead of trying to offer an as smooth migration path as possible, and not even trying to support Linux and Android (that now has a lot greater market share than IOS) obviously recommends a decent

Reply by email

Michael Schnell
to Michael Van Canneyt: AFAIK This is only for the new nextgen compiler, for the Win32 target, nothing changes.…
Michael Van Canneyt wrote
AFAIK This is only for the new nextgen compiler, for the Win32 target, nothing changes.

To me it makes absolutely no sense to force the programmers to use different paradigms for different platforms. A decent programming system should hide this diorty stuff from the application programmer. Only who wants to dig deeper (for performance or to implement really platform specific stuff) should be forced (and able to) get there.

Win32 is dead anyway. (IMHO soon the main platforms to be supported will be LINUX in ARM 64 and Android. No notion of either with Embarcadero.)

-Michael

Reply by email

Hans-Peter Diettrich
to Felipe Monteiro de Carvalho: On Mon, Jun 24, 2013 at 5:14 PM, Hans-Peter Diettrich lol! That's ridiculous ... they…
Show quoted text 14 lines
On Mon, Jun 24, 2013 at 5:14 PM, Hans-Peter Diettrich wrote: >> I just have been told that Embarcadero plans to do away with the stuff fpc >> is just implementing in the "Unicode branch" and is on the verge to change >> to a completely new String type that is >> - UTF-16-only, >> - Zero-Based, and >> - immutable. >> And thus completely incompatible with any "String" Type ever known in >> Pascal. > They also make TObject reference counted... lol! That's ridiculous ... they will just keep changing and changing? And expect people to rewrite their codebases every 4 years?

Yes, that's the only way to make people buy new Delphi versions. In theory at least, in practice it may make people stop buying new

Reply by email

Marco van de Voort
to Michael Schnell: I just have been told that Embarcadero plans to do away with the stuff fpc is just…
Michael Schnell wrote 8 lines
I just have been told that Embarcadero plans to do away with the stuff fpc is just implementing in the "Unicode branch" and is on the verge to change to a completely new String type that is - UTF-16-only, - Zero-Based, and - immutable. And thus completely incompatible with any "String" Type ever known in Pascal.

As far as I know that was all to be limited to their mobile offering.

Reply by email

Marco van de Voort
to Graeme Geldenhuys: When you say Win32 do you mean Windows (as in 32 & 64-bit) or only 32-bit Windows? So…
Graeme Geldenhuys wrote
So what platforms with the nextgen compiler target? OS X, iOS, Android, Windows Phone, Linux? All but Windows?

There is a note in the XE4 related documentation, that desktop Delphi/nextgen will be compatible with the current situation a long time.

I took that as the whole thing being a cheap shot at avoiding the platform/architecture dependent parts of legacy implementation on the new mobile targets, and a sign that the mobile targets are more a quick buck than a fundamental new addition.

Reply by email

Marco van de Voort
to Vincent Snijders: 2013/6/8 Marco van de Voort I did a make all at the top level directory, which ignores my…
Vincent Snijders wrote 10 lines
> To build a 2-byte windows unit (and the new RTL), > > 1) checkout fpc/branches/unicode > 2) do a make cycle to get a fresh 2.7.1 > I did a make all at the top level directory, which ignores my fpc.cfg (good) and calls make cycle in the compiler dir (good). It fails. http://svn.freepascal.org/cgi-bin/viewvc.cgi/branches/unicode/rtl/inc/astrings.inc?r1=24715&r2=24885&diff_format=lseems an unnecesary change which I suspect breaks compilation

Fixed.

Reply by email

Sven Barth
to Michael Schnell: If this really works and does not break anything, I wonder why this has not been…
Michael Schnell wrote
On 06/25/2013 03:14 PM, Sven Barth wrote: > Yes, it will merely be an empty method then. If this really works and does not break anything, I wonder why this has not been implemented since long...

There can be problems where the reference counting mechanism is misled. Similar to the problems that appear with reference counted interfaces.

Another problem could be circular references especially in legacy code where object A needs object B and vice versa and none does an explicit "OtherObject := Nil".

Regards,
Sven

PS: You CC'ed me again, which is why my message was sent to you only...

Reply by email

Hans-Peter Diettrich
to Graeme Geldenhuys: Yeah, that change is going to be a nightmare to lots of existing code. I hope Delphi…
Show quoted text 6 lines
On 26/06/13 07:19, Martin Schreiber wrote: > Because then classes work like COM interfaces. Shudder. Yeah, that change is going to be a nightmare to lots of existing code. I hope Delphi developers enjoy debugging!

I don't see any relationship to COM here. Java has managed objects, C++ has, .NET has, so why not OPL too?

The management overhead is as low as for managed strings. Also a "weak" keyword has been introduced for unmanaged object references - for people who don't like reference counting.

I don't like managed (refcounted) class objects for other reasons. In detail they can easily lead to zombies, which keep each other alive by circular references. It also is not really possible to remove destructor/finalizer code in such an environment, so that no or dangerous comfort is the only result from using such a model.

DoDi

Reply by email

Graeme Geldenhuys
to Hans-Peter Diettrich
Hans-Peter Diettrich wrote
I don't see any relationship to COM here. Java has managed objects, C++ has, .NET has, so why not OPL too?

I wasn't referring to COM explicitly. But having objects being freed when the developer didn't expect it (because that was not the behaviour before), is what is going to cause troubles. When you work with reference counted Interfaces you know what to expect and coded accordingly [eg: by putting checks in place, knowing how to pass interfaces with/without incrementing/decrementing reference counts etc.].

Regards,
- Graeme -

Reply by email

Hans-Peter Diettrich
to Graeme Geldenhuys
Show quoted text 8 lines
On 2013-06-26 16:59, Hans-Peter Diettrich wrote: > I don't see any relationship to COM here. Java has managed objects, C++ > has, .NET has, so why not OPL too? I wasn't referring to COM explicitly. But having objects being freed when the developer didn't expect it (because that was not the behaviour before), is what is going to cause troubles.

I don't see a chance for trouble when the object is destroyed *after* the last usable reference disappears.

When you work with reference counted Interfaces you know what to expect and coded accordingly [eg: by putting checks in place, knowing how to pass interfaces with/without incrementing/decrementing reference counts etc.].

Automatic reference counting works pretty well, doing it manually is asking for trouble.

DoDi

Reply by email

Marco van de Voort
to Hans-Peter Diettrich: I don't see any relationship to COM here. Java has managed objects, C++ has, .NET has, so…
Hans-Peter Diettrich wrote 5 lines
> Yeah, that change is going to be a nightmare to lots of existing code. I > hope Delphi developers enjoy debugging! I don't see any relationship to COM here. Java has managed objects, C++ has, .NET has, so why not OPL too?

Java and C# don't count, as safe languages, they have _ONLY_ managed types. Their choices will be hard to backport.

As far as the C++ bit goes, that is all fairly new. Which part of the standard (and which standard) do you mean exactly, and which implementation?

The management overhead is as low as for managed strings.

Where did you get that information? It is easy to see that it is somewhat doubtful as string has copy-on-write properties in addition to ref-counting.

Show quoted text 5 lines
I don't like managed (refcounted) class objects for other reasons. In detail they can easily lead to zombies, which keep each other alive by circular references. It also is not really possible to remove destructor/finalizer code in such an environment, so that no or dangerous comfort is the only result from using such a model.

I think Embarcadero is using the mobile version as testing ground, and maybe they are having doubts if the desktop-mobile product lines will be synchronous in the long end.

Reply by email

Marco van de Voort
to Michael Schnell: As stated earlier by several contributors, splitting the language into two separate…
Michael Schnell wrote 5 lines
On 06/25/2013 03:16 PM, Marco van de Voort wrote: > As far as I know that was all to be limited to their mobile offering. As stated earlier by several contributors, splitting the language into two separate branches for different architectures seems like an utterly bad idea.

That's the whole idea, I think they expect to attract a new audience with the mobile offering, and not just sell upgrades to the old Delphi crowd.

I do hope Lazarus will be able to provide a better alternative :-) .

IMHO Delphi XE4 mobile version is an unrelated product (like 3rdrail, Delphi.NET, Delphi Prism etc) till proven otherwise.

Reply by email

Michael Schnell
to Hans-Peter Diettrich: I don't see any relationship to COM here. Java has managed objects, C++ has, .NET has, so…
Hans-Peter Diettrich wrote
I don't see any relationship to COM here.

Delphi "interfaces" mostly are seen as COM thingies, even though they are just straight forward language constructs that _can_ be used to attach to COM objects. but they can be happily be used for other purposes.

Supposedly ref-counted object could allow for a much more "relaxed" way of doing a Com object implementation.

-Michael

Reply by email

Hans-Peter Diettrich
to Marco van de Voort: Java and C# don't count, as safe languages, they have _ONLY_ managed types. Their choices…
Show quoted text 8 lines
On Wed, Jun 26, 2013 at 05:59:06PM +0200, Hans-Peter Diettrich wrote: >> Yeah, that change is going to be a nightmare to lots of existing code. I >> hope Delphi developers enjoy debugging! > I don't see any relationship to COM here. Java has managed objects, C++ > has, .NET has, so why not OPL too? Java and C# don't count, as safe languages, they have _ONLY_ managed types. Their choices will be hard to backport.

Right. The idea sounds to me like the other half-baked attempts to introduce anonymous methods, class helpers etc. into Pascal.

As far as the C++ bit goes, that is all fairly new. Which part of the standard (and which standard) do you mean exactly, and which implementation?

All local C++ objects are destroyed when they go out of scope.

> The management overhead is as low as for managed strings. Where did you get that information? It is easy to see that it is somewhat doubtful as string has copy-on-write properties in addition to ref-counting.

That's something different. While it's possible to copy strings automatically, the same is impossible with more complex objects. At least a copy-constructor were required for that purpose. Or more than one, depending on the kind of the copy (deep/shallow...).

DoDi

Reply by email

Graeme Geldenhuys
to Hans-Peter Diettrich: I don't see a chance for trouble when the object is destroyed *after* the last usable…
Hans-Peter Diettrich wrote
Automatic reference counting works pretty well, doing it manually is asking for trouble.

Sometimes it becomes trick (at least with reference counted interfaces). eg: I have code where I pass a interface around, but don't want the reference count to increment - so you need to take special precaution. Then I also have a container that holds references to interfaces, but again I don't want the container to increment reference counts - which would normally be the case. Sometimes the opposite is also true.

Then there is also the question of when does the interface or object get freed - timing is sometimes important too. eg: I can't use some of the code I used to use in Delphi with interfaces, because the code "apparently" relies on undocumented Delphi language behaviour (even some commercial apps rely on that same behaviour). Free Pascal frees the Interface instances at different times to Delphi - so the code in my application under Free Pascal had to be changed. More info: Google mouse cursor management with Interfaces, or look at CodeSite's method tracing abilities.

Reference counting is a double-edged sword.

Regards,
- Graeme -

Reply by email

Hans-Peter Diettrich
to Graeme Geldenhuys
Show quoted text 10 lines
On 2013-06-27 11:45, Hans-Peter Diettrich wrote: > Automatic reference counting works pretty well, doing it manually is > asking for trouble. Sometimes it becomes trick (at least with reference counted interfaces). eg: I have code where I pass a interface around, but don't want the reference count to increment - so you need to take special precaution. Then I also have a container that holds references to interfaces, but again I don't want the container to increment reference counts - which would normally be the case. Sometimes the opposite is also true.

I see no valid reason for doing so.

Show quoted text 9 lines
Then there is also the question of when does the interface or object get freed - timing is sometimes important too. eg: I can't use some of the code I used to use in Delphi with interfaces, because the code "apparently" relies on undocumented Delphi language behaviour (even some commercial apps rely on that same behaviour). Free Pascal frees the Interface instances at different times to Delphi - so the code in my application under Free Pascal had to be changed. More info: Google mouse cursor management with Interfaces, or look at CodeSite's method tracing abilities.

I don't see how this is related to managed objects.

DoDi

Reply by email

Sven Barth
to Hans-Peter Diettrich: Right. The idea sounds to me like the other half-baked attempts to introduce anonymous…
"Hans-Peter Diettrich" wrote 6 lines
Marco van de Voort schrieb: > On Wed, Jun 26, 2013 at 05:59:06PM +0200, Hans-Peter Diettrich wrote: >>> >>> Yeah, that change is going to be a nightmare to lots of existing code.

I

>>> hope Delphi developers enjoy debugging! >> >> I don't see any relationship to COM here. Java has managed objects, C++

has, .NET has, so why not OPL too?

> > > Java and C# don't count, as safe languages, they have _ONLY_ managed

types.

> Their choices will be hard to backport. Right. The idea sounds to me like the other half-baked attempts to

introduce anonymous methods, class helpers etc. into Pascal.

I personally consider helper types implemented cleaner in Object Pascal than C#'s extension methods (except the "one helper only" restriction, but I want to lift that anyway :) ).

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130627/2a2acaf9/attachment.html>

Reply by email

Hans-Peter Diettrich
to Graeme Geldenhuys
Show quoted text 6 lines
On 2013-06-27 21:32, Hans-Peter Diettrich wrote: > I don't see how this is related to managed objects. If FPC implements managed objects, is it going to behave _exactly_ like Delphi, or slightly different to Delphi - like what happened to the Interfaces implementation.

Right, and you seem to be the only one playing around with manual refcounting, and having (consequential) problems with managed objects.

DoDi

Reply by email

Sven Barth
to Graeme Geldenhuys: If FPC implements managed objects, is it going to behave _exactly_ like Delphi, or…
Graeme Geldenhuys wrote 6 lines
On 2013-06-27 21:32, Hans-Peter Diettrich wrote: > I don't see how this is related to managed objects. If FPC implements managed objects, is it going to behave _exactly_ like Delphi, or slightly different to Delphi - like what happened to the Interfaces implementation.

There won't be any exact Delphi like implementation, because like with interfaces it isn't documented _when exactly_ the reference count is decreased.

Regards,
Sven

Reply by email

Marco van de Voort
to Hans-Peter Diettrich: Right. The idea sounds to me like the other half-baked attempts to introduce anonymous…
Hans-Peter Diettrich wrote 5 lines
> Java and C# don't count, as safe languages, they have _ONLY_ managed types. > Their choices will be hard to backport. Right. The idea sounds to me like the other half-baked attempts to introduce anonymous methods, class helpers etc. into Pascal.

Class helpers are more a solution to a Delphi problem, namely its high binary dcu usage. Class helpers help to "add" methods, even when the mother unit is dcu only. People often confuse it with mixins and other complicated runtime object systems that it is not.

> As far as the C++ bit goes, that is all fairly new. Which part of the > standard (and which standard) do you mean exactly, and which implementation? All local C++ objects are destroyed when they go out of scope.

Yes, but if you only aim that high, just use an editor macro that autogenerates a create-try-finally-free sequence, or JCL safeguards.

Show quoted text 7 lines
>> The management overhead is as low as for managed strings. > > Where did you get that information? It is easy to see that it is somewhat > doubtful as string has copy-on-write properties in addition to ref-counting. That's something different. While it's possible to copy strings automatically, the same is impossible with more complex objects.

True. But my point was that makes performance comparisons somewhat odd, since there are two properties that strings have that can't be emulated easily (no nesting and copy-on-write).

So I really wondered where you got the numbers on, and I note you still haven't posted anything that made that claim believable.

Reply by email

Hans-Peter Diettrich
to Sven Barth: There won't be any exact Delphi like implementation, because like with interfaces it…
Show quoted text 11 lines
On 28.06.2013 16:49, Graeme Geldenhuys wrote: > On 2013-06-27 21:32, Hans-Peter Diettrich wrote: >> I don't see how this is related to managed objects. > > If FPC implements managed objects, is it going to behave _exactly_ like > Delphi, or slightly different to Delphi - like what happened to the > Interfaces implementation. There won't be any exact Delphi like implementation, because like with interfaces it isn't documented _when exactly_ the reference count is decreased.

It is decreased whenever a reference expires. Where do you see chances for a different implementation?

DoDi

Reply by email

Sven Barth
to Hans-Peter Diettrich
Hans-Peter Diettrich wrote 15 lines
Sven Barth schrieb: > On 28.06.2013 16:49, Graeme Geldenhuys wrote: >> On 2013-06-27 21:32, Hans-Peter Diettrich wrote: >>> I don't see how this is related to managed objects. >> >> If FPC implements managed objects, is it going to behave _exactly_ like >> Delphi, or slightly different to Delphi - like what happened to the >> Interfaces implementation. > > There won't be any exact Delphi like implementation, because like with > interfaces it isn't documented _when exactly_ the reference count is > decreased. It is decreased whenever a reference expires. Where do you see chances for a different implementation?

It's mostly related to temporary variables. See the old discussions about interfaces.

Regards,
Sven

Reply by email

Marco van de Voort
to Hans-Peter Diettrich: It is decreased whenever a reference expires. Where do you see chances for a different…
Hans-Peter Diettrich wrote 6 lines
> There won't be any exact Delphi like implementation, because like with > interfaces it isn't documented _when exactly_ the reference count is > decreased. It is decreased whenever a reference expires. Where do you see chances for a different implementation?

(Some versions of?) Delphi deallocate interfaces at the end of a block of procedures, not immediately after first usage.

When FPC did, those programs broke.

Reply by email

Marcos Douglas
to Hans-Peter Diettrich: Right, and you seem to be the only one playing around with manual refcounting, and having…
Hans-Peter Diettrich wrote 14 lines
Graeme Geldenhuys schrieb: > On 2013-06-27 21:32, Hans-Peter Diettrich wrote: >> >> I don't see how this is related to managed objects. > > > If FPC implements managed objects, is it going to behave _exactly_ like > Delphi, or slightly different to Delphi - like what happened to the > Interfaces implementation. Right, and you seem to be the only one playing around with manual refcounting, and having (consequential) problems with managed objects.

Everybody that have used Interfaces in Delphi had already problems at least once.
It seems easiest to use "CORBA interfaces" instead "COM interfaces" because you have more control on your objects.

Marcos Douglas

Reply by email

waldo kitty
to Marco van de Voort: (Some versions of?) Delphi deallocate interfaces at the end of a block of procedures, not…
Marco van de Voort wrote 10 lines
On Sat, Jun 29, 2013 at 12:14:35AM +0200, Hans-Peter Diettrich wrote: >> There won't be any exact Delphi like implementation, because like with >> interfaces it isn't documented _when exactly_ the reference count is >> decreased. > > It is decreased whenever a reference expires. Where do you see chances > for a different implementation? (Some versions of?) Delphi deallocate interfaces at the end of a block of procedures, not immediately after first usage.

first usage or last usage?

When FPC did, those programs broke.

i'm just trying to follow along and get this whole new paradigm to me understood...

NOTE: No off-list assistance is given without prior approval. Please keep mailing list traffic on the list unless private contact is specifically requested and granted.

Reply by email

Marco van de Voort
to waldo kitty
waldo kitty wrote
> (Some versions of?) Delphi deallocate interfaces at the end of a block of > procedures, not immediately after first usage. first usage or last usage?

Last usage of course, sorry.

Reply by email

Hans-Peter Diettrich
to Marco van de Voort
Show quoted text 6 lines
On Sat, Jun 29, 2013 at 08:47:37PM -0400, waldo kitty wrote: >> (Some versions of?) Delphi deallocate interfaces at the end of a block of >> procedures, not immediately after first usage. > first usage or last usage? Last usage of course, sorry.

I'm somewhat confused now. When an object has an definite "last use", it should not matter when it is destroyed afterwards, sooner or later.

A problem I could imagine were a refcount dropping to zero *before* that reference is stored in another variable. E.g. in

   intfvar := intfvar;

it will be a bad idea to _Release the old reference stored in the intfvar variable while the same reference is kept in a register or stack, before assigning the new reference to the variable. This is a known aliasing problem, which must be solved properly by every compiler. I'd solve it this way (compiled code):
//tempvar added by the compiler

   tempvar := intfvar; //intfvar.AddRef
   intfvar := newvalue; //intfvar._Release; newvalue.AddRef;
   tempvar := nil; //here or on exit from the subroutine or code block

Another solution could use the property setter pattern:

   if value  newvalue then value := newvalue;

DoDi

Reply by email

Flávio Etrusco
to Marcos Douglas: On Fri, Jun 28, 2013 at 1:07 PM, Hans-Peter Diettrich Everybody that have used Interfaces…
Marcos Douglas wrote 23 lines
On Fri, Jun 28, 2013 at 1:07 PM, Hans-Peter Diettrich wrote: > Graeme Geldenhuys schrieb: > >> On 2013-06-27 21:32, Hans-Peter Diettrich wrote: >>> >>> I don't see how this is related to managed objects. >> >> >> If FPC implements managed objects, is it going to behave _exactly_ like >> Delphi, or slightly different to Delphi - like what happened to the >> Interfaces implementation. > > > Right, and you seem to be the only one playing around with manual > refcounting, and having (consequential) problems with managed objects. Everybody that have used Interfaces in Delphi had already problems at least once. It seems easiest to use "CORBA interfaces" instead "COM interfaces" because you have more control on your objects. Marcos Douglas

That's a bold statement. COM interfaces work nice and simple as long don't try to use the implicit reference-count mechanism to hack "aspects" and other stuff, and when you use TInterfacedObject avoid using using it as a normal object (unless you know what you're doing). Not to repeat myself, but I only wish there was a way TInterfacedObject (and probably a few others) replaced the default constructor to return IUnknown... Even shadowing the default constructor with a factory (class method that casts the constructor to IUnknown, declare another protected-creatively-named-constructor) would be an improvement IMHO.

-Fl?vio

Reply by email

Florian Klämpfl
to Hans-Peter Diettrich: I'm somewhat confused now. When an object has an definite "last use", it should not…
Hans-Peter Diettrich wrote 11 lines
Marco van de Voort schrieb: > On Sat, Jun 29, 2013 at 08:47:37PM -0400, waldo kitty wrote: >>> (Some versions of?) Delphi deallocate interfaces at the end of a >>> block of >>> procedures, not immediately after first usage. >> first usage or last usage? > > Last usage of course, sorry. I'm somewhat confused now. When an object has an definite "last use", it should not matter when it is destroyed afterwards, sooner or later.

It matters when people make assumptions when the a temp. interface is released. If the temp. interface is the only left reference to a class instance, this means in turn that the class is freed at different points thus resulting in different behaviour of the program if the destructor of the class has some side effect.

Reply by email

Graeme Geldenhuys
to Florian Klämpfl
Florian Kl?mpfl wrote
It matters when people make assumptions when the a temp.

Yes, people like Embarcadero themselves (even though it is not officially documented), or Embarcadero partners that ship products with Delphi (think Raize's CodeSite etc).

I seriously doubt Embarcadero will change that behaviour now - considering it has been the same for many many years, and developers and products depend on its behaviour.

But I do understand FPC's point of view - you guys only copy functionality that is documented.

Regards,
- Graeme -

Reply by email

Graeme Geldenhuys
to Hans-Peter Diettrich: I'm somewhat confused now. When an object has an definite "last use", it should not…
Hans-Peter Diettrich wrote
I'm somewhat confused now. When an object has an definite "last use", it should not matter when it is destroyed afterwards, sooner or later.

The simplest example... You have code that executes when the Interface gets destroyed. A very simple example (you can Google for exact code or more examples) is using Interfaces to change the mouse cursor to "busy", then let the Interface set the mouse cursor back to what it initially was when the Interface finally goes out of scope.

eg: [not really code - ]

procedure SomeLongProcedure;
begin
  SetBusyMouseCursor;
  // <----------------------- (2)
  ... long running code here
end;   //  <------------------ (1)

(1) is where Delphi will release the interface, and the mouse cursor will be reset. Always at the end of a code block.

(2) is where FPC will release the interface, and the mouse cursor will be reset [at the undesired place].

Like I said, this is a very simple example - but the Delphi behaviour is consistent since forever, and allows for some very nifty code (eg: debugging call stacks etc) - and without the need to define local interface variables.

Regards,
- Graeme -

Reply by email

Hans-Peter Diettrich
to Florian Klämpfl: It matters when people make assumptions when the a temp. interface is released. If the…
Show quoted text 16 lines
Am 30.06.2013 18:25, schrieb Hans-Peter Diettrich: > Marco van de Voort schrieb: >> On Sat, Jun 29, 2013 at 08:47:37PM -0400, waldo kitty wrote: >>>> (Some versions of?) Delphi deallocate interfaces at the end of a >>>> block of >>>> procedures, not immediately after first usage. >>> first usage or last usage? >> Last usage of course, sorry. > I'm somewhat confused now. When an object has an definite "last use", it > should not matter when it is destroyed afterwards, sooner or later. It matters when people make assumptions when the a temp. interface is released. If the temp. interface is the only left reference to a class instance, this means in turn that the class is freed at different points thus resulting in different behaviour of the program if the destructor of the class has some side effect.

Such coding style is asking for trouble :-(

DoDi

Reply by email

Hans-Peter Diettrich
to Graeme Geldenhuys: The simplest example... You have code that executes when the Interface gets destroyed. A…
Show quoted text 7 lines
On 2013-06-30 17:25, Hans-Peter Diettrich wrote: > I'm somewhat confused now. When an object has an definite "last use", it > should not matter when it is destroyed afterwards, sooner or later. The simplest example... You have code that executes when the Interface gets destroyed.

Such coding style is asking for trouble :-(

DoDi

Reply by email

Martin Schreiber
to Hans-Peter Diettrich
Hans-Peter Diettrich wrote 10 lines
Graeme Geldenhuys schrieb: > On 2013-06-30 17:25, Hans-Peter Diettrich wrote: >> I'm somewhat confused now. When an object has an definite "last use", it >> should not matter when it is destroyed afterwards, sooner or later. > > The simplest example... You have code that executes when the Interface > gets destroyed. Such coding style is asking for trouble :-(

Working with autodestroyed objects is asking for trouble. ;-)

Martin

Reply by email

Michael Schnell
to Florian Klämpfl: It matters when people make assumptions when the a temp. interface is released. If the…
Florian Kl?mpfl wrote
It matters when people make assumptions when the a temp.

If an interface indeed is used as an "interface" externally of the program, Destroying it might result in a crash when the external program writes something back to the interface object (because it had been provided with a pointer so a field in same) later.

(I know of something similar when a friend of mine used a call to a (converted) c library to an external system. Here a var parameter was provided that (not "obviously") provided a pointer the the external system. The actual variable was just a local variable and thus on the stack. Now the external system stored the pointer and minutes after the call had been executed it decided to save some value at that location making the pascal application crash.)

Do you think something like that could happen with ref counted objects (that unlike interfaces can't be associated with external stuff) ?

-Michael

Reply by email

Benito van der Zander
to Graeme Geldenhuys: The simplest example... You have code that executes when the Interface gets destroyed. A…

That would be much clearer to use, if Pascal had scope local variables and auto created stack objects:

begin
    var x: SetBusyMouseCursorObject;
end;

That would also make the ref-counted classes at language level unnecessary, because you could just use

       type TObjectWithRefCounting=  specialize TRefCountingObject<TObjectWithoutRefCounting>;

Benito

Graeme Geldenhuys wrote 42 lines
On 2013-06-30 17:25, Hans-Peter Diettrich wrote: > I'm somewhat confused now. When an object has an definite "last use", it > should not matter when it is destroyed afterwards, sooner or later. The simplest example... You have code that executes when the Interface gets destroyed. A very simple example (you can Google for exact code or more examples) is using Interfaces to change the mouse cursor to "busy", then let the Interface set the mouse cursor back to what it initially was when the Interface finally goes out of scope. eg: [not really code - ] procedure SomeLongProcedure; begin SetBusyMouseCursor; // <----------------------- (2) ... long running code here end; // <------------------ (1) (1) is where Delphi will release the interface, and the mouse cursor will be reset. Always at the end of a code block. (2) is where FPC will release the interface, and the mouse cursor will be reset [at the undesired place]. Like I said, this is a very simple example - but the Delphi behaviour is consistent since forever, and allows for some very nifty code (eg: debugging call stacks etc) - and without the need to define local interface variables. Regards, - Graeme - -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

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

Reply by email

Marco van de Voort
to Graeme Geldenhuys: Hardly, but maybe our advanced applications and coding has moved past your level of…
Graeme Geldenhuys wrote 6 lines
On 30/06/13 23:33, Hans-Peter Diettrich wrote: > > Such coding style is asking for trouble :-( Hardly, but maybe our advanced applications and coding has moved past your level of knowledge of the language.

No, abusing non documented features is not advanced programming nor advanced applications. On the contrary.

That doesn't make us wrong or "asking for trouble".

Then when you got into trouble, your testsuite revealed this problem immediately? Since if you didn't even know you were on thin ice, it is more a sign that this belonged into the "accidentally happened to work and I didn't even know it was wrong" rather than "a high level of knowledge of the language" :-)

Reply by email

Graeme Geldenhuys
to Marco van de Voort
Marco van de Voort wrote
Then when you got into trouble, your testsuite revealed this problem immediately?

Yes it did, and I promptly reported it to FPC. Somehow I thought [at the time] FPC was "delphi compatible", as advertised. But I quickly learned that "delphi compatible" was a term used very loosely. Neither FPC or Lazarus are very Delphi [XE to XE4] compatible at this point.

Regards,
- Graeme -

Reply by email