Created
January 18, 2017 00:29
-
-
Save ptomato/6fe7bb89aacd8863dc6d155e63225b44 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* gcc -o undrflow undrflow.c `pkg-config --cflags --libs gobject-2.0` */ | |
#include <glib-object.h> | |
#define PROP_FOO 1 | |
#define TEST_TYPE_FOO test_foo_get_type () | |
G_DECLARE_FINAL_TYPE (TestFoo, test_foo, TEST, FOO, GObject); | |
struct _TestFoo | |
{ | |
GObject parent; | |
unsigned foo; | |
}; | |
G_DEFINE_TYPE(TestFoo, test_foo, G_TYPE_OBJECT); | |
static void | |
test_foo_get_property (GObject *object, unsigned id, GValue *value, | |
GParamSpec *pspec) | |
{ | |
if (id == PROP_FOO) | |
g_value_set_uint (value, TEST_FOO (object)->foo); | |
else | |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, id, pspec); | |
} | |
static void | |
test_foo_set_property (GObject *object, unsigned id, const GValue *value, | |
GParamSpec *pspec) | |
{ | |
if (id == PROP_FOO) | |
TEST_FOO (object)->foo = g_value_get_uint (value); | |
else | |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, id, pspec); | |
} | |
static void | |
test_foo_class_init (TestFooClass *klass) | |
{ | |
GObjectClass *object_class = G_OBJECT_CLASS (klass); | |
object_class->get_property = test_foo_get_property; | |
object_class->set_property = test_foo_set_property; | |
g_object_class_install_property (object_class, PROP_FOO, | |
g_param_spec_uint ("foo", "Foo", "Foo", 0, G_MAXUINT32, 0, | |
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS)); | |
} | |
static void test_foo_init (TestFoo *self) {} | |
int | |
main (int argc, char **argv) | |
{ | |
unsigned fooval; | |
TestFoo* foo = g_object_new(TEST_TYPE_FOO, "foo", -1, NULL); | |
g_object_get(foo, "foo", &fooval, NULL); | |
g_printerr("%u ", fooval); | |
g_object_set(foo, "foo", -2, NULL); | |
g_object_get(foo, "foo", &fooval, NULL); | |
g_printerr("%u\n", fooval); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment