summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Henstridge <james@daa.com.au>2002-06-23 13:56:46 +0000
committerJames Henstridge <jamesh@src.gnome.org>2002-06-23 13:56:46 +0000
commitee6e2f2bf962136029b000e3dc77abf13d217672 (patch)
treef90bc7ad89a01c147fce0b5c56d7c9397c22930e
parent8a4a369dd860c5e584c5562c3b90e7d1290796a3 (diff)
downloadpygobject-ee6e2f2bf962136029b000e3dc77abf13d217672.tar.gz
pygobject-ee6e2f2bf962136029b000e3dc77abf13d217672.tar.xz
pygobject-ee6e2f2bf962136029b000e3dc77abf13d217672.zip
copy boxed arguments.
2002-06-23 James Henstridge <james@daa.com.au> * gtk/gtk.override (_wrap_gtk_tree_sortable_get_sort_column_id): copy boxed arguments. * pygobject.h: fix up prototypes. * gobjectmodule.c (pyg_object_set_property): copy boxed arguments. * pygobject.c (pygobject_get_property): copy boxed arguments here. (pygobject_emit): same here. (pygobject_chain_from_overridden): same here. * pygtype.c (pyg_value_as_pyobject): add "copy_boxed" argument to this function. (pyg_closure_marshal): pass FALSE for copy_boxed argument. (pyg_signal_class_closure_marshal): same here.
-rw-r--r--gobject/gobjectmodule.c2
-rw-r--r--gobject/pygobject-private.h2
-rw-r--r--gobject/pygobject.c6
-rw-r--r--gobject/pygobject.h2
-rw-r--r--gobject/pygtype.c29
5 files changed, 28 insertions, 13 deletions
diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c
index 8238f7c..2e6b471 100644
--- a/gobject/gobjectmodule.c
+++ b/gobject/gobjectmodule.c
@@ -385,7 +385,7 @@ pyg_object_set_property (GObject *object, guint property_id,
g_return_if_fail(object_wrapper != NULL);
py_pspec = pyg_param_spec_new(pspec);
- py_value = pyg_value_as_pyobject (value);
+ py_value = pyg_value_as_pyobject (value, TRUE);
retval = PyObject_CallMethod(object_wrapper, "do_set_property",
"OO", py_pspec, py_value);
if (retval) {
diff --git a/gobject/pygobject-private.h b/gobject/pygobject-private.h
index acf13b0..e8b768d 100644
--- a/gobject/pygobject-private.h
+++ b/gobject/pygobject-private.h
@@ -50,7 +50,7 @@ void pyg_register_boxed_custom(GType boxed_type,
fromvaluefunc from_func,
tovaluefunc to_func);
int pyg_value_from_pyobject(GValue *value, PyObject *obj);
-PyObject *pyg_value_as_pyobject(const GValue *value);
+PyObject *pyg_value_as_pyobject(const GValue *value, gboolean copy_boxed);
GClosure *pyg_closure_new(PyObject *callback, PyObject *extra_args, PyObject *swap_data);
GClosure *pyg_signal_class_closure_get(void);
diff --git a/gobject/pygobject.c b/gobject/pygobject.c
index d54b5b3..1c99deb 100644
--- a/gobject/pygobject.c
+++ b/gobject/pygobject.c
@@ -279,7 +279,7 @@ pygobject_get_property(PyGObject *self, PyObject *args)
}
g_value_init(&value, G_PARAM_SPEC_VALUE_TYPE(pspec));
g_object_get_property(self->obj, param_name, &value);
- ret = pyg_value_as_pyobject(&value);
+ ret = pyg_value_as_pyobject(&value, TRUE);
g_value_unset(&value);
return ret;
}
@@ -633,7 +633,7 @@ pygobject_emit(PyGObject *self, PyObject *args)
g_value_unset(&params[i]);
g_free(params);
if ((query.return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE) != G_TYPE_NONE) {
- py_ret = pyg_value_as_pyobject(&ret);
+ py_ret = pyg_value_as_pyobject(&ret, TRUE);
g_value_unset(&ret);
} else {
Py_INCREF(Py_None);
@@ -721,7 +721,7 @@ pygobject_chain_from_overridden(PyGObject *self, PyObject *args)
g_value_unset(&params[i]);
g_free(params);
if ((query.return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE) != G_TYPE_NONE) {
- py_ret = pyg_value_as_pyobject(&ret);
+ py_ret = pyg_value_as_pyobject(&ret, TRUE);
g_value_unset(&ret);
} else {
Py_INCREF(Py_None);
diff --git a/gobject/pygobject.h b/gobject/pygobject.h
index 69af1af..5cc4f49 100644
--- a/gobject/pygobject.h
+++ b/gobject/pygobject.h
@@ -60,7 +60,7 @@ struct _PyGObject_Functions {
PyObject *(* from_func)(const GValue *value),
int (* to_func)(GValue *value, PyObject *obj));
int (* value_from_pyobject)(GValue *value, PyObject *obj);
- PyObject *(* value_as_pyobject)(const GValue *value);
+ PyObject *(* value_as_pyobject)(const GValue *value, gboolean copy_boxed);
void (* register_interface)(PyObject *dict, const gchar *class_name,
GType gtype, PyTypeObject *type);
diff --git a/gobject/pygtype.c b/gobject/pygtype.c
index d03f7f6..36256b7 100644
--- a/gobject/pygtype.c
+++ b/gobject/pygtype.c
@@ -476,8 +476,18 @@ pyg_value_from_pyobject(GValue *value, PyObject *obj)
return 0;
}
+/**
+ * pyg_value_as_pyobject:
+ * @value: the GValue object.
+ * @copy_boxed: true if boxed values should be copied.
+ *
+ * This function creates/returns a Python wrapper object that
+ * represents the GValue passed as an argument.
+ *
+ * Returns: a PyObject representing the value.
+ */
PyObject *
-pyg_value_as_pyobject(const GValue *value)
+pyg_value_as_pyobject(const GValue *value, gboolean copy_boxed)
{
gchar buf[128];
@@ -575,11 +585,16 @@ pyg_value_as_pyobject(const GValue *value)
}
bm = pyg_boxed_lookup(G_VALUE_TYPE(value));
- if (bm)
+ if (bm) {
return bm->fromvalue(value);
- else
- return pyg_boxed_new(G_VALUE_TYPE(value),
- g_value_get_boxed(value), TRUE, TRUE);
+ } else {
+ if (copy_boxed)
+ return pyg_boxed_new(G_VALUE_TYPE(value),
+ g_value_get_boxed(value), TRUE, TRUE);
+ else
+ return pyg_boxed_new(G_VALUE_TYPE(value),
+ g_value_get_boxed(value),FALSE,FALSE);
+ }
}
case G_TYPE_PARAM:
return pyg_param_spec_new(g_value_get_param(value));
@@ -639,7 +654,7 @@ pyg_closure_marshal(GClosure *closure,
Py_INCREF(pc->swap_data);
PyTuple_SetItem(params, 0, pc->swap_data);
} else {
- PyObject *item = pyg_value_as_pyobject(&param_values[i]);
+ PyObject *item = pyg_value_as_pyobject(&param_values[i], FALSE);
/* error condition */
if (!item) {
@@ -758,7 +773,7 @@ pyg_signal_class_closure_marshal(GClosure *closure,
/* construct Python tuple for the parameter values */
params = PyTuple_New(n_param_values - 1);
for (i = 1; i < n_param_values; i++) {
- PyObject *item = pyg_value_as_pyobject(&param_values[i]);
+ PyObject *item = pyg_value_as_pyobject(&param_values[i], TRUE);
/* error condition */
if (!item) {