• pragmas in doubly linked lists

    From L. B.@21:1/5 to All on Thu Jan 26 10:25:04 2023
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Niklas Holsti@21:1/5 to L. B. on Fri Jan 27 18:16:18 2023
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mario Blunk@21:1/5 to All on Sat Feb 11 00:13:25 2023
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Emmanuel Briot@21:1/5 to Mario Blunk on Sun Feb 12 23:43:08 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Emmanuel Briot@21:1/5 to All on Sun Feb 12 23:22:10 2023
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mario Blunk@21:1/5 to Emmanuel Briot on Sun Feb 12 23:40:23 2023
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mario Blunk@21:1/5 to All on Wed Mar 29 09:46:39 2023
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mario Blunk@21:1/5 to All on Wed Apr 19 00:17:22 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)