emacs-devel
[Top][All Lists]
Advanced

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

Re: [RFC, PATCH] shrink struct vectorlike_header #2


From: Paul Eggert
Subject: Re: [RFC, PATCH] shrink struct vectorlike_header #2
Date: Wed, 07 Nov 2012 21:25:26 -0800
User-agent: Mozilla/5.0 (X11; Linux i686; rv:16.0) Gecko/20121028 Thunderbird/16.0.2

On 11/07/2012 07:08 PM, Stefan Monnier wrote:
> I doubt (*(struct Lisp_Vector **)((char *) v + header_size))
> is any better.  I guess it just defeats gcc's detection of the problem.

Casting through char * is better, because the C standard
says that a compiler cannot do type-based alias inferencing
in the presence of char * pointers.  I presume this is why GCC
generates all those warnings when we don't use char * -- GCC is
warning us that it may be doing optimizations that will crash
our code.

But better yet would be to omit the casts entirely.
This might let GCC do more optimizations safely.  That is,
change struct Lisp_Vector to be something like this:

struct Lisp_Vector
  {
     struct vectorlike_header header;
     union
       {
          Lisp_Object contents[1];
          struct Lisp_Vector *next;
       } u;
  };

Replace all current uses of 'contents'
with 'u.contents', and then use u.next
when you want to use the memory as a next field.
No pointer-casts necessary, and the union is more likely to
work correctly and efficiency than either of the techniques
that involve casting pointers.



reply via email to

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