2 * ====================================================================
3 * Copyright (c) 2000-2006 CollabNet. All rights reserved.
5 * This software is licensed as described in the file COPYING, which
6 * you should have received as part of this distribution. The terms
7 * are also available at http://subversion.tigris.org/license-1.html.
8 * If newer versions of this license are posted there, you may use a
9 * newer version instead, at your option.
11 * This software consists of voluntary contributions made by many
12 * individuals. For exact contribution history, see the revision
13 * history and logs, available at http://subversion.tigris.org/.
14 * ====================================================================
16 * svn_string.swg: This is a child file of svn_types.swg, and should
17 * not be included directly. This file should contain typemaps that
18 * deal with svn_string_t, svn_stringbuf_t and char * string types.
21 typedef struct svn_stringbuf_t svn_stringbuf_t;
22 typedef struct svn_string_t svn_string_t;
24 /* -----------------------------------------------------------------------
25 generic OUT param typemap for svn_string(buf)_t. we can share these
26 because we only refer to the ->data and ->len values.
29 %typemap(argout) RET_STRING {
36 s = PyString_FromStringAndSize((*$1)->data, (*$1)->len);
44 %typemap(argout) RET_STRING {
46 %append_output(sv_2mortal(newSVpvn((*$1)->data, (*$1)->len)));
48 %append_output(&PL_sv_undef);
53 %typemap(argout) RET_STRING {
55 %append_output(rb_str_new((*$1)->data, (*$1)->len));
67 /* -----------------------------------------------------------------------
72 %typemap(in) svn_stringbuf_t * {
73 if (!PyString_Check($input)) {
74 PyErr_SetString(PyExc_TypeError, "not a string");
77 $1 = svn_stringbuf_ncreate(PyString_AS_STRING($input),
78 PyString_GET_SIZE($input),
79 /* ### gah... what pool to use? */
85 %typemap(in) svn_stringbuf_t * {
91 } else if (SvPOK($input)) {
92 buf = SvPV($input, len);
93 /* Another case of ugly pool handling, this should use the current
94 default pool, or make a new one if it doesn't exist yet */
95 $1 = svn_stringbuf_ncreate(buf,len,
96 svn_swig_pl_make_pool ((SV *)NULL));
98 croak("Not a string");
104 %typemap(in) svn_stringbuf_t *
109 $1 = svn_stringbuf_ncreate(StringValuePtr($input),
110 RSTRING($input)->len,
115 %typemap(in) svn_stringbuf_t *node_name
123 svn_swig_rb_get_pool(argc, argv, self, &rb_pool, &pool);
125 $1 = svn_stringbuf_ncreate(StringValuePtr($input),
126 RSTRING($input)->len,
134 %typemap(out) svn_stringbuf_t * {
135 $result = PyString_FromStringAndSize($1->data, $1->len);
140 %typemap(out) svn_stringbuf_t * {
141 SV *sv = sv_newmortal();
142 sv_setpvn(sv,$1->data,$1->len);
149 %typemap(out) svn_stringbuf_t *
151 $result = rb_str_new($1->data, $1->len);
154 %typemap(argout) svn_stringbuf_t *output
156 %append_output(rb_str_new($1->data, $1->len));
160 /* -----------------------------------------------------------------------
164 /* const svn_string_t * is always an input parameter */
166 %typemap(in) const svn_string_t * (svn_string_t value) {
167 if ($input == Py_None)
170 if (!PyString_Check($input)) {
171 PyErr_SetString(PyExc_TypeError, "not a string");
174 value.data = PyString_AS_STRING($input);
175 value.len = PyString_GET_SIZE($input);
181 %typemap(in) const svn_string_t * (svn_string_t value) {
183 value.data = SvPV($input, value.len);
192 %typemap(in) const svn_string_t * (svn_string_t value)
197 value.data = StringValuePtr($input);
198 value.len = RSTRING($input)->len;
204 /* when storing an svn_string_t* into a structure, we must allocate the
205 svn_string_t structure on the heap. */
207 %typemap(memberin) const svn_string_t * {
208 $1 = svn_string_dup($input, _global_pool);
212 %typemap(memberin) const svn_string_t * {
213 $1 = svn_string_dup($input, _global_pool);
217 %typemap(memberin) const svn_string_t * {
218 $1 = svn_string_dup($input, _global_pool);
223 %typemap(out) svn_string_t * {
224 $result = PyString_FromStringAndSize($1->data, $1->len);
228 %typemap(out) svn_string_t * {
229 $result = sv_2mortal(newSVpv($1->data, $1->len));
234 %typemap(out) svn_string_t * {
236 $result = rb_str_new($1->data, $1->len);
243 /* -----------------------------------------------------------------------
244 define a way to return a 'const char *'
247 %typemap(argout) const char **OUTPUT {
254 s = PyString_FromString(*$1);
263 %typemap(argout) const char **OUTPUT {
265 %append_output(&PL_sv_undef);
267 %append_output(sv_2mortal(newSVpv(*$1, 0)));
273 %typemap(argout) const char **OUTPUT
276 %append_output(rb_str_new2(*$1));
278 %append_output(Qnil);
283 /* svn_wc_get_ancestry() lacks a 'const' */
284 %apply const char **OUTPUT { const char **, char **url };