evince r3378 - in trunk: . libdocument



Author: carlosgc
Date: Sat Jan 24 18:10:21 2009
New Revision: 3378
URL: http://svn.gnome.org/viewvc/evince?rev=3378&view=rev

Log:
2009-01-24  Carlos Garcia Campos  <carlosgc gnome org>

	* libdocument/ev-document.[ch]:

	Add EV_DEFINE_BOXED_TYPE macro to define boxed types. See bug
	#568228.

Modified:
   trunk/ChangeLog
   trunk/libdocument/ev-document.c
   trunk/libdocument/ev-document.h

Modified: trunk/libdocument/ev-document.c
==============================================================================
--- trunk/libdocument/ev-document.c	(original)
+++ trunk/libdocument/ev-document.c	Sat Jan 24 18:10:21 2009
@@ -244,16 +244,7 @@
 }
 
 /* EvDocumentInfo */
-GType
-ev_document_info_get_type (void)
-{
-	static GType type = 0;
-	if (type == 0)
-		type = g_boxed_type_register_static ("EvDocumentInfo",
-						     (GBoxedCopyFunc)ev_document_info_copy,
-						     (GBoxedFreeFunc)ev_document_info_free);
-	return type;
-}
+EV_DEFINE_BOXED_TYPE (EvDocumentInfo, ev_document_info, ev_document_info_copy, ev_document_info_free)
 
 EvDocumentInfo *
 ev_document_info_copy (EvDocumentInfo *info)

Modified: trunk/libdocument/ev-document.h
==============================================================================
--- trunk/libdocument/ev-document.h	(original)
+++ trunk/libdocument/ev-document.h	Sat Jan 24 18:10:21 2009
@@ -216,6 +216,26 @@
 #define EV_BACKEND_REGISTER(BackendName, backend_name)			\
 	EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, ;)
 
+/*
+ * A convenience macro for boxed type implementations, which defines a
+ * type_name_get_type() function registering the boxed type.
+ */
+#define EV_DEFINE_BOXED_TYPE(TypeName, type_name, copy_func, free_func)               \
+GType                                                                                 \
+type_name##_get_type (void)                                                           \
+{                                                                                     \
+        static volatile gsize g_define_type_id__volatile = 0;                         \
+	if (g_once_init_enter (&g_define_type_id__volatile)) {                        \
+	        GType g_define_type_id =                                              \
+		    g_boxed_type_register_static (g_intern_static_string (#TypeName), \
+		                                  (GBoxedCopyFunc) copy_func,         \
+						  (GBoxedFreeFunc) free_func);        \
+		g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);    \
+	}                                                                             \
+	return g_define_type_id__volatile;                                            \
+}
+ 
+
 G_END_DECLS
 
 #endif /* EV_DOCUMENT_H */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]