/pidgin/main: b6f09494adda: cross-win32: hide glib bug of mismat...

Daniel Atallah daniel.atallah at gmail.com
Thu Apr 17 10:05:27 EDT 2014


I don't think this is going to work correctly - we need to use g_stat
because it handles mapping the filename to the appropriate encoding before
calling the native API - internal strings in libpurple are UTF-8 and are
converted to w_char before calling _wstat().

If you look at
https://developer.gnome.org/glib/2.30/glib-File-Utilities.html#g-statthere's
an explanation of what's going on.

GStatBuf needs to be the 32-bit stat structure (since it's going to call
_wstat()) - this default behavior for mingw, but not for mingw64 or MSVC.

gstdio.h has some special handling for msvc, but not (yet?) for mingw64 (I
guess an upstream patch is probably appropriate to fix that).

If mingw64 is being used for 32-bit builds, we'll need to redefine stat to
_stat32 before gstdio.h is included or redefine GStatBuf to _stat32 after
the include.


On Apr 17, 2014 2:19 AM, "Tomasz Wasilczyk" <twasilczyk at pidgin.im> wrote:

> Changeset: b6f09494addae4f7f6ef7a59cf524203637cc807
> Author:  Tomasz Wasilczyk <twasilczyk at pidgin.im>
> Date:    2014-04-17 08:19 +0200
> Branch:  default
> URL: https://hg.pidgin.im/pidgin/main/rev/b6f09494adda
>
> Description:
>
> cross-win32: hide glib bug of mismatched g_stat and GStatBuf for win32
> (not win64)
>
> diffstat:
>
>  libpurple/glibcompat.h           |  12 ++++++++++++
>  libpurple/util.c                 |  15 ++++++++++-----
>  libpurple/win32/libc_interface.h |   1 +
>  3 files changed, 23 insertions(+), 5 deletions(-)
>
> diffs (59 lines):
>
> diff --git a/libpurple/glibcompat.h b/libpurple/glibcompat.h
> --- a/libpurple/glibcompat.h
> +++ b/libpurple/glibcompat.h
> @@ -148,6 +148,18 @@ static inline void g_object_class_instal
>  #endif /* < 2.36.0 */
>
>
> +/* glib's definition of g_stat+GStatBuf seems to be broken on 32-bit
> windows,
> + * so instead of relying on it, we'll define our own macros.
> + */
> +#if defined(_WIN32) && !defined(_MSC_VER) && !defined(_WIN64)
> +#  include <glib/gstdio.h>
> +typedef struct _stat64 GStatBuf64;
> +#  define GStatBuf GStatBuf64
> +#  undef g_stat
> +#  define g_stat _stat64
> +#endif
> +
> +
>  #ifdef __clang__
>
>  #undef G_GNUC_BEGIN_IGNORE_DEPRECATIONS
> diff --git a/libpurple/util.c b/libpurple/util.c
> --- a/libpurple/util.c
> +++ b/libpurple/util.c
> @@ -3095,12 +3095,17 @@ purple_util_write_data_to_file_absolute(
>                 return FALSE;
>         }
>         /* Use stat to be absolutely sure. */
> -       if ((g_stat(filename_temp, &st) == -1) || (st.st_size !=
> (off_t)real_size))
> -       {
> +       if (g_stat(filename_temp, &st) == -1) {
>                 purple_debug_error("util", "Error writing data to file %s:
> "
> -                                  "Incomplete file written; is your disk "
> -                                  "full?\n",
> -                                  filename_temp);
> +                       "couldn't g_stat file", filename_temp);
> +               g_free(filename_temp);
> +               return FALSE;
> +       }
> +       if (st.st_size != (off_t)real_size) {
> +               purple_debug_error("util", "Error writing data to file %s:
> "
> +                       "Incomplete file written (%" G_GSIZE_FORMAT " != %"
> +                       G_GSIZE_FORMAT "); is your disk full?",
> +                       filename_temp, (gsize)st.st_size, real_size);
>                 g_free(filename_temp);
>                 return FALSE;
>         }
> diff --git a/libpurple/win32/libc_interface.h
> b/libpurple/win32/libc_interface.h
> --- a/libpurple/win32/libc_interface.h
> +++ b/libpurple/win32/libc_interface.h
> @@ -28,6 +28,7 @@
>  #include <errno.h>
>  #include "libc_internal.h"
>  #include <glib.h>
> +#include "glibcompat.h"
>
>  #ifdef __cplusplus
>  extern "C" {
>
> _______________________________________________
> Commits mailing list
> Commits at pidgin.im
> https://pidgin.im/cgi-bin/mailman/listinfo/commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pidgin.im/pipermail/devel/attachments/20140417/f1e785fe/attachment.html>


More information about the Devel mailing list