[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bison 1.30f

From: Hans Aberg
Subject: Re: Bison 1.30f
Date: Sat, 15 Dec 2001 13:51:15 +0100

At 11:07 +0100 2001/12/15, Akim Demaille wrote:
>>> It assumes that the values can be copied merely by copying their
>>> bits.  It uses memcpy in places.
>Hans> Can you give examples of this (so I can think more about it)?
>src/bison-1.29/src % grep memcpy bison.simple -C4                nostromo

Thank you. I realized this one after writing my email (without a search). :-)

># define YYSTACK_RELOCATE(Type, Stack)                                  \
>    do                                                                  \
>      {                                                                 \
>        YYSIZE_T yynewbytes;                                            \
>        yymemcpy ((char *) yyptr, (char *) (Stack),                     \
>                  yysize * (YYSIZE_T) sizeof (Type));                   \
>        Stack = &yyptr->Stack;                                          \
>        yynewbytes = yystacksize * sizeof (Type) + YYSTACK_GAP_MAX;     \
>        yyptr += yynewbytes / sizeof (*yyptr);                          \

There are two problems with this code under C++, first that the whole stack
is copied in one chunk so that the copy constructors of the YWCA type
objects are not invoked.

The second problem is that one has
  union yyalloc *yyptr = ...
  union yyalloc
    short yyss;
    YYSTYPE yyvs;
    YYLTYPE yyls;
  # endif
and unions are under C++ only allowed (or so I recall) for POD's (plain ol'
data's), basically data types which does not have non-default constructors.

So I am not really sure why my code compiled, as my YYSTYPE contains
non-default constructors.

And I never encountered a stack reallocation, which is probably I why I did
not have any problems with that.

Anyway, it seems safest to give Bison genuine C++ support, where one is
using std containers for stack allocation. Then this problem will go away.

I am not sure it's worth to improve the C++ support in the compile C as C++
mode, but the manual should have some notes about it, I think. (Warning:
Stack re-allocation does currently not invoke YYSTYPE copy constructors in
the compile C as C++ mode.)

  Hans Aberg

reply via email to

[Prev in Thread] Current Thread [Next in Thread]