This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Fix Wide_[Wide_]Text_IO Current_Output/null file handling


Tested on i686-linux, committed on trunk

This patch fixes two separate problems, both tested in the test
program below. First, reading or writing a null file should cause
a status error. It was instead causing a segmentation fault, as
a result of attempting to access the wide character encoding
method before setting the file status.

The other problem was in handling the forms of Current_Input etc
that return a File_Access. This had been fixed in Text_IO some
time ago, but not in Wide_[Wide_]Text_IO, the soolution is to
introduce a self pointer in files, and use a pointer to this
self pointer to implement Current_Input etc.

The following test programs should run outputting
a single line "It works" with the out.log file
containing two lines saying Hello.

with Ada.Wide_Text_IO; use Ada.Wide_Text_IO;
procedure Wide_Current_Output is
   New_File : File_Type;
   Old_File_Ref : constant File_Access := Current_Output;
begin
   Create (New_File, Out_File, "out.log");
   Set_Output (New_File);
   Put_Line ("Hello");
   Set_Output (Old_File_Ref.all);
   Put_Line ("It works");
   Set_Output (New_File);
   Put_Line ("Hello");
   Close (New_File);
   Put_Line ("It works");
exception
   when Status_Error => null;
end;

with Ada.Wide_Wide_Text_IO; use Ada.Wide_Wide_Text_IO;
procedure Wide_Wide_Current_Output is
   New_File : File_Type;
   Old_File_Ref : constant File_Access := Current_Output;
begin
   Create (New_File, Out_File, "out.log");
   Set_Output (New_File);
   Put_Line ("Hello");
   Set_Output (Old_File_Ref.all);
   Put_Line ("It works");
   Set_Output (New_File);
   Put_Line ("Hello");
   Close (New_File);
   Put_Line ("It works");
exception
   when Status_Error => null;
end;

2008-03-26  Robert Dewar  <dewar@adacore.com>

	* a-ztexio.adb, a-ztexio.ads, a-witeio.ads, a-witeio.adb: Fix problem
	with Current_Output (introduce Self).

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]