/* Functions used by cgen output */#include "Python.h"#include "cgensupport.h"/* Functions to extract arguments. These needs to know the total number of arguments supplied, since the argument list is a tuple only of there is more than one argument. */intPyArg_GetObject(registerPyObject*args,intnargs,inti,PyObject**p_arg){if(nargs!=1){if(args==NULL||!PyTuple_Check(args)||nargs!=PyTuple_Size(args)||i<0||i>=nargs){returnPyErr_BadArgument();}else{args=PyTuple_GetItem(args,i);}}if(args==NULL){returnPyErr_BadArgument();}*p_arg=args;return1;}intPyArg_GetLong(registerPyObject*args,intnargs,inti,long*p_arg){if(nargs!=1){if(args==NULL||!PyTuple_Check(args)||nargs!=PyTuple_Size(args)||i<0||i>=nargs){returnPyErr_BadArgument();}args=PyTuple_GetItem(args,i);}if(args==NULL||!PyInt_Check(args)){returnPyErr_BadArgument();}*p_arg=PyInt_AsLong(args);return1;}intPyArg_GetShort(registerPyObject*args,intnargs,inti,short*p_arg){longx;if(!PyArg_GetLong(args,nargs,i,&x))return0;*p_arg=(short)x;return1;}staticintextractdouble(registerPyObject*v,double*p_arg){if(v==NULL){/* Fall through to error return at end of function */}elseif(PyFloat_Check(v)){*p_arg=PyFloat_AS_DOUBLE((PyFloatObject*)v);return1;}elseif(PyInt_Check(v)){*p_arg=PyInt_AS_LONG((PyIntObject*)v);return1;}elseif(PyLong_Check(v)){*p_arg=PyLong_AsDouble(v);return1;}returnPyErr_BadArgument();}staticintextractfloat(registerPyObject*v,float*p_arg){if(v==NULL){/* Fall through to error return at end of function */}elseif(PyFloat_Check(v)){*p_arg=(float)PyFloat_AS_DOUBLE((PyFloatObject*)v);return1;}elseif(PyInt_Check(v)){*p_arg=(float)PyInt_AS_LONG((PyIntObject*)v);return1;}elseif(PyLong_Check(v)){*p_arg=(float)PyLong_AsDouble(v);return1;}returnPyErr_BadArgument();}intPyArg_GetFloat(registerPyObject*args,intnargs,inti,float*p_arg){PyObject*v;floatx;if(!PyArg_GetObject(args,nargs,i,&v))return0;if(!extractfloat(v,&x))return0;*p_arg=x;return1;}intPyArg_GetString(PyObject*args,intnargs,inti,string*p_arg){PyObject*v;if(!PyArg_GetObject(args,nargs,i,&v))return0;if(!PyString_Check(v)){returnPyErr_BadArgument();}*p_arg=PyString_AsString(v);return1;}intPyArg_GetChar(PyObject*args,intnargs,inti,char*p_arg){stringx;if(!PyArg_GetString(args,nargs,i,&x))return0;if(x[0]=='\0'||x[1]!='\0'){/* Not exactly one char */returnPyErr_BadArgument();}*p_arg=x[0];return1;}intPyArg_GetLongArraySize(PyObject*args,intnargs,inti,long*p_arg){PyObject*v;if(!PyArg_GetObject(args,nargs,i,&v))return0;if(PyTuple_Check(v)){*p_arg=PyTuple_Size(v);return1;}if(PyList_Check(v)){*p_arg=PyList_Size(v);return1;}returnPyErr_BadArgument();}intPyArg_GetShortArraySize(PyObject*args,intnargs,inti,short*p_arg){longx;if(!PyArg_GetLongArraySize(args,nargs,i,&x))return0;*p_arg=(short)x;return1;}/* XXX The following four are too similar. Should share more code. */intPyArg_GetLongArray(PyObject*args,intnargs,inti,intn,long*p_arg){PyObject*v,*w;if(!PyArg_GetObject(args,nargs,i,&v))return0;if(PyTuple_Check(v)){if(PyTuple_Size(v)!=n){returnPyErr_BadArgument();}for(i=0;i<n;i++){w=PyTuple_GetItem(v,i);if(!PyInt_Check(w)){returnPyErr_BadArgument();}p_arg[i]=PyInt_AsLong(w);}return1;}elseif(PyList_Check(v)){if(PyList_Size(v)!=n){returnPyErr_BadArgument();}for(i=0;i<n;i++){w=PyList_GetItem(v,i);if(!PyInt_Check(w)){returnPyErr_BadArgument();}p_arg[i]=PyInt_AsLong(w);}return1;}else{returnPyErr_BadArgument();}}intPyArg_GetShortArray(PyObject*args,intnargs,inti,intn,short*p_arg){PyObject*v,*w;if(!PyArg_GetObject(args,nargs,i,&v))return0;if(PyTuple_Check(v)){if(PyTuple_Size(v)!=n){returnPyErr_BadArgument();}for(i=0;i<n;i++){w=PyTuple_GetItem(v,i);if(!PyInt_Check(w)){returnPyErr_BadArgument();}p_arg[i]=(short)PyInt_AsLong(w);}return1;}elseif(PyList_Check(v)){if(PyList_Size(v)!=n){returnPyErr_BadArgument();}for(i=0;i<n;i++){w=PyList_GetItem(v,i);if(!PyInt_Check(w)){returnPyErr_BadArgument();}p_arg[i]=(short)PyInt_AsLong(w);}return1;}else{returnPyErr_BadArgument();}}intPyArg_GetDoubleArray(PyObject*args,intnargs,inti,intn,double*p_arg){PyObject*v,*w;if(!PyArg_GetObject(args,nargs,i,&v))return0;if(PyTuple_Check(v)){if(PyTuple_Size(v)!=n){returnPyErr_BadArgument();}for(i=0;i<n;i++){w=PyTuple_GetItem(v,i);if(!extractdouble(w,&p_arg[i]))return0;}return1;}elseif(PyList_Check(v)){if(PyList_Size(v)!=n){returnPyErr_BadArgument();}for(i=0;i<n;i++){w=PyList_GetItem(v,i);if(!extractdouble(w,&p_arg[i]))return0;}return1;}else{returnPyErr_BadArgument();}}intPyArg_GetFloatArray(PyObject*args,intnargs,inti,intn,float*p_arg){PyObject*v,*w;if(!PyArg_GetObject(args,nargs,i,&v))return0;if(PyTuple_Check(v)){if(PyTuple_Size(v)!=n){returnPyErr_BadArgument();}for(i=0;i<n;i++){w=PyTuple_GetItem(v,i);if(!extractfloat(w,&p_arg[i]))return0;}return1;}elseif(PyList_Check(v)){if(PyList_Size(v)!=n){returnPyErr_BadArgument();}for(i=0;i<n;i++){w=PyList_GetItem(v,i);if(!extractfloat(w,&p_arg[i]))return0;}return1;}else{returnPyErr_BadArgument();}}