Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atom defined as c_ulong #95

Closed
mickvangelderen opened this issue Jan 21, 2019 · 2 comments
Closed

Atom defined as c_ulong #95

mickvangelderen opened this issue Jan 21, 2019 · 2 comments

Comments

@mickvangelderen
Copy link

I am confused with the definition of Atom (and friends) in xlib.rs. The X protocol specification says it should be a 32 bit value. That is how it is defined in Xproto.h for me:

#define Atom CARD32

On my 64 bit machine, c_ulong ends up as a u64. Can anyone shed some light on this?

mickvangelderen added a commit to mickvangelderen/xcb-sys-rust that referenced this issue Jan 21, 2019
The x11 crate implements Atom and others as c_ulong.
See AltF02/x11-rs#95.
@ghost
Copy link

ghost commented Jan 26, 2019

It's because CARD32 itself is defined as unsigned long. The API has been around since long before the C standard had uint32_t, and int was only 16 bit in many implementations at the time. This crate has to do things exactly as the C libraries do for binary compatibility.

@mickvangelderen
Copy link
Author

Ah I see.

I'm trying to figure out how those basic X types are defined now but it isn't simple. The type definitions depend mostly on LONG64 and _XSERVER64 being defined or not. Also they're spread over multiple files like X.h, Xmd.h, Xproto.h, Xdefs.h and maybe more.

In Xproto.h the defintions are said to be overwritten and restored:

/* For the purpose of the structure definitions in this file,
we must redefine the following types in terms of Xmd.h's types, which may
include bit fields.  All of these are #undef'd at the end of this file,
restoring the definitions in X.h.  */

Then there's exceptions like this in XI.h

/*
 * Make XEventClass be a CARD32 for 64 bit servers.  Don't affect client
 * definition of XEventClass since that would be a library interface change.
 * See the top of X.h for more _XSERVER64 magic.
 *
 * But, don't actually use the CARD32 type.  We can't get it defined here
 * without polluting the namespace.
 */
#ifdef _XSERVER64
typedef	unsigned int	XEventClass;
#else
typedef	unsigned long	XEventClass;
#endif

Found this comment https://gitlab.freedesktop.org/xorg/xserver/issues/553#note_94062

For the second, it appears you've missed the _XSERVER64 definition that's required when building X server code on 64-bit systems - this is normally
defined in xorg-config.h, xorg-server.h, or dix-config.h depending on which
portion of the X server source code you're working in. The difference in types between clients & servers in 64-bit builds is a very sad mistake from the distant past we're stuck with to avoid breaking compatibility.

To me it looks like X clients use 64 bit integers for some types, but the data structures communicating with the X server (Xproto.h) use the right (as per the X protocol specification) integer widths. Approximately, probably.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant