unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Alex Gramiak <agrambot@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: Removing the usage of X structures (or their names) in independent code
Date: Thu, 09 May 2019 09:06:02 +0300	[thread overview]
Message-ID: <83d0ksgo1h.fsf@gnu.org> (raw)
In-Reply-To: <875zqkdzfc.fsf@gmail.com> (message from Alex Gramiak on Wed, 08 May 2019 22:28:23 -0600)

> From: Alex Gramiak <agrambot@gmail.com>
> 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.



  reply	other threads:[~2019-05-09  6:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-09  4:28 Removing the usage of X structures (or their names) in independent code Alex Gramiak
2019-05-09  6:06 ` Eli Zaretskii [this message]
2019-05-09 16:26   ` Alex Gramiak
2019-05-09 17:12     ` Eli Zaretskii
2019-05-11  5:45       ` Alex Gramiak
2019-05-13 16:15         ` Alex Gramiak
2019-05-13 17:40           ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83d0ksgo1h.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=agrambot@gmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).