From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!mx05.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: =?utf-8?Q?Yannick_Duch=C3=AAne_=28Hibou57?= =?utf-8?Q?=29?= Newsgroups: comp.lang.ada Subject: Allocators and the requirement to raise `Storage_Error` Date: Fri, 03 May 2013 07:35:29 +0200 Organization: Ada @ Home Message-ID: NNTP-Posting-Host: nReaOVWq/ugo3wZUL0F24Q.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Content-Transfer-Encoding: Quoted-Printable X-Complaints-To: abuse@aioe.org User-Agent: Opera Mail/12.15 (Linux) X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:15308 Date: 2013-05-03T07:35:29+02:00 List-Id: ARM 2012 @4.8 says: http://www.ada-auth.org/standards/12rm/html/RM-4-8.html > For an allocator with a subtype_indication, the > subtype_indication shall not specify a null_exclusion This may be interpreted as =E2=80=9Cnull may be returned by an allocator= =E2=80=9D. ARM 2012 @13.11 says: http://www.ada-auth.org/standards/12rm/html/RM-13-11.html > If Storage_Pool is not specified for a type defined > by an access_to_object_definition, then the implementation > chooses a standard storage pool for it in an > implementation-defined manner. In this case, the exception > Storage_Error is raised by an allocator if there is not > enough storage. This may be interpreted as =E2=80=9Cmay be a user defined storage pool=E2= =80=9D is allowed = to return `null` when there is not enough storage in the pool. ARM 2012 @13.11, again, says: > If Storage_Pool is specified for an access type, then if Allocate > can satisfy the request, it should allocate a contiguous block of > memory, and return the address of the first storage element in > Storage_Address. The block should contain Size_In_Storage_Elements > storage elements, and should be aligned according to Alignment. > The allocated storage should not be used for any other purpose > while the pool element remains in existence. If the request cannot > be satisfied, then Allocate should propagate an exception (such as > Storage_Error). If Allocate behaves in any other manner, then the > program execution is erroneous. So finally, in no case at all it is allowed for an allocator, to return = = `null` instead of raising `Storage_Error` when there is not enough = storage, even if the two quotes above had possibly provisional hope for = = the other way. I'm disappointed with the last =E2=80=9CIf Allocate behaves in any other= manner, = then the program execution is erroneous=E2=80=9D, which implies it's err= oneous to = return `null`. I may understand allocations failing in a declarative part, may be an = issue if some declarations coming next to it refers to this allocation. = = But finally, one may also define a function doing something similar and = = not being imposed this requirement, i.e. returning an access type after = = some kind of allocation and returning `null` if it fails, except it won'= t = work with non=E2=80=91constrained types and such a function would need t= o be = defined for each constrained subtypes or derived types of the = non=E2=80=91constrained type (a pain). I though there may be something in the RM, allowing an allocator to retu= rn = `null`, and expect `Program_Error` to be raise instead, on any attempt t= o = dereference an unallocated access. I will review the relevant parts of the RM again for the reasons, but = right now, I don't see why it is this way. (yes, I know I'm playing silly things, but I have my silly reasons). -- = =E2=80=9CSyntactic sugar causes cancer of the semi-colons.=E2=80=9D [1] =E2=80=9CStructured Programming supports the law of the excluded muddle.= =E2=80=9D [1] [1]: Epigrams on Programming =E2=80=94 Alan J. =E2=80=94 P. Yale Univers= ity