remove glib dependency by provide compatible replacements
This commit is contained in:
@@ -1,201 +0,0 @@
|
||||
/*
|
||||
* GLIB Compatibility Functions
|
||||
*
|
||||
* Copyright IBM, Corp. 2013
|
||||
*
|
||||
* Authors:
|
||||
* Anthony Liguori <aliguori@us.ibm.com>
|
||||
* Michael Tokarev <mjt@tls.msk.ru>
|
||||
* Paolo Bonzini <pbonzini@redhat.com>
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||
* See the COPYING file in the top-level directory.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef QEMU_GLIB_COMPAT_H
|
||||
#define QEMU_GLIB_COMPAT_H
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
/* GLIB version compatibility flags */
|
||||
#if !GLIB_CHECK_VERSION(2, 26, 0)
|
||||
#define G_TIME_SPAN_SECOND (G_GINT64_CONSTANT(1000000))
|
||||
#endif
|
||||
|
||||
#if !GLIB_CHECK_VERSION(2, 14, 0)
|
||||
static inline guint g_timeout_add_seconds(guint interval, GSourceFunc function,
|
||||
gpointer data)
|
||||
{
|
||||
return g_timeout_add(interval * 1000, function, data);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !GLIB_CHECK_VERSION(2, 28, 0)
|
||||
static inline gint64 g_get_monotonic_time(void)
|
||||
{
|
||||
/* g_get_monotonic_time() is best-effort so we can use the wall clock as a
|
||||
* fallback.
|
||||
*/
|
||||
|
||||
GTimeVal time;
|
||||
g_get_current_time(&time);
|
||||
|
||||
return time.tv_sec * G_TIME_SPAN_SECOND + time.tv_usec;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !GLIB_CHECK_VERSION(2, 16, 0)
|
||||
static inline int g_strcmp0(const char *str1, const char *str2)
|
||||
{
|
||||
int result;
|
||||
|
||||
if (!str1) {
|
||||
result = -(str1 != str2);
|
||||
} else if (!str2) {
|
||||
result = (str1 != str2);
|
||||
} else {
|
||||
result = strcmp(str1, str2);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
/*
|
||||
* g_poll has a problem on Windows when using
|
||||
* timeouts < 10ms, so use wrapper.
|
||||
*/
|
||||
#define g_poll(fds, nfds, timeout) g_poll_fixed(fds, nfds, timeout)
|
||||
gint g_poll_fixed(GPollFD *fds, guint nfds, gint timeout);
|
||||
#elif !GLIB_CHECK_VERSION(2, 20, 0)
|
||||
/*
|
||||
* Glib before 2.20.0 doesn't implement g_poll, so wrap it to compile properly
|
||||
* on older systems.
|
||||
*/
|
||||
static inline gint g_poll(GPollFD *fds, guint nfds, gint timeout)
|
||||
{
|
||||
GMainContext *ctx = g_main_context_default();
|
||||
return g_main_context_get_poll_func(ctx)(fds, nfds, timeout);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !GLIB_CHECK_VERSION(2, 31, 0)
|
||||
/* before glib-2.31, GMutex and GCond was dynamic-only (there was a separate
|
||||
* GStaticMutex, but it didn't work with condition variables).
|
||||
*
|
||||
* Our implementation uses GOnce to fake a static implementation that does
|
||||
* not require separate initialization.
|
||||
* We need to rename the types to avoid passing our CompatGMutex/CompatGCond
|
||||
* by mistake to a function that expects GMutex/GCond. However, for ease
|
||||
* of use we keep the GLib function names. GLib uses macros for the
|
||||
* implementation, we use inline functions instead and undefine the macros.
|
||||
*/
|
||||
|
||||
typedef struct CompatGMutex {
|
||||
GOnce once;
|
||||
} CompatGMutex;
|
||||
|
||||
typedef struct CompatGCond {
|
||||
GOnce once;
|
||||
} CompatGCond;
|
||||
|
||||
static inline gpointer do_g_mutex_new(gpointer unused)
|
||||
{
|
||||
return (gpointer) g_mutex_new();
|
||||
}
|
||||
|
||||
static inline void g_mutex_init(CompatGMutex *mutex)
|
||||
{
|
||||
mutex->once = (GOnce) G_ONCE_INIT;
|
||||
}
|
||||
|
||||
static inline void g_mutex_clear(CompatGMutex *mutex)
|
||||
{
|
||||
assert(mutex->once.status != G_ONCE_STATUS_PROGRESS);
|
||||
if (mutex->once.retval) {
|
||||
g_mutex_free((GMutex *) mutex->once.retval);
|
||||
}
|
||||
mutex->once = (GOnce) G_ONCE_INIT;
|
||||
}
|
||||
|
||||
static inline void (g_mutex_lock)(CompatGMutex *mutex)
|
||||
{
|
||||
g_once(&mutex->once, do_g_mutex_new, NULL);
|
||||
g_mutex_lock((GMutex *) mutex->once.retval);
|
||||
}
|
||||
#undef g_mutex_lock
|
||||
|
||||
static inline gboolean (g_mutex_trylock)(CompatGMutex *mutex)
|
||||
{
|
||||
g_once(&mutex->once, do_g_mutex_new, NULL);
|
||||
return g_mutex_trylock((GMutex *) mutex->once.retval);
|
||||
}
|
||||
#undef g_mutex_trylock
|
||||
|
||||
|
||||
static inline void (g_mutex_unlock)(CompatGMutex *mutex)
|
||||
{
|
||||
g_mutex_unlock((GMutex *) mutex->once.retval);
|
||||
}
|
||||
#undef g_mutex_unlock
|
||||
|
||||
static inline gpointer do_g_cond_new(gpointer unused)
|
||||
{
|
||||
return (gpointer) g_cond_new();
|
||||
}
|
||||
|
||||
static inline void g_cond_init(CompatGCond *cond)
|
||||
{
|
||||
cond->once = (GOnce) G_ONCE_INIT;
|
||||
}
|
||||
|
||||
static inline void g_cond_clear(CompatGCond *cond)
|
||||
{
|
||||
assert(cond->once.status != G_ONCE_STATUS_PROGRESS);
|
||||
if (cond->once.retval) {
|
||||
g_cond_free((GCond *) cond->once.retval);
|
||||
}
|
||||
cond->once = (GOnce) G_ONCE_INIT;
|
||||
}
|
||||
|
||||
static inline void (g_cond_wait)(CompatGCond *cond, CompatGMutex *mutex)
|
||||
{
|
||||
assert(mutex->once.status != G_ONCE_STATUS_PROGRESS);
|
||||
g_once(&cond->once, do_g_cond_new, NULL);
|
||||
g_cond_wait((GCond *) cond->once.retval, (GMutex *) mutex->once.retval);
|
||||
}
|
||||
#undef g_cond_wait
|
||||
|
||||
static inline void (g_cond_broadcast)(CompatGCond *cond)
|
||||
{
|
||||
g_once(&cond->once, do_g_cond_new, NULL);
|
||||
g_cond_broadcast((GCond *) cond->once.retval);
|
||||
}
|
||||
#undef g_cond_broadcast
|
||||
|
||||
static inline void (g_cond_signal)(CompatGCond *cond)
|
||||
{
|
||||
g_once(&cond->once, do_g_cond_new, NULL);
|
||||
g_cond_signal((GCond *) cond->once.retval);
|
||||
}
|
||||
#undef g_cond_signal
|
||||
|
||||
|
||||
/* before 2.31 there was no g_thread_new() */
|
||||
static inline GThread *g_thread_new(const char *name,
|
||||
GThreadFunc func, gpointer data)
|
||||
{
|
||||
GThread *thread = g_thread_create(func, data, TRUE, NULL);
|
||||
if (!thread) {
|
||||
g_error("creating thread");
|
||||
}
|
||||
return thread;
|
||||
}
|
||||
#else
|
||||
#define CompatGMutex GMutex
|
||||
#define CompatGCond GCond
|
||||
#endif /* glib 2.31 */
|
||||
|
||||
#endif
|
||||
135
qemu/include/glib_compat.h
Normal file
135
qemu/include/glib_compat.h
Normal file
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
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 <stdint.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 1
|
||||
#endif
|
||||
|
||||
#define g_assert(expr) assert(expr)
|
||||
#define g_assert_not_reached() assert(0)
|
||||
|
||||
/* typedefs for glib related types that may still be referenced */
|
||||
typedef void* gpointer;
|
||||
typedef const void *gconstpointer;
|
||||
typedef uint32_t guint;
|
||||
typedef char gchar;
|
||||
typedef int gboolean;
|
||||
|
||||
typedef int (*GCompareFunc)(const void *v1, const void *v2);
|
||||
typedef void (*GDestroyNotify)(void *data);
|
||||
|
||||
uint32_t g_direct_hash(const void *v);
|
||||
int g_direct_equal(const void *v1, const void *v2);
|
||||
uint32_t g_str_hash(const void *v);
|
||||
int g_str_equal(const void *v1, const void *v2);
|
||||
uint32_t g_int_hash(const void *v);
|
||||
int g_int_equal(const void *v1, const void *v2);
|
||||
|
||||
typedef struct _GList {
|
||||
void *data;
|
||||
struct _GList *next;
|
||||
struct _GList *prev;
|
||||
} GList;
|
||||
|
||||
typedef void (*list_func)(void* data, void* user_data);
|
||||
typedef int (*compare_func)(const void *d1, const void *d2);
|
||||
|
||||
GList *g_list_first(GList *list);
|
||||
void g_list_foreach(GList *list, list_func func, void* user_data);
|
||||
void g_list_free(GList *list);
|
||||
GList *g_list_insert_sorted(GList *list, void* data, compare_func compare);
|
||||
#define g_list_next(list) (list->next)
|
||||
GList *g_list_prepend(GList *list, void* data);
|
||||
GList *g_list_remove_link(GList *list, GList *llink);
|
||||
GList *g_list_sort(GList *list, compare_func compare);
|
||||
|
||||
typedef struct _GSList {
|
||||
void *data;
|
||||
struct _GSList *next;
|
||||
} GSList;
|
||||
|
||||
GSList *g_slist_append(GSList *list, void* data);
|
||||
void g_slist_foreach(GSList *list, list_func func, void* user_data);
|
||||
void g_slist_free(GSList *list);
|
||||
void g_slist_free_full(GSList *list, GDestroyNotify free_func);
|
||||
GSList *g_slist_prepend(GSList *list, void* data);
|
||||
GSList *g_slist_sort(GSList *list, compare_func compare);
|
||||
GSList *g_slist_find_custom(GSList *list, const void *data, compare_func func);
|
||||
GSList *g_slist_remove(GSList *list, const void *data);
|
||||
|
||||
typedef uint32_t (*GHashFunc)(const void *key);
|
||||
typedef int (*GEqualFunc)(const void *a, const void *b);
|
||||
typedef void (*GHFunc)(void* key, void* value, void* user_data);
|
||||
typedef int (*GHRFunc)(void* key, void* value, void* user_data);
|
||||
|
||||
typedef struct _GHashTable GHashTable;
|
||||
|
||||
void g_hash_table_destroy(GHashTable *hash_table);
|
||||
void* g_hash_table_find(GHashTable *hash_table, GHRFunc predicate, void* user_data);
|
||||
void g_hash_table_foreach(GHashTable *hash_table, GHFunc func, void* user_data);
|
||||
int g_hash_table_insert(GHashTable *hash_table, void* key, void* value);
|
||||
void* g_hash_table_lookup(GHashTable *hash_table, const void* key);
|
||||
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_remove_all(GHashTable *hash_table);
|
||||
int g_hash_table_remove(GHashTable *hash_table, const void* key);
|
||||
void g_hash_table_unref(GHashTable *hash_table);
|
||||
GHashTable *g_hash_table_ref(GHashTable *hash_table);
|
||||
uint32_t g_hash_table_size(GHashTable *hash_table);
|
||||
|
||||
/* replacement for g_malloc dependency */
|
||||
void *g_malloc(size_t size);
|
||||
void *g_malloc0(size_t size);
|
||||
void *g_try_malloc0(size_t size);
|
||||
void *g_realloc(void *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);
|
||||
void *g_memdup(const void *mem, size_t byte_size);
|
||||
void *g_new_(size_t sz, size_t n_structs);
|
||||
void *g_new0_(size_t sz, size_t n_structs);
|
||||
void *g_renew_(size_t sz, void *mem, size_t n_structs);
|
||||
char *g_strconcat(const char *string1, ...);
|
||||
|
||||
char **g_strsplit(const char *string, const char *delimiter, int max_tokens);
|
||||
|
||||
#define g_new(struct_type, n_structs) ((struct_type*)g_new_(sizeof(struct_type), n_structs))
|
||||
#define g_new0(struct_type, n_structs) ((struct_type*)g_new0_(sizeof(struct_type), n_structs))
|
||||
#define g_renew(struct_type, mem, n_structs) ((struct_type*)g_renew_(sizeof(struct_type), mem, n_structs))
|
||||
|
||||
#ifdef _WIN32
|
||||
char *g_win32_error_message(int error);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -57,7 +57,7 @@ struct arm_boot_info {
|
||||
* sets get_dtb. This will only be used if no dtb file is provided
|
||||
* by the user. On success, sets *size to the length of the created
|
||||
* dtb, and returns a pointer to it. (The caller must free this memory
|
||||
* with g_free() when it has finished with it.) On failure, returns NULL.
|
||||
* with free() when it has finished with it.) On failure, returns NULL.
|
||||
*/
|
||||
void *(*get_dtb)(const struct arm_boot_info *info, int *size);
|
||||
/* if a board needs to be able to modify a device tree provided by
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* String printing Visitor
|
||||
*
|
||||
* Copyright Red Hat, Inc. 2012
|
||||
*
|
||||
* Author: Paolo Bonzini <pbonzini@redhat.com>
|
||||
*
|
||||
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
|
||||
* See the COPYING.LIB file in the top-level directory.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef STRING_OUTPUT_VISITOR_H
|
||||
#define STRING_OUTPUT_VISITOR_H
|
||||
|
||||
#include "qapi/visitor.h"
|
||||
|
||||
typedef struct StringOutputVisitor StringOutputVisitor;
|
||||
|
||||
StringOutputVisitor *string_output_visitor_new(bool human);
|
||||
void string_output_visitor_cleanup(StringOutputVisitor *v);
|
||||
|
||||
char *string_output_get_string(StringOutputVisitor *v);
|
||||
Visitor *string_output_get_visitor(StringOutputVisitor *v);
|
||||
|
||||
#endif
|
||||
@@ -41,7 +41,7 @@
|
||||
#include <sys/time.h>
|
||||
#include <assert.h>
|
||||
#include <signal.h>
|
||||
#include "glib-compat.h"
|
||||
#include "glib_compat.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "sysemu/os-win32.h"
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#ifndef BITMAP_H
|
||||
#define BITMAP_H
|
||||
|
||||
#include <glib.h>
|
||||
#include "glib_compat.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
@@ -209,19 +209,8 @@ const char *qemu_get_version(void);
|
||||
void fips_set_state(bool requested);
|
||||
bool fips_get_state(void);
|
||||
|
||||
/* Return a dynamically allocated pathname denoting a file or directory that is
|
||||
* appropriate for storing local state.
|
||||
*
|
||||
* @relative_pathname need not start with a directory separator; one will be
|
||||
* added automatically.
|
||||
*
|
||||
* The caller is responsible for releasing the value returned with g_free()
|
||||
* after use.
|
||||
*/
|
||||
char *qemu_get_local_state_pathname(const char *relative_pathname);
|
||||
|
||||
/* Get the saved exec dir.
|
||||
* Caller needs to release the returned string by g_free() */
|
||||
* Caller needs to release the returned string by free() */
|
||||
char *qemu_get_exec_dir(void);
|
||||
|
||||
/**
|
||||
|
||||
@@ -119,7 +119,7 @@ static inline GList *g_list_insert_sorted_merged(GList *list,
|
||||
return list;
|
||||
}
|
||||
|
||||
static inline gint range_compare(gconstpointer a, gconstpointer b)
|
||||
static inline int32_t range_compare(gconstpointer a, gconstpointer b)
|
||||
{
|
||||
Range *ra = (Range *)a, *rb = (Range *)b;
|
||||
if (ra->begin == rb->begin && ra->end == rb->end) {
|
||||
|
||||
@@ -574,19 +574,6 @@ void timer_put(QEMUFile *f, QEMUTimer *ts);
|
||||
*/
|
||||
int qemu_timeout_ns_to_ms(int64_t ns);
|
||||
|
||||
/**
|
||||
* qemu_poll_ns:
|
||||
* @fds: Array of file descriptors
|
||||
* @nfds: number of file descriptors
|
||||
* @timeout: timeout in nanoseconds
|
||||
*
|
||||
* Perform a poll like g_poll but with a timeout in nanoseconds.
|
||||
* See g_poll documentation for further details.
|
||||
*
|
||||
* Returns: number of fds ready
|
||||
*/
|
||||
int qemu_poll_ns(GPollFD *fds, guint nfds, int64_t timeout);
|
||||
|
||||
/**
|
||||
* qemu_soonest_timeout:
|
||||
* @timeout1: first timeout in nanoseconds (or -1 for infinite)
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#ifndef QEMU_OBJECT_H
|
||||
#define QEMU_OBJECT_H
|
||||
|
||||
#include <glib.h>
|
||||
#include "glib_compat.h"
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "qemu/queue.h"
|
||||
@@ -932,34 +932,6 @@ void object_property_set_int(struct uc_struct *uc, Object *obj, int64_t value,
|
||||
int64_t object_property_get_int(struct uc_struct *uc, Object *obj, const char *name,
|
||||
Error **errp);
|
||||
|
||||
/**
|
||||
* object_property_get_enum:
|
||||
* @obj: the object
|
||||
* @name: the name of the property
|
||||
* @strings: strings corresponding to enums
|
||||
* @errp: returns an error if this function fails
|
||||
*
|
||||
* Returns: the value of the property, converted to an integer, or
|
||||
* undefined if an error occurs (including when the property value is not
|
||||
* an enum).
|
||||
*/
|
||||
int object_property_get_enum(struct uc_struct *uc, Object *obj, const char *name,
|
||||
const char *strings[], Error **errp);
|
||||
|
||||
/**
|
||||
* object_property_get_uint16List:
|
||||
* @obj: the object
|
||||
* @name: the name of the property
|
||||
* @list: the returned int list
|
||||
* @errp: returns an error if this function fails
|
||||
*
|
||||
* Returns: the value of the property, converted to integers, or
|
||||
* undefined if an error occurs (including when the property value is not
|
||||
* an list of integers).
|
||||
*/
|
||||
void object_property_get_uint16List(struct uc_struct *uc, Object *obj, const char *name,
|
||||
uint16List **list, Error **errp);
|
||||
|
||||
/**
|
||||
* object_property_set:
|
||||
* @obj: the object
|
||||
@@ -986,19 +958,6 @@ void object_property_set(struct uc_struct *uc, Object *obj, struct Visitor *v, c
|
||||
void object_property_parse(struct uc_struct *uc, Object *obj, const char *string,
|
||||
const char *name, Error **errp);
|
||||
|
||||
/**
|
||||
* object_property_print:
|
||||
* @obj: the object
|
||||
* @name: the name of the property
|
||||
* @human: if true, print for human consumption
|
||||
* @errp: returns an error if this function fails
|
||||
*
|
||||
* Returns a string representation of the value of the property. The
|
||||
* caller shall free the string.
|
||||
*/
|
||||
char *object_property_print(struct uc_struct *uc, Object *obj, const char *name, bool human,
|
||||
Error **errp);
|
||||
|
||||
/**
|
||||
* object_property_get_type:
|
||||
* @obj: the object
|
||||
@@ -1166,7 +1125,7 @@ void object_property_add_link(Object *obj, const char *name,
|
||||
* @obj: the object to add a property to
|
||||
* @name: the name of the property
|
||||
* @get: the getter or NULL if the property is write-only. This function must
|
||||
* return a string to be freed by g_free().
|
||||
* return a string to be freed by free().
|
||||
* @set: the setter or NULL if the property is read-only
|
||||
* @errp: if an error occurs, a pointer to an area to store the error
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user