mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-26 15:36:14 +01:00
Add a note about size limits of private structures
Also add some assertions to check these limits, instead of failing silently. Bug 604479.
This commit is contained in:
parent
db4fb1b115
commit
42080449d0
@ -4372,13 +4372,20 @@ g_type_init (void)
|
|||||||
* @g_class: class structure for an instantiatable type
|
* @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;
|
* Registers a private structure for an instantiatable type.
|
||||||
* when an object is allocated, the private structures for
|
*
|
||||||
|
* When an object is allocated, the private structures for
|
||||||
* the type and all of its parent types are allocated
|
* the type and all of its parent types are allocated
|
||||||
* sequentially in the same memory block as the public
|
* sequentially in the same memory block as the public
|
||||||
* structures. This function should be called in the
|
* structures.
|
||||||
* type's class_init() function. The private structure can
|
*
|
||||||
* be retrieved using the G_TYPE_INSTANCE_GET_PRIVATE() macro.
|
* Note that the accumulated size of the private structures of
|
||||||
|
* a type and all its parent types cannot excced 64kB.
|
||||||
|
*
|
||||||
|
* This function should be called in the type's class_init() function.
|
||||||
|
* The private structure can be retrieved using the
|
||||||
|
* G_TYPE_INSTANCE_GET_PRIVATE() macro.
|
||||||
|
*
|
||||||
* The following example shows attaching a private structure
|
* The following example shows attaching a private structure
|
||||||
* <structname>MyObjectPrivate</structname> to an object
|
* <structname>MyObjectPrivate</structname> to an object
|
||||||
* <structname>MyObject</structname> defined in the standard GObject
|
* <structname>MyObject</structname> defined in the standard GObject
|
||||||
@ -4433,6 +4440,7 @@ g_type_class_add_private (gpointer g_class,
|
|||||||
gsize offset;
|
gsize offset;
|
||||||
|
|
||||||
g_return_if_fail (private_size > 0);
|
g_return_if_fail (private_size > 0);
|
||||||
|
g_return_if_fail (private_size <= 0xffff);
|
||||||
|
|
||||||
if (!node || !node->is_instantiatable || !node->data || node->data->class.class != g_class)
|
if (!node || !node->is_instantiatable || !node->data || node->data->class.class != g_class)
|
||||||
{
|
{
|
||||||
@ -4454,6 +4462,9 @@ g_type_class_add_private (gpointer g_class,
|
|||||||
G_WRITE_LOCK (&type_rw_lock);
|
G_WRITE_LOCK (&type_rw_lock);
|
||||||
|
|
||||||
offset = ALIGN_STRUCT (node->data->instance.private_size);
|
offset = ALIGN_STRUCT (node->data->instance.private_size);
|
||||||
|
|
||||||
|
g_assert (offset + private_size <= 0xffff);
|
||||||
|
|
||||||
node->data->instance.private_size = offset + private_size;
|
node->data->instance.private_size = offset + private_size;
|
||||||
|
|
||||||
G_WRITE_UNLOCK (&type_rw_lock);
|
G_WRITE_UNLOCK (&type_rw_lock);
|
||||||
|
Loading…
Reference in New Issue
Block a user