comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: Can anyone help with GNAT.Perfect_Hash_Generators ? (Possible memory corruption)
Date: Tue, 06 Sep 2016 22:04:43 +0100
Date: 2016-09-06T22:04:43+01:00	[thread overview]
Message-ID: <lyoa40rb84.fsf@pushface.org> (raw)
In-Reply-To: 877fao24da.fsf@mid.deneb.enyo.de

Florian Weimer <fw@deneb.enyo.de> writes:

> * Natasha Kerensikova:

(BTW, phg4 failed badly with "too many tries" or some such)

>> So at this my conclusion is that GNAT.Perfect_Hash_Generators somehow
>> works fine with 1-based string, but has trouble dealing with strings
>> with larger indices.
>
> Yes, that's reasonable to assume.  It's a relatively common source of
> bugs in Ada library code.
>
> One way to pin-point this further is to makea copy of the
> g-pehage.ads, g-pehage.adb files, rename the package, and compile it
> as part of your project, so that the usual Ada checks aren't
> eliminated.

Yes. With phg2, under gdb, macOS, GNAT GPL 2016,

Catchpoint 1, CONSTRAINT_ERROR (perfect_hash_generators.adb:2268 index check failed) at 0x000000010000e03e in perfect_hash_generators.select_char_position.count_different_keys (
    table=..., last=1, pos=1) at perfect_hash_generators.adb:2268
2268	               C := WT.Table (Reduced (K))(Pos);
(gdb) l
2263	
2264	            --  Count the occurrences of the different characters
2265	
2266	            N := (others => 0);
2267	            for K in Table (S).First .. Table (S).Last loop
2268	               C := WT.Table (Reduced (K))(Pos);
2269	               N (C) := N (C) + 1;
2270	            end loop;
2271	
2272	            --  Update the number of different keys. Each character used
(gdb) bt
#0  <__gnat_debug_raise_exception> (e=0x100059440, message=...) at s-excdeb.adb:43
#1  0x0000000100019e8c in ada.exceptions.complete_occurrence (x=0x100500af0)
    at a-except.adb:925
#2  0x0000000100019e9b in ada.exceptions.complete_and_propagate_occurrence (
    x=0x100500af0) at a-except.adb:936
#3  0x000000010001a2a6 in ada.exceptions.raise_with_location_and_msg (e=0x100059440, 
    f=(system.address) 0x10003ca64, l=2268, c=0, m=(system.address) 0x10003e640)
    at a-except.adb:1162
#4  0x0000000100019e61 in <__gnat_raise_constraint_error_msg> (file=<optimized out>, 
    line=<optimized out>, column=<optimized out>, msg=<optimized out>)
    at a-except.adb:891
#5  0x000000010001a390 in <__gnat_rcheck_CE_Index_Check> (file=<optimized out>, 
    line=<optimized out>) at a-except.adb:1237
#6  0x000000010000e03e in perfect_hash_generators.select_char_position.count_different_keys (table=..., last=1, pos=1) at perfect_hash_generators.adb:2268
#7  0x000000010000ca72 in perfect_hash_generators.select_char_position ()
    at perfect_hash_generators.adb:2326
#8  0x000000010000354b in perfect_hash_generators.compute (position=...)
    at perfect_hash_generators.adb:685
#9  0x000000010000f466 in phg2 () at phg2.adb:52
(gdb) p k
$1 = 67
(gdb) p pos
$2 = 1
(gdb) p reduced(k)
$3 = 322
(gdb) p table(s)
$4 = (first => 0, last => 253)

... gdb doesn't know what WT.Table is ... it's in an instantiation of
gnat.table ..


You were right about the strings, this

with Ada.Text_IO;
procedure Str is
   type A is access String;
   S : String := "xxxhelloyyy";
   P : A;
begin
   P := new String'(S (4 .. 8));
   Ada.Text_IO.Put_Line
     ("""" & P.all & """ has indices"
        & P.all'First'Img & " .." & P.all'Last'Img);
end Str;

gives

$ ./str
"hello" has indices 4 .. 8


  parent reply	other threads:[~2016-09-06 21:04 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-04 19:22 Can anyone help with GNAT.Perfect_Hash_Generators ? (Possible memory corruption) Natasha Kerensikova
2016-09-05 17:18 ` Stephen Leake
2016-09-06 19:24   ` Natasha Kerensikova
2016-09-06 19:52     ` Florian Weimer
2016-09-06 20:55       ` Jeffrey R. Carter
2016-09-06 21:04       ` Simon Wright [this message]
2016-09-08 16:00         ` Anh Vo
2016-09-08 17:04           ` Simon Wright
2016-09-08 18:03             ` Anh Vo
2016-09-08 18:10               ` Simon Wright
2016-09-08 19:08               ` Jeffrey R. Carter
2016-09-09  6:04                 ` Natasha Kerensikova
2016-09-09  6:15                   ` Jeffrey R. Carter
2016-09-09  8:25                   ` J-P. Rosen
2016-09-08 19:19       ` Florian Weimer
2016-09-06 19:44   ` Florian Weimer
replies disabled

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