PyArg_ParseTuple help

zyqnews at 163.net zyqnews at 163.net
Sun Jul 10 11:44:00 EDT 2005


hello all,
  how to parse the arguments of a c function with PyArg_ParseTuple?
 The prototype of the c function is :
  int func(unsigned char * in , int inlen, unsigned char * v, unsigned
char * out, int * outlen);

The problem is , when the func returns, there will be results in out
and outlen. Is the following format is correct?

PyObject* wrap_func(PyObject* self, PyObject* args)
{
  unsigned char *in;
  int inlen;
  unsigned char *v;
  unsigned char *out;
  int outlen;

  PyArg_ParseTuple(args, "s|i|s|s|i", &in, &inlen, &v, &out, &outlen);

  result = func(in, inlen, v, out, &outlen);// notice out and &outlen

  return Py_BuildValue("i", result);
}

Thanks




More information about the Python-list mailing list