Re: GObjectClass->constructor revised, g_object_newv_with_data



On Tue, 5 Jul 2005, Tim Janik wrote:

On Tue, 7 Jun 2005, Gustavo J. A. M. Carneiro wrote:

i'm not sure i fully understand your problems here, so far i see
three use cases:
1) you create a GObject derived C object and have a PyObject proxy
2) you create a GObject derived Python object and have a PyObject proxy
3) you create a GObject derived Python object and have no PyObject proxy
[...]

for (2), you derived from some GObject type, so you get to provide your own
GInstanceInitFunc and can do something like:

static __thread PyObject *current_proxy = NULL;

static void
python_gobject_init (GObject    *object,
                    GTypeClass *g_class)
{
 PyObject *pob = current_proxy;
 current_proxy = NULL;
 python_proxy_attach (pob, object);
}

static void
python_proxy_create_python_object (PyObject       *pob,
                                  GType           python_gobject_type,
                                  guint           n_parameters,
                                  GParameter     *parameters)
{
 g_assert (current_proxy == NULL);
 current_proxy = pob;
GObject *object = g_object_newv (python_gobject_type, n_parameters, parameters);
}

and the extension to cover (3):

static PyObject*
create_python_gobject             (GType           python_gobject_type,
                                  guint           n_parameters,
                                  GParameter     *parameters)
{
 PyObject *pob = python_proxy_create();
 python_proxy_create_python_object (pob, python_gobject_type,
                                    n_parameters, parameters);
 return pob;
}

i need to correct myself here. (3) was meant to cover the case where
someone creates a python object from C code, i.e. via g_object_new().
so solving (3) does not involve writing a wrapper around g_object_newv(),
but demand creation of a python proxy in python_gobject_init(), i.e.
forget create_python_gobject() and apply the following:

 static void
 python_gobject_init (GObject    *object,
                     GTypeClass *g_class)
 {
  PyObject *pob = current_proxy;
  current_proxy = NULL;
+ if (!pob)
+   pob = python_proxy_create();
  python_proxy_attach (pob, object);
 }


---
ciaoTJ

---
ciaoTJ



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]