Login | Register
My pages Projects Community openCollabNet

Discussions > users > Charles: unexpected(?) access error in C.S.S.Unbounded.Generic_Element instance

charles
Discussion topic

Back to topic list

Charles: unexpected(?) access error in C.S.S.Unbounded.Generic_Element instance

Reply

Author Georg Bauhaus <bauhaus at arcor dot de>
Full name Georg Bauhaus <bauhaus at arcor dot de>
Date 2004-10-19 00:22:17 PDT
Message A program shows different behavior depending on whether it is
tranlated using GNAT or using ObjectAda. In one case there is
no trouble at all, in the other case I get PROGRAM_ERROR.
A sorted set is storing pointers. When I try to use a
Generic_Element instance to retrieve a pointer to a pointer,
the ObjectAda made executable stops with a stack trace when
the stored pointer is null.

I think this happends near the attempt to execute
      return Iterator.Node.Element'Access;
At least this is as close as I can get using the Aonix debugger.
The topmost stack trace entry refers to line 909 in C.S.S.Unbounded,
so this is in agreement. When I try to execute the step in the
debugger it stops after some time, saying
  ERROR: Cannot read register: EIP
Alternatively, I have seen INTERNAL, ... EIP in slightly
different programs.

A similar effect occurs when using Maps.
Can I use pointers as values in a container, including null,
or was I guessing wrong? And which one of the compilers is
correct?

This is the program, the error (or not) occurs when direct(p)
is called in the main procedure.


with Charles.Sets.Sorted.Unbounded;

package P is

   type T_Eq is access constant Integer;


   type T is new T_Eq;

   function "<"(L, R: T) return Boolean;
   -- by .all unless `null`

   function "="(L, R: T) return Boolean;
   -- by .all unless `null`


   --i1, i2, i3: aliased constant Integer := 17;

   package ISets is new Charles.Sets.Sorted.​Unbounded(T);

end P;

package body P is

   function is_null(x: T) return Boolean is
   begin
      return T_Eq(x) = null;
   end is_null;


   function "<"(L, R: T) return Boolean is
   begin
      if is_null(L) then
         return not is_null(R);

      elsif is_null(R) then
         return false; -- because not is_null(L))

      else
         return L.all < R.all;

      end if;
   end "<";


   function "="(L, R: T) return Boolean is
   begin
      if is_null(L) then
         return is_null(R);

      elsif is_null(R) then
         return false;

      else
         return L.all = R.all;
      end if;
   end "=";

end P;


with P; use P;
with Ada.Text_IO;

procedure P_test is

   package TIO renames Ada.Text_IO;

   use ISets;

   numbers: Container_Type;

   k: Iterator_Type;
   inserted: Boolean;

   null_item: T;

   type T_Access is access constant T;

   function value_in_place return T_Access is
      result: T_Access;
      p: Iterator_Type;
      z: T;
      function direct is new generic_element(T_Access);
   begin
      p := find(numbers, null_item);
      if p /= back(numbers) then
         result := direct(p); -- OA: bang!
         z := result.all;
      end if;
      return result;
   end value_in_place;

begin
   insert(numbers, null_item, k, inserted);
   pragma assert(inserted);
   pragma assert(k /= back(numbers));

   TIO.put_line(Natural​'image(length(number​s)));

   works:
   declare
      new_k: Iterator_Type := find(numbers, null_item);
   begin
      pragma assert(k = new_k);
      pragma assert(element(k) = null);
      --TIO.put_line(Natur​al'image(element(k).​all));
      null;
   end works;


   declare
      ind: T_Access;
   begin
      ind := value_in_place;
   end;

end P_test;


-- Georg

--------------------​--------------------​--------------------​---------
To unsubscribe, e-mail: users-unsubscribe@ch​arles.tigris.org
For additional commands, e-mail: users-help at charles dot tigris dot org

« Previous message in topic | 1 of 9 | Next message in topic »

Messages

Show all messages in topic

Charles: unexpected(?) access error in C.S.S.Unbounded.Generic_Element instance Georg Bauhaus <bauhaus at arcor dot de> Georg Bauhaus <bauhaus at arcor dot de> 2004-10-19 00:22:17 PDT
     RE: Charles: unexpected(?) access error in C.S.S.Unbounded.Generic_Element instance matthewjheaney Matthew Heaney 2004-10-19 07:37:07 PDT
         Re: Charles: unexpected(?) access error in C.S.S.Unbounded.Generic_Element instance Georg Bauhaus <bauhaus at arcor dot de> Georg Bauhaus <bauhaus at arcor dot de> 2004-10-19 13:02:10 PDT
             Re: Charles: unexpected(?) access error in C.S.S.Unbounded.Generic_Element instance Matthew Heaney <mheaney at on2 dot com> Matthew Heaney <mheaney at on2 dot com> 2004-10-19 13:22:31 PDT
                 Re: Charles: unexpected(?) access error in C.S.S.Unbounded.Generic_Element instance Georg Bauhaus <bauhaus at arcor dot de> Georg Bauhaus <bauhaus at arcor dot de> 2004-10-20 11:52:08 PDT
                     Re: Charles: unexpected(?) access error in C.S.S.Unbounded.Generic_Element instance Matthew Heaney <mheaney at on2 dot com> Matthew Heaney <mheaney at on2 dot com> 2004-10-20 13:56:01 PDT
                         Re: Charles: unexpected(?) access error in C.S.S.Unbounded.Generic_Element instance Georg Bauhaus <bauhaus at arcor dot de> Georg Bauhaus <bauhaus at arcor dot de> 2004-10-20 14:15:06 PDT
                             RE: Charles: unexpected(?) access error in C.S.S.Unbounded.Generic_Element instance matthewjheaney Matthew Heaney 2004-10-20 19:15:32 PDT
                     Re: Charles: unexpected(?) access error in C.S.S.Unbounded.Generic_Element instance Georg Bauhaus <bauhaus at arcor dot de> Georg Bauhaus <bauhaus at arcor dot de> 2004-11-03 08:13:45 PST
Messages per page: