diff options
| author | Tomeu Vizoso <tomeu.vizoso@collabora.co.uk> | 2010-07-30 14:14:16 +0200 |
|---|---|---|
| committer | Tomeu Vizoso <tomeu.vizoso@collabora.co.uk> | 2010-07-30 16:49:47 +0200 |
| commit | caac75a6ed6f671b37e38a78e71b87906a00ac1b (patch) | |
| tree | 7cdd926d2d6930faceb5a77b9aa6408e07d19a49 /gi/pygi-boxed.c | |
| parent | 99c7322898c00a576c7319ea0a7c808446253133 (diff) | |
| download | pygobject-caac75a6ed6f671b37e38a78e71b87906a00ac1b.tar.gz | |
Properly allocate boxed structs that are (caller-allocates)
* gi/pygi-boxed.[hc]: Refactor out the allocation of boxed structs
* gi/pygi-invoke.c: Don't use g_malloc0 for boxed structs that
are (caller-allocates)
* tests/test_overrides.py: Split the TreeView tests
https://bugzilla.gnome.org/show_bug.cgi?id=625653
Diffstat (limited to 'gi/pygi-boxed.c')
| -rw-r--r-- | gi/pygi-boxed.c | 50 |
1 files changed, 33 insertions, 17 deletions
diff --git a/gi/pygi-boxed.c b/gi/pygi-boxed.c index 49038344..66a25850 100644 --- a/gi/pygi-boxed.c +++ b/gi/pygi-boxed.c @@ -47,6 +47,37 @@ _boxed_dealloc (PyGIBoxed *self) ( (PyGObject *) self)->ob_type->tp_free ( (PyObject *) self); } +void * +_pygi_boxed_alloc (GIBaseInfo *info, gsize *size_out) +{ + gsize size; + + /* FIXME: Remove when bgo#622711 is fixed */ + if (g_registered_type_info_get_g_type (info) == G_TYPE_VALUE) { + size = sizeof (GValue); + } else { + switch (g_base_info_get_type (info)) { + case GI_INFO_TYPE_UNION: + size = g_union_info_get_size ( (GIUnionInfo *) info); + break; + case GI_INFO_TYPE_BOXED: + case GI_INFO_TYPE_STRUCT: + size = g_struct_info_get_size ( (GIStructInfo *) info); + break; + default: + PyErr_Format (PyExc_TypeError, + "info should be Boxed or Union, not '%d'", + g_base_info_get_type (info)); + return NULL; + } + } + + if( size_out != NULL) + *size_out = size; + + return g_slice_alloc0 (size); +} + static PyObject * _boxed_new (PyTypeObject *type, PyObject *args, @@ -55,7 +86,7 @@ _boxed_new (PyTypeObject *type, static char *kwlist[] = { NULL }; GIBaseInfo *info; - gsize size; + gsize size = 0; gpointer boxed; PyGIBoxed *self = NULL; @@ -71,22 +102,7 @@ _boxed_new (PyTypeObject *type, return NULL; } - switch (g_base_info_get_type (info)) { - case GI_INFO_TYPE_UNION: - size = g_union_info_get_size ( (GIUnionInfo *) info); - break; - case GI_INFO_TYPE_BOXED: - case GI_INFO_TYPE_STRUCT: - size = g_struct_info_get_size ( (GIStructInfo *) info); - break; - default: - PyErr_Format (PyExc_TypeError, - "info should be Boxed or Union, not '%d'", - g_base_info_get_type (info)); - return NULL; - } - - boxed = g_slice_alloc0 (size); + boxed = _pygi_boxed_alloc (info, &size); if (boxed == NULL) { PyErr_NoMemory(); goto out; |
