I'm trying to return a Python string from a C++ function (actually
inside gnuradio) using CPython 2.5. My C++ function is declared like:

typedef struct {
  int size;
  unsigned char *data;
} STRING

STRINGBUF myfunc(std::string s)
{
  STRINGBUF buf;
  .
  .
  .
  buf.size = s.length();
  buf.data = s.data();
  return buf;
}

Since gnuradio uses SWIG, I found a SWIG example that seemed to fit:

%typemap(myfunc) STRINGBUF {
  $result = PyString_FromStringAndSize($1.data, $1.size);
}

STRINGBUF myfunc(std::string s);

At runtime though, I'm getting a type mismatch error from Python
(PyObject of some type found when PyString was expected - I can post
the exact message tomorrow if it'll help.)

Any ideas or suggestions appreciated!
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to