Work with old and new glib

Avoids "deprecated" warnings.
This commit is contained in:
Behdad Esfahbod 2013-10-27 23:36:35 +01:00
parent 46a863d91d
commit c2bc818706
7 changed files with 30 additions and 10 deletions

View File

@ -34,7 +34,10 @@
#endif #endif
#ifdef HAVE_GLIB #ifdef HAVE_GLIB
#include <glib.h> # include <glib.h>
# if !GLIB_CHECK_VERSION (2, 22, 0)
# define g_mapped_file_unref g_mapped_file_free
# endif
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
@ -61,7 +64,7 @@ main (int argc, char **argv)
GMappedFile *mf = g_mapped_file_new (argv[1], false, NULL); GMappedFile *mf = g_mapped_file_new (argv[1], false, NULL);
font_data = g_mapped_file_get_contents (mf); font_data = g_mapped_file_get_contents (mf);
len = g_mapped_file_get_length (mf); len = g_mapped_file_get_length (mf);
destroy = (hb_destroy_func_t) g_mapped_file_free; destroy = (hb_destroy_func_t) g_mapped_file_unref;
user_data = (void *) mf; user_data = (void *) mf;
mm = HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE; mm = HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE;
#else #else

View File

@ -32,7 +32,10 @@
#include "hb-ot.h" #include "hb-ot.h"
#ifdef HAVE_GLIB #ifdef HAVE_GLIB
#include <glib.h> # include <glib.h>
# if !GLIB_CHECK_VERSION (2, 22, 0)
# define g_mapped_file_unref g_mapped_file_free
# endif
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
@ -59,7 +62,7 @@ main (int argc, char **argv)
GMappedFile *mf = g_mapped_file_new (argv[1], false, NULL); GMappedFile *mf = g_mapped_file_new (argv[1], false, NULL);
font_data = g_mapped_file_get_contents (mf); font_data = g_mapped_file_get_contents (mf);
len = g_mapped_file_get_length (mf); len = g_mapped_file_get_length (mf);
destroy = (hb_destroy_func_t) g_mapped_file_free; destroy = (hb_destroy_func_t) g_mapped_file_unref;
user_data = (void *) mf; user_data = (void *) mf;
mm = HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE; mm = HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE;
#else #else

View File

@ -32,7 +32,10 @@
#include "hb-ot.h" #include "hb-ot.h"
#ifdef HAVE_GLIB #ifdef HAVE_GLIB
#include <glib.h> # include <glib.h>
# if !GLIB_CHECK_VERSION (2, 22, 0)
# define g_mapped_file_unref g_mapped_file_free
# endif
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
@ -63,7 +66,7 @@ main (int argc, char **argv)
GMappedFile *mf = g_mapped_file_new (argv[1], false, NULL); GMappedFile *mf = g_mapped_file_new (argv[1], false, NULL);
font_data = g_mapped_file_get_contents (mf); font_data = g_mapped_file_get_contents (mf);
len = g_mapped_file_get_length (mf); len = g_mapped_file_get_length (mf);
destroy = (hb_destroy_func_t) g_mapped_file_free; destroy = (hb_destroy_func_t) g_mapped_file_unref;
user_data = (void *) mf; user_data = (void *) mf;
mm = HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE; mm = HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE;
#else #else

View File

@ -31,7 +31,10 @@
#include "hb.h" #include "hb.h"
#ifdef HAVE_GLIB #ifdef HAVE_GLIB
#include <glib.h> # include <glib.h>
# if !GLIB_CHECK_VERSION (2, 22, 0)
# define g_mapped_file_unref g_mapped_file_free
# endif
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
@ -62,7 +65,7 @@ main (int argc, char **argv)
GMappedFile *mf = g_mapped_file_new (argv[1], false, NULL); GMappedFile *mf = g_mapped_file_new (argv[1], false, NULL);
font_data = g_mapped_file_get_contents (mf); font_data = g_mapped_file_get_contents (mf);
len = g_mapped_file_get_length (mf); len = g_mapped_file_get_length (mf);
destroy = (hb_destroy_func_t) g_mapped_file_free; destroy = (hb_destroy_func_t) g_mapped_file_unref;
user_data = (void *) mf; user_data = (void *) mf;
mm = HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE; mm = HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE;
#else #else

View File

@ -436,11 +436,11 @@ font_options_t::get_font (void) const
font_data = g_mapped_file_get_contents (mf); font_data = g_mapped_file_get_contents (mf);
len = g_mapped_file_get_length (mf); len = g_mapped_file_get_length (mf);
if (len) { if (len) {
destroy = (hb_destroy_func_t) g_mapped_file_free; destroy = (hb_destroy_func_t) g_mapped_file_unref;
user_data = (void *) mf; user_data = (void *) mf;
mm = HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE; mm = HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE;
} else } else
g_mapped_file_free (mf); g_mapped_file_unref (mf);
} else { } else {
fail (false, "%s", error->message); fail (false, "%s", error->message);
//g_error_free (error); //g_error_free (error);

View File

@ -54,6 +54,10 @@
#include <glib.h> #include <glib.h>
#include <glib/gprintf.h> #include <glib/gprintf.h>
#if !GLIB_CHECK_VERSION (2, 22, 0)
# define g_mapped_file_unref g_mapped_file_free
#endif
#undef MIN #undef MIN
template <typename Type> static inline Type MIN (const Type &a, const Type &b) { return a < b ? a : b; } template <typename Type> static inline Type MIN (const Type &a, const Type &b) { return a < b ? a : b; }

View File

@ -81,7 +81,11 @@ struct view_cairo_t
helper_cairo_line_t &line = g_array_index (lines, helper_cairo_line_t, i); helper_cairo_line_t &line = g_array_index (lines, helper_cairo_line_t, i);
line.finish (); line.finish ();
} }
#if GLIB_CHECK_VERSION (2, 22, 0)
g_array_unref (lines);
#else
g_array_free (lines, TRUE); g_array_free (lines, TRUE);
#endif
} }
protected: protected: