[pygobject] GVariant: Don't use pyg_boxed_new as GVariant isn't a PyGBoxed but a PyGIStruct.
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] GVariant: Don't use pyg_boxed_new as GVariant isn't a PyGBoxed but a PyGIStruct.
- Date: Mon, 29 Feb 2016 13:43:54 +0000 (UTC)
commit 49880800b35029de3731523eede1b3174f10c1db
Author: Christoph Reiter <creiter src gnome org>
Date: Sat Jul 4 21:40:04 2015 +0200
GVariant: Don't use pyg_boxed_new as GVariant isn't a PyGBoxed but a PyGIStruct.
This only worked because they share the same struct layout.
This adds a new constructor for creating a new PyGIStruct instance from GType.
https://bugzilla.gnome.org/show_bug.cgi?id=751956
gi/pygi-struct.c | 32 ++++++++++++++++++++++++++++++++
gi/pygi-struct.h | 5 +++++
gi/pygi-value.c | 3 ++-
3 files changed, 39 insertions(+), 1 deletions(-)
---
diff --git a/gi/pygi-struct.c b/gi/pygi-struct.c
index d84eed5..c379a88 100644
--- a/gi/pygi-struct.c
+++ b/gi/pygi-struct.c
@@ -132,6 +132,38 @@ _struct_init (PyObject *self,
PYGLIB_DEFINE_TYPE("gi.Struct", PyGIStruct_Type, PyGIStruct);
+
+PyObject *
+_pygi_struct_new_from_g_type (GType g_type,
+ gpointer pointer,
+ gboolean free_on_dealloc)
+{
+ PyGIStruct *self;
+ PyTypeObject *type;
+
+ type = (PyTypeObject *)pygi_type_import_by_g_type (g_type);
+
+ if (!type)
+ type = (PyTypeObject *)&PyGIStruct_Type; /* fallback */
+
+ if (!PyType_IsSubtype (type, &PyGIStruct_Type)) {
+ PyErr_SetString (PyExc_TypeError, "must be a subtype of gi.Struct");
+ return NULL;
+ }
+
+ self = (PyGIStruct *) type->tp_alloc (type, 0);
+ if (self == NULL) {
+ return NULL;
+ }
+
+ pyg_pointer_set_ptr (self, pointer);
+ ( (PyGPointer *) self)->gtype = g_type;
+ self->free_on_dealloc = free_on_dealloc;
+
+ return (PyObject *) self;
+}
+
+
PyObject *
_pygi_struct_new (PyTypeObject *type,
gpointer pointer,
diff --git a/gi/pygi-struct.h b/gi/pygi-struct.h
index ab303e0..347c55f 100644
--- a/gi/pygi-struct.h
+++ b/gi/pygi-struct.h
@@ -31,6 +31,11 @@ _pygi_struct_new (PyTypeObject *type,
gpointer pointer,
gboolean free_on_dealloc);
+PyObject *
+_pygi_struct_new_from_g_type (GType g_type,
+ gpointer pointer,
+ gboolean free_on_dealloc);
+
void _pygi_struct_register_types (PyObject *m);
G_END_DECLS
diff --git a/gi/pygi-value.c b/gi/pygi-value.c
index 3bdd854..413e14a 100644
--- a/gi/pygi-value.c
+++ b/gi/pygi-value.c
@@ -18,6 +18,7 @@
#include <Python.h>
#include "pygi-value.h"
+#include "pygi-struct.h"
#include "pyglib-python-compat.h"
#include "pygobject-private.h"
#include "pygtype.h"
@@ -810,7 +811,7 @@ pygi_value_to_py_structured_type (const GValue *value, GType fundamental, gboole
Py_INCREF(Py_None);
return Py_None;
}
- return pyg_boxed_new(G_TYPE_VARIANT, g_variant_ref(v), FALSE, FALSE);
+ return _pygi_struct_new_from_g_type (G_TYPE_VARIANT, g_variant_ref(v), FALSE);
}
default:
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]