On 2/29/24 12:56 PM, Steve Kargl wrote:
On Thu, Feb 29, 2024 at 10:28:19AM -0800, Jerry D wrote:
On 2/29/24 10:13 AM, Steve Kargl wrote:
On Thu, Feb 29, 2024 at 09:36:43AM -0800, Jerry D wrote:
On 2/29/24 1:47 AM, Bernhard Reutner-Fischer wrote:

And, just for my own education, the length limitation of iomsg to 255
chars is not backed by the standard AFAICS, right? It's just our
STRERR_MAXSZ?

Yes, its what we have had for a long lone time. Once you throw an error
things get very processor dependent. I found MSGLEN set to 100 and IOMSG_len
to 256. Nothing magic about it.


There is no restriction on the length for the iomsg-variable
that receives the generated error message.  In fact, if the
iomsg-variable has a deferred-length type parameter, then
(re)-allocation to the exact length is expected.

    F2023

    12.11.6 IOMSG= specifier

    If an error, end-of-file, or end-of-record condition occurs during
    execution of an input/output statement, iomsg-variable is assigned
    an explanatory message, as if by intrinsic assignment. If no such
    condition occurs, the definition status and value of iomsg-variable
    are unchanged.
character(len=23) emsg
read(fd,*,iomsg=emsg)

Here, the generated iomsg is either truncated to a length of 23
or padded with blanks to a length of 23.

character(len=:), allocatable :: emsg
read(fd,*,iomsg=emsg)

Here, emsg should have the length of whatever error message was
generated.
HTH


Well, currently, if someone uses a larger string than 256 we are going to
chop it off.

Do we want to process this differently now?


If I look at the interfaces for UDTIO in F2023 (pp. 254-255),
the declaration for iomsg is

   CHARACTER (LEN=*), INTENT(INOUT) :: iomsg

F2023 (p. 62) has
   An asterisk as a type-param-value specifies that a length type
   parameter is an assumed type parameter.  It is used for a dummy
   argument to assume the type parameter value from the effective
   argument, ...

So, in theory, one should be able to get the required length
from length from the argument.

   CHARACTER(LEN=23) str
   WRITE(6,'(DT)',iomsg=str) derived-type-entity

If the subroutine supplied by the user internally creates
an error message with 300 characters, then from the above I
would think that it will be truncated to 23 characters.
OTOH, if the user is expecting the full 300 characters with

   CHARACTER(LEN=300) str
   WRITE(6,'(DT)',iomsg=str) derived-type-entity

then truncating internally to 256 seems wrong.

Now, that I looked at the interface more closely, the declaration

   CHARACTER (LEN=*), INTENT(INOUT) :: iomsg

seems to block the use of an unallocated deferred-length 'str'
and (re)-allocation does not occur.

Without addressing the length discussions above, I did find an existing function in libgfortran to trim the spaces at the end (string_len_trim). I am using it as follows:

                if ((dtp->u.p.child_saved_iostat != 0) &&
                    !(dtp->common.flags & IOPARM_HAS_IOMSG) &&
                    !(dtp->common.flags & IOPARM_HAS_IOSTAT))
                  {
                    char message[IOMSG_LEN];
                    child_iomsg_len = string_len_trim (IOMSG_LEN, child_iomsg) 
+ 1;
                    snprintf (message, child_iomsg_len, child_iomsg);
                    generate_error (&dtp->common, dtp->u.p.child_saved_iostat,
                                    message);
                    goto nml_err_ret;
                  }

I will study the len questions further.

Jerry

PS I wish my mail client would not wrap text on me, working on that issue.

Reply via email to