/* ------------------------------------------------------------
* utility methods for char strings
* ------------------------------------------------------------ */
%fragment("SWIG_AsCharPtrAndSize","header") {
/* returns SWIG_OLDOBJ if the input is a raw char*, SWIG_PYSTR if is a PyString */
SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize)
static swig_type_info* pchar_info = 0;
if (!pchar_info) pchar_info = SWIG_TypeQuery("char *");
if (SWIG_ConvertPtr(obj, (void**)&vptr, pchar_info, 0) != -1) {
if (psize) *psize = vptr ? (strlen(vptr) + 1) : 0;
if (PyString_Check(obj)) {
*cptr = PyString_AS_STRING(obj);
*psize = PyString_GET_SIZE(obj) + 1;
SWIG_type_error("char *", obj);
%fragment("SWIG_AsCharPtr","header",
fragment="SWIG_AsCharPtrAndSize") {
SWIG_AsCharPtr(PyObject *obj, char **val)
if (SWIG_AsCharPtrAndSize(obj, val, (size_t*)(0))) {
SWIG_type_error("char *", obj);
%fragment("SWIG_FromCharPtr","header") {
SWIG_FromCharPtr(const char* cptr)
size_t size = strlen(cptr);
return SWIG_NewPointerObj(SWIG_const_cast(cptr,char*),
SWIG_TypeQuery("char *"), 0);
return PyString_FromStringAndSize(cptr, size);
return PyString_FromString(cptr);
%fragment("SWIG_AsNewCharPtr","header",
fragment="SWIG_AsCharPtrAndSize") {
SWIG_AsNewCharPtr(PyObject *obj, char **val)
char* cptr = 0; size_t csize = 0;
int res = SWIG_AsCharPtrAndSize(obj, &cptr, &csize);
*val = SWIG_new_array(csize, char);
memcpy(*val, cptr, --csize);
*val = SWIG_new_array(1, char);
SWIG_type_error("char *", obj);
%fragment("SWIG_AsCharArray","header",
fragment="SWIG_AsCharPtrAndSize") {
SWIG_AsCharArray(PyObject *obj, char *val, size_t size)
char* cptr; size_t csize;
if (SWIG_AsCharPtrAndSize(obj, &cptr, &csize)) {
ie, assing the array using an extra '0' char.
if ((csize == size + 1) && !(cptr[csize-1])) --csize;
if (csize) memcpy(val, cptr, csize);
if (csize < size) memset(val + csize, 0, size - csize);
PyErr_Format(PyExc_TypeError,
"a char array of maximum size %lu is expected",
%fragment("SWIG_FromCharArray","header") {
SWIGINTERNINLINE PyObject *
SWIG_FromCharArray(const char* carray, size_t size)
return SWIG_NewPointerObj(SWIG_const_cast(carray,char *),
SWIG_TypeQuery("char *"), 0);
return PyString_FromStringAndSize(carray, SWIG_numeric_cast(size,int));
/* ------------------------------------------------------------
* The plain char * handling
* ------------------------------------------------------------ */