I'm adding a wrapper for gtk_tree_selection_selected_foreach to
gtk.overrides.  So far, I have this code:

    %%
    override gtk_tree_selection_selected_foreach
    static void
    _ts_select_foreach_func(GtkTreeModel *model,
                            GtkTreePath *path,
                            GtkTreeIter *iter,
                            gpointer data)
    {

    /* the real Python function we want to call is hidden in the data */
    /* extract that function, wrap the various data args and call it */

        PyObject *compound = (PyObject *)data;
        PyObject *foreach_func;
        PyObject *gdata;
        PyObject *pymodel;
        PyObject *pypath;
        PyObject *pyiter;
        PyObject *result;

        foreach_func = PyTuple_GET_ITEM(compound, 0);
        gdata = PyTuple_GET_ITEM(compound, 1);

        pymodel = pygobject_new((GObject *)model);
        if (pymodel == NULL)
            return;
        pypath = pygobject_new((GObject *)path);
        if (pypath == NULL) {
            Py_DECREF(pypath);
            return;
        }
        pyiter = pygobject_new((GObject *)iter);
        if (pyiter == NULL) {
            Py_DECREF(pymodel);
            Py_DECREF(pypath);
            return;
        }

        result = PyObject_CallFunction(foreach_func, "OOOO", pymodel, pypath,
                                       pyiter, gdata);
        Py_XDECREF(result);
        Py_DECREF(pymodel);
        Py_DECREF(pypath);
        Py_DECREF(pyiter);

    }

    static PyObject *
    _wrap_gtk_tree_selection_selected_foreach(PyGObject *self, PyObject *args)
    {
        PyObject *foreach_func = NULL;
        PyObject *data = NULL;
        PyObject *compound;

        if (!PyArg_ParseTuple(args, "O|O:GtkTreeSelection.selected_foreach",
                              &foreach_func, &data))
            return NULL;

        if (data == NULL) {
            data = Py_None;
        }
        Py_INCREF(data);

        compound = Py_BuildValue("(OO)", foreach_func, data);
        Py_DECREF(data);

        if (compound == NULL)
            return NULL;

        gtk_tree_selection_selected_foreach(GTK_TREE_SELECTION(self->obj),
                                            _ts_select_foreach_func,
                                            (gpointer)compound);
        Py_DECREF(compound);

        if (PyErr_Occurred())
            return NULL;
        Py_INCREF(Py_None);
        return Py_None;
    }

When I run my example script and select an item in a list, it segfaults a
couple of stackframes down from _ts_select_foreach_func trying to make a
pygobject out of the GtkTreePath pointer that was passed in.  That object
looks reasonable when viewed from gdb:

    (gdb) p *path
    $2 = {
      depth = 1, 
      indices = 0x835f1e0
    }

but that's not a lot to go on.

Here's the beginning of the backtrace with the corresponding C source lines:

    (gdb) bt
    #0  0x401be364 in g_object_get_qdata (object=0x835f9f8, quark=46)
        at gobject.c:1328
  g_return_val_if_fail (G_IS_OBJECT (object), NULL);

    #1  0x4019a10f in pygobject_new (obj=0x835f9f8) at gobjectmodule.c:305
  if ((self = (PyGObject *)g_object_get_qdata(obj, pygobject_wrapper_key))) {

    #2  0x40293c01 in _ts_select_foreach_func (model=0x82ec210, path=0x835f9f8, 
        iter=0xbfffdf10, data=0x82e22e4) at gtk.override:1371
  pypath = pygobject_new((GObject *)path);

    #3  0x4046684d in gtk_tree_selection_selected_foreach (selection=0x82e9d80, 
        func=0x40293bb0 <_ts_select_foreach_func>, data=0x82e22e4)
        at gtktreeselection.c:401
  (* func) (selection->tree_view->priv->model, path, &iter, data);

    #4  0x40293dc1 in _wrap_gtk_tree_selection_selected_foreach (self=0x82f9ebc, 
        args=0x82da1d4) at gtk.override:1415
  gtk_tree_selection_selected_foreach(GTK_TREE_SELECTION(self->obj),

I'm only operating on a simple single-column list for my initial testing.
I'd post the code that that, but it's as complex as the C code, and I think
this is more likely a problem with my C code.  (The script was working using
selection.get_selected instead of selection.selected_foreach.)

Any ideas?

-- 
Skip Montanaro ([EMAIL PROTECTED])
http://www.mojam.com/
http://www.musi-cal.com/
_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk

Reply via email to