After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 519137 - g_slice_dup macro needs cast for 64-bit platform
g_slice_dup macro needs cast for 64-bit platform
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
2.14.x
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2008-02-27 19:52 UTC by Martin Pokorny
Modified: 2008-04-10 21:40 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Martin Pokorny 2008-02-27 19:52:30 UTC
The g_slice_dup macro produces a warning under gcc 4.1.3. For example, with the following code snippet

    lf_lag_frame_t *new_key = g_slice_dup(lf_lag_frame_t, lf);

I get this error upon compilation:

    wcbe_sort.c:1494: warning: cast to pointer from integer of different size

This warning presents me with a problem when compiling with the gcc -Werror flag.

I have found a modification to the g_slice_dup macro to solve the problem.

$ diff /usr/include/glib-2.0/glib/gslice.h gslice.h.new 
57c57
<   (1 ? g_slice_copy (sizeof (type), (mem)) : (type*) ((type*) 0 == (mem)))
---
>   (1 ? g_slice_copy (sizeof (type), (mem)) : (type*) GINT_TO_POINTER ((type*) 0 == (mem)))

Of course, there might be better ways to solve the problem, but you get the idea.
Comment 1 Tim Janik 2008-03-04 09:43:53 UTC
(In reply to comment #0)
> >   (1 ? g_slice_copy (sizeof (type), (mem)) : (type*) GINT_TO_POINTER ((type*) 0 == (mem)))

thanks a lot for reporting and working out a fix. bratsche,tbf, can you please apply this?
Comment 2 Zbigniew Chyla 2008-04-10 20:43:50 UTC
Wouldn't it be cleaner to use comma operator instead?

(1 ? g_slice_copy (sizeof (type), (mem)) : ((void) ((type*) 0 == (mem)), (type*) 0))

There's also another problem with this macro: its type is gpointer (that's what g_slice_copy returns) and it should be "type *" according to the pseudo prototype in the header. Existing definition allows you to assign g_slice_copy(...) to any pointer variable without type errors.

With additional correction the macro would look like this:

(1 ? (type*) g_slice_copy (sizeof (type), (mem)) : ((void) ((type*) 0 == (mem)), (type*) 0))
Comment 3 Tim Janik 2008-04-10 21:04:31 UTC
(In reply to comment #2)
> Wouldn't it be cleaner to use comma operator instead?

> (1 ? (type*) g_slice_copy (sizeof (type), (mem)) : ((void) ((type*) 0 ==
> (mem)), (type*) 0))

thanks, this looks indeed preferrable.
Bratsche, tbf, can you please commit this?


Comment 4 Mathias Hasselmann (IRC: tbf) 2008-04-10 21:40:40 UTC
Bug 519137 – g_slice_dup macro needs cast for 64-bit platform
    
* glib/gslice.h (g_slice_copy): Apply type casts needed
  for proper compilation on 64-bit platforms.