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

A

Anand

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
 
A

Anand

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.
 
A

Anand

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top