X11 binding, XGetWindowProperty, and different behaviour for similar code between D and C++ (D fails)
Fawzi Mohamed
fmohamed at mac.com
Fri Apr 3 04:07:19 PDT 2009
On 2009-04-03 19:33:21 +0200, "Simon Gomizelj" <simongmzlj at gmail.com> said:
> On Thu, 02 Apr 2009 09:59:55 -0400, Jarrett Billingsley
> <jarrett.billingsley at gmail.com> wrote:
>
>> On Fri, Apr 3, 2009 at 4:40 AM, Simon Gomizelj <simongmzlj at gmail.com> wrote:
>>> On Fri, 03 Apr 2009 04:09:25 -0400, Simon Gomizelj <simongmzlj at gmail.com>
>>> wrote:
>>> [...]
>> My best guess is that you've translated those X11 function headers
>> incorrectly. Perhaps you've used a D long where you shouldn't have.
>> A D long is 64 bits, while a C long is 32, at least on 32-bit
>> platforms. If you were to pass a 64-bit value where it was expecting
>> a 32-bit one, the params would be in all the wrong places. But this
>> is just speculation, since I don't know what your bindings look like.
>
> Yeah, thats it exactly, which is annoying because since I downloaded
> this binding I just assumed it was done right 8-).
>
> extern (C):
> extern int XGetWindowProperty(
> Display* /* display */,
> Window /* w */,
> Atom /* property */,
> long /* long_offset */, <-- should be int
> long /* long_length */, <-- should be int
> Bool /* delete */,
> Atom /* req_type */,
> Atom* /* actual_type_return */,
> int* /* actual_format_return */,
> uint* /* nitems_return */,
> uint* /* bytes_after_return */,
> ubyte** /* prop_return */
> );
>
> Since their are no occurences of long longs I just did a search and
> replace across the whole file for longs to ints
actually the correct thing is to use c_long and c_ulong for that, c
long on 64 bit platform is 64 bit...
I think that typically long should have the same size as a pointer, I
even think that something along these lines is in the standard, but I
am not 100% sure.
anyway D c_long should correspond to c long. tango defines it in
tango.stdc.config, phobos probably in std.c.config (or something
similar I did not check)
Fawzi
More information about the Digitalmars-d
mailing list