Python C extension: Value different if passed as list than if passed as number

Discussion in 'Python' started by Anand, Sep 10, 2003.

  1. Anand

    Anand Guest

    I have a C extension to a dll function.

    static PyObject *_wrap_SetTxCommandRegister(PyObject *self, PyObject
    *args) {
    PyObject *resultobj;
    int arg1 ;
    int arg2 ;
    int arg3 ;
    char *arg4 = (char *)"Python" ;
    err result;

    if(!PyArg_ParseTuple(args,(char
    *)"iii|s:SetTxCommandRegister",&arg1,&arg2,&arg3,&arg4)) goto fail;
    result = (err)SetTxCommandRegister(arg1,arg2,arg3,(char const
    *)arg4);
    resultobj = PyInt_FromLong((long)result);
    return resultobj;
    fail:
    return NULL;
    }

    Now here is what i pass from python
    test = [0xff,0xaf,0xf0]
    newint = test[0]
    SetTxCommandRegister(0xff,test[1],test[2])
    print test

    arg1 = 0xaf if i pass either test[0] or newint
    arg1 = 0xff if i pass constant like what i have shown in the code

    What am i doing wrong?

    Thanks in advance
    Anand
     
    Anand, Sep 10, 2003
    #1
    1. Advertising

  2. Anand

    Anand Guest

    My bad. I wanted to a inplace memory write for an int. so

    i = 0;
    func(i);
    print i;

    ======
    output = 1.

    The funny thing is python doesnt use 0 as 0. instead it points to a
    memory location whose value = 0.

    Since in my inplace replace, i changed that value from 0 to 1,
    test[0] actually became test[1] :))

    so i had tons of strange behavior happening. I shouldnt have made an
    immutable object as mutable.
     
    Anand, Sep 11, 2003
    #2
    1. Advertising

  3. Anand

    Anand Guest

    My bad. I wanted to do a inplace memory write for an int. so

    i = 0;
    func(i);
    print i;

    ======
    output = 1.

    The funny thing is python doesnt use 0 as 0. instead it points to a
    memory location whose value = 0.

    Since in my inplace replace, i changed that value from 0 to 1,
    test[0] actually became test[1] :))

    so i had tons of strange behavior happening. I shouldnt have made an
    immutable object as mutable.
     
    Anand, Sep 11, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mayur
    Replies:
    2
    Views:
    1,040
    Natty Gur
    Jul 2, 2004
  2. dee
    Replies:
    9
    Views:
    528
    Joseph Byrns
    Apr 15, 2005
  3. Christian Seberino
    Replies:
    3
    Views:
    1,208
    Christian Seberino
    Feb 5, 2004
  4. Gaijinco
    Replies:
    29
    Views:
    2,950
    Anonymous 7843
    Sep 28, 2005
  5. Gaijinco
    Replies:
    27
    Views:
    1,098
    Anonymous 7843
    Sep 28, 2005
Loading...

Share This Page