comp.lang.ada
 help / color / mirror / Atom feed
* pragmas in doubly linked lists
@ 2023-01-26 18:25 L. B.
  2023-01-27 16:16 ` Niklas Holsti
  0 siblings, 1 reply; 8+ messages in thread
From: L. B. @ 2023-01-26 18:25 UTC (permalink / raw)


Hello,

I'm having issues with cursors of doubly linked lists (erroneous memory access exceptions).
So I'm wondering whether the pragmas might solve the problems. What is the purpose of the pragmas defined in the package like

pragma Preelaborate(Doubly_Linked_Lists);
pragma Preelaborable_Initialization(List);
pragma Preelaborable_Initialization(Cursor);

What are they good for and how to use them ? Some simple examples would be very helpful. Thank you.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: pragmas in doubly linked lists
  2023-01-26 18:25 pragmas in doubly linked lists L. B.
@ 2023-01-27 16:16 ` Niklas Holsti
  2023-02-11  8:13   ` Mario Blunk
  0 siblings, 1 reply; 8+ messages in thread
From: Niklas Holsti @ 2023-01-27 16:16 UTC (permalink / raw)



On 2023-01-26 20:25, L. B. wrote:
> Hello,
> 
> I'm having issues with cursors of doubly linked lists (erroneous
> memory access exceptions).


Sounds like a rather common programming error, perhaps trying to 
dereference pointers that are null.


> So I'm wondering whether the pragmas might solve the problems.


That is very unlikely, IMO.


> What is the purpose of the pragmas defined in the package like
> 
> pragma Preelaborate(Doubly_Linked_Lists);
> pragma Preelaborable_Initialization(List);
> pragma Preelaborable_Initialization(Cursor);


They tell the Ada compiler that the named package and the named types 
will and should have very simple initialization requirements (default 
initialization, for the types). They have no (visible) effect on how the 
program executes and, AIUI, cannot be related to your memory access 
exceptions.

For more explanation, see the Ada RM, 
http://www.ada-auth.org/standards/22rm/html/RM-10-2-1.html.

If you would like help on the memory access exceptions, do describe the 
problem more in detail here, and perhaps someone can help.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: pragmas in doubly linked lists
  2023-01-27 16:16 ` Niklas Holsti
@ 2023-02-11  8:13   ` Mario Blunk
  2023-02-13  7:22     ` Emmanuel Briot
  0 siblings, 1 reply; 8+ messages in thread
From: Mario Blunk @ 2023-02-11  8:13 UTC (permalink / raw)


> If you would like help on the memory access exceptions, do describe the 
> problem more in detail here, and perhaps someone can help.

I'm thinking about writing a demo program to reproduce the problem. The actual project where the issue arises is way to complex. 

I discovered that these problems occur in connection with doubly and indefinite doubly linked lists of cursors. The lists contain not elements but cursors to the elements of different containers.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: pragmas in doubly linked lists
  2023-02-11  8:13   ` Mario Blunk
@ 2023-02-13  7:22     ` Emmanuel Briot
  2023-02-13  7:40       ` Mario Blunk
  0 siblings, 1 reply; 8+ messages in thread
From: Emmanuel Briot @ 2023-02-13  7:22 UTC (permalink / raw)


I believe the GNAT run time is still built without checks on.  So it is quite possible that you have kept around cursors which
are no longer valid (those cursors are direct access types in practice), and GNAT has no way to test that.
In general, it is very dangerous to keep cursors outside of a very local context where you know exactly what is going on.

You could use vectors, instead of lists, and keep the corresponding index around (rather than a cursor directly) for instance.
But I would try and refactor the code to avoid having a container with cursors into another container, that seems fragile.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: pragmas in doubly linked lists
  2023-02-13  7:22     ` Emmanuel Briot
@ 2023-02-13  7:40       ` Mario Blunk
  2023-02-13  7:43         ` Emmanuel Briot
  0 siblings, 1 reply; 8+ messages in thread
From: Mario Blunk @ 2023-02-13  7:40 UTC (permalink / raw)


Emmanuel Briot schrieb am Montag, 13. Februar 2023 um 08:22:13 UTC+1:
> I believe the GNAT run time is still built without checks on. So it is quite possible that you have kept around cursors which 
> are no longer valid (those cursors are direct access types in practice), and GNAT has no way to test that. 
Thanks for your reply. All the cursors in my scenario are still valid. As far as I understood from John Barnes book Ada 2005, a cursor identifies the container and the item. In my case both the items and the containers still exist. So I assumed that collecting cursors in a list should work.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: pragmas in doubly linked lists
  2023-02-13  7:40       ` Mario Blunk
@ 2023-02-13  7:43         ` Emmanuel Briot
  2023-03-29 16:46           ` Mario Blunk
  0 siblings, 1 reply; 8+ messages in thread
From: Emmanuel Briot @ 2023-02-13  7:43 UTC (permalink / raw)


On Monday, February 13, 2023 at 8:40:25 AM UTC+1, Mario Blunk wrote:
> Thanks for your reply. All the cursors in my scenario are still valid. As far as I understood from John Barnes book Ada 2005, a cursor identifies the container and the item. In my case both the items and the containers still exist. So I assumed that collecting cursors in a list should work.


Fair enough,
The next things I would try (I am on linux, not sure what works on other platforms) are:
    - valgrind to detect invalid memory access (that will immediately which cursor, if any, is accessing free memory and where that memory was freed)
    - address sanitiser (asan) which does the same but so much faster.  That requires recompiling your executable with `-fsanitizer=address` though

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: pragmas in doubly linked lists
  2023-02-13  7:43         ` Emmanuel Briot
@ 2023-03-29 16:46           ` Mario Blunk
  2023-04-19  7:17             ` Mario Blunk
  0 siblings, 1 reply; 8+ messages in thread
From: Mario Blunk @ 2023-03-29 16:46 UTC (permalink / raw)


I've put together some examples to reproduce the problem in:
https://github.com/Blunk-electronic/ada_training/tree/master/src/containers/lists/lists_of_cursors
But, everything behaves as it should.

The examples store cursors of a single list. In another example (to follow in the next days) I will use multiple lists. Then the list of cursors contains cursors of more than one list.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: pragmas in doubly linked lists
  2023-03-29 16:46           ` Mario Blunk
@ 2023-04-19  7:17             ` Mario Blunk
  0 siblings, 0 replies; 8+ messages in thread
From: Mario Blunk @ 2023-04-19  7:17 UTC (permalink / raw)


There is a demo program that reproduces a strange behavior. It could be related to the issue above. See:
https://groups.google.com/g/comp.lang.ada/c/eOtyCu7dQ_c/m/3drS5DHuBQAJ

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-04-19  7:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-26 18:25 pragmas in doubly linked lists L. B.
2023-01-27 16:16 ` Niklas Holsti
2023-02-11  8:13   ` Mario Blunk
2023-02-13  7:22     ` Emmanuel Briot
2023-02-13  7:40       ` Mario Blunk
2023-02-13  7:43         ` Emmanuel Briot
2023-03-29 16:46           ` Mario Blunk
2023-04-19  7:17             ` Mario Blunk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox