mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 15:06: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
|
||||
* @private_size: size of private structure.
|
||||
*
|
||||
* Registers a private structure for an instantiatable type;
|
||||
* when an object is allocated, the private structures for
|
||||
* 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. 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.
|
||||
* structures.
|
||||
*
|
||||
* 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
|
||||
* <structname>MyObjectPrivate</structname> to an object
|
||||
* <structname>MyObject</structname> defined in the standard GObject
|
||||
@ -4433,6 +4440,7 @@ g_type_class_add_private (gpointer g_class,
|
||||
gsize offset;
|
||||
|
||||
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)
|
||||
{
|
||||
@ -4454,6 +4462,9 @@ g_type_class_add_private (gpointer g_class,
|
||||
G_WRITE_LOCK (&type_rw_lock);
|
||||
|
||||
offset = ALIGN_STRUCT (node->data->instance.private_size);
|
||||
|
||||
g_assert (offset + private_size <= 0xffff);
|
||||
|
||||
node->data->instance.private_size = offset + private_size;
|
||||
|
||||
G_WRITE_UNLOCK (&type_rw_lock);
|
||||
|
Loading…
Reference in New Issue
Block a user