❌ About FreshRSS

Reading view

There are new articles available, click to refresh the page.

How does one override an operation with classwide types?

I didn’t think it was possible, but some annotations in the annotated RM seem to indicate it is possible. I’m working with subpools and I want to create some of my own for non heap objects. The problem is that in GNAT they use heap allocation in the function Set_Pool_of_Subpool, which is a required call, so if it is possible to override this, then I would like to so I can have it avoid heap allocation.

For reference from System.Storage_Pools.Subpools:

type Subpool_Handle is access all Root_Subpool'Class;
   for Subpool_Handle'Storage_Size use 0;

function Pool_of_Subpool (Subpool : not null Subpool_Handle)
      return access Root_Storage_Pool_With_Subpools'Class;

procedure Set_Pool_of_Subpool (
      Subpool : in not null Subpool_Handle;
      To : in out Root_Storage_Pool_With_Subpools'Class)
         with Global => overriding in out Subpool;

And the RM annotation (Ada22 annotated RM 20.a/3):

Discussion: Pool_of_Subpool and Set_Pool_of_Subpool are provided by the Ada 
implementation and typically will not be overridden by the pool implementer. 

There is uses the phrasing “typically” which would imply that they could be overridden by an implementer for some cases.

The only way I could come up to override it was to create a derived type of the handle but then the compiler complains when I use “new” with the derived subpool handle type that the handle type isn’t the standard one, so I don’t think that is what the discussion point was referring to (as it would be pointless to override in this way).

To my knowledge you can’t override operations with classwide types. Anyone have any insight into this?

Subpools reference: Storage Subpools

1 post - 1 participant

Read full topic

Running RecordFlux

I’m writing a protocol parser and would like to use RecordFlux to generate a parser from a specification. I’ve been unable to get any recent version of RecordFlux working with the GNAT toolchain from Alire. The wheel on pypi expects a GNAT Studio install with gnatcoll in the path and compiling from source seems to require and even deeper tree of manually built dependencies.

I’m begging anyone at AdaCore to write an alire.toml file.

1 post - 1 participant

Read full topic

Exceptional_Cases aspect

Hello,

I would like to use the Exceptional_Cases aspect described in this post. However, it seems that the latest version of GNATprove (13.2.1) available on Alire does not include the feature. Does anyone know if there is any community version of GNATprove that supports it?

Thank you,
Daniel

2 posts - 2 participants

Read full topic

Question about vector initialization

Yesterday, I was trying to do something with an array of vectors and stumbled a bit. So I’d like to ask some clarification questions about initialization…

With arrays (as with most other types), a variable is uninitialized until it’s explicitly set to a value.

My_List : array (1 .. 10) of Boolean;   -- uninitialized
My_List := [1 => True, other => False];

With vectors it’s slightly different. The reference manual says:

If an object of type Vector is not otherwise initialized, it is initialized to the same value as Empty_Vector.

So if I have:

package Boolean_Vectors is Ada.Containers.Vectors (
  Index_Type   => Positive,
  Element_Type => Boolean
);

subtype Boolean_Vector is Boolean_Vectors.Vector;

I can actually do:

My_Vector : Boolean_Vector; -- Implicitly initialized here?
My_Vector.Append (True);    -- Or here?
My_Vector.Append (False);

Although I’m not sure when exactly initialization happens (and why it was designed to happen implicitly).

Now, Empty_Vector is a constant, so I cannot use it if I want to initialize an empty vector explicitly.
So, what do I do when I want to have an array of vectors?

My_Vector_List : array (1 .. 10) of Boolean_Vector;
My_Vector_List := [others => ??]; -- How do I put an empty vector here
                                  -- that can grow later?

Or do I have to do it like this?

My_Vector_1, My_Vector_2 : Boolean_Vector;

My_Vector_List (1) := My_Vector_1;
My_Vector_List (2) := My_Vector_2;
...

9 posts - 7 participants

Read full topic

VSCode + GtkAda problem

Hi!
After a long break I started learning Ada again…
Under Windows 10 using Alire + VSCode I tried to compile a gtkada test program.
From the command line the usual “alr build” and “alr run” works, the test program builds and runs without errors.
Under VSCode the build is started with the following command:
alr exec -- gprbuild -P gtkada_test.gpr -cargs -gnatef

The “-gnatef” option seems to cause problems when compiling misc_generated.c:

Translated with DeepL.com (free version)
Compile
   [C]            misc_generated.c
cc1.exe: error: unrecognized debug output level 'natef'
gprbuild: *** compilation phase failed
ERROR: Command ["gprbuild", "-P", "gtkada_test.gpr", "-cargs", "-gnatef"] exited with code 4
ERROR: Command ["alr", "exec", "--", "gprbuild", "-P", "gtkada_test.gpr", "-cargs", "-gnatef"] exited with code 1

 *  The terminal process "C:\Program Files\PowerShell\7\pwsh.exe -Command alr exec -- alr exec -- gprbuild -P gtkada_test.gpr -cargs -gnatef" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it.

Unfortunately I don’t know how to make gcc not get the “-gnatef” option when compiling misc_generated.c.
Or maybe the problem is completely different?
I haven’t gone that deep into the depths of gprbuild yet… :slight_smile:
Thanks in advance for any help!

6 posts - 3 participants

Read full topic

AArch64 cross toolchain

The community has long expressed interest in supporting Ada on ARM64 and Apple Silicon platforms. Unfortunately, GitHub Action Runners are not available for ARM for open-source projects. The publication of the Ada extension for VS Code (as well as Alire) relies on GitHub Actions, limiting ARM support. However, it turns out that creating an ARM version is still possible, and I’d like to share my experience with using cross-compilers for this purpose.

Through the actions described below, I managed to obtain two cross-compilers for the aarch64 CPU (running on x86_64), one for Linux and the other for macOS. These proved sufficient to build ALS and VSCode extensions for these platforms.

I began by building the Ada Language Server version for ARM64/Linux since this platform is more familiar to me. Ubuntu provides cross-versions of dependencies for GNAT (glibc, binutils). Ubuntu even has GNAT GCC 13, but on newer versions than the one (20.04) we use for ALS building. The first thing I did was attempt to rebuild GCC 13 on Ubuntu 20.04 from the source package of the latest Ubuntu distribution (23.10). Although this might be the most correct method from a reuse perspective, it didn’t suit me - too many packages and installation steps.

Building GNAT from the GCC 13 source texts proved much simpler. The resulting script was just a dozen lines long.

If you unpack the resulting archive in /, gprbuild finds the cross-compiler and using it subsequently is straightforward: you just need to specify the option --target=aarch64-linux.

Mac OS also provides cross-versions of binutils and libc, which come with the standard installation of Xcode Command Line Tools. For example, /usr/bin/as can create object files for both x86_64 and aarch64, depending on the --target. Therefore, we only need to build GNAT using the GCC sources from the repository iains/gcc-13-branch.

If you need binaries for these cross-compilers or have ideas on how to use them, please leave a comment in this thread.

PS Thanks to Simon Wright for experimenting with Mac OS and providing advices.

2 posts - 2 participants

Read full topic

Is there a good way to handle exceptioins in the declarative region of a function

While working on day 6 of AoC, I found myself breaking a larger calculation into parts and saving them as constants in the declarative region of the function. This was super clean for reading and let me document all my steps nicely. I also knew that if any of the steps failed, then my result should be 0. So I figured I would put an exception handler in the function and return 0 (Note that the case where exceptions happen would be pretty rare based on some really edge case inputs that weren’t practical to the problem):

The problem I ran into is if the early steps raised an exception, then the exception handler wouldn’t catch them as they were in the declarative region. See mock up below:

function Calculate(Inputs : Input_Type) return Integer is
   Step_1 : constant Integer := Some_Function(Stuff);
   Step_2 : constant Integer := Some_Other_Function(Stuff);
begin
   return Final_Function(Step_1, Step_2);
exception
   when others => return 0;  -- doesn't catch Step_1 or Step_2 exceptions!!!
end Calculate;

Any suggestions on a clean way to catch those declarative exceptions? I don’t like putting them in a declare block in the function body because that just indents everything needlessly. Currently I renamed my original function to old_name_unhandled and call it a new wrapper function named the original name, but that does feel kinda silly.

I was hoping there is an aspect or pragma maybe?

6 posts - 5 participants

Read full topic

Volatile records containing an array

svd2ada generates volatile arrays.

e.g. IMR_MR_Field_Array

There are two other options that I believe will work easily with spark. The .Val Hal.UInt32 or a record of booleans with different names instead of the array.

The array makes for simpler code. So before I switch to the value. Could anyone suggest how the Spark compatibility error may be avoided. Editing the svds isn’t ideal but possible. A function or procedure local instantiation would be ideal. Any ideas?

IMR1.MR.Arr(Var) := True;

error: volatile object cannot appear in this context. Spark RM 7.1.3 (10).

Thanks

2 posts - 1 participant

Read full topic

AdaCV - OpenCV but Ada

Hi everyone,

I’ve been a long time lurker on the Ada subreddit and was directed here by Lucretia to share my plan/idea. After a few years in Python and short, unhappy tread through the chaos of C++, I’m learning Ada, while I’m still new to the language, I have a project idea. I want to make sure I don’t reinvent the wheel and that I engage with anyone else who is interested.

Are you familiar with OpenCV? If not, it’s a very good computer vision library in C++ and Python.

Well I have a several years experience with it in both C++ and Python (and the science/math directly). My interpretation is that, while the basics can be easy to use, the more complicated functions (Stereo Calibration, triangulation, really anything with photogrammetry) are nuanced and somewhat unforgiving. A lot of it is driven by poor examples and the poor documentation on what you’re actually getting. For example, it doesn’t talk about what units is a particular return value is in? Distance units or a some normalized unit? What’s expected as the input? A vector of vectors of a custom cv::Point2f two dimension float type. Stack overflow is filled with questions where people don’t get much help and their answers are met more with theory photogrammetry and I never see actual usage help or answers. It’s just like the documentation: theory heavy, usage thin, typing vague. A more… user friendly library with thorough usage documentation would be very popular if it was genuinely easy to use.

I’m sure you see where this is going but please let me finish:

Ada is the language of reliability and safety. Look at the popular and booming Tech industries, two relevant highlights are Autonomous Vehicles and Augmented Reality. Both use imaging processing and photogrammetric techniques. If an ADA based package or library that was easily usable and accurate, while having the reliability and safety of ADA, it could bring a lot of new people, companies, and industries to the language.

So anyways, the idea is AdaCV. A potentially slimmer but more easily usable and user friendly OpenCV in Ada.

Anyone working on that? Anyone finished it? Thoughts? Objections?

7 posts - 4 participants

Read full topic

Elaboration circularity detected

Hi, I am new in this forum.
I have a problem porting ada code from Red Hat 8 (gnat 8.5.0) to Red Hat 9 (gnat 11.3.1).
The linking phase on RHEL9 fails for “Elaboration circularity detected”.
I let the ada compiler to choose the module compilation order using the following instruction:
gnatmake -c
The reason is: “unit depends on its own elaboration”
The circularity detected is: "unit invokes a construct of unit at elaboration time.
What shall I do to find the exact location of the problem?
And why this problem was not detected before using other gnat versions?
Thanks a lot

7 posts - 4 participants

Read full topic

Possible compiler bug?

I have some code that is running fine for me at home using gnat/gcc 12.2. I decided to test it out on various versions of gnat, so I fired up godbolt and tried a few. I found that starting with version 13, my code throws an exception when the program ends:

raised PROGRAM_ERROR : example.adb:4 finalize/adjust raised exception

I wanted to double check and make sure I am not doing anything illegal and 13 catches it vs 13 just having a bug. I had to make a kinda convoluted example since the original code was from a much larger code base, so apologies if the generic formals and code don’t look too practical. I spent a few hours whittling it down from the original. Full code on godbolt is here:

Code is below:

example.adb:

with Ada.Text_IO; use Ada.Text_IO;
with Test;

procedure Example is

    package B is 
        type Instance is limited interface;
        function Make return Instance is abstract;
    end B;

    package C is
        type Instance is new B.Instance with null record;
        function Make return Instance is (null record);
    end C; use C;

    package T is new Test(B.Instance, C.Instance, C.Make);

    Thing : B.Instance'Class := T.Make(2);

begin
    Put_Line("Hello World");
end Example;

test.ads:

generic
    type First(<>) is abstract tagged limited private;
    type Second(<>) is new First with private;
    with function Make return Second is <>;
package Test is

    function Make(Key : Integer) return First'Class;

private

    type Some_Access is not null access function return First'Class;

    function Make_Delegate return First'Class;

    Thing_Access : constant Some_Access := Make_Delegate'Access;

end Test;

test.adb:

with Ada.Containers.Indefinite_Ordered_Maps;

package body Test is

    package Maps is new Ada.Containers.Indefinite_Ordered_Maps
        (Key_Type     => Integer,
         Element_Type => Some_Access);

    Map : Maps.Map;

    function Make(Key : Integer) return First'Class is
    begin
        return Map(Key).all;
    end Make;

    function Make_Delegate return First'Class is
    begin
        return Make;
    end Make_Delegate;

begin
    Map.Insert(2,Thing_Access);
end Test;

It’s essentially a map of function pointers (only one in this example). I had to use a wrapper function (Make_Delegate) in order to have correct accessibility to it within the generic.

10 posts - 3 participants

Read full topic

Gnatd.v elaboration

I wonder. Is gnatd.v a better option than
pragma preelaborate

Is preelaborate more compiler portable? Though I do not use the features that it protects against such as dynamic dispatch, so it is simply an unneeded restriction for me with Gnat. However gnatd.v seems to offer more such as in regard to uninitialised variables? Assuming it works as I had no compile issues :joy:.

see 7.7

https://docs.adacore.com/spark2014-docs/html/lrm/packages.html

2 posts - 2 participants

Read full topic

❌