[gob] Fri Jul 10 09:57:29 2009 Jiri (George) Lebl <jirka 5z com>
- From: George Lebl <jirka src gnome org>
- To: svn-commits-list gnome org
- Subject: [gob] Fri Jul 10 09:57:29 2009 Jiri (George) Lebl <jirka 5z com>
- Date: Fri, 10 Jul 2009 15:14:49 +0000 (UTC)
commit 0596fa418848a8cf9610a9b0478c93fdb30e1ff3
Author: Jiri (George) Lebl <jirka 5z com>
Date: Fri Jul 10 10:14:31 2009 -0500
Fri Jul 10 09:57:29 2009 Jiri (George) Lebl <jirka 5z com>
* doc/gob2.1.in, src/checks.c, src/checks.h, src/lexer.l, src/main.c,
src/parse.y, src/str.gob, src/str_test.c, src/test.gob,
src/treefuncs.def: Apply patch by Britton Kerin
bkerin at fastmail dot fm, to allow function attributes
like G_GNUC_PRINTF, etc...
* src/main.c: fix a warning
src/Makefile.str | 18 +++++++++++++
src/str.gob | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/str_test.c | 20 ++++++++++++++
3 files changed, 111 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.str b/src/Makefile.str
new file mode 100644
index 0000000..b5bba61
--- /dev/null
+++ b/src/Makefile.str
@@ -0,0 +1,18 @@
+# This is a test makefile for the str_test to check string attributes stuff
+#
+
+FLAGS := -Wall $(shell pkg-config --cflags gobject-2.0 glib-2.0)
+LDFLAGS := $(shell pkg-config --libs-only-other --libs-only-L \
+ gobject-2.0 glib-2.0)
+LDLIBS := $(shell pkg-config --libs-only-l gobject-2.0 glib-2.0)
+
+default: str.o str_test.o Makefile.str
+ gcc $(LDFLAGS) str.o str_test.o $(LDLIBS) -o str_test
+
+%.c %.h: %.gob
+ ./gob2 $<
+
+str.o str_test.o: Makefile.str
+
+clean:
+ rm -rf str.o str_test.o str.c str.h str-private.h str_test
diff --git a/src/str.gob b/src/str.gob
new file mode 100644
index 0000000..3d51e26
--- /dev/null
+++ b/src/str.gob
@@ -0,0 +1,73 @@
+// A simple string class, a lot like GString but with full GObject
+// machinery and really short method names for the lazy :)
+
+%{
+#include <stdio.h>
+%}
+
+class :Str from G:Object {
+
+ private GString *contents;
+
+ public
+ void
+ print (self)
+ {
+ g_print (self->_priv->contents->str);
+ }
+
+ public
+ GObject *
+ new (const char *format (check null), ...) G_GNUC_PRINTF (1, 2)
+ onerror NULL defreturn NULL
+ {
+ va_list ap;
+ va_start (ap, format);
+ gchar *tmp = g_strdup_vprintf (format, ap);
+ va_end (ap);
+
+ Self *self = (Self *) GET_NEW;
+
+ self->_priv->contents = g_string_new (tmp);
+
+ g_free (tmp);
+
+ return G_OBJECT (self);
+ }
+
+ // It seems gob accepts defreturn on non-virtual non-signal types
+ // without complaint, though from the man page I'm not sure the
+ // resulting behavior is well defined.
+ public
+ char *
+ nonvirt_test (self, const char *format (check null), ...)
+ G_GNUC_PRINTF (2,3)
+ defreturn NULL
+ {
+ return NULL;
+ }
+
+ private
+ char *
+ private_test_method (self, const char *format (check null), ...)
+ G_GNUC_PRINTF (2, 3)
+ defreturn NULL
+ {
+ return NULL;
+ }
+
+ public
+ char *
+ private_method_caller (self)
+ {
+ int much_too_general = 42;
+
+ // This should trigger a warning.
+ self_private_test_method (self, "want a string: %s", much_too_general);
+
+ // So should this.
+ str_private_test_method (self, "want a string: %s", much_too_general);
+
+ return NULL;
+ }
+}
diff --git a/src/str_test.c b/src/str_test.c
new file mode 100644
index 0000000..12a1be9
--- /dev/null
+++ b/src/str_test.c
@@ -0,0 +1,20 @@
+#include "str.h"
+
+int
+main (void)
+{
+ g_type_init ();
+
+ int the_answer = 42;
+ char *stupid_pointer = "ug";
+
+ // This works fine.
+ Str *test_good = (Str *) (str_new ("%d", the_answer));
+ test_good = test_good;
+
+ // This gets a warning thanks to our function attribute.
+ Str *test_bad = (Str *) (str_new ("%d", stupid_pointer));
+ test_bad = test_bad;
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]