1 /* ------------------------------------------------------------ 2 * utility methods for char strings 3 * ------------------------------------------------------------ */ 4 5 %fragment("SWIG_AsCharPtrAndSize","header") { 6 SWIGINTERN int 7 SWIG_AsCharPtrAndSize(Tcl_Obj *obj, char** cptr, size_t* psize, int *alloc) 8 { 9 int len = 0; 10 char *cstr = Tcl_GetStringFromObj(obj, &len); 11 if (cstr) { 12 if (cptr) *cptr = cstr; 13 if (psize) *psize = len + 1; 14 if (alloc) *alloc = SWIG_OLDOBJ; 15 return SWIG_OK; 16 } 17 return SWIG_TypeError; 18 } 19 } 20 21 22 %fragment("SWIG_FromCharPtrAndSize","header", 23 fragment="<limits.h>") { 24 SWIGINTERNINLINE Tcl_Obj * 25 SWIG_FromCharPtrAndSize(const char* carray, size_t size) 26 { 27 return (size < INT_MAX) ? Tcl_NewStringObj(carray, %numeric_cast(size,int)) : NULL; 28 } 29 } 30 31 32