diff --git a/ChangeLog b/ChangeLog index fbec0a36e..4dc9d3181 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Wed Mar 7 09:32:06 2001 Tim Janik + + * glib-object.h: add gvaluearray.h. + + * gstring.[hc]: fixup naming of g_string_sprint*. + + * gtypes.h: fixed GCompareDataFunc naming. + 2001-03-07 Christian Meyer * configure.in: Added de (German) to ALL_LINGUAS. diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index fbec0a36e..4dc9d3181 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,11 @@ +Wed Mar 7 09:32:06 2001 Tim Janik + + * glib-object.h: add gvaluearray.h. + + * gstring.[hc]: fixup naming of g_string_sprint*. + + * gtypes.h: fixed GCompareDataFunc naming. + 2001-03-07 Christian Meyer * configure.in: Added de (German) to ALL_LINGUAS. diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index fbec0a36e..4dc9d3181 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,11 @@ +Wed Mar 7 09:32:06 2001 Tim Janik + + * glib-object.h: add gvaluearray.h. + + * gstring.[hc]: fixup naming of g_string_sprint*. + + * gtypes.h: fixed GCompareDataFunc naming. + 2001-03-07 Christian Meyer * configure.in: Added de (German) to ALL_LINGUAS. diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index fbec0a36e..4dc9d3181 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,11 @@ +Wed Mar 7 09:32:06 2001 Tim Janik + + * glib-object.h: add gvaluearray.h. + + * gstring.[hc]: fixup naming of g_string_sprint*. + + * gtypes.h: fixed GCompareDataFunc naming. + 2001-03-07 Christian Meyer * configure.in: Added de (German) to ALL_LINGUAS. diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index fbec0a36e..4dc9d3181 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,11 @@ +Wed Mar 7 09:32:06 2001 Tim Janik + + * glib-object.h: add gvaluearray.h. + + * gstring.[hc]: fixup naming of g_string_sprint*. + + * gtypes.h: fixed GCompareDataFunc naming. + 2001-03-07 Christian Meyer * configure.in: Added de (German) to ALL_LINGUAS. diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index fbec0a36e..4dc9d3181 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,11 @@ +Wed Mar 7 09:32:06 2001 Tim Janik + + * glib-object.h: add gvaluearray.h. + + * gstring.[hc]: fixup naming of g_string_sprint*. + + * gtypes.h: fixed GCompareDataFunc naming. + 2001-03-07 Christian Meyer * configure.in: Added de (German) to ALL_LINGUAS. diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index fbec0a36e..4dc9d3181 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,11 @@ +Wed Mar 7 09:32:06 2001 Tim Janik + + * glib-object.h: add gvaluearray.h. + + * gstring.[hc]: fixup naming of g_string_sprint*. + + * gtypes.h: fixed GCompareDataFunc naming. + 2001-03-07 Christian Meyer * configure.in: Added de (German) to ALL_LINGUAS. diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index fbec0a36e..4dc9d3181 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,11 @@ +Wed Mar 7 09:32:06 2001 Tim Janik + + * glib-object.h: add gvaluearray.h. + + * gstring.[hc]: fixup naming of g_string_sprint*. + + * gtypes.h: fixed GCompareDataFunc naming. + 2001-03-07 Christian Meyer * configure.in: Added de (German) to ALL_LINGUAS. diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index 98dad9239..5fcacd12b 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,3 +1,13 @@ +Wed Mar 7 09:33:27 2001 Tim Janik + + * gobject/Makefile.am: shuffled rules to avoid excessive + rebuilds. + + * gobject/gobject-sections.txt: updates. + + * gobject/tmpl/*: bunch of updates, added another patch + from Eric Lemings . + 2001-03-07 Sebastian Wilhelmi * glib/glib-sections.txt, glib/tmpl/messages.sgml: Removed diff --git a/docs/reference/glib/tmpl/glib-unused.sgml b/docs/reference/glib/tmpl/glib-unused.sgml index 1a46e2fa2..63b8f6d70 100644 --- a/docs/reference/glib/tmpl/glib-unused.sgml +++ b/docs/reference/glib/tmpl/glib-unused.sgml @@ -1,3 +1,13 @@ + + + + + +@a: +@b: +@user_data: +@Returns: + diff --git a/docs/reference/glib/tmpl/misc_utils.sgml b/docs/reference/glib/tmpl/misc_utils.sgml index 522d9bbf5..e95f0b0e9 100644 --- a/docs/reference/glib/tmpl/misc_utils.sgml +++ b/docs/reference/glib/tmpl/misc_utils.sgml @@ -278,17 +278,6 @@ and has no return value. It is not currently used in GLib or GTK+. @data: - - - - - -@a: -@b: -@user_data: -@Returns: - - diff --git a/docs/reference/glib/tmpl/strings.sgml b/docs/reference/glib/tmpl/strings.sgml index 23bfc3bc6..c096bb717 100644 --- a/docs/reference/glib/tmpl/strings.sgml +++ b/docs/reference/glib/tmpl/strings.sgml @@ -78,7 +78,7 @@ you do not have to worry about having enough space to copy the string. @Returns: the destination #GString. - + Writes a formatted string into a #GString. This is similar to the standard sprintf() function, @@ -86,19 +86,21 @@ except that the GString buffer automatically expands to contain the results. The previous contents of the GString are destroyed. + @string: a #GString. @format: the string format. See the sprintf() documentation. @Varargs: the parameters to insert into the format string. - + Appends a formatted string onto the end of a #GString. This function is is similar to g_string_sprintf() except that the text is appended to the GString. + @string: a #GString. @format: the string format. See the sprintf() documentation. diff --git a/docs/reference/gobject/Makefile.am b/docs/reference/gobject/Makefile.am index 82772f7a0..e515bf7fc 100644 --- a/docs/reference/gobject/Makefile.am +++ b/docs/reference/gobject/Makefile.am @@ -2,47 +2,36 @@ # The name of the module. DOC_MODULE=gobject - # The top-level SGML file. DOC_MAIN_SGML_FILE=gobject-docs.sgml - +# Extra SGML files that are included by $(DOC_MAIN_SGML_FILE) +EXTRA_DIST += # The directory containing the source code. Relative to $(srcdir) DOC_SOURCE_DIR=../../../gobject - # Extra options to supply to gtkdoc-scan SCAN_OPTIONS= - # Extra options to supply to gtkdoc-mkdb MKDB_OPTIONS= - # Extra options to supply to gtkdoc-fixref FIXXREF_OPTIONS=--extra-dir=$(srcdir)/../glib/html +# Images to copy into HTML directory +HTML_IMAGES = # Used for dependencies HFILE_GLOB=$(top_srcdir)/gobject/*.h CFILE_GLOB=$(top_srcdir)/gobject/*.c - # Headers to ignore IGNORE_HFILES= \ + .saved \ + glib-genmarshal.c \ gbsearcharray.h - # Extra files to add when scanning EXTRA_HFILES= -# Images to copy into HTML directory -HTML_IMAGES = - -# Extra SGML files that are included by $(DOC_MAIN_SGML_FILE) -content_files = - -# Other files to distribute -extra_files = - # CFLAGS and LDFLAGS for compiling scan program. Only needed # if $(DOC_MODULE).types is non-empty. GTKDOC_CFLAGS = GTKDOC_LIBS = - # Commands for compiling and linking GTKDOC_CC=$(LIBTOOL) --mode=compile $(CC) GTKDOC_LD=$(LIBTOOL) --mode=link $(CC) @@ -54,29 +43,29 @@ GTKDOC_LD=$(LIBTOOL) --mode=link $(CC) TARGET_DIR=$(HTML_DIR)/$(DOC_MODULE) -EXTRA_DIST = \ - $(content_files) \ - $(extra_files) \ - $(HTML_IMAGES) \ - $(DOC_MAIN_SGML_FILE) \ - $(DOC_MODULE).types \ - $(DOC_MODULE)-sections.txt \ - $(DOC_MODULE)-overrides.txt +DOC_STAMPS = $(srcdir)/tmpl.stamp $(srcdir)/sgml.stamp $(srcdir)/html.stamp \ + build-scan.stamp build-tmpl.stamp build-sgml.stamp build-html.stamp +# gtkdoc-mktmpl: creates, and on changes touches: tmpl.stamp +# gtkdoc-mkdb: creates, and on changes touches: sgml.stamp +# gtkdoc-mkhtml: creates, and on changes touches: html.stamp -DOC_STAMPS=scan-build.stamp tmpl-build.stamp sgml-build.stamp html-build.stamp + +.PHONY: gtkdoc-build-all if ENABLE_GTK_DOC -all-local: html-build.stamp - SCANOBJ_FILES = \ $(DOC_MODULE).args \ $(DOC_MODULE).hierarchy \ $(DOC_MODULE).signal -scan-build.stamp: $(HFILE_GLOB) +all-local: gtkdoc-build-all + +gtkdoc-build-all: build-sgml.stamp build-html.stamp + @true +build-scan.stamp: $(HFILE_GLOB) @echo '*** Scanning header files ***' cd $(srcdir) && ( \ - if grep -l '^.+$$' $(DOC_MODULE).types > /dev/null ; then \ + if grep -l '^.+$$' $(DOC_MODULE).types > /dev/null 2>/dev/null ; then \ CC="$(GTKDOC_CC)" LD="$(GTKDOC_LD)" CFLAGS="$(GTKDOC_CFLAGS)" LDFLAGS="$(GTKDOC_LIBS)" gtkdoc-scangobj --module=$(DOC_MODULE) ; \ else \ for i in $(SCANOBJ_FILES) ; do \ @@ -85,46 +74,32 @@ scan-build.stamp: $(HFILE_GLOB) fi ) cd $(srcdir) && \ gtkdoc-scan --module=$(DOC_MODULE) --source-dir=$(DOC_SOURCE_DIR) --ignore-headers="$(IGNORE_HFILES)" $(SCAN_OPTIONS) $(EXTRA_HFILES) - touch scan-build.stamp - -check_scan: - $(MAKE) scan-build.stamp - -$(DOC_MODULE)-decl.txt $(SCANOBJ_FILES): check_scan - -tmpl-build.stamp: $(DOC_MODULE)-decl.txt $(SCANOBJ_FILES) $(DOC_MODULE)-sections.txt $(DOC_MODULE)-overrides.txt + touch build-scan.stamp +build-tmpl.stamp: build-scan.stamp $(DOC_MODULE)-decl.txt $(SCANOBJ_FILES) $(DOC_MODULE)-sections.txt $(DOC_MODULE)-overrides.txt $(srcdir)/tmpl/*.sgml @echo '*** Rebuilding template files ***' cd $(srcdir) && gtkdoc-mktmpl --module=$(DOC_MODULE) - touch tmpl-build.stamp - -check_templates: - $(MAKE) tmpl-build.stamp - -tmpl.stamp: check_templates - -sgml-build.stamp: tmpl.stamp $(CFILE_GLOB) + touch build-tmpl.stamp +tmpl.stamp: build-tmpl.stamp + @true +build-sgml.stamp: tmpl.stamp $(CFILE_GLOB) @echo '*** Building SGML ***' cd $(srcdir) && \ gtkdoc-mkdb --module=$(DOC_MODULE) --source-dir=$(DOC_SOURCE_DIR) $(MKDB_OPTIONS) - touch sgml-build.stamp - -check_sgml: - $(MAKE) sgml-build.stamp - -sgml.stamp: check_sgml - -html-build.stamp: sgml.stamp $(DOC_MAIN_SGML_FILE) + touch build-sgml.stamp +sgml.stamp: build-sgml.stamp + @true +build-html.stamp: sgml.stamp $(DOC_MAIN_SGML_FILE) @echo '*** Building HTML ***' test -d $(srcdir)/html || mkdir $(srcdir)/html cd $(srcdir)/html && gtkdoc-mkhtml $(DOC_MODULE) ../$(DOC_MAIN_SGML_FILE) test "x$(HTML_IMAGES)" = "x" || ( cd $(srcdir) && cp $(HTML_IMAGES) html ) @echo '-- Fixing Crossreferences' cd $(srcdir) && gtkdoc-fixxref --module-dir=html --html-dir=$(HTML_DIR) $(FIXXREF_OPTIONS) - touch html-build.stamp + touch build-html.stamp endif clean-local: - rm -f *~ *.bak $(SCANOBJ_FILES) *-unused.txt $(DOC_STAMPS) $(srcdir)/sgml.stamp + rm -f *~ *.bak $(SCANOBJ_FILES) *-unused.txt $(DOC_STAMPS) maintainer-clean-local: clean cd $(srcdir) && rm -rf sgml html $(DOC_MODULE)-decl-list.txt $(DOC_MODULE)-decl.txt @@ -167,4 +142,12 @@ dist-hook: dist-check-gtkdoc dist-hook-local cp $(srcdir)/$$i $(distdir)/html ; \ done -.PHONY : check_sgml check_templates check_scan dist-hook-local +.PHONY: dist-hook-local + + +EXTRA_DIST = \ + $(HTML_IMAGES) \ + $(DOC_MAIN_SGML_FILE) \ + $(DOC_MODULE).types \ + $(DOC_MODULE)-sections.txt \ + $(DOC_MODULE)-overrides.txt diff --git a/docs/reference/gobject/gobject-sections.txt b/docs/reference/gobject/gobject-sections.txt index 5c3106882..550c4c240 100644 --- a/docs/reference/gobject/gobject-sections.txt +++ b/docs/reference/gobject/gobject-sections.txt @@ -24,7 +24,6 @@ GTypeInstance GTypeInfo GTypeFundamentalInfo GInterfaceInfo -GTypeValueTable GType G_TYPE_FROM_INSTANCE @@ -141,45 +140,47 @@ GObjectClass GObjectConstructParam GObjectGetPropertyFunc GObjectSetPropertyFunc +GObjectFinalizeFunc +G_TYPE_IS_OBJECT G_OBJECT +G_IS_OBJECT +G_OBJECT_CLASS +G_IS_OBJECT_CLASS G_OBJECT_GET_CLASS G_OBJECT_TYPE G_OBJECT_TYPE_NAME G_OBJECT_CLASS_TYPE G_OBJECT_CLASS_NAME -G_IS_VALUE_OBJECT -G_TYPE_IS_OBJECT -G_IS_OBJECT -G_OBJECT_CLASS -G_IS_OBJECT_CLASS -GObjectFinalizeFunc +G_VALUE_HOLDS_OBJECT g_object_class_install_property g_object_class_find_property g_object_new -g_object_new_valist -g_object_set -g_object_get -g_object_set_valist -g_object_get_valist -g_object_set_property -g_object_get_property -g_object_freeze_notify -g_object_notify -g_object_thaw_notify g_object_ref g_object_unref -g_object_get_qdata -g_object_set_qdata -g_object_set_qdata_full -g_object_steal_qdata +g_object_connect +g_object_disconnect +g_object_set +g_object_get +g_object_notify +g_object_freeze_notify +g_object_thaw_notify g_object_get_data g_object_set_data g_object_set_data_full g_object_steal_data +g_object_get_qdata +g_object_set_qdata +g_object_set_qdata_full +g_object_steal_qdata +g_object_set_property +g_object_get_property +g_object_new_valist +g_object_set_valist +g_object_get_valist +g_object_watch_closure g_value_set_object g_value_get_object g_value_dup_object -g_object_watch_closure G_OBJECT_WARN_INVALID_PROPERTY_ID @@ -198,8 +199,8 @@ G_FLAGS_CLASS G_IS_FLAGS_CLASS G_FLAGS_CLASS_TYPE G_FLAGS_CLASS_TYPE_NAME -G_IS_VALUE_ENUM -G_IS_VALUE_FLAGS +G_VALUE_HOLDS_ENUM +G_VALUE_HOLDS_FLAGS GEnumValue GFlagsValue g_enum_get_value @@ -228,11 +229,12 @@ g_boxed_copy g_boxed_free g_value_set_boxed g_value_set_static_boxed +g_value_set_boxed_take_ownership g_value_get_boxed g_value_dup_boxed g_boxed_type_register_static -G_IS_VALUE_BOXED +G_VALUE_HOLDS_BOXED G_TYPE_IS_BOXED @@ -248,31 +250,48 @@ GValueExchange GValue g_value_init g_value_copy -g_value_convert g_value_reset g_value_unset g_value_fits_pointer +g_value_peek_pointer +g_value_convert g_values_exchange g_value_types_exchangable g_value_register_exchange_func +GTypeValueTable + + +
+Value arrays +value_types +GValueArray +g_value_array_new +g_value_array_copy +g_value_array_free +g_value_array_index +g_value_array_append +g_value_array_prepend +g_value_array_insert +g_value_array_remove +g_value_array_sort +g_value_array_sort_with_data
Standard value types value_types -G_IS_VALUE_CHAR -G_IS_VALUE_UCHAR -G_IS_VALUE_BOOLEAN -G_IS_VALUE_INT -G_IS_VALUE_UINT -G_IS_VALUE_LONG -G_IS_VALUE_ULONG -G_IS_VALUE_FLOAT -G_IS_VALUE_DOUBLE -G_IS_VALUE_STRING -G_IS_VALUE_POINTER -G_IS_VALUE_CCALLBACK -G_IS_VALUE_PARAM +G_VALUE_HOLDS_CHAR +G_VALUE_HOLDS_UCHAR +G_VALUE_HOLDS_BOOLEAN +G_VALUE_HOLDS_INT +G_VALUE_HOLDS_UINT +G_VALUE_HOLDS_LONG +G_VALUE_HOLDS_ULONG +G_VALUE_HOLDS_FLOAT +G_VALUE_HOLDS_DOUBLE +G_VALUE_HOLDS_STRING +G_VALUE_HOLDS_POINTER +G_VALUE_HOLDS_PARAM g_value_set_char g_value_get_char g_value_set_uchar @@ -293,16 +312,14 @@ g_value_set_double g_value_get_double g_value_set_string g_value_set_static_string +g_value_set_string_take_ownership g_value_get_string g_value_dup_string g_value_set_param g_value_get_param g_value_dup_param -g_value_get_ccallback g_value_get_pointer g_value_set_pointer -g_value_get_as_pointer -g_value_set_ccallback g_value_set_instance
@@ -374,8 +391,6 @@ G_IS_PARAM_SPEC_POINTER G_PARAM_SPEC_POINTER G_IS_PARAM_SPEC_BOXED G_PARAM_SPEC_BOXED -G_IS_PARAM_SPEC_CCALLBACK -G_PARAM_SPEC_CCALLBACK G_IS_PARAM_SPEC_PARAM G_PARAM_SPEC_PARAM G_IS_PARAM_SPEC_OBJECT @@ -393,7 +408,6 @@ GParamSpecFloat GParamSpecDouble GParamSpecString GParamSpecBoxed -GParamSpecCCallback GParamSpecParam GParamSpecPointer GParamSpecObject @@ -411,7 +425,6 @@ g_param_spec_double g_param_spec_string g_param_spec_string_c g_param_spec_boxed -g_param_spec_ccallback g_param_spec_param g_param_spec_pointer g_param_spec_object @@ -435,6 +448,9 @@ GSignalEmissionHook GSignalFlags GSignalMatchType GSignalQuery +G_SIGNAL_TYPE_STATIC_SCOPE +G_SIGNAL_MATCH_MASK +G_SIGNAL_FLAGS_MASK g_signal_newc g_signal_newv g_signal_new_valist diff --git a/docs/reference/gobject/tmpl/enumerations_flags.sgml b/docs/reference/gobject/tmpl/enumerations_flags.sgml index 971195e5d..c72b7d3fb 100644 --- a/docs/reference/gobject/tmpl/enumerations_flags.sgml +++ b/docs/reference/gobject/tmpl/enumerations_flags.sgml @@ -106,7 +106,7 @@ Enumeration and Flag Types @class: - + @@ -114,7 +114,7 @@ Enumeration and Flag Types @value: - + diff --git a/docs/reference/gobject/tmpl/gboxed.sgml b/docs/reference/gobject/tmpl/gboxed.sgml index 1ffd58fb1..0e6835741 100644 --- a/docs/reference/gobject/tmpl/gboxed.sgml +++ b/docs/reference/gobject/tmpl/gboxed.sgml @@ -74,6 +74,15 @@ gboxed @boxed: + + +This is an internal function introduced mainly for C marshallers. + + +@value: +@boxed: + + @@ -98,8 +107,10 @@ gboxed @name: +@boxed_init: @boxed_copy: @boxed_free: +@is_refcounted: @Returns: diff --git a/docs/reference/gobject/tmpl/generic_values.sgml b/docs/reference/gobject/tmpl/generic_values.sgml index 099dd3f90..ab588ec97 100644 --- a/docs/reference/gobject/tmpl/generic_values.sgml +++ b/docs/reference/gobject/tmpl/generic_values.sgml @@ -1,58 +1,75 @@ -Generic values +Generic Values - +A polymorphic type that can hold values of any other type. - +The #GValue structure is basically a variable container that consists +of a type identifier and a specific value of that type. +The type identifier within a #GValue structure always determines the +type of the associated value. +To create a undefined #GValue structure, simply create a zero-filled +#GValue structure. To intialize the #GValue, use the g_value_init() +function. A #GValue cannot be used until it is initialized. +The basic type operations (such as freeing and copying) are determined +by the #GTypeValueTable associated with the type ID stored in the #GValue. +Other #GValue operations (such as converting values between types) are +provided by this interface. - +The fundamental types which all support #GValue operations and thus +can be used as a type initializer for g_value_init() are defined by +a separate interface. See the Standard Values API for details. - +Returns #TRUE if @value holds (or contains) a value of @type. +This macro will also check for @value != #NULL and issue a +warning if the check fails. @value: -@g_type: +@type: - +Returns the type identifier of @value. -@value: +@value: A #GValue structure. - +Returns the type name of @value. -@value: +@value: A #GValue structure. - +Return whether the passed in type ID can be used for g_value_init(). +That is, this macro checks whether this type provides an implementation +of the #GTypeValueTable functions required for a type to create a #GValue of. -@type: +@type: A #GType value. +@Returns: Whether @type is suitable as a #GValue type. - +Returns #TRUE if @value is a valid and initialized #GValue structure. -@value: +@value: A #GValue structure. @@ -66,26 +83,72 @@ Generic values - +A mostly opaque structure used to hold a #GValue object. Mostly because +the data within the structure has protected scope: it is accessible only +to functions within a #GTypeValueTable structure, or implementations of +the g_value_*() API. - +Initializes @value with the default value of @type. -@value: -@g_type: +@value: A zero-filled (uninitialized) #GValue structure. +@g_type: Type the #GValue should hold values of. +@Returns: - +Copies the value of @src_value into @dest_value. -@src_value: -@dest_value: +@src_value: An initialized #GValue structure. +@dest_value: An initialized #GValue structure of the same type as @src_value. + + + + +Clears the current value in @value and resets it to the default value +(as if the value had just been initialized). + + +@value: An initialized #GValue structure. +@Returns: + + + + +Clears the current value in @value and "unsets" the type, +this releases all resources associated with this GValue. +An unset value is the same as an uninitialized (zero-filled) +#GValue structure. + + +@value: An initialized #GValue structure. + + + + +Determines if @value will fit inside the size of a pointer value. +This is an internal function introduced mainly for C marshallers. + + +@value: An initialized #GValue structure. +@Returns: #TRUE if @value will fit inside a pointer value. + + + + +Return the value contents as pointer. This function asserts that +g_value_fits_pointer() returned #TRUE for the passed in value. +This is an internal function introduced mainly for C marshallers. + + +@value: An initialized #GValue structure. +@Returns: #TRUE if @value will fit inside a pointer value. @@ -98,58 +161,191 @@ Generic values @Returns: - + - +The #GTypeValueTable provides the functions required by the #GValue implementation, +to serve as a container for values of a type. -@value: +@value_init: Default initialize @values contents by poking values + directly into the value->data array. The data array of + the #GValue passed into this function was zero-filled + with memset, so no care has to be taken to free any + old contents. E.g. for the implementation of a string + value that may never be NULL, the implementation might + look like: + +{ + value->data[0].v_pointer = g_strdup (""); +} + +@value_free: Free any old contents that might be left in the + data array of the passed in @value. No resources may + remain allocated through the #GValue contents after + this function returns. E.g. for our above string type: + +{ + /* only free strings without a specific flag for static storage */ + if (!(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)) + g_free (value->data[0].v_pointer); +} + +@value_copy: @dest_value is a #GValue with zero-filled data section + and @src_value is a properly setup #GValue of same or + derived type. + The purpose of this function is to copy the contents of + @src_value into @dest_value in a way, that even after + @src_value has been freed, the contents of @dest_value + remain valid. String type example: + +{ + dest_value->data[0].v_pointer = g_strdup (src_value->data[0].v_pointer); +} + +@value_peek_pointer: If the value contents fit into a pointer, such as objects + or strings, return this pointer, so the caller can peek at + the current contents. To extend on our above string example: + +{ + return value->data[0].v_pointer; +} + +@collect_format: A string format describing how to collect the contents of + this value, bit-by-bit. Each character in the format represents + an argument to be collected, the characters themselves indicate + the type of the argument. Currently supported arguments are: + + + 'i' - Integers. passed as collect_values[].v_int. + + + 'l' - Longs. passed as collect_values[].v_long. + + + 'd' - Doubles. passed as collect_values[].v_double. + + + 'p' - Pointers. passed as collect_values[].v_pointer. + + + It should be noted, that for variable argument list construction, + ANSI C promotes every type smaller than an integer to an int, and + floats to doubles. So for collection of short int or char, 'i' + needs to be used, and for collection of floats 'd'. +@collect_value: The collect_value() function is responsible for converting the + values collected from a variable argument list into contents + suitable for storage in a GValue. This function should setup + @value similar to value_init(), e.g. for a string value that + does not allow NULL pointers, it needs to either spew an error, + or do an implicit conversion by storing an empty string. + The @value passed in to this function has a zero-filled data + array, so just like for @value_init it is guarranteed to not + contain any old contents that might need freeing. + @n_collect_values is exactly the string length of @collect_format, + and @collect_values is an array of unions #GTypeCValue with + length @n_collect_values, containing the collected values + according to @collect_format. + @collect_flags is an argument provided as a hint by the caller, + which may contain the flag #G_VALUE_NOCOPY_CONTENTS indicating, + that the collected value contents may be considered "static" + for the duration of the #@value lifetime. + Thus an extra copy of the contents stored in @collect_values is + not required for assignment to @value. + For our above string example, we continue with: + +{ + if (!collect_values[0].v_pointer) + value->data[0].v_pointer = g_strdup (""); + else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) + { + value->data[0].v_pointer = collect_values[0].v_pointer; + /* keep a flag for the value_free() implementation to not free this string */ + value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS; + } + else + value->data[0].v_pointer = g_strdup (collect_values[0].v_pointer); + return NULL; +} + + It should be noted, that it is generally a bad idea to follow the + #G_VALUE_NOCOPY_CONTENTS hint for reference counted types. Due to + reentrancy requirements and reference count assertions performed + by the GSignal code, reference counts should always be incremented + for reference counted contents stored in the value->data array. + To deviate from our string example for a moment, and taking a look + at an exemplary implementation for collect_value() of #GObject: + +{ + if (collect_values[0].v_pointer) + { + GObject *object = G_OBJECT (collect_values[0].v_pointer); - - + /* never honour G_VALUE_NOCOPY_CONTENTS for ref-counted types */ + value->data[0].v_pointer = g_object_ref (object); + return NULL; + } + else + return g_strdup_printf ("Object passed as invalid NULL pointer"); +} + + The reference count for valid objects is always incremented, + regardless of @collect_flags. For invalid objects, the example + returns a newly allocated string without altering @value. + Upon success, collect_value() needs to return NULL, if however + a malicious condition occoured, collect_value() may spew an + error by returning a newly allocated non-NULL string, giving + a suitable description of the error condition. + The calling code makes no assumptions about the @value + contents being valid upon error returns, @value + is simply thrown away without further freeing. As such, it is + a good idea to not allocate #GValue contents, prior to returning + an error, however, collect_values() is not obliged to return + a correctly setup @value for error returns, simply because + any non-NULL return is considered a fatal condition so further + program behaviour is undefined. +@lcopy_format: Format description of the arguments to collect for @lcopy_value, + analogous to @collect_format. Usually, @lcopy_format string consist + only of 'p's to provide lcopy_value() with pointers to storage locations. +@lcopy_value: This function is responsible for storing the @value contents into + arguments passed through a variable argument list which got + collected into @collect_values according to @lcopy_format. + @n_collect_values equals the string length of @lcopy_format, + and @collect_flags may contain #G_VALUE_NOCOPY_CONTENTS. + In contrast to collect_value(), lcopy_value() is obliged to + always properly support #G_VALUE_NOCOPY_CONTENTS. + Similar to collect_value() the function may prematurely abort + by returning a newly allocated string describing an error condition. + To complete the string example: + +{ + gchar **string_p = collect_values[0].v_pointer; -
+ if (!string_p) + return g_strdup_printf ("string location passed as NULL"); -@value: + if (collect_flags & G_VALUE_NOCOPY_CONTENTS) + *string_p = value->data[0].v_pointer; + else + *string_p = g_strdup (value->data[0].v_pointer); +} + + And an exemplary version of lcopy_value() for + reference-counted types: + +{ + GObject **object_p = collect_values[0].v_pointer; - - - - - -@value: -@Returns: - - - - - - - -@value1: -@value2: -@Returns: - - - - - - - -@value_type1: -@value_type2: -@Returns: - - - - - - - -@value_type1: -@value_type2: -@func: - + if (!object_p) + return g_strdup_printf ("object location passed as NULL"); + if (!value->data[0].v_pointer) + *object_p = NULL; + else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) /* always honour */ + *object_p = value->data[0].v_pointer; + else + *object_p = g_object_ref (value->data[0].v_pointer); + return NULL; +} + diff --git a/docs/reference/gobject/tmpl/gobject-unused.sgml b/docs/reference/gobject/tmpl/gobject-unused.sgml index 8098c0650..1fe73b575 100644 --- a/docs/reference/gobject/tmpl/gobject-unused.sgml +++ b/docs/reference/gobject/tmpl/gobject-unused.sgml @@ -1,350 +1,36 @@ - + + +Determines if @value is a #GValue whose type conforms to @type. + + +@value: A valid #GValue structure. +@type: A #GType value. +@Returns: #TRUE if @value is a #GValue of @type or #FALSE if not. + + +@value_type1: +@value_type2: +@func: - + - - - - - - -Closures - - - - - - - - - - - - - - - - - - - -gtypemodule.sgml - - - - -The basic concept of the signal system is that of the emission -of a signal. -Signals are introduced per-type and are identified through strings. -Signals introduced for a parent type are availale in derived types as well, -so basically they are a per-type facility that is inherited. -A signal emission mainly involves invocation of a certain set of callbacks in -precisely defined manner. There are two main categories of such callbacks, -per-object - Although signals can deal with any kind of type, i'm - referring to those types as "object types" in the following, simply - because that is the context most users will encounter signals in. - -ones and user provided ones. -The per-object callbacks are most often referred to as "object method -handler" or "default (signal) handler", while user provided callbacks are -usually just called "signal handler". -The object method handler is provided at signal creation time (this most -frequently happens at the end of an object class' creation), while user -provided handlers are frequently connected and disconnected to/from a certain -signal on certain object instances. - - -A signal emission consists of five stages, unless prematurely stopped: - - - 1 - Invocation of the object method handler for %G_SIGNAL_RUN_FIRST signals - - - 2 - Invocation of normal user-provided signal handlers (after flag %FALSE) - - - 3 - Invocation of the object method handler for %G_SIGNAL_RUN_LAST signals - - - 4 - Invocation of user provided signal handlers, connected with an after flag of %TRUE - - - 5 - Invocation of the object method handler for %G_SIGNAL_RUN_CLEANUP signals - - -The user provided signal handlers are called in the order they were -connected in. -All handlers may prematurely stop a signal emission, and any number of -handlers may be connected, disconnected, blocked or unblocked during -a signal emission. -There are certain criteria for skipping user handlers in stages 2 and 4 -of a signal emission. -First, user handlers may be blocked, blocked handlers are omitted -during callback invocation, to return from the "blocked" state, a -handler has to get unblocked exactly the same amount of times -it has been blocked before. -Second, upon emission of a %G_SIGNAL_DETAILED signal, an additional -"detail" argument passed in to g_signal_emit() has to match the detail -argument of the signal handler currently subject to invocation. -Specification of no detail argument for signal handlers (omission of the -detail part of the signal specification upon connection) serves as a -wildcard and matches any detail argument passed in to emission. - - - - - - - - - - -Signals provide a means for customization of object behaviour and are used -as general purpose notification mechanism. - - - -Signals - - - - - - - -@object: -@param_id: -@value: -@pspec: -@trailer: - - - - - - -@object: -@param_id: -@value: -@pspec: -@trailer: - - - - - - -@G_SIGNAL_RUN_FIRST: -@G_SIGNAL_RUN_LAST: -@G_SIGNAL_RUN_CLEANUP: -@G_SIGNAL_NO_RECURSE: -@G_SIGNAL_ACTION: -@G_SIGNAL_NO_HOOKS: - - - - - - -@plugin: -@interface_type: -@instance_type: -@info: - - - - - - -@plugin: -@g_type: -@info: -@value_table: - - - - - - -@plugin: - - - - - - -@plugin: - - - - - - -@plugin_ref: -@plugin_unref: -@complete_type_info: -@complete_interface_info: - - - - - - -@pspec: -@value: - - - - - - - - - - - - -@object: -@param_id: -@pspec: - - - - - - -@oclass: -@param_name: +@value_type1: +@value_type2: @Returns: - + -@oclass: -@param_id: -@pspec: - - - - - - -@object: -@param_name: -@value: - - - - - - -@object: -@param_name: - - - - - - -@object: -@param_name: -@value: - - - - - - -@hash_table: -@pspec: -@owner_type: - - - - - - -@hash_table: -@param_name: -@owner_type: -@try_ancestors: -@trailer: -@Returns: - - - - - - -@Returns: - - - - - - -@hash_table: -@pspec: - - - - - - -@itype: -@struct_offset: -@Returns: - - - - - - -@itype: - - - - - - -@type: -@iface_type: -@Returns: - - - - - - -@instance: -@iface_type: -@Returns: - - - - - - -@type: -@flags: -@Returns: - - - - - - -@value: -@type: +@value1: +@value2: @Returns: diff --git a/docs/reference/gobject/tmpl/objects.sgml b/docs/reference/gobject/tmpl/objects.sgml index 9cb7851c0..2e69507e1 100644 --- a/docs/reference/gobject/tmpl/objects.sgml +++ b/docs/reference/gobject/tmpl/objects.sgml @@ -34,7 +34,6 @@ The Base Object Type @pspec: @value: -@trailer: @@ -45,6 +44,7 @@ The Base Object Type @property_id: @value: @pspec: + @trailer: @@ -57,9 +57,26 @@ The Base Object Type @property_id: @value: @pspec: + @trailer: + + + + + +@object: + + + + + + + +@type: + + @@ -68,6 +85,30 @@ The Base Object Type @object: + + + + + +@object: + + + + + + + +@class: + + + + + + + +@class: + + @@ -108,7 +149,7 @@ The Base Object Type @class: - + @@ -116,46 +157,6 @@ The Base Object Type @value: - - - - - -@type: - - - - - - - -@object: - - - - - - - -@class: - - - - - - - -@class: - - - - - - - -@object: - - @@ -189,112 +190,6 @@ The Base Object Type @first_param_name: - - - - - -@object_type: -@first_property_name: -@var_args: -@Returns: - -@first_param_name: - - - - - - - -@object: -@first_property_name: -@Varargs: - -@first_param_name: - - - - - - - -@object: -@first_property_name: -@Varargs: - -@first_param_name: - - - - - - - -@object: -@first_property_name: -@var_args: - -@first_param_name: - - - - - - - -@object: -@first_property_name: -@var_args: - -@first_param_name: - - - - - - - -@object: -@property_name: -@value: - - - - - - - -@object: -@property_name: -@value: - - - - - - - -@object: - - - - - - - -@object: -@property_name: - - - - - - - -@object: - - @@ -312,47 +207,78 @@ The Base Object Type @object: - + @object: -@quark: +@signal_spec: +@Varargs: @Returns: - + @object: -@quark: -@data: - - - - - - - -@object: -@quark: -@data: -@destroy: - - - - - - - -@object: -@quark: +@signal_spec: +@Varargs: @Returns: + + + + + +@object: +@first_property_name: +@Varargs: +@Returns: + +@first_param_name: + + + + + + + +@object: +@first_property_name: +@Varargs: + +@first_param_name: + + + + + + + +@object: +@property_name: + + + + + + + +@object: + + + + + + + +@object: + + @@ -394,6 +320,113 @@ The Base Object Type @Returns: + + + + + +@object: +@quark: +@Returns: + + + + + + + +@object: +@quark: +@data: + + + + + + + +@object: +@quark: +@data: +@destroy: + + + + + + + +@object: +@quark: +@Returns: + + + + + + + +@object: +@property_name: +@value: + + + + + + + +@object: +@property_name: +@value: + + + + + + + +@object_type: +@first_property_name: +@var_args: +@Returns: + +@first_param_name: + + + + + + + +@object: +@first_property_name: +@var_args: + +@first_param_name: + + + + + + + +@object: +@first_property_name: +@var_args: + +@first_param_name: + + + + + + + +@object: +@closure: + + @@ -421,15 +454,6 @@ The Base Object Type @Returns: - - - - - -@object: -@closure: - - diff --git a/docs/reference/gobject/tmpl/param_specs.sgml b/docs/reference/gobject/tmpl/param_specs.sgml index 53319627a..d57c0a40c 100644 --- a/docs/reference/gobject/tmpl/param_specs.sgml +++ b/docs/reference/gobject/tmpl/param_specs.sgml @@ -118,6 +118,7 @@ Parameter Specifications @G_PARAM_WRITABLE: @G_PARAM_CONSTRUCT: @G_PARAM_CONSTRUCT_ONLY: +@G_PARAM_LAX_VALIDATION: @G_PARAM_PRIVATE: @@ -293,8 +294,9 @@ Parameter Specifications @param_name: @owner_type: @walk_ancestors: -@trailer_p: @Returns: + +@trailer_p: diff --git a/docs/reference/gobject/tmpl/signals.sgml b/docs/reference/gobject/tmpl/signals.sgml index 558b97388..4445fa03d 100644 --- a/docs/reference/gobject/tmpl/signals.sgml +++ b/docs/reference/gobject/tmpl/signals.sgml @@ -15,8 +15,8 @@ so basically they are a per-type facility that is inherited. A signal emission mainly involves invocation of a certain set of callbacks in precisely defined manner. There are two main categories of such callbacks, per-object - Although signals can deal with any kind of type, i'm - referring to those types as "object types" in the following, simply + Although signals can deal with any kind of instantiatable type, + i'm referring to those types as "object types" in the following, simply because that is the context most users will encounter signals in. ones and user provided ones. @@ -182,6 +182,27 @@ filled in by the g_signal_query() function. #gpointer data2); + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/reference/gobject/tmpl/standard_params.sgml b/docs/reference/gobject/tmpl/standard_params.sgml index ec7df7c2e..08b218caf 100644 --- a/docs/reference/gobject/tmpl/standard_params.sgml +++ b/docs/reference/gobject/tmpl/standard_params.sgml @@ -238,22 +238,6 @@ Standard Parameter Types @pspec: - - - - - -@pspec: - - - - - - - -@pspec: - - @@ -414,13 +398,6 @@ Standard Parameter Types @parent_instance: - - - - - -@parent_instance: - @@ -642,18 +619,6 @@ Standard Parameter Types @Returns: - - - - - -@name: -@nick: -@blurb: -@flags: -@Returns: - - diff --git a/docs/reference/gobject/tmpl/types.sgml b/docs/reference/gobject/tmpl/types.sgml index 4289ca474..87f848d1f 100644 --- a/docs/reference/gobject/tmpl/types.sgml +++ b/docs/reference/gobject/tmpl/types.sgml @@ -178,50 +178,48 @@ interfaces and C++ classes containing only pure virtual functions. The predefined identifiers of the reserved fundamental types. -@G_TYPE_INVALID: Usually a return value indicating an error. -@G_TYPE_NONE: A synonym for the "void" type in C. -@G_TYPE_INTERFACE: Root type of all interface types. -@G_TYPE_CHAR: Identifier for the built-in type "gchar". -@G_TYPE_UCHAR: Identifier for the built-in type "guchar". -@G_TYPE_BOOLEAN: Identifier for the built-in type "gboolean". -@G_TYPE_INT: Identifier for the built-in type "gint". -@G_TYPE_UINT: Identifier for the built-in type "guint". -@G_TYPE_LONG: Identifier for the built-in type "glong". -@G_TYPE_ULONG: Identifier for the built-in type "gulong". -@G_TYPE_ENUM: Identifier for the "#GEnum" type. -@G_TYPE_FLAGS: Identifier for the "#GFlags" type. -@G_TYPE_FLOAT: Identifier for the built-in type "gfloat". +@G_TYPE_INVALID: Usually a return value indicating an error. +@G_TYPE_NONE: A synonym for the "void" type in C. +@G_TYPE_INTERFACE: Root type of all interface types. +@G_TYPE_CHAR: Identifier for the built-in type "gchar". +@G_TYPE_UCHAR: Identifier for the built-in type "guchar". +@G_TYPE_BOOLEAN: Identifier for the built-in type "gboolean". +@G_TYPE_INT: Identifier for the built-in type "gint". +@G_TYPE_UINT: Identifier for the built-in type "guint". +@G_TYPE_LONG: Identifier for the built-in type "glong". +@G_TYPE_ULONG: Identifier for the built-in type "gulong". +@G_TYPE_ENUM: Identifier for the "#GEnum" type. +@G_TYPE_FLAGS: Identifier for the "#GFlags" type. +@G_TYPE_FLOAT: Identifier for the built-in type "gfloat". @G_TYPE_DOUBLE: Identifier for the built-in type "gdouble". @G_TYPE_STRING: Identifier for a pointer to a null-terminated string "gchar*". -@G_TYPE_PARAM: Identifier for the "#GParam" type. -@G_TYPE_BOXED: Identifier for the "#GBoxed" type. -@G_TYPE_POINTER: Identifier for anonymous pointers "void*". -@G_TYPE_CCALLBACK: Identifier for a pointer to a C function. +@G_TYPE_POINTER: Identifier for anonymous pointers "void*". +@G_TYPE_BOXED: Identifier for the "#GBoxed" type. +@G_TYPE_PARAM: Identifier for the "#GParam" type. @G_TYPE_OBJECT: Identifier for the "#GObject" type. -@G_TYPE_GTK_SIGNAL: Reserved for use by the Gtk+ software package. -@G_TYPE_BSE_PROCEDURE: Reserved for use by the BSE software package. -@G_TYPE_BSE_TIME: Reserved for use by the BSE software package. -@G_TYPE_BSE_NOTE: Reserved for use by the BSE software package. -@G_TYPE_BSE_DOTS: Reserved for use by the BSE software package. -@G_TYPE_GLE_GOBJECT: Reserved for use by the GLE software package. -@G_TYPE_LAST_RESERVED_FUNDAMENTAL: New third-party fundamental types have to use IDs higher than this. -@G_TYPE_PARAM_CHAR: Identifier for the "#GParamSpecChar" type. -@G_TYPE_PARAM_UCHAR: Identifier for the "#GParamSpecUChar" type. -@G_TYPE_PARAM_BOOLEAN: Identifier for the "#GParamSpecBoolean" type. -@G_TYPE_PARAM_INT: Identifier for the "#GParamSpecInt" type. -@G_TYPE_PARAM_UINT: Identifier for the "#GParamSpecUInt" type. -@G_TYPE_PARAM_LONG: Identifier for the "#GParamSpecLong" type. -@G_TYPE_PARAM_ULONG: Identifier for the "#GParamSpecULong" type. -@G_TYPE_PARAM_ENUM: Identifier for the "#GParamSpecEnum" type. -@G_TYPE_PARAM_FLAGS: Identifier for the "#GParamSpecFlags" type. -@G_TYPE_PARAM_FLOAT: Identifier for the "#GParamSpecFloat" type. -@G_TYPE_PARAM_DOUBLE: Identifier for the "#GParamSpecDouble" type. -@G_TYPE_PARAM_STRING: Identifier for the "#GParamSpecString" type. -@G_TYPE_PARAM_PARAM: Identifier for the "#GParamSpecParam" type. -@G_TYPE_PARAM_POINTER: Identifier for the "#GParamSpecPointer" type. -@G_TYPE_PARAM_CCALLBACK: Identifier for the "#GParamSpecCCallback" type. -@G_TYPE_PARAM_BOXED: Identifier for the "#GParamSpecBoxed" type. -@G_TYPE_PARAM_OBJECT: Identifier for the "#GParamSpecObject" type. +@G_TYPE_RESERVED_BSE_FIRST: First fundamental type ID reserved for BSE. +@G_TYPE_RESERVED_BSE_LAST: Last fundamental type ID reserved for BSE. +@G_TYPE_RESERVED_LAST_FUNDAMENTAL: Last reserved fundamental type ID. +@G_TYPE_CLOSURE: +@G_TYPE_VALUE_ARRAY: +@G_TYPE_PARAM_CHAR: Identifier for the "#GParamSpecChar" type. +@G_TYPE_PARAM_UCHAR: Identifier for the "#GParamSpecUChar" type. +@G_TYPE_PARAM_BOOLEAN: Identifier for the "#GParamSpecBoolean" type. +@G_TYPE_PARAM_INT: Identifier for the "#GParamSpecInt" type. +@G_TYPE_PARAM_UINT: Identifier for the "#GParamSpecUInt" type. +@G_TYPE_PARAM_LONG: Identifier for the "#GParamSpecLong" type. +@G_TYPE_PARAM_ULONG: Identifier for the "#GParamSpecULong" type. +@G_TYPE_PARAM_ENUM: Identifier for the "#GParamSpecEnum" type. +@G_TYPE_PARAM_FLAGS: Identifier for the "#GParamSpecFlags" type. +@G_TYPE_PARAM_FLOAT: Identifier for the "#GParamSpecFloat" type. +@G_TYPE_PARAM_DOUBLE: Identifier for the "#GParamSpecDouble" type. +@G_TYPE_PARAM_STRING: Identifier for the "#GParamSpecString" type. +@G_TYPE_PARAM_PARAM: Identifier for the "#GParamSpecParam" type. +@G_TYPE_PARAM_BOXED: Identifier for the "#GParamSpecBoxed" type. +@G_TYPE_PARAM_POINTER: Identifier for the "#GParamSpecPointer" type. +@G_TYPE_PARAM_VALUE_ARRAY: Identifier for the "#GParamSpecValueArray" type. +@G_TYPE_PARAM_CLOSURE: Identifier for the "#GParamClosure" type. +@G_TYPE_PARAM_OBJECT: Identifier for the "#GParamSpecObject" type. @@ -256,8 +254,8 @@ across invocation of g_type_register_static(). @instance_size: Size of the instance (object) structure (required for instantiatable types only). @n_preallocs: Number of pre-allocated (cached) instances to reserve memory for (0 indicates no caching). @instance_init: Location of the instance initialization function (optional, for instantiatable types only). -@value_table: Function table for generic handling of GValues of this type (usualy only usefull for - fundamental types). +@value_table: A #GTypeValueTable function table for generic handling of GValues of this type (usualy only + usefull for fundamental types). @@ -278,20 +276,6 @@ used specifically for managing interface types. @interface_data: Location of user data passed to the @interface_init and @interface_finalize functions (optional). - - - - - -@value_init: -@value_free: -@value_copy: -@value_peek_pointer: -@collect_format: -@collect_value: -@lcopy_format: -@lcopy_value: - Returns the type identifier from a given @instance structure. @@ -423,8 +407,8 @@ Return the unique name that is assigned to a type ID (this is the preferred meth to find out whether a specific type has been registered for the passed in ID yet). -@type: Type to return name for. -@Returns: Static type name or NULL. +@type: Type to return name for. +@Returns: Static type name or NULL. @@ -458,17 +442,17 @@ If the passed in type has no parent, i.e. is a fundamental type, 0 is returned. -Given a @type and a @base_type which is contained in its anchestry, return -the type that @base_type is the direct parent type for. -In other words, for a given type branch, e.g. Root-Derived1-Derived2-Leaf, specified -through @type=Leaf, return the nextmost child of @base_type. In this example, for -@base_type=Derived1, the returned value would be Derived2, for @base_type=Root, the -returned value would be Derived1. +Given a @leaf_type and a @root_type which is contained in its anchestry, return +the type that @root_type is the immediate parent of. +In other words, this function determines the type that is derived directly from +@root_type which is also a base class of @leaf_type. Given a root type and a +leaf type, this function can be used to determine the types and order in which +the leaf type is descended from the root type. -@type: Descendant of @base_type and the type to be returned. -@base_type: Direct parent of the returned type. -@Returns: Immediate child of @base_type and anchestor of @type. +@leaf_type: Descendant of @root_type and the type to be returned. +@root_type: Immediate parent of the returned type. +@Returns: Immediate child of @root_type and anchestor of @leaf_type. @@ -799,6 +783,7 @@ Bit masks used to check or determine characteristics of a type. @G_TYPE_FLAG_ABSTRACT: Indicates an abstract type. No instances can be created for an abstract type. +@G_TYPE_FLAG_VALUE_ABSTRACT: @@ -1034,16 +1019,6 @@ the anchestry of @instance. @Returns: - - -Determines if @value is a #GValue whose type conforms to @type. - - -@value: A valid #GValue structure. -@type: A #GType value. -@Returns: #TRUE if @value is a #GValue of @type or #FALSE if not. - - Returns the location of the #GTypeValueTable associated with @type. diff --git a/docs/reference/gobject/tmpl/value_types.sgml b/docs/reference/gobject/tmpl/value_types.sgml index 9e568b26e..fe77eb6ae 100644 --- a/docs/reference/gobject/tmpl/value_types.sgml +++ b/docs/reference/gobject/tmpl/value_types.sgml @@ -9,12 +9,14 @@ Standard value types + - + + @@ -22,7 +24,7 @@ Standard value types @value: - + @@ -30,7 +32,7 @@ Standard value types @value: - + @@ -38,7 +40,7 @@ Standard value types @value: - + @@ -46,7 +48,7 @@ Standard value types @value: - + @@ -54,7 +56,7 @@ Standard value types @value: - + @@ -62,7 +64,7 @@ Standard value types @value: - + @@ -70,7 +72,7 @@ Standard value types @value: - + @@ -78,7 +80,7 @@ Standard value types @value: - + @@ -86,7 +88,7 @@ Standard value types @value: - + @@ -94,7 +96,7 @@ Standard value types @value: - + @@ -102,15 +104,7 @@ Standard value types @value: - - - - - -@value: - - - + @@ -298,6 +292,15 @@ Standard value types @v_string: + + +This is an internal function introduced mainly for C marshallers. + + +@value: +@v_string: + + @@ -343,16 +346,6 @@ Standard value types @Returns: - - - - - -@value: -@callback_func: -@callback_data: - - @@ -371,25 +364,6 @@ Standard value types @v_pointer: - - - - - -@value: -@Returns: - - - - - - - -@value: -@callback_func: -@callback_data: - - diff --git a/garray.c b/garray.c index c50d643f2..9f32b7600 100644 --- a/garray.c +++ b/garray.c @@ -286,7 +286,7 @@ g_array_sort (GArray *farray, void g_array_sort_with_data (GArray *farray, - GCompareFuncData compare_func, + GCompareDataFunc compare_func, gpointer user_data) { GRealArray *array = (GRealArray*) farray; @@ -580,7 +580,7 @@ g_ptr_array_sort (GPtrArray *array, void g_ptr_array_sort_with_data (GPtrArray *array, - GCompareFuncData compare_func, + GCompareDataFunc compare_func, gpointer user_data) { g_return_if_fail (array != NULL); @@ -663,7 +663,7 @@ g_byte_array_sort (GByteArray *array, void g_byte_array_sort_with_data (GByteArray *array, - GCompareFuncData compare_func, + GCompareDataFunc compare_func, gpointer user_data) { g_array_sort_with_data ((GArray *) array, compare_func, user_data); diff --git a/garray.h b/garray.h index ddade3688..766da77d6 100644 --- a/garray.h +++ b/garray.h @@ -91,7 +91,7 @@ GArray* g_array_remove_index_fast (GArray *array, void g_array_sort (GArray *array, GCompareFunc compare_func); void g_array_sort_with_data (GArray *array, - GCompareFuncData compare_func, + GCompareDataFunc compare_func, gpointer user_data); /* Resizable pointer array. This interface is much less complicated @@ -119,7 +119,7 @@ void g_ptr_array_add (GPtrArray *array, void g_ptr_array_sort (GPtrArray *array, GCompareFunc compare_func); void g_ptr_array_sort_with_data (GPtrArray *array, - GCompareFuncData compare_func, + GCompareDataFunc compare_func, gpointer user_data); @@ -146,7 +146,7 @@ GByteArray* g_byte_array_remove_index_fast (GByteArray *array, void g_byte_array_sort (GByteArray *array, GCompareFunc compare_func); void g_byte_array_sort_with_data (GByteArray *array, - GCompareFuncData compare_func, + GCompareDataFunc compare_func, gpointer user_data); diff --git a/glib-object.h b/glib-object.h index b4392431b..98e3dfebc 100644 --- a/glib-object.h +++ b/glib-object.h @@ -31,6 +31,7 @@ #include #include #include +#include #include diff --git a/glib/garray.c b/glib/garray.c index c50d643f2..9f32b7600 100644 --- a/glib/garray.c +++ b/glib/garray.c @@ -286,7 +286,7 @@ g_array_sort (GArray *farray, void g_array_sort_with_data (GArray *farray, - GCompareFuncData compare_func, + GCompareDataFunc compare_func, gpointer user_data) { GRealArray *array = (GRealArray*) farray; @@ -580,7 +580,7 @@ g_ptr_array_sort (GPtrArray *array, void g_ptr_array_sort_with_data (GPtrArray *array, - GCompareFuncData compare_func, + GCompareDataFunc compare_func, gpointer user_data) { g_return_if_fail (array != NULL); @@ -663,7 +663,7 @@ g_byte_array_sort (GByteArray *array, void g_byte_array_sort_with_data (GByteArray *array, - GCompareFuncData compare_func, + GCompareDataFunc compare_func, gpointer user_data) { g_array_sort_with_data ((GArray *) array, compare_func, user_data); diff --git a/glib/garray.h b/glib/garray.h index ddade3688..766da77d6 100644 --- a/glib/garray.h +++ b/glib/garray.h @@ -91,7 +91,7 @@ GArray* g_array_remove_index_fast (GArray *array, void g_array_sort (GArray *array, GCompareFunc compare_func); void g_array_sort_with_data (GArray *array, - GCompareFuncData compare_func, + GCompareDataFunc compare_func, gpointer user_data); /* Resizable pointer array. This interface is much less complicated @@ -119,7 +119,7 @@ void g_ptr_array_add (GPtrArray *array, void g_ptr_array_sort (GPtrArray *array, GCompareFunc compare_func); void g_ptr_array_sort_with_data (GPtrArray *array, - GCompareFuncData compare_func, + GCompareDataFunc compare_func, gpointer user_data); @@ -146,7 +146,7 @@ GByteArray* g_byte_array_remove_index_fast (GByteArray *array, void g_byte_array_sort (GByteArray *array, GCompareFunc compare_func); void g_byte_array_sort_with_data (GByteArray *array, - GCompareFuncData compare_func, + GCompareDataFunc compare_func, gpointer user_data); diff --git a/glib/gbsearcharray.c b/glib/gbsearcharray.c index dbba47c9b..9a8dbcf8e 100644 --- a/glib/gbsearcharray.c +++ b/glib/gbsearcharray.c @@ -1,5 +1,5 @@ /* GObject - GLib Type, Object, Parameter and Signal Library - * Copyright (C) 2000 Tim Janik + * Copyright (C) 2000-2001 Tim Janik * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -94,7 +94,7 @@ bsearch_array_insert (GBSearchArray *barray, } else barray->nodes = g_realloc (barray->nodes, barray->n_nodes * sizeof_node); - check = (char *) barray->nodes + i * sizeof_node; + check = ((guint8*) barray->nodes) + i * sizeof_node; g_memmove (check + sizeof_node, check, (n_nodes - i) * sizeof_node); replace = TRUE; SKIP_GROW: diff --git a/glib/gbsearcharray.h b/glib/gbsearcharray.h index 3b0cf1682..1bc0ab21e 100644 --- a/glib/gbsearcharray.h +++ b/glib/gbsearcharray.h @@ -1,5 +1,5 @@ /* GObject - GLib Type, Object, Parameter and Signal Library - * Copyright (C) 2000 Tim Janik + * Copyright (C) 2000-2001 Tim Janik * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -69,6 +69,9 @@ gpointer g_bsearch_array_lookup (GBSearchArray *barray, G_INLINE_FUNC gpointer g_bsearch_array_get_nth (GBSearchArray *barray, guint n); +G_INLINE_FUNC +guint g_bsearch_array_get_index (GBSearchArray *barray, + gpointer node_in_array); /* --- implementation details --- */ @@ -115,14 +118,25 @@ g_bsearch_array_get_nth (GBSearchArray *barray, { if (n < barray->n_nodes) { - guint8 *nodes = (guint8 *) barray->nodes; + guint8 *nodes = (guint8*) barray->nodes; return nodes + n * barray->sizeof_node; } else return NULL; } -#endif /* G_CAN_INLINE && __G_BSEARCHARRAY_C__ */ +G_INLINE_FUNC +guint +g_bsearch_array_get_index (GBSearchArray *barray, + gpointer node_in_array) +{ + guint distance = ((guint8*) node_in_array) - ((guint8*) barray->nodes); + + distance /= barray->sizeof_node; + + return MIN (distance, barray->n_nodes); +} +#endif /* G_CAN_INLINE || __G_BSEARCHARRAY_C__ */ diff --git a/glib/glib-object.h b/glib/glib-object.h index b4392431b..98e3dfebc 100644 --- a/glib/glib-object.h +++ b/glib/glib-object.h @@ -31,6 +31,7 @@ #include #include #include +#include #include diff --git a/glib/glist.c b/glib/glist.c index 8c2201069..e629b1a20 100644 --- a/glib/glist.c +++ b/glib/glist.c @@ -651,7 +651,7 @@ g_list_sort_merge (GList *l1, while (l1 && l2) { if (use_data) - cmp = ((GCompareFuncData) compare_func) (l1->data, l2->data, user_data); + cmp = ((GCompareDataFunc) compare_func) (l1->data, l2->data, user_data); else cmp = ((GCompareFunc) compare_func) (l1->data, l2->data); @@ -720,7 +720,7 @@ g_list_sort (GList *list, GList * g_list_sort_with_data (GList *list, - GCompareFuncData compare_func, + GCompareDataFunc compare_func, gpointer user_data) { return g_list_sort_real (list, (GFunc) compare_func, TRUE, user_data); diff --git a/glib/glist.h b/glib/glist.h index 438b89bf6..7b3e977a5 100644 --- a/glib/glist.h +++ b/glib/glist.h @@ -87,7 +87,7 @@ void g_list_foreach (GList *list, GList* g_list_sort (GList *list, GCompareFunc compare_func); GList* g_list_sort_with_data (GList *list, - GCompareFuncData compare_func, + GCompareDataFunc compare_func, gpointer user_data); gpointer g_list_nth_data (GList *list, guint n); diff --git a/glib/gqsort.c b/glib/gqsort.c index 69b63637e..c75cca31a 100644 --- a/glib/gqsort.c +++ b/glib/gqsort.c @@ -96,7 +96,7 @@ void g_qsort_with_data (gconstpointer pbase, gint total_elems, size_t size, - GCompareFuncData compare_func, + GCompareDataFunc compare_func, gpointer user_data) { register char *base_ptr = (char *) pbase; diff --git a/glib/gqsort.h b/glib/gqsort.h index f236e04fb..d946e80ca 100644 --- a/glib/gqsort.h +++ b/glib/gqsort.h @@ -35,7 +35,7 @@ G_BEGIN_DECLS void g_qsort_with_data (gconstpointer pbase, gint total_elems, size_t size, - GCompareFuncData compare_func, + GCompareDataFunc compare_func, gpointer user_data); G_END_DECLS diff --git a/glib/gslist.c b/glib/gslist.c index 6c9019914..65c2c6cdb 100644 --- a/glib/gslist.c +++ b/glib/gslist.c @@ -634,7 +634,7 @@ g_slist_sort_merge (GSList *l1, while (l1 && l2) { if (use_data) - cmp = ((GCompareFuncData) compare_func) (l1->data, l2->data, user_data); + cmp = ((GCompareDataFunc) compare_func) (l1->data, l2->data, user_data); else cmp = ((GCompareFunc) compare_func) (l1->data, l2->data); @@ -695,7 +695,7 @@ g_slist_sort (GSList *list, GSList * g_slist_sort_with_data (GSList *list, - GCompareFuncData compare_func, + GCompareDataFunc compare_func, gpointer user_data) { return g_slist_sort_real (list, (GFunc) compare_func, TRUE, user_data); diff --git a/glib/gslist.h b/glib/gslist.h index 446eab43e..8d94b2c07 100644 --- a/glib/gslist.h +++ b/glib/gslist.h @@ -88,7 +88,7 @@ void g_slist_foreach (GSList *list, GSList* g_slist_sort (GSList *list, GCompareFunc compare_func); GSList* g_slist_sort_with_data (GSList *list, - GCompareFuncData compare_func, + GCompareDataFunc compare_func, gpointer user_data); gpointer g_slist_nth_data (GSList *list, guint n); diff --git a/glib/gstring.c b/glib/gstring.c index ff6fc7c6d..a720ac73d 100644 --- a/glib/gstring.c +++ b/glib/gstring.c @@ -565,9 +565,9 @@ g_string_up (GString *fstring) } static void -g_string_sprintfa_int (GString *string, - const gchar *fmt, - va_list args) +g_string_printfa_internal (GString *string, + const gchar *fmt, + va_list args) { gchar *buffer; @@ -577,27 +577,27 @@ g_string_sprintfa_int (GString *string, } void -g_string_sprintf (GString *string, - const gchar *fmt, - ...) +g_string_printf (GString *string, + const gchar *fmt, + ...) { va_list args; g_string_truncate (string, 0); va_start (args, fmt); - g_string_sprintfa_int (string, fmt, args); + g_string_printfa_internal (string, fmt, args); va_end (args); } void -g_string_sprintfa (GString *string, - const gchar *fmt, - ...) +g_string_printfa (GString *string, + const gchar *fmt, + ...) { va_list args; va_start (args, fmt); - g_string_sprintfa_int (string, fmt, args); + g_string_printfa_internal (string, fmt, args); va_end (args); } diff --git a/glib/gstring.h b/glib/gstring.h index d2f88e066..84d0bbb3f 100644 --- a/glib/gstring.h +++ b/glib/gstring.h @@ -94,12 +94,15 @@ GString* g_string_erase (GString *string, gint len); GString* g_string_down (GString *string); GString* g_string_up (GString *string); -void g_string_sprintf (GString *string, +void g_string_printf (GString *string, const gchar *format, ...) G_GNUC_PRINTF (2, 3); -void g_string_sprintfa (GString *string, +void g_string_printfa (GString *string, const gchar *format, ...) G_GNUC_PRINTF (2, 3); +/* compatibility */ +#define g_string_sprintf g_string_printf +#define g_string_sprintfa g_string_printfa G_END_DECLS diff --git a/glib/gtree.c b/glib/gtree.c index c453eb64b..5e0c0f573 100644 --- a/glib/gtree.c +++ b/glib/gtree.c @@ -41,7 +41,7 @@ typedef struct _GTreeNode GTreeNode; struct _GRealTree { GTreeNode *root; - GCompareFuncData key_compare; + GCompareDataFunc key_compare; gpointer key_compare_data; }; @@ -59,13 +59,13 @@ static GTreeNode* g_tree_node_new (gpointer key, gpointer value); static void g_tree_node_destroy (GTreeNode *node); static GTreeNode* g_tree_node_insert (GTreeNode *node, - GCompareFuncData compare, + GCompareDataFunc compare, gpointer comp_data, gpointer key, gpointer value, gint *inserted); static GTreeNode* g_tree_node_remove (GTreeNode *node, - GCompareFuncData compare, + GCompareDataFunc compare, gpointer comp_data, gconstpointer key); static GTreeNode* g_tree_node_balance (GTreeNode *node); @@ -76,7 +76,7 @@ static GTreeNode* g_tree_node_restore_left_balance (GTreeNode *node, static GTreeNode* g_tree_node_restore_right_balance (GTreeNode *node, gint old_balance); static gpointer g_tree_node_lookup (GTreeNode *node, - GCompareFuncData compare, + GCompareDataFunc compare, gpointer comp_data, gconstpointer key); static gint g_tree_node_count (GTreeNode *node); @@ -157,7 +157,7 @@ g_tree_node_destroy (GTreeNode *node) } } -GTree* g_tree_new_udata(GCompareFuncData key_compare_func, +GTree* g_tree_new_udata(GCompareDataFunc key_compare_func, gpointer key_compare_data) { GRealTree *rtree; @@ -175,7 +175,7 @@ GTree* g_tree_new_udata(GCompareFuncData key_compare_func, GTree* g_tree_new (GCompareFunc key_compare_func) { - return g_tree_new_udata ((GCompareFuncData) key_compare_func, NULL); + return g_tree_new_udata ((GCompareDataFunc) key_compare_func, NULL); } @@ -322,7 +322,7 @@ g_tree_nnodes (GTree *tree) static GTreeNode* g_tree_node_insert (GTreeNode *node, - GCompareFuncData compare, + GCompareDataFunc compare, gpointer compare_data, gpointer key, gpointer value, @@ -393,7 +393,7 @@ g_tree_node_insert (GTreeNode *node, static GTreeNode* g_tree_node_remove (GTreeNode *node, - GCompareFuncData compare, + GCompareDataFunc compare, gpointer compare_data, gconstpointer key) { @@ -526,7 +526,7 @@ g_tree_node_restore_right_balance (GTreeNode *node, static gpointer g_tree_node_lookup (GTreeNode *node, - GCompareFuncData compare, + GCompareDataFunc compare, gpointer compare_data, gconstpointer key) { diff --git a/glib/gtree.h b/glib/gtree.h index 3530a6374..78a52fb0f 100644 --- a/glib/gtree.h +++ b/glib/gtree.h @@ -40,7 +40,7 @@ typedef gint (*GTraverseFunc) (gpointer key, /* Balanced binary trees */ GTree* g_tree_new (GCompareFunc key_compare_func); -GTree* g_tree_new_with_data (GCompareFuncData key_compare_func, +GTree* g_tree_new_with_data (GCompareDataFunc key_compare_func, gpointer user_data); void g_tree_destroy (GTree *tree); void g_tree_insert (GTree *tree, diff --git a/glib/gtypes.h b/glib/gtypes.h index 21a29e919..487ecdc77 100644 --- a/glib/gtypes.h +++ b/glib/gtypes.h @@ -69,7 +69,7 @@ typedef const void *gconstpointer; typedef gint (*GCompareFunc) (gconstpointer a, gconstpointer b); -typedef gint (*GCompareFuncData) (gconstpointer a, +typedef gint (*GCompareDataFunc) (gconstpointer a, gconstpointer b, gpointer user_data); typedef gboolean (*GEqualFunc) (gconstpointer a, diff --git a/glist.c b/glist.c index 8c2201069..e629b1a20 100644 --- a/glist.c +++ b/glist.c @@ -651,7 +651,7 @@ g_list_sort_merge (GList *l1, while (l1 && l2) { if (use_data) - cmp = ((GCompareFuncData) compare_func) (l1->data, l2->data, user_data); + cmp = ((GCompareDataFunc) compare_func) (l1->data, l2->data, user_data); else cmp = ((GCompareFunc) compare_func) (l1->data, l2->data); @@ -720,7 +720,7 @@ g_list_sort (GList *list, GList * g_list_sort_with_data (GList *list, - GCompareFuncData compare_func, + GCompareDataFunc compare_func, gpointer user_data) { return g_list_sort_real (list, (GFunc) compare_func, TRUE, user_data); diff --git a/glist.h b/glist.h index 438b89bf6..7b3e977a5 100644 --- a/glist.h +++ b/glist.h @@ -87,7 +87,7 @@ void g_list_foreach (GList *list, GList* g_list_sort (GList *list, GCompareFunc compare_func); GList* g_list_sort_with_data (GList *list, - GCompareFuncData compare_func, + GCompareDataFunc compare_func, gpointer user_data); gpointer g_list_nth_data (GList *list, guint n); diff --git a/gobject/ChangeLog b/gobject/ChangeLog index 2dc5102da..9e70d5131 100644 --- a/gobject/ChangeLog +++ b/gobject/ChangeLog @@ -2,10 +2,87 @@ * Makefile.am: Avoid rebuilding everything everytime. -Mon Mar 5 15:26:30 2001 Jonathan Blandford +Wed Mar 7 09:36:33 2001 Tim Janik - * gparamspecs.c (g_param_spec_interface): add a new param spec to - handle interfaces. + * gboxed.[hc]: changed prototype of g_boxed_type_register_static() + to contain an optional init function and a hint at whether the + boxed structure uses ref counting internally. + added g_value_set_boxed_take_ownership(). + made G_TYPE_BOXED an abstract value type. + + * genums.[hc]: made G_TYPE_ENUM and G_TYPE_FLAGS abstract value + types. + + * glib-genmarshal.c: argument type changes, preparation for third-party + arg specification. + + * gobject.[hc]: cleaned up get/set property code. + added g_strdup_value_contents() to improve warnings. + + * gparam.[hc]: added g_param_value_convert(), taking over responsibility + of the old g_value_convert(). added G_PARAM_LAX_VALIDATION flag so + validation alterations may be valid a part of the property setting + process. + + * gparamspecs.[hc]: made value comparisons stable (for sort applications). + added GParamSpecValueArray, a param spec for value arrays and + GParamSpecClosure. nuked the value exchange functions and + GParamSpecCCallback. + + * gtype.[hc]: catch unintialized usages of the type system with + g_return_val_if_uninitialized(). introduced G_TYPE_FLAG_VALUE_ABSTRACT + to flag types that introduce a value table, but can't be used for + g_value_init(). cleaned up reserved type ids. + + * gvalue.[hc]: code cleanups and saner checking. + nuked the value exchange API. implemented value transformations, we + can't really "convert" values, rather transforms are an anylogy to + C casts, real conversions need a param spec for validation, which is + why g_param_value_convert() does real conversions now. + + * gvaluearray.[hc]: new files that implement a GValueArray, a struct + that can hold inhomogeneous arrays of value (to that extend that it + also allowes undefined values, i.e. G_VALUE_TYPE(value)==0). + this is exposed to the type system as a boxed type. + + * gvaluetransform.c: new file implementing most of the former value + exchange functions as single-sided transformations. + + * gvaluetypes.[hc]: nuked G_TYPE_CCALLBACK, added + g_value_set_string_take_ownership(). + + * *.h: s/G_IS_VALUE_/G_VALUE_HOLDS_/. + + * *.[hc]: many fixes and cleanups. + + * many warning improvements. + +Tue Feb 27 18:35:15 2001 Tim Janik + + * gobject.c (g_object_get_valist): urg, pass G_VALUE_NOCOPY_CONTENTS + into G_VALUE_LCOPY(), this needs proper documenting. + + * gparam.c: fixed G_PARAM_USER_MASK. + + * gtype.c (type_data_make_W): + (type_data_last_unref_Wm): fixed invalid memory freeing. + + * gobject.c (g_object_last_unref): destroy signal handlers associated + with object, right before finalization. + + * gsignal.c (g_signal_parse_name): catch destroyed nodes or signals + that don't actually support details. + + * gobject.[hc]: got rid of property trailers. nuked GObject + properties "data" and the "signal" variants. + (g_object_connect): new convenience function to do multiple + signal connections at once. + (g_object_disconnect): likewise, for disconnections. + + * gparam.[hc] (g_param_spec_pool_lookup): took out trailer support. + + * gvalue.[hc]: marked g_value_fits_pointer() and g_value_peek_pointer() + as private (the latter got renamed from g_value_get_as_pointer()). Wed Feb 21 18:31:46 2001 Jonathan Blandford diff --git a/gobject/Makefile.am b/gobject/Makefile.am index aecfc3ae0..1005bee33 100644 --- a/gobject/Makefile.am +++ b/gobject/Makefile.am @@ -8,6 +8,7 @@ INCLUDES = @STRIP_BEGIN@ \ -I$(top_srcdir) \ -I$(top_builddir) \ @GLIB_DEBUG_FLAGS@ \ + -DG_DISABLE_CONST_RETURNS \ @STRIP_END@ # libraries to compile and install @@ -38,6 +39,7 @@ gruntime_public_h_sources = @STRIP_BEGIN@ \ gtypemodule.h \ gtypeplugin.h \ gvalue.h \ + gvaluearray.h \ gvaluecollector.h \ gvaluetypes.h \ @STRIP_END@ @@ -57,6 +59,8 @@ gruntime_c_sources = @STRIP_BEGIN@ \ gtypemodule.c \ gtypeplugin.c \ gvalue.c \ + gvaluearray.c \ + gvaluetransform.c \ gvaluetypes.c \ @STRIP_END@ diff --git a/gobject/gboxed.c b/gobject/gboxed.c index a2684b31b..5356513e9 100644 --- a/gobject/gboxed.c +++ b/gobject/gboxed.c @@ -1,5 +1,5 @@ /* GObject - GLib Type, Object, Parameter and Signal Library - * Copyright (C) 2000 Red Hat, Inc. + * Copyright (C) 2000-2001 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -20,6 +20,8 @@ #include "gbsearcharray.h" #include "gvalue.h" +#include "gvaluearray.h" +#include "gclosure.h" #include "gvaluecollector.h" #include @@ -28,8 +30,10 @@ typedef struct { GType type; + GBoxedInitFunc init; GBoxedCopyFunc copy; GBoxedFreeFunc free; + gboolean is_refcounted; } BoxedNode; @@ -52,6 +56,20 @@ boxed_nodes_cmp (gconstpointer p1, return G_BSEARCH_ARRAY_CMP (node1->type, node2->type); } +static inline void /* keep this function in sync with gvalue.c */ +value_meminit (GValue *value, + GType value_type) +{ + value->g_type = value_type; + memset (value->data, 0, sizeof (value->data)); +} + +static gpointer +value_array_init (void) +{ + return g_value_array_new (0); +} + void g_boxed_type_init (void) /* sync with gtype.c */ { @@ -72,14 +90,37 @@ g_boxed_type_init (void) /* sync with gtype.c */ /* G_TYPE_BOXED */ - type = g_type_register_fundamental (G_TYPE_BOXED, "GBoxed", &info, &finfo, G_TYPE_FLAG_ABSTRACT); + type = g_type_register_fundamental (G_TYPE_BOXED, "GBoxed", &info, &finfo, + G_TYPE_FLAG_ABSTRACT | G_TYPE_FLAG_VALUE_ABSTRACT); g_assert (type == G_TYPE_BOXED); + + /* boxed: G_TYPE_CLOSURE + */ + type = g_boxed_type_register_static ("GClosure", + (GBoxedInitFunc) NULL, + (GBoxedCopyFunc) g_closure_ref, + (GBoxedFreeFunc) g_closure_unref, + TRUE); + g_assert (type == G_TYPE_CLOSURE); + + /* boxed: G_TYPE_VALUE_ARRAY + */ + type = g_boxed_type_register_static ("GValueArray", + value_array_init, /* don't allow NULL values */ + (GBoxedCopyFunc) g_value_array_copy, + (GBoxedFreeFunc) g_value_array_free, + FALSE); + g_assert (type == G_TYPE_VALUE_ARRAY); } static void boxed_proxy_value_init (GValue *value) { - value->data[0].v_pointer = 0; + BoxedNode key, *node; + + key.type = G_VALUE_TYPE (value); + node = g_bsearch_array_lookup (&boxed_bsa, &key); + value->data[0].v_pointer = node->init ? node->init () : NULL; } static void @@ -89,7 +130,7 @@ boxed_proxy_value_free (GValue *value) { BoxedNode key, *node; - key.type = value->g_type; + key.type = G_VALUE_TYPE (value); node = g_bsearch_array_lookup (&boxed_bsa, &key); node->free (value->data[0].v_pointer); } @@ -103,7 +144,7 @@ boxed_proxy_value_copy (const GValue *src_value, { BoxedNode key, *node; - key.type = src_value->g_type; + key.type = G_VALUE_TYPE (src_value); node = g_bsearch_array_lookup (&boxed_bsa, &key); dest_value->data[0].v_pointer = node->copy (src_value->data[0].v_pointer); } @@ -123,20 +164,24 @@ boxed_proxy_collect_value (GValue *value, GTypeCValue *collect_values, guint collect_flags) { + BoxedNode key, *node; + + key.type = G_VALUE_TYPE (value); + node = g_bsearch_array_lookup (&boxed_bsa, &key); + + /* for NULL values, we have to call GBoxedInitFunc */ if (!collect_values[0].v_pointer) - value->data[0].v_pointer = NULL; - else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) - { - value->data[0].v_pointer = collect_values[0].v_pointer; - value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS; - } + value->data[0].v_pointer = node->init ? node->init () : NULL; else { - BoxedNode key, *node; - - key.type = value->g_type; - node = g_bsearch_array_lookup (&boxed_bsa, &key); - value->data[0].v_pointer = node->copy (collect_values[0].v_pointer); + /* never honour G_VALUE_NOCOPY_CONTENTS for ref-counted types */ + if (!node->is_refcounted && (collect_flags & G_VALUE_NOCOPY_CONTENTS)) + { + value->data[0].v_pointer = collect_values[0].v_pointer; + value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS; + } + else + value->data[0].v_pointer = node->copy (collect_values[0].v_pointer); } return NULL; @@ -161,7 +206,7 @@ boxed_proxy_lcopy_value (const GValue *value, { BoxedNode key, *node; - key.type = value->g_type; + key.type = G_VALUE_TYPE (value); node = g_bsearch_array_lookup (&boxed_bsa, &key); *boxed_p = node->copy (value->data[0].v_pointer); } @@ -171,8 +216,10 @@ boxed_proxy_lcopy_value (const GValue *value, GType g_boxed_type_register_static (const gchar *name, + GBoxedInitFunc boxed_init, GBoxedCopyFunc boxed_copy, - GBoxedFreeFunc boxed_free) + GBoxedFreeFunc boxed_free, + gboolean is_refcounted) { static const GTypeValueTable vtable = { boxed_proxy_value_init, @@ -211,8 +258,10 @@ g_boxed_type_register_static (const gchar *name, BoxedNode key; key.type = type; + key.init = boxed_init; key.copy = boxed_copy; key.free = boxed_free; + key.is_refcounted = is_refcounted != FALSE; g_bsearch_array_insert (&boxed_bsa, &key, TRUE); } @@ -247,14 +296,26 @@ g_boxed_copy (GType boxed_type, { GValue src_value, dest_value; - /* we heavil rely on the gvalue.c implementation here */ - - memset (&src_value.data, 0, sizeof (src_value.data)); - memset (&dest_value.data, 0, sizeof (dest_value.data)); - dest_value.g_type = boxed_type; - src_value.g_type = boxed_type; + /* we heavil rely on third-party boxed type value vtable + * implementations to follow normal boxed value storage + * (data[0].v_pointer is the boxed struct, and + * data[1].v_uint holds the G_VALUE_NOCOPY_CONTENTS flag, + * rest zero). + * but then, we can expect that since we layed out the + * g_boxed_*() API. + * data[1].v_uint&G_VALUE_NOCOPY_CONTENTS shouldn't be set + * after a copy. + */ + /* equiv. to g_value_set_static_boxed() */ + value_meminit (&src_value, boxed_type); src_value.data[0].v_pointer = (gpointer) src_boxed; + src_value.data[1].v_uint = G_VALUE_NOCOPY_CONTENTS; + + /* call third-party code copy fucntion, fingers-crossed */ + value_meminit (&dest_value, boxed_type); value_table->value_copy (&src_value, &dest_value); + + /* double check and grouse if things went wrong */ if (dest_value.data[1].v_ulong || dest_value.data[2].v_ulong || dest_value.data[3].v_ulong) @@ -294,44 +355,17 @@ g_boxed_free (GType boxed_type, { GValue value; - /* we heavil rely on the gvalue.c implementation here */ - memset (&value.data, 0, sizeof (value.data)); - value.g_type = boxed_type; + /* see g_boxed_copy() on why we think we can do this */ + value_meminit (&value, boxed_type); value.data[0].v_pointer = boxed; value_table->value_free (&value); } } -void -g_value_set_boxed (GValue *value, - gconstpointer boxed) -{ - g_return_if_fail (G_IS_VALUE_BOXED (value)); - g_return_if_fail (G_TYPE_IS_VALUE (G_VALUE_TYPE (value))); - - if (value->data[0].v_pointer && !(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)) - g_boxed_free (G_VALUE_TYPE (value), value->data[0].v_pointer); - value->data[0].v_pointer = boxed ? g_boxed_copy (G_VALUE_TYPE (value), boxed) : NULL; - value->data[1].v_uint = 0; -} - -void -g_value_set_static_boxed (GValue *value, - gconstpointer boxed) -{ - g_return_if_fail (G_IS_VALUE_BOXED (value)); - g_return_if_fail (G_TYPE_IS_VALUE (G_VALUE_TYPE (value))); - - if (value->data[0].v_pointer && !(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)) - g_boxed_free (G_VALUE_TYPE (value), value->data[0].v_pointer); - value->data[0].v_pointer = (gpointer) boxed; - value->data[1].v_uint = boxed ? G_VALUE_NOCOPY_CONTENTS : 0; -} - gpointer g_value_get_boxed (const GValue *value) { - g_return_val_if_fail (G_IS_VALUE_BOXED (value), NULL); + g_return_val_if_fail (G_VALUE_HOLDS_BOXED (value), NULL); g_return_val_if_fail (G_TYPE_IS_VALUE (G_VALUE_TYPE (value)), NULL); return value->data[0].v_pointer; @@ -340,8 +374,81 @@ g_value_get_boxed (const GValue *value) gpointer g_value_dup_boxed (GValue *value) { - g_return_val_if_fail (G_IS_VALUE_BOXED (value), NULL); + g_return_val_if_fail (G_VALUE_HOLDS_BOXED (value), NULL); g_return_val_if_fail (G_TYPE_IS_VALUE (G_VALUE_TYPE (value)), NULL); return value->data[0].v_pointer ? g_boxed_copy (G_VALUE_TYPE (value), value->data[0].v_pointer) : NULL; } + +static inline void +value_set_boxed_internal (GValue *value, + gconstpointer const_boxed, + gboolean need_copy, + gboolean need_free) +{ + BoxedNode key, *node; + gpointer boxed = (gpointer) const_boxed; + + if (!boxed) + { + /* just resetting to NULL might not be desired, need to + * have value reinitialized also (for values defaulting + * to other default value states than a NULL data pointer), + * g_value_reset() will handle this + */ + g_value_reset (value); + return; + } + + key.type = G_VALUE_TYPE (value); + node = g_bsearch_array_lookup (&boxed_bsa, &key); + + if (node) + { + /* we proxy this type, free contents and copy right away */ + if (value->data[0].v_pointer && !(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)) + node->free (value->data[0].v_pointer); + value->data[1].v_uint = need_free ? 0 : G_VALUE_NOCOPY_CONTENTS; + value->data[0].v_pointer = need_copy ? node->copy (boxed) : boxed; + } + else + { + /* we don't handle this type, free contents and let g_boxed_copy() + * figure what's required + */ + if (value->data[0].v_pointer && !(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)) + g_boxed_free (G_VALUE_TYPE (value), value->data[0].v_pointer); + value->data[1].v_uint = need_free ? 0 : G_VALUE_NOCOPY_CONTENTS; + value->data[0].v_pointer = need_copy ? g_boxed_copy (G_VALUE_TYPE (value), boxed) : boxed; + } +} + +void +g_value_set_boxed (GValue *value, + gconstpointer boxed) +{ + g_return_if_fail (G_VALUE_HOLDS_BOXED (value)); + g_return_if_fail (G_TYPE_IS_VALUE (G_VALUE_TYPE (value))); + + value_set_boxed_internal (value, boxed, TRUE, TRUE); +} + +void +g_value_set_static_boxed (GValue *value, + gconstpointer boxed) +{ + g_return_if_fail (G_VALUE_HOLDS_BOXED (value)); + g_return_if_fail (G_TYPE_IS_VALUE (G_VALUE_TYPE (value))); + + value_set_boxed_internal (value, boxed, FALSE, FALSE); +} + +void +g_value_set_boxed_take_ownership (GValue *value, + gconstpointer boxed) +{ + g_return_if_fail (G_VALUE_HOLDS_BOXED (value)); + g_return_if_fail (G_TYPE_IS_VALUE (G_VALUE_TYPE (value))); + + value_set_boxed_internal (value, boxed, FALSE, TRUE); +} diff --git a/gobject/gboxed.h b/gobject/gboxed.h index 7b7e9a51a..c12bd4038 100644 --- a/gobject/gboxed.h +++ b/gobject/gboxed.h @@ -1,5 +1,5 @@ /* GObject - GLib Type, Object, Parameter and Signal Library - * Copyright (C) 2000 Red Hat, Inc. + * Copyright (C) 2000-2001 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -28,12 +28,13 @@ extern "C" { /* --- type macros --- */ -#define G_TYPE_IS_BOXED(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_BOXED) -#define G_IS_VALUE_BOXED(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_BOXED)) +#define G_TYPE_IS_BOXED(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_BOXED) +#define G_VALUE_HOLDS_BOXED(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_BOXED)) /* --- typedefs --- */ typedef struct _GBoxed GBoxed; +typedef gpointer (*GBoxedInitFunc) (void); typedef gpointer (*GBoxedCopyFunc) (gpointer boxed); typedef void (*GBoxedFreeFunc) (gpointer boxed); @@ -43,20 +44,26 @@ GBoxed* g_boxed_copy (GType boxed_type, gconstpointer src_boxed); void g_boxed_free (GType boxed_type, gpointer boxed); -void g_value_set_boxed (GValue *value, - gconstpointer boxed); -void g_value_set_static_boxed (GValue *value, - gconstpointer boxed); -gpointer g_value_get_boxed (const GValue *value); -gpointer g_value_dup_boxed (GValue *value); +void g_value_set_boxed (GValue *value, + gconstpointer boxed); +void g_value_set_static_boxed (GValue *value, + gconstpointer boxed); +gpointer g_value_get_boxed (const GValue *value); +gpointer g_value_dup_boxed (GValue *value); /* --- convenience --- */ -GType g_boxed_type_register_static (const gchar *name, - GBoxedCopyFunc boxed_copy, - GBoxedFreeFunc boxed_free); +GType g_boxed_type_register_static (const gchar *name, + GBoxedInitFunc boxed_init, + GBoxedCopyFunc boxed_copy, + GBoxedFreeFunc boxed_free, + gboolean is_refcounted); +/* --- marshaller specific --- */ +void g_value_set_boxed_take_ownership (GValue *value, + gconstpointer boxed); + #ifdef __cplusplus diff --git a/gobject/gbsearcharray.c b/gobject/gbsearcharray.c index dbba47c9b..9a8dbcf8e 100644 --- a/gobject/gbsearcharray.c +++ b/gobject/gbsearcharray.c @@ -1,5 +1,5 @@ /* GObject - GLib Type, Object, Parameter and Signal Library - * Copyright (C) 2000 Tim Janik + * Copyright (C) 2000-2001 Tim Janik * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -94,7 +94,7 @@ bsearch_array_insert (GBSearchArray *barray, } else barray->nodes = g_realloc (barray->nodes, barray->n_nodes * sizeof_node); - check = (char *) barray->nodes + i * sizeof_node; + check = ((guint8*) barray->nodes) + i * sizeof_node; g_memmove (check + sizeof_node, check, (n_nodes - i) * sizeof_node); replace = TRUE; SKIP_GROW: diff --git a/gobject/gbsearcharray.h b/gobject/gbsearcharray.h index 3b0cf1682..1bc0ab21e 100644 --- a/gobject/gbsearcharray.h +++ b/gobject/gbsearcharray.h @@ -1,5 +1,5 @@ /* GObject - GLib Type, Object, Parameter and Signal Library - * Copyright (C) 2000 Tim Janik + * Copyright (C) 2000-2001 Tim Janik * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -69,6 +69,9 @@ gpointer g_bsearch_array_lookup (GBSearchArray *barray, G_INLINE_FUNC gpointer g_bsearch_array_get_nth (GBSearchArray *barray, guint n); +G_INLINE_FUNC +guint g_bsearch_array_get_index (GBSearchArray *barray, + gpointer node_in_array); /* --- implementation details --- */ @@ -115,14 +118,25 @@ g_bsearch_array_get_nth (GBSearchArray *barray, { if (n < barray->n_nodes) { - guint8 *nodes = (guint8 *) barray->nodes; + guint8 *nodes = (guint8*) barray->nodes; return nodes + n * barray->sizeof_node; } else return NULL; } -#endif /* G_CAN_INLINE && __G_BSEARCHARRAY_C__ */ +G_INLINE_FUNC +guint +g_bsearch_array_get_index (GBSearchArray *barray, + gpointer node_in_array) +{ + guint distance = ((guint8*) node_in_array) - ((guint8*) barray->nodes); + + distance /= barray->sizeof_node; + + return MIN (distance, barray->n_nodes); +} +#endif /* G_CAN_INLINE || __G_BSEARCHARRAY_C__ */ diff --git a/gobject/gclosure.c b/gobject/gclosure.c index 5b386d6b8..3fc3387c1 100644 --- a/gobject/gclosure.c +++ b/gobject/gclosure.c @@ -1,5 +1,5 @@ /* GObject - GLib Type, Object, Parameter and Signal Library - * Copyright (C) 2000 Red Hat, Inc. + * Copyright (C) 2000-2001 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -158,7 +158,7 @@ g_closure_set_meta_marshal (GClosure *closure, g_return_if_fail (meta_marshal != NULL); g_return_if_fail (closure->is_invalid == FALSE); g_return_if_fail (closure->in_marshal == FALSE); - g_return_if_fail (closure->meta_marshal == FALSE); + g_return_if_fail (closure->meta_marshal == 0); n = CLOSURE_N_NOTIFIERS (closure); notifiers = closure->notifiers; @@ -506,7 +506,7 @@ g_type_class_meta_marshal (GClosure *closure, /* GType itype = GPOINTER_TO_UINT (closure->data); */ guint offset = GPOINTER_TO_UINT (marshal_data); - class = G_TYPE_INSTANCE_GET_CLASS (g_value_get_as_pointer (param_values + 0), itype, GTypeClass); + class = G_TYPE_INSTANCE_GET_CLASS (g_value_peek_pointer (param_values + 0), itype, GTypeClass); callback = G_STRUCT_MEMBER (gpointer, class, offset); if (callback) closure->marshal (closure, @@ -529,7 +529,7 @@ g_type_iface_meta_marshal (GClosure *closure, GType itype = GPOINTER_TO_UINT (closure->data); guint offset = GPOINTER_TO_UINT (marshal_data); - class = G_TYPE_INSTANCE_GET_INTERFACE (g_value_get_as_pointer (param_values + 0), itype, GTypeClass); + class = G_TYPE_INSTANCE_GET_INTERFACE (g_value_peek_pointer (param_values + 0), itype, GTypeClass); callback = G_STRUCT_MEMBER (gpointer, class, offset); if (callback) closure->marshal (closure, diff --git a/gobject/gclosure.h b/gobject/gclosure.h index df766413a..8ae329f6b 100644 --- a/gobject/gclosure.h +++ b/gobject/gclosure.h @@ -1,5 +1,5 @@ /* GObject - GLib Type, Object, Parameter and Signal Library - * Copyright (C) 2000 Red Hat, Inc. + * Copyright (C) 2000-2001 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -38,7 +38,7 @@ extern "C" { /* -- typedefs --- */ typedef struct _GClosure GClosure; typedef struct _GClosureNotifyData GClosureNotifyData; -typedef gpointer GCallback; +typedef gpointer GCallback; typedef void (*GClosureNotify) (gpointer data, GClosure *closure); typedef void (*GClosureMarshal) (GClosure *closure, @@ -85,7 +85,7 @@ struct _GClosure * - order of inotifiers is random * inotifiers may _not_ free/invalidate parameter values (e.g. ->data) * - order of fnotifiers is random - * - notifiers may only be removed before or during their invocation + * - each notifier may only be removed before or during its invocation * - reference counting may only happen prior to fnotify invocation * (in that sense, fnotifiers are really finalization handlers) */ diff --git a/gobject/genums.c b/gobject/genums.c index 6a20024fd..e0ecf5c5a 100644 --- a/gobject/genums.c +++ b/gobject/genums.c @@ -1,5 +1,5 @@ /* GObject - GLib Type, Object, Parameter and Signal Library - * Copyright (C) 1998, 1999, 2000 Tim Janik and Red Hat, Inc. + * Copyright (C) 1998-1999, 2000-2001 Tim Janik and Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -85,13 +85,15 @@ g_enum_types_init (void) /* sync with gtype.c */ /* G_TYPE_ENUM */ info.class_size = sizeof (GEnumClass); - type = g_type_register_fundamental (G_TYPE_ENUM, "GEnum", &info, &finfo, G_TYPE_FLAG_ABSTRACT); + type = g_type_register_fundamental (G_TYPE_ENUM, "GEnum", &info, &finfo, + G_TYPE_FLAG_ABSTRACT | G_TYPE_FLAG_VALUE_ABSTRACT); g_assert (type == G_TYPE_ENUM); /* G_TYPE_FLAGS */ info.class_size = sizeof (GFlagsClass); - type = g_type_register_fundamental (G_TYPE_FLAGS, "GFlags", &info, &finfo, G_TYPE_FLAG_ABSTRACT); + type = g_type_register_fundamental (G_TYPE_FLAGS, "GFlags", &info, &finfo, + G_TYPE_FLAG_ABSTRACT | G_TYPE_FLAG_VALUE_ABSTRACT); g_assert (type == G_TYPE_FLAGS); } @@ -378,7 +380,7 @@ g_flags_get_first_value (GFlagsClass *flags_class, GFlagsValue *flags_value; for (flags_value = flags_class->values; flags_value->value_name; flags_value++) - if ((flags_value->value & value) > 0) + if ((flags_value->value & value) == flags_value->value) return flags_value; } @@ -389,7 +391,7 @@ void g_value_set_enum (GValue *value, gint v_enum) { - g_return_if_fail (G_IS_VALUE_ENUM (value)); + g_return_if_fail (G_VALUE_HOLDS_ENUM (value)); value->data[0].v_long = v_enum; } @@ -397,7 +399,7 @@ g_value_set_enum (GValue *value, gint g_value_get_enum (const GValue *value) { - g_return_val_if_fail (G_IS_VALUE_ENUM (value), 0); + g_return_val_if_fail (G_VALUE_HOLDS_ENUM (value), 0); return value->data[0].v_long; } @@ -406,7 +408,7 @@ void g_value_set_flags (GValue *value, guint v_flags) { - g_return_if_fail (G_IS_VALUE_FLAGS (value)); + g_return_if_fail (G_VALUE_HOLDS_FLAGS (value)); value->data[0].v_ulong = v_flags; } @@ -414,7 +416,7 @@ g_value_set_flags (GValue *value, guint g_value_get_flags (const GValue *value) { - g_return_val_if_fail (G_IS_VALUE_FLAGS (value), 0); + g_return_val_if_fail (G_VALUE_HOLDS_FLAGS (value), 0); return value->data[0].v_ulong; } diff --git a/gobject/genums.h b/gobject/genums.h index d2d4ff052..bd1ea6ef6 100644 --- a/gobject/genums.h +++ b/gobject/genums.h @@ -1,5 +1,5 @@ /* GObject - GLib Type, Object, Parameter and Signal Library - * Copyright (C) 1998, 1999, 2000 Tim Janik and Red Hat, Inc. + * Copyright (C) 1998-1999, 2000-2001 Tim Janik and Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -38,8 +38,8 @@ extern "C" { #define G_IS_FLAGS_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_FLAGS)) #define G_FLAGS_CLASS_TYPE(class) (G_TYPE_FROM_CLASS (class)) #define G_FLAGS_CLASS_TYPE_NAME(class) (g_type_name (G_FLAGS_TYPE (class))) -#define G_IS_VALUE_ENUM(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_ENUM)) -#define G_IS_VALUE_FLAGS(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_FLAGS)) +#define G_VALUE_HOLDS_ENUM(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_ENUM)) +#define G_VALUE_HOLDS_FLAGS(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_FLAGS)) /* --- enum/flag values & classes --- */ diff --git a/gobject/glib-genmarshal.1 b/gobject/glib-genmarshal.1 index 687b02011..c35606a5a 100644 --- a/gobject/glib-genmarshal.1 +++ b/gobject/glib-genmarshal.1 @@ -124,6 +124,7 @@ for boxed (anonymous but reference counted) types (GBoxed*) .TP 12 \fIPARAM for GParamSpec or derived types (GParamSpec*) +.TP 12 \fIPOINTER for anonymous pointer types (gpointer) .TP 12 diff --git a/gobject/glib-genmarshal.c b/gobject/glib-genmarshal.c index f1b4c3b08..5b6b86ba8 100644 --- a/gobject/glib-genmarshal.c +++ b/gobject/glib-genmarshal.c @@ -1,5 +1,5 @@ /* GLIB-GenMarshal - Marshaller generator for GObject library - * Copyright (C) 2000 Red Hat, Inc. + * Copyright (C) 2000-2001 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -48,21 +48,27 @@ char *g_log_domain_gruntime = "GLib-Genmarshal"; /* --- typedefs & structures --- */ -typedef struct _Argument Argument; -typedef struct _Signature Signature; -struct _Argument +typedef struct { - gchar *pname; /* parsed name */ - const gchar *sname; /* signature name */ - const gchar *func; /* functional extension */ - const gchar *cname; /* C name */ -}; -struct _Signature + gchar *keyword; /* marhaller list keyword [MY_STRING] */ + const gchar *sig_name; /* signature name [STRING] */ + const gchar *ctype; /* C type name [gchar*] */ + const gchar *getter; /* value getter function [g_value_get_string] */ +} InArgument; +typedef struct { - gchar *ploc; - Argument *rarg; - GList *args; /* of type Argument* */ -}; + gchar *keyword; /* marhaller list keyword [MY_STRING] */ + const gchar *sig_name; /* signature name [STRING] */ + const gchar *ctype; /* C type name [gchar*] */ + const gchar *setter; /* value setter function [g_value_set_string] */ + const gchar *release; /* value release function [g_free] */ +} OutArgument; +typedef struct +{ + gchar *ploc; + OutArgument *rarg; + GList *args; /* of type InArgument* */ +} Signature; /* --- prototypes --- */ @@ -125,72 +131,89 @@ static gboolean std_includes = TRUE; /* --- functions --- */ static gboolean -complete_arg (Argument *arg, - gboolean is_return) +complete_in_arg (InArgument *iarg) { - static const Argument inout_arguments[] = { - /* pname, sname, func, cname */ - { "VOID", "VOID", NULL, "void", }, - { "BOOLEAN", "BOOLEAN", "boolean", "gboolean", }, - { "CHAR", "CHAR", "char", "gchar", }, - { "UCHAR", "UCHAR", "uchar", "guchar", }, - { "INT", "INT", "int", "gint", }, - { "UINT", "UINT", "uint", "guint", }, - { "LONG", "LONG", "long", "glong", }, - { "ULONG", "ULONG", "ulong", "gulong", }, - { "ENUM", "ENUM", "enum", "gint", }, - { "FLAGS", "FLAGS", "flags", "guint", }, - { "FLOAT", "FLOAT", "float", "gfloat", }, - { "DOUBLE", "DOUBLE", "double", "gdouble", }, + static const InArgument args[] = { + /* keyword sig_name ctype getter */ + { "VOID", "VOID", "void", NULL, }, + { "BOOLEAN", "BOOLEAN", "gboolean", "g_value_get_boolean", }, + { "CHAR", "CHAR", "gchar", "g_value_get_char", }, + { "UCHAR", "UCHAR", "guchar", "g_value_get_uchar", }, + { "INT", "INT", "gint", "g_value_get_int", }, + { "UINT", "UINT", "guint", "g_value_get_uint", }, + { "LONG", "LONG", "glong", "g_value_get_long", }, + { "ULONG", "ULONG", "gulong", "g_value_get_ulong", }, + { "ENUM", "ENUM", "gint", "g_value_get_enum", }, + { "FLAGS", "FLAGS", "guint", "g_value_get_flags", }, + { "FLOAT", "FLOAT", "gfloat", "g_value_get_float", }, + { "DOUBLE", "DOUBLE", "gdouble", "g_value_get_double", }, + { "STRING", "STRING", "gpointer", "(char*) g_value_get_string", }, + { "PARAM", "PARAM", "gpointer", "g_value_get_param", }, + { "BOXED", "BOXED", "gpointer", "g_value_get_boxed", }, + { "POINTER", "POINTER", "gpointer", "g_value_get_pointer", }, + { "OBJECT", "OBJECT", "gpointer", "g_value_get_object", }, /* deprecated: */ - { "NONE", "VOID", NULL, "void", }, - { "BOOL", "BOOLEAN", "boolean", "gboolean", }, + { "NONE", "VOID", "void", NULL, }, + { "BOOL", "BOOLEAN", "gboolean", "g_value_get_boolean", }, }; - static const Argument in_arguments[] = { - { "STRING", "POINTER", "as_pointer", "gpointer", }, - { "BOXED", "POINTER", "as_pointer", "gpointer", }, - { "POINTER", "POINTER", "as_pointer", "gpointer", }, - { "PARAM", "POINTER", "as_pointer", "gpointer", }, - { "OBJECT", "POINTER", "as_pointer", "gpointer", }, - }; - static const Argument out_arguments[] = { - { "STRING", "STRING", "string", "gchar*", }, - { "BOXED", "BOXED", "boxed", "gpointer", }, - { "POINTER", "POINTER", "pointer", "gpointer", }, - { "PARAM", "PARAM", "param", "GParamSpec*", }, - { "OBJECT", "OBJECT", "object", "GObject*", }, - }; - const guint n_inout_arguments = sizeof (inout_arguments) / sizeof (inout_arguments[0]); - const guint n_out_arguments = sizeof (out_arguments) / sizeof (out_arguments[0]); - const guint n_in_arguments = sizeof (in_arguments) / sizeof (in_arguments[0]); - const Argument *arguments; - guint i, n_arguments; + const guint n_args = sizeof (args) / sizeof (args[0]); + guint i; - g_return_val_if_fail (arg != NULL, FALSE); + g_return_val_if_fail (iarg != NULL, FALSE); - arguments = inout_arguments; - n_arguments = n_inout_arguments; - for (i = 0; i < n_arguments; i++) - if (strcmp (arguments[i].pname, arg->pname) == 0) + for (i = 0; i < n_args; i++) + if (strcmp (args[i].keyword, iarg->keyword) == 0) { - arg->sname = arguments[i].sname; - arg->func = arguments[i].func; - arg->cname = arguments[i].cname; + iarg->sig_name = args[i].sig_name; + iarg->ctype = args[i].ctype; + iarg->getter = args[i].getter; return TRUE; } - arguments = is_return ? out_arguments : in_arguments; - n_arguments = is_return ? n_out_arguments : n_in_arguments; - for (i = 0; i < n_arguments; i++) - if (strcmp (arguments[i].pname, arg->pname) == 0) + return FALSE; +} + +static gboolean +complete_out_arg (OutArgument *oarg) +{ + static const OutArgument args[] = { + /* keyword sig_name ctype setter release */ + { "VOID", "VOID", "void", NULL, NULL, }, + { "BOOLEAN", "BOOLEAN", "gboolean", "g_value_set_boolean", NULL, }, + { "CHAR", "CHAR", "gchar", "g_value_set_char", NULL, }, + { "UCHAR", "UCHAR", "guchar", "g_value_set_uchar", NULL, }, + { "INT", "INT", "gint", "g_value_set_int", NULL, }, + { "UINT", "UINT", "guint", "g_value_set_uint", NULL, }, + { "LONG", "LONG", "glong", "g_value_set_long", NULL, }, + { "ULONG", "ULONG", "gulong", "g_value_set_ulong", NULL, }, + { "ENUM", "ENUM", "gint", "g_value_set_enum", NULL, }, + { "FLAGS", "FLAGS", "guint", "g_value_set_flags", NULL, }, + { "FLOAT", "FLOAT", "gfloat", "g_value_set_float", NULL, }, + { "DOUBLE", "DOUBLE", "gdouble", "g_value_set_double", NULL, }, + { "STRING", "STRING", "gchar*", "g_value_set_string_take_ownership", NULL, }, + { "PARAM", "PARAM", "GParamSpec*", "g_value_set_param", "g_param_spec_unref", }, + { "BOXED", "BOXED", "gpointer", "g_value_set_boxed_take_ownership", NULL, }, + { "POINTER", "POINTER", "gpointer", "g_value_set_pointer", NULL, }, + { "OBJECT", "OBJECT", "GObject*", "g_value_set_object", "g_object_unref", }, + /* deprecated: */ + { "NONE", "VOID", "void", NULL, NULL, }, + { "BOOL", "BOOLEAN", "gboolean", "g_value_set_boolean", NULL, }, + }; + const guint n_args = sizeof (args) / sizeof (args[0]); + guint i; + + g_return_val_if_fail (oarg != NULL, FALSE); + + for (i = 0; i < n_args; i++) + if (strcmp (args[i].keyword, oarg->keyword) == 0) { - arg->sname = arguments[i].sname; - arg->func = arguments[i].func; - arg->cname = arguments[i].cname; + oarg->sig_name = args[i].sig_name; + oarg->ctype = args[i].ctype; + oarg->setter = args[i].setter; + oarg->release = args[i].release; return TRUE; } - return FALSE; } @@ -230,7 +253,7 @@ pad (const gchar *string) static const gchar* indent (guint n_spaces) { - static gchar *buffer; + static gchar *buffer = NULL; static guint blength = 0; if (blength <= n_spaces) @@ -307,38 +330,38 @@ generate_marshal (const gchar *signame, fprintf (fout, "%sgpointer marshal_data)\n", indent (ind)); fprintf (fout, "{\n"); - /* cfile GSignalFunc typedef */ - ind = fprintf (fout, " typedef %s (*GSignalFunc_%s) (", sig->rarg->cname, signame); + /* cfile GMarshalFunc typedef */ + ind = fprintf (fout, " typedef %s (*GMarshalFunc_%s) (", sig->rarg->ctype, signame); fprintf (fout, "%s data1,\n", pad ("gpointer")); for (a = 1, node = sig->args; node; node = node->next) { - Argument *arg = node->data; + InArgument *iarg = node->data; - if (arg->func) - fprintf (fout, "%s%s arg_%d,\n", indent (ind), pad (arg->cname), a++); + if (iarg->getter) + fprintf (fout, "%s%s arg_%d,\n", indent (ind), pad (iarg->ctype), a++); } fprintf (fout, "%s%s data2);\n", indent (ind), pad ("gpointer")); /* cfile marshal variables */ - fprintf (fout, " register GSignalFunc_%s callback;\n", signame); + fprintf (fout, " register GMarshalFunc_%s callback;\n", signame); fprintf (fout, " register GCClosure *cc = (GCClosure*) closure;\n"); fprintf (fout, " register gpointer data1, data2;\n"); - if (sig->rarg->func) - fprintf (fout, " %s v_return;\n", sig->rarg->cname); + if (sig->rarg->setter) + fprintf (fout, " %s v_return;\n", sig->rarg->ctype); - if (sig->args || sig->rarg->func) + if (sig->args || sig->rarg->setter) { fprintf (fout, "\n"); - if (sig->rarg->func) + if (sig->rarg->setter) fprintf (fout, " g_return_if_fail (return_value != NULL);\n"); if (sig->args) { for (a = 0, node = sig->args; node; node = node->next) { - Argument *arg = node->data; + InArgument *iarg = node->data; - if (arg->func) + if (iarg->getter) a++; } fprintf (fout, " g_return_if_fail (n_param_values >= %u);\n", 1 + a); @@ -349,31 +372,33 @@ generate_marshal (const gchar *signame, fprintf (fout, "\n"); fprintf (fout, " if (G_CCLOSURE_SWAP_DATA (closure))\n {\n"); fprintf (fout, " data1 = closure->data;\n"); - fprintf (fout, " data2 = g_value_get_as_pointer (param_values + 0);\n"); + fprintf (fout, " data2 = g_value_peek_pointer (param_values + 0);\n"); fprintf (fout, " }\n else\n {\n"); - fprintf (fout, " data1 = g_value_get_as_pointer (param_values + 0);\n"); + fprintf (fout, " data1 = g_value_peek_pointer (param_values + 0);\n"); fprintf (fout, " data2 = closure->data;\n"); fprintf (fout, " }\n"); - fprintf (fout, " callback = (GSignalFunc_%s) (marshal_data ? marshal_data : cc->callback);\n", signame); + fprintf (fout, " callback = (GMarshalFunc_%s) (marshal_data ? marshal_data : cc->callback);\n", signame); /* cfile marshal callback action */ fprintf (fout, "\n"); - ind = fprintf (fout, " %s callback (", sig->rarg->func ? " v_return =" : ""); + ind = fprintf (fout, " %s callback (", sig->rarg->setter ? " v_return =" : ""); fprintf (fout, "data1,\n"); for (a = 1, node = sig->args; node; node = node->next) { - Argument *arg = node->data; + InArgument *iarg = node->data; - if (arg->func) - fprintf (fout, "%sg_value_get_%s (param_values + %d),\n", indent (ind), arg->func, a++); + if (iarg->getter) + fprintf (fout, "%s%s (param_values + %d),\n", indent (ind), iarg->getter, a++); } fprintf (fout, "%sdata2);\n", indent (ind)); /* cfile marshal return value storage */ - if (sig->rarg->func) + if (sig->rarg->setter) { fprintf (fout, "\n"); - fprintf (fout, " g_value_set_%s (return_value, v_return);\n", sig->rarg->func); + fprintf (fout, " %s (return_value, v_return);\n", sig->rarg->setter); + if (sig->rarg->release) + fprintf (fout, " %s (v_return);\n", sig->rarg->release); } /* cfile marshal footer */ @@ -388,45 +413,45 @@ process_signature (Signature *sig) GList *node; /* lookup and complete info on arguments */ - if (!complete_arg (sig->rarg, TRUE)) + if (!complete_out_arg (sig->rarg)) { - g_warning ("unknown type: %s", sig->rarg->pname); + g_warning ("unknown type: %s", sig->rarg->keyword); return; } for (node = sig->args; node; node = node->next) { - Argument *arg = node->data; + InArgument *iarg = node->data; - if (!complete_arg (arg, FALSE)) + if (!complete_in_arg (iarg)) { - g_warning ("unknown type: %s", arg->pname); + g_warning ("unknown type: %s", iarg->keyword); return; } } /* construct requested marshaller name and technical marshaller name */ - pname = g_strconcat (sig->rarg->pname, "_", NULL); - sname = g_strconcat (sig->rarg->sname, "_", NULL); + pname = g_strconcat (sig->rarg->keyword, "_", NULL); + sname = g_strconcat (sig->rarg->sig_name, "_", NULL); for (node = sig->args; node; node = node->next) { - Argument *arg = node->data; + InArgument *iarg = node->data; gchar *tmp; tmp = sname; - sname = g_strconcat (tmp, "_", arg->sname, NULL); + sname = g_strconcat (tmp, "_", iarg->sig_name, NULL); g_free (tmp); tmp = pname; - pname = g_strconcat (tmp, "_", arg->pname, NULL); + pname = g_strconcat (tmp, "_", iarg->keyword, NULL); g_free (tmp); } /* introductionary comment */ - fprintf (fout, "\n/* %s", sig->rarg->pname); + fprintf (fout, "\n/* %s", sig->rarg->keyword); for (node = sig->args; node; node = node->next) { - Argument *arg = node->data; + InArgument *iarg = node->data; - fprintf (fout, "%c%s", node->prev ? ',' : ':', arg->pname); + fprintf (fout, "%c%s", node->prev ? ',' : ':', iarg->keyword); } if (!skip_ploc) fprintf (fout, " (%s)", sig->ploc); @@ -450,14 +475,24 @@ process_signature (Signature *sig) g_free (sname); } -static Argument* -new_arg (const gchar *pname) +static InArgument* +new_in_arg (const gchar *pname) { - Argument *arg = g_new0 (Argument, 1); + InArgument *iarg = g_new0 (InArgument, 1); - arg->pname = g_strdup (pname); + iarg->keyword = g_strdup (pname); - return arg; + return iarg; +} + +static OutArgument* +new_out_arg (const gchar *pname) +{ + OutArgument *oarg = g_new0 (OutArgument, 1); + + oarg->keyword = g_strdup (pname); + + return oarg; } static guint @@ -467,7 +502,7 @@ parse_line (GScanner *scanner, /* parse identifier for return value */ if (g_scanner_get_next_token (scanner) != G_TOKEN_IDENTIFIER) return G_TOKEN_IDENTIFIER; - sig->rarg = new_arg (scanner->value.v_identifier); + sig->rarg = new_out_arg (scanner->value.v_identifier); /* keep a note on the location */ sig->ploc = g_strdup_printf ("%s:%u", scanner->input_name, scanner->line); @@ -479,7 +514,7 @@ parse_line (GScanner *scanner, /* parse first argument */ if (g_scanner_get_next_token (scanner) != G_TOKEN_IDENTIFIER) return G_TOKEN_IDENTIFIER; - sig->args = g_list_append (sig->args, new_arg (scanner->value.v_identifier)); + sig->args = g_list_append (sig->args, new_in_arg (scanner->value.v_identifier)); /* parse rest of argument list */ while (g_scanner_peek_next_token (scanner) == ',') @@ -490,7 +525,7 @@ parse_line (GScanner *scanner, /* parse arg identifier */ if (g_scanner_get_next_token (scanner) != G_TOKEN_IDENTIFIER) return G_TOKEN_IDENTIFIER; - sig->args = g_list_append (sig->args, new_arg (scanner->value.v_identifier)); + sig->args = g_list_append (sig->args, new_in_arg (scanner->value.v_identifier)); } /* expect end of line, done */ @@ -605,14 +640,14 @@ main (int argc, /* clean up signature contents */ g_free (signature.ploc); if (signature.rarg) - g_free (signature.rarg->pname); + g_free (signature.rarg->keyword); g_free (signature.rarg); for (node = signature.args; node; node = node->next) { - Argument *arg = node->data; + InArgument *iarg = node->data; - g_free (arg->pname); - g_free (arg); + g_free (iarg->keyword); + g_free (iarg); } g_list_free (signature.args); } diff --git a/gobject/gmarshal.list b/gobject/gmarshal.list index cec63a828..835fe8598 100644 --- a/gobject/gmarshal.list +++ b/gobject/gmarshal.list @@ -15,18 +15,31 @@ # FLOAT for single-precision float types (gfloat) # DOUBLE for double-precision float types (gdouble) # STRING for string types (gchar*) +# PARAM for GParamSpec or derived types (GParamSpec*) # BOXED for boxed (anonymous but reference counted) types (GBoxed*) # POINTER for anonymous pointer types (gpointer) -# PARAM for GParamSpec or derived types (GParamSpec*) # OBJECT for GObject or derived types (GObject*) # NONE deprecated alias for VOID # BOOL deprecated alias for BOOLEAN +# standard VOID return marshallers VOID:VOID -VOID:UINT,POINTER -VOID:PARAM +VOID:BOOLEAN +VOID:CHAR +VOID:UCHAR VOID:INT -VOID:OBJECT -VOID:POINTER -VOID:STRING VOID:UINT +VOID:LONG +VOID:ULONG +VOID:ENUM +VOID:FLAGS +VOID:FLOAT +VOID:DOUBLE +VOID:STRING +VOID:PARAM +VOID:BOXED +VOID:POINTER +VOID:OBJECT + +# GRuntime specific marshallers +VOID:UINT,POINTER diff --git a/gobject/gobject-query.c b/gobject/gobject-query.c index 37f87980c..fd5746bb2 100644 --- a/gobject/gobject-query.c +++ b/gobject/gobject-query.c @@ -1,5 +1,5 @@ /* GObject - GLib Type, Object, Parameter and Signal Library - * Copyright (C) 1998, 1999, 2000 Tim Janik and Red Hat, Inc. + * Copyright (C) 1998-1999, 2000-2001 Tim Janik and Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -119,16 +119,21 @@ int main (gint argc, gchar *argv[]) { + GLogLevelFlags fatal_mask; gboolean gen_froots = 0; gboolean gen_tree = 0; guint i; gchar *iindent = ""; - + f_out = stdout; - g_type_init (0); + fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK); + fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL; + g_log_set_always_fatal (fatal_mask); root = G_TYPE_OBJECT; + + g_type_init (0); for (i = 1; i < argc; i++) { @@ -194,6 +199,7 @@ main (gint argc, else return help (argv[i]); } + if (!gen_froots && !gen_tree) return help (argv[i-1]); diff --git a/gobject/gobject.c b/gobject/gobject.c index a4aed1f65..690fe6b7c 100644 --- a/gobject/gobject.c +++ b/gobject/gobject.c @@ -1,5 +1,5 @@ /* GObject - GLib Type, Object, Parameter and Signal Library - * Copyright (C) 1998, 1999, 2000 Tim Janik and Red Hat, Inc. + * Copyright (C) 1998-1999, 2000-2001 Tim Janik and Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -48,12 +48,7 @@ enum { /* --- properties --- */ enum { - PROP_NONE, - PROP_DATA, - PROP_SIGNAL, - PROP_SWAPPED_SIGNAL, - PROP_SIGNAL_AFTER, - PROP_SWAPPED_SIGNAL_AFTER + PROP_NONE }; @@ -75,17 +70,17 @@ static void g_object_finalize (GObject *object); static void g_object_do_set_property (GObject *object, guint property_id, const GValue *value, - GParamSpec *pspec, - const gchar *trailer); + GParamSpec *pspec); static void g_object_do_get_property (GObject *object, guint property_id, GValue *value, - GParamSpec *pspec, - const gchar *trailer); + GParamSpec *pspec); static void g_value_object_init (GValue *value); static void g_value_object_free_value (GValue *value); static void g_value_object_copy_value (const GValue *src_value, GValue *dest_value); +static void g_value_object_transform_value (const GValue *src_value, + GValue *dest_value); static gpointer g_value_object_peek_pointer (const GValue *value); static gchar* g_value_object_collect_value (GValue *value, guint n_collect_values, @@ -110,13 +105,11 @@ static inline void object_queue_property (GObject *object, static inline void object_thaw_notifies (GObject *object, NotifyQueue *nqueue); static inline void object_get_property (GObject *object, - GValue *value, GParamSpec *pspec, - const gchar *trailer); + GValue *value); static inline void object_set_property (GObject *object, - GValue *value, GParamSpec *pspec, - const gchar *trailer, + const GValue *value, NotifyQueue *nqueue); @@ -211,6 +204,7 @@ g_object_type_init (void) /* sync with gtype.c */ info.value_table = &value_table; type = g_type_register_fundamental (G_TYPE_OBJECT, "GObject", &info, &finfo, 0); g_assert (type == G_TYPE_OBJECT); + g_value_register_transform_func (G_TYPE_OBJECT, G_TYPE_OBJECT, g_value_object_transform_value); #ifdef G_ENABLE_DEBUG IF_DEBUG (OBJECTS) @@ -272,35 +266,6 @@ g_object_do_class_init (GObjectClass *class) class->properties_changed = g_object_properties_changed; class->notify = g_object_notify_property_changed; - g_object_class_install_property (class, - PROP_DATA, - g_param_spec_pointer ("data", "Named Data", - "Named anonymous pointers", - G_PARAM_READABLE | G_PARAM_WRITABLE)); - g_object_class_install_property (class, - PROP_SIGNAL, - g_param_spec_ccallback ("signal", "Signal Connection", - "Signal connection consisting of a callback function " - "and a data pointer", - G_PARAM_WRITABLE)); - g_object_class_install_property (class, - PROP_SWAPPED_SIGNAL, - g_param_spec_ccallback ("swapped_signal", "Swapped Signal Connection", - "Signal connection consisting of a callback function " - "and a data pointer", - G_PARAM_WRITABLE)); - g_object_class_install_property (class, - PROP_SIGNAL_AFTER, - g_param_spec_ccallback ("signal_after", "Signal After Connection", - "Signal connection consisting of a callback function " - "and a data pointer", - G_PARAM_WRITABLE)); - g_object_class_install_property (class, - PROP_SWAPPED_SIGNAL_AFTER, - g_param_spec_ccallback ("swapped_signal_after", "Swapped Signal After Connection", - "Signal connection consisting of a callback function " - "and a data pointer", - G_PARAM_WRITABLE)); gobject_signals[PROPERTIES_CHANGED] = g_signal_newc ("properties_changed", G_TYPE_FROM_CLASS (class), @@ -353,7 +318,7 @@ g_object_class_install_property (GObjectClass *class, pspec->name); return; } - if (g_param_spec_pool_lookup (pspec_pool, pspec->name, G_OBJECT_CLASS_TYPE (class), FALSE, NULL)) + if (g_param_spec_pool_lookup (pspec_pool, pspec->name, G_OBJECT_CLASS_TYPE (class), FALSE)) { g_warning (G_STRLOC ": class `%s' already contains a property named `%s'", G_OBJECT_CLASS_NAME (class), @@ -374,7 +339,7 @@ g_object_class_install_property (GObjectClass *class, /* for property overrides of construct poperties, we have to get rid * of the overidden inherited construct property */ - pspec = g_param_spec_pool_lookup (pspec_pool, pspec->name, g_type_parent (G_OBJECT_CLASS_TYPE (class)), TRUE, NULL); + pspec = g_param_spec_pool_lookup (pspec_pool, pspec->name, g_type_parent (G_OBJECT_CLASS_TYPE (class)), TRUE); if (pspec && pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY)) class->construct_properties = g_slist_remove (class->construct_properties, pspec); } @@ -389,7 +354,7 @@ g_object_class_find_property (GObjectClass *class, return g_param_spec_pool_lookup (pspec_pool, property_name, G_OBJECT_CLASS_TYPE (class), - TRUE, NULL); + TRUE); } static void @@ -453,36 +418,10 @@ static void g_object_do_set_property (GObject *object, guint property_id, const GValue *value, - GParamSpec *pspec, - const gchar *trailer) + GParamSpec *pspec) { - guint i = 0; - switch (property_id) { - gboolean swapped, after; - gpointer callback, data; - case PROP_DATA: - g_return_if_fail (trailer != NULL); - - g_object_set_data (object, trailer, g_value_get_pointer (value)); - break; - case PROP_SWAPPED_SIGNAL_AFTER: - i++; - case PROP_SIGNAL_AFTER: - i++; - case PROP_SWAPPED_SIGNAL: - i++; - case PROP_SIGNAL: - after = i > 2; - swapped = i & 1; - g_return_if_fail (trailer != NULL); - - g_value_get_ccallback (value, &callback, &data); - g_signal_connect_data (object, trailer, - callback, data, NULL, - swapped, after); - break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -493,16 +432,10 @@ static void g_object_do_get_property (GObject *object, guint property_id, GValue *value, - GParamSpec *pspec, - const gchar *trailer) + GParamSpec *pspec) { switch (property_id) { - case PROP_DATA: - g_return_if_fail (trailer != NULL); - - g_value_set_pointer (value, g_object_get_data (object, trailer)); - break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -526,6 +459,8 @@ g_object_last_unref (GObject *object) if (object->ref_count == 0) /* may have been re-referenced meanwhile */ { + g_signal_handlers_destroy (object); + g_object_set_qdata (object, quark_closure_array, NULL); G_OBJECT_GET_CLASS (object)->finalize (object); #ifdef G_ENABLE_DEBUG IF_DEBUG (OBJECTS) @@ -659,7 +594,7 @@ g_object_notify (GObject *object, pspec = g_param_spec_pool_lookup (pspec_pool, property_name, G_OBJECT_TYPE (object), - TRUE, NULL); + TRUE); if (!pspec) g_warning ("%s: object class `%s' has no property named `%s'", G_STRLOC, @@ -696,34 +631,110 @@ g_object_thaw_notify (GObject *object) static inline void object_get_property (GObject *object, - GValue *value, GParamSpec *pspec, - const gchar *trailer) + GValue *value) { GObjectClass *class; - g_return_if_fail (g_type_is_a (G_OBJECT_TYPE (object), pspec->owner_type)); /* paranoid */ - class = g_type_class_peek (pspec->owner_type); - class->get_property (object, PARAM_SPEC_PARAM_ID (pspec), value, pspec, trailer); + class->get_property (object, PARAM_SPEC_PARAM_ID (pspec), value, pspec); +} + +static gchar* +g_strdup_value_contents (const GValue *value) +{ + const gchar *src; + gchar *contents; + + g_return_val_if_fail (G_IS_VALUE (value), NULL); + + if (G_VALUE_HOLDS_STRING (value)) + { + src = g_value_get_string (value); + + if (!src) + contents = g_strdup ("NULL"); + else + { + gchar *s = g_strescape (src, NULL); + + contents = g_strdup_printf ("\"%s\"", s); + g_free (s); + } + } + else if (g_value_type_transformable (G_VALUE_TYPE (value), G_TYPE_STRING)) + { + GValue tmp_value = { 0, }; + + g_value_init (&tmp_value, G_TYPE_STRING); + g_value_transform (value, &tmp_value); + if (G_VALUE_HOLDS_ENUM (value) || G_VALUE_HOLDS_FLAGS (value)) + contents = g_strdup_printf ("((%s) %s)", + g_type_name (G_VALUE_TYPE (value)), + g_value_get_string (&tmp_value)); + else + { + src = g_value_get_string (&tmp_value); + contents = g_strdup (src ? src : "NULL"); + } + g_value_unset (&tmp_value); + } + else if (g_value_fits_pointer (value)) + { + gpointer p = g_value_peek_pointer (value); + + if (!p) + contents = g_strdup ("NULL"); + else if (G_VALUE_HOLDS_OBJECT (value)) + contents = g_strdup_printf ("((%s*) %p)", G_OBJECT_TYPE_NAME (p), p); + else if (G_VALUE_HOLDS_PARAM (value)) + contents = g_strdup_printf ("((%s*) %p)", G_PARAM_SPEC_TYPE_NAME (p), p); + else if (G_VALUE_HOLDS_BOXED (value)) + contents = g_strdup_printf ("((%s*) %p)", g_type_name (G_VALUE_TYPE (value)), p); + else if (G_VALUE_HOLDS_POINTER (value)) + contents = g_strdup_printf ("((gpointer) %p)", p); + else + contents = g_strdup ("???"); + } + else + contents = g_strdup ("???"); + return contents; } static inline void -object_set_property (GObject *object, - GValue *value, - GParamSpec *pspec, - const gchar *trailer, - NotifyQueue *nqueue) +object_set_property (GObject *object, + GParamSpec *pspec, + const GValue *value, + NotifyQueue *nqueue) { - GObjectClass *class; - - g_return_if_fail (g_type_is_a (G_OBJECT_TYPE (object), pspec->owner_type)); /* paranoid */ - - class = g_type_class_peek (pspec->owner_type); - - class->set_property (object, PARAM_SPEC_PARAM_ID (pspec), value, pspec, trailer); - object_queue_property (object, pspec, nqueue); + GValue tmp_value = { 0, }; + GObjectClass *class = g_type_class_peek (pspec->owner_type); + + /* provide a copy to work from, convert (if necessary) and validate */ + g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec)); + if (!g_value_transform (value, &tmp_value)) + g_warning ("unable to set property `%s' of type `%s' from value of type `%s'", + pspec->name, + g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)), + G_VALUE_TYPE_NAME (value)); + else if (g_param_value_validate (pspec, &tmp_value) && !(pspec->flags & G_PARAM_LAX_VALIDATION)) + { + gchar *contents = g_strdup_value_contents (value); + + g_warning ("value <%s> of type `%s' is invalid for property `%s' of type `%s'", + contents, + G_VALUE_TYPE_NAME (value), + pspec->name, + g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec))); + g_free (contents); + } + else + { + class->set_property (object, PARAM_SPEC_PARAM_ID (pspec), &tmp_value, pspec); + object_queue_property (object, pspec, nqueue); + } + g_value_unset (&tmp_value); } gpointer @@ -765,7 +776,6 @@ g_object_new_valist (GType object_type, name = first_property_name; while (name) { - const gchar *trailer = NULL; GValue *value; GParamSpec *pspec; gchar *error = NULL; @@ -773,8 +783,7 @@ g_object_new_valist (GType object_type, pspec = g_param_spec_pool_lookup (pspec_pool, name, object_type, - TRUE, - &trailer); + TRUE); if (!pspec) { g_warning ("%s: object class `%s' has no property named `%s'", @@ -814,7 +823,6 @@ g_object_new_valist (GType object_type, cparams = g_renew (GObjectConstructParam, cparams, MAX (n_cparams + 1, PREALLOC_CPARAMS)); cparams[n_cparams].pspec = pspec; cparams[n_cparams].value = value; - cparams[n_cparams].trailer = trailer; for (i = 0; i < n_cparams; i++) /* picky, aren't we? ;) */ if (cparams[i].pspec == pspec) g_warning (G_STRLOC ": construct property \"%s\" for object `%s' is being set twice", @@ -828,7 +836,6 @@ g_object_new_valist (GType object_type, nparams = g_renew (GObjectConstructParam, nparams, MAX (n_nparams + 1, PREALLOC_CPARAMS)); nparams[n_nparams].pspec = pspec; nparams[n_nparams].value = value; - nparams[n_nparams].trailer = trailer; n_nparams++; } @@ -850,7 +857,6 @@ g_object_new_valist (GType object_type, cparams = g_renew (GObjectConstructParam, cparams, MAX (n_cparams + 1, PREALLOC_CPARAMS)); cparams[n_cparams].pspec = pspec; cparams[n_cparams].value = value; - cparams[n_cparams].trailer = NULL; n_cparams++; g_slist_free_1 (clist); @@ -876,28 +882,9 @@ g_object_new_valist (GType object_type, { GValue *value = nparams->value; GParamSpec *pspec = nparams->pspec; - const gchar *trailer = nparams++->trailer; - /* convert if necessary */ - if (!g_type_is_a (G_VALUE_TYPE (value), G_PARAM_SPEC_VALUE_TYPE (pspec))) - { - GValue tmp_value = { 0, }; - - g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec)); - if (!g_value_convert (value, &tmp_value) || - g_param_value_validate (pspec, &tmp_value)) - g_warning ("%s: cannot convert `%s' value to property `%s' value of type `%s'", - G_STRLOC, - G_VALUE_TYPE_NAME (value), - pspec->name, - g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec))); - else - object_set_property (object, &tmp_value, pspec, trailer, nqueue); - g_value_unset (&tmp_value); - } - else - object_set_property (object, value, pspec, trailer, nqueue); - + nparams++; + object_set_property (object, pspec, value, nqueue); g_value_unset (value); g_free (value); } @@ -931,27 +918,9 @@ g_object_constructor (GType type, { GValue *value = construct_params->value; GParamSpec *pspec = construct_params->pspec; - const gchar *trailer = construct_params++->trailer; - - /* convert if necessary */ - if (!g_type_is_a (G_VALUE_TYPE (value), G_PARAM_SPEC_VALUE_TYPE (pspec))) - { - GValue tmp_value = { 0, }; - - g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec)); - if (!g_value_convert (value, &tmp_value) || - g_param_value_validate (pspec, &tmp_value)) - g_warning ("%s: cannot convert `%s' value to property `%s' value of type `%s'", - G_STRLOC, - G_VALUE_TYPE_NAME (value), - pspec->name, - g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec))); - else - object_set_property (object, &tmp_value, pspec, trailer, nqueue); - g_value_unset (&tmp_value); - } - else - object_set_property (object, value, pspec, trailer, nqueue); + + construct_params++; + object_set_property (object, pspec, value, nqueue); } nqueue->freeze_count--; /* the notification queue is still frozen from g_object_init(), so @@ -979,7 +948,6 @@ g_object_set_valist (GObject *object, name = first_property_name; while (name) { - const gchar *trailer = NULL; GValue value = { 0, }; GParamSpec *pspec; gchar *error = NULL; @@ -987,8 +955,7 @@ g_object_set_valist (GObject *object, pspec = g_param_spec_pool_lookup (pspec_pool, name, G_OBJECT_TYPE (object), - TRUE, - &trailer); + TRUE); if (!pspec) { g_warning ("%s: object class `%s' has no property named `%s'", @@ -1020,8 +987,7 @@ g_object_set_valist (GObject *object, break; } - object_set_property (object, &value, pspec, trailer, nqueue); - + object_set_property (object, pspec, &value, nqueue); g_value_unset (&value); name = va_arg (var_args, gchar*); @@ -1046,7 +1012,6 @@ g_object_get_valist (GObject *object, while (name) { - const gchar *trailer = NULL; GValue value = { 0, }; GParamSpec *pspec; gchar *error; @@ -1054,8 +1019,7 @@ g_object_get_valist (GObject *object, pspec = g_param_spec_pool_lookup (pspec_pool, name, G_OBJECT_TYPE (object), - TRUE, - &trailer); + TRUE); if (!pspec) { g_warning ("%s: object class `%s' has no property named `%s'", @@ -1075,9 +1039,9 @@ g_object_get_valist (GObject *object, g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec)); - object_get_property (object, &value, pspec, trailer); + object_get_property (object, pspec, &value); - G_VALUE_LCOPY (&value, var_args, 0, &error); + G_VALUE_LCOPY (&value, var_args, G_VALUE_NOCOPY_CONTENTS, &error); if (error) { g_warning ("%s: %s", G_STRLOC, error); @@ -1097,7 +1061,7 @@ g_object_get_valist (GObject *object, g_object_unref (object); } -void +gpointer g_object_set (gpointer _object, const gchar *first_property_name, ...) @@ -1105,11 +1069,13 @@ g_object_set (gpointer _object, GObject *object = _object; va_list var_args; - g_return_if_fail (G_IS_OBJECT (object)); + g_return_val_if_fail (G_IS_OBJECT (object), NULL); va_start (var_args, first_property_name); g_object_set_valist (object, first_property_name, var_args); va_end (var_args); + + return object; } void @@ -1134,7 +1100,6 @@ g_object_set_property (GObject *object, { NotifyQueue *nqueue; GParamSpec *pspec; - const gchar *trailer; g_return_if_fail (G_IS_OBJECT (object)); g_return_if_fail (property_name != NULL); @@ -1146,32 +1111,13 @@ g_object_set_property (GObject *object, pspec = g_param_spec_pool_lookup (pspec_pool, property_name, G_OBJECT_TYPE (object), - TRUE, - &trailer); + TRUE); if (!pspec) - g_warning ("%s: object class `%s' has no property named `%s'", - G_STRLOC, + g_warning ("object class `%s' has no property named `%s'", G_OBJECT_TYPE_NAME (object), property_name); else - { - GValue tmp_value = { 0, }; - - /* provide a copy to work from and convert if necessary */ - g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec)); - - if (!g_value_convert (value, &tmp_value) || - g_param_value_validate (pspec, &tmp_value)) - g_warning ("%s: cannot convert `%s' value to property `%s' value of type `%s'", - G_STRLOC, - G_VALUE_TYPE_NAME (value), - pspec->name, - g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec))); - else - object_set_property (object, &tmp_value, pspec, trailer, nqueue); - - g_value_unset (&tmp_value); - } + object_set_property (object, pspec, value, nqueue); object_thaw_notifies (object, nqueue); g_object_unref (object); @@ -1183,7 +1129,6 @@ g_object_get_property (GObject *object, GValue *value) { GParamSpec *pspec; - const gchar *trailer; g_return_if_fail (G_IS_OBJECT (object)); g_return_if_fail (property_name != NULL); @@ -1194,44 +1139,140 @@ g_object_get_property (GObject *object, pspec = g_param_spec_pool_lookup (pspec_pool, property_name, G_OBJECT_TYPE (object), - TRUE, - &trailer); + TRUE); if (!pspec) - g_warning ("%s: object class `%s' has no property named `%s'", - G_STRLOC, + g_warning ("object class `%s' has no property named `%s'", G_OBJECT_TYPE_NAME (object), property_name); else { - GValue tmp_value = { 0, }; + GValue *prop_value, tmp_value = { 0, }; - /* provide a copy to work from and later convert if necessary, so - * _get_property() implementations need *not* care about freeing values - * that might be already set in the property to get. - * (though, at this point, GValue should exclusively be modified - * through the accessor functions anyways) + /* auto-conversion of the callers value type */ - g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec)); - - if (!g_value_types_exchangable (G_VALUE_TYPE (value), G_PARAM_SPEC_VALUE_TYPE (pspec))) - g_warning ("%s: can't retrive property `%s' value of type `%s' as value of type `%s'", - G_STRLOC, - pspec->name, - g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)), - G_VALUE_TYPE_NAME (value)); + if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec)) + { + g_value_reset (value); + prop_value = value; + } + else if (!g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value))) + { + g_warning ("can't retrive property `%s' of type `%s' as value of type `%s'", + pspec->name, + g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)), + G_VALUE_TYPE_NAME (value)); + return; + } else { - object_get_property (object, &tmp_value, pspec, trailer); - g_value_convert (&tmp_value, value); - /* g_value_validate (value, pspec); */ + g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec)); + prop_value = &tmp_value; + } + object_get_property (object, pspec, prop_value); + if (prop_value != value) + { + g_value_transform (prop_value, value); + g_value_unset (&tmp_value); } - - g_value_unset (&tmp_value); } g_object_unref (object); } +gpointer +g_object_connect (gpointer _object, + const gchar *signal_spec, + ...) +{ + GObject *object = _object; + va_list var_args; + + g_return_val_if_fail (G_IS_OBJECT (object), NULL); + g_return_val_if_fail (object->ref_count > 0, object); + + va_start (var_args, signal_spec); + while (signal_spec) + { + gpointer callback = va_arg (var_args, gpointer); + gpointer data = va_arg (var_args, gpointer); + guint sid; + + if (strncmp (signal_spec, "signal::", 8) == 0) + sid = g_signal_connect_data (object, signal_spec + 8, + callback, data, NULL, + FALSE, FALSE); + else if (strncmp (signal_spec, "swapped_signal::", 16) == 0) + sid = g_signal_connect_data (object, signal_spec + 16, + callback, data, NULL, + TRUE, FALSE); + else if (strncmp (signal_spec, "signal_after::", 14) == 0) + sid = g_signal_connect_data (object, signal_spec + 14, + callback, data, NULL, + FALSE, TRUE); + else if (strncmp (signal_spec, "swapped_signal_after::", 22) == 0) + sid = g_signal_connect_data (object, signal_spec + 22, + callback, data, NULL, + TRUE, TRUE); + else + { + g_warning ("%s: invalid signal spec \"%s\"", G_STRLOC, signal_spec); + break; + } + signal_spec = va_arg (var_args, gchar*); + } + va_end (var_args); + + return object; +} + +gpointer +g_object_disconnect (gpointer _object, + const gchar *signal_spec, + ...) +{ + GObject *object = _object; + va_list var_args; + + g_return_val_if_fail (G_IS_OBJECT (object), NULL); + g_return_val_if_fail (object->ref_count > 0, object); + + va_start (var_args, signal_spec); + while (signal_spec) + { + gpointer callback = va_arg (var_args, gpointer); + gpointer data = va_arg (var_args, gpointer); + guint sid = 0, detail = 0, mask = 0; + + if (strncmp (signal_spec, "any_signal::", 12) == 0) + { + signal_spec += 12; + mask = G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA; + } + else if (strcmp (signal_spec, "any_signal") == 0) + { + signal_spec += 10; + mask = G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA; + } + else + { + g_warning ("%s: invalid signal spec \"%s\"", G_STRLOC, signal_spec); + break; + } + + if ((mask & G_SIGNAL_MATCH_ID) && + !g_signal_parse_name (signal_spec, G_OBJECT_TYPE (object), &sid, &detail, FALSE)) + g_warning ("%s: invalid signal name \"%s\"", G_STRLOC, signal_spec); + else if (!g_signal_handlers_disconnect_matched (object, mask | (detail ? G_SIGNAL_MATCH_DETAIL : 0), + sid, detail, + NULL, callback, data)) + g_warning (G_STRLOC ": signal handler %p(%p) is not connected", callback, data); + signal_spec = va_arg (var_args, gchar*); + } + va_end (var_args); + + return object; +} + gpointer g_object_ref (gpointer _object) { @@ -1385,6 +1426,16 @@ g_value_object_copy_value (const GValue *src_value, dest_value->data[0].v_pointer = NULL; } +static void +g_value_object_transform_value (const GValue *src_value, + GValue *dest_value) +{ + if (src_value->data[0].v_pointer && g_type_is_a (G_OBJECT_TYPE (src_value->data[0].v_pointer), G_VALUE_TYPE (dest_value))) + dest_value->data[0].v_pointer = g_object_ref (src_value->data[0].v_pointer); + else + dest_value->data[0].v_pointer = NULL; +} + static gpointer g_value_object_peek_pointer (const GValue *value) { @@ -1406,13 +1457,14 @@ g_value_object_collect_value (GValue *value, G_VALUE_TYPE_NAME (value), "'", NULL); - else if (!g_type_is_a (G_OBJECT_TYPE (object), G_VALUE_TYPE (value))) + else if (!g_value_type_compatible (G_OBJECT_TYPE (object), G_VALUE_TYPE (value))) return g_strconcat ("invalid object type `", G_OBJECT_TYPE_NAME (object), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL); + /* never honour G_VALUE_NOCOPY_CONTENTS for ref-counted types */ value->data[0].v_pointer = g_object_ref (object); } else @@ -1446,7 +1498,7 @@ void g_value_set_object (GValue *value, GObject *v_object) { - g_return_if_fail (G_IS_VALUE_OBJECT (value)); + g_return_if_fail (G_VALUE_HOLDS_OBJECT (value)); if (value->data[0].v_pointer) { @@ -1457,17 +1509,17 @@ g_value_set_object (GValue *value, if (v_object) { g_return_if_fail (G_IS_OBJECT (v_object)); - g_return_if_fail (g_type_is_a (G_OBJECT_TYPE (v_object), G_VALUE_TYPE (value))); + g_return_if_fail (g_value_type_compatible (G_OBJECT_TYPE (v_object), G_VALUE_TYPE (value))); value->data[0].v_pointer = v_object; g_object_ref (value->data[0].v_pointer); } } -GObject* +gpointer g_value_get_object (const GValue *value) { - g_return_val_if_fail (G_IS_VALUE_OBJECT (value), NULL); + g_return_val_if_fail (G_VALUE_HOLDS_OBJECT (value), NULL); return value->data[0].v_pointer; } @@ -1475,7 +1527,7 @@ g_value_get_object (const GValue *value) GObject* g_value_dup_object (const GValue *value) { - g_return_val_if_fail (G_IS_VALUE_OBJECT (value), NULL); + g_return_val_if_fail (G_VALUE_HOLDS_OBJECT (value), NULL); return value->data[0].v_pointer ? g_object_ref (value->data[0].v_pointer) : NULL; } diff --git a/gobject/gobject.h b/gobject/gobject.h index 603906124..31eb56438 100644 --- a/gobject/gobject.h +++ b/gobject/gobject.h @@ -1,5 +1,5 @@ /* GObject - GLib Type, Object, Parameter and Signal Library - * Copyright (C) 1998, 1999, 2000 Tim Janik and Red Hat, Inc. + * Copyright (C) 1998-1999, 2000-2001 Tim Janik and Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -31,17 +31,17 @@ extern "C" { /* --- type macros --- */ -#define G_TYPE_IS_OBJECT(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_OBJECT) -#define G_OBJECT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), G_TYPE_OBJECT, GObject)) -#define G_OBJECT_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_OBJECT, GObjectClass)) -#define G_IS_OBJECT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), G_TYPE_OBJECT)) -#define G_IS_OBJECT_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_OBJECT)) -#define G_OBJECT_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), G_TYPE_OBJECT, GObjectClass)) -#define G_OBJECT_TYPE(object) (G_TYPE_FROM_INSTANCE (object)) -#define G_OBJECT_TYPE_NAME(object) (g_type_name (G_OBJECT_TYPE (object))) -#define G_OBJECT_CLASS_TYPE(class) (G_TYPE_FROM_CLASS (class)) -#define G_OBJECT_CLASS_NAME(class) (g_type_name (G_OBJECT_CLASS_TYPE (class))) -#define G_IS_VALUE_OBJECT(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_OBJECT)) +#define G_TYPE_IS_OBJECT(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_OBJECT) +#define G_OBJECT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), G_TYPE_OBJECT, GObject)) +#define G_OBJECT_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_OBJECT, GObjectClass)) +#define G_IS_OBJECT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), G_TYPE_OBJECT)) +#define G_IS_OBJECT_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_OBJECT)) +#define G_OBJECT_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), G_TYPE_OBJECT, GObjectClass)) +#define G_OBJECT_TYPE(object) (G_TYPE_FROM_INSTANCE (object)) +#define G_OBJECT_TYPE_NAME(object) (g_type_name (G_OBJECT_TYPE (object))) +#define G_OBJECT_CLASS_TYPE(class) (G_TYPE_FROM_CLASS (class)) +#define G_OBJECT_CLASS_NAME(class) (g_type_name (G_OBJECT_CLASS_TYPE (class))) +#define G_VALUE_HOLDS_OBJECT(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_OBJECT)) /* --- typedefs & structures --- */ @@ -51,13 +51,11 @@ typedef struct _GObjectConstructParam GObjectConstructParam; typedef void (*GObjectGetPropertyFunc) (GObject *object, guint property_id, GValue *value, - GParamSpec *pspec, - const gchar *trailer); + GParamSpec *pspec); typedef void (*GObjectSetPropertyFunc) (GObject *object, guint property_id, const GValue *value, - GParamSpec *pspec, - const gchar *trailer); + GParamSpec *pspec); typedef void (*GObjectFinalizeFunc) (GObject *object); struct _GObject { @@ -83,13 +81,11 @@ struct _GObjectClass void (*set_property) (GObject *object, guint property_id, const GValue *value, - GParamSpec *pspec, - const gchar *trailer); + GParamSpec *pspec); void (*get_property) (GObject *object, guint property_id, GValue *value, - GParamSpec *pspec, - const gchar *trailer); + GParamSpec *pspec); void (*shutdown) (GObject *object); void (*finalize) (GObject *object); @@ -109,7 +105,6 @@ struct _GObjectConstructParam { GParamSpec *pspec; GValue *value; - const gchar *trailer; }; @@ -125,12 +120,18 @@ gpointer g_object_new (GType object_type, gpointer g_object_new_valist (GType object_type, const gchar *first_property_name, va_list var_args); -void g_object_set (gpointer object, +gpointer g_object_set (gpointer object, const gchar *first_property_name, ...); void g_object_get (gpointer object, const gchar *first_property_name, ...); +gpointer g_object_connect (gpointer object, + const gchar *signal_spec, + ...); +gpointer g_object_disconnect (gpointer object, + const gchar *signal_spec, + ...); void g_object_set_valist (GObject *object, const gchar *first_property_name, va_list var_args); @@ -181,7 +182,7 @@ GClosure* g_closure_new_object (guint sizeof_closure, GObject *object); void g_value_set_object (GValue *value, GObject *v_object); -GObject* g_value_get_object (const GValue *value); +gpointer g_value_get_object (const GValue *value); GObject* g_value_dup_object (const GValue *value); guint g_signal_connect_object (gpointer instance, const gchar *detailed_signal, diff --git a/gobject/gparam.c b/gobject/gparam.c index 7ead600ee..5a1dff4a4 100644 --- a/gobject/gparam.c +++ b/gobject/gparam.c @@ -1,5 +1,5 @@ /* GObject - GLib Type, Object, Parameter and Signal Library - * Copyright (C) 1997, 1998, 1999, 2000 Tim Janik and Red Hat, Inc. + * Copyright (C) 1997-1999, 2000-2001 Tim Janik and Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -31,7 +31,7 @@ /* --- defines --- */ #define G_PARAM_SPEC_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_PARAM, GParamSpecClass)) -#define G_PARAM_USER_MASK ((1 << G_PARAM_USER_SHIFT) - 1) +#define G_PARAM_USER_MASK (~0 << G_PARAM_USER_SHIFT) #define PSPEC_APPLIES_TO_VALUE(pspec, value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_PARAM_SPEC_VALUE_TYPE (pspec))) #define G_SLOCK(mutex) g_static_mutex_lock (mutex) #define G_SUNLOCK(mutex) g_static_mutex_unlock (mutex) @@ -49,6 +49,8 @@ static void value_param_init (GValue *value); static void value_param_free_value (GValue *value); static void value_param_copy_value (const GValue *src_value, GValue *dest_value); +static void value_param_transform_value (const GValue *src_value, + GValue *dest_value); static gpointer value_param_peek_pointer (const GValue *value); static gchar* value_param_collect_value (GValue *value, guint n_collect_values, @@ -104,6 +106,7 @@ g_param_type_init (void) /* sync with gtype.c */ type = g_type_register_fundamental (G_TYPE_PARAM, "GParam", ¶m_spec_info, &finfo, G_TYPE_FLAG_ABSTRACT); g_assert (type == G_TYPE_PARAM); + g_value_register_transform_func (G_TYPE_PARAM, G_TYPE_PARAM, value_param_transform_value); } static void @@ -345,6 +348,40 @@ g_param_value_validate (GParamSpec *pspec, return FALSE; } +gboolean +g_param_value_convert (GParamSpec *pspec, + const GValue *src_value, + GValue *dest_value, + gboolean strict_validation) +{ + GValue tmp_value = { 0, }; + + g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE); + g_return_val_if_fail (G_IS_VALUE (src_value), FALSE); + g_return_val_if_fail (G_IS_VALUE (dest_value), FALSE); + g_return_val_if_fail (PSPEC_APPLIES_TO_VALUE (pspec, dest_value), FALSE); + + /* better leave dest_value untouched when returning FALSE */ + + g_value_init (&tmp_value, G_VALUE_TYPE (dest_value)); + if (g_value_transform (src_value, &tmp_value) && + (!g_param_value_validate (pspec, &tmp_value) || !strict_validation)) + { + g_value_unset (dest_value); + + /* values are relocatable */ + memcpy (dest_value, &tmp_value, sizeof (tmp_value)); + + return TRUE; + } + else + { + g_value_unset (&tmp_value); + + return FALSE; + } +} + gint g_param_values_cmp (GParamSpec *pspec, const GValue *value1, @@ -386,9 +423,21 @@ static void value_param_copy_value (const GValue *src_value, GValue *dest_value) { - dest_value->data[0].v_pointer = (src_value->data[0].v_pointer - ? g_param_spec_ref (src_value->data[0].v_pointer) - : NULL); + if (src_value->data[0].v_pointer) + dest_value->data[0].v_pointer = g_param_spec_ref (src_value->data[0].v_pointer); + else + dest_value->data[0].v_pointer = NULL; +} + +static void +value_param_transform_value (const GValue *src_value, + GValue *dest_value) +{ + if (src_value->data[0].v_pointer && + g_type_is_a (G_PARAM_SPEC_TYPE (dest_value->data[0].v_pointer), G_VALUE_TYPE (dest_value))) + dest_value->data[0].v_pointer = g_param_spec_ref (src_value->data[0].v_pointer); + else + dest_value->data[0].v_pointer = NULL; } static gpointer @@ -412,7 +461,7 @@ value_param_collect_value (GValue *value, G_VALUE_TYPE_NAME (value), "'", NULL); - else if (!g_type_is_a (G_PARAM_SPEC_TYPE (param), G_VALUE_TYPE (value))) + else if (!g_value_type_compatible (G_PARAM_SPEC_TYPE (param), G_VALUE_TYPE (value))) return g_strconcat ("invalid param spec type `", G_PARAM_SPEC_TYPE_NAME (param), "' for value type `", @@ -601,8 +650,7 @@ GParamSpec* g_param_spec_pool_lookup (GParamSpecPool *pool, const gchar *param_name, GType owner_type, - gboolean walk_ancestors, - const gchar **trailer_p) + gboolean walk_ancestors) { GParamSpec *pspec; gchar *delim; @@ -615,13 +663,11 @@ g_param_spec_pool_lookup (GParamSpecPool *pool, G_SLOCK (&pool->smutex); - delim = strchr (param_name, ':'); + delim = pool->type_prefixing ? strchr (param_name, ':') : NULL; - /* try quick and away, i.e. no prefix, no trailer */ + /* try quick and away, i.e. without prefix */ if (!delim) { - if (trailer_p) - *trailer_p = NULL; pspec = param_spec_ht_lookup (pool->hash_table, param_name, owner_type, walk_ancestors); G_SUNLOCK (&pool->smutex); @@ -645,48 +691,20 @@ g_param_spec_pool_lookup (GParamSpecPool *pool, /* sanity check, these cases don't make a whole lot of sense */ if ((!walk_ancestors && type != owner_type) || !g_type_is_a (owner_type, type)) { - if (trailer_p) - *trailer_p = NULL; G_SUNLOCK (&pool->smutex); return NULL; } owner_type = type; param_name += l + 2; - delim = strchr (param_name, ':'); - if (!delim) /* good, can still forget about trailer */ - { - if (trailer_p) - *trailer_p = NULL; - pspec = param_spec_ht_lookup (pool->hash_table, param_name, owner_type, walk_ancestors); - G_SUNLOCK (&pool->smutex); + pspec = param_spec_ht_lookup (pool->hash_table, param_name, owner_type, walk_ancestors); + G_SUNLOCK (&pool->smutex); - return pspec; - } + return pspec; } } - - /* ok, no prefix, handle trailer */ - if (delim[1] == ':') - { - guint l = delim - param_name; - gchar stack_buffer[32], *buffer = l < 32 ? stack_buffer : g_new (gchar, l + 1); - - strncpy (buffer, param_name, delim - param_name); - buffer[l] = 0; - pspec = param_spec_ht_lookup (pool->hash_table, buffer, owner_type, walk_ancestors); - if (l >= 32) - g_free (buffer); - if (trailer_p) - *trailer_p = pspec ? delim + 2 : NULL; - G_SUNLOCK (&pool->smutex); - - return pspec; - } - /* malformed param_name */ - if (trailer_p) - *trailer_p = NULL; + G_SUNLOCK (&pool->smutex); return NULL; @@ -784,7 +802,7 @@ void g_value_set_param (GValue *value, GParamSpec *param) { - g_return_if_fail (G_IS_VALUE_PARAM (value)); + g_return_if_fail (G_VALUE_HOLDS_PARAM (value)); if (param) g_return_if_fail (G_IS_PARAM_SPEC (param)); @@ -798,7 +816,7 @@ g_value_set_param (GValue *value, GParamSpec* g_value_get_param (const GValue *value) { - g_return_val_if_fail (G_IS_VALUE_PARAM (value), NULL); + g_return_val_if_fail (G_VALUE_HOLDS_PARAM (value), NULL); return value->data[0].v_pointer; } @@ -806,7 +824,7 @@ g_value_get_param (const GValue *value) GParamSpec* g_value_dup_param (const GValue *value) { - g_return_val_if_fail (G_IS_VALUE_PARAM (value), NULL); + g_return_val_if_fail (G_VALUE_HOLDS_PARAM (value), NULL); return value->data[0].v_pointer ? g_param_spec_ref (value->data[0].v_pointer) : NULL; } diff --git a/gobject/gparam.h b/gobject/gparam.h index 3a27b1ff8..d186ffdf9 100644 --- a/gobject/gparam.h +++ b/gobject/gparam.h @@ -1,5 +1,5 @@ /* GObject - GLib Type, Object, Parameter and Signal Library - * Copyright (C) 1997, 1998, 1999, 2000 Tim Janik and Red Hat, Inc. + * Copyright (C) 1997-1999, 2000-2001 Tim Janik and Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -38,7 +38,7 @@ extern "C" { #define G_IS_PARAM_SPEC(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM)) #define G_PARAM_SPEC_GET_CLASS(pspec) (G_TYPE_INSTANCE_GET_CLASS ((pspec), G_TYPE_PARAM, GParamSpecClass)) #define G_PARAM_SPEC_VALUE_TYPE(pspec) (G_PARAM_SPEC (pspec)->value_type) -#define G_IS_VALUE_PARAM(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_PARAM)) +#define G_VALUE_HOLDS_PARAM(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_PARAM)) /* --- flags --- */ @@ -48,7 +48,8 @@ typedef enum G_PARAM_WRITABLE = 1 << 1, G_PARAM_CONSTRUCT = 1 << 2, G_PARAM_CONSTRUCT_ONLY = 1 << 3, - G_PARAM_PRIVATE = 1 << 4 + G_PARAM_LAX_VALIDATION = 1 << 4, + G_PARAM_PRIVATE = 1 << 5 } GParamFlags; #define G_PARAM_READWRITE (G_PARAM_READABLE | G_PARAM_WRITABLE) #define G_PARAM_MASK (0x000000ff) @@ -115,6 +116,10 @@ gboolean g_param_value_defaults (GParamSpec *pspec, GValue *value); gboolean g_param_value_validate (GParamSpec *pspec, GValue *value); +gboolean g_param_value_convert (GParamSpec *dest_value_spec, + const GValue *src_value, + GValue *dest_value, + gboolean strict_validation); gint g_param_values_cmp (GParamSpec *pspec, const GValue *value1, const GValue *value2); @@ -163,8 +168,7 @@ void g_param_spec_pool_remove (GParamSpecPool *pool, GParamSpec* g_param_spec_pool_lookup (GParamSpecPool *pool, const gchar *param_name, GType owner_type, - gboolean walk_ancestors, - const gchar **trailer_p); + gboolean walk_ancestors); /* contracts: diff --git a/gobject/gparamspecs.c b/gobject/gparamspecs.c index 358041c35..44dca645d 100644 --- a/gobject/gparamspecs.c +++ b/gobject/gparamspecs.c @@ -1,5 +1,5 @@ /* GObject - GLib Type, Object, Parameter and Signal Library - * Copyright (C) 1997, 1998, 1999, 2000 Tim Janik and Red Hat, Inc. + * Copyright (C) 1997-1999, 2000-2001 Tim Janik and Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -24,6 +24,7 @@ #include "gparamspecs.h" #include "gvaluecollector.h" +#include "gvaluearray.h" #include #include "../config.h" /* for SIZEOF_LONG */ @@ -33,7 +34,7 @@ /* --- param spec functions --- */ static void -param_spec_char_init (GParamSpec *pspec) +param_char_init (GParamSpec *pspec) { GParamSpecChar *cspec = G_PARAM_SPEC_CHAR (pspec); @@ -62,7 +63,7 @@ param_char_validate (GParamSpec *pspec, } static void -param_spec_uchar_init (GParamSpec *pspec) +param_uchar_init (GParamSpec *pspec) { GParamSpecUChar *uspec = G_PARAM_SPEC_UCHAR (pspec); @@ -109,7 +110,7 @@ param_boolean_validate (GParamSpec *pspec, } static void -param_spec_int_init (GParamSpec *pspec) +param_int_init (GParamSpec *pspec) { GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec); @@ -149,7 +150,7 @@ param_int_values_cmp (GParamSpec *pspec, } static void -param_spec_uint_init (GParamSpec *pspec) +param_uint_init (GParamSpec *pspec) { GParamSpecUInt *uspec = G_PARAM_SPEC_UINT (pspec); @@ -189,7 +190,7 @@ param_uint_values_cmp (GParamSpec *pspec, } static void -param_spec_long_init (GParamSpec *pspec) +param_long_init (GParamSpec *pspec) { GParamSpecLong *lspec = G_PARAM_SPEC_LONG (pspec); @@ -234,7 +235,7 @@ param_long_values_cmp (GParamSpec *pspec, } static void -param_spec_ulong_init (GParamSpec *pspec) +param_ulong_init (GParamSpec *pspec) { GParamSpecULong *uspec = G_PARAM_SPEC_ULONG (pspec); @@ -278,7 +279,7 @@ param_ulong_values_cmp (GParamSpec *pspec, } static void -param_spec_enum_init (GParamSpec *pspec) +param_enum_init (GParamSpec *pspec) { GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec); @@ -287,7 +288,7 @@ param_spec_enum_init (GParamSpec *pspec) } static void -param_spec_enum_finalize (GParamSpec *pspec) +param_enum_finalize (GParamSpec *pspec) { GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec); GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_ENUM)); @@ -323,7 +324,7 @@ param_enum_validate (GParamSpec *pspec, } static void -param_spec_flags_init (GParamSpec *pspec) +param_flags_init (GParamSpec *pspec) { GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec); @@ -332,7 +333,7 @@ param_spec_flags_init (GParamSpec *pspec) } static void -param_spec_flags_finalize (GParamSpec *pspec) +param_flags_finalize (GParamSpec *pspec) { GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec); GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_FLAGS)); @@ -369,7 +370,7 @@ param_flags_validate (GParamSpec *pspec, } static void -param_spec_float_init (GParamSpec *pspec) +param_float_init (GParamSpec *pspec) { GParamSpecFloat *fspec = G_PARAM_SPEC_FLOAT (pspec); @@ -412,7 +413,7 @@ param_float_values_cmp (GParamSpec *pspec, } static void -param_spec_double_init (GParamSpec *pspec) +param_double_init (GParamSpec *pspec) { GParamSpecDouble *dspec = G_PARAM_SPEC_DOUBLE (pspec); @@ -455,7 +456,7 @@ param_double_values_cmp (GParamSpec *pspec, } static void -param_spec_string_init (GParamSpec *pspec) +param_string_init (GParamSpec *pspec) { GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec); @@ -468,7 +469,7 @@ param_spec_string_init (GParamSpec *pspec) } static void -param_spec_string_finalize (GParamSpec *pspec) +param_string_finalize (GParamSpec *pspec) { GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec); GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_STRING)); @@ -546,7 +547,7 @@ param_string_values_cmp (GParamSpec *pspec, } static void -param_spec_param_init (GParamSpec *pspec) +param_param_init (GParamSpec *pspec) { /* GParamSpecParam *spec = G_PARAM_SPEC_PARAM (pspec); */ } @@ -566,7 +567,7 @@ param_param_validate (GParamSpec *pspec, GParamSpec *param = value->data[0].v_pointer; guint changed = 0; - if (param && !g_type_is_a (G_PARAM_SPEC_TYPE (param), G_PARAM_SPEC_VALUE_TYPE (pspec))) + if (param && !g_value_type_compatible (G_PARAM_SPEC_TYPE (param), G_PARAM_SPEC_VALUE_TYPE (pspec))) { g_param_spec_unref (param); value->data[0].v_pointer = NULL; @@ -577,71 +578,7 @@ param_param_validate (GParamSpec *pspec, } static void -param_spec_pointer_init (GParamSpec *pspec) -{ - /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */ -} - -static void -param_pointer_set_default (GParamSpec *pspec, - GValue *value) -{ - value->data[0].v_pointer = NULL; -} - -static gboolean -param_pointer_validate (GParamSpec *pspec, - GValue *value) -{ - /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */ - guint changed = 0; - - return changed; -} - -static gint -param_pointer_values_cmp (GParamSpec *pspec, - const GValue *value1, - const GValue *value2) -{ - return value1->data[0].v_pointer != value2->data[0].v_pointer; -} - -static void -param_spec_ccallback_init (GParamSpec *pspec) -{ - /* GParamSpecCCallback *spec = G_PARAM_SPEC_CCALLBACK (pspec); */ -} - -static void -param_ccallback_set_default (GParamSpec *pspec, - GValue *value) -{ - value->data[0].v_pointer = NULL; - value->data[1].v_pointer = NULL; -} - -static gboolean -param_ccallback_validate (GParamSpec *pspec, - GValue *value) -{ - /* GParamSpecCCallback *spec = G_PARAM_SPEC_CCALLBACK (pspec); */ - guint changed = 0; - - return changed; -} - -static gint -param_ccallback_values_cmp (GParamSpec *pspec, - const GValue *value1, - const GValue *value2) -{ - return (value1->data[0].v_pointer != value2->data[0].v_pointer || - value1->data[1].v_pointer != value2->data[1].v_pointer); -} - -static void -param_spec_boxed_init (GParamSpec *pspec) +param_boxed_init (GParamSpec *pspec) { /* GParamSpecBoxed *bspec = G_PARAM_SPEC_BOXED (pspec); */ } @@ -670,17 +607,231 @@ param_boxed_values_cmp (GParamSpec *pspec, const GValue *value1, const GValue *value2) { - return value1->data[0].v_pointer != value2->data[0].v_pointer; + guint8 *p1 = value1->data[0].v_pointer; + guint8 *p2 = value2->data[0].v_pointer; + + /* not much to compare here, try to at least provide stable lesser/greater result */ + + return p1 < p2 ? -1 : p1 > p2; } static void -param_spec_object_init (GParamSpec *pspec) +param_pointer_init (GParamSpec *pspec) { - /* GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec); */ + /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */ } static void -param_spec_interface_init (GParamSpec *pspec) +param_pointer_set_default (GParamSpec *pspec, + GValue *value) +{ + value->data[0].v_pointer = NULL; +} + +static gboolean +param_pointer_validate (GParamSpec *pspec, + GValue *value) +{ + /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */ + guint changed = 0; + + return changed; +} + +static gint +param_pointer_values_cmp (GParamSpec *pspec, + const GValue *value1, + const GValue *value2) +{ + guint8 *p1 = value1->data[0].v_pointer; + guint8 *p2 = value2->data[0].v_pointer; + + /* not much to compare here, try to at least provide stable lesser/greater result */ + + return p1 < p2 ? -1 : p1 > p2; +} + +static void +param_closure_init (GParamSpec *pspec) +{ + /* GParamSpecClosure *cspec = G_PARAM_SPEC_CLOSURE (pspec); */ +} + +static void +param_closure_set_default (GParamSpec *pspec, + GValue *value) +{ + value->data[0].v_pointer = NULL; +} + +static gboolean +param_closure_validate (GParamSpec *pspec, + GValue *value) +{ + /* GParamSpecClosure *cspec = G_PARAM_SPEC_CLOSURE (pspec); */ + /* GClosure *closure = value->data[0].v_pointer; */ + guint changed = 0; + + /* we don't actually have necessary means to ensure closure validity */ + + return changed; +} + +static gint +param_closure_values_cmp (GParamSpec *pspec, + const GValue *value1, + const GValue *value2) +{ + guint8 *p1 = value1->data[0].v_pointer; + guint8 *p2 = value2->data[0].v_pointer; + + /* not much to compare here, try to at least provide stable lesser/greater result */ + + return p1 < p2 ? -1 : p1 > p2; +} + +static void +param_value_array_init (GParamSpec *pspec) +{ + GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec); + + aspec->element_spec = NULL; + aspec->fixed_n_elements = 0; /* disable */ +} + +static inline guint +value_array_ensure_size (GValueArray *value_array, + guint fixed_n_elements) +{ + guint changed = 0; + + if (fixed_n_elements) + { + while (value_array->n_values < fixed_n_elements) + { + g_value_array_append (value_array, NULL); + changed++; + } + while (value_array->n_values > fixed_n_elements) + { + g_value_array_remove (value_array, value_array->n_values - 1); + changed++; + } + } + return changed; +} + +static void +param_value_array_finalize (GParamSpec *pspec) +{ + GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec); + GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_VALUE_ARRAY)); + + if (aspec->element_spec) + { + g_param_spec_unref (aspec->element_spec); + aspec->element_spec = NULL; + } + + parent_class->finalize (pspec); +} + +static void +param_value_array_set_default (GParamSpec *pspec, + GValue *value) +{ + GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec); + + g_return_if_fail (value->data[0].v_pointer != NULL); /* paranoid */ + + /* g_value_reset (value); already done */ + value_array_ensure_size (value->data[0].v_pointer, aspec->fixed_n_elements); +} + +static gboolean +param_value_array_validate (GParamSpec *pspec, + GValue *value) +{ + GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec); + GValueArray *value_array = value->data[0].v_pointer; + guint changed = 0; + + g_return_val_if_fail (value->data[0].v_pointer != NULL, FALSE); /* paranoid */ + + /* ensure array size validity */ + changed += value_array_ensure_size (value_array, aspec->fixed_n_elements); + + /* ensure array values validity against a present element spec */ + if (aspec->element_spec) + { + GParamSpec *element_spec = aspec->element_spec; + guint i; + + for (i = 0; i < value_array->n_values; i++) + { + GValue *element = value_array->values + i; + + /* need to fixup value type, or ensure that the array value is initialized at all */ + if (!g_value_type_compatible (G_VALUE_TYPE (element), G_PARAM_SPEC_VALUE_TYPE (element_spec))) + { + if (G_VALUE_TYPE (element) != 0) + g_value_unset (element); + g_value_init (element, G_PARAM_SPEC_VALUE_TYPE (element_spec)); + g_param_value_set_default (element_spec, element); + changed++; + } + /* validate array value against element_spec */ + changed += g_param_value_validate (element_spec, element); + } + } + + return changed; +} + +static gint +param_value_array_values_cmp (GParamSpec *pspec, + const GValue *value1, + const GValue *value2) +{ + GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec); + GValueArray *value_array1 = value1->data[0].v_pointer; + GValueArray *value_array2 = value2->data[0].v_pointer; + + g_return_val_if_fail (value1->data[0].v_pointer != NULL, -1); /* paranoid */ + g_return_val_if_fail (value2->data[0].v_pointer != NULL, 1); /* paranoid */ + + if (value_array1->n_values != value_array2->n_values) + return value_array1->n_values < value_array2->n_values ? -1 : 1; + else if (!aspec->element_spec) + { + /* we need an element specification for comparisons, so there's not much + * to compare here, try to at least provide stable lesser/greater result + */ + return value_array1->n_values < value_array2->n_values ? -1 : value_array1->n_values > value_array2->n_values; + } + else /* value_array1->n_values == value_array2->n_values */ + { + guint i; + + for (i = 0; i < value_array1->n_values; i++) + { + GValue *element1 = value_array1->values + i; + GValue *element2 = value_array2->values + i; + gint cmp; + + /* need corresponding element types, provide stable result otherwise */ + if (G_VALUE_TYPE (element1) != G_VALUE_TYPE (element2)) + return G_VALUE_TYPE (element1) < G_VALUE_TYPE (element2) ? -1 : 1; + cmp = g_param_values_cmp (aspec->element_spec, element1, element2); + if (cmp) + return cmp; + } + return 0; + } +} + +static void +param_object_init (GParamSpec *pspec) { /* GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec); */ } @@ -700,7 +851,7 @@ param_object_validate (GParamSpec *pspec, GObject *object = value->data[0].v_pointer; guint changed = 0; - if (object && !g_type_is_a (G_OBJECT_TYPE (object), G_PARAM_SPEC_VALUE_TYPE (ospec))) + if (object && !g_value_type_compatible (G_OBJECT_TYPE (object), G_PARAM_SPEC_VALUE_TYPE (ospec))) { g_object_unref (object); value->data[0].v_pointer = NULL; @@ -715,161 +866,12 @@ param_object_values_cmp (GParamSpec *pspec, const GValue *value1, const GValue *value2) { - return value1->data[0].v_pointer != value2->data[0].v_pointer; -} + guint8 *p1 = value1->data[0].v_pointer; + guint8 *p2 = value2->data[0].v_pointer; -static void -param_interface_set_default (GParamSpec *pspec, - GValue *value) -{ - value->data[0].v_pointer = NULL; -} + /* not much to compare here, try to at least provide stable lesser/greater result */ -static gboolean -param_interface_validate (GParamSpec *pspec, - GValue *value) -{ - guint changed = 0; - - if (value->data[0].v_pointer == NULL) - changed++; - - return changed; -} - -static gint -param_interface_values_cmp (GParamSpec *pspec, - const GValue *value1, - const GValue *value2) -{ - return value1->data[0].v_pointer != value2->data[0].v_pointer; -} - -static void -value_exch_memcpy (GValue *value1, - GValue *value2) -{ - GValue tmp_value; - memcpy (&tmp_value.data, &value1->data, sizeof (value1->data)); - memcpy (&value1->data, &value2->data, sizeof (value1->data)); - memcpy (&value2->data, &tmp_value.data, sizeof (value2->data)); -} - -static void -value_exch_long_int (GValue *value1, - GValue *value2) -{ - glong tmp = value1->data[0].v_long; - value1->data[0].v_long = value2->data[0].v_int; - value2->data[0].v_int = tmp; -} - -static void -value_exch_long_uint (GValue *value1, - GValue *value2) -{ - glong tmp = value1->data[0].v_long; - value1->data[0].v_long = value2->data[0].v_uint; - value2->data[0].v_uint = tmp; -} - -static void -value_exch_ulong_int (GValue *value1, - GValue *value2) -{ - gulong tmp = value1->data[0].v_ulong; - value1->data[0].v_ulong = value2->data[0].v_int; - value2->data[0].v_int = tmp; -} - -static void -value_exch_ulong_uint (GValue *value1, - GValue *value2) -{ - gulong tmp = value1->data[0].v_ulong; - value1->data[0].v_ulong = value2->data[0].v_uint; - value2->data[0].v_uint = tmp; -} - -static void -value_exch_float_int (GValue *value1, - GValue *value2) -{ - gfloat tmp = value1->data[0].v_float; - value1->data[0].v_float = value2->data[0].v_int; - value2->data[0].v_int = 0.5 + tmp; -} - -static void -value_exch_float_uint (GValue *value1, - GValue *value2) -{ - gfloat tmp = value1->data[0].v_float; - value1->data[0].v_float = value2->data[0].v_uint; - value2->data[0].v_uint = 0.5 + tmp; -} - -static void -value_exch_float_long (GValue *value1, - GValue *value2) -{ - gfloat tmp = value1->data[0].v_float; - value1->data[0].v_float = value2->data[0].v_long; - value2->data[0].v_long = 0.5 + tmp; -} - -static void -value_exch_float_ulong (GValue *value1, - GValue *value2) -{ - gfloat tmp = value1->data[0].v_float; - value1->data[0].v_float = value2->data[0].v_ulong; - value2->data[0].v_ulong = 0.5 + tmp; -} - -static void -value_exch_double_int (GValue *value1, - GValue *value2) -{ - gdouble tmp = value1->data[0].v_double; - value1->data[0].v_double = value2->data[0].v_int; - value2->data[0].v_int = 0.5 + tmp; -} - -static void -value_exch_double_uint (GValue *value1, - GValue *value2) -{ - gdouble tmp = value1->data[0].v_double; - value1->data[0].v_double = value2->data[0].v_uint; - value2->data[0].v_uint = 0.5 + tmp; -} - -static void -value_exch_double_long (GValue *value1, - GValue *value2) -{ - gdouble tmp = value1->data[0].v_double; - value1->data[0].v_double = value2->data[0].v_long; - value2->data[0].v_long = 0.5 + tmp; -} - -static void -value_exch_double_ulong (GValue *value1, - GValue *value2) -{ - gdouble tmp = value1->data[0].v_double; - value1->data[0].v_double = value2->data[0].v_ulong; - value2->data[0].v_ulong = 0.5 + tmp; -} - -static void -value_exch_double_float (GValue *value1, - GValue *value2) -{ - gdouble tmp = value1->data[0].v_double; - value1->data[0].v_double = value2->data[0].v_float; - value2->data[0].v_float = tmp; + return p1 < p2 ? -1 : p1 > p2; } @@ -885,7 +887,7 @@ g_param_spec_types_init (void) /* sync with gtype.c */ static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecChar), /* instance_size */ 16, /* n_preallocs */ - param_spec_char_init, /* instance_init */ + param_char_init, /* instance_init */ G_TYPE_CHAR, /* value_type */ NULL, /* finalize */ param_char_set_default, /* value_set_default */ @@ -902,7 +904,7 @@ g_param_spec_types_init (void) /* sync with gtype.c */ static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecUChar), /* instance_size */ 16, /* n_preallocs */ - param_spec_uchar_init, /* instance_init */ + param_uchar_init, /* instance_init */ G_TYPE_UCHAR, /* value_type */ NULL, /* finalize */ param_uchar_set_default, /* value_set_default */ @@ -936,7 +938,7 @@ g_param_spec_types_init (void) /* sync with gtype.c */ static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecInt), /* instance_size */ 16, /* n_preallocs */ - param_spec_int_init, /* instance_init */ + param_int_init, /* instance_init */ G_TYPE_INT, /* value_type */ NULL, /* finalize */ param_int_set_default, /* value_set_default */ @@ -953,7 +955,7 @@ g_param_spec_types_init (void) /* sync with gtype.c */ static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecUInt), /* instance_size */ 16, /* n_preallocs */ - param_spec_uint_init, /* instance_init */ + param_uint_init, /* instance_init */ G_TYPE_UINT, /* value_type */ NULL, /* finalize */ param_uint_set_default, /* value_set_default */ @@ -970,7 +972,7 @@ g_param_spec_types_init (void) /* sync with gtype.c */ static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecLong), /* instance_size */ 16, /* n_preallocs */ - param_spec_long_init, /* instance_init */ + param_long_init, /* instance_init */ G_TYPE_LONG, /* value_type */ NULL, /* finalize */ param_long_set_default, /* value_set_default */ @@ -987,7 +989,7 @@ g_param_spec_types_init (void) /* sync with gtype.c */ static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecULong), /* instance_size */ 16, /* n_preallocs */ - param_spec_ulong_init, /* instance_init */ + param_ulong_init, /* instance_init */ G_TYPE_ULONG, /* value_type */ NULL, /* finalize */ param_ulong_set_default, /* value_set_default */ @@ -1004,9 +1006,9 @@ g_param_spec_types_init (void) /* sync with gtype.c */ static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecEnum), /* instance_size */ 16, /* n_preallocs */ - param_spec_enum_init, /* instance_init */ + param_enum_init, /* instance_init */ G_TYPE_ENUM, /* value_type */ - param_spec_enum_finalize, /* finalize */ + param_enum_finalize, /* finalize */ param_enum_set_default, /* value_set_default */ param_enum_validate, /* value_validate */ param_long_values_cmp, /* values_cmp */ @@ -1019,11 +1021,11 @@ g_param_spec_types_init (void) /* sync with gtype.c */ */ { static const GParamSpecTypeInfo pspec_info = { - sizeof (GParamSpecFlags), /* instance_size */ - 16, /* n_preallocs */ - param_spec_flags_init, /* instance_init */ + sizeof (GParamSpecFlags), /* instance_size */ + 16, /* n_preallocs */ + param_flags_init, /* instance_init */ G_TYPE_FLAGS, /* value_type */ - param_spec_flags_finalize,/* finalize */ + param_flags_finalize, /* finalize */ param_flags_set_default, /* value_set_default */ param_flags_validate, /* value_validate */ param_ulong_values_cmp, /* values_cmp */ @@ -1038,7 +1040,7 @@ g_param_spec_types_init (void) /* sync with gtype.c */ static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecFloat), /* instance_size */ 16, /* n_preallocs */ - param_spec_float_init, /* instance_init */ + param_float_init, /* instance_init */ G_TYPE_FLOAT, /* value_type */ NULL, /* finalize */ param_float_set_default, /* value_set_default */ @@ -1053,14 +1055,14 @@ g_param_spec_types_init (void) /* sync with gtype.c */ */ { static const GParamSpecTypeInfo pspec_info = { - sizeof (GParamSpecDouble), /* instance_size */ - 16, /* n_preallocs */ - param_spec_double_init, /* instance_init */ - G_TYPE_DOUBLE, /* value_type */ - NULL, /* finalize */ - param_double_set_default, /* value_set_default */ - param_double_validate, /* value_validate */ - param_double_values_cmp, /* values_cmp */ + sizeof (GParamSpecDouble), /* instance_size */ + 16, /* n_preallocs */ + param_double_init, /* instance_init */ + G_TYPE_DOUBLE, /* value_type */ + NULL, /* finalize */ + param_double_set_default, /* value_set_default */ + param_double_validate, /* value_validate */ + param_double_values_cmp, /* values_cmp */ }; type = g_param_type_register_static ("GParamDouble", &pspec_info); g_assert (type == G_TYPE_PARAM_DOUBLE); @@ -1070,14 +1072,14 @@ g_param_spec_types_init (void) /* sync with gtype.c */ */ { static const GParamSpecTypeInfo pspec_info = { - sizeof (GParamSpecString), /* instance_size */ - 16, /* n_preallocs */ - param_spec_string_init, /* instance_init */ - G_TYPE_STRING, /* value_type */ - param_spec_string_finalize, /* finalize */ - param_string_set_default, /* value_set_default */ - param_string_validate, /* value_validate */ - param_string_values_cmp, /* values_cmp */ + sizeof (GParamSpecString), /* instance_size */ + 16, /* n_preallocs */ + param_string_init, /* instance_init */ + G_TYPE_STRING, /* value_type */ + param_string_finalize, /* finalize */ + param_string_set_default, /* value_set_default */ + param_string_validate, /* value_validate */ + param_string_values_cmp, /* values_cmp */ }; type = g_param_type_register_static ("GParamString", &pspec_info); g_assert (type == G_TYPE_PARAM_STRING); @@ -1087,26 +1089,43 @@ g_param_spec_types_init (void) /* sync with gtype.c */ */ { static const GParamSpecTypeInfo pspec_info = { - sizeof (GParamSpecParam), /* instance_size */ - 16, /* n_preallocs */ - param_spec_param_init, /* instance_init */ - G_TYPE_PARAM, /* value_type */ - NULL, /* finalize */ - param_param_set_default, /* value_set_default */ - param_param_validate, /* value_validate */ - param_pointer_values_cmp, /* values_cmp */ + sizeof (GParamSpecParam), /* instance_size */ + 16, /* n_preallocs */ + param_param_init, /* instance_init */ + G_TYPE_PARAM, /* value_type */ + NULL, /* finalize */ + param_param_set_default, /* value_set_default */ + param_param_validate, /* value_validate */ + param_pointer_values_cmp, /* values_cmp */ }; type = g_param_type_register_static ("GParamParam", &pspec_info); g_assert (type == G_TYPE_PARAM_PARAM); } + /* G_TYPE_PARAM_BOXED + */ + { + static const GParamSpecTypeInfo pspec_info = { + sizeof (GParamSpecBoxed), /* instance_size */ + 4, /* n_preallocs */ + param_boxed_init, /* instance_init */ + G_TYPE_BOXED, /* value_type */ + NULL, /* finalize */ + param_boxed_set_default, /* value_set_default */ + param_boxed_validate, /* value_validate */ + param_boxed_values_cmp, /* values_cmp */ + }; + type = g_param_type_register_static ("GParamBoxed", &pspec_info); + g_assert (type == G_TYPE_PARAM_BOXED); + } + /* G_TYPE_PARAM_POINTER */ { static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecPointer), /* instance_size */ 0, /* n_preallocs */ - param_spec_pointer_init, /* instance_init */ + param_pointer_init, /* instance_init */ G_TYPE_POINTER, /* value_type */ NULL, /* finalize */ param_pointer_set_default, /* value_set_default */ @@ -1117,47 +1136,47 @@ g_param_spec_types_init (void) /* sync with gtype.c */ g_assert (type == G_TYPE_PARAM_POINTER); } - /* G_TYPE_PARAM_CCALLBACK + /* G_TYPE_PARAM_VALUE_ARRAY */ { static const GParamSpecTypeInfo pspec_info = { - sizeof (GParamSpecCCallback), /* instance_size */ - 0, /* n_preallocs */ - param_spec_ccallback_init, /* instance_init */ - G_TYPE_CCALLBACK, /* value_type */ - NULL, /* finalize */ - param_ccallback_set_default, /* value_set_default */ - param_ccallback_validate, /* value_validate */ - param_ccallback_values_cmp, /* values_cmp */ + sizeof (GParamSpecValueArray), /* instance_size */ + 0, /* n_preallocs */ + param_value_array_init, /* instance_init */ + G_TYPE_VALUE_ARRAY, /* value_type */ + param_value_array_finalize, /* finalize */ + param_value_array_set_default, /* value_set_default */ + param_value_array_validate, /* value_validate */ + param_value_array_values_cmp, /* values_cmp */ }; - type = g_param_type_register_static ("GParamCCallback", &pspec_info); - g_assert (type == G_TYPE_PARAM_CCALLBACK); - } - - /* G_TYPE_PARAM_BOXED - */ - { - static const GParamSpecTypeInfo pspec_info = { - sizeof (GParamSpecBoxed), /* instance_size */ - 4, /* n_preallocs */ - param_spec_boxed_init, /* instance_init */ - G_TYPE_BOXED, /* value_type */ - NULL, /* finalize */ - param_boxed_set_default, /* value_set_default */ - param_boxed_validate, /* value_validate */ - param_boxed_values_cmp, /* values_cmp */ - }; - type = g_param_type_register_static ("GParamBoxed", &pspec_info); - g_assert (type == G_TYPE_PARAM_BOXED); + type = g_param_type_register_static ("GParamValueArray", &pspec_info); + g_assert (type == G_TYPE_PARAM_VALUE_ARRAY); } + /* G_TYPE_PARAM_CLOSURE + */ + { + static const GParamSpecTypeInfo pspec_info = { + sizeof (GParamSpecClosure), /* instance_size */ + 0, /* n_preallocs */ + param_closure_init, /* instance_init */ + G_TYPE_CLOSURE, /* value_type */ + NULL, /* finalize */ + param_closure_set_default, /* value_set_default */ + param_closure_validate, /* value_validate */ + param_closure_values_cmp, /* values_cmp */ + }; + type = g_param_type_register_static ("GParamClosure", &pspec_info); + g_assert (type == G_TYPE_PARAM_CLOSURE); + } + /* G_TYPE_PARAM_OBJECT */ { static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecObject), /* instance_size */ 16, /* n_preallocs */ - param_spec_object_init, /* instance_init */ + param_object_init, /* instance_init */ G_TYPE_OBJECT, /* value_type */ NULL, /* finalize */ param_object_set_default, /* value_set_default */ @@ -1167,79 +1186,6 @@ g_param_spec_types_init (void) /* sync with gtype.c */ type = g_param_type_register_static ("GParamObject", &pspec_info); g_assert (type == G_TYPE_PARAM_OBJECT); } - - /* G_TYPE_PARAM_INTERFACE - */ - { - static const GParamSpecTypeInfo pspec_info = { - sizeof (GParamSpecInterface), /* instance_size */ - 4, /* n_preallocs */ - param_spec_interface_init, /* instance_init */ - G_TYPE_INTERFACE, /* value_type */ - NULL, /* finalize */ - param_interface_set_default, /* value_set_default */ - param_interface_validate, /* value_validate */ - param_interface_values_cmp, /* values_cmp */ - }; - type = g_param_type_register_static ("GParamInterface", &pspec_info); - g_assert (type == G_TYPE_PARAM_INTERFACE); - } - - g_value_register_exchange_func (G_TYPE_CHAR, G_TYPE_UCHAR, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_CHAR, G_TYPE_BOOLEAN, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_CHAR, G_TYPE_INT, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_CHAR, G_TYPE_UINT, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_CHAR, G_TYPE_ENUM, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_CHAR, G_TYPE_FLAGS, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_UCHAR, G_TYPE_BOOLEAN, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_UCHAR, G_TYPE_INT, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_UCHAR, G_TYPE_UINT, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_UCHAR, G_TYPE_ENUM, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_UCHAR, G_TYPE_FLAGS, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_BOOLEAN, G_TYPE_INT, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_BOOLEAN, G_TYPE_UINT, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_BOOLEAN, G_TYPE_ENUM, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_BOOLEAN, G_TYPE_FLAGS, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_INT, G_TYPE_UINT, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_INT, G_TYPE_ENUM, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_INT, G_TYPE_FLAGS, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_UINT, G_TYPE_ENUM, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_UINT, G_TYPE_FLAGS, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_LONG, G_TYPE_CHAR, value_exch_long_int); - g_value_register_exchange_func (G_TYPE_LONG, G_TYPE_UCHAR, value_exch_long_uint); - g_value_register_exchange_func (G_TYPE_LONG, G_TYPE_BOOLEAN, value_exch_long_int); - g_value_register_exchange_func (G_TYPE_LONG, G_TYPE_INT, value_exch_long_int); - g_value_register_exchange_func (G_TYPE_LONG, G_TYPE_UINT, value_exch_long_uint); - g_value_register_exchange_func (G_TYPE_LONG, G_TYPE_ULONG, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_LONG, G_TYPE_ENUM, value_exch_long_int); - g_value_register_exchange_func (G_TYPE_LONG, G_TYPE_FLAGS, value_exch_long_uint); - g_value_register_exchange_func (G_TYPE_ULONG, G_TYPE_CHAR, value_exch_ulong_int); - g_value_register_exchange_func (G_TYPE_ULONG, G_TYPE_UCHAR, value_exch_ulong_uint); - g_value_register_exchange_func (G_TYPE_ULONG, G_TYPE_BOOLEAN, value_exch_ulong_int); - g_value_register_exchange_func (G_TYPE_ULONG, G_TYPE_INT, value_exch_ulong_int); - g_value_register_exchange_func (G_TYPE_ULONG, G_TYPE_UINT, value_exch_ulong_uint); - g_value_register_exchange_func (G_TYPE_ULONG, G_TYPE_ENUM, value_exch_ulong_int); - g_value_register_exchange_func (G_TYPE_ULONG, G_TYPE_FLAGS, value_exch_ulong_uint); - g_value_register_exchange_func (G_TYPE_ENUM, G_TYPE_FLAGS, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_FLOAT, G_TYPE_CHAR, value_exch_float_int); - g_value_register_exchange_func (G_TYPE_FLOAT, G_TYPE_UCHAR, value_exch_float_uint); - g_value_register_exchange_func (G_TYPE_FLOAT, G_TYPE_BOOLEAN, value_exch_float_int); - g_value_register_exchange_func (G_TYPE_FLOAT, G_TYPE_INT, value_exch_float_int); - g_value_register_exchange_func (G_TYPE_FLOAT, G_TYPE_UINT, value_exch_float_uint); - g_value_register_exchange_func (G_TYPE_FLOAT, G_TYPE_LONG, value_exch_float_long); - g_value_register_exchange_func (G_TYPE_FLOAT, G_TYPE_ULONG, value_exch_float_ulong); - g_value_register_exchange_func (G_TYPE_FLOAT, G_TYPE_ENUM, value_exch_float_int); - g_value_register_exchange_func (G_TYPE_FLOAT, G_TYPE_FLAGS, value_exch_float_uint); - g_value_register_exchange_func (G_TYPE_DOUBLE, G_TYPE_CHAR, value_exch_double_int); - g_value_register_exchange_func (G_TYPE_DOUBLE, G_TYPE_UCHAR, value_exch_double_uint); - g_value_register_exchange_func (G_TYPE_DOUBLE, G_TYPE_BOOLEAN, value_exch_double_int); - g_value_register_exchange_func (G_TYPE_DOUBLE, G_TYPE_INT, value_exch_double_int); - g_value_register_exchange_func (G_TYPE_DOUBLE, G_TYPE_UINT, value_exch_double_uint); - g_value_register_exchange_func (G_TYPE_DOUBLE, G_TYPE_LONG, value_exch_double_long); - g_value_register_exchange_func (G_TYPE_DOUBLE, G_TYPE_ULONG, value_exch_double_ulong); - g_value_register_exchange_func (G_TYPE_DOUBLE, G_TYPE_ENUM, value_exch_double_int); - g_value_register_exchange_func (G_TYPE_DOUBLE, G_TYPE_FLAGS, value_exch_double_uint); - g_value_register_exchange_func (G_TYPE_DOUBLE, G_TYPE_FLOAT, value_exch_double_float); } @@ -1552,38 +1498,6 @@ g_param_spec_param (const gchar *name, return G_PARAM_SPEC (pspec); } -GParamSpec* -g_param_spec_pointer (const gchar *name, - const gchar *nick, - const gchar *blurb, - GParamFlags flags) -{ - GParamSpecPointer *pspec; - - pspec = g_param_spec_internal (G_TYPE_PARAM_POINTER, - name, - nick, - blurb, - flags); - return G_PARAM_SPEC (pspec); -} - -GParamSpec* -g_param_spec_ccallback (const gchar *name, - const gchar *nick, - const gchar *blurb, - GParamFlags flags) -{ - GParamSpecCCallback *cspec; - - cspec = g_param_spec_internal (G_TYPE_PARAM_CCALLBACK, - name, - nick, - blurb, - flags); - return G_PARAM_SPEC (cspec); -} - GParamSpec* g_param_spec_boxed (const gchar *name, const gchar *nick, @@ -1606,6 +1520,64 @@ g_param_spec_boxed (const gchar *name, return G_PARAM_SPEC (bspec); } +GParamSpec* +g_param_spec_pointer (const gchar *name, + const gchar *nick, + const gchar *blurb, + GParamFlags flags) +{ + GParamSpecPointer *pspec; + + pspec = g_param_spec_internal (G_TYPE_PARAM_POINTER, + name, + nick, + blurb, + flags); + return G_PARAM_SPEC (pspec); +} + +GParamSpec* +g_param_spec_value_array (const gchar *name, + const gchar *nick, + const gchar *blurb, + GParamSpec *element_spec, + GParamFlags flags) +{ + GParamSpecValueArray *aspec; + + if (element_spec) + g_return_val_if_fail (G_IS_PARAM_SPEC (element_spec), NULL); + + aspec = g_param_spec_internal (G_TYPE_PARAM_VALUE_ARRAY, + name, + nick, + blurb, + flags); + if (element_spec) + { + aspec->element_spec = g_param_spec_ref (element_spec); + g_param_spec_sink (element_spec); + } + + return G_PARAM_SPEC (aspec); +} + +GParamSpec* +g_param_spec_closure (const gchar *name, + const gchar *nick, + const gchar *blurb, + GParamFlags flags) +{ + GParamSpecClosure *cspec; + + cspec = g_param_spec_internal (G_TYPE_PARAM_CLOSURE, + name, + nick, + blurb, + flags); + return G_PARAM_SPEC (cspec); +} + GParamSpec* g_param_spec_object (const gchar *name, const gchar *nick, @@ -1626,25 +1598,3 @@ g_param_spec_object (const gchar *name, return G_PARAM_SPEC (ospec); } - -GParamSpec* -g_param_spec_interface (const gchar *name, - const gchar *nick, - const gchar *blurb, - GType interface_type, - GParamFlags flags) -{ - GParamSpecInterface *ispec; - - g_return_val_if_fail (G_TYPE_IS_INTERFACE (interface_type), NULL); - - ispec = g_param_spec_internal (G_TYPE_PARAM_INTERFACE, - name, - nick, - blurb, - flags); - G_PARAM_SPEC (ispec)->value_type = interface_type; - - return G_PARAM_SPEC (ispec); -} - diff --git a/gobject/gparamspecs.h b/gobject/gparamspecs.h index a3dc72394..1072a4b95 100644 --- a/gobject/gparamspecs.h +++ b/gobject/gparamspecs.h @@ -1,5 +1,5 @@ /* GObject - GLib Type, Object, Parameter and Signal Library - * Copyright (C) 1997, 1998, 1999, 2000 Tim Janik and Red Hat, Inc. + * Copyright (C) 1997-1999, 2000-2001 Tim Janik and Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -34,63 +34,63 @@ extern "C" { /* --- type macros --- */ -#define G_IS_PARAM_SPEC_CHAR(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_CHAR)) -#define G_PARAM_SPEC_CHAR(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_CHAR, GParamSpecChar)) -#define G_IS_PARAM_SPEC_UCHAR(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_UCHAR)) -#define G_PARAM_SPEC_UCHAR(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_UCHAR, GParamSpecUChar)) -#define G_IS_PARAM_SPEC_BOOLEAN(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_BOOLEAN)) -#define G_PARAM_SPEC_BOOLEAN(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_BOOLEAN, GParamSpecBoolean)) -#define G_IS_PARAM_SPEC_INT(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_INT)) -#define G_PARAM_SPEC_INT(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_INT, GParamSpecInt)) -#define G_IS_PARAM_SPEC_UINT(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_UINT)) -#define G_PARAM_SPEC_UINT(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_UINT, GParamSpecUInt)) -#define G_IS_PARAM_SPEC_LONG(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_LONG)) -#define G_PARAM_SPEC_LONG(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_LONG, GParamSpecLong)) -#define G_IS_PARAM_SPEC_ULONG(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_ULONG)) -#define G_PARAM_SPEC_ULONG(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_ULONG, GParamSpecULong)) -#define G_IS_PARAM_SPEC_ENUM(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_ENUM)) -#define G_PARAM_SPEC_ENUM(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_ENUM, GParamSpecEnum)) -#define G_IS_PARAM_SPEC_FLAGS(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_FLAGS)) -#define G_PARAM_SPEC_FLAGS(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_FLAGS, GParamSpecFlags)) -#define G_IS_PARAM_SPEC_FLOAT(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_FLOAT)) -#define G_PARAM_SPEC_FLOAT(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_FLOAT, GParamSpecFloat)) -#define G_IS_PARAM_SPEC_DOUBLE(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_DOUBLE)) -#define G_PARAM_SPEC_DOUBLE(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_DOUBLE, GParamSpecDouble)) -#define G_IS_PARAM_SPEC_STRING(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_STRING)) -#define G_PARAM_SPEC_STRING(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_STRING, GParamSpecString)) -#define G_IS_PARAM_SPEC_PARAM(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_PARAM)) -#define G_PARAM_SPEC_PARAM(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_PARAM, GParamSpecParam)) -#define G_IS_PARAM_SPEC_POINTER(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_POINTER)) -#define G_PARAM_SPEC_POINTER(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_POINTER, GParamSpecPointer)) -#define G_IS_PARAM_SPEC_CCALLBACK(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_CCALLBACK)) -#define G_PARAM_SPEC_CCALLBACK(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_CCALLBACK, GParamSpecCCallback)) -#define G_IS_PARAM_SPEC_BOXED(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_BOXED)) -#define G_PARAM_SPEC_BOXED(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_BOXED, GParamSpecBoxed)) -#define G_IS_PARAM_SPEC_OBJECT(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_OBJECT)) -#define G_PARAM_SPEC_OBJECT(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_OBJECT, GParamSpecObject)) -#define G_IS_PARAM_SPEC_INTERFACE(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_INTERFACE)) -#define G_PARAM_SPEC_INTERFACE(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_INTERFACE, GParamSpecInterface)) +#define G_IS_PARAM_SPEC_CHAR(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_CHAR)) +#define G_PARAM_SPEC_CHAR(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_CHAR, GParamSpecChar)) +#define G_IS_PARAM_SPEC_UCHAR(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_UCHAR)) +#define G_PARAM_SPEC_UCHAR(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_UCHAR, GParamSpecUChar)) +#define G_IS_PARAM_SPEC_BOOLEAN(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_BOOLEAN)) +#define G_PARAM_SPEC_BOOLEAN(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_BOOLEAN, GParamSpecBoolean)) +#define G_IS_PARAM_SPEC_INT(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_INT)) +#define G_PARAM_SPEC_INT(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_INT, GParamSpecInt)) +#define G_IS_PARAM_SPEC_UINT(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_UINT)) +#define G_PARAM_SPEC_UINT(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_UINT, GParamSpecUInt)) +#define G_IS_PARAM_SPEC_LONG(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_LONG)) +#define G_PARAM_SPEC_LONG(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_LONG, GParamSpecLong)) +#define G_IS_PARAM_SPEC_ULONG(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_ULONG)) +#define G_PARAM_SPEC_ULONG(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_ULONG, GParamSpecULong)) +#define G_IS_PARAM_SPEC_ENUM(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_ENUM)) +#define G_PARAM_SPEC_ENUM(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_ENUM, GParamSpecEnum)) +#define G_IS_PARAM_SPEC_FLAGS(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_FLAGS)) +#define G_PARAM_SPEC_FLAGS(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_FLAGS, GParamSpecFlags)) +#define G_IS_PARAM_SPEC_FLOAT(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_FLOAT)) +#define G_PARAM_SPEC_FLOAT(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_FLOAT, GParamSpecFloat)) +#define G_IS_PARAM_SPEC_DOUBLE(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_DOUBLE)) +#define G_PARAM_SPEC_DOUBLE(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_DOUBLE, GParamSpecDouble)) +#define G_IS_PARAM_SPEC_STRING(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_STRING)) +#define G_PARAM_SPEC_STRING(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_STRING, GParamSpecString)) +#define G_IS_PARAM_SPEC_PARAM(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_PARAM)) +#define G_PARAM_SPEC_PARAM(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_PARAM, GParamSpecParam)) +#define G_IS_PARAM_SPEC_BOXED(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_BOXED)) +#define G_PARAM_SPEC_BOXED(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_BOXED, GParamSpecBoxed)) +#define G_IS_PARAM_SPEC_POINTER(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_POINTER)) +#define G_PARAM_SPEC_POINTER(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_POINTER, GParamSpecPointer)) +#define G_IS_PARAM_SPEC_VALUE_ARRAY(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_VALUE_ARRAY)) +#define G_PARAM_SPEC_VALUE_ARRAY(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_VALUE_ARRAY, GParamSpecValueArray)) +#define G_IS_PARAM_SPEC_CLOSURE(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_CLOSURE)) +#define G_PARAM_SPEC_CLOSURE(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_CLOSURE, GParamSpecClosure)) +#define G_IS_PARAM_SPEC_OBJECT(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_OBJECT)) +#define G_PARAM_SPEC_OBJECT(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_OBJECT, GParamSpecObject)) /* --- typedefs & structures --- */ -typedef struct _GParamSpecChar GParamSpecChar; -typedef struct _GParamSpecUChar GParamSpecUChar; -typedef struct _GParamSpecBoolean GParamSpecBoolean; -typedef struct _GParamSpecInt GParamSpecInt; -typedef struct _GParamSpecUInt GParamSpecUInt; -typedef struct _GParamSpecLong GParamSpecLong; -typedef struct _GParamSpecULong GParamSpecULong; -typedef struct _GParamSpecEnum GParamSpecEnum; -typedef struct _GParamSpecFlags GParamSpecFlags; -typedef struct _GParamSpecFloat GParamSpecFloat; -typedef struct _GParamSpecDouble GParamSpecDouble; -typedef struct _GParamSpecString GParamSpecString; -typedef struct _GParamSpecParam GParamSpecParam; -typedef struct _GParamSpecPointer GParamSpecPointer; -typedef struct _GParamSpecCCallback GParamSpecCCallback; -typedef struct _GParamSpecBoxed GParamSpecBoxed; -typedef struct _GParamSpecObject GParamSpecObject; -typedef struct _GParamSpecInterface GParamSpecInterface; +typedef struct _GParamSpecChar GParamSpecChar; +typedef struct _GParamSpecUChar GParamSpecUChar; +typedef struct _GParamSpecBoolean GParamSpecBoolean; +typedef struct _GParamSpecInt GParamSpecInt; +typedef struct _GParamSpecUInt GParamSpecUInt; +typedef struct _GParamSpecLong GParamSpecLong; +typedef struct _GParamSpecULong GParamSpecULong; +typedef struct _GParamSpecEnum GParamSpecEnum; +typedef struct _GParamSpecFlags GParamSpecFlags; +typedef struct _GParamSpecFloat GParamSpecFloat; +typedef struct _GParamSpecDouble GParamSpecDouble; +typedef struct _GParamSpecString GParamSpecString; +typedef struct _GParamSpecParam GParamSpecParam; +typedef struct _GParamSpecBoxed GParamSpecBoxed; +typedef struct _GParamSpecPointer GParamSpecPointer; +typedef struct _GParamSpecValueArray GParamSpecValueArray; +typedef struct _GParamSpecClosure GParamSpecClosure; +typedef struct _GParamSpecObject GParamSpecObject; struct _GParamSpecChar { GParamSpec parent_instance; @@ -192,15 +192,21 @@ struct _GParamSpecParam { GParamSpec parent_instance; }; +struct _GParamSpecBoxed +{ + GParamSpec parent_instance; +}; struct _GParamSpecPointer { GParamSpec parent_instance; }; -struct _GParamSpecCCallback +struct _GParamSpecValueArray { GParamSpec parent_instance; + GParamSpec *element_spec; + guint fixed_n_elements; }; -struct _GParamSpecBoxed +struct _GParamSpecClosure { GParamSpec parent_instance; }; @@ -208,124 +214,120 @@ struct _GParamSpecObject { GParamSpec parent_instance; }; -struct _GParamSpecInterface -{ - GParamSpec parent_instance; -}; /* --- GParamSpec prototypes --- */ -GParamSpec* g_param_spec_char (const gchar *name, - const gchar *nick, - const gchar *blurb, - gint8 minimum, - gint8 maximum, - gint8 default_value, - GParamFlags flags); -GParamSpec* g_param_spec_uchar (const gchar *name, - const gchar *nick, - const gchar *blurb, - guint8 minimum, - guint8 maximum, - guint8 default_value, - GParamFlags flags); -GParamSpec* g_param_spec_boolean (const gchar *name, - const gchar *nick, - const gchar *blurb, - gboolean default_value, - GParamFlags flags); -GParamSpec* g_param_spec_int (const gchar *name, - const gchar *nick, - const gchar *blurb, - gint minimum, - gint maximum, - gint default_value, - GParamFlags flags); -GParamSpec* g_param_spec_uint (const gchar *name, - const gchar *nick, - const gchar *blurb, - guint minimum, - guint maximum, - guint default_value, - GParamFlags flags); -GParamSpec* g_param_spec_long (const gchar *name, - const gchar *nick, - const gchar *blurb, - glong minimum, - glong maximum, - glong default_value, - GParamFlags flags); -GParamSpec* g_param_spec_ulong (const gchar *name, - const gchar *nick, - const gchar *blurb, - gulong minimum, - gulong maximum, - gulong default_value, - GParamFlags flags); -GParamSpec* g_param_spec_enum (const gchar *name, - const gchar *nick, - const gchar *blurb, - GType enum_type, - gint default_value, - GParamFlags flags); -GParamSpec* g_param_spec_flags (const gchar *name, - const gchar *nick, - const gchar *blurb, - GType flags_type, - guint default_value, - GParamFlags flags); -GParamSpec* g_param_spec_float (const gchar *name, - const gchar *nick, - const gchar *blurb, - gfloat minimum, - gfloat maximum, - gfloat default_value, - GParamFlags flags); -GParamSpec* g_param_spec_double (const gchar *name, - const gchar *nick, - const gchar *blurb, - gdouble minimum, - gdouble maximum, - gdouble default_value, - GParamFlags flags); -GParamSpec* g_param_spec_string (const gchar *name, - const gchar *nick, - const gchar *blurb, - const gchar *default_value, - GParamFlags flags); -GParamSpec* g_param_spec_string_c (const gchar *name, - const gchar *nick, - const gchar *blurb, - const gchar *default_value, - GParamFlags flags); -GParamSpec* g_param_spec_param (const gchar *name, - const gchar *nick, - const gchar *blurb, - GType param_type, - GParamFlags flags); -GParamSpec* g_param_spec_pointer (const gchar *name, - const gchar *nick, - const gchar *blurb, - GParamFlags flags); -GParamSpec* g_param_spec_ccallback (const gchar *name, - const gchar *nick, - const gchar *blurb, - GParamFlags flags); -GParamSpec* g_param_spec_boxed (const gchar *name, - const gchar *nick, - const gchar *blurb, - GType boxed_type, - GParamFlags flags); -GParamSpec* g_param_spec_object (const gchar *name, - const gchar *nick, - const gchar *blurb, - GType object_type, - GParamFlags flags); -GParamSpec* g_param_spec_interface (const gchar *name, - const gchar *nick, - const gchar *blurb, - GType object_type, - GParamFlags flags); +GParamSpec* g_param_spec_char (const gchar *name, + const gchar *nick, + const gchar *blurb, + gint8 minimum, + gint8 maximum, + gint8 default_value, + GParamFlags flags); +GParamSpec* g_param_spec_uchar (const gchar *name, + const gchar *nick, + const gchar *blurb, + guint8 minimum, + guint8 maximum, + guint8 default_value, + GParamFlags flags); +GParamSpec* g_param_spec_boolean (const gchar *name, + const gchar *nick, + const gchar *blurb, + gboolean default_value, + GParamFlags flags); +GParamSpec* g_param_spec_int (const gchar *name, + const gchar *nick, + const gchar *blurb, + gint minimum, + gint maximum, + gint default_value, + GParamFlags flags); +GParamSpec* g_param_spec_uint (const gchar *name, + const gchar *nick, + const gchar *blurb, + guint minimum, + guint maximum, + guint default_value, + GParamFlags flags); +GParamSpec* g_param_spec_long (const gchar *name, + const gchar *nick, + const gchar *blurb, + glong minimum, + glong maximum, + glong default_value, + GParamFlags flags); +GParamSpec* g_param_spec_ulong (const gchar *name, + const gchar *nick, + const gchar *blurb, + gulong minimum, + gulong maximum, + gulong default_value, + GParamFlags flags); +GParamSpec* g_param_spec_enum (const gchar *name, + const gchar *nick, + const gchar *blurb, + GType enum_type, + gint default_value, + GParamFlags flags); +GParamSpec* g_param_spec_flags (const gchar *name, + const gchar *nick, + const gchar *blurb, + GType flags_type, + guint default_value, + GParamFlags flags); +GParamSpec* g_param_spec_float (const gchar *name, + const gchar *nick, + const gchar *blurb, + gfloat minimum, + gfloat maximum, + gfloat default_value, + GParamFlags flags); +GParamSpec* g_param_spec_double (const gchar *name, + const gchar *nick, + const gchar *blurb, + gdouble minimum, + gdouble maximum, + gdouble default_value, + GParamFlags flags); +GParamSpec* g_param_spec_string (const gchar *name, + const gchar *nick, + const gchar *blurb, + const gchar *default_value, + GParamFlags flags); +GParamSpec* g_param_spec_string_c (const gchar *name, + const gchar *nick, + const gchar *blurb, + const gchar *default_value, + GParamFlags flags); +GParamSpec* g_param_spec_param (const gchar *name, + const gchar *nick, + const gchar *blurb, + GType param_type, + GParamFlags flags); +GParamSpec* g_param_spec_boxed (const gchar *name, + const gchar *nick, + const gchar *blurb, + GType boxed_type, + GParamFlags flags); +GParamSpec* g_param_spec_pointer (const gchar *name, + const gchar *nick, + const gchar *blurb, + GParamFlags flags); +GParamSpec* g_param_spec_value_array (const gchar *name, + const gchar *nick, + const gchar *blurb, + GParamSpec *element_spec, + GParamFlags flags); +GParamSpec* g_param_spec_closure (const gchar *name, + const gchar *nick, + const gchar *blurb, + GParamFlags flags); +GParamSpec* g_param_spec_object (const gchar *name, + const gchar *nick, + const gchar *blurb, + GType object_type, + GParamFlags flags); #ifdef __cplusplus diff --git a/gobject/gsignal.c b/gobject/gsignal.c index c86533dd6..5cad4bb7a 100644 --- a/gobject/gsignal.c +++ b/gobject/gsignal.c @@ -1,5 +1,5 @@ /* GObject - GLib Type, Object, Parameter and Signal Library - * Copyright (C) 2000 Red Hat, Inc. + * Copyright (C) 2000-2001 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -774,6 +774,7 @@ g_signal_parse_name (const gchar *detailed_signal, GQuark *detail_p, gboolean force_detail_quark) { + SignalNode *node; GQuark detail = 0; guint signal_id; @@ -783,18 +784,18 @@ g_signal_parse_name (const gchar *detailed_signal, G_LOCK (g_signal_mutex); signal_id = signal_parse_name (detailed_signal, itype, &detail, force_detail_quark); G_UNLOCK (g_signal_mutex); - - if (signal_id) - { - if (signal_id_p) - *signal_id_p = signal_id; - if (detail_p) - *detail_p = detail; - - return TRUE; - } - else + + node = signal_id ? LOOKUP_SIGNAL_NODE (signal_id) : NULL; + if (!node || node->destroyed || + (detail && !(node->flags & G_SIGNAL_DETAILED))) return FALSE; + + if (signal_id_p) + *signal_id_p = signal_id; + if (detail_p) + *detail_p = detail; + + return TRUE; } guint @@ -1000,9 +1001,7 @@ g_signal_newv (const gchar *signal_name, return 0; } for (i = 0; i < n_params; i++) - if (!G_TYPE_IS_VALUE (param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE) || - (param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE) == G_TYPE_ENUM || - (param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE) == G_TYPE_FLAGS) /* FIXME: kludge */ + if (!G_TYPE_IS_VALUE (param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE)) { g_warning (G_STRLOC ": parameter %d of type `%s' for signal \"%s::%s\" is not a value type", i + 1, g_type_name (param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE), g_type_name (itype), name); @@ -1537,7 +1536,7 @@ g_signal_emitv (const GValue *instance_and_params, guint i; g_return_if_fail (instance_and_params != NULL); - instance = g_value_get_as_pointer (instance_and_params); + instance = g_value_peek_pointer (instance_and_params); g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance)); g_return_if_fail (signal_id > 0); @@ -1559,7 +1558,7 @@ g_signal_emitv (const GValue *instance_and_params, return; } for (i = 0; i < node->n_params; i++) - if (!G_VALUE_HOLDS (param_values + i, node->param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE)) + if (!G_TYPE_CHECK_VALUE_TYPE (param_values + i, node->param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE)) { g_critical ("%s: value for `%s' parameter %u for signal \"%s\" is of type `%s'", G_STRLOC, @@ -1581,7 +1580,7 @@ g_signal_emitv (const GValue *instance_and_params, G_UNLOCK (g_signal_mutex); return; } - else if (!node->accumulator && !G_VALUE_HOLDS (return_value, node->return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE)) + else if (!node->accumulator && !G_TYPE_CHECK_VALUE_TYPE (return_value, node->return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE)) { g_critical ("%s: return value `%s' for signal \"%s\" is of type `%s'", G_STRLOC, @@ -2045,4 +2044,7 @@ signal_emit_R (SignalNode *node, /* --- compile standard marshallers --- */ #include "gvaluetypes.h" +#include "gobject.h" +#include "genums.h" +#include "gboxed.h" #include "gmarshal.c" diff --git a/gobject/gsignal.h b/gobject/gsignal.h index a967d2eae..a1434da7a 100644 --- a/gobject/gsignal.h +++ b/gobject/gsignal.h @@ -1,5 +1,5 @@ /* GObject - GLib Type, Object, Parameter and Signal Library - * Copyright (C) 2000 Red Hat, Inc. + * Copyright (C) 2000-2001 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/gobject/gtype.c b/gobject/gtype.c index bcbed34f8..65bdb9cd7 100644 --- a/gobject/gtype.c +++ b/gobject/gtype.c @@ -1,5 +1,5 @@ /* GObject - GLib Type, Object, Parameter and Signal Library - * Copyright (C) 1998, 1999, 2000 Tim Janik and Red Hat, Inc. + * Copyright (C) 1998-1999, 2000-2001 Tim Janik and Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -74,6 +74,16 @@ static GStaticRWLock type_rw_lock = G_STATIC_RW_LOCK_INIT; else \ g_error ("%s()%s`%s'", _fname, _action, _tname); \ }G_STMT_END +#define g_return_val_if_uninitialized(condition, init_function, return_value) G_STMT_START{ \ + if (!(condition)) \ + { \ + g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, \ + "%s: initialization assertion failed, use %s() prior to this function", \ + G_STRLOC, G_STRINGIFY (init_function)); \ + return (return_value); \ + } \ +}G_STMT_END + #ifdef G_ENABLE_DEBUG #define DEBUG_CODE(debug_type, code_block) G_STMT_START { \ if (_g_type_debug_flags & G_TYPE_DEBUG_ ## debug_type) \ @@ -87,7 +97,7 @@ static GStaticRWLock type_rw_lock = G_STATIC_RW_LOCK_INIT; G_TYPE_FLAG_INSTANTIATABLE | \ G_TYPE_FLAG_DERIVABLE | \ G_TYPE_FLAG_DEEP_DERIVABLE) -#define TYPE_FLAG_MASK (G_TYPE_FLAG_ABSTRACT) +#define TYPE_FLAG_MASK (G_TYPE_FLAG_ABSTRACT | G_TYPE_FLAG_VALUE_ABSTRACT) /* --- typedefs --- */ @@ -811,7 +821,15 @@ type_data_make_W (TypeNode *node, } } if (value_table) - vtable_size = sizeof (GTypeValueTable); + { + /* need to setup vtable_size since we have to allocate it with data in one chunk */ + vtable_size = sizeof (GTypeValueTable); + if (value_table->collect_format) + vtable_size += strlen (value_table->collect_format); + if (value_table->lcopy_format) + vtable_size += strlen (value_table->lcopy_format); + vtable_size += 2; + } if (node->is_instantiatable) /* carefull, is_instantiatable is also is_classed */ { @@ -868,9 +886,26 @@ type_data_make_W (TypeNode *node, if (vtable_size) { + gchar *p; + + /* we allocate the vtable and its strings together with the type data, so + * children can take over their parent's vtable pointer, and we don't + * need to worry freeing it or not when the child data is destroyed + */ *vtable = *value_table; - vtable->collect_format = g_strdup (value_table->collect_format ? value_table->collect_format : ""); - vtable->lcopy_format = g_strdup (value_table->lcopy_format ? value_table->lcopy_format : ""); + p = G_STRUCT_MEMBER_P (vtable, sizeof (*vtable)); + p[0] = 0; + vtable->collect_format = p; + if (value_table->collect_format) + { + strcat (p, value_table->collect_format); + p += strlen (value_table->collect_format); + } + p++; + p[0] = 0; + vtable->lcopy_format = p; + if (value_table->lcopy_format) + strcat (p, value_table->lcopy_format); } node->data->common.value_table = vtable; @@ -1323,10 +1358,6 @@ type_data_finalize_class_U (TypeNode *node, g_assert (cdata->class && cdata->common.ref_count == 0); - g_message ("finalizing %sClass `%s'", - type_descriptive_name_U (G_TYPE_FUNDAMENTAL (NODE_TYPE (node))), - type_descriptive_name_U (NODE_TYPE (node))); - if (cdata->class_finalize) cdata->class_finalize (class, (gpointer) cdata->class_data); @@ -1415,11 +1446,9 @@ type_data_last_unref_Wm (GType type, else node->data = NULL; - if (tdata->common.value_table) - { - g_free (tdata->common.value_table->collect_format); - g_free (tdata->common.value_table->lcopy_format); - } + /* freeing tdata->common.value_table and its contents is taking care of + * by allocating it in one chunk with tdata + */ g_free (tdata); if (ptype) @@ -1487,6 +1516,7 @@ g_type_register_fundamental (GType type_id, GTypeFundamentalInfo *node_finfo; TypeNode *node; + g_return_val_if_uninitialized (static_last_fundamental_id, g_type_init, 0); g_return_val_if_fail (type_id > 0, 0); g_return_val_if_fail (type_name != NULL, 0); g_return_val_if_fail (info != NULL, 0); @@ -1539,6 +1569,7 @@ g_type_register_static (GType parent_type, TypeNode *pnode, *node; GType type = 0; + g_return_val_if_uninitialized (static_last_fundamental_id, g_type_init, 0); g_return_val_if_fail (parent_type > 0, 0); g_return_val_if_fail (type_name != NULL, 0); g_return_val_if_fail (info != NULL, 0); @@ -1578,6 +1609,7 @@ g_type_register_dynamic (GType parent_type, TypeNode *pnode, *node; GType type; + g_return_val_if_uninitialized (static_last_fundamental_id, g_type_init, 0); g_return_val_if_fail (parent_type > 0, 0); g_return_val_if_fail (type_name != NULL, 0); g_return_val_if_fail (plugin != NULL, 0); @@ -1800,27 +1832,13 @@ g_type_interface_peek (gpointer instance_class, return vtable; } -GTypeValueTable* -g_type_value_table_peek (GType type) -{ - TypeNode *node; - GTypeValueTable *vtable = NULL; - - G_READ_LOCK (&type_rw_lock); - node = lookup_type_node_L (type); - if (node && node->data && node->data->common.ref_count > 0 && - node->data->common.value_table->value_init) - vtable = node->data->common.value_table; - G_READ_UNLOCK (&type_rw_lock); - - return vtable; -} - G_CONST_RETURN gchar* g_type_name (GType type) { TypeNode *node; + g_return_val_if_uninitialized (static_last_fundamental_id, g_type_init, NULL); + G_READ_LOCK (&type_rw_lock); node = lookup_type_node_L (type); G_READ_UNLOCK (&type_rw_lock); @@ -2140,7 +2158,7 @@ type_add_flags_W (TypeNode *node, g_return_if_fail ((flags & ~TYPE_FLAG_MASK) == 0); g_return_if_fail (node != NULL); - if ((flags & G_TYPE_FLAG_ABSTRACT) && node->is_classed && node->data && node->data->class.class) + if ((flags & TYPE_FLAG_MASK) && node->is_classed && node->data && node->data->class.class) g_warning ("tagging type `%s' as abstract after class initialization", NODE_NAME (node)); dflags = GPOINTER_TO_UINT (type_get_qdata_L (node, static_quark_type_flags)); dflags |= flags; @@ -2261,39 +2279,6 @@ g_type_class_is_a (GTypeClass *type_class, g_type_is_a (type_class->g_type, is_a_type)); } -gboolean -g_type_value_is_a (GValue *value, - GType type) -{ - TypeNode *node; - - if (!value) - return FALSE; - - G_READ_LOCK (&type_rw_lock); - node = lookup_type_node_L (value->g_type); -#if 0 - if (!G_TYPE_IS_FUNDAMENTAL (value->g_type) && !node || !node->data) - node = lookup_type_node_L (G_TYPE_FUNDAMENTAL (value->g_type)); -#endif - if (!node || !node->data || node->data->common.ref_count < 1 || - !node->data->common.value_table->value_init) - { - G_READ_UNLOCK (&type_rw_lock); - - return FALSE; - } - G_READ_UNLOCK (&type_rw_lock); - - return g_type_is_a (value->g_type, type); -} - -gboolean -g_type_check_value (GValue *value) -{ - return value && g_type_value_is_a (value, value->g_type); -} - GTypeInstance* g_type_check_instance_cast (GTypeInstance *type_instance, GType iface_type) @@ -2392,6 +2377,57 @@ g_type_check_instance (GTypeInstance *type_instance) return TRUE; } +static inline gboolean +type_check_is_value_type_U (GType type) +{ + GTypeFlags tflags = G_TYPE_FLAG_VALUE_ABSTRACT; + TypeNode *node; + + G_READ_LOCK (&type_rw_lock); + node = lookup_type_node_L (type); + if (node && node->data && node->data->common.ref_count > 0 && + node->data->common.value_table->value_init) + tflags = GPOINTER_TO_UINT (type_get_qdata_L (node, static_quark_type_flags)); + G_READ_UNLOCK (&type_rw_lock); + + return !(tflags & G_TYPE_FLAG_VALUE_ABSTRACT); +} + +gboolean +g_type_check_is_value_type (GType type) +{ + return type_check_is_value_type_U (type); +} + +gboolean +g_type_check_value (GValue *value) +{ + return value && type_check_is_value_type_U (value->g_type); +} + +gboolean +g_type_check_value_holds (GValue *value, + GType type) +{ + return value && type_check_is_value_type_U (value->g_type) && g_type_is_a (value->g_type, type); +} + +GTypeValueTable* +g_type_value_table_peek (GType type) +{ + TypeNode *node; + GTypeValueTable *vtable = NULL; + + G_READ_LOCK (&type_rw_lock); + node = lookup_type_node_L (type); + if (node && node->data && node->data->common.ref_count > 0 && + node->data->common.value_table->value_init) + vtable = node->data->common.value_table; + G_READ_UNLOCK (&type_rw_lock); + + return vtable; +} + /* --- foreign prototypes --- */ extern void g_value_types_init (void); /* sync with gvaluetypes.c */ @@ -2400,6 +2436,7 @@ extern void g_param_type_init (void); /* sync with gparam.c */ extern void g_boxed_type_init (void); /* sync with gboxed.c */ extern void g_object_type_init (void); /* sync with gobject.c */ extern void g_param_spec_types_init (void); /* sync with gparamspecs.c */ +extern void g_value_transforms_init (void); /* sync with gvaluetransform.c */ extern void g_signal_init (void); /* sync with gsignal.c */ @@ -2483,13 +2520,13 @@ g_type_init (GTypeDebugFlags debug_flags) */ g_enum_types_init (); - /* G_TYPE_PARAM + /* G_TYPE_BOXED */ - g_param_type_init (); + g_boxed_type_init (); /* G_TYPE_PARAM */ - g_boxed_type_init (); + g_param_type_init (); /* G_TYPE_OBJECT */ @@ -2499,6 +2536,10 @@ g_type_init (GTypeDebugFlags debug_flags) */ g_param_spec_types_init (); + /* Value Transformations + */ + g_value_transforms_init (); + /* Signal system */ g_signal_init (); diff --git a/gobject/gtype.h b/gobject/gtype.h index b251c3919..81e9e3c90 100644 --- a/gobject/gtype.h +++ b/gobject/gtype.h @@ -1,5 +1,5 @@ /* GObject - GLib Type, Object, Parameter and Signal Library - * Copyright (C) 1998, 1999, 2000 Tim Janik and Red Hat, Inc. + * Copyright (C) 1998-1999, 2000-2001 Tim Janik and Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -59,45 +59,39 @@ typedef enum /*< skip >*/ G_TYPE_FLOAT, G_TYPE_DOUBLE, G_TYPE_STRING, - G_TYPE_PARAM, - G_TYPE_BOXED, G_TYPE_POINTER, - G_TYPE_CCALLBACK, + G_TYPE_BOXED, + G_TYPE_PARAM, G_TYPE_OBJECT, - /* the following reserved ids should vanish soon */ - G_TYPE_GTK_SIGNAL, - /* reserved fundamental type ids, * mail gtk-devel-list@redhat.com for reservations */ - G_TYPE_BSE_PROCEDURE, - G_TYPE_BSE_TIME, - G_TYPE_BSE_NOTE, - G_TYPE_BSE_DOTS, - G_TYPE_GLE_GOBJECT, - - G_TYPE_LAST_RESERVED_FUNDAMENTAL, + G_TYPE_RESERVED_BSE_FIRST, + G_TYPE_RESERVED_BSE_LAST = G_TYPE_RESERVED_BSE_FIRST + 15, + G_TYPE_RESERVED_LAST_FUNDAMENTAL, /* derived type ids */ - G_TYPE_PARAM_CHAR = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 1), - G_TYPE_PARAM_UCHAR = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 2), - G_TYPE_PARAM_BOOLEAN = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 3), - G_TYPE_PARAM_INT = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 4), - G_TYPE_PARAM_UINT = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 5), - G_TYPE_PARAM_LONG = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 6), - G_TYPE_PARAM_ULONG = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 7), - G_TYPE_PARAM_ENUM = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 8), - G_TYPE_PARAM_FLAGS = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 9), - G_TYPE_PARAM_FLOAT = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 10), - G_TYPE_PARAM_DOUBLE = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 11), - G_TYPE_PARAM_STRING = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 12), - G_TYPE_PARAM_PARAM = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 13), - G_TYPE_PARAM_POINTER = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 14), - G_TYPE_PARAM_CCALLBACK = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 15), - G_TYPE_PARAM_BOXED = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 16), - G_TYPE_PARAM_OBJECT = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 17), - G_TYPE_PARAM_INTERFACE = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 18) + G_TYPE_CLOSURE = G_TYPE_DERIVE_ID (G_TYPE_BOXED, 1), + G_TYPE_VALUE_ARRAY = G_TYPE_DERIVE_ID (G_TYPE_BOXED, 2), + G_TYPE_PARAM_CHAR = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 1), + G_TYPE_PARAM_UCHAR = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 2), + G_TYPE_PARAM_BOOLEAN = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 3), + G_TYPE_PARAM_INT = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 4), + G_TYPE_PARAM_UINT = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 5), + G_TYPE_PARAM_LONG = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 6), + G_TYPE_PARAM_ULONG = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 7), + G_TYPE_PARAM_ENUM = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 8), + G_TYPE_PARAM_FLAGS = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 9), + G_TYPE_PARAM_FLOAT = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 10), + G_TYPE_PARAM_DOUBLE = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 11), + G_TYPE_PARAM_STRING = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 12), + G_TYPE_PARAM_PARAM = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 13), + G_TYPE_PARAM_BOXED = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 14), + G_TYPE_PARAM_POINTER = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 15), + G_TYPE_PARAM_VALUE_ARRAY = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 16), + G_TYPE_PARAM_CLOSURE = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 17), + G_TYPE_PARAM_OBJECT = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 18) } GTypeFundamentals; @@ -111,8 +105,10 @@ typedef enum /*< skip >*/ #define G_TYPE_IS_DERIVABLE(type) (g_type_check_flags ((type), G_TYPE_FLAG_DERIVABLE)) #define G_TYPE_IS_DEEP_DERIVABLE(type) (g_type_check_flags ((type), G_TYPE_FLAG_DEEP_DERIVABLE)) #define G_TYPE_IS_ABSTRACT(type) (g_type_check_flags ((type), G_TYPE_FLAG_ABSTRACT)) +#define G_TYPE_IS_VALUE_ABSTRACT(type) (g_type_check_flags ((type), G_TYPE_FLAG_VALUE_ABSTRACT)) #define G_TYPE_IS_PARAM(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_PARAM) -#define G_TYPE_IS_VALUE_TYPE(type) (g_type_value_table_peek (type) != NULL) +#define G_TYPE_IS_VALUE_TYPE(type) (g_type_check_is_value_type (type)) +#define G_TYPE_HAS_VALUE_TABLE(type) (g_type_value_table_peek (type) != NULL) /* Typedefs @@ -152,7 +148,6 @@ struct _GTypeInterface /* Casts, checks and accessors for structured types * usage of these macros is reserved to type implementations only - * */ /*< protected >*/ #define G_TYPE_CHECK_INSTANCE(instance) (_G_TYPE_CHI ((GTypeInstance*) (instance))) @@ -163,7 +158,7 @@ struct _GTypeInterface #define G_TYPE_CHECK_CLASS_CAST(g_class, g_type, c_type) (_G_TYPE_CCC ((g_class), (g_type), c_type)) #define G_TYPE_CHECK_CLASS_TYPE(g_class, g_type) (_G_TYPE_CCT ((g_class), (g_type))) #define G_TYPE_CHECK_VALUE(value) (_G_TYPE_CHV ((value))) -#define G_TYPE_CHECK_VALUE_TYPE(value, g_type) (_G_TYPE_CVT ((value), (g_type))) +#define G_TYPE_CHECK_VALUE_TYPE(value, g_type) (_G_TYPE_CVH ((value), (g_type))) #define G_TYPE_FROM_INSTANCE(instance) (G_TYPE_FROM_CLASS (((GTypeInstance*) (instance))->g_class)) #define G_TYPE_FROM_CLASS(g_class) (((GTypeClass*) (g_class))->g_type) #define G_TYPE_FROM_INTERFACE(g_iface) (((GTypeInterface*) (g_iface))->g_type) @@ -185,8 +180,8 @@ G_CONST_RETURN gchar* g_type_name (GType type); GQuark g_type_qname (GType type); GType g_type_from_name (const gchar *name); GType g_type_parent (GType type); -GType g_type_next_base (GType type, - GType base_type); +GType g_type_next_base (GType leaf_type, + GType root_type); gboolean g_type_is_a (GType type, GType is_a_type); guint g_type_fundamental_branch_last (GType type); @@ -235,7 +230,8 @@ typedef enum /*< skip >*/ } GTypeFundamentalFlags; typedef enum /*< skip >*/ { - G_TYPE_FLAG_ABSTRACT = (1 << 4) + G_TYPE_FLAG_ABSTRACT = (1 << 4), + G_TYPE_FLAG_VALUE_ABSTRACT = (1 << 5) } GTypeFlags; struct _GTypeInfo { @@ -335,8 +331,9 @@ GTypeClass* g_type_check_class_cast (GTypeClass *g_class, GType is_a_type); gboolean g_type_class_is_a (GTypeClass *g_class, GType is_a_type); +gboolean g_type_check_is_value_type (GType type); gboolean g_type_check_value (GValue *value); -gboolean g_type_value_is_a (GValue *value, +gboolean g_type_check_value_holds (GValue *value, GType type); GTypeValueTable* g_type_value_table_peek (GType type); @@ -354,7 +351,7 @@ GTypeValueTable* g_type_value_table_peek (GType type); #define _G_TYPE_CHI(ip) (g_type_check_instance ((GTypeInstance*) ip)) #define _G_TYPE_CIT(ip, gt) (g_type_instance_is_a ((GTypeInstance*) ip, gt)) #define _G_TYPE_CCT(cp, gt) (g_type_class_is_a ((GTypeClass*) cp, gt)) -#define _G_TYPE_CVT(vl, gt) (g_type_value_is_a ((GValue*) vl, gt)) +#define _G_TYPE_CVH(vl, gt) (g_type_check_value_holds ((GValue*) vl, gt)) #define _G_TYPE_CHV(vl) (g_type_check_value ((GValue*) vl)) #define _G_TYPE_IGC(ip, gt, ct) ((ct*) (((GTypeInstance*) ip)->g_class)) #define _G_TYPE_IGI(ip, gt, ct) ((ct*) g_type_interface_peek (((GTypeInstance*) ip)->g_class, gt)) diff --git a/gobject/gvalue.c b/gobject/gvalue.c index b7f6856c3..70a04d312 100644 --- a/gobject/gvalue.c +++ b/gobject/gvalue.c @@ -1,5 +1,5 @@ /* GObject - GLib Type, Object, Parameter and Signal Library - * Copyright (C) 1997, 1998, 1999, 2000 Tim Janik and Red Hat, Inc. + * Copyright (C) 1997-1999, 2000-2001 Tim Janik and Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -25,66 +25,130 @@ #include "gvalue.h" #include "gvaluecollector.h" +#include "gbsearcharray.h" /* --- typedefs & structures --- */ -typedef struct -{ - GType value_type1; - GType value_type2; - GValueExchange func; - GType first_type; -} ExchangeEntry; +typedef struct { + GType src_type; + GType dest_type; + GValueTransform func; +} TransformEntry; + + +/* --- prototypes --- */ +static gint transform_entries_cmp (gconstpointer bsearch_node1, + gconstpointer bsearch_node2); /* --- variables --- */ -static GHashTable *param_exchange_ht = NULL; +static GBSearchArray transform_array = { + transform_entries_cmp, + sizeof (TransformEntry), + 0, /* no flags */ + 0, NULL, +}; /* --- functions --- */ -void +static inline void /* keep this function in sync with gvaluecollector.h and gboxed.c */ +value_meminit (GValue *value, + GType value_type) +{ + value->g_type = value_type; + memset (value->data, 0, sizeof (value->data)); +} + +GValue* g_value_init (GValue *value, GType g_type) { - GTypeValueTable *value_table = g_type_value_table_peek (g_type); - - g_return_if_fail (value != NULL); - g_return_if_fail (G_VALUE_TYPE (value) == 0); - - if (value_table) + /* g_return_val_if_fail (G_TYPE_IS_VALUE (g_type), NULL); be more elaborate below */ + g_return_val_if_fail (value != NULL, NULL); + /* g_return_val_if_fail (G_VALUE_TYPE (value) == 0, NULL); be more elaborate below */ + + if (G_TYPE_IS_VALUE (g_type) && G_VALUE_TYPE (value) == 0) { - memset (value, 0, sizeof (*value)); - value->g_type = g_type; + GTypeValueTable *value_table = g_type_value_table_peek (g_type); + + /* setup and init */ + value_meminit (value, g_type); value_table->value_init (value); } - else - g_warning (G_STRLOC ": cannot initialize value of type `%s' which has no GTypeValueTable", - g_type_name (g_type)); + else if (G_VALUE_TYPE (value)) + g_warning ("%s: cannot initialize GValue with type `%s', the value has already been initialized as `%s'", + G_STRLOC, + g_type_name (g_type), + g_type_name (G_VALUE_TYPE (value))); + else /* !G_TYPE_IS_VALUE (g_type) */ + g_warning ("%s: cannot initialize GValue with type `%s', %s", + G_STRLOC, + g_type_name (g_type), + g_type_value_table_peek (g_type) ? + "this type is abstract with regards to GValue use, use a more specific (derived) type" : + "this type has no GTypeValueTable implementation"); + return value; } void g_value_copy (const GValue *src_value, GValue *dest_value) { - GTypeValueTable *value_table; - g_return_if_fail (G_IS_VALUE (src_value)); g_return_if_fail (G_IS_VALUE (dest_value)); - g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), G_VALUE_TYPE (dest_value))); - - value_table = g_type_value_table_peek (G_VALUE_TYPE (dest_value)); - if (!value_table) - g_return_if_fail (g_type_value_table_peek (G_VALUE_TYPE (dest_value)) != NULL); + g_return_if_fail (g_value_type_compatible (G_VALUE_TYPE (src_value), G_VALUE_TYPE (dest_value))); if (src_value != dest_value) { - /* make sure dest_value's value is free()d and zero initialized */ - g_value_reset (dest_value); - + GType dest_type = G_VALUE_TYPE (dest_value); + GTypeValueTable *value_table = g_type_value_table_peek (dest_type); + + /* make sure dest_value's value is free()d */ + if (value_table->value_free) + value_table->value_free (dest_value); + + /* setup and copy */ + value_meminit (dest_value, dest_type); value_table->value_copy (src_value, dest_value); } } +GValue* +g_value_reset (GValue *value) +{ + GTypeValueTable *value_table; + GType g_type; + + g_return_val_if_fail (G_IS_VALUE (value), NULL); + + g_type = G_VALUE_TYPE (value); + value_table = g_type_value_table_peek (g_type); + + /* make sure value's value is free()d */ + if (value_table->value_free) + value_table->value_free (value); + + /* setup and init */ + value_meminit (value, g_type); + value_table->value_init (value); + + return value; +} + +void +g_value_unset (GValue *value) +{ + GTypeValueTable *value_table; + + g_return_if_fail (G_IS_VALUE (value)); + + value_table = g_type_value_table_peek (G_VALUE_TYPE (value)); + + if (value_table->value_free) + value_table->value_free (value); + memset (value, 0, sizeof (*value)); +} + gboolean g_value_fits_pointer (const GValue *value) { @@ -93,22 +157,18 @@ g_value_fits_pointer (const GValue *value) g_return_val_if_fail (G_IS_VALUE (value), FALSE); value_table = g_type_value_table_peek (G_VALUE_TYPE (value)); - if (!value_table) - g_return_val_if_fail (g_type_value_table_peek (G_VALUE_TYPE (value)) != NULL, FALSE); return value_table->value_peek_pointer != NULL; } gpointer -g_value_get_as_pointer (const GValue *value) +g_value_peek_pointer (const GValue *value) { GTypeValueTable *value_table; g_return_val_if_fail (G_IS_VALUE (value), NULL); value_table = g_type_value_table_peek (G_VALUE_TYPE (value)); - if (!value_table) - g_return_val_if_fail (g_type_value_table_peek (G_VALUE_TYPE (value)) != NULL, NULL); if (!value_table->value_peek_pointer) g_return_val_if_fail (g_value_fits_pointer (value) == TRUE, NULL); @@ -119,231 +179,167 @@ void g_value_set_instance (GValue *value, gpointer instance) { - g_return_if_fail (G_IS_VALUE (value)); + GType g_type; + GTypeValueTable *value_table; + GTypeCValue cvalue; + gchar *error_msg; - g_value_reset (value); + g_return_if_fail (G_IS_VALUE (value)); if (instance) { - GType g_type = G_VALUE_TYPE (value); - GTypeValueTable *value_table = g_type_value_table_peek (g_type); - GTypeCValue cvalue = { 0, }; - gchar *error_msg; - g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance)); - g_return_if_fail (g_type_is_a (G_TYPE_FROM_INSTANCE (instance), G_VALUE_TYPE (value))); - g_return_if_fail (strcmp (value_table->collect_format, "p") == 0); + g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (instance), G_VALUE_TYPE (value))); + } + + g_type = G_VALUE_TYPE (value); + value_table = g_type_value_table_peek (g_type); + + g_return_if_fail (strcmp (value_table->collect_format, "p") == 0); + + memset (&cvalue, 0, sizeof (cvalue)); + cvalue.v_pointer = instance; + + /* make sure value's value is free()d */ + if (value_table->value_free) + value_table->value_free (value); + + /* setup and collect */ + value_meminit (value, g_type); + error_msg = value_table->collect_value (value, 1, &cvalue, 0); + if (error_msg) + { + g_warning ("%s: %s", G_STRLOC, error_msg); + g_free (error_msg); - cvalue.v_pointer = instance; - error_msg = value_table->collect_value (value, 1, &cvalue, 0); - - if (error_msg) - { - g_warning ("%s: %s", G_STRLOC, error_msg); - g_free (error_msg); - - /* we purposely leak the value here, it might not be - * in a sane state if an error condition occoured - */ - memset (value, 0, sizeof (*value)); - value->g_type = g_type; - value_table->value_init (value); - } + /* we purposely leak the value here, it might not be + * in a sane state if an error condition occoured + */ + value_meminit (value, g_type); + value_table->value_init (value); } } -void -g_value_unset (GValue *value) +static GValueTransform +transform_func_lookup (GType src_type, + GType dest_type) { - GTypeValueTable *value_table = g_type_value_table_peek (G_VALUE_TYPE (value)); - - g_return_if_fail (G_IS_VALUE (value)); - if (!value_table) - g_return_if_fail (g_type_value_table_peek (G_VALUE_TYPE (value)) != NULL); - - if (value_table->value_free) - value_table->value_free (value); - memset (value, 0, sizeof (*value)); -} + TransformEntry entry; -void -g_value_reset (GValue *value) -{ - GTypeValueTable *value_table; - GType g_type; - - g_return_if_fail (G_IS_VALUE (value)); - - value_table = g_type_value_table_peek (G_VALUE_TYPE (value)); - g_type = G_VALUE_TYPE (value); - - if (value_table->value_free) - value_table->value_free (value); - memset (value, 0, sizeof (*value)); - - value->g_type = g_type; - value_table->value_init (value); -} - -static gboolean -exchange_entries_equal (gconstpointer v1, - gconstpointer v2) -{ - const ExchangeEntry *entry1 = v1; - const ExchangeEntry *entry2 = v2; - - return (entry1->value_type1 == entry2->value_type1 && - entry1->value_type2 == entry2->value_type2); -} - -static guint -exchange_entry_hash (gconstpointer key) -{ - const ExchangeEntry *entry = key; - - return entry->value_type1 ^ entry->value_type2; -} - -static void -value_exchange_memcpy (GValue *value1, - GValue *value2) -{ - GValue tmp_value; - - memcpy (&tmp_value.data, &value1->data, sizeof (value1->data)); - memcpy (&value1->data, &value2->data, sizeof (value1->data)); - memcpy (&value2->data, &tmp_value.data, sizeof (value2->data)); -} - -static inline GValueExchange -exchange_func_lookup (GType value_type1, - GType value_type2, - gboolean *need_swap) -{ - if (value_type1 == value_type2) - return value_exchange_memcpy; - else + entry.src_type = src_type; + do { - GType type1 = value_type1; - + entry.dest_type = dest_type; do { - GType type2 = value_type2; + TransformEntry *e; - do + e = g_bsearch_array_lookup (&transform_array, &entry); + if (e) { - ExchangeEntry entry, *ret; - - entry.value_type1 = MIN (type1, type2); - entry.value_type2 = MAX (type1, type2); - ret = g_hash_table_lookup (param_exchange_ht, &entry); - if (ret) - { - if (need_swap) - *need_swap = ret->first_type == type2; - - return ret->func; - } - - type2 = g_type_parent (type2); + /* need to check that there hasn't been a change in value handling */ + if (g_type_value_table_peek (entry.dest_type) == g_type_value_table_peek (dest_type) && + g_type_value_table_peek (entry.src_type) == g_type_value_table_peek (src_type)) + return e->func; } - while (type2); - - type1 = g_type_parent (type1); + entry.dest_type = g_type_parent (entry.dest_type); } - while (type1); + while (entry.dest_type); + + entry.src_type = g_type_parent (entry.src_type); } - + while (entry.src_type); + return NULL; } -void -g_value_register_exchange_func (GType value_type1, - GType value_type2, - GValueExchange func) +static gint +transform_entries_cmp (gconstpointer bsearch_node1, + gconstpointer bsearch_node2) { - ExchangeEntry entry; - - g_return_if_fail (g_type_name (value_type1) != NULL); - g_return_if_fail (g_type_name (value_type2) != NULL); - g_return_if_fail (func != NULL); - - entry.value_type1 = MIN (value_type1, value_type2); - entry.value_type2 = MAX (value_type1, value_type2); - if (param_exchange_ht && g_hash_table_lookup (param_exchange_ht, &entry)) - g_warning (G_STRLOC ": cannot re-register param value exchange function " - "for `%s' and `%s'", - g_type_name (value_type1), - g_type_name (value_type2)); + const TransformEntry *e1 = bsearch_node1; + const TransformEntry *e2 = bsearch_node2; + gint cmp = G_BSEARCH_ARRAY_CMP (e1->src_type, e2->src_type); + + if (cmp) + return cmp; else - { - ExchangeEntry *entry = g_new (ExchangeEntry, 1); - - if (!param_exchange_ht) - param_exchange_ht = g_hash_table_new (exchange_entry_hash, exchange_entries_equal); - entry->value_type1 = MIN (value_type1, value_type2); - entry->value_type2 = MAX (value_type1, value_type2); - entry->func = func; - entry->first_type = value_type1; - g_hash_table_insert (param_exchange_ht, entry, entry); - } + return G_BSEARCH_ARRAY_CMP (e1->dest_type, e2->dest_type); +} + +void +g_value_register_transform_func (GType src_type, + GType dest_type, + GValueTransform transform_func) +{ + TransformEntry entry; + + g_return_if_fail (G_TYPE_HAS_VALUE_TABLE (src_type)); + g_return_if_fail (G_TYPE_HAS_VALUE_TABLE (dest_type)); + g_return_if_fail (transform_func != NULL); + + if (transform_func_lookup (src_type, dest_type)) + g_warning ("reregistering value transformation function (%p) for `%s' to `%s'", + transform_func, + g_type_name (src_type), + g_type_name (dest_type)); + entry.src_type = src_type; + entry.dest_type = dest_type; + entry.func = transform_func; + g_bsearch_array_insert (&transform_array, &entry, TRUE); } gboolean -g_value_types_exchangable (GType value_type1, - GType value_type2) +g_value_type_transformable (GType src_type, + GType dest_type) { - g_return_val_if_fail (G_TYPE_IS_VALUE (value_type1), FALSE); /* these might bite us, think G_TYPE_ENUM */ - g_return_val_if_fail (G_TYPE_IS_VALUE (value_type2), FALSE); - - return exchange_func_lookup (value_type1, value_type2, NULL) != NULL; + g_return_val_if_fail (G_TYPE_IS_VALUE (src_type), FALSE); + g_return_val_if_fail (G_TYPE_IS_VALUE (dest_type), FALSE); + + return (g_value_type_compatible (src_type, dest_type) || + transform_func_lookup (src_type, dest_type) != NULL); } gboolean -g_values_exchange (GValue *value1, - GValue *value2) +g_value_type_compatible (GType src_type, + GType dest_type) { - g_return_val_if_fail (G_IS_VALUE (value1), FALSE); - g_return_val_if_fail (G_IS_VALUE (value2), FALSE); - - if (value1 != value2) - { - gboolean need_swap; - GValueExchange value_exchange = exchange_func_lookup (G_VALUE_TYPE (value1), - G_VALUE_TYPE (value2), - &need_swap); - if (value_exchange) - { - if (need_swap) - value_exchange (value2, value1); - else - value_exchange (value1, value2); - } - - return value_exchange != NULL; - } - - return TRUE; + g_return_val_if_fail (G_TYPE_IS_VALUE (src_type), FALSE); + g_return_val_if_fail (G_TYPE_IS_VALUE (dest_type), FALSE); + + return (g_type_is_a (src_type, dest_type) && + g_type_value_table_peek (dest_type) == g_type_value_table_peek (src_type)); } gboolean -g_value_convert (const GValue *src_value, - GValue *dest_value) +g_value_transform (const GValue *src_value, + GValue *dest_value) { - gboolean success = TRUE; - + GType dest_type; + g_return_val_if_fail (G_IS_VALUE (src_value), FALSE); g_return_val_if_fail (G_IS_VALUE (dest_value), FALSE); - - if (src_value != dest_value) + + dest_type = G_VALUE_TYPE (dest_value); + if (g_value_type_compatible (G_VALUE_TYPE (src_value), dest_type)) { - GValue tmp_value = { 0, }; + g_value_copy (src_value, dest_value); - g_value_init (&tmp_value, G_VALUE_TYPE (src_value)); - g_value_copy (src_value, &tmp_value); - - success = g_values_exchange (&tmp_value, dest_value); - g_value_unset (&tmp_value); + return TRUE; } - - return success; + else + { + GValueTransform transform = transform_func_lookup (G_VALUE_TYPE (src_value), dest_type); + + if (transform) + { + g_value_unset (dest_value); + + /* setup and transform */ + value_meminit (dest_value, dest_type); + transform (src_value, dest_value); + + return TRUE; + } + } + return FALSE; } diff --git a/gobject/gvalue.h b/gobject/gvalue.h index 54d6498b4..bef28a777 100644 --- a/gobject/gvalue.h +++ b/gobject/gvalue.h @@ -1,5 +1,5 @@ /* GObject - GLib Type, Object, Parameter and Signal Library - * Copyright (C) 1997, 1998, 1999, 2000 Tim Janik and Red Hat, Inc. + * Copyright (C) 1997-1999, 2000-2001 Tim Janik and Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -32,14 +32,16 @@ extern "C" { /* --- type macros --- */ #define G_TYPE_IS_VALUE(type) (g_type_value_table_peek (type) != NULL) #define G_IS_VALUE(value) (G_TYPE_CHECK_VALUE (value)) -#define G_VALUE_HOLDS(value, g_type) (G_TYPE_CHECK_VALUE_TYPE ((value), (g_type))) #define G_VALUE_TYPE(value) (((GValue*) (value))->g_type) #define G_VALUE_TYPE_NAME(value) (g_type_name (G_VALUE_TYPE (value))) +#define G_VALUE_HOLDS(value,type) (G_TYPE_CHECK_VALUE_TYPE ((value), (type))) /* --- typedefs & structures --- */ -typedef void (*GValueExchange) (GValue *value1, - GValue *value2); +typedef void (*GValueExchange) (GValue *value1, + GValue *value2); +typedef void (*GValueTransform) (const GValue *src_value, + GValue *dest_value); struct _GValue { /*< private >*/ @@ -59,28 +61,33 @@ struct _GValue /* --- prototypes --- */ -void g_value_init (GValue *value, +GValue* g_value_init (GValue *value, GType g_type); void g_value_copy (const GValue *src_value, GValue *dest_value); gboolean g_value_convert (const GValue *src_value, GValue *dest_value); -void g_value_reset (GValue *value); +GValue* g_value_reset (GValue *value); void g_value_unset (GValue *value); -gboolean g_value_fits_pointer (const GValue *value); -gpointer g_value_get_as_pointer (const GValue *value); void g_value_set_instance (GValue *value, gpointer instance); +/* --- private --- */ +gboolean g_value_fits_pointer (const GValue *value); +gpointer g_value_peek_pointer (const GValue *value); + + /* --- implementation details --- */ -gboolean g_values_exchange (GValue *value1, - GValue *value2); -gboolean g_value_types_exchangable (GType value_type1, - GType value_type2); -void g_value_register_exchange_func (GType value_type1, - GType value_type2, - GValueExchange func); +gboolean g_value_type_compatible (GType src_type, + GType dest_type); +gboolean g_value_type_transformable (GType src_type, + GType dest_type); +gboolean g_value_transform (const GValue *src_value, + GValue *dest_value); +void g_value_register_transform_func (GType src_type, + GType dest_type, + GValueTransform transform_func); #define G_VALUE_NOCOPY_CONTENTS (1 << 27) diff --git a/gobject/gvaluearray.c b/gobject/gvaluearray.c new file mode 100644 index 000000000..30bc6b9e6 --- /dev/null +++ b/gobject/gvaluearray.c @@ -0,0 +1,184 @@ +/* GObject - GLib Type, Object, Parameter and Signal Library + * Copyright (C) 2001 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* + * MT safe + */ + +#include "gvaluearray.h" +#include +#include /* qsort() */ + + + +/* --- functions --- */ +GValue* +g_value_array_get_nth (GValueArray *value_array, + guint index) +{ + g_return_val_if_fail (value_array != NULL, NULL); + g_return_val_if_fail (index < value_array->n_values, NULL); + + return value_array->values + index; +} + +GValueArray* +g_value_array_new (guint n_prealloced) +{ + GValueArray *value_array = g_new0 (GValueArray, 1); + + value_array->n_values = n_prealloced; + value_array->values = g_renew (GValue, value_array->values, value_array->n_values); + memset (value_array->values, 0, value_array->n_values * sizeof (value_array->values[0])); + + return value_array; +} + +void +g_value_array_free (GValueArray *value_array) +{ + guint i; + + g_return_if_fail (value_array != NULL); + + for (i = 0; i < value_array->n_values; i++) + { + GValue *value = value_array->values + i; + + if (G_VALUE_TYPE (value) != 0) /* we allow unset values in the array */ + g_value_unset (value); + } + g_free (value_array->values); + g_free (value_array); +} + +GValueArray* +g_value_array_copy (const GValueArray *value_array) +{ + GValueArray *new_array; + guint i; + + g_return_val_if_fail (value_array != NULL, NULL); + + new_array = g_new0 (GValueArray, 1); + new_array->n_values = value_array->n_values; + new_array->values = g_renew (GValue, new_array->values, new_array->n_values); + memset (new_array->values, 0, new_array->n_values * sizeof (new_array->values[0])); + for (i = 0; i < new_array->n_values; i++) + if (G_VALUE_TYPE (value_array->values + i) != 0) + { + GValue *value = new_array->values + i; + + g_value_init (value, G_VALUE_TYPE (value_array->values + i)); + g_value_copy (value_array->values + i, value); + } + return new_array; +} + +GValueArray* +g_value_array_prepend (GValueArray *value_array, + const GValue *value) +{ + g_return_val_if_fail (value_array != NULL, NULL); + + return g_value_array_insert (value_array, 0, value); +} + +GValueArray* +g_value_array_append (GValueArray *value_array, + const GValue *value) +{ + g_return_val_if_fail (value_array != NULL, NULL); + + return g_value_array_insert (value_array, value_array->n_values, value); +} + +GValueArray* +g_value_array_insert (GValueArray *value_array, + guint index, + const GValue *value) +{ + guint i; + + g_return_val_if_fail (value_array != NULL, NULL); + g_return_val_if_fail (index <= value_array->n_values, value_array); + + /* we support NULL for "value" as a shortcut for an unset value */ + + i = value_array->n_values++; + value_array->values = g_renew (GValue, value_array->values, value_array->n_values); + if (index + 1 < value_array->n_values) + g_memmove (value_array->values + index + 1, value_array->values + index, + (i - index) * sizeof (value_array->values[0])); + memset (value_array->values + index, 0, sizeof (value_array->values[0])); + if (value) + { + g_value_init (value_array->values + index, G_VALUE_TYPE (value)); + g_value_copy (value, value_array->values + index); + } + return value_array; +} + +GValueArray* +g_value_array_remove (GValueArray *value_array, + guint index) +{ + g_return_val_if_fail (value_array != NULL, NULL); + g_return_val_if_fail (index < value_array->n_values, value_array); + + if (G_VALUE_TYPE (value_array->values + index) != 0) + g_value_unset (value_array->values + index); + value_array->n_values--; + if (index < value_array->n_values) + g_memmove (value_array->values + index, value_array->values + index + 1, + (value_array->n_values - index) * sizeof (value_array->values[0])); + value_array->values = g_renew (GValue, value_array->values, value_array->n_values); + + return value_array; +} + +GValueArray* +g_value_array_sort (GValueArray *value_array, + GCompareFunc compare_func) +{ + g_return_val_if_fail (compare_func != NULL, NULL); + + if (value_array->n_values) + qsort (value_array->values, + value_array->n_values, + sizeof (value_array->values[0]), + compare_func); + return value_array; +} + +GValueArray* +g_value_array_sort_with_data (GValueArray *value_array, + GCompareDataFunc compare_func, + gpointer user_data) +{ + g_return_val_if_fail (value_array != NULL, NULL); + g_return_val_if_fail (compare_func != NULL, NULL); + + if (value_array->n_values) + g_qsort_with_data (value_array->values, + value_array->n_values, + sizeof (value_array->values[0]), + compare_func, user_data); + return value_array; +} diff --git a/gobject/gvaluearray.h b/gobject/gvaluearray.h new file mode 100644 index 000000000..21fcfbd3e --- /dev/null +++ b/gobject/gvaluearray.h @@ -0,0 +1,69 @@ +/* GObject - GLib Type, Object, Parameter and Signal Library + * Copyright (C) 2001 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + * + * gvaluearray.h: GLib array type holding GValues + */ +#ifndef __G_VALUE_ARRAY_H__ +#define __G_VALUE_ARRAY_H__ + + +#include + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +/* --- typedefs & structs --- */ +typedef struct _GValueArray GValueArray; +struct _GValueArray +{ + guint n_values; + GValue *values; +}; + + +/* --- prototypes --- */ +GValue* g_value_array_get_nth (GValueArray *value_array, + guint index); +GValueArray* g_value_array_new (guint n_prealloced); +void g_value_array_free (GValueArray *value_array); +GValueArray* g_value_array_copy (const GValueArray *value_array); +GValueArray* g_value_array_prepend (GValueArray *value_array, + const GValue *value); +GValueArray* g_value_array_append (GValueArray *value_array, + const GValue *value); +GValueArray* g_value_array_insert (GValueArray *value_array, + guint index, + const GValue *value); +GValueArray* g_value_array_remove (GValueArray *value_array, + guint index); +GValueArray* g_value_array_sort (GValueArray *value_array, + GCompareFunc compare_func); +GValueArray* g_value_array_sort_with_data (GValueArray *value_array, + GCompareDataFunc compare_func, + gpointer user_data); + + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __G_VALUE_ARRAY_H__ */ diff --git a/gobject/gvaluecollector.h b/gobject/gvaluecollector.h index b34a21a7a..55b613d81 100644 --- a/gobject/gvaluecollector.h +++ b/gobject/gvaluecollector.h @@ -1,5 +1,5 @@ /* GObject - GLib Type, Object, Parameter and Signal Library - * Copyright (C) 1998, 1999, 2000 Tim Janik and Red Hat, Inc. + * Copyright (C) 1998-1999, 2000-2001 Tim Janik and Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -66,12 +66,16 @@ union _GTypeCValue G_STMT_START { \ GValue *_value = (value); \ guint _flags = (flags); \ - GTypeValueTable *_vtable = g_type_value_table_peek (G_VALUE_TYPE (_value)); \ + GType _value_type = G_VALUE_TYPE (_value); \ + GTypeValueTable *_vtable = g_type_value_table_peek (_value_type); \ gchar *_collect_format = _vtable->collect_format; \ GTypeCValue _cvalues[G_VALUE_COLLECT_FORMAT_MAX_LENGTH] = { { 0, }, }; \ guint _n_values = 0; \ \ - g_value_reset (_value); \ + if (_vtable->value_free) \ + _vtable->value_free (_value); \ + _value->g_type = _value_type; /* value_meminit() from gvalue.c */ \ + memset (_value->data, 0, sizeof (_value->data)); \ while (*_collect_format) \ { \ GTypeCValue *_cvalue = _cvalues + _n_values++; \ @@ -108,7 +112,8 @@ G_STMT_START { \ G_STMT_START { \ GValue *_value = (value); \ guint _flags = (flags); \ - GTypeValueTable *_vtable = g_type_value_table_peek (G_VALUE_TYPE (_value)); \ + GType _value_type = G_VALUE_TYPE (_value); \ + GTypeValueTable *_vtable = g_type_value_table_peek (_value_type); \ gchar *_lcopy_format = _vtable->lcopy_format; \ GTypeCValue _cvalues[G_VALUE_COLLECT_FORMAT_MAX_LENGTH] = { { 0, }, }; \ guint _n_values = 0; \ diff --git a/gobject/gvaluetransform.c b/gobject/gvaluetransform.c new file mode 100644 index 000000000..065f31ef3 --- /dev/null +++ b/gobject/gvaluetransform.c @@ -0,0 +1,339 @@ +/* GObject - GLib Type, Object, Parameter and Signal Library + * Copyright (C) 2001 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + */ +#include "gvalue.h" +#include "genums.h" + + +/* same type transforms + */ +static void +value_transform_memcpy_data0 (const GValue *src_value, + GValue *dest_value) +{ + memcpy (&dest_value->data[0], &src_value->data[0], sizeof (src_value->data[0])); +} +#define value_transform_int_int value_transform_memcpy_data0 +#define value_transform_uint_uint value_transform_memcpy_data0 +#define value_transform_long_long value_transform_memcpy_data0 +#define value_transform_ulong_ulong value_transform_memcpy_data0 +#define value_transform_float_float value_transform_memcpy_data0 +#define value_transform_double_double value_transform_memcpy_data0 + + +/* numeric casts + */ +#define DEFINE_CAST(func_name, from_member, ctype, to_member) \ + static void \ + value_transform_##func_name (const GValue *src_value, \ + GValue *dest_value) \ + { \ + ctype c_value = src_value->data[0].##from_member; \ + dest_value->data[0].##to_member = c_value; \ + } +DEFINE_CAST (int_s8, v_int, gint8, v_int); +DEFINE_CAST (int_u8, v_int, guint8, v_uint); +DEFINE_CAST (int_uint, v_int, guint, v_uint); +DEFINE_CAST (int_long, v_int, glong, v_long); +DEFINE_CAST (int_ulong, v_int, gulong, v_ulong); +DEFINE_CAST (int_float, v_int, gfloat, v_float); +DEFINE_CAST (int_double, v_int, gdouble, v_double); +DEFINE_CAST (uint_s8, v_uint, gint8, v_int); +DEFINE_CAST (uint_u8, v_uint, guint8, v_uint); +DEFINE_CAST (uint_int, v_uint, gint, v_int); +DEFINE_CAST (uint_long, v_uint, glong, v_long); +DEFINE_CAST (uint_ulong, v_uint, gulong, v_ulong); +DEFINE_CAST (uint_float, v_uint, gfloat, v_float); +DEFINE_CAST (uint_double, v_uint, gdouble, v_double); +DEFINE_CAST (long_s8, v_long, gint8, v_int); +DEFINE_CAST (long_u8, v_long, guint8, v_uint); +DEFINE_CAST (long_int, v_long, gint, v_int); +DEFINE_CAST (long_uint, v_long, guint, v_uint); +DEFINE_CAST (long_ulong, v_long, gulong, v_ulong); +DEFINE_CAST (long_float, v_long, gfloat, v_float); +DEFINE_CAST (long_double, v_long, gdouble, v_double); +DEFINE_CAST (ulong_s8, v_ulong, gint8, v_int); +DEFINE_CAST (ulong_u8, v_ulong, guint8, v_uint); +DEFINE_CAST (ulong_int, v_ulong, gint, v_int); +DEFINE_CAST (ulong_uint, v_ulong, guint, v_uint); +DEFINE_CAST (ulong_long, v_ulong, glong, v_long); +DEFINE_CAST (ulong_float, v_ulong, gfloat, v_float); +DEFINE_CAST (ulong_double, v_ulong, gdouble, v_double); +DEFINE_CAST (float_s8, v_float, gint8, v_int); +DEFINE_CAST (float_u8, v_float, guint8, v_uint); +DEFINE_CAST (float_int, v_float, gint, v_int); +DEFINE_CAST (float_uint, v_float, guint, v_uint); +DEFINE_CAST (float_long, v_float, glong, v_long); +DEFINE_CAST (float_ulong, v_float, gulong, v_ulong); +DEFINE_CAST (float_double, v_float, gdouble, v_double); +DEFINE_CAST (double_s8, v_double, gint8, v_int); +DEFINE_CAST (double_u8, v_double, guint8, v_uint); +DEFINE_CAST (double_int, v_double, gint, v_int); +DEFINE_CAST (double_uint, v_double, guint, v_uint); +DEFINE_CAST (double_long, v_double, glong, v_long); +DEFINE_CAST (double_ulong, v_double, gulong, v_ulong); +DEFINE_CAST (double_float, v_double, gfloat, v_float); + + +/* boolean assignments + */ +#define DEFINE_BOOL_CHECK(func_name, from_member) \ + static void \ + value_transform_##func_name (const GValue *src_value, \ + GValue *dest_value) \ + { \ + dest_value->data[0].v_int = src_value->data[0].##from_member != 0; \ + } +DEFINE_BOOL_CHECK (int_bool, v_int); +DEFINE_BOOL_CHECK (uint_bool, v_uint); +DEFINE_BOOL_CHECK (long_bool, v_long); +DEFINE_BOOL_CHECK (ulong_bool, v_uint); + + +/* string printouts + */ +#define DEFINE_SPRINTF(func_name, from_member, format) \ + static void \ + value_transform_##func_name (const GValue *src_value, \ + GValue *dest_value) \ + { \ + dest_value->data[0].v_pointer = \ + g_strdup_printf ((format), src_value->data[0].##from_member); \ + } +DEFINE_SPRINTF (int_string, v_int, "%d"); +DEFINE_SPRINTF (uint_string, v_uint, "%u"); +DEFINE_SPRINTF (long_string, v_long, "%ld"); +DEFINE_SPRINTF (ulong_string, v_ulong, "%lu"); +DEFINE_SPRINTF (float_string, v_float, "%f"); +DEFINE_SPRINTF (double_string, v_double, "%f"); + + +/* special cases + */ +static void +value_transform_bool_string (const GValue *src_value, + GValue *dest_value) +{ + dest_value->data[0].v_pointer = g_strdup_printf ("%s", + src_value->data[0].v_int ? + "TRUE" : "FALSE"); +} +static void +value_transform_string_string (const GValue *src_value, + GValue *dest_value) +{ + dest_value->data[0].v_pointer = g_strdup (src_value->data[0].v_pointer); +} +static void +value_transform_enum_string (const GValue *src_value, + GValue *dest_value) +{ + GEnumClass *class = g_type_class_ref (G_VALUE_TYPE (src_value)); + GEnumValue *enum_value = g_enum_get_value (class, src_value->data[0].v_int); + + if (enum_value) + dest_value->data[0].v_pointer = g_strdup (enum_value->value_name); + else + dest_value->data[0].v_pointer = g_strdup_printf ("%d", src_value->data[0].v_int); + + g_type_class_unref (class); +} +static void +value_transform_flags_string (const GValue *src_value, + GValue *dest_value) +{ + GFlagsClass *class = g_type_class_ref (G_VALUE_TYPE (src_value)); + GFlagsValue *flags_value = g_flags_get_first_value (class, src_value->data[0].v_uint); + + if (flags_value) + { + GString *gstring = g_string_new (""); + guint v_flags = src_value->data[0].v_uint; + + do + { + v_flags &= ~flags_value->value; + + if (gstring->str[0]) + g_string_append (gstring, " | "); + g_string_append (gstring, flags_value->value_name); + flags_value = g_flags_get_first_value (class, v_flags); + } + while (flags_value); + + if (v_flags) + dest_value->data[0].v_pointer = g_strdup_printf ("%s | %u", + gstring->str, + v_flags); + else + dest_value->data[0].v_pointer = g_strdup (gstring->str); + g_string_free (gstring, TRUE); + } + else + dest_value->data[0].v_pointer = g_strdup_printf ("%u", src_value->data[0].v_uint); + + g_type_class_unref (class); +} + + +/* registration + */ +void +g_value_transforms_init (void) /* sync with gtype.c */ +{ + /* some transformations are a bit questionable, + * we currently skip those + */ +#define SKIP____register_transform_func(type1,type2,transform_func) /* skip questionable transforms */ + + /* numeric types (plus to string) */ + g_value_register_transform_func (G_TYPE_CHAR, G_TYPE_CHAR, value_transform_int_int); + g_value_register_transform_func (G_TYPE_CHAR, G_TYPE_UCHAR, value_transform_int_u8); + g_value_register_transform_func (G_TYPE_CHAR, G_TYPE_BOOLEAN, value_transform_int_bool); + g_value_register_transform_func (G_TYPE_CHAR, G_TYPE_INT, value_transform_int_int); + g_value_register_transform_func (G_TYPE_CHAR, G_TYPE_UINT, value_transform_int_uint); + g_value_register_transform_func (G_TYPE_CHAR, G_TYPE_LONG, value_transform_int_long); + g_value_register_transform_func (G_TYPE_CHAR, G_TYPE_ULONG, value_transform_int_ulong); + g_value_register_transform_func (G_TYPE_CHAR, G_TYPE_ENUM, value_transform_int_int); + g_value_register_transform_func (G_TYPE_CHAR, G_TYPE_FLAGS, value_transform_int_uint); + g_value_register_transform_func (G_TYPE_CHAR, G_TYPE_FLOAT, value_transform_int_float); + g_value_register_transform_func (G_TYPE_CHAR, G_TYPE_DOUBLE, value_transform_int_double); + g_value_register_transform_func (G_TYPE_CHAR, G_TYPE_STRING, value_transform_int_string); + g_value_register_transform_func (G_TYPE_UCHAR, G_TYPE_CHAR, value_transform_uint_s8); + g_value_register_transform_func (G_TYPE_UCHAR, G_TYPE_UCHAR, value_transform_uint_uint); + g_value_register_transform_func (G_TYPE_UCHAR, G_TYPE_BOOLEAN, value_transform_uint_bool); + g_value_register_transform_func (G_TYPE_UCHAR, G_TYPE_INT, value_transform_uint_int); + g_value_register_transform_func (G_TYPE_UCHAR, G_TYPE_UINT, value_transform_uint_uint); + g_value_register_transform_func (G_TYPE_UCHAR, G_TYPE_LONG, value_transform_uint_long); + g_value_register_transform_func (G_TYPE_UCHAR, G_TYPE_ULONG, value_transform_uint_ulong); + g_value_register_transform_func (G_TYPE_UCHAR, G_TYPE_ENUM, value_transform_uint_int); + g_value_register_transform_func (G_TYPE_UCHAR, G_TYPE_FLAGS, value_transform_uint_uint); + g_value_register_transform_func (G_TYPE_UCHAR, G_TYPE_FLOAT, value_transform_uint_float); + g_value_register_transform_func (G_TYPE_UCHAR, G_TYPE_DOUBLE, value_transform_uint_double); + g_value_register_transform_func (G_TYPE_UCHAR, G_TYPE_STRING, value_transform_uint_string); + g_value_register_transform_func (G_TYPE_BOOLEAN, G_TYPE_CHAR, value_transform_int_s8); + g_value_register_transform_func (G_TYPE_BOOLEAN, G_TYPE_UCHAR, value_transform_int_u8); + g_value_register_transform_func (G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, value_transform_int_int); + g_value_register_transform_func (G_TYPE_BOOLEAN, G_TYPE_INT, value_transform_int_int); + g_value_register_transform_func (G_TYPE_BOOLEAN, G_TYPE_UINT, value_transform_int_uint); + g_value_register_transform_func (G_TYPE_BOOLEAN, G_TYPE_LONG, value_transform_int_long); + g_value_register_transform_func (G_TYPE_BOOLEAN, G_TYPE_ULONG, value_transform_int_ulong); + g_value_register_transform_func (G_TYPE_BOOLEAN, G_TYPE_ENUM, value_transform_int_int); + g_value_register_transform_func (G_TYPE_BOOLEAN, G_TYPE_FLAGS, value_transform_int_uint); + SKIP____register_transform_func (G_TYPE_BOOLEAN, G_TYPE_FLOAT, value_transform_int_float); + SKIP____register_transform_func (G_TYPE_BOOLEAN, G_TYPE_DOUBLE, value_transform_int_double); + g_value_register_transform_func (G_TYPE_BOOLEAN, G_TYPE_STRING, value_transform_bool_string); + g_value_register_transform_func (G_TYPE_INT, G_TYPE_CHAR, value_transform_int_s8); + g_value_register_transform_func (G_TYPE_INT, G_TYPE_UCHAR, value_transform_int_u8); + g_value_register_transform_func (G_TYPE_INT, G_TYPE_BOOLEAN, value_transform_int_bool); + g_value_register_transform_func (G_TYPE_INT, G_TYPE_INT, value_transform_int_int); + g_value_register_transform_func (G_TYPE_INT, G_TYPE_UINT, value_transform_int_uint); + g_value_register_transform_func (G_TYPE_INT, G_TYPE_LONG, value_transform_int_long); + g_value_register_transform_func (G_TYPE_INT, G_TYPE_ULONG, value_transform_int_ulong); + g_value_register_transform_func (G_TYPE_INT, G_TYPE_ENUM, value_transform_int_int); + g_value_register_transform_func (G_TYPE_INT, G_TYPE_FLAGS, value_transform_int_uint); + g_value_register_transform_func (G_TYPE_INT, G_TYPE_FLOAT, value_transform_int_float); + g_value_register_transform_func (G_TYPE_INT, G_TYPE_DOUBLE, value_transform_int_double); + g_value_register_transform_func (G_TYPE_INT, G_TYPE_STRING, value_transform_int_string); + g_value_register_transform_func (G_TYPE_UINT, G_TYPE_CHAR, value_transform_uint_s8); + g_value_register_transform_func (G_TYPE_UINT, G_TYPE_UCHAR, value_transform_uint_u8); + g_value_register_transform_func (G_TYPE_UINT, G_TYPE_BOOLEAN, value_transform_uint_bool); + g_value_register_transform_func (G_TYPE_UINT, G_TYPE_INT, value_transform_uint_int); + g_value_register_transform_func (G_TYPE_UINT, G_TYPE_UINT, value_transform_uint_uint); + g_value_register_transform_func (G_TYPE_UINT, G_TYPE_LONG, value_transform_uint_long); + g_value_register_transform_func (G_TYPE_UINT, G_TYPE_ULONG, value_transform_uint_ulong); + g_value_register_transform_func (G_TYPE_UINT, G_TYPE_ENUM, value_transform_uint_int); + g_value_register_transform_func (G_TYPE_UINT, G_TYPE_FLAGS, value_transform_uint_uint); + g_value_register_transform_func (G_TYPE_UINT, G_TYPE_FLOAT, value_transform_uint_float); + g_value_register_transform_func (G_TYPE_UINT, G_TYPE_DOUBLE, value_transform_uint_double); + g_value_register_transform_func (G_TYPE_UINT, G_TYPE_STRING, value_transform_uint_string); + g_value_register_transform_func (G_TYPE_LONG, G_TYPE_CHAR, value_transform_long_s8); + g_value_register_transform_func (G_TYPE_LONG, G_TYPE_UCHAR, value_transform_long_u8); + g_value_register_transform_func (G_TYPE_LONG, G_TYPE_BOOLEAN, value_transform_long_bool); + g_value_register_transform_func (G_TYPE_LONG, G_TYPE_INT, value_transform_long_int); + g_value_register_transform_func (G_TYPE_LONG, G_TYPE_UINT, value_transform_long_uint); + g_value_register_transform_func (G_TYPE_LONG, G_TYPE_LONG, value_transform_long_long); + g_value_register_transform_func (G_TYPE_LONG, G_TYPE_ULONG, value_transform_long_ulong); + g_value_register_transform_func (G_TYPE_LONG, G_TYPE_ENUM, value_transform_long_int); + g_value_register_transform_func (G_TYPE_LONG, G_TYPE_FLAGS, value_transform_long_uint); + g_value_register_transform_func (G_TYPE_LONG, G_TYPE_FLOAT, value_transform_long_float); + g_value_register_transform_func (G_TYPE_LONG, G_TYPE_DOUBLE, value_transform_long_double); + g_value_register_transform_func (G_TYPE_LONG, G_TYPE_STRING, value_transform_long_string); + g_value_register_transform_func (G_TYPE_ULONG, G_TYPE_CHAR, value_transform_ulong_s8); + g_value_register_transform_func (G_TYPE_ULONG, G_TYPE_UCHAR, value_transform_ulong_u8); + g_value_register_transform_func (G_TYPE_ULONG, G_TYPE_BOOLEAN, value_transform_ulong_bool); + g_value_register_transform_func (G_TYPE_ULONG, G_TYPE_INT, value_transform_ulong_int); + g_value_register_transform_func (G_TYPE_ULONG, G_TYPE_UINT, value_transform_ulong_uint); + g_value_register_transform_func (G_TYPE_ULONG, G_TYPE_LONG, value_transform_ulong_long); + g_value_register_transform_func (G_TYPE_ULONG, G_TYPE_ULONG, value_transform_ulong_ulong); + g_value_register_transform_func (G_TYPE_ULONG, G_TYPE_ENUM, value_transform_ulong_int); + g_value_register_transform_func (G_TYPE_ULONG, G_TYPE_FLAGS, value_transform_ulong_uint); + g_value_register_transform_func (G_TYPE_ULONG, G_TYPE_FLOAT, value_transform_ulong_float); + g_value_register_transform_func (G_TYPE_ULONG, G_TYPE_DOUBLE, value_transform_ulong_double); + g_value_register_transform_func (G_TYPE_ULONG, G_TYPE_STRING, value_transform_ulong_string); + g_value_register_transform_func (G_TYPE_ENUM, G_TYPE_CHAR, value_transform_int_s8); + g_value_register_transform_func (G_TYPE_ENUM, G_TYPE_UCHAR, value_transform_int_u8); + SKIP____register_transform_func (G_TYPE_ENUM, G_TYPE_BOOLEAN, value_transform_int_bool); + g_value_register_transform_func (G_TYPE_ENUM, G_TYPE_INT, value_transform_int_int); + g_value_register_transform_func (G_TYPE_ENUM, G_TYPE_UINT, value_transform_int_uint); + g_value_register_transform_func (G_TYPE_ENUM, G_TYPE_LONG, value_transform_int_long); + g_value_register_transform_func (G_TYPE_ENUM, G_TYPE_ULONG, value_transform_int_ulong); + g_value_register_transform_func (G_TYPE_ENUM, G_TYPE_ENUM, value_transform_int_int); + g_value_register_transform_func (G_TYPE_ENUM, G_TYPE_FLAGS, value_transform_int_uint); + SKIP____register_transform_func (G_TYPE_ENUM, G_TYPE_FLOAT, value_transform_int_float); + SKIP____register_transform_func (G_TYPE_ENUM, G_TYPE_DOUBLE, value_transform_int_double); + g_value_register_transform_func (G_TYPE_ENUM, G_TYPE_STRING, value_transform_enum_string); + g_value_register_transform_func (G_TYPE_FLAGS, G_TYPE_CHAR, value_transform_uint_s8); + g_value_register_transform_func (G_TYPE_FLAGS, G_TYPE_UCHAR, value_transform_uint_u8); + SKIP____register_transform_func (G_TYPE_FLAGS, G_TYPE_BOOLEAN, value_transform_uint_bool); + g_value_register_transform_func (G_TYPE_FLAGS, G_TYPE_INT, value_transform_uint_int); + g_value_register_transform_func (G_TYPE_FLAGS, G_TYPE_UINT, value_transform_uint_uint); + g_value_register_transform_func (G_TYPE_FLAGS, G_TYPE_LONG, value_transform_uint_long); + g_value_register_transform_func (G_TYPE_FLAGS, G_TYPE_ULONG, value_transform_uint_ulong); + SKIP____register_transform_func (G_TYPE_FLAGS, G_TYPE_ENUM, value_transform_uint_int); + g_value_register_transform_func (G_TYPE_FLAGS, G_TYPE_FLAGS, value_transform_uint_uint); + SKIP____register_transform_func (G_TYPE_FLAGS, G_TYPE_FLOAT, value_transform_uint_float); + SKIP____register_transform_func (G_TYPE_FLAGS, G_TYPE_DOUBLE, value_transform_uint_double); + g_value_register_transform_func (G_TYPE_FLAGS, G_TYPE_STRING, value_transform_flags_string); + g_value_register_transform_func (G_TYPE_FLOAT, G_TYPE_CHAR, value_transform_float_s8); + g_value_register_transform_func (G_TYPE_FLOAT, G_TYPE_UCHAR, value_transform_float_u8); + SKIP____register_transform_func (G_TYPE_FLOAT, G_TYPE_BOOLEAN, value_transform_float_bool); + g_value_register_transform_func (G_TYPE_FLOAT, G_TYPE_INT, value_transform_float_int); + g_value_register_transform_func (G_TYPE_FLOAT, G_TYPE_UINT, value_transform_float_uint); + g_value_register_transform_func (G_TYPE_FLOAT, G_TYPE_LONG, value_transform_float_long); + g_value_register_transform_func (G_TYPE_FLOAT, G_TYPE_ULONG, value_transform_float_ulong); + SKIP____register_transform_func (G_TYPE_FLOAT, G_TYPE_ENUM, value_transform_float_int); + SKIP____register_transform_func (G_TYPE_FLOAT, G_TYPE_FLAGS, value_transform_float_uint); + g_value_register_transform_func (G_TYPE_FLOAT, G_TYPE_FLOAT, value_transform_float_float); + g_value_register_transform_func (G_TYPE_FLOAT, G_TYPE_DOUBLE, value_transform_float_double); + g_value_register_transform_func (G_TYPE_FLOAT, G_TYPE_STRING, value_transform_float_string); + g_value_register_transform_func (G_TYPE_DOUBLE, G_TYPE_CHAR, value_transform_double_s8); + g_value_register_transform_func (G_TYPE_DOUBLE, G_TYPE_UCHAR, value_transform_double_u8); + SKIP____register_transform_func (G_TYPE_DOUBLE, G_TYPE_BOOLEAN, value_transform_double_bool); + g_value_register_transform_func (G_TYPE_DOUBLE, G_TYPE_INT, value_transform_double_int); + g_value_register_transform_func (G_TYPE_DOUBLE, G_TYPE_UINT, value_transform_double_uint); + g_value_register_transform_func (G_TYPE_DOUBLE, G_TYPE_LONG, value_transform_double_long); + g_value_register_transform_func (G_TYPE_DOUBLE, G_TYPE_ULONG, value_transform_double_ulong); + SKIP____register_transform_func (G_TYPE_DOUBLE, G_TYPE_ENUM, value_transform_double_int); + SKIP____register_transform_func (G_TYPE_DOUBLE, G_TYPE_FLAGS, value_transform_double_uint); + g_value_register_transform_func (G_TYPE_DOUBLE, G_TYPE_FLOAT, value_transform_double_float); + g_value_register_transform_func (G_TYPE_DOUBLE, G_TYPE_DOUBLE, value_transform_double_double); + g_value_register_transform_func (G_TYPE_DOUBLE, G_TYPE_STRING, value_transform_double_string); + /* string types */ + g_value_register_transform_func (G_TYPE_STRING, G_TYPE_STRING, value_transform_string_string); +} diff --git a/gobject/gvaluetypes.c b/gobject/gvaluetypes.c index 1e8ae92cd..d148f03b9 100644 --- a/gobject/gvaluetypes.c +++ b/gobject/gvaluetypes.c @@ -1,5 +1,5 @@ /* GObject - GLib Type, Object, Parameter and Signal Library - * Copyright (C) 1997, 1998, 1999, 2000 Tim Janik and Red Hat, Inc. + * Copyright (C) 1997-1999, 2000-2001 Tim Janik and Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -25,27 +25,28 @@ #include "gvaluecollector.h" #include +#include /* qsort() */ /* --- value functions --- */ static void -value_long0_init (GValue *value) +value_init_long0 (GValue *value) { value->data[0].v_long = 0; } static void -value_long0_copy (const GValue *src_value, +value_copy_long0 (const GValue *src_value, GValue *dest_value) { dest_value->data[0].v_long = src_value->data[0].v_long; } static gchar* -value_char_lcopy_value (const GValue *value, - guint n_collect_values, - GTypeCValue *collect_values, - guint collect_flags) +value_lcopy_char (const GValue *value, + guint n_collect_values, + GTypeCValue *collect_values, + guint collect_flags) { gint8 *int8_p = collect_values[0].v_pointer; @@ -58,10 +59,10 @@ value_char_lcopy_value (const GValue *value, } static gchar* -value_boolean_lcopy_value (const GValue *value, - guint n_collect_values, - GTypeCValue *collect_values, - guint collect_flags) +value_lcopy_boolean (const GValue *value, + guint n_collect_values, + GTypeCValue *collect_values, + guint collect_flags) { gboolean *bool_p = collect_values[0].v_pointer; @@ -74,10 +75,10 @@ value_boolean_lcopy_value (const GValue *value, } static gchar* -value_int_collect_value (GValue *value, - guint n_collect_values, - GTypeCValue *collect_values, - guint collect_flags) +value_collect_int (GValue *value, + guint n_collect_values, + GTypeCValue *collect_values, + guint collect_flags) { value->data[0].v_int = collect_values[0].v_int; @@ -85,10 +86,10 @@ value_int_collect_value (GValue *value, } static gchar* -value_int_lcopy_value (const GValue *value, - guint n_collect_values, - GTypeCValue *collect_values, - guint collect_flags) +value_lcopy_int (const GValue *value, + guint n_collect_values, + GTypeCValue *collect_values, + guint collect_flags) { gint *int_p = collect_values[0].v_pointer; @@ -101,10 +102,10 @@ value_int_lcopy_value (const GValue *value, } static gchar* -value_long_collect_value (GValue *value, - guint n_collect_values, - GTypeCValue *collect_values, - guint collect_flags) +value_collect_long (GValue *value, + guint n_collect_values, + GTypeCValue *collect_values, + guint collect_flags) { value->data[0].v_long = collect_values[0].v_long; @@ -112,10 +113,10 @@ value_long_collect_value (GValue *value, } static gchar* -value_long_lcopy_value (const GValue *value, - guint n_collect_values, - GTypeCValue *collect_values, - guint collect_flags) +value_lcopy_long (const GValue *value, + guint n_collect_values, + GTypeCValue *collect_values, + guint collect_flags) { glong *long_p = collect_values[0].v_pointer; @@ -128,23 +129,23 @@ value_long_lcopy_value (const GValue *value, } static void -value_float_init (GValue *value) +value_init_float (GValue *value) { value->data[0].v_float = 0.0; } static void -value_float_copy (const GValue *src_value, +value_copy_float (const GValue *src_value, GValue *dest_value) { dest_value->data[0].v_float = src_value->data[0].v_float; } static gchar* -value_float_collect_value (GValue *value, - guint n_collect_values, - GTypeCValue *collect_values, - guint collect_flags) +value_collect_float (GValue *value, + guint n_collect_values, + GTypeCValue *collect_values, + guint collect_flags) { value->data[0].v_float = collect_values[0].v_double; @@ -152,10 +153,10 @@ value_float_collect_value (GValue *value, } static gchar* -value_float_lcopy_value (const GValue *value, - guint n_collect_values, - GTypeCValue *collect_values, - guint collect_flags) +value_lcopy_float (const GValue *value, + guint n_collect_values, + GTypeCValue *collect_values, + guint collect_flags) { gfloat *float_p = collect_values[0].v_pointer; @@ -168,23 +169,23 @@ value_float_lcopy_value (const GValue *value, } static void -value_double_init (GValue *value) +value_init_double (GValue *value) { value->data[0].v_double = 0.0; } static void -value_double_copy (const GValue *src_value, +value_copy_double (const GValue *src_value, GValue *dest_value) { dest_value->data[0].v_double = src_value->data[0].v_double; } static gchar* -value_double_collect_value (GValue *value, - guint n_collect_values, - GTypeCValue *collect_values, - guint collect_flags) +value_collect_double (GValue *value, + guint n_collect_values, + GTypeCValue *collect_values, + guint collect_flags) { value->data[0].v_double = collect_values[0].v_double; @@ -192,10 +193,10 @@ value_double_collect_value (GValue *value, } static gchar* -value_double_lcopy_value (const GValue *value, - guint n_collect_values, - GTypeCValue *collect_values, - guint collect_flags) +value_lcopy_double (const GValue *value, + guint n_collect_values, + GTypeCValue *collect_values, + guint collect_flags) { gdouble *double_p = collect_values[0].v_pointer; @@ -208,30 +209,30 @@ value_double_lcopy_value (const GValue *value, } static void -value_string_init (GValue *value) +value_init_string (GValue *value) { value->data[0].v_pointer = NULL; } static void -value_string_free_value (GValue *value) +value_free_string (GValue *value) { if (!(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)) g_free (value->data[0].v_pointer); } static void -value_string_copy_value (const GValue *src_value, - GValue *dest_value) +value_copy_string (const GValue *src_value, + GValue *dest_value) { dest_value->data[0].v_pointer = g_strdup (src_value->data[0].v_pointer); } static gchar* -value_string_collect_value (GValue *value, - guint n_collect_values, - GTypeCValue *collect_values, - guint collect_flags) +value_collect_string (GValue *value, + guint n_collect_values, + GTypeCValue *collect_values, + guint collect_flags) { if (!collect_values[0].v_pointer) value->data[0].v_pointer = NULL; @@ -247,10 +248,10 @@ value_string_collect_value (GValue *value, } static gchar* -value_string_lcopy_value (const GValue *value, - guint n_collect_values, - GTypeCValue *collect_values, - guint collect_flags) +value_lcopy_string (const GValue *value, + guint n_collect_values, + GTypeCValue *collect_values, + guint collect_flags) { gchar **string_p = collect_values[0].v_pointer; @@ -268,29 +269,29 @@ value_string_lcopy_value (const GValue *value, } static void -value_pointer_init (GValue *value) +value_init_pointer (GValue *value) { value->data[0].v_pointer = NULL; } static void -value_pointer_copy (const GValue *src_value, +value_copy_pointer (const GValue *src_value, GValue *dest_value) { dest_value->data[0].v_pointer = src_value->data[0].v_pointer; } static gpointer -value_pointer_peek_pointer (const GValue *value) +value_peek_pointer0 (const GValue *value) { return value->data[0].v_pointer; } static gchar* -value_pointer_collect_value (GValue *value, - guint n_collect_values, - GTypeCValue *collect_values, - guint collect_flags) +value_collect_pointer (GValue *value, + guint n_collect_values, + GTypeCValue *collect_values, + guint collect_flags) { value->data[0].v_pointer = collect_values[0].v_pointer; @@ -298,10 +299,10 @@ value_pointer_collect_value (GValue *value, } static gchar* -value_pointer_lcopy_value (const GValue *value, - guint n_collect_values, - GTypeCValue *collect_values, - guint collect_flags) +value_lcopy_pointer (const GValue *value, + guint n_collect_values, + GTypeCValue *collect_values, + guint collect_flags) { gpointer *pointer_p = collect_values[0].v_pointer; @@ -313,59 +314,6 @@ value_pointer_lcopy_value (const GValue *value, return NULL; } -static void -value_ccallback_init (GValue *value) -{ - value->data[0].v_pointer = NULL; - value->data[1].v_pointer = NULL; -} - -static void -value_ccallback_copy (const GValue *src_value, - GValue *dest_value) -{ - dest_value->data[0].v_pointer = src_value->data[0].v_pointer; - dest_value->data[1].v_pointer = src_value->data[1].v_pointer; -} - -static gchar* -value_ccallback_collect_value (GValue *value, - guint n_collect_values, - GTypeCValue *collect_values, - guint collect_flags) -{ - gchar *error = NULL; - - if (!collect_values[0].v_pointer) - error = g_strconcat ("invalid (NULL) pointer callback function for value type `", - G_VALUE_TYPE_NAME (value), - "'", - NULL); - value->data[0].v_pointer = collect_values[0].v_pointer; - value->data[1].v_pointer = collect_values[1].v_pointer; - - return error; -} - -static gchar* -value_ccallback_lcopy_value (const GValue *value, - guint n_collect_values, - GTypeCValue *collect_values, - guint collect_flags) -{ - gpointer *callback_p = collect_values[0].v_pointer; - gpointer *data_p = collect_values[1].v_pointer; - - if (!callback_p || !data_p) - return g_strdup_printf ("%s location for `%s' passed as NULL", - callback_p ? "data" : "callback", - G_VALUE_TYPE_NAME (value)); - *callback_p = value->data[0].v_pointer; - *data_p = value->data[1].v_pointer; - - return NULL; -} - /* --- type initialization --- */ void @@ -390,14 +338,14 @@ g_value_types_init (void) /* sync with gtype.c */ */ { static const GTypeValueTable value_table = { - value_long0_init, /* value_init */ + value_init_long0, /* value_init */ NULL, /* value_free */ - value_long0_copy, /* value_copy */ + value_copy_long0, /* value_copy */ NULL, /* value_peek_pointer */ "i", /* collect_format */ - value_int_collect_value, /* collect_value */ + value_collect_int, /* collect_value */ "p", /* lcopy_format */ - value_char_lcopy_value, /* lcopy_value */ + value_lcopy_char, /* lcopy_value */ }; info.value_table = &value_table; type = g_type_register_fundamental (G_TYPE_CHAR, "gchar", &info, &finfo, 0); @@ -410,14 +358,14 @@ g_value_types_init (void) /* sync with gtype.c */ */ { static const GTypeValueTable value_table = { - value_long0_init, /* value_init */ + value_init_long0, /* value_init */ NULL, /* value_free */ - value_long0_copy, /* value_copy */ + value_copy_long0, /* value_copy */ NULL, /* value_peek_pointer */ "i", /* collect_format */ - value_int_collect_value, /* collect_value */ + value_collect_int, /* collect_value */ "p", /* lcopy_format */ - value_boolean_lcopy_value, /* lcopy_value */ + value_lcopy_boolean, /* lcopy_value */ }; info.value_table = &value_table; type = g_type_register_fundamental (G_TYPE_BOOLEAN, "gboolean", &info, &finfo, 0); @@ -428,14 +376,14 @@ g_value_types_init (void) /* sync with gtype.c */ */ { static const GTypeValueTable value_table = { - value_long0_init, /* value_init */ + value_init_long0, /* value_init */ NULL, /* value_free */ - value_long0_copy, /* value_copy */ + value_copy_long0, /* value_copy */ NULL, /* value_peek_pointer */ "i", /* collect_format */ - value_int_collect_value, /* collect_value */ + value_collect_int, /* collect_value */ "p", /* lcopy_format */ - value_int_lcopy_value, /* lcopy_value */ + value_lcopy_int, /* lcopy_value */ }; info.value_table = &value_table; type = g_type_register_fundamental (G_TYPE_INT, "gint", &info, &finfo, 0); @@ -448,14 +396,14 @@ g_value_types_init (void) /* sync with gtype.c */ */ { static const GTypeValueTable value_table = { - value_long0_init, /* value_init */ + value_init_long0, /* value_init */ NULL, /* value_free */ - value_long0_copy, /* value_copy */ + value_copy_long0, /* value_copy */ NULL, /* value_peek_pointer */ "l", /* collect_format */ - value_long_collect_value, /* collect_value */ + value_collect_long, /* collect_value */ "p", /* lcopy_format */ - value_long_lcopy_value, /* lcopy_value */ + value_lcopy_long, /* lcopy_value */ }; info.value_table = &value_table; type = g_type_register_fundamental (G_TYPE_LONG, "glong", &info, &finfo, 0); @@ -468,14 +416,14 @@ g_value_types_init (void) /* sync with gtype.c */ */ { static const GTypeValueTable value_table = { - value_float_init, /* value_init */ + value_init_float, /* value_init */ NULL, /* value_free */ - value_float_copy, /* value_copy */ + value_copy_float, /* value_copy */ NULL, /* value_peek_pointer */ "d", /* collect_format */ - value_float_collect_value, /* collect_value */ + value_collect_float, /* collect_value */ "p", /* lcopy_format */ - value_float_lcopy_value, /* lcopy_value */ + value_lcopy_float, /* lcopy_value */ }; info.value_table = &value_table; type = g_type_register_fundamental (G_TYPE_FLOAT, "gfloat", &info, &finfo, 0); @@ -486,14 +434,14 @@ g_value_types_init (void) /* sync with gtype.c */ */ { static const GTypeValueTable value_table = { - value_double_init, /* value_init */ - NULL, /* value_free */ - value_double_copy, /* value_copy */ - NULL, /* value_peek_pointer */ - "d", /* collect_format */ - value_double_collect_value, /* collect_value */ - "p", /* lcopy_format */ - value_double_lcopy_value, /* lcopy_value */ + value_init_double, /* value_init */ + NULL, /* value_free */ + value_copy_double, /* value_copy */ + NULL, /* value_peek_pointer */ + "d", /* collect_format */ + value_collect_double, /* collect_value */ + "p", /* lcopy_format */ + value_lcopy_double, /* lcopy_value */ }; info.value_table = &value_table; type = g_type_register_fundamental (G_TYPE_DOUBLE, "gdouble", &info, &finfo, 0); @@ -504,14 +452,14 @@ g_value_types_init (void) /* sync with gtype.c */ */ { static const GTypeValueTable value_table = { - value_string_init, /* value_init */ - value_string_free_value, /* value_free */ - value_string_copy_value, /* value_copy */ - value_pointer_peek_pointer, /* value_peek_pointer */ - "p", /* collect_format */ - value_string_collect_value, /* collect_value */ - "p", /* lcopy_format */ - value_string_lcopy_value, /* lcopy_value */ + value_init_string, /* value_init */ + value_free_string, /* value_free */ + value_copy_string, /* value_copy */ + value_peek_pointer0, /* value_peek_pointer */ + "p", /* collect_format */ + value_collect_string, /* collect_value */ + "p", /* lcopy_format */ + value_lcopy_string, /* lcopy_value */ }; info.value_table = &value_table; type = g_type_register_fundamental (G_TYPE_STRING, "gstring", &info, &finfo, 0); @@ -522,71 +470,53 @@ g_value_types_init (void) /* sync with gtype.c */ */ { static const GTypeValueTable value_table = { - value_pointer_init, /* value_init */ - NULL, /* value_free */ - value_pointer_copy, /* value_copy */ - value_pointer_peek_pointer, /* value_peek_pointer */ - "p", /* collect_format */ - value_pointer_collect_value, /* collect_value */ - "p", /* lcopy_format */ - value_pointer_lcopy_value, /* lcopy_value */ + value_init_pointer, /* value_init */ + NULL, /* value_free */ + value_copy_pointer, /* value_copy */ + value_peek_pointer0, /* value_peek_pointer */ + "p", /* collect_format */ + value_collect_pointer, /* collect_value */ + "p", /* lcopy_format */ + value_lcopy_pointer, /* lcopy_value */ }; info.value_table = &value_table; type = g_type_register_fundamental (G_TYPE_POINTER, "gpointer", &info, &finfo, 0); g_assert (type == G_TYPE_POINTER); } - - /* G_TYPE_CCALLBACK - */ - { - static const GTypeValueTable value_table = { - value_ccallback_init, /* value_init */ - NULL, /* value_free */ - value_ccallback_copy, /* value_copy */ - NULL, /* value_peek_pointer */ - "pp", /* collect_format */ - value_ccallback_collect_value, /* collect_value */ - "pp", /* lcopy_format */ - value_ccallback_lcopy_value, /* lcopy_value */ - }; - info.value_table = &value_table; - type = g_type_register_fundamental (G_TYPE_CCALLBACK, "GCCallback", &info, &finfo, 0); - g_assert (type == G_TYPE_CCALLBACK); - } } /* --- GValue functions --- */ void g_value_set_char (GValue *value, - gint8 v_char) + gchar v_char) { - g_return_if_fail (G_IS_VALUE_CHAR (value)); + g_return_if_fail (G_VALUE_HOLDS_CHAR (value)); value->data[0].v_int = v_char; } -gint8 +gchar g_value_get_char (const GValue *value) { - g_return_val_if_fail (G_IS_VALUE_CHAR (value), 0); + g_return_val_if_fail (G_VALUE_HOLDS_CHAR (value), 0); return value->data[0].v_int; } void g_value_set_uchar (GValue *value, - guint8 v_uchar) + guchar v_uchar) { - g_return_if_fail (G_IS_VALUE_UCHAR (value)); + g_return_if_fail (G_VALUE_HOLDS_UCHAR (value)); value->data[0].v_uint = v_uchar; } -guint8 +guchar g_value_get_uchar (const GValue *value) { - g_return_val_if_fail (G_IS_VALUE_UCHAR (value), 0); + g_return_val_if_fail (G_VALUE_HOLDS_UCHAR (value), 0); return value->data[0].v_uint; } @@ -595,15 +525,15 @@ void g_value_set_boolean (GValue *value, gboolean v_boolean) { - g_return_if_fail (G_IS_VALUE_BOOLEAN (value)); + g_return_if_fail (G_VALUE_HOLDS_BOOLEAN (value)); - value->data[0].v_int = v_boolean; + value->data[0].v_int = v_boolean != FALSE; } gboolean g_value_get_boolean (const GValue *value) { - g_return_val_if_fail (G_IS_VALUE_BOOLEAN (value), 0); + g_return_val_if_fail (G_VALUE_HOLDS_BOOLEAN (value), 0); return value->data[0].v_int; } @@ -612,7 +542,7 @@ void g_value_set_int (GValue *value, gint v_int) { - g_return_if_fail (G_IS_VALUE_INT (value)); + g_return_if_fail (G_VALUE_HOLDS_INT (value)); value->data[0].v_int = v_int; } @@ -620,7 +550,7 @@ g_value_set_int (GValue *value, gint g_value_get_int (const GValue *value) { - g_return_val_if_fail (G_IS_VALUE_INT (value), 0); + g_return_val_if_fail (G_VALUE_HOLDS_INT (value), 0); return value->data[0].v_int; } @@ -629,7 +559,7 @@ void g_value_set_uint (GValue *value, guint v_uint) { - g_return_if_fail (G_IS_VALUE_UINT (value)); + g_return_if_fail (G_VALUE_HOLDS_UINT (value)); value->data[0].v_uint = v_uint; } @@ -637,7 +567,7 @@ g_value_set_uint (GValue *value, guint g_value_get_uint (const GValue *value) { - g_return_val_if_fail (G_IS_VALUE_UINT (value), 0); + g_return_val_if_fail (G_VALUE_HOLDS_UINT (value), 0); return value->data[0].v_uint; } @@ -646,7 +576,7 @@ void g_value_set_long (GValue *value, glong v_long) { - g_return_if_fail (G_IS_VALUE_LONG (value)); + g_return_if_fail (G_VALUE_HOLDS_LONG (value)); value->data[0].v_long = v_long; } @@ -654,7 +584,7 @@ g_value_set_long (GValue *value, glong g_value_get_long (const GValue *value) { - g_return_val_if_fail (G_IS_VALUE_LONG (value), 0); + g_return_val_if_fail (G_VALUE_HOLDS_LONG (value), 0); return value->data[0].v_long; } @@ -663,7 +593,7 @@ void g_value_set_ulong (GValue *value, gulong v_ulong) { - g_return_if_fail (G_IS_VALUE_ULONG (value)); + g_return_if_fail (G_VALUE_HOLDS_ULONG (value)); value->data[0].v_ulong = v_ulong; } @@ -671,7 +601,7 @@ g_value_set_ulong (GValue *value, gulong g_value_get_ulong (const GValue *value) { - g_return_val_if_fail (G_IS_VALUE_ULONG (value), 0); + g_return_val_if_fail (G_VALUE_HOLDS_ULONG (value), 0); return value->data[0].v_ulong; } @@ -680,7 +610,7 @@ void g_value_set_float (GValue *value, gfloat v_float) { - g_return_if_fail (G_IS_VALUE_FLOAT (value)); + g_return_if_fail (G_VALUE_HOLDS_FLOAT (value)); value->data[0].v_float = v_float; } @@ -688,7 +618,7 @@ g_value_set_float (GValue *value, gfloat g_value_get_float (const GValue *value) { - g_return_val_if_fail (G_IS_VALUE_FLOAT (value), 0); + g_return_val_if_fail (G_VALUE_HOLDS_FLOAT (value), 0); return value->data[0].v_float; } @@ -697,7 +627,7 @@ void g_value_set_double (GValue *value, gdouble v_double) { - g_return_if_fail (G_IS_VALUE_DOUBLE (value)); + g_return_if_fail (G_VALUE_HOLDS_DOUBLE (value)); value->data[0].v_double = v_double; } @@ -705,7 +635,7 @@ g_value_set_double (GValue *value, gdouble g_value_get_double (const GValue *value) { - g_return_val_if_fail (G_IS_VALUE_DOUBLE (value), 0); + g_return_val_if_fail (G_VALUE_HOLDS_DOUBLE (value), 0); return value->data[0].v_double; } @@ -714,7 +644,7 @@ void g_value_set_string (GValue *value, const gchar *v_string) { - g_return_if_fail (G_IS_VALUE_STRING (value)); + g_return_if_fail (G_VALUE_HOLDS_STRING (value)); if (value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS) value->data[1].v_uint = 0; @@ -727,7 +657,7 @@ void g_value_set_static_string (GValue *value, const gchar *v_string) { - g_return_if_fail (G_IS_VALUE_STRING (value)); + g_return_if_fail (G_VALUE_HOLDS_STRING (value)); if (!(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)) g_free (value->data[0].v_pointer); @@ -735,10 +665,23 @@ g_value_set_static_string (GValue *value, value->data[0].v_pointer = (gchar*) v_string; } +void +g_value_set_string_take_ownership (GValue *value, + gchar *v_string) +{ + g_return_if_fail (G_VALUE_HOLDS_STRING (value)); + + if (value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS) + value->data[1].v_uint = 0; + else + g_free (value->data[0].v_pointer); + value->data[0].v_pointer = v_string; +} + G_CONST_RETURN gchar* g_value_get_string (const GValue *value) { - g_return_val_if_fail (G_IS_VALUE_STRING (value), NULL); + g_return_val_if_fail (G_VALUE_HOLDS_STRING (value), NULL); return value->data[0].v_pointer; } @@ -746,7 +689,7 @@ g_value_get_string (const GValue *value) gchar* g_value_dup_string (const GValue *value) { - g_return_val_if_fail (G_IS_VALUE_STRING (value), NULL); + g_return_val_if_fail (G_VALUE_HOLDS_STRING (value), NULL); return g_strdup (value->data[0].v_pointer); } @@ -755,7 +698,7 @@ void g_value_set_pointer (GValue *value, gpointer v_pointer) { - g_return_if_fail (G_IS_VALUE_POINTER (value)); + g_return_if_fail (G_VALUE_HOLDS_POINTER (value)); value->data[0].v_pointer = v_pointer; } @@ -763,31 +706,7 @@ g_value_set_pointer (GValue *value, gpointer g_value_get_pointer (const GValue *value) { - g_return_val_if_fail (G_IS_VALUE_POINTER (value), NULL); + g_return_val_if_fail (G_VALUE_HOLDS_POINTER (value), NULL); return value->data[0].v_pointer; } - -void -g_value_set_ccallback (GValue *value, - gpointer callback_func, - gpointer callback_data) -{ - g_return_if_fail (G_IS_VALUE_CCALLBACK (value)); - - value->data[0].v_pointer = callback_func; - value->data[1].v_pointer = callback_data; -} - -void -g_value_get_ccallback (const GValue *value, - gpointer *callback_func, - gpointer *callback_data) -{ - g_return_if_fail (G_IS_VALUE_CCALLBACK (value)); - - if (callback_func) - *callback_func = value->data[0].v_pointer; - if (callback_data) - *callback_data = value->data[1].v_pointer; -} diff --git a/gobject/gvaluetypes.h b/gobject/gvaluetypes.h index 5cf5b8865..557ca2343 100644 --- a/gobject/gvaluetypes.h +++ b/gobject/gvaluetypes.h @@ -1,5 +1,5 @@ /* GObject - GLib Type, Object, Parameter and Signal Library - * Copyright (C) 1997, 1998, 1999, 2000 Tim Janik and Red Hat, Inc. + * Copyright (C) 1997-1999, 2000-2001 Tim Janik and Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -31,63 +31,63 @@ extern "C" { /* --- type macros --- */ -#define G_IS_VALUE_CHAR(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_CHAR)) -#define G_IS_VALUE_UCHAR(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_UCHAR)) -#define G_IS_VALUE_BOOLEAN(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_BOOLEAN)) -#define G_IS_VALUE_INT(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_INT)) -#define G_IS_VALUE_UINT(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_UINT)) -#define G_IS_VALUE_LONG(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_LONG)) -#define G_IS_VALUE_ULONG(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_ULONG)) -#define G_IS_VALUE_FLOAT(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_FLOAT)) -#define G_IS_VALUE_DOUBLE(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_DOUBLE)) -#define G_IS_VALUE_STRING(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_STRING)) -#define G_IS_VALUE_POINTER(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_POINTER)) -#define G_IS_VALUE_CCALLBACK(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_CCALLBACK)) +#define G_VALUE_HOLDS_CHAR(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_CHAR)) +#define G_VALUE_HOLDS_UCHAR(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_UCHAR)) +#define G_VALUE_HOLDS_BOOLEAN(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_BOOLEAN)) +#define G_VALUE_HOLDS_INT(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_INT)) +#define G_VALUE_HOLDS_UINT(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_UINT)) +#define G_VALUE_HOLDS_LONG(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_LONG)) +#define G_VALUE_HOLDS_ULONG(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_ULONG)) +#define G_VALUE_HOLDS_FLOAT(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_FLOAT)) +#define G_VALUE_HOLDS_DOUBLE(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_DOUBLE)) +#define G_VALUE_HOLDS_STRING(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_STRING)) +#define G_VALUE_HOLDS_POINTER(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_POINTER)) /* --- prototypes --- */ -void g_value_set_char (GValue *value, - gint8 v_char); -gint8 g_value_get_char (const GValue *value); -void g_value_set_uchar (GValue *value, - guint8 v_uchar); -guint8 g_value_get_uchar (const GValue *value); -void g_value_set_boolean (GValue *value, +void g_value_set_char (GValue *value, + gchar v_char); +gchar g_value_get_char (const GValue *value); +void g_value_set_uchar (GValue *value, + guchar v_uchar); +guchar g_value_get_uchar (const GValue *value); +void g_value_set_boolean (GValue *value, gboolean v_boolean); -gboolean g_value_get_boolean (const GValue *value); -void g_value_set_int (GValue *value, - gint v_int); -gint g_value_get_int (const GValue *value); -void g_value_set_uint (GValue *value, - guint v_uint); -guint g_value_get_uint (const GValue *value); -void g_value_set_long (GValue *value, - glong v_long); -glong g_value_get_long (const GValue *value); -void g_value_set_ulong (GValue *value, - gulong v_ulong); -gulong g_value_get_ulong (const GValue *value); -void g_value_set_float (GValue *value, - gfloat v_float); -gfloat g_value_get_float (const GValue *value); -void g_value_set_double (GValue *value, +gboolean g_value_get_boolean (const GValue *value); +void g_value_set_int (GValue *value, + gint v_int); +gint g_value_get_int (const GValue *value); +void g_value_set_uint (GValue *value, + guint v_uint); +guint g_value_get_uint (const GValue *value); +void g_value_set_long (GValue *value, + glong v_long); +glong g_value_get_long (const GValue *value); +void g_value_set_ulong (GValue *value, + gulong v_ulong); +gulong g_value_get_ulong (const GValue *value); +void g_value_set_float (GValue *value, + gfloat v_float); +gfloat g_value_get_float (const GValue *value); +void g_value_set_double (GValue *value, gdouble v_double); -gdouble g_value_get_double (const GValue *value); -void g_value_set_string (GValue *value, +gdouble g_value_get_double (const GValue *value); +void g_value_set_string (GValue *value, const gchar *v_string); -void g_value_set_static_string (GValue *value, +void g_value_set_static_string (GValue *value, const gchar *v_string); -G_CONST_RETURN gchar* g_value_get_string (const GValue *value); -gchar* g_value_dup_string (const GValue *value); -void g_value_set_pointer (GValue *value, +G_CONST_RETURN gchar* g_value_get_string (const GValue *value); +gchar* g_value_dup_string (const GValue *value); +void g_value_set_pointer (GValue *value, gpointer v_pointer); -gpointer g_value_get_pointer (const GValue *value); -void g_value_set_ccallback (GValue *value, - gpointer callback_func, - gpointer callback_data); -void g_value_get_ccallback (const GValue *value, - gpointer *callback_func, - gpointer *callback_data); +gpointer g_value_get_pointer (const GValue *value); + + +/* --- marshaller specific --- */ +void g_value_set_string_take_ownership (GValue *value, + gchar *v_string); + + #ifdef __cplusplus } diff --git a/gqsort.c b/gqsort.c index 69b63637e..c75cca31a 100644 --- a/gqsort.c +++ b/gqsort.c @@ -96,7 +96,7 @@ void g_qsort_with_data (gconstpointer pbase, gint total_elems, size_t size, - GCompareFuncData compare_func, + GCompareDataFunc compare_func, gpointer user_data) { register char *base_ptr = (char *) pbase; diff --git a/gqsort.h b/gqsort.h index f236e04fb..d946e80ca 100644 --- a/gqsort.h +++ b/gqsort.h @@ -35,7 +35,7 @@ G_BEGIN_DECLS void g_qsort_with_data (gconstpointer pbase, gint total_elems, size_t size, - GCompareFuncData compare_func, + GCompareDataFunc compare_func, gpointer user_data); G_END_DECLS diff --git a/gslist.c b/gslist.c index 6c9019914..65c2c6cdb 100644 --- a/gslist.c +++ b/gslist.c @@ -634,7 +634,7 @@ g_slist_sort_merge (GSList *l1, while (l1 && l2) { if (use_data) - cmp = ((GCompareFuncData) compare_func) (l1->data, l2->data, user_data); + cmp = ((GCompareDataFunc) compare_func) (l1->data, l2->data, user_data); else cmp = ((GCompareFunc) compare_func) (l1->data, l2->data); @@ -695,7 +695,7 @@ g_slist_sort (GSList *list, GSList * g_slist_sort_with_data (GSList *list, - GCompareFuncData compare_func, + GCompareDataFunc compare_func, gpointer user_data) { return g_slist_sort_real (list, (GFunc) compare_func, TRUE, user_data); diff --git a/gslist.h b/gslist.h index 446eab43e..8d94b2c07 100644 --- a/gslist.h +++ b/gslist.h @@ -88,7 +88,7 @@ void g_slist_foreach (GSList *list, GSList* g_slist_sort (GSList *list, GCompareFunc compare_func); GSList* g_slist_sort_with_data (GSList *list, - GCompareFuncData compare_func, + GCompareDataFunc compare_func, gpointer user_data); gpointer g_slist_nth_data (GSList *list, guint n); diff --git a/gstring.c b/gstring.c index ff6fc7c6d..a720ac73d 100644 --- a/gstring.c +++ b/gstring.c @@ -565,9 +565,9 @@ g_string_up (GString *fstring) } static void -g_string_sprintfa_int (GString *string, - const gchar *fmt, - va_list args) +g_string_printfa_internal (GString *string, + const gchar *fmt, + va_list args) { gchar *buffer; @@ -577,27 +577,27 @@ g_string_sprintfa_int (GString *string, } void -g_string_sprintf (GString *string, - const gchar *fmt, - ...) +g_string_printf (GString *string, + const gchar *fmt, + ...) { va_list args; g_string_truncate (string, 0); va_start (args, fmt); - g_string_sprintfa_int (string, fmt, args); + g_string_printfa_internal (string, fmt, args); va_end (args); } void -g_string_sprintfa (GString *string, - const gchar *fmt, - ...) +g_string_printfa (GString *string, + const gchar *fmt, + ...) { va_list args; va_start (args, fmt); - g_string_sprintfa_int (string, fmt, args); + g_string_printfa_internal (string, fmt, args); va_end (args); } diff --git a/gstring.h b/gstring.h index d2f88e066..84d0bbb3f 100644 --- a/gstring.h +++ b/gstring.h @@ -94,12 +94,15 @@ GString* g_string_erase (GString *string, gint len); GString* g_string_down (GString *string); GString* g_string_up (GString *string); -void g_string_sprintf (GString *string, +void g_string_printf (GString *string, const gchar *format, ...) G_GNUC_PRINTF (2, 3); -void g_string_sprintfa (GString *string, +void g_string_printfa (GString *string, const gchar *format, ...) G_GNUC_PRINTF (2, 3); +/* compatibility */ +#define g_string_sprintf g_string_printf +#define g_string_sprintfa g_string_printfa G_END_DECLS diff --git a/gtree.c b/gtree.c index c453eb64b..5e0c0f573 100644 --- a/gtree.c +++ b/gtree.c @@ -41,7 +41,7 @@ typedef struct _GTreeNode GTreeNode; struct _GRealTree { GTreeNode *root; - GCompareFuncData key_compare; + GCompareDataFunc key_compare; gpointer key_compare_data; }; @@ -59,13 +59,13 @@ static GTreeNode* g_tree_node_new (gpointer key, gpointer value); static void g_tree_node_destroy (GTreeNode *node); static GTreeNode* g_tree_node_insert (GTreeNode *node, - GCompareFuncData compare, + GCompareDataFunc compare, gpointer comp_data, gpointer key, gpointer value, gint *inserted); static GTreeNode* g_tree_node_remove (GTreeNode *node, - GCompareFuncData compare, + GCompareDataFunc compare, gpointer comp_data, gconstpointer key); static GTreeNode* g_tree_node_balance (GTreeNode *node); @@ -76,7 +76,7 @@ static GTreeNode* g_tree_node_restore_left_balance (GTreeNode *node, static GTreeNode* g_tree_node_restore_right_balance (GTreeNode *node, gint old_balance); static gpointer g_tree_node_lookup (GTreeNode *node, - GCompareFuncData compare, + GCompareDataFunc compare, gpointer comp_data, gconstpointer key); static gint g_tree_node_count (GTreeNode *node); @@ -157,7 +157,7 @@ g_tree_node_destroy (GTreeNode *node) } } -GTree* g_tree_new_udata(GCompareFuncData key_compare_func, +GTree* g_tree_new_udata(GCompareDataFunc key_compare_func, gpointer key_compare_data) { GRealTree *rtree; @@ -175,7 +175,7 @@ GTree* g_tree_new_udata(GCompareFuncData key_compare_func, GTree* g_tree_new (GCompareFunc key_compare_func) { - return g_tree_new_udata ((GCompareFuncData) key_compare_func, NULL); + return g_tree_new_udata ((GCompareDataFunc) key_compare_func, NULL); } @@ -322,7 +322,7 @@ g_tree_nnodes (GTree *tree) static GTreeNode* g_tree_node_insert (GTreeNode *node, - GCompareFuncData compare, + GCompareDataFunc compare, gpointer compare_data, gpointer key, gpointer value, @@ -393,7 +393,7 @@ g_tree_node_insert (GTreeNode *node, static GTreeNode* g_tree_node_remove (GTreeNode *node, - GCompareFuncData compare, + GCompareDataFunc compare, gpointer compare_data, gconstpointer key) { @@ -526,7 +526,7 @@ g_tree_node_restore_right_balance (GTreeNode *node, static gpointer g_tree_node_lookup (GTreeNode *node, - GCompareFuncData compare, + GCompareDataFunc compare, gpointer compare_data, gconstpointer key) { diff --git a/gtree.h b/gtree.h index 3530a6374..78a52fb0f 100644 --- a/gtree.h +++ b/gtree.h @@ -40,7 +40,7 @@ typedef gint (*GTraverseFunc) (gpointer key, /* Balanced binary trees */ GTree* g_tree_new (GCompareFunc key_compare_func); -GTree* g_tree_new_with_data (GCompareFuncData key_compare_func, +GTree* g_tree_new_with_data (GCompareDataFunc key_compare_func, gpointer user_data); void g_tree_destroy (GTree *tree); void g_tree_insert (GTree *tree, diff --git a/gtypes.h b/gtypes.h index 21a29e919..487ecdc77 100644 --- a/gtypes.h +++ b/gtypes.h @@ -69,7 +69,7 @@ typedef const void *gconstpointer; typedef gint (*GCompareFunc) (gconstpointer a, gconstpointer b); -typedef gint (*GCompareFuncData) (gconstpointer a, +typedef gint (*GCompareDataFunc) (gconstpointer a, gconstpointer b, gpointer user_data); typedef gboolean (*GEqualFunc) (gconstpointer a,