Hi,
I am writing an extension module in C++. I am facing a problem with PyArg_ParseTuple. Here is the relevant portion of my code:
TInt type = -1;
char *s_key, *s_value;//to address, data
s_key=NULL;
s_value=NULL;
int l_key, l_value; //lengths of strings
long int l_valuel;//from serviceid, to serviceid
int i_value; //protocol
double d_value1;
double d_value2;
float f_value;
Py_complex c;
/* Possible types are:
EIntType,
ELongType,
EStringType,
EFloatType,
EComplexType
Determine type:
*/
if(PyArg_ParseTuple(args, "u#s#", &s_key, &l_key, &s_value, &l_value)) /* type-checked */
type=CAppConfig::EStringType;
else if(PyArg_ParseTuple(args, "u#f", &s_key, &l_key, &f_value))
{
d_value1 = f_value;
type=CAppConfig::EFloatType;
}
else if(PyArg_ParseTuple(args, "u#d", &s_key, &l_key, &d_value1))
type=CAppConfig::EFloatType;
else if(PyArg_ParseTuple(args, "u#i", &s_key, &l_key, &i_value))
type=CAppConfig::EIntType;
else if(PyArg_ParseTuple(args, "u#l", &s_key, &l_key, &l_valuel))
type=CAppConfig::ELongType;
else if(PyArg_ParseTuple(args, "u#D", &s_key, &l_key, &c))
{
type=CAppConfig::EComplexType;
d_value1 = c.real;
d_value2 = c.imag;
}
else
{
PyErr_BadArgument();
return NULL;
}
This code always works with strings and ints with no problems. However, when i pass in a float like 12.22, it detects it as int. For complex type is always branches to PyErr_BadArgument(); same applies for long int's
Any info/help in this regard will be much appreciated!!!!
Regards,
Varun

Reply With Quote

