Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Python C extension: Value different if passed as list than if passed as number

Reply
Thread Tools

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

 
 
Anand
Guest
Posts: n/a
 
      09-10-2003
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
 
Reply With Quote
 
 
 
 
Anand
Guest
Posts: n/a
 
      09-11-2003
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.
 
Reply With Quote
 
 
 
 
Anand
Guest
Posts: n/a
 
      09-11-2003
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to tell if a number has decimal places different than 0 Gaijinco C++ 27 09-28-2005 07:58 PM
How to tell if a number has decimal places different than 0 Gaijinco C Programming 29 09-28-2005 07:58 PM
The while loop for calculating a power of a number less than another number? Erik the Red Ruby 4 07-29-2005 08:28 PM
The number name 'System.Web.UI.WebControls' contains more than the maximum number of prefixes. The maximum is 3. mayur ASP .Net Web Controls 2 07-16-2004 05:14 PM
The number name 'System.Web.UI.WebControls' contains more than the maximum number of prefixes. The maximum is 3. mayur ASP .Net 2 07-02-2004 10:35 AM



Advertisments