* 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.
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
/*
#include "gtype-private.h"
#include "gtypeplugin.h"
#include "gvaluecollector.h"
-#include "gbsearcharray.h"
#include "gatomicarray.h"
#include "gobject_trace.h"
#include "gconstructor.h"
+#ifdef G_ENABLE_DEBUG
+#define IF_DEBUG(debug_type) if (_g_type_debug_flags & G_TYPE_DEBUG_ ## debug_type)
+#endif
/**
* SECTION:gtype
* unloaded at run-time as dynamic types may be. Static types are created
* with g_type_register_static() that gets type specific information passed
* in via a #GTypeInfo structure.
+ *
* Dynamic types are created with g_type_register_dynamic() which takes a
* #GTypePlugin structure instead. The remaining type information (the
* #GTypeInfo structure) is retrieved during runtime through #GTypePlugin
* and the g_type_plugin_*() API.
+ *
* These registration functions are usually called only once from a
* function whose only purpose is to return the type identifier for a
* specific class. Once the type (or class or interface) is registered,
* it may be instantiated, inherited, or implemented depending on exactly
* what sort of type it is.
+ *
* There is also a third registration function for registering fundamental
* types called g_type_register_fundamental() which requires both a #GTypeInfo
* structure and a #GTypeFundamentalInfo structure but it is seldom used
* separately (typically by using #GArray or #GPtrArray) and put a pointer
* to the buffer in the structure.
*
- * A final word about type names.
- * Such an identifier needs to be at least three characters long. There is no
- * upper length limit. The first character needs to be a letter (a-z or A-Z)
- * or an underscore '_'. Subsequent characters can be letters, numbers or
- * any of '-_+'.
+ * A final word about type names: Such an identifier needs to be at least
+ * three characters long. There is no upper length limit. The first character
+ * needs to be a letter (a-z or A-Z) or an underscore '_'. Subsequent
+ * characters can be letters, numbers or any of '-_+'.
*/
struct _TypeNode
{
guint volatile ref_count;
+#ifdef G_ENABLE_DEBUG
+ guint volatile instance_count;
+#endif
GTypePlugin *plugin;
guint n_children; /* writable with lock */
guint n_supers : 8;
static GType static_fundamental_next = G_TYPE_RESERVED_USER_FIRST;
static inline TypeNode*
-lookup_type_node_I (register GType utype)
+lookup_type_node_I (GType utype)
{
if (utype > G_TYPE_FUNDAMENTAL_MAX)
return (TypeNode*) (utype & ~TYPE_ID_MASK);
/**
* g_type_get_type_registration_serial:
*
- * Returns an opaque serial number that represents the state of the set of
- * registered types. Any time a type is registered this serial changes,
+ * Returns an opaque serial number that represents the state of the set
+ * of registered types. Any time a type is registered this serial changes,
* which means you can cache information based on type lookups (such as
* g_type_from_name()) and know if the cache is still valid at a later
* time by comparing the current serial with the one at the type lookup.
*
* Since: 2.36
*
- * Returns: An unsigned int, representing the state of type registrations.
+ * Returns: An unsigned int, representing the state of type registrations
*/
guint
g_type_get_type_registration_serial (void)
node->data = NULL;
node->qname = g_quark_from_string (name);
node->global_gdata = NULL;
-
g_hash_table_insert (static_type_nodes_ht,
(gpointer) g_quark_to_string (node->qname),
(gpointer) type);
{
g_warning ("attempting to add an interface (%s) to class (%s) after class_init",
NODE_NAME (iface), NODE_NAME (node));
-
- /* See https://bugzilla.gnome.org/show_bug.cgi?id=697229,
- * https://bugzilla.gnome.org/show_bug.cgi?id=687659
- */
- if (!g_str_has_prefix (NODE_NAME (node), "gtkmm__CustomObject_") && !strstr (NODE_NAME (node), "_gtksharp_"))
- return FALSE;
+ return FALSE;
}
tnode = lookup_type_node_I (NODE_PARENT_TYPE (iface));
if (NODE_PARENT_TYPE (tnode) && !type_lookup_iface_entry_L (node, tnode))
/**
* g_type_interface_add_prerequisite:
- * @interface_type: #GType value of an interface type.
- * @prerequisite_type: #GType value of an interface or instantiatable type.
+ * @interface_type: #GType value of an interface type
+ * @prerequisite_type: #GType value of an interface or instantiatable type
*
* Adds @prerequisite_type to the list of prerequisites of @interface_type.
* This means that any type implementing @interface_type must also implement
* g_type_interface_prerequisites:
* @interface_type: an interface type
* @n_prerequisites: (out) (allow-none): location to return the number
- * of prerequisites, or %NULL
+ * of prerequisites, or %NULL
*
* Returns the prerequisites of an interfaces type.
*
* Since: 2.2
*
* Returns: (array length=n_prerequisites) (transfer full): a
- * newly-allocated zero-terminated array of #GType containing
- * the prerequisites of @interface_type
+ * newly-allocated zero-terminated array of #GType containing
+ * the prerequisites of @interface_type
*/
GType*
g_type_interface_prerequisites (GType interface_type,
/**
* g_type_create_instance: (skip)
- * @type: An instantiatable type to create an instance for.
+ * @type: an instantiatable type to create an instance for
*
* Creates and initializes an instance of @type if @type is valid and
* can be instantiated. The type system only performs basic allocation
* happen through functions supplied by the type's fundamental type
* implementation. So use of g_type_create_instance() is reserved for
* implementators of fundamental types only. E.g. instances of the
- * #GObject hierarchy should be created via g_object_new() and
- * <emphasis>never</emphasis> directly through
- * g_type_create_instance() which doesn't handle things like singleton
- * objects or object construction. Note: Do <emphasis>not</emphasis>
- * use this function, unless you're implementing a fundamental
- * type. Also language bindings should <emphasis>not</emphasis> use
- * this function but g_object_new() instead.
- *
- * Returns: An allocated and initialized instance, subject to further
- * treatment by the fundamental type implementation.
+ * #GObject hierarchy should be created via g_object_new() and never
+ * directly through g_type_create_instance() which doesn't handle things
+ * like singleton objects or object construction.
+ *
+ * The extended members of the returned instance are guaranteed to be filled
+ * with zeros.
+ *
+ * Note: Do not use this function, unless you're implementing a
+ * fundamental type. Also language bindings should not use this
+ * function, but g_object_new() instead.
+ *
+ * Returns: an allocated and initialized instance, subject to further
+ * treatment by the fundamental type implementation
*/
GTypeInstance*
g_type_create_instance (GType type)
if (node->data->instance.instance_init)
node->data->instance.instance_init (instance, class);
+#ifdef G_ENABLE_DEBUG
+ IF_DEBUG (INSTANCE_COUNT)
+ {
+ g_atomic_int_inc ((int *) &node->instance_count);
+ }
+#endif
+
TRACE(GOBJECT_OBJECT_NEW(instance, type));
return instance;
/**
* g_type_free_instance:
- * @instance: an instance of a type.
+ * @instance: an instance of a type
*
* Frees an instance of a type, returning it to the instance pool for
* the type, if there is one.
else
g_slice_free1 (private_size + ivar_size, allocated);
+#ifdef G_ENABLE_DEBUG
+ IF_DEBUG (INSTANCE_COUNT)
+ {
+ g_atomic_int_add ((int *) &node->instance_count, -1);
+ }
+#endif
+
g_type_class_unref (class);
}
* g_type_add_interface_check: (skip)
* @check_data: data to pass to @check_func
* @check_func: function to be called after each interface
- * is initialized.
+ * is initialized
*
* Adds a function to be called after an interface vtable is
- * initialized for any class (i.e. after the @interface_init member of
- * #GInterfaceInfo has been called).
+ * initialized for any class (i.e. after the @interface_init
+ * member of #GInterfaceInfo has been called).
*
- * This function is useful when you want to check an invariant that
- * depends on the interfaces of a class. For instance, the
+ * This function is useful when you want to check an invariant
+ * that depends on the interfaces of a class. For instance, the
* implementation of #GObject uses this facility to check that an
* object implements all of the properties that are defined on its
* interfaces.
/* --- type registration --- */
/**
* g_type_register_fundamental:
- * @type_id: A predefined type identifier.
- * @type_name: 0-terminated string used as the name of the new type.
- * @info: The #GTypeInfo structure for this type.
- * @finfo: The #GTypeFundamentalInfo structure for this type.
- * @flags: Bitwise combination of #GTypeFlags values.
+ * @type_id: a predefined type identifier
+ * @type_name: 0-terminated string used as the name of the new type
+ * @info: #GTypeInfo structure for this type
+ * @finfo: #GTypeFundamentalInfo structure for this type
+ * @flags: bitwise combination of #GTypeFlags values
*
* Registers @type_id as the predefined identifier and @type_name as the
- * name of a fundamental type. If @type_id is already registered, or a type
- * named @type_name is already registered, the behaviour is undefined. The type
- * system uses the information contained in the #GTypeInfo structure pointed to
- * by @info and the #GTypeFundamentalInfo structure pointed to by @finfo to
- * manage the type and its instances. The value of @flags determines additional
- * characteristics of the fundamental type.
- *
- * Returns: The predefined type identifier.
+ * name of a fundamental type. If @type_id is already registered, or a
+ * type named @type_name is already registered, the behaviour is undefined.
+ * The type system uses the information contained in the #GTypeInfo structure
+ * pointed to by @info and the #GTypeFundamentalInfo structure pointed to by
+ * @finfo to manage the type and its instances. The value of @flags determines
+ * additional characteristics of the fundamental type.
+ *
+ * Returns: the predefined type identifier
*/
GType
g_type_register_fundamental (GType type_id,
/**
* g_type_register_static_simple: (skip)
- * @parent_type: Type from which this type will be derived.
- * @type_name: 0-terminated string used as the name of the new type.
- * @class_size: Size of the class structure (see #GTypeInfo)
- * @class_init: Location of the class initialization function (see #GTypeInfo)
- * @instance_size: Size of the instance structure (see #GTypeInfo)
- * @instance_init: Location of the instance initialization function (see #GTypeInfo)
- * @flags: Bitwise combination of #GTypeFlags values.
+ * @parent_type: type from which this type will be derived
+ * @type_name: 0-terminated string used as the name of the new type
+ * @class_size: size of the class structure (see #GTypeInfo)
+ * @class_init: location of the class initialization function (see #GTypeInfo)
+ * @instance_size: size of the instance structure (see #GTypeInfo)
+ * @instance_init: location of the instance initialization function (see #GTypeInfo)
+ * @flags: bitwise combination of #GTypeFlags values
*
* Registers @type_name as the name of a new static type derived from
* @parent_type. The value of @flags determines the nature (e.g.
*
* Since: 2.12
*
- * Returns: The new type identifier.
+ * Returns: the new type identifier
*/
GType
g_type_register_static_simple (GType parent_type,
/**
* g_type_register_static:
- * @parent_type: Type from which this type will be derived.
- * @type_name: 0-terminated string used as the name of the new type.
- * @info: The #GTypeInfo structure for this type.
- * @flags: Bitwise combination of #GTypeFlags values.
+ * @parent_type: type from which this type will be derived
+ * @type_name: 0-terminated string used as the name of the new type
+ * @info: #GTypeInfo structure for this type
+ * @flags: bitwise combination of #GTypeFlags values
*
* Registers @type_name as the name of a new static type derived from
- * @parent_type. The type system uses the information contained in the
+ * @parent_type. The type system uses the information contained in the
* #GTypeInfo structure pointed to by @info to manage the type and its
- * instances (if not abstract). The value of @flags determines the nature
+ * instances (if not abstract). The value of @flags determines the nature
* (e.g. abstract or not) of the type.
*
- * Returns: The new type identifier.
+ * Returns: the new type identifier
*/
GType
g_type_register_static (GType parent_type,
/**
* g_type_register_dynamic:
- * @parent_type: Type from which this type will be derived.
- * @type_name: 0-terminated string used as the name of the new type.
- * @plugin: The #GTypePlugin structure to retrieve the #GTypeInfo from.
- * @flags: Bitwise combination of #GTypeFlags values.
+ * @parent_type: type from which this type will be derived
+ * @type_name: 0-terminated string used as the name of the new type
+ * @plugin: #GTypePlugin structure to retrieve the #GTypeInfo from
+ * @flags: bitwise combination of #GTypeFlags values
*
* Registers @type_name as the name of a new dynamic type derived from
* @parent_type. The type system uses the information contained in the
* instances (if not abstract). The value of @flags determines the nature
* (e.g. abstract or not) of the type.
*
- * Returns: The new type identifier or #G_TYPE_INVALID if registration failed.
+ * Returns: the new type identifier or #G_TYPE_INVALID if registration failed
*/
GType
g_type_register_dynamic (GType parent_type,
/**
* g_type_add_interface_static:
- * @instance_type: #GType value of an instantiable type.
- * @interface_type: #GType value of an interface type.
- * @info: The #GInterfaceInfo structure for this
- * (@instance_type, @interface_type) combination.
- *
- * Adds the static @interface_type to @instantiable_type. The
- * information contained in the #GInterfaceInfo structure pointed to by
- * @info is used to manage the relationship.
+ * @instance_type: #GType value of an instantiable type
+ * @interface_type: #GType value of an interface type
+ * @info: #GInterfaceInfo structure for this
+ * (@instance_type, @interface_type) combination
+ *
+ * Adds the static @interface_type to @instantiable_type.
+ * The information contained in the #GInterfaceInfo structure
+ * pointed to by @info is used to manage the relationship.
*/
void
g_type_add_interface_static (GType instance_type,
/**
* g_type_add_interface_dynamic:
- * @instance_type: the #GType value of an instantiable type.
- * @interface_type: the #GType value of an interface type.
- * @plugin: the #GTypePlugin structure to retrieve the #GInterfaceInfo from.
+ * @instance_type: #GType value of an instantiable type
+ * @interface_type: #GType value of an interface type
+ * @plugin: #GTypePlugin structure to retrieve the #GInterfaceInfo from
*
* Adds the dynamic @interface_type to @instantiable_type. The information
* contained in the #GTypePlugin structure pointed to by @plugin
/* --- public API functions --- */
/**
* g_type_class_ref:
- * @type: Type ID of a classed type.
+ * @type: type ID of a classed type
*
* Increments the reference count of the class structure belonging to
* @type. This function will demand-create the class if it doesn't
* exist already.
*
- * Returns: (type GObject.TypeClass) (transfer none): The #GTypeClass
- * structure for the given type ID.
+ * Returns: (type GObject.TypeClass) (transfer none): the #GTypeClass
+ * structure for the given type ID
*/
gpointer
g_type_class_ref (GType type)
/**
* g_type_class_unref:
- * @g_class: (type GObject.TypeClass): The #GTypeClass structure to
- * unreference.
+ * @g_class: (type GObject.TypeClass): a #GTypeClass structure to unref
*
* Decrements the reference count of the class structure being passed in.
* Once the last reference count of a class has been released, classes
/**
* g_type_class_unref_uncached: (skip)
- * @g_class: (type GObject.TypeClass): The #GTypeClass structure to
- * unreference.
+ * @g_class: (type GObject.TypeClass): a #GTypeClass structure to unref
*
* A variant of g_type_class_unref() for use in #GTypeClassCacheFunc
* implementations. It unreferences a class without consulting the chain
- * of #GTypeClassCacheFunc<!-- -->s, avoiding the recursion which would occur
+ * of #GTypeClassCacheFuncs, avoiding the recursion which would occur
* otherwise.
*/
void
/**
* g_type_class_peek:
- * @type: Type ID of a classed type.
+ * @type: type ID of a classed type
*
- * This function is essentially the same as g_type_class_ref(), except that
- * the classes reference count isn't incremented. As a consequence, this function
- * may return %NULL if the class of the type passed in does not currently
- * exist (hasn't been referenced before).
+ * This function is essentially the same as g_type_class_ref(),
+ * except that the classes reference count isn't incremented.
+ * As a consequence, this function may return %NULL if the class
+ * of the type passed in does not currently exist (hasn't been
+ * referenced before).
*
- * Returns: (type GObject.TypeClass) (transfer none): The #GTypeClass
- * structure for the given type ID or %NULL if the class does not
- * currently exist.
+ * Returns: (type GObject.TypeClass) (transfer none): the #GTypeClass
+ * structure for the given type ID or %NULL if the class does not
+ * currently exist
*/
gpointer
g_type_class_peek (GType type)
/**
* g_type_class_peek_static:
- * @type: Type ID of a classed type.
+ * @type: type ID of a classed type
*
* A more efficient version of g_type_class_peek() which works only for
* static types.
*
+ * Returns: (type GObject.TypeClass) (transfer none): the #GTypeClass
+ * structure for the given type ID or %NULL if the class does not
+ * currently exist or is dynamically loaded
+ *
* Since: 2.4
- * Returns: (type GObject.TypeClass) (transfer none): The #GTypeClass
- * structure for the given type ID or %NULL if the class does not
- * currently exist or is dynamically loaded.
*/
gpointer
g_type_class_peek_static (GType type)
/**
* g_type_class_peek_parent:
- * @g_class: (type GObject.TypeClass): The #GTypeClass structure to
- * retrieve the parent class for.
+ * @g_class: (type GObject.TypeClass): the #GTypeClass structure to
+ * retrieve the parent class for
*
* This is a convenience function often needed in class initializers.
* It returns the class structure of the immediate parent type of the
* class passed in. Since derived classes hold a reference count on
* their parent classes as long as they are instantiated, the returned
- * class will always exist. This function is essentially equivalent
- * to:
+ * class will always exist.
*
- * <programlisting>
- * g_type_class_peek (g_type_parent (G_TYPE_FROM_CLASS (g_class)));
- * </programlisting>
+ * This function is essentially equivalent to:
+ * g_type_class_peek (g_type_parent (G_TYPE_FROM_CLASS (g_class)))
*
- * Returns: (type GObject.TypeClass) (transfer none): The parent class
- * of @g_class.
+ * Returns: (type GObject.TypeClass) (transfer none): the parent class
+ * of @g_class
*/
gpointer
g_type_class_peek_parent (gpointer g_class)
/**
* g_type_interface_peek:
- * @instance_class: (type GObject.TypeClass): A #GTypeClass structure.
- * @iface_type: An interface ID which this class conforms to.
+ * @instance_class: (type GObject.TypeClass): a #GTypeClass structure
+ * @iface_type: an interface ID which this class conforms to
*
* Returns the #GTypeInterface structure of an interface to which the
* passed in class conforms.
*
- * Returns: (type GObject.TypeInterface) (transfer none): The GTypeInterface
- * structure of iface_type if implemented by @instance_class, %NULL
- * otherwise
+ * Returns: (type GObject.TypeInterface) (transfer none): the #GTypeInterface
+ * structure of @iface_type if implemented by @instance_class, %NULL
+ * otherwise
*/
gpointer
g_type_interface_peek (gpointer instance_class,
/**
* g_type_interface_peek_parent:
- * @g_iface: (type GObject.TypeInterface): A #GTypeInterface structure.
+ * @g_iface: (type GObject.TypeInterface): a #GTypeInterface structure
*
* Returns the corresponding #GTypeInterface structure of the parent type
* of the instance type to which @g_iface belongs. This is useful when
* deriving the implementation of an interface from the parent type and
* then possibly overriding some methods.
*
- * Returns: (transfer none) (type GObject.TypeInterface): The
- * corresponding #GTypeInterface structure of the parent type of the
- * instance type to which @g_iface belongs, or %NULL if the parent
- * type doesn't conform to the interface.
+ * Returns: (transfer none) (type GObject.TypeInterface): the
+ * corresponding #GTypeInterface structure of the parent type of the
+ * instance type to which @g_iface belongs, or %NULL if the parent
+ * type doesn't conform to the interface
*/
gpointer
g_type_interface_peek_parent (gpointer g_iface)
* Since: 2.4
*
* Returns: (type GObject.TypeInterface) (transfer none): the default
- * vtable for the interface; call g_type_default_interface_unref()
- * when you are done using the interface.
+ * vtable for the interface; call g_type_default_interface_unref()
+ * when you are done using the interface.
*/
gpointer
g_type_default_interface_ref (GType g_type)
* Since: 2.4
*
* Returns: (type GObject.TypeInterface) (transfer none): the default
- * vtable for the interface, or %NULL if the type is not currently in
- * use.
+ * vtable for the interface, or %NULL if the type is not currently
+ * in use
*/
gpointer
g_type_default_interface_peek (GType g_type)
/**
* g_type_default_interface_unref:
* @g_iface: (type GObject.TypeInterface): the default vtable
- * structure for a interface, as returned by
- * g_type_default_interface_ref()
+ * structure for a interface, as returned by g_type_default_interface_ref()
*
* Decrements the reference count for the type corresponding to the
* interface default vtable @g_iface. If the type is dynamic, then
/**
* g_type_name:
- * @type: Type to return name for.
+ * @type: type to return name for
*
* Get the unique name that is assigned to a type ID. Note that this
* function (like all other GType API) cannot cope with invalid type
* other validly registered type ID, but randomized type IDs should
* not be passed in and will most likely lead to a crash.
*
- * Returns: Static type name or %NULL.
+ * Returns: static type name or %NULL
*/
const gchar *
g_type_name (GType type)
/**
* g_type_qname:
- * @type: Type to return quark of type name for.
+ * @type: type to return quark of type name for
*
* Get the corresponding quark of the type IDs name.
*
- * Returns: The type names quark or 0.
+ * Returns: the type names quark or 0
*/
GQuark
g_type_qname (GType type)
/**
* g_type_from_name:
- * @name: Type name to lookup.
+ * @name: type name to lookup
*
* Lookup the type ID from a given type name, returning 0 if no type
* has been registered under this name (this is the preferred method
* to find out by name whether a specific type has been registered
* yet).
*
- * Returns: Corresponding type ID or 0.
+ * Returns: corresponding type ID or 0
*/
GType
g_type_from_name (const gchar *name)
/**
* g_type_parent:
- * @type: The derived type.
+ * @type: the derived type
*
- * Return the direct parent type of the passed in type. If the passed
+ * Return the direct parent type of the passed in type. If the passed
* in type has no parent, i.e. is a fundamental type, 0 is returned.
*
- * Returns: The parent type.
+ * Returns: the parent type
*/
GType
g_type_parent (GType type)
/**
* g_type_depth:
- * @type: A #GType value.
+ * @type: a #GType
*
* Returns the length of the ancestry of the passed in type. This
* includes the type itself, so that e.g. a fundamental type has depth 1.
*
- * Returns: The depth of @type.
+ * Returns: the depth of @type
*/
guint
g_type_depth (GType type)
/**
* g_type_next_base:
- * @leaf_type: Descendant of @root_type and the type to be returned.
- * @root_type: Immediate parent of the returned type.
+ * @leaf_type: descendant of @root_type and the type to be returned
+ * @root_type: immediate parent of the returned type
*
* 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
+ * 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.
*
- * Returns: Immediate child of @root_type and anchestor of @leaf_type.
+ * Returns: immediate child of @root_type and anchestor of @leaf_type
*/
GType
g_type_next_base (GType type,
/**
* g_type_is_a:
- * @type: Type to check anchestry for.
- * @is_a_type: Possible anchestor of @type or interface @type could conform to.
+ * @type: type to check anchestry for
+ * @is_a_type: possible anchestor of @type or interface that @type
+ * could conform to
*
* If @is_a_type is a derivable type, check whether @type is a
- * descendant of @is_a_type. If @is_a_type is an interface, check
+ * descendant of @is_a_type. If @is_a_type is an interface, check
* whether @type conforms to it.
*
- * Returns: %TRUE if @type is_a @is_a_type holds true.
+ * Returns: %TRUE if @type is a @is_a_type
*/
gboolean
g_type_is_a (GType type,
{
TypeNode *node, *iface_node;
gboolean is_a;
+
+ if (type == iface_type)
+ return TRUE;
node = lookup_type_node_I (type);
iface_node = lookup_type_node_I (iface_type);
/**
* g_type_children:
- * @type: The parent type.
- * @n_children: (out) (allow-none): Optional #guint pointer to contain
- * the number of child types.
+ * @type: the parent type
+ * @n_children: (out) (allow-none): location to store the length of
+ * the returned array, or %NULL
*
- * Return a newly allocated and 0-terminated array of type IDs, listing the
- * child types of @type. The return value has to be g_free()ed after use.
+ * Return a newly allocated and 0-terminated array of type IDs, listing
+ * the child types of @type.
*
* Returns: (array length=n_children) (transfer full): Newly allocated
- * and 0-terminated array of child types.
+ * and 0-terminated array of child types, free with g_free()
*/
GType*
g_type_children (GType type,
/**
* g_type_interfaces:
- * @type: The type to list interface types for.
- * @n_interfaces: (out) (allow-none): Optional #guint pointer to
- * contain the number of interface types.
+ * @type: the type to list interface types for
+ * @n_interfaces: (out) (allow-none): location to store the length of
+ * the returned array, or %NULL
*
- * Return a newly allocated and 0-terminated array of type IDs, listing the
- * interface types that @type conforms to. The return value has to be
- * g_free()ed after use.
+ * Return a newly allocated and 0-terminated array of type IDs, listing
+ * the interface types that @type conforms to.
*
- * Returns: (array length=n_interfaces) (transfer full): Newly
- * allocated and 0-terminated array of interface types.
+ * Returns: (array length=n_interfaces) (transfer full): Newly allocated
+ * and 0-terminated array of interface types, free with g_free()
*/
GType*
g_type_interfaces (GType type,
/**
* g_type_query:
- * @type: the #GType value of a static, classed type.
- * @query: (out caller-allocates): A user provided structure that is
- * filled in with constant values upon success.
+ * @type: #GType of a static, classed type
+ * @query: (out caller-allocates): a user provided structure that is
+ * filled in with constant values upon success
*
* Queries the type system for information about a specific type.
* This function will fill in a user-provided structure to hold
}
}
+/**
+ * g_type_get_instance_count:
+ * @type: a #GType
+ *
+ * Returns the number of instances allocated of the particular type;
+ * this is only available if GLib is built with debugging support and
+ * the instance_count debug flag is set (by setting the GOBJECT_DEBUG
+ * variable to include instance-count).
+ *
+ * Returns: the number of instances allocated of the given type;
+ * if instance counts are not available, returns 0.
+ *
+ * Since: 2.44
+ */
+int
+g_type_get_instance_count (GType type)
+{
+#ifdef G_ENABLE_DEBUG
+ TypeNode *node;
+
+ node = lookup_type_node_I (type);
+ g_return_val_if_fail (node != NULL, 0);
+
+ return g_atomic_int_get (&node->instance_count);
+#else
+ return 0;
+#endif
+}
/* --- implementation details --- */
gboolean
/**
* g_type_get_plugin:
- * @type: The #GType to retrieve the plugin for.
+ * @type: #GType to retrieve the plugin for
*
- * Returns the #GTypePlugin structure for @type or
- * %NULL if @type does not have a #GTypePlugin structure.
+ * Returns the #GTypePlugin structure for @type.
*
- * Returns: (transfer none): The corresponding plugin if @type is a
- * dynamic type, %NULL otherwise.
+ * Returns: (transfer none): the corresponding plugin
+ * if @type is a dynamic type, %NULL otherwise
*/
GTypePlugin*
g_type_get_plugin (GType type)
/**
* g_type_interface_get_plugin:
- * @instance_type: the #GType value of an instantiatable type.
- * @interface_type: the #GType value of an interface type.
+ * @instance_type: #GType of an instantiatable type
+ * @interface_type: #GType of an interface type
*
* Returns the #GTypePlugin structure for the dynamic interface
- * @interface_type which has been added to @instance_type, or %NULL if
- * @interface_type has not been added to @instance_type or does not
- * have a #GTypePlugin structure. See g_type_add_interface_dynamic().
+ * @interface_type which has been added to @instance_type, or %NULL
+ * if @interface_type has not been added to @instance_type or does
+ * not have a #GTypePlugin structure. See g_type_add_interface_dynamic().
*
* Returns: (transfer none): the #GTypePlugin for the dynamic
- * interface @interface_type of @instance_type.
+ * interface @interface_type of @instance_type
*/
GTypePlugin*
g_type_interface_get_plugin (GType instance_type,
* The returned type ID represents the highest currently registered
* fundamental type identifier.
*
- * Returns: The nextmost fundamental type ID to be registered,
- * or 0 if the type system ran out of fundamental type IDs.
+ * Returns: the next available fundamental type ID to be registered,
+ * or 0 if the type system ran out of fundamental type IDs
*/
GType
g_type_fundamental_next (void)
* @type_id: valid type ID
*
* Internal function, used to extract the fundamental type ID portion.
- * use G_TYPE_FUNDAMENTAL() instead.
+ * Use G_TYPE_FUNDAMENTAL() instead.
*
* Returns: fundamental type ID
*/
}
gboolean
+g_type_check_instance_is_fundamentally_a (GTypeInstance *type_instance,
+ GType fundamental_type)
+{
+ TypeNode *node;
+ if (!type_instance || !type_instance->g_class)
+ return FALSE;
+ node = lookup_type_node_I (type_instance->g_class->g_type);
+ return node && (NODE_FUNDAMENTAL_TYPE(node) == fundamental_type);
+}
+
+gboolean
g_type_check_class_is_a (GTypeClass *type_class,
GType is_a_type)
{
/**
* g_type_check_instance:
- * @instance: A valid #GTypeInstance structure.
+ * @instance: a valid #GTypeInstance structure
*
- * Private helper function to aid implementation of the G_TYPE_CHECK_INSTANCE()
- * macro.
+ * Private helper function to aid implementation of the
+ * G_TYPE_CHECK_INSTANCE() macro.
*
- * Returns: %TRUE if @instance is valid, %FALSE otherwise.
+ * Returns: %TRUE if @instance is valid, %FALSE otherwise
*/
gboolean
g_type_check_instance (GTypeInstance *type_instance)
/**
* g_type_value_table_peek: (skip)
- * @type: A #GType value.
+ * @type: a #GType
*
* Returns the location of the #GTypeValueTable associated with @type.
- * <emphasis>Note that this function should only be used from source code
+ *
+ * Note that this function should only be used from source code
* that implements or has internal knowledge of the implementation of
- * @type.</emphasis>
+ * @type.
*
- * Returns: Location of the #GTypeValueTable associated with @type or
- * %NULL if there is no #GTypeValueTable associated with @type.
+ * Returns: location of the #GTypeValueTable associated with @type or
+ * %NULL if there is no #GTypeValueTable associated with @type
*/
GTypeValueTable*
g_type_value_table_peek (GType type)
/* --- initialization --- */
/**
* g_type_init_with_debug_flags:
- * @debug_flags: Bitwise combination of #GTypeDebugFlags values for
- * debugging purposes.
+ * @debug_flags: bitwise combination of #GTypeDebugFlags values for
+ * debugging purposes
*
* This function used to initialise the type system with debugging
* flags. Since GLib 2.36, the type system is initialised automatically
{
GDebugKey debug_keys[] = {
{ "objects", G_TYPE_DEBUG_OBJECTS },
+ { "instance-count", G_TYPE_DEBUG_INSTANCE_COUNT },
{ "signals", G_TYPE_DEBUG_SIGNALS },
};
/**
* g_type_class_add_private:
* @g_class: class structure for an instantiatable type
- * @private_size: size of private structure.
+ * @private_size: size of private structure
*
* Registers a private structure for an instantiatable type.
*
* When an object is allocated, the private structures for
* the type and all of its parent types are allocated
* sequentially in the same memory block as the public
- * structures.
+ * structures, and are zero-filled.
*
* Note that the accumulated size of the private structures of
* a type and all its parent types cannot exceed 64 KiB.
* G_TYPE_INSTANCE_GET_PRIVATE() macro.
*
* The following example shows attaching a private structure
- * <structname>MyObjectPrivate</structname> to an object
- * <structname>MyObject</structname> defined in the standard GObject
- * fashion.
- * type's class_init() function.
+ * MyObjectPrivate to an object MyObject defined in the standard
+ * GObject fashion in the type's class_init() function.
+ *
* Note the use of a structure member "priv" to avoid the overhead
* of repeatedly calling MY_OBJECT_GET_PRIVATE().
*
- * |[
+ * |[<!-- language="C" -->
* typedef struct _MyObject MyObject;
* typedef struct _MyObjectPrivate MyObjectPrivate;
*
* my_object->priv = G_TYPE_INSTANCE_GET_PRIVATE (my_object,
* MY_TYPE_OBJECT,
* MyObjectPrivate);
+ * // my_object->priv->some_field will be automatically initialised to 0
* }
*
* static int
/**
* g_type_add_class_private:
- * @class_type: GType of an classed type.
- * @private_size: size of private structure.
+ * @class_type: GType of an classed type
+ * @private_size: size of private structure
*
* Registers a private class structure for a classed type;
* when the class is allocated, the private structures for
* the class and all of its parent types are allocated
* sequentially in the same memory block as the public
- * structures. This function should be called in the
+ * structures, and are zero-filled.
+ *
+ * This function should be called in the
* type's get_type() function after the type is registered.
* The private structure can be retrieved using the
* G_TYPE_CLASS_GET_PRIVATE() macro.
/**
* g_type_ensure:
- * @type: a #GType.
+ * @type: a #GType
*
* Ensures that the indicated @type has been registered with the
* type system, and its _class_init() method has been run.
g_error ("can't happen");
}
-gboolean
-g_type_is_in_init (GType type)
-{
- TypeNode *node;
-
- node = lookup_type_node_I (type);
-
- return node->data->class.init_state != INITIALIZED;
-}