/* key.c generated by valac 0.56.18, the Vala compiler
 * generated from key.vala, do not modify */

/*///////////////////////////////////////////////////////////////////////*/
/* Copyright 2011-2021 Simon Schneegans*/
/**/
/* Permission is hereby granted, free of charge, to any person obtaining*/
/* a copy of this software and associated documentation files (the*/
/* "Software"), to deal in the Software without restriction, including*/
/* without limitation the rights to use, copy, modify, merge, publish,*/
/* distribute, sublicense, and/or sell copies of the Software, and to*/
/* permit persons to whom the Software is furnished to do so, subject to*/
/* the following conditions:*/
/* */
/* The above copyright notice and this permission notice shall be*/
/* included in all copies or substantial portions of the Software.*/
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,*/
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF*/
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY*/
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,*/
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE*/
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/
/*///////////////////////////////////////////////////////////////////////*/

#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gdk/gdk.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#include <X11/Xregion.h>
#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>
#include <X11/extensions/XTest.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define GNOME_PIE_TYPE_KEY (gnome_pie_key_get_type ())
#define GNOME_PIE_KEY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNOME_PIE_TYPE_KEY, GnomePieKey))
#define GNOME_PIE_KEY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GNOME_PIE_TYPE_KEY, GnomePieKeyClass))
#define GNOME_PIE_IS_KEY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNOME_PIE_TYPE_KEY))
#define GNOME_PIE_IS_KEY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNOME_PIE_TYPE_KEY))
#define GNOME_PIE_KEY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GNOME_PIE_TYPE_KEY, GnomePieKeyClass))

typedef struct _GnomePieKey GnomePieKey;
typedef struct _GnomePieKeyClass GnomePieKeyClass;
typedef struct _GnomePieKeyPrivate GnomePieKeyPrivate;
enum  {
	GNOME_PIE_KEY_0_PROPERTY,
	GNOME_PIE_KEY_LABEL_PROPERTY,
	GNOME_PIE_KEY_ACCELERATOR_PROPERTY,
	GNOME_PIE_KEY_NUM_PROPERTIES
};
static GParamSpec* gnome_pie_key_properties[GNOME_PIE_KEY_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _XCloseDisplay0(var) ((var == NULL) ? NULL : (var = (XCloseDisplay (var), NULL)))

struct _GnomePieKey {
	GObject parent_instance;
	GnomePieKeyPrivate * priv;
};

struct _GnomePieKeyClass {
	GObjectClass parent_class;
};

struct _GnomePieKeyPrivate {
	gchar* _label;
	gchar* _accelerator;
	gint key_code;
	GdkModifierType modifiers;
};

static gint GnomePieKey_private_offset;
static gpointer gnome_pie_key_parent_class = NULL;
static Display* gnome_pie_key_display;
static Display* gnome_pie_key_display = NULL;
static gint gnome_pie_key_shift_l_code;
static gint gnome_pie_key_shift_l_code = 0;
static gint gnome_pie_key_shift_r_code;
static gint gnome_pie_key_shift_r_code = 0;
static gint gnome_pie_key_ctrl_l_code;
static gint gnome_pie_key_ctrl_l_code = 0;
static gint gnome_pie_key_ctrl_r_code;
static gint gnome_pie_key_ctrl_r_code = 0;
static gint gnome_pie_key_alt_l_code;
static gint gnome_pie_key_alt_l_code = 0;
static gint gnome_pie_key_alt_r_code;
static gint gnome_pie_key_alt_r_code = 0;
static gint gnome_pie_key_super_l_code;
static gint gnome_pie_key_super_l_code = 0;
static gint gnome_pie_key_super_r_code;
static gint gnome_pie_key_super_r_code = 0;

VALA_EXTERN GType gnome_pie_key_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GnomePieKey, g_object_unref)
VALA_EXTERN GnomePieKey* gnome_pie_key_new (void);
VALA_EXTERN GnomePieKey* gnome_pie_key_construct (GType object_type);
static void gnome_pie_key_set_accelerator (GnomePieKey* self,
                                    const gchar* value);
static void gnome_pie_key_set_label (GnomePieKey* self,
                              const gchar* value);
VALA_EXTERN GnomePieKey* gnome_pie_key_new_from_string (const gchar* stroke);
VALA_EXTERN GnomePieKey* gnome_pie_key_construct_from_string (GType object_type,
                                                  const gchar* stroke);
VALA_EXTERN GnomePieKey* gnome_pie_key_new_from_values (guint keysym,
                                            GdkModifierType modifiers);
VALA_EXTERN GnomePieKey* gnome_pie_key_construct_from_values (GType object_type,
                                                  guint keysym,
                                                  GdkModifierType modifiers);
VALA_EXTERN void gnome_pie_key_press (GnomePieKey* self);
VALA_EXTERN GdkModifierType gnome_pie_key_get_modifiers (void);
static void gnome_pie_key_release_modifiers (GnomePieKey* self,
                                      GdkModifierType modifiers);
static void gnome_pie_key_press_modifiers (GnomePieKey* self,
                                    GdkModifierType modifiers);
VALA_EXTERN const gchar* gnome_pie_key_get_label (GnomePieKey* self);
VALA_EXTERN const gchar* gnome_pie_key_get_accelerator (GnomePieKey* self);
static void gnome_pie_key_finalize (GObject * obj);
static GType gnome_pie_key_get_type_once (void);
static void _vala_gnome_pie_key_get_property (GObject * object,
                                       guint property_id,
                                       GValue * value,
                                       GParamSpec * pspec);
static void _vala_gnome_pie_key_set_property (GObject * object,
                                       guint property_id,
                                       const GValue * value,
                                       GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
gnome_pie_key_get_instance_private (GnomePieKey* self)
{
	return G_STRUCT_MEMBER_P (self, GnomePieKey_private_offset);
}

GnomePieKey*
gnome_pie_key_construct (GType object_type)
{
	GnomePieKey * self = NULL;
	self = (GnomePieKey*) g_object_new (object_type, NULL);
	gnome_pie_key_set_accelerator (self, "");
	self->priv->modifiers = 0;
	self->priv->key_code = 0;
	gnome_pie_key_set_label (self, _ ("Not bound"));
	return self;
}

GnomePieKey*
gnome_pie_key_new (void)
{
	return gnome_pie_key_construct (GNOME_PIE_TYPE_KEY);
}

GnomePieKey*
gnome_pie_key_construct_from_string (GType object_type,
                                     const gchar* stroke)
{
	GnomePieKey * self = NULL;
	guint keysym = 0U;
	guint _tmp0_ = 0U;
	GdkModifierType _tmp1_ = 0U;
	Display* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	g_return_val_if_fail (stroke != NULL, NULL);
	self = (GnomePieKey*) g_object_new (object_type, NULL);
	gnome_pie_key_set_accelerator (self, stroke);
	gtk_accelerator_parse (stroke, &_tmp0_, &_tmp1_);
	keysym = _tmp0_;
	self->priv->modifiers = _tmp1_;
	_tmp2_ = gnome_pie_key_display;
	self->priv->key_code = (gint) XKeysymToKeycode (_tmp2_, (gulong) keysym);
	_tmp3_ = gtk_accelerator_get_label (keysym, self->priv->modifiers);
	_tmp4_ = _tmp3_;
	gnome_pie_key_set_label (self, _tmp4_);
	_g_free0 (_tmp4_);
	return self;
}

GnomePieKey*
gnome_pie_key_new_from_string (const gchar* stroke)
{
	return gnome_pie_key_construct_from_string (GNOME_PIE_TYPE_KEY, stroke);
}

GnomePieKey*
gnome_pie_key_construct_from_values (GType object_type,
                                     guint keysym,
                                     GdkModifierType modifiers)
{
	GnomePieKey * self = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	Display* _tmp4_;
	self = (GnomePieKey*) g_object_new (object_type, NULL);
	_tmp0_ = gtk_accelerator_name (keysym, modifiers);
	_tmp1_ = _tmp0_;
	gnome_pie_key_set_accelerator (self, _tmp1_);
	_g_free0 (_tmp1_);
	_tmp2_ = gtk_accelerator_get_label (keysym, modifiers);
	_tmp3_ = _tmp2_;
	gnome_pie_key_set_label (self, _tmp3_);
	_g_free0 (_tmp3_);
	_tmp4_ = gnome_pie_key_display;
	self->priv->key_code = (gint) XKeysymToKeycode (_tmp4_, (gulong) keysym);
	self->priv->modifiers = modifiers;
	return self;
}

GnomePieKey*
gnome_pie_key_new_from_values (guint keysym,
                               GdkModifierType modifiers)
{
	return gnome_pie_key_construct_from_values (GNOME_PIE_TYPE_KEY, keysym, modifiers);
}

void
gnome_pie_key_press (GnomePieKey* self)
{
	GdkModifierType current_modifiers = 0U;
	Display* _tmp0_;
	Display* _tmp1_;
	Display* _tmp2_;
	Display* _tmp3_;
	g_return_if_fail (self != NULL);
	current_modifiers = gnome_pie_key_get_modifiers ();
	gnome_pie_key_release_modifiers (self, current_modifiers);
	gnome_pie_key_press_modifiers (self, self->priv->modifiers);
	_tmp0_ = gnome_pie_key_display;
	XFlush (_tmp0_);
	_tmp1_ = gnome_pie_key_display;
	XTestFakeKeyEvent (_tmp1_, (guint) self->priv->key_code, TRUE, (gulong) 0);
	_tmp2_ = gnome_pie_key_display;
	XTestFakeKeyEvent (_tmp2_, (guint) self->priv->key_code, FALSE, (gulong) 0);
	gnome_pie_key_release_modifiers (self, self->priv->modifiers);
	_tmp3_ = gnome_pie_key_display;
	XFlush (_tmp3_);
}

GdkModifierType
gnome_pie_key_get_modifiers (void)
{
	GdkDisplay* _tmp0_;
	GdkKeymap* _tmp1_;
	GdkModifierType result;
	_tmp0_ = gdk_display_get_default ();
	_tmp1_ = gdk_keymap_get_for_display (_tmp0_);
	result = (GdkModifierType) gdk_keymap_get_modifier_state (_tmp1_);
	return result;
}

static void
gnome_pie_key_release_modifiers (GnomePieKey* self,
                                 GdkModifierType modifiers)
{
	g_return_if_fail (self != NULL);
	if ((modifiers & GDK_CONTROL_MASK) > 0) {
		Display* _tmp0_;
		Display* _tmp1_;
		_tmp0_ = gnome_pie_key_display;
		XTestFakeKeyEvent (_tmp0_, (guint) gnome_pie_key_ctrl_l_code, FALSE, (gulong) 0);
		_tmp1_ = gnome_pie_key_display;
		XTestFakeKeyEvent (_tmp1_, (guint) gnome_pie_key_ctrl_r_code, FALSE, (gulong) 0);
	}
	if ((modifiers & GDK_SHIFT_MASK) > 0) {
		Display* _tmp2_;
		Display* _tmp3_;
		_tmp2_ = gnome_pie_key_display;
		XTestFakeKeyEvent (_tmp2_, (guint) gnome_pie_key_shift_l_code, FALSE, (gulong) 0);
		_tmp3_ = gnome_pie_key_display;
		XTestFakeKeyEvent (_tmp3_, (guint) gnome_pie_key_shift_r_code, FALSE, (gulong) 0);
	}
	if ((modifiers & GDK_MOD1_MASK) > 0) {
		Display* _tmp4_;
		Display* _tmp5_;
		_tmp4_ = gnome_pie_key_display;
		XTestFakeKeyEvent (_tmp4_, (guint) gnome_pie_key_alt_l_code, FALSE, (gulong) 0);
		_tmp5_ = gnome_pie_key_display;
		XTestFakeKeyEvent (_tmp5_, (guint) gnome_pie_key_alt_r_code, FALSE, (gulong) 0);
	}
	if ((modifiers & GDK_SUPER_MASK) > 0) {
		Display* _tmp6_;
		Display* _tmp7_;
		_tmp6_ = gnome_pie_key_display;
		XTestFakeKeyEvent (_tmp6_, (guint) gnome_pie_key_super_l_code, FALSE, (gulong) 0);
		_tmp7_ = gnome_pie_key_display;
		XTestFakeKeyEvent (_tmp7_, (guint) gnome_pie_key_super_r_code, FALSE, (gulong) 0);
	}
}

static void
gnome_pie_key_press_modifiers (GnomePieKey* self,
                               GdkModifierType modifiers)
{
	g_return_if_fail (self != NULL);
	if ((modifiers & GDK_CONTROL_MASK) > 0) {
		Display* _tmp0_;
		_tmp0_ = gnome_pie_key_display;
		XTestFakeKeyEvent (_tmp0_, (guint) gnome_pie_key_ctrl_l_code, TRUE, (gulong) 0);
	}
	if ((modifiers & GDK_SHIFT_MASK) > 0) {
		Display* _tmp1_;
		_tmp1_ = gnome_pie_key_display;
		XTestFakeKeyEvent (_tmp1_, (guint) gnome_pie_key_shift_l_code, TRUE, (gulong) 0);
	}
	if ((modifiers & GDK_MOD1_MASK) > 0) {
		Display* _tmp2_;
		_tmp2_ = gnome_pie_key_display;
		XTestFakeKeyEvent (_tmp2_, (guint) gnome_pie_key_alt_l_code, TRUE, (gulong) 0);
	}
	if ((modifiers & GDK_SUPER_MASK) > 0) {
		Display* _tmp3_;
		_tmp3_ = gnome_pie_key_display;
		XTestFakeKeyEvent (_tmp3_, (guint) gnome_pie_key_super_l_code, TRUE, (gulong) 0);
	}
}

const gchar*
gnome_pie_key_get_label (GnomePieKey* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_label;
	result = _tmp0_;
	return result;
}

static void
gnome_pie_key_set_label (GnomePieKey* self,
                         const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = gnome_pie_key_get_label (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_label);
		self->priv->_label = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, gnome_pie_key_properties[GNOME_PIE_KEY_LABEL_PROPERTY]);
	}
}

const gchar*
gnome_pie_key_get_accelerator (GnomePieKey* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_accelerator;
	result = _tmp0_;
	return result;
}

static void
gnome_pie_key_set_accelerator (GnomePieKey* self,
                               const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = gnome_pie_key_get_accelerator (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_accelerator);
		self->priv->_accelerator = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, gnome_pie_key_properties[GNOME_PIE_KEY_ACCELERATOR_PROPERTY]);
	}
}

static void
gnome_pie_key_class_init (GnomePieKeyClass * klass,
                          gpointer klass_data)
{
	Display* _tmp0_;
	Display* _tmp1_;
	Display* _tmp2_;
	Display* _tmp3_;
	Display* _tmp4_;
	Display* _tmp5_;
	Display* _tmp6_;
	Display* _tmp7_;
	Display* _tmp8_;
	gnome_pie_key_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GnomePieKey_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_gnome_pie_key_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_gnome_pie_key_set_property;
	G_OBJECT_CLASS (klass)->finalize = gnome_pie_key_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GNOME_PIE_KEY_LABEL_PROPERTY, gnome_pie_key_properties[GNOME_PIE_KEY_LABEL_PROPERTY] = g_param_spec_string ("label", "label", "label", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GNOME_PIE_KEY_ACCELERATOR_PROPERTY, gnome_pie_key_properties[GNOME_PIE_KEY_ACCELERATOR_PROPERTY] = g_param_spec_string ("accelerator", "accelerator", "accelerator", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	_tmp0_ = XOpenDisplay (NULL);
	_XCloseDisplay0 (gnome_pie_key_display);
	gnome_pie_key_display = _tmp0_;
	_tmp1_ = gnome_pie_key_display;
	gnome_pie_key_shift_l_code = (gint) XKeysymToKeycode (_tmp1_, (gulong) gdk_keyval_from_name ("Shift_L"));
	_tmp2_ = gnome_pie_key_display;
	gnome_pie_key_shift_r_code = (gint) XKeysymToKeycode (_tmp2_, (gulong) gdk_keyval_from_name ("Shift_R"));
	_tmp3_ = gnome_pie_key_display;
	gnome_pie_key_ctrl_l_code = (gint) XKeysymToKeycode (_tmp3_, (gulong) gdk_keyval_from_name ("Control_L"));
	_tmp4_ = gnome_pie_key_display;
	gnome_pie_key_ctrl_r_code = (gint) XKeysymToKeycode (_tmp4_, (gulong) gdk_keyval_from_name ("Control_R"));
	_tmp5_ = gnome_pie_key_display;
	gnome_pie_key_alt_l_code = (gint) XKeysymToKeycode (_tmp5_, (gulong) gdk_keyval_from_name ("Alt_L"));
	_tmp6_ = gnome_pie_key_display;
	gnome_pie_key_alt_r_code = (gint) XKeysymToKeycode (_tmp6_, (gulong) gdk_keyval_from_name ("Alt_R"));
	_tmp7_ = gnome_pie_key_display;
	gnome_pie_key_super_l_code = (gint) XKeysymToKeycode (_tmp7_, (gulong) gdk_keyval_from_name ("Super_L"));
	_tmp8_ = gnome_pie_key_display;
	gnome_pie_key_super_r_code = (gint) XKeysymToKeycode (_tmp8_, (gulong) gdk_keyval_from_name ("Super_R"));
}

static void
gnome_pie_key_instance_init (GnomePieKey * self,
                             gpointer klass)
{
	self->priv = gnome_pie_key_get_instance_private (self);
}

static void
gnome_pie_key_finalize (GObject * obj)
{
	GnomePieKey * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GNOME_PIE_TYPE_KEY, GnomePieKey);
	_g_free0 (self->priv->_label);
	_g_free0 (self->priv->_accelerator);
	G_OBJECT_CLASS (gnome_pie_key_parent_class)->finalize (obj);
}

static GType
gnome_pie_key_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GnomePieKeyClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gnome_pie_key_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GnomePieKey), 0, (GInstanceInitFunc) gnome_pie_key_instance_init, NULL };
	GType gnome_pie_key_type_id;
	gnome_pie_key_type_id = g_type_register_static (G_TYPE_OBJECT, "GnomePieKey", &g_define_type_info, 0);
	GnomePieKey_private_offset = g_type_add_instance_private (gnome_pie_key_type_id, sizeof (GnomePieKeyPrivate));
	return gnome_pie_key_type_id;
}

GType
gnome_pie_key_get_type (void)
{
	static volatile gsize gnome_pie_key_type_id__once = 0;
	if (g_once_init_enter (&gnome_pie_key_type_id__once)) {
		GType gnome_pie_key_type_id;
		gnome_pie_key_type_id = gnome_pie_key_get_type_once ();
		g_once_init_leave (&gnome_pie_key_type_id__once, gnome_pie_key_type_id);
	}
	return gnome_pie_key_type_id__once;
}

static void
_vala_gnome_pie_key_get_property (GObject * object,
                                  guint property_id,
                                  GValue * value,
                                  GParamSpec * pspec)
{
	GnomePieKey * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GNOME_PIE_TYPE_KEY, GnomePieKey);
	switch (property_id) {
		case GNOME_PIE_KEY_LABEL_PROPERTY:
		g_value_set_string (value, gnome_pie_key_get_label (self));
		break;
		case GNOME_PIE_KEY_ACCELERATOR_PROPERTY:
		g_value_set_string (value, gnome_pie_key_get_accelerator (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_gnome_pie_key_set_property (GObject * object,
                                  guint property_id,
                                  const GValue * value,
                                  GParamSpec * pspec)
{
	GnomePieKey * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GNOME_PIE_TYPE_KEY, GnomePieKey);
	switch (property_id) {
		case GNOME_PIE_KEY_LABEL_PROPERTY:
		gnome_pie_key_set_label (self, g_value_get_string (value));
		break;
		case GNOME_PIE_KEY_ACCELERATOR_PROPERTY:
		gnome_pie_key_set_accelerator (self, g_value_get_string (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

