Difference between revisions of "User Changes Trunk"

From Lazarus wiki
Jump to navigationJump to search
(→‎Unit changes: fcl-extra)
(→‎Language changes: Abstract and Sealed classes)
Line 48: Line 48:
 
* '''Reason''': In FPC, adding an ''array of const'' parameter to a ''cdecl'' routine has the same effect as adding the ''varargs'' modifier. It means that the routine takes a C-style variable number of arguments. There is however no way in (Free) Pascal to access these arguments on the callee side. This change means that both ''varargs'' and ''array of const'' are treated consistently, since ''varargs'' routines already had to be external.
 
* '''Reason''': In FPC, adding an ''array of const'' parameter to a ''cdecl'' routine has the same effect as adding the ''varargs'' modifier. It means that the routine takes a C-style variable number of arguments. There is however no way in (Free) Pascal to access these arguments on the callee side. This change means that both ''varargs'' and ''array of const'' are treated consistently, since ''varargs'' routines already had to be external.
 
* '''Remedy''': Remove the ''cdecl'' specifier and use a Pascal-style ''array of const'', or implement the routine in C and add ''external'' to the Pascal declaration.
 
* '''Remedy''': Remove the ''cdecl'' specifier and use a Pascal-style ''array of const'', or implement the routine in C and add ''external'' to the Pascal declaration.
 +
 +
==== Abstract abd Sealed classe modifiers ====
 +
* '''Old behaviour''': It was possible to have ''abstract'' or ''sealed'' fields followed just after the ''class'' keyword.
 +
* '''New behaviour''': Compiler now understand ''abstract'' and ''sealed'' which follows the ''class'' keyword as class modifiers.
 +
* '''Example''':
 +
<delphi>
 +
{$mode objfpc}
 +
type
 +
  TSomeClass1 = class
 +
    abstract: integer;
 +
  end;
 +
 +
  TSomeClass2 = class
 +
    sealed: integer;
 +
  end;
 +
</delphi>
 +
* '''Reason''': Delphi compatibility. ''abstract'' and ''sealed'' are now the class modifiers.
 +
* '''Remedy''': Add visibility section (published, public, ...) before ''abstract'' or ''sealed'' field declaration or place that field declaration after another one.
  
 
=== Implementation changes ===
 
=== Implementation changes ===

Revision as of 15:09, 19 October 2009

About this page

Below you can find a list of intentional changes since the upcoming release branched off not yet scheduled for inclusion in a next fixes release that can change the behaviour of previously working code, along with why these changes were performed and how you can adapt your code if you are affected by them.

All systems

Usage Changes

Language changes

Passing derived classes to var- and out-parameters

  • Old behaviour: If a routine was declared with a var- or out-parameter of a certain class type, the compiler also allowed passing derived classes to this parameter.
  • New behaviour: The compile-time type of a class passed to a routine now has to match the declared parameter type exactly in case of var- and out-parameters.
  • Example:

<delphi> {$mode objfpc}

type

 ta = class
 end;
 tb = class(ta)
 end;

var

 b: tb;

procedure test(var a: ta); begin

 a:=ta.create;
 // now b contains an instance of type "ta"

end;

begin

 b:=nil;
 test(b);

end. </delphi> The compiler used to accept the above program, but now it will give an error at the call to test.

  • Reason: As the example above demonstrates, allowing this behaviour circumvents the language's type checking. This change is also Delphi-compatible.
  • Remedy: Rewrite the affected code so it that all var/out-parameters and the class types passed to them match exactly. There are ways to circumvent the type checking at the caller side by using explicit type conversions, but using such hacks is strongly discouraged since the resulting code is not type-safe.

Array of const parameters and cdecl routines

  • Old behaviour: It was possible to have non-external cdecl routines with an array of const parameter.
  • New behaviour: Cdecl routines with an array of const parameter now always must be external.
  • Reason: In FPC, adding an array of const parameter to a cdecl routine has the same effect as adding the varargs modifier. It means that the routine takes a C-style variable number of arguments. There is however no way in (Free) Pascal to access these arguments on the callee side. This change means that both varargs and array of const are treated consistently, since varargs routines already had to be external.
  • Remedy: Remove the cdecl specifier and use a Pascal-style array of const, or implement the routine in C and add external to the Pascal declaration.

Abstract abd Sealed classe modifiers

  • Old behaviour: It was possible to have abstract or sealed fields followed just after the class keyword.
  • New behaviour: Compiler now understand abstract and sealed which follows the class keyword as class modifiers.
  • Example:

<delphi> {$mode objfpc} type

 TSomeClass1 = class
    abstract: integer;
 end;
 TSomeClass2 = class
    sealed: integer;
 end;

</delphi>

  • Reason: Delphi compatibility. abstract and sealed are now the class modifiers.
  • Remedy: Add visibility section (published, public, ...) before abstract or sealed field declaration or place that field declaration after another one.

Implementation changes

Order of parameters in RTTI

  • Old behaviour: The order in which the parameter information for a function was stored in the RTTI depended on the function's calling convention. If the calling convention on i386 passed parameters from left-to-right, parameters were stored from left to right (regardless of the actual platform, which was a bug in itself), otherwise they were stored from right to left.
  • New behaviour: The parameters are always stored from left to right in the RTTI, i.e., as they appear in the source code.
  • Effect: Code parsing RTTI information for the purpose of figuring out in which order to pass the parameters will no longer work.
  • Reason: Delphi compatibility, making the information more useful for IDEs.
  • Remedy: Adjust your code so it always expects parameters to appear in the RTTI ordered from left to right. In the future, we will also add the calling convention itself to the RTTI (like Delphi), so you can use that information to reorder the parameters in case you want to use this information to call the routine.


Unit changes

unit Daemonapp switched package

  • Old behaviour: unit Daemonapp resided in package fcl-base.
  • New behaviour: unit Daemonapp resides in package fcl-extra.
  • Effect: On OSes that have a package for every directory in packages, daemonapp seems to be missing if fcl-extra is not installed.
  • Reason: Breaking dependancy cycles in the FCL, most notably on Windows.
  • Remedy: On operating systems where a package in packages/ corresponds to a separate package to install (like on Debian), an additional package corresponding to fcl-extra must be installed

All Unix-based systems