From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Removing the usage of X structures (or their names) in independent code Date: Thu, 09 May 2019 09:06:02 +0300 Message-ID: <83d0ksgo1h.fsf@gnu.org> References: <875zqkdzfc.fsf@gmail.com> Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="203180"; mail-complaints-to="usenet@blaine.gmane.org" Cc: emacs-devel@gnu.org To: Alex Gramiak Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu May 09 08:25:26 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hOcUg-000qiN-K6 for ged-emacs-devel@m.gmane.org; Thu, 09 May 2019 08:25:26 +0200 Original-Received: from localhost ([127.0.0.1]:48933 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOcUf-00018Z-JD for ged-emacs-devel@m.gmane.org; Thu, 09 May 2019 02:25:25 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:46039) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOcCD-0001A6-Ee for emacs-devel@gnu.org; Thu, 09 May 2019 02:06:25 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:36779) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOcCC-00013m-1C; Thu, 09 May 2019 02:06:21 -0400 Original-Received: from [176.228.60.248] (port=3794 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1hOcC4-0002uM-SG; Thu, 09 May 2019 02:06:15 -0400 In-reply-to: <875zqkdzfc.fsf@gmail.com> (message from Alex Gramiak on Wed, 08 May 2019 22:28:23 -0600) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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" Xref: news.gmane.org gmane.emacs.devel:236324 Archived-At: > From: Alex Gramiak > Date: Wed, 08 May 2019 22:28:23 -0600 > > Numerous internal procedures in Emacs that aren't tied to X expect and > use structures with the same name as X structures: e.g., XColor, > XGCValues, GC, XRectangle, XChar2b, Display, Pixmap, Cursor. > > This poses an issue when attempting to use a non-X backend to Emacs that > conditionally uses X itself: name clashes occur between the structures > intended for use in the independent Emacs code and the internal X > structures. Workarounds using the preprocessor exist but are ugly and > fragile. > > What would be the preferred way to fix this situation? Two options are > to use typedefs for these structures like XImagePtr_or_DC, or to use > unions. Everything else being equal, I would prefer the union approach. Why do you prefer a union? It uglifies the code and makes it harder to read and understand. OTOH, having a backend-independent type (what you call "typedef") is much cleaner. > Alternatively, for structures like XColor, there could be new generic > structures that all the backends share, but that would involve some > overhead on the X side for conversion. If that new structure is defined as (for example) typedef XColor EColor; then there's no overhead at all: you could simply assign an EColor to XColor or even use the former directly in APIs that want the latter. For more complex situations, see what we do with 'struct font' and 'struct FOOfont' for font backend FOO. So I'm not sure what overhead did you have in mind.