From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.devel Subject: Re: [RFC, PATCH] shrink struct vectorlike_header #2 Date: Wed, 07 Nov 2012 21:25:26 -0800 Organization: UCLA Computer Science Department Message-ID: <509B4246.2050203@cs.ucla.edu> References: <50766A2C.8070705@yandex.ru> <50994448.6020602@yandex.ru> <509A76F7.3050105@yandex.ru> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1352352336 20478 80.91.229.3 (8 Nov 2012 05:25:36 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 8 Nov 2012 05:25:36 +0000 (UTC) Cc: Dmitry Antipov , Emacs development discussions To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Nov 08 06:25:45 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TWKcb-0004q0-1i for ged-emacs-devel@m.gmane.org; Thu, 08 Nov 2012 06:25:45 +0100 Original-Received: from localhost ([::1]:40464 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TWKcR-0000cj-PK for ged-emacs-devel@m.gmane.org; Thu, 08 Nov 2012 00:25:35 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:47304) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TWKcO-0000cT-FI for emacs-devel@gnu.org; Thu, 08 Nov 2012 00:25:33 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TWKcN-0001D2-J1 for emacs-devel@gnu.org; Thu, 08 Nov 2012 00:25:32 -0500 Original-Received: from smtp.cs.ucla.edu ([131.179.128.62]:43356) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TWKcN-0001CK-DL for emacs-devel@gnu.org; Thu, 08 Nov 2012 00:25:31 -0500 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 2A791A60016; Wed, 7 Nov 2012 21:25:23 -0800 (PST) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Original-Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id pLa+5cQwls4O; Wed, 7 Nov 2012 21:25:22 -0800 (PST) Original-Received: from [192.168.1.3] (pool-108-23-119-2.lsanca.fios.verizon.net [108.23.119.2]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 98754A60001; Wed, 7 Nov 2012 21:25:22 -0800 (PST) User-Agent: Mozilla/5.0 (X11; Linux i686; rv:16.0) Gecko/20121028 Thunderbird/16.0.2 In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 131.179.128.62 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:154725 Archived-At: 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.