Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Ada Pure or Preelaborate or ? in Adare_net

114 views
Skip to first unread message

Daniel Norte Moraes

unread,
Dec 31, 2021, 11:13:33 AM12/31/21
to
Hi!

I and a friend created an Ada network lib where,
from the begining, we tried very hard to make It a Ada Pure.

From the examples dir, the lib worked as expected (in gcc-10.2 gcc-11.2 and gcc-12).
To our surprise, what most caught the attention of the group's friends was the fact that the lib was Ada Pure and if that was correct.

For this reason, if really 'is' pure, not pure, preelaborate or what (?), pleeeeeeaaase, we ask the group's Ada Language Lawyers to help analyze and suggest modifications if necessary.

link: https://gitlab.com/daresoft/network/adare_net/-/tree/202x
for Ada version use 2012 and or 202x.

Best Wishes and Happy New Year,
Dani.



Simon Belmont

unread,
Jan 3, 2022, 8:11:37 PM1/3/22
to
It seems to be mostly just a thin binding to a bunch of C functions, so the applicability of any Ada feature is mostly a moot point. The Ada compiler has no control or visibility into the C domain, so while on the one hand your packages are technically Pure, on the other hand the C functions can violate those "purity rules" all they want, which might be misleading to users expecting otherwise. You don't use 'Unchecked_Access either, but obviously that doesn't mean the C functions are somehow prevented from creating dangling pointers. Personally, I would have the interfaces reflect the reality of the actual behavior (which in the case of C code you don't control, is usually assume-the-worst).

-sb


Fabien Chouteau

unread,
Jan 4, 2022, 8:52:42 AM1/4/22
to
On Friday, December 31, 2021 at 5:13:33 PM UTC+1, daniel...@gmail.com wrote:
> For this reason, if really 'is' pure, not pure, preelaborate or what (?), pleeeeeeaaase, we ask the group's Ada Language Lawyers to help analyze and suggest modifications if necessary.

I recommend reading this: https://stackoverflow.com/questions/19353228/when-to-use-pragma-pure-preelaborate

If your units are declared as Pure, the compiler considers that they have no side effect and can decided to call the sub-programs only once and cache the result, or not even call the sub-program if the result is not used after.

Daniel Norte Moraes

unread,
Jan 5, 2022, 11:11:53 AM1/5/22
to
Thanks !

The C pointers are only created in c_initialize_socket.c (c_init_address() ) and data pointed copied
to an ada array, and then immediately free by c part. this is the only time there is a dynamic allocation.
We managed to make libadare_net very close to 100% static allocation!
Because this, don´t are dangling pointers.

There is still the problem of omitting the execution of subprograms by the compiler by pure packages.
would 'preelaborate' solve this?

Thanks!

Best Wishes,
Dani.

Daniel Norte Moraes

unread,
Jan 5, 2022, 11:34:00 AM1/5/22
to
Thanks!
I read the post and believe that because most variables are either streamed or aliased and imported, lib works as it should.
However, there is still the possible problem of omitting the same subprograms with the same parameters (by compiler), although in the tests this did not happen, would replacing aspect 'pure' by 'preelaborate' solve this possible problem?

Thanks!
Best Whishes,
Dani.

Randy Brukardt

unread,
Jan 5, 2022, 6:40:08 PM1/5/22
to
"Daniel Norte Moraes" <daniel...@gmail.com> wrote in message
news:378bc69a-8388-4daf...@googlegroups.com...
Yes. The permission to omit calls only applies to Pure (see 10.2.1(18/3)).
http://www.ada-auth.org/standards/2xaarm/html/AA-10-2-1.html#p18. (I gave a
reference to the Ada 2022 AARM, but this rule hasn't changed in spirit since
it was introduced in Ada 95.)

Randy.


Daniel Norte Moraes

unread,
Jan 6, 2022, 3:39:23 PM1/6/22
to
Thanks!

We will change the packages in LibAdare_Net to 'preelaborate'. :-)
and continue from here.

Thanks All,
Best Whishes,
Dani.

Enjoy!! :-)

0 new messages