diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2cffc0fc83..cccabaa4b8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -82,13 +82,16 @@ else()
endif()
include_directories(
- glib_compat
qemu
qemu/include
include
qemu/tcg
)
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
+set(UNICORN_LINK_LIBRARIES ${UNICORN_LINK_LIBRARIES} ${GLIB_LDFLAGS})
+
# Some distributions on some rare architecures don't auto link atomic for us and
# we do this manually by adding flags.
set(ATOMIC_LINKAGE_FIX FALSE)
@@ -1135,16 +1138,6 @@ set(UNICORN_COMMON_SRCS
list.c
- glib_compat/glib_compat.c
- glib_compat/gtestutils.c
- glib_compat/garray.c
- glib_compat/gtree.c
- glib_compat/grand.c
- glib_compat/glist.c
- glib_compat/gmem.c
- glib_compat/gpattern.c
- glib_compat/gslice.c
-
qemu/util/bitmap.c
qemu/util/bitops.c
qemu/util/crc32c.c
@@ -1399,6 +1392,10 @@ target_include_directories(unicorn PUBLIC
include
)
+target_include_directories(unicorn-common PUBLIC
+ ${GLIB_INCLUDE_DIRS}
+)
+
# For static archive
if (BUILD_SHARED_LIBS)
target_include_directories(unicorn_static PUBLIC
diff --git a/glib_compat/README b/glib_compat/README
deleted file mode 100644
index 7031488073..0000000000
--- a/glib_compat/README
+++ /dev/null
@@ -1,2 +0,0 @@
-This is a compatible glib library, customized for Unicorn.
-Based on glib 2.64.4.
diff --git a/glib_compat/garray.c b/glib_compat/garray.c
deleted file mode 100644
index 2ffe559a00..0000000000
--- a/glib_compat/garray.c
+++ /dev/null
@@ -1,1649 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see .
- */
-
-/*
- * Modified by the GLib Team and others 1997-2000. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-/*
- * MT safe
- */
-
-//#include "config.h"
-
-#include
-#include
-
-#include "glib_compat.h"
-
-#define g_mem_gc_friendly FALSE
-
-/**
- * SECTION:arrays
- * @title: Arrays
- * @short_description: arrays of arbitrary elements which grow
- * automatically as elements are added
- *
- * Arrays are similar to standard C arrays, except that they grow
- * automatically as elements are added.
- *
- * Array elements can be of any size (though all elements of one array
- * are the same size), and the array can be automatically cleared to
- * '0's and zero-terminated.
- *
- * To create a new array use g_array_new().
- *
- * To add elements to an array, use g_array_append_val(),
- * g_array_append_vals(), g_array_prepend_val(), and
- * g_array_prepend_vals().
- *
- * To access an element of an array, use g_array_index().
- *
- * To set the size of an array, use g_array_set_size().
- *
- * To free an array, use g_array_free().
- *
- * Here is an example that stores integers in a #GArray:
- * |[
- * GArray *garray;
- * gint i;
- * // We create a new array to store gint values.
- * // We don't want it zero-terminated or cleared to 0's.
- * garray = g_array_new (FALSE, FALSE, sizeof (gint));
- * for (i = 0; i < 10000; i++)
- * g_array_append_val (garray, i);
- * for (i = 0; i < 10000; i++)
- * if (g_array_index (garray, gint, i) != i)
- * g_print ("ERROR: got %d instead of %d\n",
- * g_array_index (garray, gint, i), i);
- * g_array_free (garray, TRUE);
- * ]|
- */
-
-#define MIN_ARRAY_SIZE 16
-
-typedef struct _GRealArray GRealArray;
-
-/**
- * GArray:
- * @data: a pointer to the element data. The data may be moved as
- * elements are added to the #GArray.
- * @len: the number of elements in the #GArray not including the
- * possible terminating zero element.
- *
- * Contains the public fields of a GArray.
- */
-struct _GRealArray
-{
- guint8 *data;
- guint len;
- guint alloc;
- guint elt_size;
- guint zero_terminated : 1;
- guint clear : 1;
- // gatomicrefcount ref_count;
- GDestroyNotify clear_func;
-};
-
-/**
- * g_array_index:
- * @a: a #GArray
- * @t: the type of the elements
- * @i: the index of the element to return
- *
- * Returns the element of a #GArray at the given index. The return
- * value is cast to the given type.
- *
- * This example gets a pointer to an element in a #GArray:
- * |[
- * EDayViewEvent *event;
- * // This gets a pointer to the 4th element in the array of
- * // EDayViewEvent structs.
- * event = &g_array_index (events, EDayViewEvent, 3);
- * ]|
- *
- * Returns: the element of the #GArray at the index given by @i
- */
-
-#define g_array_elt_len(array,i) ((array)->elt_size * (i))
-#define g_array_elt_pos(array,i) ((array)->data + g_array_elt_len((array),(i)))
-#define g_array_elt_zero(array, pos, len) \
- (memset (g_array_elt_pos ((array), pos), 0, g_array_elt_len ((array), len)))
-#define g_array_zero_terminate(array) G_STMT_START{ \
- if ((array)->zero_terminated) \
- g_array_elt_zero ((array), (array)->len, 1); \
-}G_STMT_END
-
-static guint g_nearest_pow (guint num);
-static void g_array_maybe_expand (GRealArray *array,
- guint len);
-
-/**
- * g_array_new:
- * @zero_terminated: %TRUE if the array should have an extra element at
- * the end which is set to 0
- * @clear_: %TRUE if #GArray elements should be automatically cleared
- * to 0 when they are allocated
- * @element_size: the size of each element in bytes
- *
- * Creates a new #GArray with a reference count of 1.
- *
- * Returns: the new #GArray
- */
-GArray* g_array_new (gboolean zero_terminated,
- gboolean clear,
- guint elt_size)
-{
- g_return_val_if_fail (elt_size > 0, NULL);
-
- return g_array_sized_new (zero_terminated, clear, elt_size, 0);
-}
-
-/**
- * g_array_sized_new:
- * @zero_terminated: %TRUE if the array should have an extra element at
- * the end with all bits cleared
- * @clear_: %TRUE if all bits in the array should be cleared to 0 on
- * allocation
- * @element_size: size of each element in the array
- * @reserved_size: number of elements preallocated
- *
- * Creates a new #GArray with @reserved_size elements preallocated and
- * a reference count of 1. This avoids frequent reallocation, if you
- * are going to add many elements to the array. Note however that the
- * size of the array is still 0.
- *
- * Returns: the new #GArray
- */
-GArray* g_array_sized_new (gboolean zero_terminated,
- gboolean clear,
- guint elt_size,
- guint reserved_size)
-{
- GRealArray *array;
-
- g_return_val_if_fail (elt_size > 0, NULL);
-
- array = g_slice_new (GRealArray);
-
- array->data = NULL;
- array->len = 0;
- array->alloc = 0;
- array->zero_terminated = (zero_terminated ? 1 : 0);
- array->clear = (clear ? 1 : 0);
- array->elt_size = elt_size;
- array->clear_func = NULL;
-
- // g_atomic_ref_count_init (&array->ref_count);
-
- if (array->zero_terminated || reserved_size != 0)
- {
- g_array_maybe_expand (array, reserved_size);
- g_array_zero_terminate(array);
- }
-
- return (GArray*) array;
-}
-
-/**
- * g_array_set_clear_func:
- * @array: A #GArray
- * @clear_func: a function to clear an element of @array
- *
- * Sets a function to clear an element of @array.
- *
- * The @clear_func will be called when an element in the array
- * data segment is removed and when the array is freed and data
- * segment is deallocated as well. @clear_func will be passed a
- * pointer to the element to clear, rather than the element itself.
- *
- * Note that in contrast with other uses of #GDestroyNotify
- * functions, @clear_func is expected to clear the contents of
- * the array element it is given, but not free the element itself.
- *
- * Since: 2.32
- */
-void g_array_set_clear_func (GArray *array,
- GDestroyNotify clear_func)
-{
- GRealArray *rarray = (GRealArray *) array;
-
- g_return_if_fail (array != NULL);
-
- rarray->clear_func = clear_func;
-}
-
-/**
- * g_array_ref:
- * @array: A #GArray
- *
- * Atomically increments the reference count of @array by one.
- * This function is thread-safe and may be called from any thread.
- *
- * Returns: The passed in #GArray
- *
- * Since: 2.22
- */
-GArray *g_array_ref (GArray *array)
-{
- //GRealArray *rarray = (GRealArray*) array;
- g_return_val_if_fail (array, NULL);
-
- // g_atomic_ref_count_inc (&rarray->ref_count);
-
- return array;
-}
-
-typedef enum
-{
- FREE_SEGMENT = 1 << 0,
- PRESERVE_WRAPPER = 1 << 1
-} ArrayFreeFlags;
-
-static gchar *array_free (GRealArray *, ArrayFreeFlags);
-
-/**
- * g_array_unref:
- * @array: A #GArray
- *
- * Atomically decrements the reference count of @array by one. If the
- * reference count drops to 0, all memory allocated by the array is
- * released. This function is thread-safe and may be called from any
- * thread.
- *
- * Since: 2.22
- */
-void g_array_unref (GArray *array)
-{
- GRealArray *rarray = (GRealArray*) array;
- g_return_if_fail (array);
-
- // if (g_atomic_ref_count_dec (&rarray->ref_count))
- array_free (rarray, FREE_SEGMENT);
-}
-
-/**
- * g_array_get_element_size:
- * @array: A #GArray
- *
- * Gets the size of the elements in @array.
- *
- * Returns: Size of each element, in bytes
- *
- * Since: 2.22
- */
-guint g_array_get_element_size (GArray *array)
-{
- GRealArray *rarray = (GRealArray*) array;
-
- g_return_val_if_fail (array, 0);
-
- return rarray->elt_size;
-}
-
-/**
- * g_array_free:
- * @array: a #GArray
- * @free_segment: if %TRUE the actual element data is freed as well
- *
- * Frees the memory allocated for the #GArray. If @free_segment is
- * %TRUE it frees the memory block holding the elements as well. Pass
- * %FALSE if you want to free the #GArray wrapper but preserve the
- * underlying array for use elsewhere. If the reference count of
- * @array is greater than one, the #GArray wrapper is preserved but
- * the size of @array will be set to zero.
- *
- * If array contents point to dynamically-allocated memory, they should
- * be freed separately if @free_seg is %TRUE and no @clear_func
- * function has been set for @array.
- *
- * This function is not thread-safe. If using a #GArray from multiple
- * threads, use only the atomic g_array_ref() and g_array_unref()
- * functions.
- *
- * Returns: the element data if @free_segment is %FALSE, otherwise
- * %NULL. The element data should be freed using g_free().
- */
-gchar *g_array_free (GArray *farray,
- gboolean free_segment)
-{
- GRealArray *array = (GRealArray*) farray;
- ArrayFreeFlags flags;
-
- g_return_val_if_fail (array, NULL);
-
- flags = (free_segment ? FREE_SEGMENT : 0);
-
- /* if others are holding a reference, preserve the wrapper but do free/return the data */
- //if (!g_atomic_ref_count_dec (&array->ref_count))
- flags |= PRESERVE_WRAPPER;
-
- return array_free (array, flags);
-}
-
-static gchar *array_free (GRealArray *array, ArrayFreeFlags flags)
-{
- gchar *segment;
-
- if (flags & FREE_SEGMENT)
- {
- if (array->clear_func != NULL)
- {
- guint i;
-
- for (i = 0; i < array->len; i++)
- array->clear_func (g_array_elt_pos (array, i));
- }
-
- g_free (array->data);
- segment = NULL;
- }
- else
- segment = (gchar*) array->data;
-
- if (flags & PRESERVE_WRAPPER)
- {
- array->data = NULL;
- array->len = 0;
- array->alloc = 0;
- }
- else
- {
- g_slice_free1 (sizeof (GRealArray), array);
- }
-
- return segment;
-}
-
-/**
- * g_array_append_vals:
- * @array: a #GArray
- * @data: (not nullable): a pointer to the elements to append to the end of the array
- * @len: the number of elements to append
- *
- * Adds @len elements onto the end of the array.
- *
- * Returns: the #GArray
- */
-/**
- * g_array_append_val:
- * @a: a #GArray
- * @v: the value to append to the #GArray
- *
- * Adds the value on to the end of the array. The array will grow in
- * size automatically if necessary.
- *
- * g_array_append_val() is a macro which uses a reference to the value
- * parameter @v. This means that you cannot use it with literal values
- * such as "27". You must use variables.
- *
- * Returns: the #GArray
- */
-GArray* g_array_append_vals (GArray *farray, gconstpointer data, guint len)
-{
- GRealArray *array = (GRealArray*) farray;
-
- g_return_val_if_fail (array, NULL);
-
- if (len == 0)
- return farray;
-
- g_array_maybe_expand (array, len);
-
- memcpy (g_array_elt_pos (array, array->len), data,
- g_array_elt_len (array, len));
-
- array->len += len;
-
- g_array_zero_terminate (array);
-
- return farray;
-}
-
-/**
- * g_array_prepend_vals:
- * @array: a #GArray
- * @data: (nullable): a pointer to the elements to prepend to the start of the array
- * @len: the number of elements to prepend, which may be zero
- *
- * Adds @len elements onto the start of the array.
- *
- * @data may be %NULL if (and only if) @len is zero. If @len is zero, this
- * function is a no-op.
- *
- * This operation is slower than g_array_append_vals() since the
- * existing elements in the array have to be moved to make space for
- * the new elements.
- *
- * Returns: the #GArray
- */
-/**
- * g_array_prepend_val:
- * @a: a #GArray
- * @v: the value to prepend to the #GArray
- *
- * Adds the value on to the start of the array. The array will grow in
- * size automatically if necessary.
- *
- * This operation is slower than g_array_append_val() since the
- * existing elements in the array have to be moved to make space for
- * the new element.
- *
- * g_array_prepend_val() is a macro which uses a reference to the value
- * parameter @v. This means that you cannot use it with literal values
- * such as "27". You must use variables.
- *
- * Returns: the #GArray
- */
-GArray* g_array_prepend_vals (GArray *farray, gconstpointer data, guint len)
-{
- GRealArray *array = (GRealArray*) farray;
-
- g_return_val_if_fail (array, NULL);
-
- if (len == 0)
- return farray;
-
- g_array_maybe_expand (array, len);
-
- memmove (g_array_elt_pos (array, len), g_array_elt_pos (array, 0),
- g_array_elt_len (array, array->len));
-
- memcpy (g_array_elt_pos (array, 0), data, g_array_elt_len (array, len));
-
- array->len += len;
-
- g_array_zero_terminate (array);
-
- return farray;
-}
-
-/**
- * g_array_insert_vals:
- * @array: a #GArray
- * @index_: the index to place the elements at
- * @data: (nullable): a pointer to the elements to insert
- * @len: the number of elements to insert
- *
- * Inserts @len elements into a #GArray at the given index.
- *
- * If @index_ is greater than the array's current length, the array is expanded.
- * The elements between the old end of the array and the newly inserted elements
- * will be initialised to zero if the array was configured to clear elements;
- * otherwise their values will be undefined.
- *
- * @data may be %NULL if (and only if) @len is zero. If @len is zero, this
- * function is a no-op.
- *
- * Returns: the #GArray
- */
-/**
- * g_array_insert_val:
- * @a: a #GArray
- * @i: the index to place the element at
- * @v: the value to insert into the array
- *
- * Inserts an element into an array at the given index.
- *
- * g_array_insert_val() is a macro which uses a reference to the value
- * parameter @v. This means that you cannot use it with literal values
- * such as "27". You must use variables.
- *
- * Returns: the #GArray
- */
-GArray* g_array_insert_vals (GArray *farray,
- guint index_,
- gconstpointer data,
- guint len)
-{
- GRealArray *array = (GRealArray*) farray;
-
- g_return_val_if_fail (array, NULL);
-
- if (len == 0)
- return farray;
-
- /* Is the index off the end of the array, and hence do we need to over-allocate
- * and clear some elements? */
- if (index_ >= array->len)
- {
- g_array_maybe_expand (array, index_ - array->len + len);
- return g_array_append_vals (g_array_set_size (farray, index_), data, len);
- }
-
- g_array_maybe_expand (array, len);
-
- memmove (g_array_elt_pos (array, len + index_),
- g_array_elt_pos (array, index_),
- g_array_elt_len (array, array->len - index_));
-
- memcpy (g_array_elt_pos (array, index_), data, g_array_elt_len (array, len));
-
- array->len += len;
-
- g_array_zero_terminate (array);
-
- return farray;
-}
-
-/**
- * g_array_set_size:
- * @array: a #GArray
- * @length: the new size of the #GArray
- *
- * Sets the size of the array, expanding it if necessary. If the array
- * was created with @clear_ set to %TRUE, the new elements are set to 0.
- *
- * Returns: the #GArray
- */
-GArray* g_array_set_size (GArray *farray,
- guint length)
-{
- GRealArray *array = (GRealArray*) farray;
-
- g_return_val_if_fail (array, NULL);
-
- if (length > array->len)
- {
- g_array_maybe_expand (array, length - array->len);
-
- if (array->clear)
- g_array_elt_zero (array, array->len, length - array->len);
- }
- else if (length < array->len)
- g_array_remove_range (farray, length, array->len - length);
-
- array->len = length;
-
- g_array_zero_terminate (array);
-
- return farray;
-}
-
-/**
- * g_array_remove_index:
- * @array: a #GArray
- * @index_: the index of the element to remove
- *
- * Removes the element at the given index from a #GArray. The following
- * elements are moved down one place.
- *
- * Returns: the #GArray
- */
-GArray* g_array_remove_index (GArray *farray,
- guint index_)
-{
- GRealArray* array = (GRealArray*) farray;
-
- g_return_val_if_fail (array, NULL);
-
- g_return_val_if_fail (index_ < array->len, NULL);
-
- if (array->clear_func != NULL)
- array->clear_func (g_array_elt_pos (array, index_));
-
- if (index_ != array->len - 1)
- memmove (g_array_elt_pos (array, index_),
- g_array_elt_pos (array, index_ + 1),
- g_array_elt_len (array, array->len - index_ - 1));
-
- array->len -= 1;
-
- if (g_mem_gc_friendly)
- g_array_elt_zero (array, array->len, 1);
- else
- g_array_zero_terminate (array);
-
- return farray;
-}
-
-/**
- * g_array_remove_index_fast:
- * @array: a @GArray
- * @index_: the index of the element to remove
- *
- * Removes the element at the given index from a #GArray. The last
- * element in the array is used to fill in the space, so this function
- * does not preserve the order of the #GArray. But it is faster than
- * g_array_remove_index().
- *
- * Returns: the #GArray
- */
-GArray* g_array_remove_index_fast (GArray *farray,
- guint index_)
-{
- GRealArray* array = (GRealArray*) farray;
-
- g_return_val_if_fail (array, NULL);
-
- g_return_val_if_fail (index_ < array->len, NULL);
-
- if (array->clear_func != NULL)
- array->clear_func (g_array_elt_pos (array, index_));
-
- if (index_ != array->len - 1)
- memcpy (g_array_elt_pos (array, index_),
- g_array_elt_pos (array, array->len - 1),
- g_array_elt_len (array, 1));
-
- array->len -= 1;
-
- if (g_mem_gc_friendly)
- g_array_elt_zero (array, array->len, 1);
- else
- g_array_zero_terminate (array);
-
- return farray;
-}
-
-/**
- * g_array_remove_range:
- * @array: a @GArray
- * @index_: the index of the first element to remove
- * @length: the number of elements to remove
- *
- * Removes the given number of elements starting at the given index
- * from a #GArray. The following elements are moved to close the gap.
- *
- * Returns: the #GArray
- *
- * Since: 2.4
- */
-GArray* g_array_remove_range (GArray *farray,
- guint index_,
- guint length)
-{
- GRealArray *array = (GRealArray*) farray;
-
- g_return_val_if_fail (array, NULL);
- g_return_val_if_fail (index_ <= array->len, NULL);
- g_return_val_if_fail (index_ + length <= array->len, NULL);
-
- if (array->clear_func != NULL)
- {
- guint i;
-
- for (i = 0; i < length; i++)
- array->clear_func (g_array_elt_pos (array, index_ + i));
- }
-
- if (index_ + length != array->len)
- memmove (g_array_elt_pos (array, index_),
- g_array_elt_pos (array, index_ + length),
- (array->len - (index_ + length)) * array->elt_size);
-
- array->len -= length;
- if (g_mem_gc_friendly)
- g_array_elt_zero (array, array->len, length);
- else
- g_array_zero_terminate (array);
-
- return farray;
-}
-
-/* Returns the smallest power of 2 greater than n, or n if
- * such power does not fit in a guint
- */
-static guint g_nearest_pow (guint num)
-{
- guint n = num - 1;
-
- g_assert (num > 0);
-
- n |= n >> 1;
- n |= n >> 2;
- n |= n >> 4;
- n |= n >> 8;
- n |= n >> 16;
-#if SIZEOF_INT == 8
- n |= n >> 32;
-#endif
-
- return n + 1;
-}
-
-static void g_array_maybe_expand (GRealArray *array, guint len)
-{
- guint want_alloc;
-
- /* Detect potential overflow */
- //if ((G_MAXUINT - array->len) < len)
- // g_error ("adding %u to array would overflow", len);
-
- want_alloc = g_array_elt_len (array, array->len + len +
- array->zero_terminated);
-
- if (want_alloc > array->alloc)
- {
- want_alloc = g_nearest_pow (want_alloc);
- want_alloc = MAX (want_alloc, MIN_ARRAY_SIZE);
-
- array->data = g_realloc (array->data, want_alloc);
-
- if (g_mem_gc_friendly)
- memset (array->data + array->alloc, 0, want_alloc - array->alloc);
-
- array->alloc = want_alloc;
- }
-}
-
-/**
- * SECTION:arrays_pointer
- * @title: Pointer Arrays
- * @short_description: arrays of pointers to any type of data, which
- * grow automatically as new elements are added
- *
- * Pointer Arrays are similar to Arrays but are used only for storing
- * pointers.
- *
- * If you remove elements from the array, elements at the end of the
- * array are moved into the space previously occupied by the removed
- * element. This means that you should not rely on the index of particular
- * elements remaining the same. You should also be careful when deleting
- * elements while iterating over the array.
- *
- * To create a pointer array, use g_ptr_array_new().
- *
- * To add elements to a pointer array, use g_ptr_array_add().
- *
- * To remove elements from a pointer array, use g_ptr_array_remove(),
- * g_ptr_array_remove_index() or g_ptr_array_remove_index_fast().
- *
- * To access an element of a pointer array, use g_ptr_array_index().
- *
- * To set the size of a pointer array, use g_ptr_array_set_size().
- *
- * To free a pointer array, use g_ptr_array_free().
- *
- * An example using a #GPtrArray:
- * |[
- * GPtrArray *array;
- * gchar *string1 = "one";
- * gchar *string2 = "two";
- * gchar *string3 = "three";
- *
- * array = g_ptr_array_new ();
- * g_ptr_array_add (array, (gpointer) string1);
- * g_ptr_array_add (array, (gpointer) string2);
- * g_ptr_array_add (array, (gpointer) string3);
- *
- * if (g_ptr_array_index (array, 0) != (gpointer) string1)
- * g_print ("ERROR: got %p instead of %p\n",
- * g_ptr_array_index (array, 0), string1);
- *
- * g_ptr_array_free (array, TRUE);
- * ]|
- */
-
-typedef struct _GRealPtrArray GRealPtrArray;
-
-/**
- * GPtrArray:
- * @pdata: points to the array of pointers, which may be moved when the
- * array grows
- * @len: number of pointers in the array
- *
- * Contains the public fields of a pointer array.
- */
-struct _GRealPtrArray
-{
- gpointer *pdata;
- guint len;
- guint alloc;
- // gatomicrefcount ref_count;
- GDestroyNotify element_free_func;
-};
-
-/**
- * g_ptr_array_index:
- * @array: a #GPtrArray
- * @index_: the index of the pointer to return
- *
- * Returns the pointer at the given index of the pointer array.
- *
- * This does not perform bounds checking on the given @index_,
- * so you are responsible for checking it against the array length.
- *
- * Returns: the pointer at the given index
- */
-
-static void g_ptr_array_maybe_expand (GRealPtrArray *array, guint len);
-
-/**
- * g_ptr_array_new:
- *
- * Creates a new #GPtrArray with a reference count of 1.
- *
- * Returns: the new #GPtrArray
- */
-GPtrArray *g_ptr_array_new (void)
-{
- return g_ptr_array_sized_new (0);
-}
-
-/**
- * g_ptr_array_steal:
- * @array: a #GPtrArray.
- * @len: (optional) (out caller-allocates): pointer to retrieve the number of
- * elements of the original array
- *
- * Frees the data in the array and resets the size to zero, while
- * the underlying array is preserved for use elsewhere and returned
- * to the caller.
- *
- * Even if set, the #GDestroyNotify function will never be called
- * on the current contents of the array and the caller is
- * responsible for freeing the array elements.
- *
- * An example of use:
- * |[
- * g_autoptr(GPtrArray) chunk_buffer = g_ptr_array_new_with_free_func (g_bytes_unref);
- *
- * // Some part of your application appends a number of chunks to the pointer array.
- * g_ptr_array_add (chunk_buffer, g_bytes_new_static ("hello", 5));
- * g_ptr_array_add (chunk_buffer, g_bytes_new_static ("world", 5));
- *
- * ...
- *
- * // Periodically, the chunks need to be sent as an array-and-length to some
- * // other part of the program.
- * GBytes **chunks;
- * gsize n_chunks;
- *
- * chunks = g_ptr_array_steal (chunk_buffer, &n_chunks);
- * for (gsize i = 0; i < n_chunks; i++)
- * {
- * // Do something with each chunk here, and then free them, since
- * // g_ptr_array_steal() transfers ownership of all the elements and the
- * // array to the caller.
- * ...
- *
- * g_bytes_unref (chunks[i]);
- * }
- *
- * g_free (chunks);
- *
- * // After calling g_ptr_array_steal(), the pointer array can be reused for the
- * // next set of chunks.
- * g_assert (chunk_buffer->len == 0);
- * ]|
- *
- * Returns: (transfer full): the element data, which should be
- * freed using g_free().
- *
- * Since: 2.64
- */
-gpointer *g_ptr_array_steal (GPtrArray *array, gsize *len)
-{
- GRealPtrArray *rarray;
- gpointer *segment;
-
- g_return_val_if_fail (array != NULL, NULL);
-
- rarray = (GRealPtrArray *) array;
- segment = (gpointer *) rarray->pdata;
-
- if (len != NULL)
- *len = rarray->len;
-
- rarray->pdata = NULL;
- rarray->len = 0;
- rarray->alloc = 0;
- return segment;
-}
-
-/**
- * g_ptr_array_copy:
- * @array: #GPtrArray to duplicate
- * @func: (nullable): a copy function used to copy every element in the array
- * @user_data: user data passed to the copy function @func, or %NULL
- *
- * Makes a full (deep) copy of a #GPtrArray.
- *
- * @func, as a #GCopyFunc, takes two arguments, the data to be copied
- * and a @user_data pointer. On common processor architectures, it's safe to
- * pass %NULL as @user_data if the copy function takes only one argument. You
- * may get compiler warnings from this though if compiling with GCC's
- * `-Wcast-function-type` warning.
- *
- * If @func is %NULL, then only the pointers (and not what they are
- * pointing to) are copied to the new #GPtrArray.
- *
- * The copy of @array will have the same #GDestroyNotify for its elements as
- * @array.
- *
- * Returns: (transfer full): a deep copy of the initial #GPtrArray.
- *
- * Since: 2.62
- **/
-GPtrArray *g_ptr_array_copy (GPtrArray *array, GCopyFunc func, gpointer user_data)
-{
- gsize i;
- GPtrArray *new_array;
-
- g_return_val_if_fail (array != NULL, NULL);
-
- new_array = g_ptr_array_sized_new (array->len);
- g_ptr_array_set_free_func (new_array, ((GRealPtrArray *) array)->element_free_func);
-
- if (func != NULL)
- {
- for (i = 0; i < array->len; i++)
- new_array->pdata[i] = func (array->pdata[i], user_data);
- }
- else if (array->len > 0)
- {
- memcpy (new_array->pdata, array->pdata,
- array->len * sizeof (*array->pdata));
- }
-
- new_array->len = array->len;
-
- return new_array;
-}
-
-/**
- * g_ptr_array_sized_new:
- * @reserved_size: number of pointers preallocated
- *
- * Creates a new #GPtrArray with @reserved_size pointers preallocated
- * and a reference count of 1. This avoids frequent reallocation, if
- * you are going to add many pointers to the array. Note however that
- * the size of the array is still 0.
- *
- * Returns: the new #GPtrArray
- */
-GPtrArray *g_ptr_array_sized_new (guint reserved_size)
-{
- GRealPtrArray *array;
-
- array = g_slice_new (GRealPtrArray);
-
- array->pdata = NULL;
- array->len = 0;
- array->alloc = 0;
- array->element_free_func = NULL;
-
- // g_atomic_ref_count_init (&array->ref_count);
-
- if (reserved_size != 0)
- g_ptr_array_maybe_expand (array, reserved_size);
-
- return (GPtrArray*) array;
-}
-
-/**
- * g_array_copy:
- * @array: A #GArray.
- *
- * Create a shallow copy of a #GArray. If the array elements consist of
- * pointers to data, the pointers are copied but the actual data is not.
- *
- * Returns: (transfer container): A copy of @array.
- *
- * Since: 2.62
- **/
-GArray *g_array_copy (GArray *array)
-{
- GRealArray *rarray = (GRealArray *) array;
- GRealArray *new_rarray;
-
- g_return_val_if_fail (rarray != NULL, NULL);
-
- new_rarray =
- (GRealArray *) g_array_sized_new (rarray->zero_terminated, rarray->clear,
- rarray->elt_size, rarray->alloc / rarray->elt_size);
- new_rarray->len = rarray->len;
- if (rarray->len > 0)
- memcpy (new_rarray->data, rarray->data, rarray->len * rarray->elt_size);
-
- g_array_zero_terminate (new_rarray);
-
- return (GArray *) new_rarray;
-}
-
-/**
- * g_ptr_array_new_with_free_func:
- * @element_free_func: (nullable): A function to free elements with
- * destroy @array or %NULL
- *
- * Creates a new #GPtrArray with a reference count of 1 and use
- * @element_free_func for freeing each element when the array is destroyed
- * either via g_ptr_array_unref(), when g_ptr_array_free() is called with
- * @free_segment set to %TRUE or when removing elements.
- *
- * Returns: A new #GPtrArray
- *
- * Since: 2.22
- */
-GPtrArray *g_ptr_array_new_with_free_func (GDestroyNotify element_free_func)
-{
- GPtrArray *array;
-
- array = g_ptr_array_new ();
- g_ptr_array_set_free_func (array, element_free_func);
-
- return array;
-}
-
-/**
- * g_ptr_array_new_full:
- * @reserved_size: number of pointers preallocated
- * @element_free_func: (nullable): A function to free elements with
- * destroy @array or %NULL
- *
- * Creates a new #GPtrArray with @reserved_size pointers preallocated
- * and a reference count of 1. This avoids frequent reallocation, if
- * you are going to add many pointers to the array. Note however that
- * the size of the array is still 0. It also set @element_free_func
- * for freeing each element when the array is destroyed either via
- * g_ptr_array_unref(), when g_ptr_array_free() is called with
- * @free_segment set to %TRUE or when removing elements.
- *
- * Returns: A new #GPtrArray
- *
- * Since: 2.30
- */
-GPtrArray *g_ptr_array_new_full (guint reserved_size, GDestroyNotify element_free_func)
-{
- GPtrArray *array;
-
- array = g_ptr_array_sized_new (reserved_size);
- g_ptr_array_set_free_func (array, element_free_func);
-
- return array;
-}
-
-/**
- * g_ptr_array_set_free_func:
- * @array: A #GPtrArray
- * @element_free_func: (nullable): A function to free elements with
- * destroy @array or %NULL
- *
- * Sets a function for freeing each element when @array is destroyed
- * either via g_ptr_array_unref(), when g_ptr_array_free() is called
- * with @free_segment set to %TRUE or when removing elements.
- *
- * Since: 2.22
- */
-void g_ptr_array_set_free_func (GPtrArray *array, GDestroyNotify element_free_func)
-{
- GRealPtrArray *rarray = (GRealPtrArray *)array;
-
- g_return_if_fail (array);
-
- rarray->element_free_func = element_free_func;
-}
-
-static void g_ptr_array_maybe_expand (GRealPtrArray *array, guint len)
-{
- /* Detect potential overflow */
- //if ((G_MAXUINT - array->len) < len)
- // g_error ("adding %u to array would overflow", len);
-
- if ((array->len + len) > array->alloc)
- {
- guint old_alloc = array->alloc;
- array->alloc = g_nearest_pow (array->len + len);
- array->alloc = MAX (array->alloc, MIN_ARRAY_SIZE);
- array->pdata = g_realloc (array->pdata, sizeof (gpointer) * array->alloc);
- if (g_mem_gc_friendly)
- for ( ; old_alloc < array->alloc; old_alloc++)
- array->pdata [old_alloc] = NULL;
- }
-}
-
-/**
- * g_ptr_array_set_size:
- * @array: a #GPtrArray
- * @length: the new length of the pointer array
- *
- * Sets the size of the array. When making the array larger,
- * newly-added elements will be set to %NULL. When making it smaller,
- * if @array has a non-%NULL #GDestroyNotify function then it will be
- * called for the removed elements.
- */
-void g_ptr_array_set_size (GPtrArray *array, gint length)
-{
- GRealPtrArray *rarray = (GRealPtrArray *)array;
- guint length_unsigned;
-
- g_return_if_fail (rarray);
- g_return_if_fail (rarray->len == 0 || (rarray->len != 0 && rarray->pdata != NULL));
- g_return_if_fail (length >= 0);
-
- length_unsigned = (guint) length;
-
- if (length_unsigned > rarray->len)
- {
- guint i;
- g_ptr_array_maybe_expand (rarray, (length_unsigned - rarray->len));
- /* This is not
- * memset (array->pdata + array->len, 0,
- * sizeof (gpointer) * (length_unsigned - array->len));
- * to make it really portable. Remember (void*)NULL needn't be
- * bitwise zero. It of course is silly not to use memset (..,0,..).
- */
- for (i = rarray->len; i < length_unsigned; i++)
- rarray->pdata[i] = NULL;
- }
- else if (length_unsigned < rarray->len)
- g_ptr_array_remove_range (array, length_unsigned, rarray->len - length_unsigned);
-
- rarray->len = length_unsigned;
-}
-
-static gpointer ptr_array_remove_index (GPtrArray *array,
- guint index_,
- gboolean fast,
- gboolean free_element)
-{
- GRealPtrArray *rarray = (GRealPtrArray *) array;
- gpointer result;
-
- g_return_val_if_fail (rarray, NULL);
- g_return_val_if_fail (rarray->len == 0 || (rarray->len != 0 && rarray->pdata != NULL), NULL);
-
- g_return_val_if_fail (index_ < rarray->len, NULL);
-
- result = rarray->pdata[index_];
-
- if (rarray->element_free_func != NULL && free_element)
- rarray->element_free_func (rarray->pdata[index_]);
-
- if (index_ != rarray->len - 1 && !fast)
- memmove (rarray->pdata + index_, rarray->pdata + index_ + 1,
- sizeof (gpointer) * (rarray->len - index_ - 1));
- else if (index_ != rarray->len - 1)
- rarray->pdata[index_] = rarray->pdata[rarray->len - 1];
-
- rarray->len -= 1;
-
- if (g_mem_gc_friendly)
- rarray->pdata[rarray->len] = NULL;
-
- return result;
-}
-
-/**
- * g_ptr_array_remove_index:
- * @array: a #GPtrArray
- * @index_: the index of the pointer to remove
- *
- * Removes the pointer at the given index from the pointer array.
- * The following elements are moved down one place. If @array has
- * a non-%NULL #GDestroyNotify function it is called for the removed
- * element. If so, the return value from this function will potentially point
- * to freed memory (depending on the #GDestroyNotify implementation).
- *
- * Returns: (nullable): the pointer which was removed
- */
-gpointer g_ptr_array_remove_index (GPtrArray *array, guint index_)
-{
- return ptr_array_remove_index (array, index_, FALSE, TRUE);
-}
-
-/**
- * g_ptr_array_remove_index_fast:
- * @array: a #GPtrArray
- * @index_: the index of the pointer to remove
- *
- * Removes the pointer at the given index from the pointer array.
- * The last element in the array is used to fill in the space, so
- * this function does not preserve the order of the array. But it
- * is faster than g_ptr_array_remove_index(). If @array has a non-%NULL
- * #GDestroyNotify function it is called for the removed element. If so, the
- * return value from this function will potentially point to freed memory
- * (depending on the #GDestroyNotify implementation).
- *
- * Returns: (nullable): the pointer which was removed
- */
-gpointer g_ptr_array_remove_index_fast (GPtrArray *array, guint index_)
-{
- return ptr_array_remove_index (array, index_, TRUE, TRUE);
-}
-
-/**
- * g_ptr_array_steal_index:
- * @array: a #GPtrArray
- * @index_: the index of the pointer to steal
- *
- * Removes the pointer at the given index from the pointer array.
- * The following elements are moved down one place. The #GDestroyNotify for
- * @array is *not* called on the removed element; ownership is transferred to
- * the caller of this function.
- *
- * Returns: (transfer full) (nullable): the pointer which was removed
- * Since: 2.58
- */
-gpointer g_ptr_array_steal_index (GPtrArray *array, guint index_)
-{
- return ptr_array_remove_index (array, index_, FALSE, FALSE);
-}
-
-/**
- * g_ptr_array_steal_index_fast:
- * @array: a #GPtrArray
- * @index_: the index of the pointer to steal
- *
- * Removes the pointer at the given index from the pointer array.
- * The last element in the array is used to fill in the space, so
- * this function does not preserve the order of the array. But it
- * is faster than g_ptr_array_steal_index(). The #GDestroyNotify for @array is
- * *not* called on the removed element; ownership is transferred to the caller
- * of this function.
- *
- * Returns: (transfer full) (nullable): the pointer which was removed
- * Since: 2.58
- */
-gpointer g_ptr_array_steal_index_fast (GPtrArray *array, guint index_)
-{
- return ptr_array_remove_index (array, index_, TRUE, FALSE);
-}
-
-/**
- * g_ptr_array_remove_range:
- * @array: a @GPtrArray
- * @index_: the index of the first pointer to remove
- * @length: the number of pointers to remove
- *
- * Removes the given number of pointers starting at the given index
- * from a #GPtrArray. The following elements are moved to close the
- * gap. If @array has a non-%NULL #GDestroyNotify function it is
- * called for the removed elements.
- *
- * Returns: the @array
- *
- * Since: 2.4
- */
-GPtrArray* g_ptr_array_remove_range (GPtrArray *array, guint index_, guint length)
-{
- GRealPtrArray *rarray = (GRealPtrArray *)array;
- guint n;
-
- g_return_val_if_fail (rarray != NULL, NULL);
- g_return_val_if_fail (rarray->len == 0 || (rarray->len != 0 && rarray->pdata != NULL), NULL);
- g_return_val_if_fail (index_ <= rarray->len, NULL);
- g_return_val_if_fail (index_ + length <= rarray->len, NULL);
-
- if (rarray->element_free_func != NULL)
- {
- for (n = index_; n < index_ + length; n++)
- rarray->element_free_func (rarray->pdata[n]);
- }
-
- if (index_ + length != rarray->len)
- {
- memmove (&rarray->pdata[index_],
- &rarray->pdata[index_ + length],
- (rarray->len - (index_ + length)) * sizeof (gpointer));
- }
-
- rarray->len -= length;
- if (g_mem_gc_friendly)
- {
- guint i;
- for (i = 0; i < length; i++)
- rarray->pdata[rarray->len + i] = NULL;
- }
-
- return array;
-}
-
-/**
- * g_ptr_array_remove:
- * @array: a #GPtrArray
- * @data: the pointer to remove
- *
- * Removes the first occurrence of the given pointer from the pointer
- * array. The following elements are moved down one place. If @array
- * has a non-%NULL #GDestroyNotify function it is called for the
- * removed element.
- *
- * It returns %TRUE if the pointer was removed, or %FALSE if the
- * pointer was not found.
- *
- * Returns: %TRUE if the pointer is removed, %FALSE if the pointer
- * is not found in the array
- */
-gboolean g_ptr_array_remove (GPtrArray *array, gpointer data)
-{
- guint i;
-
- g_return_val_if_fail (array, FALSE);
- g_return_val_if_fail (array->len == 0 || (array->len != 0 && array->pdata != NULL), FALSE);
-
- for (i = 0; i < array->len; i += 1)
- {
- if (array->pdata[i] == data)
- {
- g_ptr_array_remove_index (array, i);
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-/**
- * g_ptr_array_remove_fast:
- * @array: a #GPtrArray
- * @data: the pointer to remove
- *
- * Removes the first occurrence of the given pointer from the pointer
- * array. The last element in the array is used to fill in the space,
- * so this function does not preserve the order of the array. But it
- * is faster than g_ptr_array_remove(). If @array has a non-%NULL
- * #GDestroyNotify function it is called for the removed element.
- *
- * It returns %TRUE if the pointer was removed, or %FALSE if the
- * pointer was not found.
- *
- * Returns: %TRUE if the pointer was found in the array
- */
-gboolean g_ptr_array_remove_fast (GPtrArray *array, gpointer data)
-{
- GRealPtrArray *rarray = (GRealPtrArray *)array;
- guint i;
-
- g_return_val_if_fail (rarray, FALSE);
- g_return_val_if_fail (rarray->len == 0 || (rarray->len != 0 && rarray->pdata != NULL), FALSE);
-
- for (i = 0; i < rarray->len; i += 1)
- {
- if (rarray->pdata[i] == data)
- {
- g_ptr_array_remove_index_fast (array, i);
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-/**
- * g_ptr_array_add:
- * @array: a #GPtrArray
- * @data: the pointer to add
- *
- * Adds a pointer to the end of the pointer array. The array will grow
- * in size automatically if necessary.
- */
-void g_ptr_array_add (GPtrArray *array, gpointer data)
-{
- GRealPtrArray *rarray = (GRealPtrArray *)array;
-
- g_return_if_fail (rarray);
- g_return_if_fail (rarray->len == 0 || (rarray->len != 0 && rarray->pdata != NULL));
-
- g_ptr_array_maybe_expand (rarray, 1);
-
- rarray->pdata[rarray->len++] = data;
-}
-
-/**
- * g_ptr_array_extend:
- * @array_to_extend: a #GPtrArray.
- * @array: (transfer none): a #GPtrArray to add to the end of @array_to_extend.
- * @func: (nullable): a copy function used to copy every element in the array
- * @user_data: user data passed to the copy function @func, or %NULL
- *
- * Adds all pointers of @array to the end of the array @array_to_extend.
- * The array will grow in size automatically if needed. @array_to_extend is
- * modified in-place.
- *
- * @func, as a #GCopyFunc, takes two arguments, the data to be copied
- * and a @user_data pointer. On common processor architectures, it's safe to
- * pass %NULL as @user_data if the copy function takes only one argument. You
- * may get compiler warnings from this though if compiling with GCC's
- * `-Wcast-function-type` warning.
- *
- * If @func is %NULL, then only the pointers (and not what they are
- * pointing to) are copied to the new #GPtrArray.
- *
- * Since: 2.62
- **/
-void g_ptr_array_extend (GPtrArray *array_to_extend,
- GPtrArray *array,
- GCopyFunc func,
- gpointer user_data)
-{
- GRealPtrArray *rarray_to_extend = (GRealPtrArray *) array_to_extend;
- gsize i;
-
- g_return_if_fail (array_to_extend != NULL);
- g_return_if_fail (array != NULL);
-
- g_ptr_array_maybe_expand (rarray_to_extend, array->len);
-
- if (func != NULL)
- {
- for (i = 0; i < array->len; i++)
- rarray_to_extend->pdata[i + rarray_to_extend->len] =
- func (array->pdata[i], user_data);
- }
- else if (array->len > 0)
- {
- memcpy (rarray_to_extend->pdata + rarray_to_extend->len, array->pdata,
- array->len * sizeof (*array->pdata));
- }
-
- rarray_to_extend->len += array->len;
-}
-
-/**
- * g_ptr_array_insert:
- * @array: a #GPtrArray
- * @index_: the index to place the new element at, or -1 to append
- * @data: the pointer to add.
- *
- * Inserts an element into the pointer array at the given index. The
- * array will grow in size automatically if necessary.
- *
- * Since: 2.40
- */
-void g_ptr_array_insert (GPtrArray *array, gint index_, gpointer data)
-{
- GRealPtrArray *rarray = (GRealPtrArray *)array;
-
- g_return_if_fail (rarray);
- g_return_if_fail (index_ >= -1);
- g_return_if_fail (index_ <= (gint)rarray->len);
-
- g_ptr_array_maybe_expand (rarray, 1);
-
- if (index_ < 0)
- index_ = rarray->len;
-
- if ((guint) index_ < rarray->len)
- memmove (&(rarray->pdata[index_ + 1]),
- &(rarray->pdata[index_]),
- (rarray->len - index_) * sizeof (gpointer));
-
- rarray->len++;
- rarray->pdata[index_] = data;
-}
-
-/**
- * g_ptr_array_foreach:
- * @array: a #GPtrArray
- * @func: the function to call for each array element
- * @user_data: user data to pass to the function
- *
- * Calls a function for each element of a #GPtrArray. @func must not
- * add elements to or remove elements from the array.
- *
- * Since: 2.4
- */
-void g_ptr_array_foreach (GPtrArray *array, GFunc func, gpointer user_data)
-{
- guint i;
-
- g_return_if_fail (array);
-
- for (i = 0; i < array->len; i++)
- (*func) (array->pdata[i], user_data);
-}
-
-/**
- * SECTION:arrays_byte
- * @title: Byte Arrays
- * @short_description: arrays of bytes
- *
- * #GByteArray is a mutable array of bytes based on #GArray, to provide arrays
- * of bytes which grow automatically as elements are added.
- *
- * To create a new #GByteArray use g_byte_array_new(). To add elements to a
- * #GByteArray, use g_byte_array_append(), and g_byte_array_prepend().
- *
- * To set the size of a #GByteArray, use g_byte_array_set_size().
- *
- * To free a #GByteArray, use g_byte_array_free().
- *
- * An example for using a #GByteArray:
- * |[
- * GByteArray *gbarray;
- * gint i;
- *
- * gbarray = g_byte_array_new ();
- * for (i = 0; i < 10000; i++)
- * g_byte_array_append (gbarray, (guint8*) "abcd", 4);
- *
- * for (i = 0; i < 10000; i++)
- * {
- * g_assert (gbarray->data[4*i] == 'a');
- * g_assert (gbarray->data[4*i+1] == 'b');
- * g_assert (gbarray->data[4*i+2] == 'c');
- * g_assert (gbarray->data[4*i+3] == 'd');
- * }
- *
- * g_byte_array_free (gbarray, TRUE);
- * ]|
- *
- * See #GBytes if you are interested in an immutable object representing a
- * sequence of bytes.
- */
-
-/**
- * GByteArray:
- * @data: a pointer to the element data. The data may be moved as
- * elements are added to the #GByteArray
- * @len: the number of elements in the #GByteArray
- *
- * Contains the public fields of a GByteArray.
- */
-
-/**
- * g_byte_array_new:
- *
- * Creates a new #GByteArray with a reference count of 1.
- *
- * Returns: (transfer full): the new #GByteArray
- */
-GByteArray *g_byte_array_new (void)
-{
- return (GByteArray *)g_array_sized_new (FALSE, FALSE, 1, 0);
-}
-
-/**
- * g_byte_array_sized_new:
- * @reserved_size: number of bytes preallocated
- *
- * Creates a new #GByteArray with @reserved_size bytes preallocated.
- * This avoids frequent reallocation, if you are going to add many
- * bytes to the array. Note however that the size of the array is still
- * 0.
- *
- * Returns: the new #GByteArray
- */
-GByteArray* g_byte_array_sized_new (guint reserved_size)
-{
- return (GByteArray *)g_array_sized_new (FALSE, FALSE, 1, reserved_size);
-}
-
-/**
- * g_byte_array_free:
- * @array: a #GByteArray
- * @free_segment: if %TRUE the actual byte data is freed as well
- *
- * Frees the memory allocated by the #GByteArray. If @free_segment is
- * %TRUE it frees the actual byte data. If the reference count of
- * @array is greater than one, the #GByteArray wrapper is preserved but
- * the size of @array will be set to zero.
- *
- * Returns: the element data if @free_segment is %FALSE, otherwise
- * %NULL. The element data should be freed using g_free().
- */
-guint8* g_byte_array_free (GByteArray *array, gboolean free_segment)
-{
- return (guint8 *)g_array_free ((GArray *)array, free_segment);
-}
-
-/**
- * g_byte_array_append:
- * @array: a #GByteArray
- * @data: the byte data to be added
- * @len: the number of bytes to add
- *
- * Adds the given bytes to the end of the #GByteArray.
- * The array will grow in size automatically if necessary.
- *
- * Returns: the #GByteArray
- */
-GByteArray* g_byte_array_append (GByteArray *array, const guint8 *data, guint len)
-{
- g_array_append_vals ((GArray *)array, (guint8 *)data, len);
-
- return array;
-}
-
-/**
- * g_byte_array_prepend:
- * @array: a #GByteArray
- * @data: the byte data to be added
- * @len: the number of bytes to add
- *
- * Adds the given data to the start of the #GByteArray.
- * The array will grow in size automatically if necessary.
- *
- * Returns: the #GByteArray
- */
-GByteArray *g_byte_array_prepend (GByteArray *array, const guint8 *data, guint len)
-{
- g_array_prepend_vals ((GArray *)array, (guint8 *)data, len);
-
- return array;
-}
-
-/**
- * g_byte_array_set_size:
- * @array: a #GByteArray
- * @length: the new size of the #GByteArray
- *
- * Sets the size of the #GByteArray, expanding it if necessary.
- *
- * Returns: the #GByteArray
- */
-GByteArray *g_byte_array_set_size (GByteArray *array, guint length)
-{
- g_array_set_size ((GArray *)array, length);
-
- return array;
-}
diff --git a/glib_compat/garray.h b/glib_compat/garray.h
deleted file mode 100644
index 020539aeec..0000000000
--- a/glib_compat/garray.h
+++ /dev/null
@@ -1,99 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see .
- */
-
-/*
- * Modified by the GLib Team and others 1997-2000. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-#ifndef __G_ARRAY_H__
-#define __G_ARRAY_H__
-
-#include "gtypes.h"
-
-typedef struct _GBytes GBytes;
-typedef struct _GArray GArray;
-typedef struct _GByteArray GByteArray;
-typedef struct _GPtrArray GPtrArray;
-
-struct _GArray
-{
- gchar *data;
- guint len;
-};
-
-struct _GByteArray
-{
- guint8 *data;
- guint len;
-};
-
-struct _GPtrArray
-{
- gpointer *pdata;
- guint len;
-};
-
-/* Resizable arrays. remove fills any cleared spot and shortens the
- * array, while preserving the order. remove_fast will distort the
- * order by moving the last element to the position of the removed.
- */
-
-#define g_array_append_val(a,v) g_array_append_vals (a, &(v), 1)
-#define g_array_index(a,t,i) (((t*) (void *) (a)->data) [(i)])
-
-GArray* g_array_append_vals (GArray *array,
- gconstpointer data,
- guint len);
-
-GArray* g_array_new (gboolean zero_terminated, gboolean clear_, guint element_size);
-GArray* g_array_sized_new (gboolean zero_terminated,
- gboolean clear_,
- guint element_size,
- guint reserved_size);
-
-gchar* g_array_free(GArray *array, gboolean free_segment);
-GArray* g_array_set_size(GArray *array, guint length);
-GArray*
-g_array_remove_range (GArray *farray,
- guint index_,
- guint length);
-
-void g_ptr_array_set_free_func (GPtrArray *array,
- GDestroyNotify element_free_func);
-
-/* Resizable pointer array. This interface is much less complicated
- * than the above. Add appends a pointer. Remove fills any cleared
- * spot and shortens the array. remove_fast will again distort order.
- */
-#define g_ptr_array_index(array,index_) ((array)->pdata)[index_]
-GPtrArray* g_ptr_array_new_with_free_func (GDestroyNotify element_free_func);
-void g_ptr_array_add(GPtrArray *array, gpointer data);
-GPtrArray* g_ptr_array_sized_new (guint reserved_size);
-GPtrArray* g_ptr_array_remove_range (GPtrArray *array, guint index_, guint length);
-
-/* Byte arrays, an array of guint8. Implemented as a GArray,
- * but type-safe.
- */
-GByteArray* g_byte_array_sized_new(guint reserved_size);
-guint8* g_byte_array_free(GByteArray *array, gboolean free_segment);
-GByteArray* g_byte_array_append(GByteArray *array, const guint8 *data, guint len);
-GByteArray* g_byte_array_set_size(GByteArray *array, guint length);
-
-#endif /* __G_ARRAY_H__ */
diff --git a/glib_compat/ghash.h b/glib_compat/ghash.h
deleted file mode 100644
index a4916a9d30..0000000000
--- a/glib_compat/ghash.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see .
- */
-
-/*
- * Modified by the GLib Team and others 1997-2000. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-#ifndef __G_HASH_H__
-#define __G_HASH_H__
-
-#include "gtypes.h"
-
-typedef struct _GHashTable GHashTable;
-
-typedef gboolean (*GHRFunc) (gpointer key, gpointer value, gpointer user_data);
-
-struct _GHashTableIter
-{
- /*< private >*/
- gpointer dummy1;
- gpointer dummy2;
- gpointer dummy3;
- int dummy4;
- gboolean dummy5;
- gpointer dummy6;
-};
-
-GHashTable* g_hash_table_new (GHashFunc hash_func, GEqualFunc key_equal_func);
-
-GHashTable* g_hash_table_new_full (GHashFunc hash_func,
- GEqualFunc key_equal_func,
- GDestroyNotify key_destroy_func,
- GDestroyNotify value_destroy_func);
-
-void g_hash_table_destroy (GHashTable *hash_table);
-
-gboolean g_hash_table_insert (GHashTable *hash_table, gpointer key, gpointer value);
-
-void g_hash_table_replace (GHashTable *hash_table, gpointer key, gpointer value);
-
-gboolean g_hash_table_remove (GHashTable *hash_table, gconstpointer key);
-
-void g_hash_table_remove_all (GHashTable *hash_table);
-
-gpointer g_hash_table_lookup (GHashTable *hash_table, gconstpointer key);
-
-void g_hash_table_foreach (GHashTable *hash_table, GHFunc func, gpointer user_data);
-
-guint g_hash_table_size (GHashTable *hash_table);
-
-GHashTable* g_hash_table_ref (GHashTable *hash_table);
-
-void g_hash_table_unref (GHashTable *hash_table);
-
-/* Hash Functions
- */
-gboolean g_int_equal (gconstpointer v1, gconstpointer v2);
-guint g_int_hash (gconstpointer v);
-
-#endif /* __G_HASH_H__ */
diff --git a/glib_compat/glib_compat.c b/glib_compat/glib_compat.c
deleted file mode 100644
index 2bb718283d..0000000000
--- a/glib_compat/glib_compat.c
+++ /dev/null
@@ -1,1492 +0,0 @@
-/*
- glib_compat.c replacement functionality for glib code used in qemu
- Copyright (C) 2016 Chris Eagle cseagle at gmail dot com
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-// Part of this code was lifted from glib-2.28.0.
-// Glib license is available in COPYING_GLIB file in root directory.
-
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
-#endif
-
-#include
-#include
-#include
-#include
-
-#include "glib_compat.h"
-
-#ifndef _WIN64
-#define GPOINTER_TO_UINT(p) ((guint)(uintptr_t)(p))
-#else
-#define GPOINTER_TO_UINT(p) ((guint) (guint64) (p))
-#endif
-
-/* All functions below added to eliminate GLIB dependency */
-
-/* hashing and equality functions */
-// Hash functions lifted glib-2.28.0/glib/ghash.c
-
-/**
- * g_direct_hash:
- * @v: a #gpointer key
- *
- * Converts a gpointer to a hash value.
- * It can be passed to g_hash_table_new() as the @hash_func parameter,
- * when using pointers as keys in a #GHashTable.
- *
- * Returns: a hash value corresponding to the key.
- */
-static guint g_direct_hash (gconstpointer v)
-{
- return GPOINTER_TO_UINT (v);
-}
-
-// g_str_hash() is lifted glib-2.28.0/glib/gstring.c
-/**
- * g_str_hash:
- * @v: a string key
- *
- * Converts a string to a hash value.
- *
- * This function implements the widely used "djb" hash apparently posted
- * by Daniel Bernstein to comp.lang.c some time ago. The 32 bit
- * unsigned hash value starts at 5381 and for each byte 'c' in the
- * string, is updated: hash = hash * 33 + c. This
- * function uses the signed value of each byte.
- *
- * It can be passed to g_hash_table_new() as the @hash_func parameter,
- * when using strings as keys in a #GHashTable.
- *
- * Returns: a hash value corresponding to the key
- **/
-guint g_str_hash (gconstpointer v)
-{
- const signed char *p;
- guint32 h = 5381;
-
- for (p = v; *p != '\0'; p++)
- h = (h << 5) + h + *p;
-
- return h;
-}
-
-gboolean g_str_equal(gconstpointer v1, gconstpointer v2)
-{
- return strcmp((const char*)v1, (const char*)v2) == 0;
-}
-
-// g_int_hash() is lifted from glib-2.28.0/glib/gutils.c
-/**
- * g_int_hash:
- * @v: a pointer to a #gint key
- *
- * Converts a pointer to a #gint to a hash value.
- * It can be passed to g_hash_table_new() as the @hash_func parameter,
- * when using pointers to integers values as keys in a #GHashTable.
- *
- * Returns: a hash value corresponding to the key.
- */
-guint g_int_hash (gconstpointer v)
-{
- return *(const gint*) v;
-}
-
-gboolean g_int_equal(gconstpointer v1, gconstpointer v2)
-{
- return *((const gint*)v1) == *((const gint*)v2);
-}
-
-/* Doubly-linked list */
-
-GList *g_list_first(GList *list)
-{
- if (list == NULL) return NULL;
- while (list->prev) list = list->prev;
- return list;
-}
-
-void g_list_foreach(GList *list, GFunc func, gpointer user_data)
-{
- GList *lp;
- for (lp = list; lp; lp = lp->next) {
- (*func)(lp->data, user_data);
- }
-}
-
-void g_list_free(GList *list)
-{
- GList *lp, *next, *prev = NULL;
- if (list) prev = list->prev;
- for (lp = list; lp; lp = next) {
- next = lp->next;
- free(lp);
- }
- for (lp = prev; lp; lp = prev) {
- prev = lp->prev;
- free(lp);
- }
-}
-
-GList *g_list_insert_sorted(GList *list, gpointer data, GCompareFunc compare)
-{
- GList *i;
- GList *n = (GList*)g_malloc(sizeof(GList));
- n->data = data;
- if (list == NULL) {
- n->next = n->prev = NULL;
- return n;
- }
- for (i = list; i; i = i->next) {
- n->prev = i->prev;
- if ((*compare)(data, i->data) <= 0) {
- n->next = i;
- i->prev = n;
- if (i == list) return n;
- else return list;
- }
- }
- n->prev = n->prev->next;
- n->next = NULL;
- n->prev->next = n;
- return list;
-}
-
-GList *g_list_prepend(GList *list, gpointer data)
-{
- GList *n = (GList*)g_malloc(sizeof(GList));
- n->next = list;
- n->prev = NULL;
- n->data = data;
- return n;
-}
-
-GList *g_list_remove_link(GList *list, GList *llink)
-{
- if (llink) {
- if (llink == list) list = list->next;
- if (llink->prev) llink->prev->next = llink->next;
- if (llink->next) llink->next->prev = llink->prev;
- }
- return list;
-}
-
-// code copied from glib/glist.c, version 2.28.0
-static GList *g_list_sort_merge(GList *l1,
- GList *l2,
- GFunc compare_func,
- gpointer user_data)
-{
- GList list, *l, *lprev;
- gint cmp;
-
- l = &list;
- lprev = NULL;
-
- while (l1 && l2)
- {
- cmp = ((GCompareDataFunc) compare_func) (l1->data, l2->data, user_data);
-
- if (cmp <= 0)
- {
- l->next = l1;
- l1 = l1->next;
- }
- else
- {
- l->next = l2;
- l2 = l2->next;
- }
- l = l->next;
- l->prev = lprev;
- lprev = l;
- }
- l->next = l1 ? l1 : l2;
- l->next->prev = l;
-
- return list.next;
-}
-
-static GList *g_list_sort_real(GList *list,
- GFunc compare_func,
- gpointer user_data)
-{
- GList *l1, *l2;
-
- if (!list)
- return NULL;
- if (!list->next)
- return list;
-
- l1 = list;
- l2 = list->next;
-
- while ((l2 = l2->next) != NULL)
- {
- if ((l2 = l2->next) == NULL)
- break;
- l1 = l1->next;
- }
- l2 = l1->next;
- l1->next = NULL;
-
- return g_list_sort_merge (g_list_sort_real (list, compare_func, user_data),
- g_list_sort_real (l2, compare_func, user_data),
- compare_func,
- user_data);
-}
-
-/**
- * g_list_sort:
- * @list: a #GList
- * @compare_func: the comparison function used to sort the #GList.
- * This function is passed the data from 2 elements of the #GList
- * and should return 0 if they are equal, a negative value if the
- * first element comes before the second, or a positive value if
- * the first element comes after the second.
- *
- * Sorts a #GList using the given comparison function.
- *
- * Returns: the start of the sorted #GList
- */
-/**
- * GCompareFunc:
- * @a: a value.
- * @b: a value to compare with.
- * @Returns: negative value if @a < @b; zero if @a = @b; positive
- * value if @a > @b.
- *
- * Specifies the type of a comparison function used to compare two
- * values. The function should return a negative integer if the first
- * value comes before the second, 0 if they are equal, or a positive
- * integer if the first value comes after the second.
- **/
-GList *g_list_sort (GList *list, GCompareFunc compare_func)
-{
- return g_list_sort_real (list, (GFunc) compare_func, NULL);
-}
-
-/* END of g_list related functions */
-
-/* Singly-linked list */
-
-GSList *g_slist_append(GSList *list, gpointer data)
-{
- GSList *head = list;
- if (list) {
- while (list->next) list = list->next;
- list->next = (GSList*)g_malloc(sizeof(GSList));
- list = list->next;
- } else {
- head = list = (GSList*)g_malloc(sizeof(GSList));
- }
- list->data = data;
- list->next = NULL;
- return head;
-}
-
-void g_slist_foreach(GSList *list, GFunc func, gpointer user_data)
-{
- GSList *lp;
- for (lp = list; lp; lp = lp->next) {
- (*func)(lp->data, user_data);
- }
-}
-
-void g_slist_free(GSList *list)
-{
- GSList *lp, *next;
- for (lp = list; lp; lp = next) {
- next = lp->next;
- free(lp);
- }
-}
-
-GSList *g_slist_prepend(GSList *list, gpointer data)
-{
- GSList *head = (GSList*)g_malloc(sizeof(GSList));
- head->next = list;
- head->data = data;
- return head;
-}
-
-static GSList *g_slist_sort_merge (GSList *l1,
- GSList *l2,
- GFunc compare_func,
- gpointer user_data)
-{
- GSList list, *l;
- gint cmp;
-
- l=&list;
-
- while (l1 && l2)
- {
- cmp = ((GCompareDataFunc) compare_func) (l1->data, l2->data, user_data);
-
- if (cmp <= 0)
- {
- l=l->next=l1;
- l1=l1->next;
- }
- else
- {
- l=l->next=l2;
- l2=l2->next;
- }
- }
- l->next= l1 ? l1 : l2;
-
- return list.next;
-}
-
-static GSList *g_slist_sort_real (GSList *list,
- GFunc compare_func,
- gpointer user_data)
-{
- GSList *l1, *l2;
-
- if (!list)
- return NULL;
- if (!list->next)
- return list;
-
- l1 = list;
- l2 = list->next;
-
- while ((l2 = l2->next) != NULL)
- {
- if ((l2 = l2->next) == NULL)
- break;
- l1=l1->next;
- }
- l2 = l1->next;
- l1->next = NULL;
-
- return g_slist_sort_merge (g_slist_sort_real (list, compare_func, user_data),
- g_slist_sort_real (l2, compare_func, user_data),
- compare_func,
- user_data);
-}
-
-/**
- * g_slist_sort:
- * @list: a #GSList
- * @compare_func: the comparison function used to sort the #GSList.
- * This function is passed the data from 2 elements of the #GSList
- * and should return 0 if they are equal, a negative value if the
- * first element comes before the second, or a positive value if
- * the first element comes after the second.
- *
- * Sorts a #GSList using the given comparison function.
- *
- * Returns: the start of the sorted #GSList
- */
-GSList *g_slist_sort (GSList *list,
- GCompareFunc compare_func)
-{
- return g_slist_sort_real (list, (GFunc) compare_func, NULL);
-}
-
-/* END of g_slist related functions */
-
-// Hash functions lifted glib-2.28.0/glib/ghash.c
-
-#define HASH_TABLE_MIN_SHIFT 3 /* 1 << 3 == 8 buckets */
-
-typedef struct _GHashNode GHashNode;
-
-struct _GHashNode {
- gpointer key;
- gpointer value;
-
- /* If key_hash == 0, node is not in use
- * If key_hash == 1, node is a tombstone
- * If key_hash >= 2, node contains data */
- guint key_hash;
-};
-
-struct _GHashTable {
- gint size;
- gint mod;
- guint mask;
- gint nnodes;
- gint noccupied; /* nnodes + tombstones */
- GHashNode *nodes;
- GHashFunc hash_func;
- GEqualFunc key_equal_func;
- volatile gint ref_count;
- GDestroyNotify key_destroy_func;
- GDestroyNotify value_destroy_func;
-};
-
-/**
- * g_hash_table_destroy:
- * @hash_table: a #GHashTable.
- *
- * Destroys all keys and values in the #GHashTable and decrements its
- * reference count by 1. If keys and/or values are dynamically allocated,
- * you should either free them first or create the #GHashTable with destroy
- * notifiers using g_hash_table_new_full(). In the latter case the destroy
- * functions you supplied will be called on all keys and values during the
- * destruction phase.
- **/
-void g_hash_table_destroy (GHashTable *hash_table)
-{
- if (hash_table == NULL) return;
- if (hash_table->ref_count == 0) return;
-
- g_hash_table_remove_all (hash_table);
- g_hash_table_unref (hash_table);
-}
-
-/**
- * g_hash_table_find:
- * @hash_table: a #GHashTable.
- * @predicate: function to test the key/value pairs for a certain property.
- * @user_data: user data to pass to the function.
- *
- * Calls the given function for key/value pairs in the #GHashTable until
- * @predicate returns %TRUE. The function is passed the key and value of
- * each pair, and the given @user_data parameter. The hash table may not
- * be modified while iterating over it (you can't add/remove items).
- *
- * Note, that hash tables are really only optimized for forward lookups,
- * i.e. g_hash_table_lookup().
- * So code that frequently issues g_hash_table_find() or
- * g_hash_table_foreach() (e.g. in the order of once per every entry in a
- * hash table) should probably be reworked to use additional or different
- * data structures for reverse lookups (keep in mind that an O(n) find/foreach
- * operation issued for all n values in a hash table ends up needing O(n*n)
- * operations).
- *
- * Return value: The value of the first key/value pair is returned, for which
- * func evaluates to %TRUE. If no pair with the requested property is found,
- * %NULL is returned.
- *
- * Since: 2.4
- **/
-gpointer g_hash_table_find (GHashTable *hash_table,
- GHRFunc predicate,
- gpointer user_data)
-{
- gint i;
-
- if (hash_table == NULL) return NULL;
- if (predicate == NULL) return NULL;
-
- for (i = 0; i < hash_table->size; i++)
- {
- GHashNode *node = &hash_table->nodes [i];
-
- if (node->key_hash > 1 && predicate (node->key, node->value, user_data))
- return node->value;
- }
-
- return NULL;
-}
-
-/**
- * g_hash_table_foreach:
- * @hash_table: a #GHashTable.
- * @func: the function to call for each key/value pair.
- * @user_data: user data to pass to the function.
- *
- * Calls the given function for each of the key/value pairs in the
- * #GHashTable. The function is passed the key and value of each
- * pair, and the given @user_data parameter. The hash table may not
- * be modified while iterating over it (you can't add/remove
- * items). To remove all items matching a predicate, use
- * g_hash_table_foreach_remove().
- *
- * See g_hash_table_find() for performance caveats for linear
- * order searches in contrast to g_hash_table_lookup().
- **/
-void g_hash_table_foreach (GHashTable *hash_table,
- GHFunc func,
- gpointer user_data)
-{
- gint i;
-
- if (hash_table == NULL) return;
- if (func == NULL) return;
-
- for (i = 0; i < hash_table->size; i++)
- {
- GHashNode *node = &hash_table->nodes [i];
-
- if (node->key_hash > 1)
- (* func) (node->key, node->value, user_data);
- }
-}
-
-/*
- * g_hash_table_lookup_node_for_insertion:
- * @hash_table: our #GHashTable
- * @key: the key to lookup against
- * @hash_return: key hash return location
- * Return value: index of the described #GHashNode
- *
- * Performs a lookup in the hash table, preserving extra information
- * usually needed for insertion.
- *
- * This function first computes the hash value of the key using the
- * user's hash function.
- *
- * If an entry in the table matching @key is found then this function
- * returns the index of that entry in the table, and if not, the
- * index of an unused node (empty or tombstone) where the key can be
- * inserted.
- *
- * The computed hash value is returned in the variable pointed to
- * by @hash_return. This is to save insertions from having to compute
- * the hash record again for the new record.
- */
-static inline guint g_hash_table_lookup_node_for_insertion (GHashTable *hash_table,
- gconstpointer key,
- guint *hash_return)
-{
- GHashNode *node;
- guint node_index;
- guint hash_value;
- guint first_tombstone = 0;
- gboolean have_tombstone = FALSE;
- guint step = 0;
-
- /* Empty buckets have hash_value set to 0, and for tombstones, it's 1.
- * We need to make sure our hash value is not one of these. */
-
- hash_value = (* hash_table->hash_func) (key);
- if (hash_value <= 1)
- hash_value = 2;
-
- *hash_return = hash_value;
-
- node_index = hash_value % hash_table->mod;
- node = &hash_table->nodes [node_index];
-
- while (node->key_hash)
- {
- /* We first check if our full hash values
- * are equal so we can avoid calling the full-blown
- * key equality function in most cases.
- */
-
- if (node->key_hash == hash_value)
- {
- if (hash_table->key_equal_func)
- {
- if (hash_table->key_equal_func (node->key, key))
- return node_index;
- }
- else if (node->key == key)
- {
- return node_index;
- }
- }
- else if (node->key_hash == 1 && !have_tombstone)
- {
- first_tombstone = node_index;
- have_tombstone = TRUE;
- }
-
- step++;
- node_index += step;
- node_index &= hash_table->mask;
- node = &hash_table->nodes [node_index];
- }
-
- if (have_tombstone)
- return first_tombstone;
-
- return node_index;
-}
-
-/* Each table size has an associated prime modulo (the first prime
- * lower than the table size) used to find the initial bucket. Probing
- * then works modulo 2^n. The prime modulo is necessary to get a
- * good distribution with poor hash functions. */
-static const gint prime_mod [] = {
- 1, /* For 1 << 0 */
- 2,
- 3,
- 7,
- 13,
- 31,
- 61,
- 127,
- 251,
- 509,
- 1021,
- 2039,
- 4093,
- 8191,
- 16381,
- 32749,
- 65521, /* For 1 << 16 */
- 131071,
- 262139,
- 524287,
- 1048573,
- 2097143,
- 4194301,
- 8388593,
- 16777213,
- 33554393,
- 67108859,
- 134217689,
- 268435399,
- 536870909,
- 1073741789,
- 2147483647 /* For 1 << 31 */
-};
-
-static void g_hash_table_set_shift (GHashTable *hash_table, gint shift)
-{
- gint i;
- guint mask = 0;
-
- hash_table->size = 1 << shift;
- hash_table->mod = prime_mod [shift];
-
- for (i = 0; i < shift; i++)
- {
- mask <<= 1;
- mask |= 1;
- }
-
- hash_table->mask = mask;
-}
-
-static gint g_hash_table_find_closest_shift (gint n)
-{
- gint i;
-
- for (i = 0; n; i++)
- n >>= 1;
-
- return i;
-}
-
-static void g_hash_table_set_shift_from_size (GHashTable *hash_table, gint size)
-{
- gint shift;
-
- shift = g_hash_table_find_closest_shift (size);
- shift = MAX (shift, HASH_TABLE_MIN_SHIFT);
-
- g_hash_table_set_shift (hash_table, shift);
-}
-
-/*
- * g_hash_table_resize:
- * @hash_table: our #GHashTable
- *
- * Resizes the hash table to the optimal size based on the number of
- * nodes currently held. If you call this function then a resize will
- * occur, even if one does not need to occur. Use
- * g_hash_table_maybe_resize() instead.
- *
- * This function may "resize" the hash table to its current size, with
- * the side effect of cleaning up tombstones and otherwise optimizing
- * the probe sequences.
- */
-static void g_hash_table_resize (GHashTable *hash_table)
-{
- GHashNode *new_nodes;
- gint old_size;
- gint i;
-
- old_size = hash_table->size;
- g_hash_table_set_shift_from_size (hash_table, hash_table->nnodes * 2);
-
- new_nodes = g_new0 (GHashNode, hash_table->size);
-
- for (i = 0; i < old_size; i++)
- {
- GHashNode *node = &hash_table->nodes [i];
- GHashNode *new_node;
- guint hash_val;
- guint step = 0;
-
- if (node->key_hash <= 1)
- continue;
-
- hash_val = node->key_hash % hash_table->mod;
- new_node = &new_nodes [hash_val];
-
- while (new_node->key_hash)
- {
- step++;
- hash_val += step;
- hash_val &= hash_table->mask; new_node = &new_nodes [hash_val];
- }
-
- *new_node = *node;
- }
-
- g_free (hash_table->nodes);
- hash_table->nodes = new_nodes;
- hash_table->noccupied = hash_table->nnodes;
-}
-
-/*
- * g_hash_table_maybe_resize:
- * @hash_table: our #GHashTable
- *
- * Resizes the hash table, if needed.
- *
- * Essentially, calls g_hash_table_resize() if the table has strayed
- * too far from its ideal size for its number of nodes.
- */
-static inline void g_hash_table_maybe_resize (GHashTable *hash_table)
-{
- gint noccupied = hash_table->noccupied;
- gint size = hash_table->size;
-
- if ((size > hash_table->nnodes * 4 && size > 1 << HASH_TABLE_MIN_SHIFT) ||
- (size <= noccupied + (noccupied / 16)))
- g_hash_table_resize (hash_table);
-}
-
-/*
- * g_hash_table_insert_internal:
- * @hash_table: our #GHashTable
- * @key: the key to insert
- * @value: the value to insert
- * @keep_new_key: if %TRUE and this key already exists in the table
- * then call the destroy notify function on the old key. If %FALSE
- * then call the destroy notify function on the new key.
- *
- * Implements the common logic for the g_hash_table_insert() and
- * g_hash_table_replace() functions.
- *
- * Do a lookup of @key. If it is found, replace it with the new
- * @value (and perhaps the new @key). If it is not found, create a
- * new node.
- */
-static void g_hash_table_insert_internal (GHashTable *hash_table,
- gpointer key,
- gpointer value,
- gboolean keep_new_key)
-{
- GHashNode *node;
- guint node_index;
- guint key_hash;
- guint old_hash;
-
- if (hash_table == NULL) return;
- if (hash_table->ref_count == 0) return;
-
- node_index = g_hash_table_lookup_node_for_insertion (hash_table, key, &key_hash);
- node = &hash_table->nodes [node_index];
-
- old_hash = node->key_hash;
-
- if (old_hash > 1)
- {
- if (keep_new_key)
- {
- if (hash_table->key_destroy_func)
- hash_table->key_destroy_func (node->key);
- node->key = key;
- }
- else
- {
- if (hash_table->key_destroy_func)
- hash_table->key_destroy_func (key);
- }
-
- if (hash_table->value_destroy_func)
- hash_table->value_destroy_func (node->value);
-
- node->value = value;
- }
- else
- {
- node->key = key;
- node->value = value;
- node->key_hash = key_hash;
-
- hash_table->nnodes++;
-
- if (old_hash == 0)
- {
- /* We replaced an empty node, and not a tombstone */
- hash_table->noccupied++;
- g_hash_table_maybe_resize (hash_table);
- }
- }
-}
-
- void
-g_hash_table_replace (GHashTable *hash_table,
- gpointer key,
- gpointer value)
-{
- g_hash_table_insert_internal (hash_table, key, value, TRUE);
-}
-
-/**
- * g_hash_table_insert:
- * @hash_table: a #GHashTable.
- * @key: a key to insert.
- * @value: the value to associate with the key.
- *
- * Inserts a new key and value into a #GHashTable.
- *
- * If the key already exists in the #GHashTable its current value is replaced
- * with the new value. If you supplied a @value_destroy_func when creating the
- * #GHashTable, the old value is freed using that function. If you supplied
- * a @key_destroy_func when creating the #GHashTable, the passed key is freed
- * using that function.
- **/
-gboolean g_hash_table_insert (GHashTable *hash_table,
- gpointer key,
- gpointer value)
-{
- g_hash_table_insert_internal (hash_table, key, value, FALSE);
- return true;
-}
-
-/*
- * g_hash_table_lookup_node:
- * @hash_table: our #GHashTable
- * @key: the key to lookup against
- * @hash_return: optional key hash return location
- * Return value: index of the described #GHashNode
- *
- * Performs a lookup in the hash table. Virtually all hash operations
- * will use this function internally.
- *
- * This function first computes the hash value of the key using the
- * user's hash function.
- *
- * If an entry in the table matching @key is found then this function
- * returns the index of that entry in the table, and if not, the
- * index of an empty node (never a tombstone).
- */
-static inline guint g_hash_table_lookup_node (GHashTable *hash_table,
- gconstpointer key)
-{
- GHashNode *node;
- guint node_index;
- guint hash_value;
- guint step = 0;
-
- /* Empty buckets have hash_value set to 0, and for tombstones, it's 1.
- * We need to make sure our hash value is not one of these. */
-
- hash_value = (* hash_table->hash_func) (key);
- if (hash_value <= 1)
- hash_value = 2;
-
- node_index = hash_value % hash_table->mod;
- node = &hash_table->nodes [node_index];
-
- while (node->key_hash)
- {
- /* We first check if our full hash values
- * are equal so we can avoid calling the full-blown
- * key equality function in most cases.
- */
-
- if (node->key_hash == hash_value)
- {
- if (hash_table->key_equal_func)
- {
- if (hash_table->key_equal_func (node->key, key))
- break;
- }
- else if (node->key == key)
- {
- break;
- }
- }
-
- step++;
- node_index += step;
- node_index &= hash_table->mask;
- node = &hash_table->nodes [node_index];
- }
-
- return node_index;
-}
-
-/**
- * g_hash_table_lookup:
- * @hash_table: a #GHashTable.
- * @key: the key to look up.
- *
- * Looks up a key in a #GHashTable. Note that this function cannot
- * distinguish between a key that is not present and one which is present
- * and has the value %NULL. If you need this distinction, use
- * g_hash_table_lookup_extended().
- *
- * Return value: the associated value, or %NULL if the key is not found.
- **/
-gpointer g_hash_table_lookup (GHashTable *hash_table,
- gconstpointer key)
-{
- GHashNode *node;
- guint node_index;
-
- if (hash_table == NULL) return NULL;
-
- node_index = g_hash_table_lookup_node (hash_table, key);
- node = &hash_table->nodes [node_index];
-
- return node->key_hash ? node->value : NULL;
-}
-
-/**
- * g_hash_table_new:
- * @hash_func: a function to create a hash value from a key.
- * Hash values are used to determine where keys are stored within the
- * #GHashTable data structure. The g_direct_hash(), g_int_hash(),
- * g_int64_hash(), g_double_hash() and g_str_hash() functions are provided
- * for some common types of keys.
- * If hash_func is %NULL, g_direct_hash() is used.
- * @key_equal_func: a function to check two keys for equality. This is
- * used when looking up keys in the #GHashTable. The g_direct_equal(),
- * g_int_equal(), g_int64_equal(), g_double_equal() and g_str_equal()
- * functions are provided for the most common types of keys.
- * If @key_equal_func is %NULL, keys are compared directly in a similar
- * fashion to g_direct_equal(), but without the overhead of a function call.
- *
- * Creates a new #GHashTable with a reference count of 1.
- *
- * Return value: a new #GHashTable.
- **/
-GHashTable *g_hash_table_new(GHashFunc hash_func, GEqualFunc key_equal_func)
-{
- return g_hash_table_new_full(hash_func, key_equal_func, NULL, NULL);
-}
-
-/**
- * g_hash_table_new_full:
- * @hash_func: a function to create a hash value from a key.
- * @key_equal_func: a function to check two keys for equality.
- * @key_destroy_func: a function to free the memory allocated for the key
- * used when removing the entry from the #GHashTable or %NULL if you
- * don't want to supply such a function.
- * @value_destroy_func: a function to free the memory allocated for the
- * value used when removing the entry from the #GHashTable or %NULL if
- * you don't want to supply such a function.
- *
- * Creates a new #GHashTable like g_hash_table_new() with a reference count
- * of 1 and allows to specify functions to free the memory allocated for the
- * key and value that get called when removing the entry from the #GHashTable.
- *
- * Return value: a new #GHashTable.
- **/
-GHashTable* g_hash_table_new_full (GHashFunc hash_func,
- GEqualFunc key_equal_func,
- GDestroyNotify key_destroy_func,
- GDestroyNotify value_destroy_func)
-{
- GHashTable *hash_table;
-
- hash_table = (GHashTable*)g_malloc(sizeof(GHashTable));
- //hash_table = g_slice_new (GHashTable);
- g_hash_table_set_shift (hash_table, HASH_TABLE_MIN_SHIFT);
- hash_table->nnodes = 0;
- hash_table->noccupied = 0;
- hash_table->hash_func = hash_func ? hash_func : g_direct_hash;
- hash_table->key_equal_func = key_equal_func;
- hash_table->ref_count = 1;
- hash_table->key_destroy_func = key_destroy_func;
- hash_table->value_destroy_func = value_destroy_func;
- hash_table->nodes = g_new0 (GHashNode, hash_table->size);
-
- return hash_table;
-}
-
-/*
- * g_hash_table_remove_all_nodes:
- * @hash_table: our #GHashTable
- * @notify: %TRUE if the destroy notify handlers are to be called
- *
- * Removes all nodes from the table. Since this may be a precursor to
- * freeing the table entirely, no resize is performed.
- *
- * If @notify is %TRUE then the destroy notify functions are called
- * for the key and value of the hash node.
- */
-static void g_hash_table_remove_all_nodes (GHashTable *hash_table,
- gboolean notify)
-{
- int i;
-
- for (i = 0; i < hash_table->size; i++)
- {
- GHashNode *node = &hash_table->nodes [i];
-
- if (node->key_hash > 1)
- {
- if (notify && hash_table->key_destroy_func)
- hash_table->key_destroy_func (node->key);
-
- if (notify && hash_table->value_destroy_func)
- hash_table->value_destroy_func (node->value);
- }
- }
-
- /* We need to set node->key_hash = 0 for all nodes - might as well be GC
- * friendly and clear everything */
- memset (hash_table->nodes, 0, hash_table->size * sizeof (GHashNode));
-
- hash_table->nnodes = 0;
- hash_table->noccupied = 0;
-}
-
-/**
- * g_hash_table_remove_all:
- * @hash_table: a #GHashTable
- *
- * Removes all keys and their associated values from a #GHashTable.
- *
- * If the #GHashTable was created using g_hash_table_new_full(), the keys
- * and values are freed using the supplied destroy functions, otherwise you
- * have to make sure that any dynamically allocated values are freed
- * yourself.
- *
- * Since: 2.12
- **/
-void g_hash_table_remove_all (GHashTable *hash_table)
-{
- if (hash_table == NULL) return;
-
- g_hash_table_remove_all_nodes (hash_table, TRUE);
- g_hash_table_maybe_resize (hash_table);
-}
-
-/*
- * g_hash_table_remove_node:
- * @hash_table: our #GHashTable
- * @node: pointer to node to remove
- * @notify: %TRUE if the destroy notify handlers are to be called
- *
- * Removes a node from the hash table and updates the node count.
- * The node is replaced by a tombstone. No table resize is performed.
- *
- * If @notify is %TRUE then the destroy notify functions are called
- * for the key and value of the hash node.
- */
-static void g_hash_table_remove_node (GHashTable *hash_table,
- GHashNode *node,
- gboolean notify)
-{
- if (notify && hash_table->key_destroy_func)
- hash_table->key_destroy_func (node->key);
-
- if (notify && hash_table->value_destroy_func)
- hash_table->value_destroy_func (node->value);
-
- /* Erect tombstone */
- node->key_hash = 1;
-
- /* Be GC friendly */
- node->key = NULL;
- node->value = NULL;
-
- hash_table->nnodes--;
-}
-/*
- * g_hash_table_remove_internal:
- * @hash_table: our #GHashTable
- * @key: the key to remove
- * @notify: %TRUE if the destroy notify handlers are to be called
- * Return value: %TRUE if a node was found and removed, else %FALSE
- *
- * Implements the common logic for the g_hash_table_remove() and
- * g_hash_table_steal() functions.
- *
- * Do a lookup of @key and remove it if it is found, calling the
- * destroy notify handlers only if @notify is %TRUE.
- */
-static gboolean g_hash_table_remove_internal (GHashTable *hash_table,
- gconstpointer key,
- gboolean notify)
-{
- GHashNode *node;
- guint node_index;
-
- if (hash_table == NULL) return FALSE;
-
- node_index = g_hash_table_lookup_node (hash_table, key);
- node = &hash_table->nodes [node_index];
-
- /* g_hash_table_lookup_node() never returns a tombstone, so this is safe */
- if (!node->key_hash)
- return FALSE;
-
- g_hash_table_remove_node (hash_table, node, notify);
- g_hash_table_maybe_resize (hash_table);
-
- return TRUE;
-}
-/**
- * g_hash_table_remove:
- * @hash_table: a #GHashTable.
- * @key: the key to remove.
- *
- * Removes a key and its associated value from a #GHashTable.
- *
- * If the #GHashTable was created using g_hash_table_new_full(), the
- * key and value are freed using the supplied destroy functions, otherwise
- * you have to make sure that any dynamically allocated values are freed
- * yourself.
- *
- * Return value: %TRUE if the key was found and removed from the #GHashTable.
- **/
-gboolean g_hash_table_remove (GHashTable *hash_table,
- gconstpointer key)
-{
- return g_hash_table_remove_internal (hash_table, key, TRUE);
-}
-
-/**
- * g_hash_table_unref:
- * @hash_table: a valid #GHashTable.
- *
- * Atomically decrements the reference count of @hash_table by one.
- * If the reference count drops to 0, all keys and values will be
- * destroyed, and all memory allocated by the hash table is released.
- * This function is MT-safe and may be called from any thread.
- *
- * Since: 2.10
- **/
-void g_hash_table_unref (GHashTable *hash_table)
-{
- if (hash_table == NULL) return;
- if (hash_table->ref_count == 0) return;
-
- hash_table->ref_count--;
- if (hash_table->ref_count == 0) {
- g_hash_table_remove_all_nodes (hash_table, TRUE);
- g_free (hash_table->nodes);
- g_free (hash_table);
- }
-}
-
-/**
- * g_hash_table_ref:
- * @hash_table: a valid #GHashTable.
- *
- * Atomically increments the reference count of @hash_table by one.
- * This function is MT-safe and may be called from any thread.
- *
- * Return value: the passed in #GHashTable.
- *
- * Since: 2.10
- **/
-GHashTable *g_hash_table_ref (GHashTable *hash_table)
-{
- if (hash_table == NULL) return NULL;
- if (hash_table->ref_count == 0) return hash_table;
-
- //g_atomic_int_add (&hash_table->ref_count, 1);
- hash_table->ref_count++;
- return hash_table;
-}
-
-guint g_hash_table_size(GHashTable *hash_table)
-{
- if (hash_table == NULL) return 0;
-
- return hash_table->nnodes;
-}
-
-/* END of g_hash_table related functions */
-
-#if 0
-/* general g_XXX substitutes */
-
-void g_free(gpointer ptr)
-{
- free(ptr);
-}
-
-gpointer g_malloc(size_t size)
-{
- void *res;
- if (size == 0) return NULL;
- res = malloc(size);
- if (res == NULL) exit(1);
- return res;
-}
-
-gpointer g_malloc0(size_t size)
-{
- void *res;
- if (size == 0) return NULL;
- res = calloc(size, 1);
- if (res == NULL) exit(1);
- return res;
-}
-
-gpointer g_try_malloc0(size_t size)
-{
- if (size == 0) return NULL;
- return calloc(size, 1);
-}
-
-gpointer g_realloc(gpointer ptr, size_t size)
-{
- void *res;
- if (size == 0) {
- free(ptr);
- return NULL;
- }
- res = realloc(ptr, size);
- if (res == NULL) exit(1);
- return res;
-}
-#endif
-
-char *g_strdup(const char *str)
-{
-#ifdef _MSC_VER
- return str ? _strdup(str) : NULL;
-#else
- return str ? strdup(str) : NULL;
-#endif
-}
-
-char *g_strdup_printf(const char *format, ...)
-{
- va_list ap;
- char *res;
- va_start(ap, format);
- res = g_strdup_vprintf(format, ap);
- va_end(ap);
- return res;
-}
-
-char *g_strdup_vprintf(const char *format, va_list ap)
-{
- char *str_res = NULL;
-#ifdef _MSC_VER
- int len = _vscprintf(format, ap);
- if( len < 0 )
- return NULL;
- str_res = (char *)malloc(len+1);
- if(str_res==NULL)
- return NULL;
- vsnprintf(str_res, len+1, format, ap);
-#else
- int ret = vasprintf(&str_res, format, ap);
- if (ret == -1) {
- return NULL;
- }
-#endif
- return str_res;
-}
-
-char *g_strndup(const char *str, size_t n)
-{
- /* try to mimic glib's g_strndup */
- char *res = calloc(n + 1, 1);
- strncpy(res, str, n);
- return res;
-}
-
-void g_strfreev(char **str_array)
-{
- char **p = str_array;
- if (p) {
- while (*p) {
- free(*p++);
- }
- }
- free(str_array);
-}
-
-gpointer g_memdup(gconstpointer mem, size_t byte_size)
-{
- if (mem) {
- void *res = g_malloc(byte_size);
- memcpy(res, mem, byte_size);
- return res;
- }
- return NULL;
-}
-
-gpointer g_new_(size_t sz, size_t n_structs)
-{
- size_t need = sz * n_structs;
- if ((need / sz) != n_structs) return NULL;
- return g_malloc(need);
-}
-
-gpointer g_new0_(size_t sz, size_t n_structs)
-{
- size_t need = sz * n_structs;
- if ((need / sz) != n_structs) return NULL;
- return g_malloc0(need);
-}
-
-gpointer g_renew_(size_t sz, gpointer mem, size_t n_structs)
-{
- size_t need = sz * n_structs;
- if ((need / sz) != n_structs) return NULL;
- return g_realloc(mem, need);
-}
-
-/**
- * g_strconcat:
- * @string1: the first string to add, which must not be %NULL
- * @Varargs: a %NULL-terminated list of strings to append to the string
- *
- * Concatenates all of the given strings into one long string.
- * The returned string should be freed with g_free() when no longer needed.
- *
- * Note that this function is usually not the right function to use to
- * assemble a translated message from pieces, since proper translation
- * often requires the pieces to be reordered.
- *
- * The variable argument list must end
- * with %NULL. If you forget the %NULL, g_strconcat() will start appending
- * random memory junk to your string.
- *
- * Returns: a newly-allocated string containing all the string arguments
- */
-gchar* g_strconcat (const gchar *string1, ...)
-{
- va_list ap;
- char *res;
- size_t sz = strlen(string1);
- va_start(ap, string1);
- while (1) {
- char *arg = va_arg(ap, char*);
- if (arg == NULL) break;
- sz += strlen(arg);
- }
- va_end(ap);
- res = g_malloc(sz + 1);
- strcpy(res, string1);
- va_start(ap, string1);
- while (1) {
- char *arg = va_arg(ap, char*);
- if (arg == NULL) break;
- strcat(res, arg);
- }
- va_end(ap);
- return res;
-}
-
-/**
- * g_strsplit:
- * @string: a string to split.
- * @delimiter: a string which specifies the places at which to split the string.
- * The delimiter is not included in any of the resulting strings, unless
- * @max_tokens is reached.
- * @max_tokens: the maximum number of pieces to split @string into. If this is
- * less than 1, the string is split completely.
- *
- * Splits a string into a maximum of @max_tokens pieces, using the given
- * @delimiter. If @max_tokens is reached, the remainder of @string is appended
- * to the last token.
- *
- * As a special case, the result of splitting the empty string "" is an empty
- * vector, not a vector containing a single string. The reason for this
- * special case is that being able to represent a empty vector is typically
- * more useful than consistent handling of empty elements. If you do need
- * to represent empty elements, you'll need to check for the empty string
- * before calling g_strsplit().
- *
- * Return value: a newly-allocated %NULL-terminated array of strings. Use
- * g_strfreev() to free it.
- **/
-gchar** g_strsplit (const gchar *string,
- const gchar *delimiter,
- gint max_tokens)
-{
- GSList *string_list = NULL, *slist;
- gchar **str_array, *s;
- guint n = 0;
- const gchar *remainder;
-
- if (string == NULL) return NULL;
- if (delimiter == NULL) return NULL;
- if (delimiter[0] == '\0') return NULL;
-
- if (max_tokens < 1)
- max_tokens = G_MAXINT;
-
- remainder = string;
- s = strstr (remainder, delimiter);
- if (s)
- {
- gsize delimiter_len = strlen (delimiter);
-
- while (--max_tokens && s)
- {
- gsize len;
-
- len = s - remainder;
- string_list = g_slist_prepend (string_list,
- g_strndup (remainder, len));
- n++;
- remainder = s + delimiter_len;
- s = strstr (remainder, delimiter);
- }
- }
- if (*string)
- {
- n++;
- string_list = g_slist_prepend (string_list, g_strdup (remainder));
- }
-
- str_array = g_new (gchar*, n + 1);
-
- str_array[n--] = NULL;
- for (slist = string_list; slist; slist = slist->next)
- str_array[n--] = slist->data;
-
- g_slist_free (string_list);
-
- return str_array;
-}
-
-GSList *g_slist_find_custom (GSList *list, gconstpointer data, GCompareFunc func)
-{
- if (!func)
- return NULL;
-
- while (list) {
- if (func (list->data, data) == 0)
- return list;
-
- list = list->next;
- }
-
- return NULL;
-}
-
-int g_strcmp0 (const char *str1, const char *str2)
-{
- if (!str1 && !str2)
- return 0;
-
- if (!str1 || !str2)
- return 0;
-
- return strcmp(str1, str2);
-}
diff --git a/glib_compat/glib_compat.h b/glib_compat/glib_compat.h
deleted file mode 100644
index 30215a1138..0000000000
--- a/glib_compat/glib_compat.h
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
-glib_compat.h replacement functionality for glib code used in qemu
-Copyright (C) 2016 Chris Eagle cseagle at gmail dot com
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-*/
-
-#ifndef __GLIB_COMPAT_H
-#define __GLIB_COMPAT_H
-
-#include "unicorn/platform.h"
-#include
-#include
-#include
-
-#define G_MAXUINT UINT_MAX
-#define G_MAXINT INT_MAX
-
-#include "gtestutils.h"
-#include "gtypes.h"
-#include "garray.h"
-#include "gtree.h"
-#include "ghash.h"
-#include "gmem.h"
-#include "gslice.h"
-#include "gmessages.h"
-#include "gpattern.h"
-#include "grand.h"
-#include "glist.h"
-#include "gnode.h"
-
-typedef gint (*GCompareDataFunc)(gconstpointer a,
- gconstpointer b,
- gpointer user_data);
-typedef void (*GFunc)(gpointer data, gpointer user_data);
-typedef gint (*GCompareFunc)(gconstpointer v1, gconstpointer v2);
-
-guint g_str_hash(gconstpointer v);
-gboolean g_str_equal(gconstpointer v1, gconstpointer v2);
-guint g_int_hash(gconstpointer v);
-
-gboolean g_int_equal(gconstpointer v1, gconstpointer v2);
-
-int g_strcmp0(const char *str1, const char *str2);
-
-GList *g_list_first(GList *list);
-void g_list_foreach(GList *list, GFunc func, gpointer user_data);
-void g_list_free(GList *list);
-GList *g_list_insert_sorted(GList *list, gpointer data, GCompareFunc compare);
-#define g_list_next(list) (list->next)
-GList *g_list_prepend(GList *list, gpointer data);
-GList *g_list_remove_link(GList *list, GList *llink);
-GList *g_list_sort(GList *list, GCompareFunc compare);
-
-typedef struct _GSList {
- gpointer data;
- struct _GSList *next;
-} GSList;
-
-GSList *g_slist_append(GSList *list, gpointer data);
-void g_slist_foreach(GSList *list, GFunc func, gpointer user_data);
-void g_slist_free(GSList *list);
-GSList *g_slist_prepend(GSList *list, gpointer data);
-GSList *g_slist_sort(GSList *list, GCompareFunc compare);
-GSList *g_slist_find_custom(GSList *list, gconstpointer data, GCompareFunc func);
-
-/* replacement for g_malloc dependency */
-void g_free(gpointer ptr);
-gpointer g_realloc(gpointer ptr, size_t size);
-
-char *g_strdup(const char *str);
-char *g_strdup_printf(const char *format, ...);
-char *g_strdup_vprintf(const char *format, va_list ap);
-char *g_strndup(const char *str, size_t n);
-void g_strfreev(char **v);
-gpointer g_memdup(gconstpointer mem, size_t byte_size);
-gpointer g_new_(size_t sz, size_t n_structs);
-gpointer g_new0_(size_t sz, size_t n_structs);
-gpointer g_renew_(size_t sz, gpointer mem, size_t n_structs);
-
-gchar** g_strsplit (const gchar *string,
- const gchar *delimiter,
- gint max_tokens);
-
-#endif
diff --git a/glib_compat/glist.c b/glib_compat/glist.c
deleted file mode 100644
index 39ba10c3db..0000000000
--- a/glib_compat/glist.c
+++ /dev/null
@@ -1,154 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see .
- */
-
-/*
- * Modified by the GLib Team and others 1997-2000. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-/*
- * MT safe
- */
-
-#include "gtypes.h"
-#include "glist.h"
-#include "gslice.h"
-#include "gmessages.h"
-
-#define _g_list_alloc() g_slice_new (GList)
-#define _g_list_alloc0() g_slice_new0 (GList)
-#define _g_list_free1(list) g_slice_free (GList, list)
-
-/**
- * g_list_alloc:
- *
- * Allocates space for one #GList element. It is called by
- * g_list_append(), g_list_prepend(), g_list_insert() and
- * g_list_insert_sorted() and so is rarely used on its own.
- *
- * Returns: a pointer to the newly-allocated #GList element
- **/
-GList *g_list_alloc (void)
-{
- return _g_list_alloc0 ();
-}
-
-static inline GList *_g_list_remove_link (GList *list, GList *link)
-{
- if (link == NULL)
- return list;
-
- if (link->prev)
- {
- if (link->prev->next == link)
- link->prev->next = link->next;
- //else
- // g_warning ("corrupted double-linked list detected");
- }
- if (link->next)
- {
- if (link->next->prev == link)
- link->next->prev = link->prev;
- //else
- // g_warning ("corrupted double-linked list detected");
- }
-
- if (link == list)
- list = list->next;
-
- link->next = NULL;
- link->prev = NULL;
-
- return list;
-}
-
-/**
- * g_list_delete_link:
- * @list: a #GList, this must point to the top of the list
- * @link_: node to delete from @list
- *
- * Removes the node link_ from the list and frees it.
- * Compare this to g_list_remove_link() which removes the node
- * without freeing it.
- *
- * Returns: the (possibly changed) start of the #GList
- */
-GList *g_list_delete_link (GList *list, GList *link_)
-{
- list = _g_list_remove_link (list, link_);
- _g_list_free1 (link_);
-
- return list;
-}
-
-/**
- * g_list_insert_before:
- * @list: a pointer to a #GList, this must point to the top of the list
- * @sibling: the list element before which the new element
- * is inserted or %NULL to insert at the end of the list
- * @data: the data for the new element
- *
- * Inserts a new element into the list before the given position.
- *
- * Returns: the (possibly changed) start of the #GList
- */
-GList *g_list_insert_before (GList *list, GList *sibling, gpointer data)
-{
- if (list == NULL)
- {
- list = g_list_alloc ();
- list->data = data;
- g_return_val_if_fail (sibling == NULL, list);
- return list;
- }
- else if (sibling != NULL)
- {
- GList *node;
-
- node = _g_list_alloc ();
- node->data = data;
- node->prev = sibling->prev;
- node->next = sibling;
- sibling->prev = node;
- if (node->prev != NULL)
- {
- node->prev->next = node;
- return list;
- }
- else
- {
- g_return_val_if_fail (sibling == list, node);
- return node;
- }
- }
- else
- {
- GList *last;
-
- for (last = list; last->next != NULL; last = last->next) {}
-
- last->next = _g_list_alloc ();
- last->next->data = data;
- last->next->prev = last;
- last->next->next = NULL;
-
- return list;
- }
-}
-
diff --git a/glib_compat/glist.h b/glib_compat/glist.h
deleted file mode 100644
index 1cb95e77f2..0000000000
--- a/glib_compat/glist.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see .
- */
-
-/*
- * Modified by the GLib Team and others 1997-2000. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-#ifndef __G_LIST_H__
-#define __G_LIST_H__
-
-#include "gmem.h"
-
-typedef struct _GList GList;
-
-struct _GList
-{
- gpointer data;
- GList *next;
- GList *prev;
-};
-
-
-GList* g_list_insert_before (GList *list, GList *sibling, gpointer data);
-
-GList* g_list_delete_link (GList *list, GList *link_);
-
-#endif /* __G_LIST_H__ */
diff --git a/glib_compat/gmacros.h b/glib_compat/gmacros.h
deleted file mode 100644
index 1fa0b149a3..0000000000
--- a/glib_compat/gmacros.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see .
- */
-
-/*
- * Modified by the GLib Team and others 1997-2000. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-/* This file must not include any other glib header file and must thus
- * not refer to variables from glibconfig.h
- */
-
-#ifndef __G_MACROS_H__
-#define __G_MACROS_H__
-
-/* We include stddef.h to get the system's definition of NULL
- */
-#include
-
-/* Here we provide G_GNUC_EXTENSION as an alias for __extension__,
- * where this is valid. This allows for warningless compilation of
- * "long long" types even in the presence of '-ansi -pedantic'.
- */
-#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)
-#define G_GNUC_EXTENSION __extension__
-#else
-#define G_GNUC_EXTENSION
-#endif
-
-#if !(defined (G_STMT_START) && defined (G_STMT_END))
-#define G_STMT_START do
-#if defined (_MSC_VER) && (_MSC_VER >= 1500)
-#define G_STMT_END \
- __pragma(warning(push)) \
- __pragma(warning(disable:4127)) \
- while(0) \
- __pragma(warning(pop))
-#else
-#define G_STMT_END while (0)
-#endif
-#endif
-
-#endif /* __G_MACROS_H__ */
diff --git a/glib_compat/gmem.c b/glib_compat/gmem.c
deleted file mode 100644
index 917b57d007..0000000000
--- a/glib_compat/gmem.c
+++ /dev/null
@@ -1,257 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see .
- */
-
-/*
- * Modified by the GLib Team and others 1997-2000. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-/*
- * MT safe
- */
-
-#include "gtypes.h"
-#include "gmem.h"
-
-#include
-
-#include "gslice.h"
-
-#define SIZE_OVERFLOWS(a,b) (((b) > 0 && (a) > G_MAXSIZE / (b)))
-
-
-/**
- * g_try_malloc:
- * @n_bytes: number of bytes to allocate.
- *
- * Attempts to allocate @n_bytes, and returns %NULL on failure.
- * Contrast with g_malloc(), which aborts the program on failure.
- *
- * Returns: the allocated memory, or %NULL.
- */
-gpointer g_try_malloc (gsize n_bytes)
-{
- gpointer mem;
-
- if (n_bytes)
- mem = malloc (n_bytes);
- else
- mem = NULL;
-
- return mem;
-}
-
-/**
- * g_try_malloc_n:
- * @n_blocks: the number of blocks to allocate
- * @n_block_bytes: the size of each block in bytes
- *
- * This function is similar to g_try_malloc(), allocating (@n_blocks * @n_block_bytes) bytes,
- * but care is taken to detect possible overflow during multiplication.
- *
- * Since: 2.24
- * Returns: the allocated memory, or %NULL.
- */
-gpointer g_try_malloc_n (gsize n_blocks, gsize n_block_bytes)
-{
- if (SIZE_OVERFLOWS (n_blocks, n_block_bytes))
- return NULL;
-
- return g_try_malloc (n_blocks * n_block_bytes);
-}
-
-/**
- * g_malloc:
- * @n_bytes: the number of bytes to allocate
- *
- * Allocates @n_bytes bytes of memory.
- * If @n_bytes is 0 it returns %NULL.
- *
- * Returns: a pointer to the allocated memory
- */
-gpointer g_malloc (gsize n_bytes)
-{
- if (n_bytes) {
- gpointer mem;
-
- mem = malloc (n_bytes);
- if (mem)
- return mem;
-
- //g_error ("%s: failed to allocate %"G_GSIZE_FORMAT" bytes",
- // G_STRLOC, n_bytes);
- }
-
- return NULL;
-}
-
-/**
- * g_malloc_n:
- * @n_blocks: the number of blocks to allocate
- * @n_block_bytes: the size of each block in bytes
- *
- * This function is similar to g_malloc(), allocating (@n_blocks * @n_block_bytes) bytes,
- * but care is taken to detect possible overflow during multiplication.
- *
- * Since: 2.24
- * Returns: a pointer to the allocated memory
- */
-gpointer g_malloc_n (gsize n_blocks, gsize n_block_bytes)
-{
- if (SIZE_OVERFLOWS (n_blocks, n_block_bytes)) {
- //g_error ("%s: overflow allocating %"G_GSIZE_FORMAT"*%"G_GSIZE_FORMAT" bytes",
- // G_STRLOC, n_blocks, n_block_bytes);
- }
-
- return g_malloc (n_blocks * n_block_bytes);
-}
-
-/**
- * g_malloc0:
- * @n_bytes: the number of bytes to allocate
- *
- * Allocates @n_bytes bytes of memory, initialized to 0's.
- * If @n_bytes is 0 it returns %NULL.
- *
- * Returns: a pointer to the allocated memory
- */
-gpointer g_malloc0 (gsize n_bytes)
-{
- if (n_bytes) {
- gpointer mem;
-
- mem = calloc (1, n_bytes);
- if (mem)
- return mem;
-
- //g_error ("%s: failed to allocate %"G_GSIZE_FORMAT" bytes",
- // G_STRLOC, n_bytes);
- }
-
- return NULL;
-}
-
-/**
- * g_malloc0_n:
- * @n_blocks: the number of blocks to allocate
- * @n_block_bytes: the size of each block in bytes
- *
- * This function is similar to g_malloc0(), allocating (@n_blocks * @n_block_bytes) bytes,
- * but care is taken to detect possible overflow during multiplication.
- *
- * Since: 2.24
- * Returns: a pointer to the allocated memory
- */
-gpointer g_malloc0_n (gsize n_blocks, gsize n_block_bytes)
-{
- if (SIZE_OVERFLOWS (n_blocks, n_block_bytes)) {
- //g_error ("%s: overflow allocating %"G_GSIZE_FORMAT"*%"G_GSIZE_FORMAT" bytes",
- // G_STRLOC, n_blocks, n_block_bytes);
- }
-
- return g_malloc0 (n_blocks * n_block_bytes);
-}
-
-/**
- * g_try_malloc0:
- * @n_bytes: number of bytes to allocate
- *
- * Attempts to allocate @n_bytes, initialized to 0's, and returns %NULL on
- * failure. Contrast with g_malloc0(), which aborts the program on failure.
- *
- * Since: 2.8
- * Returns: the allocated memory, or %NULL
- */
-gpointer g_try_malloc0 (gsize n_bytes)
-{
- gpointer mem;
-
- if (n_bytes)
- mem = calloc (1, n_bytes);
- else
- mem = NULL;
-
- return mem;
-}
-
-/**
- * g_realloc:
- * @mem: (nullable): the memory to reallocate
- * @n_bytes: new size of the memory in bytes
- *
- * Reallocates the memory pointed to by @mem, so that it now has space for
- * @n_bytes bytes of memory. It returns the new address of the memory, which may
- * have been moved. @mem may be %NULL, in which case it's considered to
- * have zero-length. @n_bytes may be 0, in which case %NULL will be returned
- * and @mem will be freed unless it is %NULL.
- *
- * Returns: the new address of the allocated memory
- */
-gpointer g_realloc (gpointer mem, gsize n_bytes)
-{
- gpointer newmem;
-
- if (n_bytes) {
- newmem = realloc (mem, n_bytes);
- if (newmem)
- return newmem;
-
- //g_error("%s: failed to allocate %"G_GSIZE_FORMAT" bytes", G_STRLOC, n_bytes);
- }
-
- free (mem);
-
- return NULL;
-}
-
-/**
- * g_realloc_n:
- * @mem: (nullable): the memory to reallocate
- * @n_blocks: the number of blocks to allocate
- * @n_block_bytes: the size of each block in bytes
- *
- * This function is similar to g_realloc(), allocating (@n_blocks * @n_block_bytes) bytes,
- * but care is taken to detect possible overflow during multiplication.
- *
- * Since: 2.24
- * Returns: the new address of the allocated memory
- */
-gpointer g_realloc_n (gpointer mem, gsize n_blocks, gsize n_block_bytes)
-{
- if (SIZE_OVERFLOWS (n_blocks, n_block_bytes)) {
- //g_error ("%s: overflow allocating %"G_GSIZE_FORMAT"*%"G_GSIZE_FORMAT" bytes",
- // G_STRLOC, n_blocks, n_block_bytes);
- }
-
- return g_realloc (mem, n_blocks * n_block_bytes);
-}
-
-/**
- * g_free:
- * @mem: (nullable): the memory to free
- *
- * Frees the memory pointed to by @mem.
- *
- * If @mem is %NULL it simply returns, so there is no need to check @mem
- * against %NULL before calling this function.
- */
-void g_free (gpointer mem)
-{
- free (mem);
-}
diff --git a/glib_compat/gmem.h b/glib_compat/gmem.h
deleted file mode 100644
index 7a32ae592c..0000000000
--- a/glib_compat/gmem.h
+++ /dev/null
@@ -1,111 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see .
- */
-
-/*
- * Modified by the GLib Team and others 1997-2000. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-#ifndef __G_MEM_H__
-#define __G_MEM_H__
-
-#include
-#include "gmacros.h"
-
-#define G_MAXSIZE ULONG_MAX
-
-/* Optimise: avoid the call to the (slower) _n function if we can
- * determine at compile-time that no overflow happens.
- */
-#if defined (__GNUC__) && (__GNUC__ >= 2) && defined (__OPTIMIZE__)
-# define _G_NEW(struct_type, n_structs, func) \
- (struct_type *) (G_GNUC_EXTENSION ({ \
- gsize __n = (gsize) (n_structs); \
- gsize __s = sizeof (struct_type); \
- gpointer __p; \
- if (__s == 1) \
- __p = g_##func (__n); \
- else if (__builtin_constant_p (__n) && \
- (__s == 0 || __n <= G_MAXSIZE / __s)) \
- __p = g_##func (__n * __s); \
- else \
- __p = g_##func##_n (__n, __s); \
- __p; \
- }))
-# define _G_RENEW(struct_type, mem, n_structs, func) \
- (struct_type *) (G_GNUC_EXTENSION ({ \
- gsize __n = (gsize) (n_structs); \
- gsize __s = sizeof (struct_type); \
- gpointer __p = (gpointer) (mem); \
- if (__s == 1) \
- __p = g_##func (__p, __n); \
- else if (__builtin_constant_p (__n) && \
- (__s == 0 || __n <= G_MAXSIZE / __s)) \
- __p = g_##func (__p, __n * __s); \
- else \
- __p = g_##func##_n (__p, __n, __s); \
- __p; \
- }))
-
-#else
-/* Unoptimised version: always call the _n() function. */
-#define _G_NEW(struct_type, n_structs, func) \
- ((struct_type *) g_##func##_n ((n_structs), sizeof (struct_type)))
-#define _G_RENEW(struct_type, mem, n_structs, func) \
- ((struct_type *) g_##func##_n (mem, (n_structs), sizeof (struct_type)))
-
-#endif
-
-gpointer g_try_malloc (gsize n_bytes);
-
-gpointer g_try_malloc0 (gsize n_bytes);
-
-gpointer g_try_malloc_n (gsize n_blocks, gsize n_block_bytes);
-
-gpointer g_malloc0_n (gsize n_blocks, gsize n_block_bytes);
-
-gpointer g_realloc_n (gpointer mem, gsize n_blocks, gsize n_block_bytes);
-
-gpointer g_malloc_n (gsize n_blocks, gsize n_block_bytes);
-
-gpointer g_malloc0 (gsize n_bytes);
-
-gpointer g_malloc (gsize n_bytes);
-
-void g_free (gpointer mem);
-
-/**
- * g_try_new:
- * @struct_type: the type of the elements to allocate
- * @n_structs: the number of elements to allocate
- *
- * Attempts to allocate @n_structs elements of type @struct_type, and returns
- * %NULL on failure. Contrast with g_new(), which aborts the program on failure.
- * The returned pointer is cast to a pointer to the given type.
- * The function returns %NULL when @n_structs is 0 of if an overflow occurs.
- *
- * Since: 2.8
- * Returns: a pointer to the allocated memory, cast to a pointer to @struct_type
- */
-#define g_try_new(struct_type, n_structs) _G_NEW (struct_type, n_structs, try_malloc)
-#define g_new0(struct_type, n_structs) _G_NEW (struct_type, n_structs, malloc0)
-#define g_new(struct_type, n_structs) _G_NEW (struct_type, n_structs, malloc)
-#define g_renew(struct_type, mem, n_structs) _G_RENEW (struct_type, mem, n_structs, realloc)
-
-#endif /* __G_MEM_H__ */
diff --git a/glib_compat/gmessages.h b/glib_compat/gmessages.h
deleted file mode 100644
index e667d4db1c..0000000000
--- a/glib_compat/gmessages.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see .
- */
-
-/*
- * Modified by the GLib Team and others 1997-2000. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-#ifndef __G_MESSAGES_H__
-#define __G_MESSAGES_H__
-
-#include "gmacros.h"
-
-#define g_return_val_if_fail(expr,val) G_STMT_START{ (void)0; }G_STMT_END
-#define g_return_if_fail(expr) G_STMT_START{ (void)0; }G_STMT_END
-#define g_return_if_reached() G_STMT_START{ return; }G_STMT_END
-#define g_return_val_if_reached(val) G_STMT_START{ return (val); }G_STMT_END
-
-#endif /* __G_MESSAGES_H__ */
diff --git a/glib_compat/gnode.h b/glib_compat/gnode.h
deleted file mode 100644
index 1b73ab4c94..0000000000
--- a/glib_compat/gnode.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see .
- */
-
-/*
- * Modified by the GLib Team and others 1997-2000. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-#ifndef __G_NODE_H__
-#define __G_NODE_H__
-
-#include "gmem.h"
-
-/* Tree traverse orders */
-typedef enum
-{
- G_IN_ORDER,
- G_PRE_ORDER,
- G_POST_ORDER,
- G_LEVEL_ORDER
-} GTraverseType;
-
-#endif /* __G_NODE_H__ */
diff --git a/glib_compat/gpattern.c b/glib_compat/gpattern.c
deleted file mode 100644
index 53fc046586..0000000000
--- a/glib_compat/gpattern.c
+++ /dev/null
@@ -1,400 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997, 1999 Peter Mattis, Red Hat, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see .
- */
-
-#include
-
-#include "gpattern.h"
-
-#include "gmacros.h"
-#include "gmessages.h"
-#include "gmem.h"
-
-/**
- * SECTION:patterns
- * @title: Glob-style pattern matching
- * @short_description: matches strings against patterns containing '*'
- * (wildcard) and '?' (joker)
- *
- * The g_pattern_match* functions match a string
- * against a pattern containing '*' and '?' wildcards with similar
- * semantics as the standard glob() function: '*' matches an arbitrary,
- * possibly empty, string, '?' matches an arbitrary character.
- *
- * Note that in contrast to glob(), the '/' character can be matched by
- * the wildcards, there are no '[...]' character ranges and '*' and '?'
- * can not be escaped to include them literally in a pattern.
- *
- * When multiple strings must be matched against the same pattern, it
- * is better to compile the pattern to a #GPatternSpec using
- * g_pattern_spec_new() and use g_pattern_match_string() instead of
- * g_pattern_match_simple(). This avoids the overhead of repeated
- * pattern compilation.
- **/
-
-/**
- * GPatternSpec:
- *
- * A GPatternSpec struct is the 'compiled' form of a pattern. This
- * structure is opaque and its fields cannot be accessed directly.
- */
-
-/* keep enum and structure of gpattern.c and patterntest.c in sync */
-typedef enum
-{
- G_MATCH_ALL, /* "*A?A*" */
- G_MATCH_ALL_TAIL, /* "*A?AA" */
- G_MATCH_HEAD, /* "AAAA*" */
- G_MATCH_TAIL, /* "*AAAA" */
- G_MATCH_EXACT, /* "AAAAA" */
- G_MATCH_LAST
-} GMatchType;
-
-struct _GPatternSpec
-{
- GMatchType match_type;
- guint pattern_length;
- guint min_length;
- guint max_length;
- gchar *pattern;
-};
-
-
-/* --- functions --- */
-static inline gboolean g_pattern_ph_match (const gchar *match_pattern,
- const gchar *match_string,
- gboolean *wildcard_reached_p)
-{
- const gchar *pattern, *string;
- gchar ch;
-
- pattern = match_pattern;
- string = match_string;
-
- ch = *pattern;
- pattern++;
- while (ch)
- {
- switch (ch)
- {
- case '?':
- if (!*string)
- return FALSE;
- string = string + 1;
- break;
-
- case '*':
- *wildcard_reached_p = TRUE;
- do
- {
- ch = *pattern;
- pattern++;
- if (ch == '?')
- {
- if (!*string)
- return FALSE;
- string = string + 1;
- }
- }
- while (ch == '*' || ch == '?');
- if (!ch)
- return TRUE;
- do
- {
- gboolean next_wildcard_reached = FALSE;
- while (ch != *string)
- {
- if (!*string)
- return FALSE;
- string = string + 1;
- }
- string++;
- if (g_pattern_ph_match (pattern, string, &next_wildcard_reached))
- return TRUE;
- if (next_wildcard_reached)
- /* the forthcoming pattern substring up to the next wildcard has
- * been matched, but a mismatch occurred for the rest of the
- * pattern, following the next wildcard.
- * there's no need to advance the current match position any
- * further if the rest pattern will not match.
- */
- return FALSE;
- }
- while (*string);
- break;
-
- default:
- if (ch == *string)
- string++;
- else
- return FALSE;
- break;
- }
-
- ch = *pattern;
- pattern++;
- }
-
- return *string == 0;
-}
-
-static gchar *string_reverse(const gchar *string, gint string_length)
-{
- gchar *new_string;
- gint i, j;
- if (string == NULL || string_length <= 0) {
- return NULL;
- }
-
- new_string = g_new(gchar, string_length + 1);
- if (new_string) {
- for (i = 0; i < string_length; i++) {
- j = string_length - i - 1;
- new_string[j] = string[i];
- }
- new_string[string_length] = 0;
- }
-
- return new_string;
-}
-
-/**
- * g_pattern_match:
- * @pspec: a #GPatternSpec
- * @string_length: the length of @string (in bytes, i.e. strlen(),
- * not g_utf8_strlen())
- * @string: the UTF-8 encoded string to match
- * @string_reversed: (nullable): the reverse of @string or %NULL
- *
- * Matches a string against a compiled pattern. Passing the correct
- * length of the string given is mandatory. The reversed string can be
- * omitted by passing %NULL, this is more efficient if the reversed
- * version of the string to be matched is not at hand, as
- * g_pattern_match() will only construct it if the compiled pattern
- * requires reverse matches.
- *
- * Note that, if the user code will (possibly) match a string against a
- * multitude of patterns containing wildcards, chances are high that
- * some patterns will require a reversed string. In this case, it's
- * more efficient to provide the reversed string to avoid multiple
- * constructions thereof in the various calls to g_pattern_match().
- *
- * Note also that the reverse of a UTF-8 encoded string can in general
- * not be obtained by g_strreverse(). This works only if the string
- * does not contain any multibyte characters. GLib offers the
- * g_utf8_strreverse() function to reverse UTF-8 encoded strings.
- *
- * Returns: %TRUE if @string matches @pspec
- **/
-gboolean g_pattern_match (GPatternSpec *pspec,
- guint string_length,
- const gchar *string,
- const gchar *string_reversed)
-{
- g_return_val_if_fail (pspec != NULL, FALSE);
- g_return_val_if_fail (string != NULL, FALSE);
-
- if (string_length < pspec->min_length ||
- string_length > pspec->max_length)
- return FALSE;
-
- switch (pspec->match_type)
- {
- gboolean dummy;
- case G_MATCH_ALL:
- return g_pattern_ph_match (pspec->pattern, string, &dummy);
- case G_MATCH_ALL_TAIL:
- if (string_reversed)
- return g_pattern_ph_match (pspec->pattern, string_reversed, &dummy);
- else
- {
- gboolean result;
- gchar *tmp;
- tmp = string_reverse (string, string_length);
- result = g_pattern_ph_match (pspec->pattern, tmp, &dummy);
- g_free (tmp);
- return result;
- }
- case G_MATCH_HEAD:
- if (pspec->pattern_length == string_length)
- return strcmp (pspec->pattern, string) == 0;
- else if (pspec->pattern_length)
- return strncmp (pspec->pattern, string, pspec->pattern_length) == 0;
- else
- return TRUE;
- case G_MATCH_TAIL:
- if (pspec->pattern_length)
- return strcmp (pspec->pattern, string + (string_length - pspec->pattern_length)) == 0;
- else
- return TRUE;
- case G_MATCH_EXACT:
- if (pspec->pattern_length != string_length)
- return FALSE;
- else
- return strcmp (pspec->pattern, string) == 0;
- default:
- g_return_val_if_fail (pspec->match_type < G_MATCH_LAST, FALSE);
- return FALSE;
- }
-}
-
-/**
- * g_pattern_spec_new:
- * @pattern: a zero-terminated UTF-8 encoded string
- *
- * Compiles a pattern to a #GPatternSpec.
- *
- * Returns: a newly-allocated #GPatternSpec
- **/
-GPatternSpec* g_pattern_spec_new (const gchar *pattern)
-{
- GPatternSpec *pspec;
- gboolean seen_joker = FALSE, seen_wildcard = FALSE, more_wildcards = FALSE;
- gint hw_pos = -1, tw_pos = -1, hj_pos = -1, tj_pos = -1;
- gboolean follows_wildcard = FALSE;
- guint pending_jokers = 0;
- const gchar *s;
- gchar *d;
- guint i;
-
- g_return_val_if_fail (pattern != NULL, NULL);
-
- /* canonicalize pattern and collect necessary stats */
- pspec = g_new (GPatternSpec, 1);
- pspec->pattern_length = strlen (pattern);
- pspec->min_length = 0;
- pspec->max_length = 0;
- pspec->pattern = g_new (gchar, pspec->pattern_length + 1);
- d = pspec->pattern;
- for (i = 0, s = pattern; *s != 0; s++)
- {
- switch (*s)
- {
- case '*':
- if (follows_wildcard) /* compress multiple wildcards */
- {
- pspec->pattern_length--;
- continue;
- }
- follows_wildcard = TRUE;
- if (hw_pos < 0)
- hw_pos = i;
- tw_pos = i;
- break;
- case '?':
- pending_jokers++;
- pspec->min_length++;
- pspec->max_length += 4; /* maximum UTF-8 character length */
- continue;
- default:
- for (; pending_jokers; pending_jokers--, i++) {
- *d++ = '?';
- if (hj_pos < 0)
- hj_pos = i;
- tj_pos = i;
- }
- follows_wildcard = FALSE;
- pspec->min_length++;
- pspec->max_length++;
- break;
- }
- *d++ = *s;
- i++;
- }
- for (; pending_jokers; pending_jokers--) {
- *d++ = '?';
- if (hj_pos < 0)
- hj_pos = i;
- tj_pos = i;
- }
- *d++ = 0;
- seen_joker = hj_pos >= 0;
- seen_wildcard = hw_pos >= 0;
- more_wildcards = seen_wildcard && hw_pos != tw_pos;
- if (seen_wildcard)
- pspec->max_length = UINT_MAX;
-
- /* special case sole head/tail wildcard or exact matches */
- if (!seen_joker && !more_wildcards)
- {
- if (pspec->pattern[0] == '*')
- {
- pspec->match_type = G_MATCH_TAIL;
- memmove (pspec->pattern, pspec->pattern + 1, --pspec->pattern_length);
- pspec->pattern[pspec->pattern_length] = 0;
- return pspec;
- }
- if (pspec->pattern_length > 0 &&
- pspec->pattern[pspec->pattern_length - 1] == '*')
- {
- pspec->match_type = G_MATCH_HEAD;
- pspec->pattern[--pspec->pattern_length] = 0;
- return pspec;
- }
- if (!seen_wildcard)
- {
- pspec->match_type = G_MATCH_EXACT;
- return pspec;
- }
- }
-
- /* now just need to distinguish between head or tail match start */
- tw_pos = pspec->pattern_length - 1 - tw_pos; /* last pos to tail distance */
- tj_pos = pspec->pattern_length - 1 - tj_pos; /* last pos to tail distance */
- if (seen_wildcard)
- pspec->match_type = tw_pos > hw_pos ? G_MATCH_ALL_TAIL : G_MATCH_ALL;
- else /* seen_joker */
- pspec->match_type = tj_pos > hj_pos ? G_MATCH_ALL_TAIL : G_MATCH_ALL;
- if (pspec->match_type == G_MATCH_ALL_TAIL) {
- gchar *tmp = pspec->pattern;
- pspec->pattern = string_reverse (pspec->pattern, pspec->pattern_length);
- g_free (tmp);
- }
- return pspec;
-}
-
-/**
- * g_pattern_spec_free:
- * @pspec: a #GPatternSpec
- *
- * Frees the memory allocated for the #GPatternSpec.
- **/
-void g_pattern_spec_free (GPatternSpec *pspec)
-{
- g_return_if_fail (pspec != NULL);
-
- g_free (pspec->pattern);
- g_free (pspec);
-}
-
-/**
- * g_pattern_match_string:
- * @pspec: a #GPatternSpec
- * @string: the UTF-8 encoded string to match
- *
- * Matches a string against a compiled pattern. If the string is to be
- * matched against more than one pattern, consider using
- * g_pattern_match() instead while supplying the reversed string.
- *
- * Returns: %TRUE if @string matches @pspec
- **/
-gboolean g_pattern_match_string (GPatternSpec *pspec, const gchar *string)
-{
- g_return_val_if_fail (pspec != NULL, FALSE);
- g_return_val_if_fail (string != NULL, FALSE);
-
- return g_pattern_match (pspec, strlen (string), string, NULL);
-}
diff --git a/glib_compat/gpattern.h b/glib_compat/gpattern.h
deleted file mode 100644
index cc50c5f5c1..0000000000
--- a/glib_compat/gpattern.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997, 1999 Peter Mattis, Red Hat, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see .
- */
-
-#ifndef __G_PATTERN_H__
-#define __G_PATTERN_H__
-
-#include "gtypes.h"
-
-typedef struct _GPatternSpec GPatternSpec;
-
-GPatternSpec* g_pattern_spec_new (const gchar *pattern);
-void g_pattern_spec_free (GPatternSpec *pspec);
-gboolean g_pattern_match (GPatternSpec *pspec,
- guint string_length,
- const gchar *string,
- const gchar *string_reversed);
-gboolean g_pattern_match_string (GPatternSpec *pspec,
- const gchar *string);
-
-#endif /* __G_PATTERN_H__ */
diff --git a/glib_compat/grand.c b/glib_compat/grand.c
deleted file mode 100644
index 0d3f95b4be..0000000000
--- a/glib_compat/grand.c
+++ /dev/null
@@ -1,384 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see .
- */
-
-/* Originally developed and coded by Makoto Matsumoto and Takuji
- * Nishimura. Please mail , if you're using
- * code from this file in your own programs or libraries.
- * Further information on the Mersenne Twister can be found at
- * http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
- * This code was adapted to glib by Sebastian Wilhelmi.
- */
-
-/*
- * Modified by the GLib Team and others 1997-2000. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-/*
- * MT safe
- */
-
-#define _CRT_RAND_S
-
-#include
-#include
-#include
-#include
-#include
-#ifndef _MSC_VER
-#include
-#include
-#else
-#include
-#endif
-
-#include "grand.h"
-#include "gmem.h"
-#include "gmessages.h"
-
-#define G_USEC_PER_SEC 1000000
-
-#if defined(__MINGW64_VERSION_MAJOR) || defined(_WIN32)
-errno_t rand_s(unsigned int* randomValue);
-#endif
-
-#define G_GINT64_CONSTANT(val) (val##L)
-
-/* Period parameters */
-#define N 624
-#define M 397
-#define MATRIX_A 0x9908b0df /* constant vector a */
-#define UPPER_MASK 0x80000000 /* most significant w-r bits */
-#define LOWER_MASK 0x7fffffff /* least significant r bits */
-
-/* Tempering parameters */
-#define TEMPERING_MASK_B 0x9d2c5680
-#define TEMPERING_MASK_C 0xefc60000
-#define TEMPERING_SHIFT_U(y) (y >> 11)
-#define TEMPERING_SHIFT_S(y) (y << 7)
-#define TEMPERING_SHIFT_T(y) (y << 15)
-#define TEMPERING_SHIFT_L(y) (y >> 18)
-
-struct _GRand
-{
- guint32 mt[N]; /* the array for the state vector */
- guint mti;
-};
-
-static guint get_random_version (void)
-{
- static gsize initialized = FALSE;
- static guint random_version;
-
- if (!initialized)
- {
- // g_warning ("Unknown G_RANDOM_VERSION \"%s\". Using version 2.2.", version_string);
- random_version = 22;
- initialized = TRUE;
- }
-
- return random_version;
-}
-
-/**
- * g_rand_set_seed:
- * @rand_: a #GRand
- * @seed: a value to reinitialize the random number generator
- *
- * Sets the seed for the random number generator #GRand to @seed.
- */
-void g_rand_set_seed (GRand *rand, guint32 seed)
-{
- g_return_if_fail (rand != NULL);
-
- switch (get_random_version ())
- {
- case 20:
- /* setting initial seeds to mt[N] using */
- /* the generator Line 25 of Table 1 in */
- /* [KNUTH 1981, The Art of Computer Programming */
- /* Vol. 2 (2nd Ed.), pp102] */
-
- if (seed == 0) /* This would make the PRNG produce only zeros */
- seed = 0x6b842128; /* Just set it to another number */
-
- rand->mt[0]= seed;
- for (rand->mti=1; rand->mtimti++)
- rand->mt[rand->mti] = (69069 * rand->mt[rand->mti-1]);
-
- break;
- case 22:
- /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
- /* In the previous version (see above), MSBs of the */
- /* seed affect only MSBs of the array mt[]. */
-
- rand->mt[0]= seed;
- for (rand->mti=1; rand->mtimti++)
- rand->mt[rand->mti] = 1812433253UL *
- (rand->mt[rand->mti-1] ^ (rand->mt[rand->mti-1] >> 30)) + rand->mti;
- break;
- default:
- // g_assert_not_reached ();
- break;
- }
-}
-
-/**
- * g_rand_new_with_seed:
- * @seed: a value to initialize the random number generator
- *
- * Creates a new random number generator initialized with @seed.
- *
- * Returns: the new #GRand
- **/
-GRand* g_rand_new_with_seed (guint32 seed)
-{
- GRand *rand = g_new0 (GRand, 1);
- g_rand_set_seed (rand, seed);
- return rand;
-}
-
-/**
- * g_rand_set_seed_array:
- * @rand_: a #GRand
- * @seed: array to initialize with
- * @seed_length: length of array
- *
- * Initializes the random number generator by an array of longs.
- * Array can be of arbitrary size, though only the first 624 values
- * are taken. This function is useful if you have many low entropy
- * seeds, or if you require more then 32 bits of actual entropy for
- * your application.
- *
- * Since: 2.4
- */
-void g_rand_set_seed_array (GRand *rand, const guint32 *seed, guint seed_length)
-{
- guint i, j, k;
-
- g_return_if_fail (rand != NULL);
- g_return_if_fail (seed_length >= 1);
-
- g_rand_set_seed (rand, 19650218UL);
-
- i=1; j=0;
- k = (N>seed_length ? N : seed_length);
- for (; k; k--)
- {
- rand->mt[i] = (rand->mt[i] ^
- ((rand->mt[i-1] ^ (rand->mt[i-1] >> 30)) * 1664525UL))
- + seed[j] + j; /* non linear */
- rand->mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
- i++; j++;
- if (i>=N)
- {
- rand->mt[0] = rand->mt[N-1];
- i=1;
- }
- if (j>=seed_length)
- j=0;
- }
- for (k=N-1; k; k--)
- {
- rand->mt[i] = (rand->mt[i] ^
- ((rand->mt[i-1] ^ (rand->mt[i-1] >> 30)) * 1566083941UL))
- - i; /* non linear */
- rand->mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
- i++;
- if (i>=N)
- {
- rand->mt[0] = rand->mt[N-1];
- i=1;
- }
- }
-
- rand->mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */
-}
-
-/**
- * g_rand_new_with_seed_array:
- * @seed: an array of seeds to initialize the random number generator
- * @seed_length: an array of seeds to initialize the random number
- * generator
- *
- * Creates a new random number generator initialized with @seed.
- *
- * Returns: the new #GRand
- *
- * Since: 2.4
- */
-GRand *g_rand_new_with_seed_array (const guint32 *seed, guint seed_length)
-{
- GRand *rand = g_new0 (GRand, 1);
- g_rand_set_seed_array (rand, seed, seed_length);
- return rand;
-}
-
-gint64 g_get_real_time (void)
-{
-#if defined(unix) || defined(__unix__) || defined(__unix) || defined (__MINGW32__) || defined(__APPLE__) || defined(__HAIKU__)
- struct timeval r;
-
- /* this is required on alpha, there the timeval structs are ints
- * not longs and a cast only would fail horribly */
- gettimeofday (&r, NULL);
-
- return (((gint64) r.tv_sec) * 1000000) + r.tv_usec;
-#else
- FILETIME ft;
- guint64 time64;
-
- GetSystemTimeAsFileTime (&ft);
- memmove (&time64, &ft, sizeof (FILETIME));
-
- /* Convert from 100s of nanoseconds since 1601-01-01
- * to Unix epoch. This is Y2038 safe.
- */
- time64 -= G_GINT64_CONSTANT (116444736000000000);
- time64 /= 10;
-
- return time64;
-#endif
-}
-
-/**
- * g_rand_new:
- *
- * Creates a new random number generator initialized with a seed taken
- * either from `/dev/urandom` (if existing) or from the current time
- * (as a fallback).
- *
- * On Windows, the seed is taken from rand_s().
- *
- * Returns: the new #GRand
- */
-GRand *g_rand_new (void)
-{
- guint32 seed[4];
-#if defined(unix) || defined(__unix__) || defined(__unix) || defined(__APPLE__) || defined(__HAIKU__)
- static gboolean dev_urandom_exists = TRUE;
-
- if (dev_urandom_exists)
- {
- FILE* dev_urandom;
-
- do
- {
- dev_urandom = fopen("/dev/urandom", "rb");
- }
- while (dev_urandom == NULL && errno == EINTR);
-
- if (dev_urandom)
- {
- int r;
-
- setvbuf (dev_urandom, NULL, _IONBF, 0);
- do
- {
- errno = 0;
- r = fread (seed, sizeof (seed), 1, dev_urandom);
- }
- while (errno == EINTR);
-
- if (r != 1)
- dev_urandom_exists = FALSE;
-
- fclose (dev_urandom);
- }
- else
- dev_urandom_exists = FALSE;
- }
-
- if (!dev_urandom_exists)
- {
- gint64 now_us = g_get_real_time ();
- seed[0] = now_us / G_USEC_PER_SEC;
- seed[1] = now_us % G_USEC_PER_SEC;
- seed[2] = getpid ();
- seed[3] = getppid ();
- }
-#else /* G_OS_WIN32 */
- /* rand_s() is only available since Visual Studio 2005 and
- * MinGW-w64 has a wrapper that will emulate rand_s() if it's not in msvcrt
- */
-#if (defined(_MSC_VER) && _MSC_VER >= 1400) || defined(__MINGW64_VERSION_MAJOR)
- gint i;
-
- for (i = 0; i < 4;/* array size of seed */ i++) {
- rand_s(&seed[i]);
- }
-#else
-#warning Using insecure seed for random number generation because of missing rand_s() in Windows XP
- GTimeVal now;
-
- g_get_current_time (&now);
- seed[0] = now.tv_sec;
- seed[1] = now.tv_usec;
- seed[2] = getpid ();
- seed[3] = 0;
-#endif
-
-#endif
-
- return g_rand_new_with_seed_array (seed, 4);
-}
-
-/**
- * g_rand_int:
- * @rand_: a #GRand
- *
- * Returns the next random #guint32 from @rand_ equally distributed over
- * the range [0..2^32-1].
- *
- * Returns: a random number
- */
-guint32 g_rand_int (GRand *rand)
-{
- guint32 y;
- static const guint32 mag01[2]={0x0, MATRIX_A};
- /* mag01[x] = x * MATRIX_A for x=0,1 */
-
- g_return_val_if_fail (rand != NULL, 0);
-
- if (rand->mti >= N) { /* generate N words at one time */
- int kk;
-
- for (kk = 0; kk < N - M; kk++) {
- y = (rand->mt[kk]&UPPER_MASK)|(rand->mt[kk+1]&LOWER_MASK);
- rand->mt[kk] = rand->mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1];
- }
- for (; kk < N - 1; kk++) {
- y = (rand->mt[kk]&UPPER_MASK)|(rand->mt[kk+1]&LOWER_MASK);
- rand->mt[kk] = rand->mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1];
- }
- y = (rand->mt[N-1]&UPPER_MASK)|(rand->mt[0]&LOWER_MASK);
- rand->mt[N-1] = rand->mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1];
-
- rand->mti = 0;
- }
-
- y = rand->mt[rand->mti++];
- y ^= TEMPERING_SHIFT_U(y);
- y ^= TEMPERING_SHIFT_S(y) & TEMPERING_MASK_B;
- y ^= TEMPERING_SHIFT_T(y) & TEMPERING_MASK_C;
- y ^= TEMPERING_SHIFT_L(y);
-
- return y;
-}
-
diff --git a/glib_compat/grand.h b/glib_compat/grand.h
deleted file mode 100644
index c8947717ec..0000000000
--- a/glib_compat/grand.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see .
- */
-
-/*
- * Modified by the GLib Team and others 1997-2000. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-#ifndef __G_RAND_H__
-#define __G_RAND_H__
-
-#include "gtypes.h"
-
-typedef struct _GRand GRand;
-
-GRand *g_rand_new_with_seed(guint32 seed);
-GRand *g_rand_new_with_seed_array (const guint32 *seed, guint seed_length);
-GRand *g_rand_new(void);
-guint32 g_rand_int(GRand *rand_);
-
-#endif /* __G_RAND_H__ */
diff --git a/glib_compat/gslice.c b/glib_compat/gslice.c
deleted file mode 100644
index 3b1581e277..0000000000
--- a/glib_compat/gslice.c
+++ /dev/null
@@ -1,91 +0,0 @@
-/* GLIB sliced memory - fast concurrent memory chunk allocator
- * Copyright (C) 2005 Tim Janik
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see .
- */
-/* MT safe */
-
-#include
-
-#include "gtypes.h"
-#include "gslice.h"
-#include "gmem.h" /* gslice.h */
-
-/**
- * g_slice_alloc:
- * @block_size: the number of bytes to allocate
- *
- * Allocates a block of memory from the slice allocator.
- * The block address handed out can be expected to be aligned
- * to at least 1 * sizeof (void*),
- * though in general slices are 2 * sizeof (void*) bytes aligned,
- * if a malloc() fallback implementation is used instead,
- * the alignment may be reduced in a libc dependent fashion.
- * Note that the underlying slice allocation mechanism can
- * be changed with the [`G_SLICE=always-malloc`][G_SLICE]
- * environment variable.
- *
- * Returns: a pointer to the allocated memory block, which will be %NULL if and
- * only if @mem_size is 0
- *
- * Since: 2.10
- */
-gpointer g_slice_alloc (gsize mem_size)
-{
- return g_malloc (mem_size);
-}
-
-/**
- * g_slice_alloc0:
- * @block_size: the number of bytes to allocate
- *
- * Allocates a block of memory via g_slice_alloc() and initializes
- * the returned memory to 0. Note that the underlying slice allocation
- * mechanism can be changed with the [`G_SLICE=always-malloc`][G_SLICE]
- * environment variable.
- *
- * Returns: a pointer to the allocated block, which will be %NULL if and only
- * if @mem_size is 0
- *
- * Since: 2.10
- */
-gpointer g_slice_alloc0 (gsize mem_size)
-{
- gpointer mem = g_slice_alloc (mem_size);
- if (mem)
- memset (mem, 0, mem_size);
- return mem;
-}
-
-/**
- * g_slice_free1:
- * @block_size: the size of the block
- * @mem_block: a pointer to the block to free
- *
- * Frees a block of memory.
- *
- * The memory must have been allocated via g_slice_alloc() or
- * g_slice_alloc0() and the @block_size has to match the size
- * specified upon allocation. Note that the exact release behaviour
- * can be changed with the [`G_DEBUG=gc-friendly`][G_DEBUG] environment
- * variable, also see [`G_SLICE`][G_SLICE] for related debugging options.
- *
- * If @mem_block is %NULL, this function does nothing.
- *
- * Since: 2.10
- */
-void g_slice_free1 (gsize mem_size, gpointer mem_block)
-{
- g_free (mem_block);
-}
diff --git a/glib_compat/gslice.h b/glib_compat/gslice.h
deleted file mode 100644
index 78fd21def3..0000000000
--- a/glib_compat/gslice.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/* GLIB sliced memory - fast threaded memory chunk allocator
- * Copyright (C) 2005 Tim Janik
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see .
- */
-
-#ifndef __G_SLICE_H__
-#define __G_SLICE_H__
-
-#include "gtypes.h"
-
-#define g_slice_new(type) ((type*) g_slice_alloc (sizeof (type)))
-#define g_slice_new0(type) ((type*) g_slice_alloc0 (sizeof (type)))
-
-gpointer g_slice_alloc0 (gsize block_size);
-gpointer g_slice_alloc (gsize block_size);
-void g_slice_free1 (gsize block_size, gpointer mem_block);
-
-#define g_slice_free(type, mem) \
- G_STMT_START { \
- if (1) g_slice_free1 (sizeof (type), (mem)); \
- else (void) ((type*) 0 == (mem)); \
- } G_STMT_END
-
-#endif /* __G_SLICE_H__ */
diff --git a/glib_compat/gtestutils.c b/glib_compat/gtestutils.c
deleted file mode 100644
index 7b795e5dae..0000000000
--- a/glib_compat/gtestutils.c
+++ /dev/null
@@ -1,34 +0,0 @@
-/* GLib testing utilities
- * Copyright (C) 2007 Imendio AB
- * Authors: Tim Janik, Sven Herzberg
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see .
- */
-
-#include "gtestutils.h"
-#include
-#include
-
-void
-g_assertion_message_expr (const char *file,
- int line,
- const char *expr)
-{
- if (!expr)
- printf("%s:%d code should not be reached", file, line);
- else
- printf("%s:%d assertion failed: %s", file, line, expr);
-
- abort();
-}
diff --git a/glib_compat/gtestutils.h b/glib_compat/gtestutils.h
deleted file mode 100644
index dd3de5d3fd..0000000000
--- a/glib_compat/gtestutils.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/* GLib testing utilities
- * Copyright (C) 2007 Imendio AB
- * Authors: Tim Janik
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see .
- */
-
-#ifndef __G_TEST_UTILS_H__
-#define __G_TEST_UTILS_H__
-
-
-#if !(defined (G_STMT_START) && defined (G_STMT_END))
-#define G_STMT_START do
-#if defined (_MSC_VER) && (_MSC_VER >= 1500)
-#define G_STMT_END \
- __pragma(warning(push)) \
- __pragma(warning(disable:4127)) \
- while(0) \
- __pragma(warning(pop))
-#else
-#define G_STMT_END while (0)
-#endif
-#endif
-
-#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
-#define G_GNUC_NORETURN \
- __attribute__((__noreturn__))
-#else /* !__GNUC__ */
-/* NOTE: MSVC has __declspec(noreturn) but unlike GCC __attribute__,
- * __declspec can only be placed at the start of the function prototype
- * and not at the end, so we can't use it without breaking API.
- */
-#define G_GNUC_NORETURN
-#endif /* !__GNUC__ */
-
-void g_assertion_message_expr (const char *file,
- int line,
- const char *expr) G_GNUC_NORETURN;
-
-#define g_assert_not_reached() G_STMT_START { g_assertion_message_expr (__FILE__, __LINE__, NULL); } G_STMT_END
-#define g_assert(expr) G_STMT_START { \
- if (expr) ; else \
- g_assertion_message_expr (__FILE__, __LINE__, #expr); \
- } G_STMT_END
-
-#endif /* __G_TEST_UTILS_H__ */
diff --git a/glib_compat/gtree.c b/glib_compat/gtree.c
deleted file mode 100644
index b2617a3fc7..0000000000
--- a/glib_compat/gtree.c
+++ /dev/null
@@ -1,1255 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see .
- */
-
-/*
- * Modified by the GLib Team and others 1997-2000. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-/*
- * MT safe
- */
-
-#include "gtypes.h"
-#include "gtree.h"
-//#include "gatomic.h"
-//#include "gtestutils.h"
-#include "gslice.h"
-#include "gmessages.h"
-#include "gnode.h"
-
-/**
- * SECTION:trees-binary
- * @title: Balanced Binary Trees
- * @short_description: a sorted collection of key/value pairs optimized
- * for searching and traversing in order
- *
- * The #GTree structure and its associated functions provide a sorted
- * collection of key/value pairs optimized for searching and traversing
- * in order.
- *
- * To create a new #GTree use g_tree_new().
- *
- * To insert a key/value pair into a #GTree use g_tree_insert().
- *
- * To look up the value corresponding to a given key, use
- * g_tree_lookup() and g_tree_lookup_extended().
- *
- * To find out the number of nodes in a #GTree, use g_tree_nnodes(). To
- * get the height of a #GTree, use g_tree_height().
- *
- * To traverse a #GTree, calling a function for each node visited in
- * the traversal, use g_tree_foreach().
- *
- * To remove a key/value pair use g_tree_remove().
- *
- * To destroy a #GTree, use g_tree_destroy().
- **/
-
-#undef G_TREE_DEBUG
-
-#define MAX_GTREE_HEIGHT 40
-
-typedef struct _GTreeNode GTreeNode;
-
-/**
- * GTree:
- *
- * The GTree struct is an opaque data structure representing a
- * [balanced binary tree][glib-Balanced-Binary-Trees]. It should be
- * accessed only by using the following functions.
- */
-struct _GTree
-{
- GTreeNode *root;
- GCompareDataFunc key_compare;
- GDestroyNotify key_destroy_func;
- GDestroyNotify value_destroy_func;
- gpointer key_compare_data;
- guint nnodes;
- gint ref_count;
-};
-
-struct _GTreeNode
-{
- gpointer key; /* key for this node */
- gpointer value; /* value stored at this node */
- GTreeNode *left; /* left subtree */
- GTreeNode *right; /* right subtree */
- gint8 balance; /* height (right) - height (left) */
- guint8 left_child;
- guint8 right_child;
-};
-
-
-static GTreeNode* g_tree_node_new (gpointer key,
- gpointer value);
-static void g_tree_insert_internal (GTree *tree,
- gpointer key,
- gpointer value,
- gboolean replace);
-static gboolean g_tree_remove_internal (GTree *tree,
- gconstpointer key,
- gboolean steal);
-static GTreeNode* g_tree_node_balance (GTreeNode *node);
-static GTreeNode *g_tree_find_node (GTree *tree,
- gconstpointer key);
-static gint g_tree_node_pre_order (GTreeNode *node,
- GTraverseFunc traverse_func,
- gpointer data);
-static gint g_tree_node_in_order (GTreeNode *node,
- GTraverseFunc traverse_func,
- gpointer data);
-static gint g_tree_node_post_order (GTreeNode *node,
- GTraverseFunc traverse_func,
- gpointer data);
-static gpointer g_tree_node_search (GTreeNode *node,
- GCompareFunc search_func,
- gconstpointer data);
-static GTreeNode* g_tree_node_rotate_left (GTreeNode *node);
-static GTreeNode* g_tree_node_rotate_right (GTreeNode *node);
-#ifdef G_TREE_DEBUG
-static void g_tree_node_check (GTreeNode *node);
-#endif
-
-
-static GTreeNode *g_tree_node_new (gpointer key, gpointer value)
-{
- GTreeNode *node = g_slice_new (GTreeNode);
-
- node->balance = 0;
- node->left = NULL;
- node->right = NULL;
- node->left_child = FALSE;
- node->right_child = FALSE;
- node->key = key;
- node->value = value;
-
- return node;
-}
-
-/**
- * g_tree_new:
- * @key_compare_func: the function used to order the nodes in the #GTree.
- * It should return values similar to the standard strcmp() function -
- * 0 if the two arguments are equal, a negative value if the first argument
- * comes before the second, or a positive value if the first argument comes
- * after the second.
- *
- * Creates a new #GTree.
- *
- * Returns: a newly allocated #GTree
- */
-GTree *g_tree_new (GCompareFunc key_compare_func)
-{
- g_return_val_if_fail (key_compare_func != NULL, NULL);
-
- return g_tree_new_full ((GCompareDataFunc) key_compare_func, NULL,
- NULL, NULL);
-}
-
-/**
- * g_tree_new_with_data:
- * @key_compare_func: qsort()-style comparison function
- * @key_compare_data: data to pass to comparison function
- *
- * Creates a new #GTree with a comparison function that accepts user data.
- * See g_tree_new() for more details.
- *
- * Returns: a newly allocated #GTree
- */
-GTree *g_tree_new_with_data (GCompareDataFunc key_compare_func, gpointer key_compare_data)
-{
- g_return_val_if_fail (key_compare_func != NULL, NULL);
-
- return g_tree_new_full (key_compare_func, key_compare_data, NULL, NULL);
-}
-
-/**
- * g_tree_new_full:
- * @key_compare_func: qsort()-style comparison function
- * @key_compare_data: data to pass to comparison function
- * @key_destroy_func: a function to free the memory allocated for the key
- * used when removing the entry from the #GTree or %NULL if you don't
- * want to supply such a function
- * @value_destroy_func: a function to free the memory allocated for the
- * value used when removing the entry from the #GTree or %NULL if you
- * don't want to supply such a function
- *
- * Creates a new #GTree like g_tree_new() and allows to specify functions
- * to free the memory allocated for the key and value that get called when
- * removing the entry from the #GTree.
- *
- * Returns: a newly allocated #GTree
- */
-GTree *g_tree_new_full (GCompareDataFunc key_compare_func,
- gpointer key_compare_data,
- GDestroyNotify key_destroy_func,
- GDestroyNotify value_destroy_func)
-{
- GTree *tree;
-
- g_return_val_if_fail (key_compare_func != NULL, NULL);
-
- tree = g_slice_new (GTree);
- tree->root = NULL;
- tree->key_compare = key_compare_func;
- tree->key_destroy_func = key_destroy_func;
- tree->value_destroy_func = value_destroy_func;
- tree->key_compare_data = key_compare_data;
- tree->nnodes = 0;
- tree->ref_count = 1;
-
- return tree;
-}
-
-static inline GTreeNode *g_tree_first_node (GTree *tree)
-{
- GTreeNode *tmp;
-
- if (!tree->root)
- return NULL;
-
- tmp = tree->root;
-
- while (tmp->left_child)
- tmp = tmp->left;
-
- return tmp;
-}
-
-static inline GTreeNode *g_tree_node_previous (GTreeNode *node)
-{
- GTreeNode *tmp;
-
- tmp = node->left;
-
- if (node->left_child)
- while (tmp->right_child)
- tmp = tmp->right;
-
- return tmp;
-}
-
-static inline GTreeNode *g_tree_node_next (GTreeNode *node)
-{
- GTreeNode *tmp;
-
- tmp = node->right;
-
- if (node->right_child)
- while (tmp->left_child)
- tmp = tmp->left;
-
- return tmp;
-}
-
-void g_tree_remove_all (GTree *tree)
-{
- GTreeNode *node;
- GTreeNode *next;
-
- g_return_if_fail (tree != NULL);
-
- node = g_tree_first_node (tree);
-
- while (node)
- {
- next = g_tree_node_next (node);
-
- if (tree->key_destroy_func)
- tree->key_destroy_func (node->key);
- if (tree->value_destroy_func)
- tree->value_destroy_func (node->value);
- g_slice_free (GTreeNode, node);
-
- node = next;
- }
-
- tree->root = NULL;
- tree->nnodes = 0;
-}
-
-/**
- * g_tree_ref:
- * @tree: a #GTree
- *
- * Increments the reference count of @tree by one.
- *
- * It is safe to call this function from any thread.
- *
- * Returns: the passed in #GTree
- *
- * Since: 2.22
- */
-GTree *g_tree_ref (GTree *tree)
-{
- g_return_val_if_fail (tree != NULL, NULL);
-
- tree->ref_count++;
-
- return tree;
-}
-
-/**
- * g_tree_unref:
- * @tree: a #GTree
- *
- * Decrements the reference count of @tree by one.
- * If the reference count drops to 0, all keys and values will
- * be destroyed (if destroy functions were specified) and all
- * memory allocated by @tree will be released.
- *
- * It is safe to call this function from any thread.
- *
- * Since: 2.22
- */
-void g_tree_unref (GTree *tree)
-{
- g_return_if_fail (tree != NULL);
-
- tree->ref_count--;
-
- if (!tree->ref_count)
- {
- g_tree_remove_all (tree);
- g_slice_free (GTree, tree);
- }
-}
-
-/**
- * g_tree_destroy:
- * @tree: a #GTree
- *
- * Removes all keys and values from the #GTree and decreases its
- * reference count by one. If keys and/or values are dynamically
- * allocated, you should either free them first or create the #GTree
- * using g_tree_new_full(). In the latter case the destroy functions
- * you supplied will be called on all keys and values before destroying
- * the #GTree.
- */
-void g_tree_destroy (GTree *tree)
-{
- g_return_if_fail (tree != NULL);
-
- g_tree_remove_all (tree);
- g_tree_unref (tree);
-}
-
-/**
- * g_tree_insert:
- * @tree: a #GTree
- * @key: the key to insert
- * @value: the value corresponding to the key
- *
- * Inserts a key/value pair into a #GTree.
- *
- * If the given key already exists in the #GTree its corresponding value
- * is set to the new value. If you supplied a @value_destroy_func when
- * creating the #GTree, the old value is freed using that function. If
- * you supplied a @key_destroy_func when creating the #GTree, the passed
- * key is freed using that function.
- *
- * The tree is automatically 'balanced' as new key/value pairs are added,
- * so that the distance from the root to every leaf is as small as possible.
- */
-void g_tree_insert (GTree *tree, gpointer key, gpointer value)
-{
- g_return_if_fail (tree != NULL);
-
- g_tree_insert_internal (tree, key, value, FALSE);
-
-#ifdef G_TREE_DEBUG
- g_tree_node_check (tree->root);
-#endif
-}
-
-/**
- * g_tree_replace:
- * @tree: a #GTree
- * @key: the key to insert
- * @value: the value corresponding to the key
- *
- * Inserts a new key and value into a #GTree similar to g_tree_insert().
- * The difference is that if the key already exists in the #GTree, it gets
- * replaced by the new key. If you supplied a @value_destroy_func when
- * creating the #GTree, the old value is freed using that function. If you
- * supplied a @key_destroy_func when creating the #GTree, the old key is
- * freed using that function.
- *
- * The tree is automatically 'balanced' as new key/value pairs are added,
- * so that the distance from the root to every leaf is as small as possible.
- */
-void g_tree_replace (GTree *tree, gpointer key, gpointer value)
-{
- g_return_if_fail (tree != NULL);
-
- g_tree_insert_internal (tree, key, value, TRUE);
-
-#ifdef G_TREE_DEBUG
- g_tree_node_check (tree->root);
-#endif
-}
-
-/* internal insert routine */
-static void g_tree_insert_internal (GTree *tree, gpointer key, gpointer value, gboolean replace)
-{
- GTreeNode *node;
- GTreeNode *path[MAX_GTREE_HEIGHT];
- int idx;
-
- g_return_if_fail (tree != NULL);
-
- if (!tree->root)
- {
- tree->root = g_tree_node_new (key, value);
- tree->nnodes++;
- return;
- }
-
- idx = 0;
- path[idx++] = NULL;
- node = tree->root;
-
- while (1)
- {
- int cmp = tree->key_compare (key, node->key, tree->key_compare_data);
-
- if (cmp == 0)
- {
- if (tree->value_destroy_func)
- tree->value_destroy_func (node->value);
-
- node->value = value;
-
- if (replace)
- {
- if (tree->key_destroy_func)
- tree->key_destroy_func (node->key);
-
- node->key = key;
- }
- else
- {
- /* free the passed key */
- if (tree->key_destroy_func)
- tree->key_destroy_func (key);
- }
-
- return;
- }
- else if (cmp < 0)
- {
- if (node->left_child)
- {
- path[idx++] = node;
- node = node->left;
- }
- else
- {
- GTreeNode *child = g_tree_node_new (key, value);
-
- child->left = node->left;
- child->right = node;
- node->left = child;
- node->left_child = TRUE;
- node->balance -= 1;
-
- tree->nnodes++;
-
- break;
- }
- }
- else
- {
- if (node->right_child)
- {
- path[idx++] = node;
- node = node->right;
- }
- else
- {
- GTreeNode *child = g_tree_node_new (key, value);
-
- child->right = node->right;
- child->left = node;
- node->right = child;
- node->right_child = TRUE;
- node->balance += 1;
-
- tree->nnodes++;
-
- break;
- }
- }
- }
-
- /* Restore balance. This is the goodness of a non-recursive
- * implementation, when we are done with balancing we 'break'
- * the loop and we are done.
- */
- while (1)
- {
- GTreeNode *bparent = path[--idx];
- gboolean left_node = (bparent && node == bparent->left);
- //g_assert (!bparent || bparent->left == node || bparent->right == node);
-
- if (node->balance < -1 || node->balance > 1)
- {
- node = g_tree_node_balance (node);
- if (bparent == NULL)
- tree->root = node;
- else if (left_node)
- bparent->left = node;
- else
- bparent->right = node;
- }
-
- if (node->balance == 0 || bparent == NULL)
- break;
-
- if (left_node)
- bparent->balance -= 1;
- else
- bparent->balance += 1;
-
- node = bparent;
- }
-}
-
-/**
- * g_tree_remove:
- * @tree: a #GTree
- * @key: the key to remove
- *
- * Removes a key/value pair from a #GTree.
- *
- * If the #GTree was created using g_tree_new_full(), the key and value
- * are freed using the supplied destroy functions, otherwise you have to
- * make sure that any dynamically allocated values are freed yourself.
- * If the key does not exist in the #GTree, the function does nothing.
- *
- * Returns: %TRUE if the key was found (prior to 2.8, this function
- * returned nothing)
- */
-gboolean g_tree_remove (GTree *tree, gconstpointer key)
-{
- gboolean removed;
-
- g_return_val_if_fail (tree != NULL, FALSE);
-
- removed = g_tree_remove_internal (tree, key, FALSE);
-
-#ifdef G_TREE_DEBUG
- g_tree_node_check (tree->root);
-#endif
-
- return removed;
-}
-
-/**
- * g_tree_steal:
- * @tree: a #GTree
- * @key: the key to remove
- *
- * Removes a key and its associated value from a #GTree without calling
- * the key and value destroy functions.
- *
- * If the key does not exist in the #GTree, the function does nothing.
- *
- * Returns: %TRUE if the key was found (prior to 2.8, this function
- * returned nothing)
- */
-gboolean g_tree_steal (GTree *tree, gconstpointer key)
-{
- gboolean removed;
-
- g_return_val_if_fail (tree != NULL, FALSE);
-
- removed = g_tree_remove_internal (tree, key, TRUE);
-
-#ifdef G_TREE_DEBUG
- g_tree_node_check (tree->root);
-#endif
-
- return removed;
-}
-
-/* internal remove routine */
-static gboolean g_tree_remove_internal (GTree *tree, gconstpointer key, gboolean steal)
-{
- GTreeNode *node, *parent, *balance;
- GTreeNode *path[MAX_GTREE_HEIGHT];
- int idx;
- gboolean left_node;
-
- g_return_val_if_fail (tree != NULL, FALSE);
-
- if (!tree->root)
- return FALSE;
-
- idx = 0;
- path[idx++] = NULL;
- node = tree->root;
-
- while (1)
- {
- int cmp = tree->key_compare (key, node->key, tree->key_compare_data);
-
- if (cmp == 0)
- break;
- else if (cmp < 0)
- {
- if (!node->left_child)
- return FALSE;
-
- path[idx++] = node;
- node = node->left;
- }
- else
- {
- if (!node->right_child)
- return FALSE;
-
- path[idx++] = node;
- node = node->right;
- }
- }
-
- /* The following code is almost equal to g_tree_remove_node,
- * except that we do not have to call g_tree_node_parent.
- */
- balance = parent = path[--idx];
- //g_assert (!parent || parent->left == node || parent->right == node);
- left_node = (parent && node == parent->left);
-
- if (!node->left_child)
- {
- if (!node->right_child)
- {
- if (!parent)
- tree->root = NULL;
- else if (left_node)
- {
- parent->left_child = FALSE;
- parent->left = node->left;
- parent->balance += 1;
- }
- else
- {
- parent->right_child = FALSE;
- parent->right = node->right;
- parent->balance -= 1;
- }
- }
- else /* node has a right child */
- {
- GTreeNode *tmp = g_tree_node_next (node);
- tmp->left = node->left;
-
- if (!parent)
- tree->root = node->right;
- else if (left_node)
- {
- parent->left = node->right;
- parent->balance += 1;
- }
- else
- {
- parent->right = node->right;
- parent->balance -= 1;
- }
- }
- }
- else /* node has a left child */
- {
- if (!node->right_child)
- {
- GTreeNode *tmp = g_tree_node_previous (node);
- tmp->right = node->right;
-
- if (parent == NULL)
- tree->root = node->left;
- else if (left_node)
- {
- parent->left = node->left;
- parent->balance += 1;
- }
- else
- {
- parent->right = node->left;
- parent->balance -= 1;
- }
- }
- else /* node has a both children (pant, pant!) */
- {
- GTreeNode *prev = node->left;
- GTreeNode *next = node->right;
- GTreeNode *nextp = node;
- int old_idx = idx + 1;
- idx++;
-
- /* path[idx] == parent */
- /* find the immediately next node (and its parent) */
- while (next->left_child)
- {
- path[++idx] = nextp = next;
- next = next->left;
- }
-
- path[old_idx] = next;
- balance = path[idx];
-
- /* remove 'next' from the tree */
- if (nextp != node)
- {
- if (next->right_child)
- nextp->left = next->right;
- else
- nextp->left_child = FALSE;
- nextp->balance += 1;
-
- next->right_child = TRUE;
- next->right = node->right;
- }
- else
- node->balance -= 1;
-
- /* set the prev to point to the right place */
- while (prev->right_child)
- prev = prev->right;
- prev->right = next;
-
- /* prepare 'next' to replace 'node' */
- next->left_child = TRUE;
- next->left = node->left;
- next->balance = node->balance;
-
- if (!parent)
- tree->root = next;
- else if (left_node)
- parent->left = next;
- else
- parent->right = next;
- }
- }
-
- /* restore balance */
- if (balance)
- while (1)
- {
- GTreeNode *bparent = path[--idx];
- //g_assert (!bparent || bparent->left == balance || bparent->right == balance);
- left_node = (bparent && balance == bparent->left);
-
- if(balance->balance < -1 || balance->balance > 1)
- {
- balance = g_tree_node_balance (balance);
- if (!bparent)
- tree->root = balance;
- else if (left_node)
- bparent->left = balance;
- else
- bparent->right = balance;
- }
-
- if (balance->balance != 0 || !bparent)
- break;
-
- if (left_node)
- bparent->balance += 1;
- else
- bparent->balance -= 1;
-
- balance = bparent;
- }
-
- if (!steal)
- {
- if (tree->key_destroy_func)
- tree->key_destroy_func (node->key);
- if (tree->value_destroy_func)
- tree->value_destroy_func (node->value);
- }
-
- g_slice_free (GTreeNode, node);
-
- tree->nnodes--;
-
- return TRUE;
-}
-
-/**
- * g_tree_lookup:
- * @tree: a #GTree
- * @key: the key to look up
- *
- * Gets the value corresponding to the given key. Since a #GTree is
- * automatically balanced as key/value pairs are added, key lookup
- * is O(log n) (where n is the number of key/value pairs in the tree).
- *
- * Returns: the value corresponding to the key, or %NULL
- * if the key was not found
- */
-gpointer g_tree_lookup (GTree *tree, gconstpointer key)
-{
- GTreeNode *node;
-
- g_return_val_if_fail (tree != NULL, NULL);
-
- node = g_tree_find_node (tree, key);
-
- return node ? node->value : NULL;
-}
-
-/**
- * g_tree_lookup_extended:
- * @tree: a #GTree
- * @lookup_key: the key to look up
- * @orig_key: (out) (optional) (nullable): returns the original key
- * @value: (out) (optional) (nullable): returns the value associated with the key
- *
- * Looks up a key in the #GTree, returning the original key and the
- * associated value. This is useful if you need to free the memory
- * allocated for the original key, for example before calling
- * g_tree_remove().
- *
- * Returns: %TRUE if the key was found in the #GTree
- */
-gboolean g_tree_lookup_extended (GTree *tree,
- gconstpointer lookup_key,
- gpointer *orig_key,
- gpointer *value)
-{
- GTreeNode *node;
-
- g_return_val_if_fail (tree != NULL, FALSE);
-
- node = g_tree_find_node (tree, lookup_key);
-
- if (node)
- {
- if (orig_key)
- *orig_key = node->key;
- if (value)
- *value = node->value;
- return TRUE;
- }
- else
- return FALSE;
-}
-
-/**
- * g_tree_foreach:
- * @tree: a #GTree
- * @func: the function to call for each node visited.
- * If this function returns %TRUE, the traversal is stopped.
- * @user_data: user data to pass to the function
- *
- * Calls the given function for each of the key/value pairs in the #GTree.
- * The function is passed the key and value of each pair, and the given
- * @data parameter. The tree is traversed in sorted order.
- *
- * The tree may not be modified while iterating over it (you can't
- * add/remove items). To remove all items matching a predicate, you need
- * to add each item to a list in your #GTraverseFunc as you walk over
- * the tree, then walk the list and remove each item.
- */
-void g_tree_foreach (GTree *tree, GTraverseFunc func, gpointer user_data)
-{
- GTreeNode *node;
-
- g_return_if_fail (tree != NULL);
-
- if (!tree->root)
- return;
-
- node = g_tree_first_node (tree);
-
- while (node)
- {
- if ((*func) (node->key, node->value, user_data))
- break;
-
- node = g_tree_node_next (node);
- }
-}
-
-/**
- * g_tree_traverse:
- * @tree: a #GTree
- * @traverse_func: the function to call for each node visited. If this
- * function returns %TRUE, the traversal is stopped.
- * @traverse_type: the order in which nodes are visited, one of %G_IN_ORDER,
- * %G_PRE_ORDER and %G_POST_ORDER
- * @user_data: user data to pass to the function
- *
- * Calls the given function for each node in the #GTree.
- *
- * Deprecated:2.2: The order of a balanced tree is somewhat arbitrary.
- * If you just want to visit all nodes in sorted order, use
- * g_tree_foreach() instead. If you really need to visit nodes in
- * a different order, consider using an [n-ary tree][glib-N-ary-Trees].
- */
-/**
- * GTraverseFunc:
- * @key: a key of a #GTree node
- * @value: the value corresponding to the key
- * @data: user data passed to g_tree_traverse()
- *
- * Specifies the type of function passed to g_tree_traverse(). It is
- * passed the key and value of each node, together with the @user_data
- * parameter passed to g_tree_traverse(). If the function returns
- * %TRUE, the traversal is stopped.
- *
- * Returns: %TRUE to stop the traversal
- */
-void g_tree_traverse (GTree *tree,
- GTraverseFunc traverse_func,
- GTraverseType traverse_type,
- gpointer user_data)
-{
- g_return_if_fail (tree != NULL);
-
- if (!tree->root)
- return;
-
- switch (traverse_type)
- {
- case G_PRE_ORDER:
- g_tree_node_pre_order (tree->root, traverse_func, user_data);
- break;
-
- case G_IN_ORDER:
- g_tree_node_in_order (tree->root, traverse_func, user_data);
- break;
-
- case G_POST_ORDER:
- g_tree_node_post_order (tree->root, traverse_func, user_data);
- break;
-
- case G_LEVEL_ORDER:
- //g_warning ("g_tree_traverse(): traverse type G_LEVEL_ORDER isn't implemented.");
- break;
- }
-}
-
-/**
- * g_tree_search:
- * @tree: a #GTree
- * @search_func: a function used to search the #GTree
- * @user_data: the data passed as the second argument to @search_func
- *
- * Searches a #GTree using @search_func.
- *
- * The @search_func is called with a pointer to the key of a key/value
- * pair in the tree, and the passed in @user_data. If @search_func returns
- * 0 for a key/value pair, then the corresponding value is returned as
- * the result of g_tree_search(). If @search_func returns -1, searching
- * will proceed among the key/value pairs that have a smaller key; if
- * @search_func returns 1, searching will proceed among the key/value
- * pairs that have a larger key.
- *
- * Returns: the value corresponding to the found key, or %NULL
- * if the key was not found
- */
-gpointer g_tree_search (GTree *tree,
- GCompareFunc search_func,
- gconstpointer user_data)
-{
- g_return_val_if_fail (tree != NULL, NULL);
-
- if (tree->root)
- return g_tree_node_search (tree->root, search_func, user_data);
- else
- return NULL;
-}
-
-/**
- * g_tree_height:
- * @tree: a #GTree
- *
- * Gets the height of a #GTree.
- *
- * If the #GTree contains no nodes, the height is 0.
- * If the #GTree contains only one root node the height is 1.
- * If the root node has children the height is 2, etc.
- *
- * Returns: the height of @tree
- */
-gint g_tree_height (GTree *tree)
-{
- GTreeNode *node;
- gint height;
-
- g_return_val_if_fail (tree != NULL, 0);
-
- if (!tree->root)
- return 0;
-
- height = 0;
- node = tree->root;
-
- while (1)
- {
- height += 1 + MAX(node->balance, 0);
-
- if (!node->left_child)
- return height;
-
- node = node->left;
- }
-}
-
-/**
- * g_tree_nnodes:
- * @tree: a #GTree
- *
- * Gets the number of nodes in a #GTree.
- *
- * Returns: the number of nodes in @tree
- */
-gint g_tree_nnodes (GTree *tree)
-{
- g_return_val_if_fail (tree != NULL, 0);
-
- return tree->nnodes;
-}
-
-static GTreeNode *g_tree_node_balance (GTreeNode *node)
-{
- if (node->balance < -1)
- {
- if (node->left->balance > 0)
- node->left = g_tree_node_rotate_left (node->left);
- node = g_tree_node_rotate_right (node);
- }
- else if (node->balance > 1)
- {
- if (node->right->balance < 0)
- node->right = g_tree_node_rotate_right (node->right);
- node = g_tree_node_rotate_left (node);
- }
-
- return node;
-}
-
-static GTreeNode *g_tree_find_node (GTree *tree, gconstpointer key)
-{
- GTreeNode *node;
- gint cmp;
-
- node = tree->root;
- if (!node)
- return NULL;
-
- while (1)
- {
- cmp = tree->key_compare (key, node->key, tree->key_compare_data);
- if (cmp == 0)
- return node;
- else if (cmp < 0)
- {
- if (!node->left_child)
- return NULL;
-
- node = node->left;
- }
- else
- {
- if (!node->right_child)
- return NULL;
-
- node = node->right;
- }
- }
-}
-
-static gint g_tree_node_pre_order (GTreeNode *node, GTraverseFunc traverse_func, gpointer data)
-{
- if ((*traverse_func) (node->key, node->value, data))
- return TRUE;
-
- if (node->left_child)
- {
- if (g_tree_node_pre_order (node->left, traverse_func, data))
- return TRUE;
- }
-
- if (node->right_child)
- {
- if (g_tree_node_pre_order (node->right, traverse_func, data))
- return TRUE;
- }
-
- return FALSE;
-}
-
-static gint g_tree_node_in_order (GTreeNode *node, GTraverseFunc traverse_func, gpointer data)
-{
- if (node->left_child)
- {
- if (g_tree_node_in_order (node->left, traverse_func, data))
- return TRUE;
- }
-
- if ((*traverse_func) (node->key, node->value, data))
- return TRUE;
-
- if (node->right_child)
- {
- if (g_tree_node_in_order (node->right, traverse_func, data))
- return TRUE;
- }
-
- return FALSE;
-}
-
-static gint g_tree_node_post_order (GTreeNode *node,
- GTraverseFunc traverse_func,
- gpointer data)
-{
- if (node->left_child)
- {
- if (g_tree_node_post_order (node->left, traverse_func, data))
- return TRUE;
- }
-
- if (node->right_child)
- {
- if (g_tree_node_post_order (node->right, traverse_func, data))
- return TRUE;
- }
-
- if ((*traverse_func) (node->key, node->value, data))
- return TRUE;
-
- return FALSE;
-}
-
-static gpointer g_tree_node_search (GTreeNode *node,
- GCompareFunc search_func,
- gconstpointer data)
-{
- gint dir;
-
- if (!node)
- return NULL;
-
- while (1)
- {
- dir = (* search_func) (node->key, data);
- if (dir == 0)
- return node->value;
- else if (dir < 0)
- {
- if (!node->left_child)
- return NULL;
-
- node = node->left;
- }
- else
- {
- if (!node->right_child)
- return NULL;
-
- node = node->right;
- }
- }
-}
-
-static GTreeNode *g_tree_node_rotate_left (GTreeNode *node)
-{
- GTreeNode *right;
- gint a_bal;
- gint b_bal;
-
- right = node->right;
-
- if (right->left_child)
- node->right = right->left;
- else
- {
- node->right_child = FALSE;
- right->left_child = TRUE;
- }
- right->left = node;
-
- a_bal = node->balance;
- b_bal = right->balance;
-
- if (b_bal <= 0)
- {
- if (a_bal >= 1)
- right->balance = b_bal - 1;
- else
- right->balance = a_bal + b_bal - 2;
- node->balance = a_bal - 1;
- }
- else
- {
- if (a_bal <= b_bal)
- right->balance = a_bal - 2;
- else
- right->balance = b_bal - 1;
- node->balance = a_bal - b_bal - 1;
- }
-
- return right;
-}
-
-static GTreeNode *g_tree_node_rotate_right (GTreeNode *node)
-{
- GTreeNode *left;
- gint a_bal;
- gint b_bal;
-
- left = node->left;
-
- if (left->right_child)
- node->left = left->right;
- else
- {
- node->left_child = FALSE;
- left->right_child = TRUE;
- }
- left->right = node;
-
- a_bal = node->balance;
- b_bal = left->balance;
-
- if (b_bal <= 0)
- {
- if (b_bal > a_bal)
- left->balance = b_bal + 1;
- else
- left->balance = a_bal + 2;
- node->balance = a_bal - b_bal + 1;
- }
- else
- {
- if (a_bal <= -1)
- left->balance = b_bal + 1;
- else
- left->balance = a_bal + b_bal + 2;
- node->balance = a_bal + 1;
- }
-
- return left;
-}
diff --git a/glib_compat/gtree.h b/glib_compat/gtree.h
deleted file mode 100644
index 47b6c8802f..0000000000
--- a/glib_compat/gtree.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see .
- */
-
-/*
- * Modified by the GLib Team and others 1997-2000. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-#ifndef __G_TREE_H__
-#define __G_TREE_H__
-
-typedef struct _GTree GTree;
-
-typedef gboolean (*GTraverseFunc) (gpointer key, gpointer value, gpointer data);
-
-/* Balanced binary trees
- */
-GTree* g_tree_new (GCompareFunc key_compare_func);
-
-GTree* g_tree_new_full (GCompareDataFunc key_compare_func,
- gpointer key_compare_data,
- GDestroyNotify key_destroy_func,
- GDestroyNotify value_destroy_func);
-
-GTree* g_tree_ref (GTree *tree);
-
-void g_tree_destroy (GTree *tree);
-
-void g_tree_insert (GTree *tree, gpointer key, gpointer value);
-
-void g_tree_remove_all (GTree *tree);
-
-gboolean g_tree_remove (GTree *tree, gconstpointer key);
-
-gpointer g_tree_lookup (GTree *tree, gconstpointer key);
-
-void g_tree_foreach (GTree *tree, GTraverseFunc func, gpointer user_data);
-
-gint g_tree_nnodes (GTree *tree);
-
-#endif /* __G_TREE_H__ */
diff --git a/glib_compat/gtypes.h b/glib_compat/gtypes.h
deleted file mode 100644
index c17b3f6655..0000000000
--- a/glib_compat/gtypes.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see .
- */
-
-/*
- * Modified by the GLib Team and others 1997-2000. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-#ifndef __G_TYPES_H__
-#define __G_TYPES_H__
-
-#include
-#include
-#include
-
-#ifndef TRUE
-#define TRUE 1
-#endif
-
-#ifndef FALSE
-#define FALSE 0
-#endif
-
-#define MAX(a, b) (((a) > (b)) ? (a) : (b))
-
-/* typedefs for glib related types that may still be referenced */
-typedef void* gpointer;
-
-typedef const void *gconstpointer;
-
-typedef int gint;
-typedef uint8_t guint8;
-typedef int8_t gint8;
-typedef uint16_t guint16;
-typedef int16_t gint16;
-typedef uint32_t guint32;
-typedef int32_t gint32;
-typedef uint64_t guint64;
-typedef int64_t gint64;
-typedef unsigned int guint;
-typedef char gchar;
-typedef int gboolean;
-typedef unsigned long gulong;
-typedef unsigned long gsize;
-
-typedef gint grefcount;
-
-typedef volatile gint gatomicrefcount;
-
-typedef void (*GDestroyNotify) (gpointer data);
-
-typedef gint (*GCompareFunc) (gconstpointer a, gconstpointer b);
-
-typedef gint (*GCompareDataFunc) (gconstpointer a, gconstpointer b, gpointer user_data);
-
-typedef guint (*GHashFunc) (gconstpointer key);
-
-typedef gboolean (*GEqualFunc) (gconstpointer a, gconstpointer b);
-
-typedef void (*GHFunc) (gpointer key, gpointer value, gpointer user_data);
-
-typedef gpointer (*GCopyFunc) (gconstpointer src, gpointer data);
-
-#endif /* __G_TYPES_H__ */
diff --git a/qemu/accel/tcg/cputlb.c b/qemu/accel/tcg/cputlb.c
index 41ae6b07ca..9e0c7964c9 100644
--- a/qemu/accel/tcg/cputlb.c
+++ b/qemu/accel/tcg/cputlb.c
@@ -35,7 +35,7 @@
#include
-#include
+#include
/* DEBUG defines, enable DEBUG_TLB_LOG to log to the CPU_LOG_MMU target */
/* #define DEBUG_TLB */
diff --git a/qemu/include/qemu/osdep.h b/qemu/include/qemu/osdep.h
index ad18b8ddd6..415357e1e8 100644
--- a/qemu/include/qemu/osdep.h
+++ b/qemu/include/qemu/osdep.h
@@ -130,7 +130,7 @@ struct uc_struct;
#define USE_MAP_JIT
#endif
-#include
+#include
#include "qemu/typedefs.h"
diff --git a/qemu/tcg/tcg.c b/qemu/tcg/tcg.c
index dcacec7cc4..26a74f8607 100644
--- a/qemu/tcg/tcg.c
+++ b/qemu/tcg/tcg.c
@@ -34,7 +34,7 @@
#include "qemu/host-utils.h"
#include "qemu/timer.h"
-#include
+#include
/* Note: the long term plan is to reduce the dependencies on the QEMU
CPU definitions. Currently they are used for qemu_ld/st