comp.lang.ada
 help / color / mirror / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* Re: fyi, GNAT and SPARK GPL 2016 are out
  @ 2016-06-04 16:13  6% ` gautier_niouzes
  0 siblings, 0 replies; 9+ results
From: gautier_niouzes @ 2016-06-04 16:13 UTC (permalink / raw)


Nice release - with new optimizations in the run-time library... and a nice banana skin. In some cases, an application working well with GNAT for years may crash with a nasty raised PROGRAM_ERROR : EXCEPTION_ACCESS_VIOLATION - but only in a typical release mode; in a typical debug mode it works as before.

In a nutshell, if you are using Ada.Containers.*Maps, and have code like the P_KO procedure below, which is legal Ada 2005 & 2012, the executable will bomb when built with the -gnatp switch.

The cure is to use a cursor like in P_OK. It removes an exception part as well.

Is there an inclusion of pragma Suppress(Container_Checks) into the standard on its way ? Then the remarks such as A.18.4, 69/2 could be updated accordingly.
_________________________ 
Gautier's Ada programming 
http://gautiersblog.blogspot.com/search/label/Ada 
NB: follow the above link for a valid e-mail address 

-----------8<-----------8<-----------8<-----------8<-------

--  GNAT GPL 2016 pragma, suppression included in -gnatp switch
pragma Suppress(Container_Checks); 

with Ada.Strings.Unbounded.Hash;             use Ada.Strings.Unbounded;
with Ada.Containers.Hashed_Maps;
with Ada.Text_IO; use Ada.Text_IO;

procedure Test_2016 is

  package T_Dic is new Ada.Containers.Hashed_Maps
    (Key_Type        => Ada.Strings.Unbounded.Unbounded_String,
     Element_Type    => Positive,
     Hash            => Ada.Strings.Unbounded.Hash,
     Equivalent_Keys => Ada.Strings.Unbounded."=");
  
  dic: T_Dic.Map;
  n: Positive:= 1;
  
  procedure P_KO(s: String) is
    i: Integer;
  begin
    i:= dic.Element(To_Unbounded_String(s));
    Put_Line("Key found, element=" & Integer'Image(i));
  exception
    when Constraint_Error =>  --  A.18.4, 69/2
      Put_Line("Key not found");
      dic.Insert(To_Unbounded_String(s), n);
      n:= n + 1;
  end P_KO;
  
  procedure P_OK(s: String) is
    i: Integer;
    use T_Dic;
    curs: Cursor;
  begin
    curs:= dic.Find(To_Unbounded_String(s));
    if curs = No_Element then
      Put_Line("Key not found");
      dic.Insert(To_Unbounded_String(s), n);
      n:= n + 1;
    else
      i:= Element(curs);
      Put_Line("Key found, element=" & Integer'Image(i));
    end if;
  end P_OK;

begin
  P_OK("A");
  P_OK("A");
  P_KO("B");
  P_KO("B");
end;

^ permalink raw reply	[relevance 6%]

* Re: Using the Hash function
  2011-07-22  6:33  0% ` Stephen Leake
@ 2011-07-22  8:29  0%   ` iloAda
  0 siblings, 0 replies; 9+ results
From: iloAda @ 2011-07-22  8:29 UTC (permalink / raw)


On Jul 22, 8:33 am, Stephen Leake <stephen_le...@stephe-leake.org>
wrote:
> iloAda <egzgh...@gmail.com> writes:
> > Hello everybody!!
>
> > I am trying to use the hash function of the Unbounded_Strings package!
>
> > Here's the code (very simple):
>
> > 1   function Unbounded_String_Hash
> > 2    (U_Str : Ada.Strings.Unbounded.Unbounded_String)
> > 3      return Ada.Containers.Hash_Type
> > 4   is
> > 5
> > 6   begin
> > 7
> > 8    return Ada.Strings.Unbounded.Hash (U_Str);
> > 9   end Unbounded_String_Hash;
>
> > I is giving me the following error on line 8 when I try to compile:
> > missing "with Unbounded.Hash";
>
> > Can anybody tell me what's going on (knowing that Unbounded.Hash isn(t
> > an existing package)!!
>
> It isn't a package, it's a function. But it is declared at library
> level, as a separate compilation unit. So it needs a 'with' clause.
>
> --
> -- Stephe

Ok....thanks guys!!



^ permalink raw reply	[relevance 0%]

* Re: Using the Hash function
  2011-07-21 14:40  6% Using the Hash function iloAda
  2011-07-21 14:57  5% ` Simon Wright
@ 2011-07-22  6:33  0% ` Stephen Leake
  2011-07-22  8:29  0%   ` iloAda
  1 sibling, 1 reply; 9+ results
From: Stephen Leake @ 2011-07-22  6:33 UTC (permalink / raw)


iloAda <egzgheib@gmail.com> writes:

> Hello everybody!!
>
> I am trying to use the hash function of the Unbounded_Strings package!
>
> Here's the code (very simple):
>
> 1   function Unbounded_String_Hash
> 2    (U_Str : Ada.Strings.Unbounded.Unbounded_String)
> 3      return Ada.Containers.Hash_Type
> 4   is
> 5
> 6   begin
> 7
> 8    return Ada.Strings.Unbounded.Hash (U_Str);
> 9   end Unbounded_String_Hash;
>
> I is giving me the following error on line 8 when I try to compile:
> missing "with Unbounded.Hash";
>
>
> Can anybody tell me what's going on (knowing that Unbounded.Hash isn(t
> an existing package)!!

It isn't a package, it's a function. But it is declared at library
level, as a separate compilation unit. So it needs a 'with' clause.

-- 
-- Stephe



^ permalink raw reply	[relevance 0%]

* Re: Using the Hash function
  2011-07-21 14:40  6% Using the Hash function iloAda
@ 2011-07-21 14:57  5% ` Simon Wright
  2011-07-22  6:33  0% ` Stephen Leake
  1 sibling, 0 replies; 9+ results
From: Simon Wright @ 2011-07-21 14:57 UTC (permalink / raw)


iloAda <egzgheib@gmail.com> writes:

> Hello everybody!!
>
> I am trying to use the hash function of the Unbounded_Strings package!
>
> Here's the code (very simple):
>
> 1   function Unbounded_String_Hash
> 2    (U_Str : Ada.Strings.Unbounded.Unbounded_String)
> 3      return Ada.Containers.Hash_Type
> 4   is
> 5
> 6   begin
> 7
> 8    return Ada.Strings.Unbounded.Hash (U_Str);
> 9   end Unbounded_String_Hash;
>
> I is giving me the following error on line 8 when I try to compile:
> missing "with Unbounded.Hash";
>
>
> Can anybody tell me what's going on (knowing that Unbounded.Hash isn(t
> an existing package)!!
>
> Thanks
>
> Elie

You need to say

   with Ada.Strings.Unbounded.Hash;

as well as Ada.Containers.



^ permalink raw reply	[relevance 5%]

* Using the Hash function
@ 2011-07-21 14:40  6% iloAda
  2011-07-21 14:57  5% ` Simon Wright
  2011-07-22  6:33  0% ` Stephen Leake
  0 siblings, 2 replies; 9+ results
From: iloAda @ 2011-07-21 14:40 UTC (permalink / raw)


Hello everybody!!

I am trying to use the hash function of the Unbounded_Strings package!

Here's the code (very simple):

1   function Unbounded_String_Hash
2    (U_Str : Ada.Strings.Unbounded.Unbounded_String)
3      return Ada.Containers.Hash_Type
4   is
5
6   begin
7
8    return Ada.Strings.Unbounded.Hash (U_Str);
9   end Unbounded_String_Hash;

I is giving me the following error on line 8 when I try to compile:
missing "with Unbounded.Hash";


Can anybody tell me what's going on (knowing that Unbounded.Hash isn(t
an existing package)!!

Thanks

Elie



^ permalink raw reply	[relevance 6%]

* Bug in GCC ?
@ 2008-05-19 15:50  6% Sébastien
  0 siblings, 0 replies; 9+ results
From: Sébastien @ 2008-05-19 15:50 UTC (permalink / raw)


He is the sample code I'm trying to compile:

with Ada.Containers.Hashed_Maps;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Strings.Unbounded.Hash;

package SCMAL.Tools.HashedMaps is

     package HashedStrStr is
         new Ada.Containers.Hashed_Maps(
         Key_Type => Unbounded_String,
         Element_Type => Unbounded_String,
         Hash => Ada.Strings.Unbounded.Hash,
         Equivalent_Keys => "=");

end SCMAL.Tools.HashedMaps;


At compile time:

$ gnatmake -Pgentest -cargs -gnatn
gcc-4.1 -c -gnat05 -g3 -O2 -gnatn -I- -gnatA 
/var/local/mscm/ada/tests/generic/scmal-tools-hashedmaps.ads
+===========================GNAT BUG DETECTED==============================+
| 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu3) 
(i486-pc-linux-gnu) GCC error:|
| in referenced_var_lookup, at tree-dfa.c:578                              |
| No source file position information available                            |
| Please submit a bug report; see http://gcc.gnu.org/bugs.html.            |
| Use a subject line meaningful to you and us to track the bug.            |
| Include the entire contents of this bug box in the report.               |
| Include the exact gcc-4.1 or gnatmake command that you entered.          |
| Also include sources listed below in gnatchop format                     |
| (concatenated together with no headers between files).                   |
+==========================================================================+

It works fine if I remove the -gnatn and -O2

Sebastien



^ permalink raw reply	[relevance 6%]

* Re: Dynamic allocation of named arrays
  2008-04-29 20:14  6% ` Gautier
@ 2008-04-29 20:59  7%   ` Gautier
  0 siblings, 0 replies; 9+ results
From: Gautier @ 2008-04-29 20:59 UTC (permalink / raw)


Mmmmh - always better to test examples before posting...
This one is working:

-----8<-----------8<-----------8<-----------8<------

with Ada.Containers.Hashed_Maps;
with Ada.Strings.Unbounded.Hash;
with Ada.Text_IO;

procedure Dummy_dico is

   package Dictionaries is new Ada.Containers.Hashed_Maps
             (Ada.Strings.Unbounded.Unbounded_String,
              Ada.Strings.Unbounded.Unbounded_String,
              Ada.Strings.Unbounded.Hash,
              Ada.Strings.Unbounded."=",
              Ada.Strings.Unbounded."=");

   use Dictionaries;

   function "-" (Source : Ada.Strings.Unbounded.Unbounded_String) return String
     renames Ada.Strings.Unbounded.To_String;
   function "+" (Source : String) return Ada.Strings.Unbounded.Unbounded_String
     renames Ada.Strings.Unbounded.To_Unbounded_String;

   procedure Translate( dico: Map; from: String ) is
     use Ada.Text_IO;
   begin
     Put_Line( from & " ---> " & (-Element(dico,+from)) );
   end Translate;

   dico_F_to_E: Map;
   c: Cursor;
   s: Boolean;

begin
   Insert(dico_F_to_E, +"souris", +"mouse", c, s);
   Insert(dico_F_to_E, +"chat",   +"cat",   c, s);
   Insert(dico_F_to_E, +"chien",  +"dog",   c, s);
   Insert(dico_F_to_E, +"cheval", +"horse", c, s);
   --
   Translate(dico_F_to_E, "chien");
   Translate(dico_F_to_E, "chat");
end;



^ permalink raw reply	[relevance 7%]

* Re: Dynamic allocation of named arrays
  @ 2008-04-29 20:14  6% ` Gautier
  2008-04-29 20:59  7%   ` Gautier
  0 siblings, 1 reply; 9+ results
From: Gautier @ 2008-04-29 20:14 UTC (permalink / raw)


Kim Rostgaard Christensen wrote:

> Hello
> 
> I need an array that has both variable length key and value (strings)
> that is dynamically allocated at run-time.
> 
> I have looked at ada05's "Containers.Hashed_maps" but am missing a good
> example on usage

with Ada.Strings.Unbounded.Hash;
...

   package Dictionaries is new Ada.Containers.Hashed_Maps
             (Ada.Strings.Unbounded.Unbounded_String,
              Ada.Strings.Unbounded.Unbounded_String,
              Ada.Strings.Unbounded.Hash,
              equivalent_keys => Ada.Strings.Unbounded."=");

For a full example, search "Texture_Name_Mapping" in:

http://globe3d.svn.sourceforge.net/viewvc/globe3d/src/globe_3d-textures.adb?revision=78&view=markup

 > , and would like to use something more portable.

Well, how can it be more portable ?!...
Do you mean with some Ada 95 compilers ?
______________________________________________________________
Gautier         -- http://www.mysunrise.ch/users/gdm/index.htm
Ada programming -- http://www.mysunrise.ch/users/gdm/gsoft.htm

NB: For a direct answer, e-mail address on the Web site!



^ permalink raw reply	[relevance 6%]

* Re: OO Style with Ada Containers
  @ 2007-11-15  9:36  6%       ` Ludovic Brenta
  0 siblings, 0 replies; 9+ results
From: Ludovic Brenta @ 2007-11-15  9:36 UTC (permalink / raw)


braver <deliverable@gmail.com> writes:
> my sample application [...] gets a Vector of tokens and inserts them
> into an Ordered_Map to count word occurrences:

I don't think you need to store all the tokens.  All you need is a
Hashed_Set (which stores objects without duplication).  I would do
something like

   type Word_Counter is
      Word : Ada.Strings.Unbounded.Unbounded_String;
      Count : Natural;
   end Word_Counter;

   function Equivalent (L, R: Word_Counter) is
      use type Ada.Strings.Unbounded.Unbounded_String;
   begin
      return L.Word = R.Word; -- ignore Count in the comparison
   end Equivalent;

   function Hash (Element : Word_Counter) is
   begin
      return Ada.Strings.Unbounded.Hash (Element.Word);
   end Hash;

   package Word_Counter_Hashed_Sets is
     new Ada.Containers.Hadhed_Sets
       (Element_Type => Word_Counter,
        Hash => Hash,
        Equivalent_Elements => Equivalent);

   Counters : Word_Counter_Hashed_Sets.Set;
   Current_Word : Ada.Strings.Unbounded.Unbounded_String;
   Position : Word_Counter_Hashed_Sets.Cursor;
   use type Word_Counter_Hashed_Sets.Cursor;
begin
   ...
   Current_Word := Get_Next_Word;
   Position := Counters.Find (Current_Word);
   if Position = Word_Counter_Hashed_Sets.No_Element then
      Counters.Insert (New_Item => (Word => Current_Word, Count => 1));
   else
      declare
         E : constant Word_Counter := Counters.Element (Position);
      begin
         Counters.Replace_Element
            (Position => Position,
             New_Item => (Word => E.Word, -- [1]
                          Counter => E.Counter + 1));
      end;
   end if;
   ...
end;

(does [1] duplicate E.Word each time we increment the counter?  If so,
consider using
Ada.Containers.Hashed_Sets.Generic_Keys.Update_Element_Preserving_Keys).

> -- would need to import "=" for private type WC.Cursor:
> -- if Ngram_Cursor = WC.No_Element

declare
   use type WC.Cursor;
begin
   if Ngram_Cursor = WC.No_Element then

> I'd appreciate any improvements to the above, which I deduced from ARM

HTH

-- 
Ludovic Brenta.




^ permalink raw reply	[relevance 6%]

Results 1-9 of 9 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2007-11-14 23:28     OO Style with Ada Containers braver
2007-11-14 23:50     ` Adam Beneschan
2007-11-14 23:59       ` braver
2007-11-15  0:24         ` braver
2007-11-15  9:36  6%       ` Ludovic Brenta
2008-04-29  9:12     Dynamic allocation of named arrays Kim Rostgaard Christensen
2008-04-29 20:14  6% ` Gautier
2008-04-29 20:59  7%   ` Gautier
2008-05-19 15:50  6% Bug in GCC ? Sébastien
2011-07-21 14:40  6% Using the Hash function iloAda
2011-07-21 14:57  5% ` Simon Wright
2011-07-22  6:33  0% ` Stephen Leake
2011-07-22  8:29  0%   ` iloAda
2016-06-01 13:33     fyi, GNAT and SPARK GPL 2016 are out Nasser M. Abbasi
2016-06-04 16:13  6% ` gautier_niouzes

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