From: Marcelo M. <mar...@us...> - 2004-05-28 20:40:45
|
Update of /cvsroot/swig/SWIG/Lib/python In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9813 Modified Files: pystrbase.swg Log Message: change char[] and char[ANY] to behave more like char* as default Index: pystrbase.swg =================================================================== RCS file: /cvsroot/swig/SWIG/Lib/python/pystrbase.swg,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** pystrbase.swg 27 May 2004 11:25:31 -0000 1.1 --- pystrbase.swg 28 May 2004 20:40:32 -0000 1.2 *************** *** 1,2 **** --- 1,17 ---- + // + // Use this macro if you prefer to preserve the size of char + // arrays, ie + // ------------------------------------------ + // C Side => Python Side + // ------------------------------------------ + // char name[5] = "hola" => 'hola\0' + // + // the default behaviour is + // + // char name[5] = "hola" => 'hola' + // + // + //#define SWIG_PRESERVE_CARRAY_SIZE + /* ------------------------------------------------------------ * String typemaps for type Char (char or wchar_t) *************** *** 137,141 **** %typemap(varin,fragment=#SWIG_AsCharArray) Char [] { ! if (!SWIG_AsCharArray($input, $1, sizeof($1))) { PyErr_Clear(); PyErr_SetString(PyExc_TypeError, "C variable '$name ($1_ltype)'"); --- 152,157 ---- %typemap(varin,fragment=#SWIG_AsCharArray) Char [] { ! size_t size = sizeof($1); ! if (!SWIG_AsCharArray($input, $1, size)) { PyErr_Clear(); PyErr_SetString(PyExc_TypeError, "C variable '$name ($1_ltype)'"); *************** *** 145,149 **** %typemap(varout,fragment=#SWIG_FromCharArray) const Char [] ! "$result = SWIG_FromCharArray($1, sizeof($1));"; --- 161,172 ---- %typemap(varout,fragment=#SWIG_FromCharArray) const Char [] ! { ! size_t size = sizeof($1); ! #ifndef SWIG_PRESERVE_CARRAY_SIZE ! while (size && ($1[size - 1] == '\0')) --size; ! #endif ! $result = SWIG_FromCharArray($1, size); ! } ! *************** *** 198,202 **** { size_t size = $1_dim0; ! //while (size && ($1[size - 1] == '\0')) --size; $result = SWIG_FromCharArray($1, size); } --- 221,227 ---- { size_t size = $1_dim0; ! #ifndef SWIG_PRESERVE_CARRAY_SIZE ! while (size && ($1[size - 1] == '\0')) --size; ! #endif $result = SWIG_FromCharArray($1, size); } |