Re: Why is sizeof(XID)==8 on AMD64?

2011-03-28 Thread Alan Coopersmith
On 03/28/11 07:35 AM, Matthieu Herrb wrote:
> Changing the APIs now would break too many things, an no one as ever
> considered  doing a new major revisition of all those APIs.

In some sense, libxcb is the major revision of the X client API,
which hopefully has fewer mistakes we won't realize for years and
then be stuck with for decades.   Because of libxcb, there's even
less incentive to try to do anything to "fix" the libX11 API.

-- 
-Alan Coopersmith-alan.coopersm...@oracle.com
 Oracle Solaris Platform Engineering: X Window System

___
xorg@lists.freedesktop.org: X.Org support
Archives: http://lists.freedesktop.org/archives/xorg
Info: http://lists.freedesktop.org/mailman/listinfo/xorg
Your subscription address: arch...@mail-archive.com


Re: Why is sizeof(XID)==8 on AMD64?

2011-03-28 Thread Matthieu Herrb
On Mon, Mar 28, 2011 at 04:47:18PM +0200, Clemens Eisserer wrote:
> Hi Matthieu,
> 
> Thanks for your explanation =)
> 
> > This is a mistake done 25 years ago or so. It's hard to justify it,
> > but it is so. A number of things that are 32 bits on the wire
> > are represented as 64 bits long at the API level on LP64 machines.
> 
> Is it considered more or less safe to store those 64-bit XIDs in 32bit
> variables?

Since they are 32 bits values at the protocol level, yes. 

> If not really required I would prefer not to change all my code.

But be careful everytime you pass your 32 bit variables to X functions
that expect 64 bit values, especially when a pointer to such a
variable is used (like in XChangeProperty() that I mentionned above).

On little endian architectures with weak alignment constaints passing
a pointer to a 32 bit only value won't harm too much since the low 32
bits will be used as expected. 

But on big endian architectures, it will use the the 32 higher bits of
the value you're pointing to, which are not well defined...

And if your architecture as strict aligment constraints for 64 bits
values, passing a pointer to a 32 bit data has great chances to
produce an unaligned access error.
-- 
Matthieu Herrb
___
xorg@lists.freedesktop.org: X.Org support
Archives: http://lists.freedesktop.org/archives/xorg
Info: http://lists.freedesktop.org/mailman/listinfo/xorg
Your subscription address: arch...@mail-archive.com


Re: Why is sizeof(XID)==8 on AMD64?

2011-03-28 Thread Clemens Eisserer
Hi Matthieu,

Thanks for your explanation =)

> This is a mistake done 25 years ago or so. It's hard to justify it,
> but it is so. A number of things that are 32 bits on the wire
> are represented as 64 bits long at the API level on LP64 machines.

Is it considered more or less safe to store those 64-bit XIDs in 32bit
variables?
If not really required I would prefer not to change all my code.

Thanks, Clemens
___
xorg@lists.freedesktop.org: X.Org support
Archives: http://lists.freedesktop.org/archives/xorg
Info: http://lists.freedesktop.org/mailman/listinfo/xorg
Your subscription address: arch...@mail-archive.com


Re: Why is sizeof(XID)==8 on AMD64?

2011-03-28 Thread Matthieu Herrb
On Mon, Mar 28, 2011 at 04:11:35PM +0200, Clemens Eisserer wrote:
> Hi,
> 
> I just ran in a couple of bugs because my code assumes sizeof(XID)==4
> on all platforms which doesn't seem to hold on AMD64.
> Whats the reason for XID to be 8bytes (unsigned long) on AMD64, I
> thought an x-id (in protocol sence) is defined as 4 bytes anyway?
> 
> Will Xlib/xcb ever return values which don't fit in 4 bytes? If so, I
> guess I have to change a lot of java-code which assumes this -
> otherwise I would only need to adapt the Java<-->Xlib interface a bit.
> 
> Thank you in advance, Clemens

This is a mistake done 25 years ago or so. It's hard to justify it, 
but it is so. A number of things that are 32 bits on the wire
are represented as 64 bits long at the API level on LP64 machines. 

You have to read the API manual pages carefully and follow them.

Changing the APIs now would break too many things, an no one as ever
considered  doing a new major revisition of all those APIs.

The most commonly mis-used API is probably XChangeProperty(), but 
others are similarly difficult. 

We also just discovered a number of issues in the XI2 API.

-- 
Matthieu Herrb
___
xorg@lists.freedesktop.org: X.Org support
Archives: http://lists.freedesktop.org/archives/xorg
Info: http://lists.freedesktop.org/mailman/listinfo/xorg
Your subscription address: arch...@mail-archive.com