Sign in Join

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

Mailing lists / lazarus / 2018-04

Runtime error: INCLOCKED

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

Valdas Jankūnas

Hello,

I'm stuck. I always getting weird error when executing this code (stripped down to minimum):

program project1;
type
   TElement = record
       strr: String;
   end;
   TList = array of TElement;
   Plist = ^TList;
   TSetting = record
       list: Plist;
   end;
const
   _List: array [0..1] of TElement = (
       (strr: 'a'),
       (strr: 'b'));
   _Settings: array [0..0] of TSetting = (
       (list: @_List));
procedure Display(a: TList);
begin // <-------------------------------- line 23
     writeln(' +++  ', a[0].strr);
end;
var
   setting: TSetting;
begin
     setting := _Settings[0];
writeln(' ----  ', Assigned(setting.list), '  ', Length(setting.list^));
     Display(setting.list^);
end.

In console I get:

---- TRUE 2
Runtime error 216 at $0000000000400BD5
$0000000000400BD5 INCLOCKED
$0000000000400216 DISPLAY, line 23 of project1.lpr $0000000000400360 main, line 32 of project1.lpr
$000000000042BE00 SYSENTRY, line 129 of system.pp $00000000004001D2

Why I getting that error? Something wrong with records and constant initialization?

My system is: Linux 4.13.0-39-generic #44-Ubuntu SMP Thu Apr 5 14:25:01 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux FPC (from SVN): 3.1.1 [2018/02/21] for x86_64

Valdas Jankūnas

Reply by email

Vojtěch Čihák

Hi,
 
I changed line 7:
 
TElement = record
      strr: String;
  end;
  TList = array[0..1] of TElement;  //HERE
  Plist = ^TList;   
 
and demo works. Simply, static and dynamic arrays are not the same. AFAIR, dynamic array is just pointer while static array are data. I guess someone else will give you more detailed answer.  
V.
______________________________________________________________

Show quoted text 5 lines
Od: Valdas Jankūnas via Lazarus Komu: Datum: 29.04.2018 18:16 Předmět: [Lazarus] Runtime error: INCLOCKED
 type
   TElement = record
       strr: String;
   end;
   TList = array of TElement;
   Plist = ^TList;
 .....

Why I getting that error? Something wrong with records and constant initialization?

My system is: Linux 4.13.0-39-generic #44-Ubuntu SMP Thu Apr 5 14:25:01 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux FPC (from SVN): 3.1.1 [2018/02/21] for x86_64

  Valdas Jankūnas --

Reply by email

Santiago A.
to Vojtěch Čihák
Vojtěch Čihák wrote 27 lines
Hi,   I changed line 7:   TElement = record       strr: String;   end;   TList = array[0..1] of TElement;  //HERE   Plist = ^TList;      and demo works. Simply, static and dynamic arrays are not the same. AFAIR, dynamic array is just pointer while static array are data. I guess someone else will give you more detailed answer.

Yes, but I think that it should be considered a FPC bug

  TList = array of TElement;
  Plist = ^TList;
  TSetting = record
      list: Plist;
  end;
const
  _List: array [0..1] of TElement = (
      (strr: 'a'),
      (strr: 'b'));

  _Settings: array [0..0] of TSetting = ( 
      (list: @_List)); //  <=== This line should rise a compiler error. You are asigning a pointer to an static array to a pointer to a dynamic array.

-------------------
You could add a type cast of the pointer to Plist

  _Settings: array [0..0] of TSetting = ( 
      (list: Plist(@_List) ));

You explicitly tell the complier to bypass type check, it is up to deal with this potential dangerous

Show quoted text 35 lines
  V. ______________________________________________________________ > Od: Valdas Jankūnas via Lazarus > Komu: > Datum: 29.04.2018 18:16 > Předmět: [Lazarus] Runtime error: INCLOCKED > type   TElement = record       strr: String;   end;   TList = array of TElement;   Plist = ^TList; ..... Why I getting that error? Something wrong with records and constant initialization? My system is: Linux 4.13.0-39-generic #44-Ubuntu SMP Thu Apr 5 14:25:01 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux FPC (from SVN): 3.1.1 [2018/02/21] for x86_64 --   Valdas Jankūnas -- _______________________________________________ Lazarus mailing list https://lists.lazarus-ide.org/listinfo/lazarus
Saludos Santiago A. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20180511/6c3c22da/attachment.html>

Reply by email

Valdas Jankūnas
to Santiago A.

2018-05-11 12:36, Santiago A. via Lazarus rašė:

Show quoted text 18 lines
Yes, but I think that it should be considered a FPC bug   TList = array of TElement;   Plist = ^TList;   TSetting = record       list: Plist;   end; const   _List: array [0..1] of TElement = (       (strr: 'a'),       (strr: 'b'));   _Settings: array [0..0] of TSetting = (       (list: @_List)); //  <=== This line should rise a compiler error. You are asigning a pointer to an static array to a pointer to a dynamic array.

Reported: https://bugs.freepascal.org/view.php?id=33757

Valdas Jankūnas

Reply by email