[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

RE: inconsistency in Python SWIG return parameters

From: Dale Hirt <dale_at_sbcltd.com>
Date: 2003-02-28 01:10:56 CET

First shot across the bow:

/*
 * Helper function to return tuples
 * SVN version to allow for first value of a tuple to be None
 */

%fragment("svn_t_output_helper","header") %{
static PyObject* svn_t_output_helper(PyObject* target, PyObject* o) {
    PyObject* o2;
    PyObject* o3;

    /* If we pass in a NULL arg, then we'll create a new tuple, and make the
first item = o*/
    if (target == NULL)
    {
        target = PyTuple_New(1);
        PyTuple_SetItem(target, 0, o);
    }
    /* If we pass in a Py_None arg, it must be the first time through.
     * We would have already created a tuple by now and populated it,
     * so we'll decrement Py_None, and then we'll create a new tuple,
     * and make the first item = o
     */
    else if (target == Py_None)
    {
        Py_DECREF(Py_None);
        target = PyTuple_New(1);
        PyTuple_SetItem(target, 0, o);
    }
    /* This should work for every argument after the first one */
    else
    {
        /* Not strictly necessary, assuming that we have actually called it
in the right order,
         * but assuming is the easy way to the grave, so we'll create a
tuple if it doesn't
         * exist.
         */
        if (!PyTuple_Check(target))
        {
            o2 = target;
            target = PyTuple_New(1);
            PyTuple_SetItem(target, 0, o2);
        }
        o3 = PyTuple_New(1);
        PyTuple_SetItem(o3, 0, o);

        o2 = target;
        target = PySequence_Concat(o2, o3);
        Py_DECREF(o2);
        Py_DECREF(o3);
    }
    return target;
}
%}

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Fri Feb 28 01:11:44 2003

This is an archived mail posted to the Subversion Dev mailing list.