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