bison-patches
[Top][All Lists]
Advanced

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

Re: remove unportable casts and storage allocation tricks from Bison


From: Akim Demaille
Subject: Re: remove unportable casts and storage allocation tricks from Bison
Date: Sun, 05 Jan 2003 14:49:42 +0100
User-agent: Gnus/5.090008 (Oort Gnus v0.08) Emacs/21.2 (i386-pc-linux-gnu)

| I found some unportable casts, and some unportable storage allocation
| tricks, and removed them by installing the following patch.
| 
| 2002-12-12  Paul Eggert  <address@hidden>
| 
|       * src/derives.c (derives_compute): Do not subtract NTOKENS from
|       the pointer DSET returned by malloc; this isn't portable.
|       Instead, always use DSET[i - NTOKENS] rather than DSET[i].
|       Similarly for DERIVES.

What was the problem with this code?  It's been in Bison since its
inception!

|       * src/derives.c (derives_compute): Do not bother invoking
|       int_of_rule_number, since rule numbers are integers.

Yes, but I used this to make sure I had propagated the types
everywhere: I was changing one typedef to something stupid, say a
pointer type, and was using the compiler to find the errors.  I would
love to have incompatible integer types in C, but...

That's also why there are those foo_as_bar_numbers macros, which are
now functions.

|       * src/state.c (TRANSITIONS_ALLOC, ERRS_ALLOC, REDUCTIONS_ALLOC,
|       STATE_ALLOC): Remove.
|       (transitions_new, errs_new, reductions_new, state_new): Use malloc
|       rather than calloc, and use offsetof to avoid allocating slightly
|       too much storage.

I don't understand this latter statement.  I guess it is related to
some form of padding I don't imagine, but I fail to understand why
using offset here is a better solution.

|       * src/system.h (alloca): Remove; decl no longer needed.
|       (<stddef.h>): Include, for offsetof.
|       (<inttypes.>, <stdint.h>): Include if available.
|       (uintptr_t): New type, if system lacks it.
|       (CALLOC, MALLOC, REALLOC): New macros.
|       All uses of XCALLOC, XMALLOC, and XREALLOC changed to use these
|       new macros.

If you think these macros are better, then they should probably make
their way into xalloc.h, and therefore the gnulib.




reply via email to

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