1/* 2 * ==================================================================== 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * ==================================================================== 20 * 21 * svn_string.swg: This is a child file of svn_types.swg, and should 22 * not be included directly. This file should contain typemaps that 23 * deal with svn_string_t, svn_stringbuf_t and char * string types. 24 */ 25 26typedef struct svn_stringbuf_t svn_stringbuf_t; 27typedef struct svn_string_t svn_string_t; 28 29/* ----------------------------------------------------------------------- 30 generic OUT param typemap for svn_string(buf)_t. we can share these 31 because we only refer to the ->data and ->len values. 32*/ 33#ifdef SWIGPYTHON 34%typemap(argout) RET_STRING { 35 PyObject *s; 36 if (*$1 == NULL) { 37 Py_INCREF(Py_None); 38 s = Py_None; 39 } else { 40 s = PyBytes_FromStringAndSize((*$1)->data, (*$1)->len); 41 if (s == NULL) 42 SWIG_fail; 43 } 44 %append_output(s); 45} 46#endif 47#ifdef SWIGPERL 48%typemap(argout) RET_STRING { 49 if (*$1) { 50 %append_output(sv_2mortal(newSVpvn((*$1)->data, (*$1)->len))); 51 } else { 52 %append_output(&PL_sv_undef); 53 } 54} 55#endif 56#ifdef SWIGRUBY 57%typemap(argout) RET_STRING { 58 if (*$1) { 59 %append_output(rb_str_new((*$1)->data, (*$1)->len)); 60 } else { 61 %append_output(Qnil); 62 } 63} 64#endif 65 66%apply RET_STRING { 67 svn_string_t **, 68 svn_stringbuf_t ** 69}; 70 71/* ----------------------------------------------------------------------- 72 TYPE: svn_stringbuf_t 73*/ 74 75#ifdef SWIGPYTHON 76%typemap(in) svn_stringbuf_t * { 77 if (!PyBytes_Check($input)) { 78 PyErr_SetString(PyExc_TypeError, "not a bytes object"); 79 SWIG_fail; 80 } 81 { 82 Py_ssize_t strBufLen; 83 char *strBufChar; 84 if (-1 == PyBytes_AsStringAndSize($input, &strBufChar, &strBufLen)) { 85 SWIG_fail; 86 } 87 $1 = svn_stringbuf_ncreate(strBufChar, strBufLen, 88 /* ### gah... what pool to use? */ 89 _global_pool); 90 } 91} 92#endif 93 94#ifdef SWIGPERL 95%typemap(in) svn_stringbuf_t * { 96 apr_size_t len; 97 char *buf; 98 apr_pool_t *pool; 99 100 if (!SvOK($input)) { 101 $1 = NULL; 102 } else if (SvPOK($input)) { 103 buf = SvPV($input, len); 104 /* Another case of ugly pool handling, this should use the current 105 default pool, or make a new one if it doesn't exist yet */ 106 pool = svn_swig_pl_make_pool ((SV *)NULL); 107 SPAGAIN; 108 $1 = svn_stringbuf_ncreate(buf,len, pool); 109 } else { 110 croak("Not a string"); 111 } 112} 113#endif 114 115#ifdef SWIGRUBY 116%typemap(in) svn_stringbuf_t * 117{ 118 if (NIL_P($input)) { 119 $1 = NULL; 120 } else { 121 $1 = svn_stringbuf_ncreate(StringValuePtr($input), 122 RSTRING_LEN($input), 123 _global_pool); 124 } 125} 126 127%typemap(in) svn_stringbuf_t *node_name 128{ 129 if (NIL_P($input)) { 130 $1 = NULL; 131 } else { 132 VALUE rb_pool; 133 apr_pool_t *pool; 134 135 svn_swig_rb_get_pool(argc, argv, self, &rb_pool, &pool); 136 137 $1 = svn_stringbuf_ncreate(StringValuePtr($input), 138 RSTRING_LEN($input), 139 pool); 140 } 141} 142#endif 143 144 145#ifdef SWIGPYTHON 146%typemap(out) svn_stringbuf_t * { 147 $result = PyBytes_FromStringAndSize($1->data, (Py_ssize_t)($1->len)); 148} 149#endif 150 151#ifdef SWIGPERL 152%typemap(out) svn_stringbuf_t * { 153 SV *sv = sv_newmortal(); 154 sv_setpvn(sv,$1->data,$1->len); 155 $result = sv; 156 argvi++; 157} 158#endif 159 160#ifdef SWIGRUBY 161%typemap(out) svn_stringbuf_t * 162{ 163 $result = rb_str_new($1->data, $1->len); 164} 165 166%typemap(argout) svn_stringbuf_t *output 167{ 168 %append_output(rb_str_new($1->data, $1->len)); 169} 170#endif 171 172/* ----------------------------------------------------------------------- 173 TYPE: svn_string_t 174*/ 175 176/* const svn_string_t * is always an input parameter */ 177#ifdef SWIGPYTHON 178%typemap(in) const svn_string_t * (svn_string_t value) { 179 if ($input == Py_None) 180 $1 = NULL; 181 else { 182 Py_ssize_t pyStrLen; 183 if (!PyBytes_Check($input)) { 184 PyErr_SetString(PyExc_TypeError, "not a bytes object"); 185 SWIG_fail; 186 } 187 if (PyBytes_AsStringAndSize($input, (char **)&(value.data), 188 &pyStrLen) == -1) { 189 SWIG_fail; 190 } 191 value.len = pyStrLen; 192 $1 = &value; 193 } 194} 195#endif 196#ifdef SWIGPERL 197%typemap(in) const svn_string_t * (svn_string_t value) { 198 if (SvOK($input)) { 199 value.data = SvPV($input, value.len); 200 $1 = &value; 201 } 202 else { 203 $1 = NULL; 204 } 205} 206#endif 207#ifdef SWIGRUBY 208%typemap(in) const svn_string_t * (svn_string_t value) 209{ 210 if (NIL_P($input)) { 211 $1 = NULL; 212 } else { 213 value.data = StringValuePtr($input); 214 value.len = RSTRING_LEN($input); 215 $1 = &value; 216 } 217} 218#endif 219 220/* when storing an svn_string_t* into a structure, we must allocate the 221 svn_string_t structure on the heap. */ 222#ifdef SWIGPERL 223%typemap(memberin) const svn_string_t * { 224 $1 = svn_string_dup($input, _global_pool); 225} 226#endif 227#ifdef SWIGRUBY 228%typemap(memberin) const svn_string_t * { 229 $1 = svn_string_dup($input, _global_pool); 230} 231#endif 232 233#ifdef SWIGPYTHON 234%typemap(out) svn_string_t * { 235 $result = PyBytes_FromStringAndSize($1->data, $1->len); 236} 237#endif 238#ifdef SWIGPERL 239%typemap(out) svn_string_t * { 240 $result = sv_2mortal(newSVpv($1->data, $1->len)); 241 ++argvi; 242} 243#endif 244#ifdef SWIGRUBY 245%typemap(out) svn_string_t * { 246 if ($1) { 247 $result = rb_str_new($1->data, $1->len); 248 } else { 249 $result = Qnil; 250 } 251} 252#endif 253 254 /* ----------------------------------------------------------------------- 255 Type: char * (input) 256*/ 257#ifdef SWIGPYTHON 258%typemap (in) IN_STRING 259{ 260 $1 = svn_swig_py_string_to_cstring($input, FALSE, "$symname", "$1_name"); 261 if (PyErr_Occurred()) SWIG_fail; 262} 263 264%typemap (freearg) IN_STRING ""; 265 266%apply IN_STRING { 267 const char *, 268 char *, 269 char const *, 270 char * const, 271 char const * const 272}; 273#endif 274/* ----------------------------------------------------------------------- 275 define a way to return a 'const char *' 276*/ 277#ifdef SWIGPYTHON 278%typemap(argout) const char **OUTPUT { 279 PyObject *s; 280 if (*$1 == NULL) { 281 Py_INCREF(Py_None); 282 s = Py_None; 283 } 284 else { 285 s = PyBytes_FromString(*$1); 286 if (s == NULL) 287 SWIG_fail; 288 } 289 %append_output(s); 290} 291#endif 292 293#ifdef SWIGPERL 294%typemap(argout) const char **OUTPUT { 295 if (*$1 == NULL) { 296 %append_output(&PL_sv_undef); 297 } else { 298 %append_output(sv_2mortal(newSVpv(*$1, 0))); 299 } 300} 301#endif 302 303#ifdef SWIGRUBY 304%typemap(argout) const char **OUTPUT 305{ 306 if (*$1) { 307 %append_output(rb_str_new2(*$1)); 308 } else { 309 %append_output(Qnil); 310 } 311} 312#endif 313 314/* svn_wc_get_ancestry() lacks a 'const' */ 315%apply const char **OUTPUT { 316 const char **, 317 char **url, 318 char **log_message 319}; 320