[Bug ada/40285] New: Including Ada.Real_Time.Timing_Events breaks signal handling

2009-05-28 Thread reet at codelabs dot ch
This issue has also been discussed on the comp.lang.ada newsgroup, see
[1] for details.

Signal-handling using a protected type as handler is not possible any more if
an application includes the Ada.Real_Time.Timing_Events package. It's not
necessary to actually use types from the package, including it is enough to
break signal handling.

I wrote a small reproducer to illustrate the problem, the files are attached.

The protected object Signal_Handler defined in the package Handlers is used as
a signal handler, which can be attached to a specific interrupt/signal.

The Signal_Handler type is used in the small test application implemented as
procedure Interrupt_Problem in the interrupt_problem.adb file.

As expected, when sending SIGTERM (or other signals) to the running
'Interrupt_Problem' process "Interrupt received ..." is displayed.

When the Ada.Real_Time.Timing_Events package is included, this mechanism
breaks. The signal handler is not invoked any more when signals are sent to a
running 'Interrupt_Problem' process, the Handler.Wait entry is not triggered.

The problem seems to have various characteristics on different architectures,
see the newsgroup thread [1].

gnatgcc -v output:
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.3.2-1.1'
--with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3
--program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug
--enable-objc-gc --enable-mpfr --enable-targets=all --enable-cld
--enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu
--target=i486-linux-gnu
Thread model: posix
gcc version 4.3.2 (Debian 4.3.2-1.1)

--

[1] -
http://groups.google.com/group/comp.lang.ada/browse_thread/thread/e69505d5161d7d41


-- 
   Summary: Including Ada.Real_Time.Timing_Events breaks signal
handling
   Product: gcc
   Version: 4.3.2
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: ada
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: reet at codelabs dot ch
 GCC build triplet: i486-linux-gnu
  GCC host triplet: i486-linux-gnu
GCC target triplet: i486-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40285



[Bug ada/40285] Including Ada.Real_Time.Timing_Events breaks signal handling

2009-05-28 Thread reet at codelabs dot ch


--- Comment #1 from reet at codelabs dot ch  2009-05-28 23:01 ---
Created an attachment (id=17926)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17926&action=view)
Simple application which uses a protected type for signal handling.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40285



[Bug ada/40285] Including Ada.Real_Time.Timing_Events breaks signal handling

2009-05-28 Thread reet at codelabs dot ch


--- Comment #2 from reet at codelabs dot ch  2009-05-28 23:02 ---
Created an attachment (id=17927)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17927&action=view)
Handlers package spec.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40285



[Bug ada/40285] Including Ada.Real_Time.Timing_Events breaks signal handling

2009-05-28 Thread reet at codelabs dot ch


--- Comment #3 from reet at codelabs dot ch  2009-05-28 23:03 ---
Created an attachment (id=17928)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17928&action=view)
Handlers package body.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40285



[Bug ada/39441] New: Discriminant & interface not implemented by full type (RM-2005 7.3 (7.3/2))

2009-03-12 Thread reet at codelabs dot ch
Given the following package spec:

package Full_View is

   type Base_Type (Num : Integer) is tagged private;

   type Base_Interface is interface;

   type New_Type is new Base_Type (Num => 11) 
 and Base_Interface with private;

private
   type Base_Type (Num : Integer) is tagged record
  My_Number : Integer := Num;
   end record;

   type New_Type is new Base_Type (Num => 11) and
 Base_Interface with null record;

end Full_View;

Trying to compile this with gcc 4.3.2 in Debian/Lenny results in the following
error:
full_view.ads:7:09: interface "Base_Interface" not implemented by full
type (RM-2005 7.3 (7.3/2))

Verbose output:

$ gcc -v -c full_view.ads
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.3.2-1.1'
--with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3
--program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug
--enable-objc-gc --enable-mpfr --enable-targets=all --enable-cld
--enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu
--target=i486-linux-gnu
Thread model: posix
gcc version 4.3.2 (Debian 4.3.2-1.1) 
COLLECT_GCC_OPTIONS='-v' '-c' '-mtune=generic'
 /usr/lib/gcc/i486-linux-gnu/4.3.2/gnat1 -quiet -dumpbase full_view.ads
-mtune=generic full_view.ads -o /tmp/cchU6wbD.s
full_view.ads:7:09: interface "Base_Interface" not implemented by full type
(RM-2005 7.3 (7.3/2))

When removing the (Num => 11) discrimant initialization or the Base_Interface
interface from the New_Type type extension, the code compiles fine.

Seems to me that the consistency check of the partial and full view of a tagged
type covering interfaces does not work with discriminants.

- reto


-- 
   Summary: Discriminant & interface not implemented by full type
(RM-2005 7.3 (7.3/2))
   Product: gcc
   Version: 4.3.2
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: ada
    AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: reet at codelabs dot ch
 GCC build triplet: i486-linux-gnu
  GCC host triplet: i486-linux-gnu
GCC target triplet: i486-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39441



[Bug ada/41383] New: Timing_Events: Event time not cleared after Cancel_Handler

2009-09-16 Thread reet at codelabs dot ch
ARM D.15 about Ada.Real_Time.Timing_Events states:

9/2 An object of type Timing_Event is said to be set if it is associated
with a non-null value of type Timing_Event_Handler and cleared
otherwise. All Timing_Event objects are initially cleared.

17/2 The procedure Cancel_Handler clears the event if it is set.
Cancelled is assigned True if the event was set prior to it being
cleared; otherwise it is assigned False.

18/2 The function Time_Of_Event returns the time of the event if the
event is set; otherwise it returns Real_Time.Time_First.

There's a bug in the Cancel_Handler() procedure, because the event time remains
set and is not reset to Ada.Real_Time.Time_First (as required by 18/2).

Here is a small reproducer:

--

with Ada.Real_Time.Timing_Events;

package Timers is

   use Ada.Real_Time.Timing_Events;

   protected type Timer_Type is
  procedure Setup (At_Time : Ada.Real_Time.Time);
  function Get_Time return Ada.Real_Time.Time;
  procedure Stop (Status : out Boolean);
   private
  procedure Handle (Event : in out Timing_Event);

  Event : Timing_Event;
   end Timer_Type;

end Timers;

--

package body Timers is

   protected body Timer_Type is

  function Get_Time return Ada.Real_Time.Time is
  begin
 return Event.Time_Of_Event;
  end Get_Time;

  procedure Handle (Event : in out Timing_Event) is
  begin
 null;
  end Handle;

  procedure Setup (At_Time : Ada.Real_Time.Time) is
  begin
 Event.Set_Handler (At_Time => At_Time,
Handler => Handle'Access);
  end Setup;

  procedure Stop (Status : out Boolean) is
  begin
 Event.Cancel_Handler (Cancelled => Status);
  end Stop;

   end Timer_Type;

end Timers;

--

with Ada.Text_IO;
with Ada.Real_Time;

with Timers;

procedure Cancel_Handler is
   use Ada.Real_Time;

   Handler : Timers.Timer_Type;
   Timer   : constant Time := Clock + Minutes (60);
begin
   if Handler.Get_Time = Time_First then
  Ada.Text_IO.Put_Line ("Time is Time_First ...");
   end if;

   Handler.Setup (At_Time => Timer);
   if Handler.Get_Time = Timer then
  Ada.Text_IO.Put_Line ("Handler set ...");
   end if;

   declare
  Stopped : Boolean := False;
   begin
  Handler.Stop (Status => Stopped);

  if Stopped then
 Ada.Text_IO.Put_Line ("Timer cancelled ...");
 if Handler.Get_Time = Timer then
Ada.Text_IO.Put_Line ("Why is the time still set then?");
 end if;
  end if;
   end;
end Cancel_Handler;


-- 
   Summary: Timing_Events: Event time not cleared after
Cancel_Handler
   Product: gcc
   Version: 4.4.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: ada
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: reet at codelabs dot ch
 GCC build triplet: i486-linux-gnu
  GCC host triplet: i486-linux-gnu
GCC target triplet: i486-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41383



[Bug ada/43598] New: GNAT.Expect.Non_Blocking_Spawn double free or corruption

2010-03-31 Thread reet at codelabs dot ch
(forwarding Debian bug #575954)

Under some conditions, using GNAT.Expect.Non_Blocking_Spawn in
conjunction with GNAT.Expect.Close leads to memory corruption on amd64.

Given the following small reproducer:

--  expect_test.adb

with Ada.Text_IO;

with GNAT.Expect;
with GNAT.OS_Lib;
with GNAT.Regpat;

procedure Expect_Test is
   use GNAT.Expect;

   Fd   : Process_Descriptor;
   Command  : constant String := "./print_file";
   Arg_List : GNAT.OS_Lib.Argument_List (1 .. 0);
   Result   : Expect_Match;
   Match: GNAT.Regpat.Match_Array (0 .. 0);
begin
   Non_Blocking_Spawn
 (Descriptor  => Fd,
  Command => Command,
  Args=> Arg_List,
  Buffer_Size => 128,
  Err_To_Out  => True);

   Expect
 (Descriptor  => Fd,
  Result  => Result,
  Regexps => Regexp_Array'
(+"END TESTS(.*)FAILED",
 +"END TESTS(.*)PASSED"),
  Matched => Match,
  Timeout => 10);
   Ada.Text_IO.Put_Line ("Terminated");
   Ada.Text_IO.Put_Line (Expect_Out (Descriptor => Fd));
   Ada.Text_IO.Put_Line ("Buffer len " &
 Expect_Out (Descriptor => Fd)'Length'Img);
   Close (Descriptor => Fd);

exception
   when Process_Died =>
  Ada.Text_IO.Put_Line ("Process died");
  Ada.Text_IO.Put_Line (Expect_Out (Descriptor => Fd));
  Close (Descriptor => Fd);
end Expect_Test;

--  print_file.adb

with Ada.Text_IO;

procedure Print_File is
   Filename : constant String := "output";
   File : Ada.Text_IO.File_Type;
begin
   Ada.Text_IO.Open (File => File,
 Mode => Ada.Text_IO.In_File,
 Name => Filename);

   while not Ada.Text_IO.End_Of_File (File => File) loop
  delay 0.001;
  Ada.Text_IO.Put_Line (Ada.Text_IO.Get_Line (File => File));
   end loop;

   Ada.Text_IO.Close (File => File);
end Print_File;

--  output




END TESTS...: PASSED
--

Running the expect_test binary on amd64 results in memory corruption. As
it seems this only happens if the following conditions are met:

* the binary spawned produces more output than the expect buffer size

This should not matter because Non_Blocking_Spawn is expected to discard
old characters:

"The expect buffer associated with that process can contain at most
Buffer_Size characters. Older characters are simply discarded when this
buffer is full."

* the spawned binary uses file IO
* the code sleeps between the text output cycles

Tests:
* gnat 4.3.2:
*** glibc detected *** ./obj/expect_test: double free or corruption
(!prev): 0x006040a0 ***

* gnat 4.4.3:
*** glibc detected *** ./obj/expect_test: free(): invalid next size
(fast): 0x00605090 ***

The bug is also present with the tip of the gcc-4_4-branch (Subversion
revision 157750) from upstream (verified by Ludovic Brenta).

Full gdb backtrace with gnat 4.3.2:

#0  0x7f9502737ed5 in raise () from /lib/libc.so.6
No symbol table info available.
#1  0x7f95027393f3 in abort () from /lib/libc.so.6
No symbol table info available.
#2  0x7f9502774388 in __libc_message () from /lib/libc.so.6
No symbol table info available.
#3  0x7f9502779928 in malloc_printerr () from /lib/libc.so.6
No symbol table info available.
#4  0x7f950277ba36 in free () from /lib/libc.so.6
No symbol table info available.
#5  0x7f9502ee53a5 in <__gnat_free> (ptr=6308000) at s-memory.adb:117
No locals.
#6  0x7f9502e670af in gnat.expect.close (descript...@0x7fffbe50) at
g-expect.adb:227
current_filter = 
next_filter = 
#7  0x00402ff7 in _ada_expect_test ()
No locals.

The complete reproducer code can be downloaded at [1].

- reto

[1] - http://www.codelabs.ch/~reet/reproducers/gnat-expect.tar.bz2


-- 
   Summary: GNAT.Expect.Non_Blocking_Spawn double free or corruption
   Product: gcc
   Version: 4.4.4
    Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: ada
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: reet at codelabs dot ch
 GCC build triplet: x86_64-linux-gnu
  GCC host triplet: x86_64-linux-gnu
GCC target triplet: x86_64-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43598