CVS difference for ais/ai-00383.txt

Differences between 1.2 and version 1.3
Log of other versions for file ais/ai-00383.txt

--- ais/ai-00383.txt	2004/09/04 01:13:46	1.2
+++ ais/ai-00383.txt	2004/09/10 00:43:34	1.3
@@ -557,3 +557,176 @@
 
 ****************************************************************
 
+From: Pascal Leroy
+Sent: Monday, September 6, 2004  4:00 AM
+
+Well, it's nice to reduce the number of implicit conversions, but it
+doesn't solve the problem I had in mind.
+
+Say that I am getting an address from some low-level mechanism, e.g.
+calling a C library.  I want to convert this address into an Ada
+access-to-record, to access individual fields in a type-safe manner.
+There are various useful properties that I am unable to express in Ada
+because the silly A_To_A_Conversion insists on declaring the access type
+itself:
+
+1 - I am not going to change the allocated structure; I'd like to have an
+access-to-constant.
+2 - I am not going to do any allocation on the Ada side; I'd like to have
+storage size of 0.
+3 - I may be doing allocations/deallocations on the Ada side, but they
+better go through the storage management mechanism provided by the C
+library, lest plague and pestilence ensue; I'd like to specify a storage
+pool.
+
+All three would be possible to express if the generic took an access type
+as a parameter (OK, we would need two generics for access-to-constant and
+access-to-variable).  And please don't tell me that I can just convert the
+access type exported by the instantiation to a user-declared one with the
+right properties, because that doesn't give me any additional safety: I
+cannot prevent code from writing/allocating/deallocating through the type
+exported by the instantiation.
+
+****************************************************************
+
+From: Robert A. Duff
+Sent: Monday, September 6, 2004  8:48 AM
+
+> All three would be possible to express if the generic took an access type
+> as a parameter (OK, we would need two generics for access-to-constant and
+> access-to-variable).
+
+The above are all true.  I just don't think it's important enough to
+fix.
+
+>...And please don't tell me that I can just convert the
+> access type exported by the instantiation to a user-declared one with the
+> right properties,...
+
+Too late.   ;-)  I already told you that.
+
+>...because that doesn't give me any additional safety: I
+> cannot prevent code from writing/allocating/deallocating through the type
+> exported by the instantiation.
+
+Well, you can work around that by instantiating in a fairly invisible
+place.  E.g.
+
+    function To_Ptr(X: System.Address) return Some_Ptr is
+        package Instance is new A_To_A_Conversions(...);
+    begin
+        return Some_Ptr(Instance.To_Pointer(X));
+    end To_Ptr;
+
+Or leave out Some_Ptr() if the conversion is implicit.
+
+These annoyances would bother me more if A_To_A_C were something I use
+every day.  I must admit that I've used Unchecked_Conversion instead,
+sometimes.
+
+****************************************************************
+
+From: Robert I. Eachus
+Sent: Monday, September 6, 2004  11:46 AM
+
+"Fixing" this issue would in my mind be a bad idea.  It would add an
+unnecessary upward incompatibility to the language. But adding separate
+children of System that takes access parameters may be worth doing.  The
+question for implementors is whether or not adding the the following
+package to the standard would require much if any work:
+
+ generic
+    type Object(<>) is limited private;
+    type Object_Pointer is access all Object;
+ package System.Address_To_Named_Access_Conversions is
+    pragma Preelaborate(Address_To_Named_Access_Conversions);
+
+    function To_Pointer(Value : Address) return access all Object;
+    function To_Address(Value : Object_Pointer) return Address;
+
+    pragma Convention(Intrinsic, To_Pointer);
+    pragma Convention(Intrinsic, To_Address);
+
+ end System.Address_To_Named_Access_Conversions;
+
+ generic
+    type Object(<>) is limited private;
+    type Object_Pointer is access constant Object;
+ package System.Address_To_Constant_Access_Conversions is
+    pragma Preelaborate(Address_To_Constant_Access_Conversions);
+
+    function To_Pointer(Value : Address) return access constant Object;
+    function To_Address(Value : Object_Pointer) return Address;
+    pragma Convention(Intrinsic, To_Pointer);
+    pragma Convention(Intrinsic, To_Address);
+
+ end System.Address_To_Constant_Access_Conversions;
+
+My guess is that the work required would be mostly cut and paste (as would the
+work in the RM), so it may be easier to add these packages than to continue the
+debate.
+
+****************************************************************
+
+From: Robert A. Duff
+Sent: Monday, September 6, 2004  12:33 PM
+
+By "fixing", I meant "adding separate children...", which is exactly
+what Pascal suggested.  But note that Pascal or any other programmer
+can implement the desired functionality in plain portable Ada 95:
+
+ generic
+    type Object(<>) is limited private;
+    type Object_Pointer is access all Object;
+ package System.Address_To_Named_Access_Conversions is
+    pragma Preelaborate(Address_To_Named_Access_Conversions);
+
+    function To_Pointer(Value : Address) return Object_Pointer;
+    function To_Address(Value : Object_Pointer) return Address;
+
+    pragma Inline(To_Pointer);
+    pragma Inline(To_Address);
+
+ end System.Address_To_Named_Access_Conversions;
+
+ with Address_To_Access_Conversions;
+ package System.Address_To_Named_Access_Conversions is
+
+    package A_To_A is new Address_To_Access_Conversions(Object);
+
+    function To_Pointer(Value : Address) return return Object_Pointer is
+    begin
+        return Object_Pointer(A_To_A.To_Pointer(Value));
+    end To_Pointer;
+
+    function To_Address(Value : Object_Pointer) return Address is
+    begin
+        return Value.all'Address;
+OR (if you want to allow nulls):
+	return To_Address(A_To_A.Object_Pointer(Value));
+    end To_Address;
+
+ end System.Address_To_Named_Access_Conversions;
+
+and similarly for the access-constant version.
+
+****************************************************************
+
+From: Robert Dewar
+Sent: Monday, September 6, 2004  12:50 PM
+
+This is not portable Ada, you can't go adding children to
+System yourself!
+
+****************************************************************
+
+From: Robert A. Duff
+Sent: Monday, September 6, 2004  2:08 PM
+
+Got me!
+
+I forgot to delete "System." from the example.  I did remember to change
+pragma Intrinsic to pragma Inline.  ;-)
+
+****************************************************************
+

Questions? Ask the ACAA Technical Agent