/pidgin/main: b6f09494adda: cross-win32: hide glib bug of mismat...
Tomasz Wasilczyk
twasilczyk at pidgin.im
Thu Apr 17 11:28:05 EDT 2014
Thanks for tracing this.
I redefined GStatBuf to _stat [1], since _wstat takes exactly that type.
I agree upstream patch is necessary, but will not help when compiling
with older glib versions.
I think, we should ultimately switch to GFileInfo and redefine g_stat to
something like "use_gfileinfo_instead_of_g_stat".
Tomek
[1] http://hg.pidgin.im/pidgin/main/rev/4cd48601e1d1
W dniu 17.04.2014 16:05, Daniel Atallah pisze:
> 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-stat
> there'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
> <mailto:twasilczyk at pidgin.im>> wrote:
>
> Changeset: b6f09494addae4f7f6ef7a59cf524203637cc807
> Author: Tomasz Wasilczyk <twasilczyk at pidgin.im
> <mailto: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 <mailto:Commits at pidgin.im>
> https://pidgin.im/cgi-bin/mailman/listinfo/commits
>
>
>
> _______________________________________________
> Devel mailing list
> Devel at pidgin.im
> https://pidgin.im/cgi-bin/mailman/listinfo/devel
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4225 bytes
Desc: Kryptograficzna sygnatura S/MIME
URL: <https://pidgin.im/pipermail/devel/attachments/20140417/328376b9/attachment-0001.bin>
More information about the Devel
mailing list