[Patch, Fortran, OOP] PR 46313: OOP-ABI issue, ALLOCATE issue, CLASS renaming issue
Janus Weil
janus@gcc.gnu.org
Mon Sep 17 19:22:00 GMT 2018
Am Mo., 17. Sep. 2018 um 10:59 Uhr schrieb Bernhard Reutner-Fischer
<rep.dot.nop@gmail.com>:
>
> On Tue, 9 Nov 2010 at 11:41, Janus Weil <janus@gcc.gnu.org> wrote:
> >
> > >> Ok, so it seems to me that using two leading underscores is really the
> > >> best option, since it's safe against collisions with Fortran and C
> > >> user code, and also safe to use with -fdollar-ok.
> > >>
> > >> The attached patch adds double underscores for the vtabs, vtypes,
> > >> class containers and temporaries.
> > >
> > > OK. Thanks for the patch!
> >
> > Committed as r166480.
> >
> > Thanks for all the helpful comments, everyone!
>
> Index: gcc/fortran/module.c
> ===================================================================
> --- gcc/fortran/module.c (revision 166419)
> +++ gcc/fortran/module.c (working copy)
> @@ -4372,8 +4372,8 @@ read_module (void)
> p = name;
>
> /* Exception: Always import vtabs & vtypes. */
> - if (p == NULL && (strncmp (name, "vtab$", 5) == 0
> - || strncmp (name, "vtype$", 6) == 0))
> + if (p == NULL && (strncmp (name, "__vtab_", 5) == 0
> + || strncmp (name, "__vtype_", 6) == 0))
> p = name;
>
> /* Skip symtree nodes not in an ONLY clause, unless there
>
> ---8<---
>
> Sorry for the late follow-up
'Late' is a pretty bold understatement for 8 years ;D
But in any case, 'late' is certainly better than 'never' ...
> but current trunk still has the code
> quoted above where we forgot to add 2 to the length parameter of both
> strncmp calls.
True! Thanks for noticing. I'll take care of fixing it.
> I think it would be nice to teach the C and C++ frontends to warn
> about this even though it might trigger in quite some code in the
> wild.
I don't really think this is a good idea. There are actually valid use
cases of strncmp, where the 'num' argument does not correspond to the
length of any of the two strings (in particular if they're not const).
Instead, for the sake of gfortran, how about a macro like this?
#define gfc_str_startswith(str, pref) \
(strncmp ((str), (pref), strlen (pref)) == 0)
(In fact I just noticed that something like this already exists in
trans-intrinsic.c, so I would just move it into gfortran.h and rename
it.)
> Looking at gcc/fortran alone there are
> gcc/fortran/interface.c: if (strncmp (mode, "unformatted", 9) == 0) // 11 !
I think this one could actually be a 'strcmp'?
> gcc/fortran/module.c: && (strncmp (name, "__vtab_", 5) == 0 // 7 !
> gcc/fortran/module.c: || strncmp (name, "__vtype_", 6) == 0)) // 8!
> gcc/fortran/module.c: || (strncmp (name, "__vtab_", 5) != 0 // 7!
> gcc/fortran/module.c: && strncmp (name, "__vtype_", 6)
> != 0)) // 8!
Here the new macro could be applied (and in a few other cases as
well), see attached patch.
I'm regtesting the patch now. Ok for trunk if it passes?
Cheers,
Janus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: strncmp_macro.diff
Type: text/x-patch
Size: 10631 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20180917/043e2ca6/attachment.bin>
More information about the Fortran
mailing list