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 754755 - playbin: Compiler warning with 64bit Windows target MinGW, cast to pointer from integer of different size
playbin: Compiler warning with 64bit Windows target MinGW, cast to pointer fr...
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-base
1.x
Other Windows
: Normal minor
: 1.5.91
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2015-09-09 04:33 UTC by Kouhei Sutou
Modified: 2015-09-12 09:48 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Fix this problem (1.73 KB, patch)
2015-09-09 04:33 UTC, Kouhei Sutou
none Details | Review
Use guintptr (2.14 KB, patch)
2015-09-11 14:49 UTC, Kouhei Sutou
committed Details | Review

Description Kouhei Sutou 2015-09-09 04:33:13 UTC
Created attachment 310945 [details] [review]
Fix this problem

We get the following error by building with 64bit Windows target MinGW:

----
gstplaybin2.c: In function 'pad_added_cb':
gstplaybin2.c:3476:7: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
       (gpointer) group_id_probe_handler);
       ^
cc1: all warnings being treated as errors
----

It shows that gulong to gpointer cast is warned.

We can use portable GUINT_TO_POINTER() macro for this propose.
Comment 1 Sebastian Dröge (slomo) 2015-09-09 07:03:42 UTC
Comment on attachment 310945 [details] [review]
Fix this problem

No that won't work as guint is not necessarily the same size as gulong. You need a GULONG_TO_POINTER and GPOINTER_TO_ULONG macro for this.

And for consistency the GPOINTER_TO_ULONG macro should be used in the other places.
Comment 2 Kouhei Sutou 2015-09-09 14:03:00 UTC
Unfortunately, GULONG_TO_PINTER() isn't provided by GLib.

But GUINT_TO_POINTER() works with gulong because GUINT_TO_PINTER() casts to gulong (or guint64) and then casts to gpointer.

https://developer.gnome.org/glib/stable/glib-Type-Conversion-Macros.html#GUINT-TO-POINTER:CAPS

> #define GUINT_TO_POINTER(u) ((gpointer) (gulong) (u))


GUINT_TO_POINTER() definition is different for 32bit Windows and 64bit Windows:

For 32bit Windows:

https://git.gnome.org/browse/glib/tree/glib/glibconfig.h.win32.in#n122

> #define GUINT_TO_POINTER(u)	((gpointer)  (u))

It directly casts to gpointer.

For 64bit Windows:

https://git.gnome.org/browse/glib/tree/glib/glibconfig.h.win32.in#n137

> #define GUINT_TO_POINTER(u)	((gpointer) (guint64) (u))

It casts to guint64 and then casts to gpointer.
Comment 3 Sebastian Dröge (slomo) 2015-09-09 14:10:20 UTC
I think instead of depending on this undocumented behaviour of the macros, we should rather define our own macros that explicitly do things via gulongs.
Comment 4 Kouhei Sutou 2015-09-11 12:55:19 UTC
If we define a macro, the following result may be helpful:

----
typedef unsigned long   gulong;
typedef void* gpointer;

#ifdef _WIN64
#  include <stdint.h>
typedef unsigned __int64 guint64;
#  define GST_ULONG_TO_POINTER(x) ((gpointer) (guint64) (x))
#else
#  define GST_ULONG_TO_POINTER(x) ((gpointer) (x))
#endif

int
main(void)
{
  gulong x = 0;
  gpointer y;

  y = GST_ULONG_TO_POINTER(x);
  y = (gpointer) x;

  return 0;
}
----

----
% gcc -Wall -Wno-unused-but-set-variable -o a.exe a.c
% i686-w64-mingw32-gcc -Wall -Wno-unused-but-set-variable -o a.exe a.c
% x86_64-w64-mingw32-gcc -Wall -Wno-unused-but-set-variable -o a.exe a.c
a.c: In function 'main':
a.c:19:7: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
   y = (gpointer) x;
       ^
----
Comment 5 Tim-Philipp Müller 2015-09-11 13:10:47 UTC
Try casting gpointer to guintptr and then guintptr to gulong.
And gulong to guintptr before casting guintptr to gpointer.
Comment 6 Kouhei Sutou 2015-09-11 13:49:54 UTC
----
typedef unsigned long   gulong;
typedef void* gpointer;

#ifdef _WIN64
#  include <stdint.h>
typedef unsigned __int64 guintptr;
#elif defined(_WIN32)
typedef unsigned int guintptr;
#else
typedef unsigned long guintptr;
#endif

#define GST_ULONG_TO_POINTER(x) ((gpointer) (guintptr) (x))

int
main(void)
{
  gulong x = 0;
  gpointer y;

  y = GST_ULONG_TO_POINTER(x);

  return 0;
}
----

----
% gcc -Wall -Wno-unused-but-set-variable -o a a.c
% i686-w64-mingw32-gcc -Wall -Wno-unused-but-set-variable -o a.exe a.c
% x86_64-w64-mingw32-gcc -Wall -Wno-unused-but-set-variable -o a.exe a.c
----
Comment 7 Sebastian Dröge (slomo) 2015-09-11 14:02:30 UTC
Looks good, do you want to provide an updated patch for this?
Comment 8 Kouhei Sutou 2015-09-11 14:26:04 UTC
No. Could you fix this?
Comment 9 Sebastian Dröge (slomo) 2015-09-11 14:27:12 UTC
No, because I don't have access to a Windows machine currently
Comment 10 Kouhei Sutou 2015-09-11 14:32:31 UTC
How about the following?

You need to just add GST_ULONG_TO_POINTER() macro and use it. If it doesn't work with MinGW, I'll send a patch.


I don't know where is the best place to define the macro.
Comment 11 Sebastian Dröge (slomo) 2015-09-11 14:38:15 UTC
Just inside gstplaybin2.c, #define a ULONG_TO_POINTER() macro and use it in the file :)
Comment 12 Kouhei Sutou 2015-09-11 14:49:53 UTC
Created attachment 311152 [details] [review]
Use guintptr
Comment 13 Sebastian Dröge (slomo) 2015-09-11 14:59:11 UTC
Looks good but I wonder why it doesn't complain in the code that converts the pointers to ulongs :)
Comment 14 Sebastian Dröge (slomo) 2015-09-11 21:28:28 UTC
Comment on attachment 311152 [details] [review]
Use guintptr

Merged and fixed to actually use the new macro. Thanks :)
Comment 15 Sebastian Dröge (slomo) 2015-09-11 21:30:35 UTC
commit ab64b00b48ab78496245d5bb0eda1d51fcb9e209
Author: Kouhei Sutou <kou@clear-code.com>
Date:   Fri Sep 11 23:48:05 2015 +0900

    playback: fix build error for 64bit Windows build by MinGW
    
    Casting to gpointer from gulong generates the following warning with
    64bit Windows target MinGW:
    
        gstplaybin2.c: In function 'pad_added_cb':
        gstplaybin2.c:3476:7: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
               (gpointer) group_id_probe_handler);
               ^
        cc1: all warnings being treated as errors
    
    We should cast to guintptr from gulong before we cast to gpointer.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=754755
Comment 16 Kouhei Sutou 2015-09-12 09:48:35 UTC
Oh... Sorry for my stupid patch...
I've confirmed that ULONG_TO_POINTER() works on x86_64-w64-mingw32-gcc.