Home | History | Annotate | Download | only in ruby
      1 /* ------------------------------------------------------------
      2  *  utility methods for char strings
      3  * ------------------------------------------------------------ */
      4 
      5 %fragment("SWIG_AsCharPtrAndSize","header",fragment="SWIG_pchar_descriptor") {
      6 SWIGINTERN int
      7 SWIG_AsCharPtrAndSize(VALUE obj, char** cptr, size_t* psize, int *alloc)
      8 {
      9   if (TYPE(obj) == T_STRING) {
     10     char *cstr = StringValuePtr(obj);
     11     size_t size = RSTRING_LEN(obj) + 1;
     12     if (cptr)  {
     13       if (alloc) {
     14 	if (*alloc == SWIG_NEWOBJ) {
     15 	  *cptr = %new_copy_array(cstr, size, char);
     16 	} else {
     17 	  *cptr = cstr;
     18 	  *alloc = SWIG_OLDOBJ;
     19 	}
     20       }
     21     }
     22     if (psize) *psize = size;
     23     return SWIG_OK;
     24   } else {
     25     swig_type_info* pchar_descriptor = SWIG_pchar_descriptor();
     26     if (pchar_descriptor) {
     27       void* vptr = 0;
     28       if (SWIG_ConvertPtr(obj, &vptr, pchar_descriptor, 0) == SWIG_OK) {
     29 	if (cptr) *cptr = (char *)vptr;
     30 	if (psize) *psize = vptr ? (strlen((char*)vptr) + 1) : 0;
     31 	if (alloc) *alloc = SWIG_OLDOBJ;
     32 	return SWIG_OK;
     33       }
     34     }
     35   }
     36   return SWIG_TypeError;
     37 }
     38 }
     39 
     40 %fragment("SWIG_FromCharPtrAndSize","header",fragment="SWIG_pchar_descriptor") {
     41 SWIGINTERNINLINE VALUE
     42 SWIG_FromCharPtrAndSize(const char* carray, size_t size)
     43 {
     44   if (carray) {
     45     if (size > LONG_MAX) {
     46       swig_type_info* pchar_descriptor = SWIG_pchar_descriptor();
     47       return pchar_descriptor ?
     48 	SWIG_NewPointerObj(%const_cast(carray,char *), pchar_descriptor, 0) : Qnil;
     49     } else {
     50       return rb_str_new(carray, %numeric_cast(size,long));
     51     }
     52   } else {
     53     return Qnil;
     54   }
     55 }
     56 }
     57 
     58