[Top][All Lists]

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

Re: Removing the usage of X structures (or their names) in independent c

From: Eli Zaretskii
Subject: Re: Removing the usage of X structures (or their names) in independent code
Date: Thu, 09 May 2019 09:06:02 +0300

> From: Alex Gramiak <address@hidden>
> 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 via email to

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