Changing the passed arguments value after returning from a module

Jean-Daniel Aussel Jean-Daniel.Aussel at bull.net
Fri Jan 21 12:57:49 EST 2000


thanks for the tips.
I tried the code you sent that does not however succeeds:

    /* N.B.: Not tested */
    static PyObject* sct_tt( PyObject* zself, PyObject* args)
    {
        PyObject* o;
        if (!PyArg_ParseTuple(args, "O", o))
             return NULL;
        ((PyIntObject*) o)->ob_ival = 101;
        Py_INCREF(Py_None);
        return Py_None;
    }

I am currently investigating code generated with SWIG1.1, wich looks like:

static PyObject *_wrap_fact(PyObject *self, PyObject *args) {
    PyObject * _resultobj;
    int  _result;
    int * _arg0;
    char * _argc0 = 0;

    if(!PyArg_ParseTuple(args,"s:fact",&_arg0))
        return NULL;
    if (_argc0) {
        if (SWIG_GetPtr(_argc0,(void **) &_arg0,"_int_p")) {
            PyErr_SetString(PyExc_TypeError,"Type error in argument 1 of
fact. Expected _int_p.");
        return NULL;
        }
    }
    _result = (int )fact(_arg0);
    _resultobj = Py_BuildValue("i",_result);
    return _resultobj;
}

I had no time to test though, since the weekend is coming. More on this next
week...

Regards,

/jda

Adrian Eyre wrote in message
<002e01bf641b$5a5f8fd0$3acbd9c2 at peridot.optichrome.com>...
>> >>> import mymodule
>> >>> i = (0,)
>> >>> apply(mymodule.test, i)
>> >>> print i
>> 101
>
>Slight correction here. Probably obvious, but...
>
>>>> import mymodule
>>>> i = (0,)
>>>> apply(mymodule.test, i)
>>>> print i
>(101,)
>
>--------------------------------------------
>Adrian Eyre <a.eyre at optichrome.com>
>http://www.optichrome.com
>
>
>





More information about the Python-list mailing list