summaryrefslogtreecommitdiff
path: root/Lib/perl5/perlstrings.swg
blob: c1b29b5f47a36fb37f5e2dc3efa8c59aa28870ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* ------------------------------------------------------------
 *  utility methods for char strings 
 * ------------------------------------------------------------ */

%fragment("SWIG_AsCharPtrAndSize","header") {
SWIGINTERN int
SWIG_AsCharPtrAndSize(SV *obj, char** cptr, size_t* psize, int *alloc)
{
  static swig_type_info* pchar_info = 0;
  char* vptr = 0;
  if (!pchar_info) pchar_info = SWIG_TypeQuery("char *");
  if (SWIG_ConvertPtr(obj, (void**)&vptr, pchar_info, 0) == SWIG_OK) {
    if (cptr) *cptr = vptr;
    if (psize) *psize = vptr ? (strlen(vptr) + 1) : 0;
    if (alloc) *alloc = SWIG_OLDOBJ;
    return SWIG_OK;
  } else {
    if (SvPOK(obj)) {
      STRLEN len = 0;
      char *cstr = SvPV(obj, len); 
      size_t size = len + 1;
      if (cptr)  {
	if (alloc) {
	  if (*alloc == SWIG_NEWOBJ) {
	    *cptr = %new_copy_array(cstr, size, char);
	  } else {
	    *cptr = cstr;
	    *alloc = SWIG_OLDOBJ;
	  }
	}
      }
      if (psize) *psize = size;
      return SWIG_OK;
    }
  }
  return SWIG_TypeError;
}
}

%fragment("SWIG_FromCharPtrAndSize","header") {
SWIGINTERNINLINE SV *
SWIG_FromCharPtrAndSize(const char* carray, size_t size)
{
  SV *obj = sv_newmortal();
  sv_setpv(obj, carray);
  return obj;
}
}