summaryrefslogtreecommitdiff
path: root/gi/pygi-boxed.c
diff options
context:
space:
mode:
authorSimon Feltman <sfeltman@src.gnome.org>2014-01-01 19:57:06 -0800
committerSimon Feltman <sfeltman@src.gnome.org>2014-01-01 19:57:06 -0800
commite8359847136e9ad76a670a382c0abc61cb4e81d3 (patch)
treeae514accfc7450852c3b2ab81e336ddc9fde4598 /gi/pygi-boxed.c
parent9ce527b09ed032f2cc83c2d83de8bb6d7b19be02 (diff)
downloadpygobject-e8359847136e9ad76a670a382c0abc61cb4e81d3.tar.gz
Cleanup disguised struct constructor error and add it to boxed
Give a cleaner error message when an attempt is made to create a disguised struct which also gives a hint to look at the pydoc. Add similar error to disguised boxed/unions. https://bugzilla.gnome.org/show_bug.cgi?id=647249
Diffstat (limited to 'gi/pygi-boxed.c')
-rw-r--r--gi/pygi-boxed.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/gi/pygi-boxed.c b/gi/pygi-boxed.c
index d352e232..ea798ff6 100644
--- a/gi/pygi-boxed.c
+++ b/gi/pygi-boxed.c
@@ -47,7 +47,8 @@ _boxed_dealloc (PyGIBoxed *self)
void *
_pygi_boxed_alloc (GIBaseInfo *info, gsize *size_out)
{
- gsize size;
+ gpointer boxed = NULL;
+ gsize size = 0;
switch (g_base_info_get_type (info)) {
case GI_INFO_TYPE_UNION:
@@ -64,10 +65,21 @@ _pygi_boxed_alloc (GIBaseInfo *info, gsize *size_out)
return NULL;
}
+ if (size == 0) {
+ PyErr_Format (PyExc_TypeError,
+ "boxed cannot be created directly; try using a constructor, see: help(%s.%s)",
+ g_base_info_get_namespace (info),
+ g_base_info_get_name (info));
+ return NULL;
+ }
+
if( size_out != NULL)
*size_out = size;
- return g_slice_alloc0 (size);
+ boxed = g_slice_alloc0 (size);
+ if (boxed == NULL)
+ PyErr_NoMemory();
+ return boxed;
}
static PyObject *
@@ -90,7 +102,6 @@ _boxed_new (PyTypeObject *type,
boxed = _pygi_boxed_alloc (info, &size);
if (boxed == NULL) {
- PyErr_NoMemory();
goto out;
}