To: J3 10-206 From: John Reid Subject: Interop TR: CFI_allocate and CFI_deallocate Date: 2010 September 10 References: 10-165r2, ISO/IEC 1539-1:2010 DISCUSSION It is stated in 5.2.6.2 of 10-165r2 that CFI_allocate uses the same mechanism as the Fortran ALLOCATE statement, but the conditions are not the same. Similarly, it is stated in 5.2.6.3 that CFI_deallocate uses the same mechanism at the Fortran DEALLOCATE statement, but the conditions are not the same. Edits are proposed to correct this. Furthermore, an edit is proposed to allow the DEALLOCATE statement to deallocate a pointer target that was allocated by CFI_allocate. A note is proposed to explain the purpose of the state member of CFI_cdesc_t. Tobias Burnus has requested that CFI_cdesc_t have a member that indicates whether a pointer is associated with a target that may be deallocated. A simple change to the state member is provided for this but there is an argument against it - there is likely overhead for setting the state in a call to a C function that makes no use of the information. For this reason, it is separated from the other edits. Malcolm Cohen suggests eliminating the state member. He says "Just requiring the address field to be non-null would be sufficient, and nicer to use. Whether the underlying Fortran implementation uses a null address for zero-sized allocations or not, the right thing to do is to hide the processor dependency from the user, not expose it." Alternative edits for this are provided. EDITS to 10-165r2: [9:36+] After the list of components of CFI_cdesc_t add NOTE The value NULL for the base_addr component does not necessarily indicate that an allocatable is not allocated since it may be allocated and of size zero. Similarly, the value NULL for the base_addr component does not necessarily indicate that a pointer is not pointer associated since it may be associated with a target of size zero. [12:3] Change "On entry, the base address in the C descriptor shall be NULL. The" to "On entry, the". [12:4] Change "disassociated" to "a". [12:4-5] Change "The supplied" to "On successful execution of CFI_allocate, the supplied", and move this sentence to be after the sentence at [12:6] ending "... assumed to be one." [12:11] Change "On entry, the base address in the C descriptor shall not be NULL. The" to "On entry, the". [12:12-13] Change "that was allocated ... statement" to "satisfying the conditions for successful deallocation by the Fortran DEALLOCATE statement (6.7.3.3 of ISO/IEC 1539-1:2010)". [13] Add a new section: 5.3 Interaction with the DEALLOCATE statement The DEALLOCATE statement shall treat a pointer whose target was allocated using CFI_allocate in exactly the same way as if it were allocated using an ALLOCATE statement. ADDITIONAL EDIT to 10-165r2: [9:35-36] Replace by has the value 1 if the object is an allocated allocatable or a pointer associated with a target satisfying the conditions for successful deallocation by the Fortran DEALLOCATE statement (6.7.3.3 of ISO/IEC 1539-1:2010). 2 if the object is a pointer that is otherwise associated with a target or is of assumed-shape, or 0 otherwise. ALTERNATIVE EDITS to 10-165r2: Do not make the above edits for [9:36+] and [9:35-36]. Instead, make these edits: [9:22]. Replace "If the object has zero size, the value is processor-dependent." by "If the object has zero size, the value is not NULL but is otherwise processor dependent." [9:35-36]. Delete the lines for int state.