* subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
[svn.git] / subversion / bindings / swig / core.i
blob9101170dcbb55691568b70a706b16aa34bb10379
1 /*
2 * ====================================================================
3 * Copyright (c) 2000-2007 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 * core.i: SWIG module interface file for libsvn_subr, a few pieces of
17 * APR functionality, and anything else that does not fit into any
18 * of the more specific module files.
21 #if defined(SWIGPYTHON)
22 %module(package="libsvn") core
23 #elif defined(SWIGPERL)
24 %module "SVN::_Core"
25 #elif defined(SWIGRUBY)
26 %module "svn::ext::core"
27 #endif
29 %include svn_global.swg
32 #include <apr.h>
33 #include <apr_general.h>
35 #include "svn_md5.h"
36 #include "svn_diff.h"
39 #ifdef SWIGRUBY
41 #include <apu.h>
42 #include <apr_xlate.h>
44 #endif
46 /* ### for now, let's ignore this thing. */
47 %ignore svn_prop_t;
49 /* -----------------------------------------------------------------------
50 The following struct members have to be read-only because otherwise
51 strings assigned to then would never be freed, resulting in memory
52 leaks. This prevents the swig warning "Warning(451): Setting const
53 char * member may leak memory."
55 %immutable svn_log_changed_path_t::copyfrom_path;
56 %immutable svn_dirent_t::last_author;
57 %immutable svn_error_t::message;
58 %immutable svn_error_t::file;
60 /* -----------------------------------------------------------------------
61 completely ignore a number of functions. the presumption is that the
62 scripting language already has facilities for these things (or they
63 are relatively trivial).
66 /* svn_io.h: We cherry-pick certain functions from this file. To aid in this,
67 * EVERY function in the file is listed in the order it appears, and is either
68 * %ignore-d, or present as a comment, explicitly documenting that we wrap it.
71 %ignore svn_io_check_path;
72 %ignore svn_io_check_special_path;
73 %ignore svn_io_check_resolved_path;
74 /* This is useful for implementing svn_ra_callbacks_t->open_tmp_file */
75 // svn_io_open_unique_file2
76 // svn_io_open_unique_file
77 %ignore svn_io_create_unique_link;
78 %ignore svn_io_read_link;
79 %ignore svn_io_temp_dir;
80 %ignore svn_io_copy_file;
81 %ignore svn_io_copy_link;
82 %ignore svn_io_copy_dir_recursively;
83 %ignore svn_io_make_dir_recursively;
84 %ignore svn_io_dir_empty;
85 %ignore svn_io_append_file;
86 %ignore svn_io_set_file_read_only;
87 %ignore svn_io_set_file_read_write;
88 %ignore svn_io_set_file_read_write_carefully;
89 %ignore svn_io_set_file_executable;
90 %ignore svn_io_is_file_executable;
91 %ignore svn_io_read_length_line;
92 %ignore svn_io_file_affected_time;
93 %ignore svn_io_set_file_affected_time;
94 %ignore svn_io_filesizes_different_p;
95 // svn_io_file_checksum
96 // svn_io_files_contents_same_p
97 %ignore svn_io_file_create;
98 %ignore svn_io_file_lock;
99 %ignore svn_io_file_lock2;
100 %ignore svn_io_file_flush_to_disk;
101 %ignore svn_io_dir_file_copy;
103 /* Not useful from scripting languages. Custom streams should be achieved
104 * by passing a scripting language native stream into a svn_stream_t *
105 * parameter, and letting a typemap using svn_swig_xx_make_stream() take
106 * care of the details. */
107 %ignore svn_stream_create;
108 %ignore svn_stream_set_baton;
109 %ignore svn_stream_set_read;
110 %ignore svn_stream_set_write;
111 %ignore svn_stream_set_close;
113 /* The permitted svn_stream and svn_stringbuf functions could possibly
114 * be used by a script, in conjunction with other APIs which return or
115 * accept streams. This requires that the relevant language's custom
116 * svn_stream_t wrapping code does not obstruct this usage. */
117 // svn_stream_empty
118 // svn_stream_disown
119 // svn_stream_from_aprfile2
120 // svn_stream_from_aprfile
121 // svn_stream_for_stdout
122 // svn_stream_from_stringbuf
123 // svn_stream_compressed
124 /* svn_stream_checksummed would require special attention to wrap, because
125 * of the read_digest and write_digest parameters. */
126 %ignore svn_stream_checksummed;
127 // svn_stream_read
128 // svn_stream_write
129 // svn_stream_close
131 /* Scripts can do the printf, then write to a stream.
132 * We can't really handle the variadic, so ignore it. */
133 %ignore svn_stream_printf;
134 %ignore svn_stream_printf_from_utf8;
136 // svn_stream_readline
137 // svn_stream_copy
138 // svn_stream_contents_same
139 // svn_stringbuf_from_file
140 // svn_stringbuf_from_aprfile
142 #ifndef SWIGPYTHON
143 /* These functions are useful in Python, because they allow you to
144 * easily delete files which are marked as read-only on Windows. */
145 %ignore svn_io_remove_file;
146 %ignore svn_io_remove_dir;
147 #endif
148 %ignore svn_io_get_dir_filenames;
149 %ignore svn_io_get_dirents2;
150 %ignore svn_io_get_dirents;
151 %ignore svn_io_dir_walk;
152 %ignore svn_io_start_cmd;
153 %ignore svn_io_wait_for_cmd;
154 %ignore svn_io_run_cmd;
155 %ignore svn_io_run_diff;
156 %ignore svn_io_run_diff3_2;
157 %ignore svn_io_run_diff3;
158 // svn_io_detect_mimetype
159 %ignore svn_io_file_open;
160 %ignore svn_io_file_close;
161 %ignore svn_io_file_getc;
162 %ignore svn_io_file_info_get;
163 %ignore svn_io_file_read;
164 %ignore svn_io_file_read_full;
165 %ignore svn_io_file_seek;
166 %ignore svn_io_file_write;
167 %ignore svn_io_file_write_full;
168 %ignore svn_io_stat;
169 %ignore svn_io_file_rename;
170 %ignore svn_io_file_move;
171 %ignore svn_io_dir_make;
172 %ignore svn_io_dir_make_hidden;
173 %ignore svn_io_dir_make_sgid;
174 %ignore svn_io_dir_open;
175 %ignore svn_io_dir_remove_nonrecursive;
176 %ignore svn_io_dir_read;
177 %ignore svn_io_read_version_file;
178 %ignore svn_io_write_version_file;
180 /* svn_path.h: We cherry-pick certain functions from this file. To aid in this,
181 * EVERY function in the file is listed in the order it appears, and is either
182 * %ignore-d, or present as a comment, explicitly documenting that we wrap it.
184 // svn_path_internal_style;
185 // svn_path_local_style;
186 %ignore svn_path_join;
187 %ignore svn_path_join_many;
188 %ignore svn_path_basename;
189 %ignore svn_path_dirname;
190 %ignore svn_path_component_count;
191 %ignore svn_path_add_component;
192 %ignore svn_path_remove_component;
193 %ignore svn_path_remove_components;
194 %ignore svn_path_split;
195 // svn_path_is_empty;
196 // svn_path_canonicalize;
197 // svn_path_compare_paths;
198 // svn_path_get_longest_ancestor;
199 %ignore svn_path_get_absolute;
200 %ignore svn_path_split_if_file;
201 %ignore svn_path_condense_targets;
202 %ignore svn_path_remove_redundancies;
203 %ignore svn_path_decompose;
204 %ignore svn_path_compose;
205 %ignore svn_path_is_single_path_component;
206 %ignore svn_path_is_backpath_present;
207 %ignore svn_path_is_child;
208 %ignore svn_path_is_ancestor;
209 %ignore svn_path_check_valid;
210 %ignore svn_path_is_url;
211 // svn_path_is_uri_safe;
212 %ignore svn_path_uri_encode;
213 %ignore svn_path_uri_decode;
214 %ignore svn_path_url_add_component;
215 %ignore svn_path_uri_from_iri;
216 %ignore svn_path_uri_autoescape;
217 %ignore svn_path_cstring_from_utf8;
218 %ignore svn_path_cstring_to_utf8;
220 /* Other files */
221 /* bad pool convention */
222 %ignore svn_opt_print_generic_help;
224 %ignore svn_opt_args_to_target_array;
226 /* Ugliness because the constants are typedefed and SWIG ignores them
227 as a result. */
228 %constant svn_revnum_t SWIG_SVN_INVALID_REVNUM = -1;
229 %constant svn_revnum_t SWIG_SVN_IGNORED_REVNUM = -1;
231 /* -----------------------------------------------------------------------
232 input rangelist
234 %apply apr_array_header_t *RANGELIST {
235 apr_array_header_t *rangeinput,
236 const apr_array_header_t *rangelist,
237 apr_array_header_t *from,
238 apr_array_header_t *to,
239 apr_array_header_t *changes,
240 apr_array_header_t *eraser,
241 apr_array_header_t *whiteboard,
242 apr_array_header_t *rangelist1,
243 apr_array_header_t *rangelist2
246 /* -----------------------------------------------------------------------
247 output rangelist
249 %apply apr_array_header_t **RANGELIST {
250 apr_array_header_t **rangelist,
251 apr_array_header_t **inheritable_rangelist,
252 apr_array_header_t **deleted,
253 apr_array_header_t **added,
254 apr_array_header_t **output
257 /* -----------------------------------------------------------------------
258 input and output rangelist
260 %apply apr_array_header_t **RANGELIST_INOUT {
261 apr_array_header_t **rangelist_inout
264 /* -----------------------------------------------------------------------
265 input mergeinfo hash
267 %apply apr_hash_t *MERGEINFO {
268 apr_hash_t *mergefrom,
269 apr_hash_t *mergeto,
270 apr_hash_t *mergein1,
271 apr_hash_t *mergein2,
272 apr_hash_t *mergeinfo,
273 apr_hash_t *mergeinput,
274 apr_hash_t *eraser,
275 apr_hash_t *whiteboard,
276 apr_hash_t *changes
279 /* -----------------------------------------------------------------------
280 output mergeinfo
283 #if defined(SWIGPYTHON) || defined(SWIGRUBY)
284 %apply apr_hash_t **MERGEINFO_INOUT {
285 apr_hash_t **mergeinfo_inout
288 %apply apr_hash_t **MERGEINFO {
289 apr_hash_t **mergeinfo,
290 apr_hash_t **inheritable_mergeinfo,
291 apr_hash_t **deleted,
292 apr_hash_t **added
294 #endif
296 /* -----------------------------------------------------------------------
297 /* -----------------------------------------------------------------------
298 output mergeinfo hash
301 #if defined(SWIGRUBY) || defined(SWIGPYTHON)
302 %apply apr_hash_t **MERGEINFO_CATALOG {
303 apr_hash_t **catalog
305 #endif
308 /* -----------------------------------------------------------------------
309 handle the default value of svn_config_get().and the
310 config directory of svn_config_read_auth_data() and
311 svn_config_write_auth_data().
313 %apply const char *MAY_BE_NULL {
314 const char *default_value,
315 const char *config_dir,
316 const char *conflict_original,
317 const char *conflict_modified,
318 const char *conflict_latest,
319 const char *conflict_separator
322 /* -----------------------------------------------------------------------
323 fix up the svn_stream_read() ptr/len arguments
325 #ifdef SWIGPYTHON
326 %typemap(in) (char *buffer, apr_size_t *len) ($*2_type temp) {
327 if (!PyInt_Check($input)) {
328 PyErr_SetString(PyExc_TypeError,
329 "expecting an integer for the buffer size");
330 SWIG_fail;
332 temp = PyInt_AsLong($input);
333 if (temp < 0) {
334 PyErr_SetString(PyExc_ValueError,
335 "buffer size must be a positive integer");
336 SWIG_fail;
338 $1 = malloc(temp);
339 $2 = ($2_ltype)&temp;
341 #endif
342 #ifdef SWIGPERL
343 %typemap(in) (char *buffer, apr_size_t *len) ($*2_type temp) {
344 temp = SvIV($input);
345 $1 = malloc(temp);
346 $2 = ($2_ltype)&temp;
348 #endif
349 #ifdef SWIGRUBY
350 %typemap(in) (char *buffer, apr_size_t *len) ($*2_type temp) {
351 temp = NUM2LONG($input);
352 $1 = malloc(temp);
353 $2 = ($2_ltype)&temp;
355 #endif
357 /* ### need to use freearg or somesuch to ensure the string is freed.
358 ### watch out for 'return' anywhere in the binding code. */
360 #ifdef SWIGPYTHON
361 %typemap(argout) (char *buffer, apr_size_t *len) {
362 %append_output(PyString_FromStringAndSize($1, *$2));
363 free($1);
365 #endif
366 #ifdef SWIGPERL
367 %typemap(argout) (char *buffer, apr_size_t *len) {
368 %append_output(sv_2mortal(newSVpvn($1, *$2)));
369 free($1);
371 #endif
372 #ifdef SWIGRUBY
373 %typemap(argout) (char *buffer, apr_size_t *len) {
374 %append_output(*$2 == 0 ? Qnil : rb_str_new($1, *$2));
375 free($1);
377 #endif
379 /* -----------------------------------------------------------------------
380 fix up the svn_stream_write() ptr/len arguments
382 #ifdef SWIGPYTHON
383 %typemap(in) (const char *data, apr_size_t *len) ($*2_type temp) {
384 if (!PyString_Check($input)) {
385 PyErr_SetString(PyExc_TypeError,
386 "expecting a string for the buffer");
387 SWIG_fail;
389 $1 = PyString_AS_STRING($input);
390 temp = PyString_GET_SIZE($input);
391 $2 = ($2_ltype)&temp;
393 #endif
394 #ifdef SWIGPERL
395 %typemap(in) (const char *data, apr_size_t *len) ($*2_type temp) {
396 $1 = SvPV($input, temp);
397 $2 = ($2_ltype)&temp;
399 #endif
400 #ifdef SWIGRUBY
401 %typemap(in) (const char *data, apr_size_t *len) ($*2_type temp)
403 $1 = StringValuePtr($input);
404 temp = RSTRING($input)->len;
405 $2 = ($2_ltype)&temp;
407 #endif
409 #ifdef SWIGPYTHON
410 %typemap(argout) (const char *data, apr_size_t *len) {
411 %append_output(PyInt_FromLong(*$2));
413 #endif
415 #ifdef SWIGPERL
416 %typemap(argout) (const char *data, apr_size_t *len) {
417 %append_output(sv_2mortal(newSViv(*$2)));
419 #endif
421 #ifdef SWIGRUBY
422 %typemap(argout) (const char *data, apr_size_t *len) {
423 %append_output(LONG2NUM(*$2));
425 #endif
427 /* -----------------------------------------------------------------------
428 auth parameter set/get
431 /* set */
432 #ifdef SWIGPYTHON
433 %typemap(in) const void *value {
434 if (PyString_Check($input)) {
435 $1 = (void *)PyString_AS_STRING($input);
437 else if (PyLong_Check($input)) {
438 $1 = (void *)PyLong_AsLong($input);
440 else if (PyInt_Check($input)) {
441 $1 = (void *)PyInt_AsLong($input);
443 else {
444 PyErr_SetString(PyExc_TypeError, "not a known type");
445 SWIG_fail;
448 #endif
451 - all values are converted to char*
452 - assume the first argument is Ruby object for svn_auth_baton_t*
454 #ifdef SWIGRUBY
455 %typemap(in) const void *value
457 if (NIL_P($input)) {
458 $1 = (void *)NULL;
459 } else {
460 VALUE _rb_pool;
461 apr_pool_t *_global_pool;
462 char *value = StringValuePtr($input);
464 svn_swig_rb_get_pool(1, argv, Qnil, &_rb_pool, &_global_pool);
465 $1 = (void *)apr_pstrdup(_global_pool, value);
468 #endif
470 /* get */
471 /* assume the value is char* */
472 #ifdef SWIGRUBY
473 %typemap(out) const void *
475 char *value = $1;
476 if (value) {
477 $result = rb_str_new2(value);
478 } else {
479 $result = Qnil;
482 #endif
484 #ifndef SWIGRUBY
485 %ignore svn_auth_get_parameter;
486 #endif
488 /* -----------------------------------------------------------------------
489 svn_io_parse_mimetypes_file()
492 #ifdef SWIGRUBY
493 %apply apr_hash_t **HASH_CSTRING {
494 apr_hash_t **type_map
496 #endif
498 /* -----------------------------------------------------------------------
499 svn_io_detect_mimetype2()
502 %apply apr_hash_t *HASH_CSTRING {
503 apr_hash_t *mimetype_map
506 /* -----------------------------------------------------------------------
507 describe how to pass a FILE* as a parameter (svn_stream_from_stdio)
509 #ifdef SWIGPYTHON
510 %typemap(in) FILE * {
511 $1 = PyFile_AsFile($input);
512 if ($1 == NULL) {
513 PyErr_SetString(PyExc_ValueError, "Must pass in a valid file object");
514 SWIG_fail;
517 #endif
518 #ifdef SWIGPERL
519 %typemap(in) FILE * {
520 $1 = PerlIO_exportFILE (IoIFP (sv_2io ($input)), NULL);
522 #endif
524 /* -----------------------------------------------------------------------
525 wrap some specific APR functionality
528 apr_status_t apr_initialize(void);
529 void apr_terminate(void);
531 apr_status_t apr_time_ansi_put(apr_time_t *result, time_t input);
533 void apr_pool_destroy(apr_pool_t *p);
534 void apr_pool_clear(apr_pool_t *p);
536 apr_status_t apr_file_open_stdout (apr_file_t **out, apr_pool_t *pool);
537 apr_status_t apr_file_open_stderr (apr_file_t **out, apr_pool_t *pool);
539 /* Allow parsing of apr_errno.h without parsing apr.h. */
540 #define APR_DECLARE(x) x
541 /* Not wrapped, use svn_strerror instead. */
542 %ignore apr_strerror;
543 /* Wrap the APR status and error codes. */
544 /* Sigh, or not. This would mean actually having access to apr_errno.h at
545 wrapper generation time, which, when rolling tarballs, the include paths
546 are not currently set up to give us. FIXME. So, instead, we replicate
547 one important typedef here instead.
548 %include apr_errno.h
550 typedef int apr_status_t;
552 /* -----------------------------------------------------------------------
553 pool functions renaming since swig doesn't take care of the #define's
555 %rename (svn_pool_create) svn_pool_create_ex;
556 %ignore svn_pool_create_ex_debug;
557 %typemap(default) apr_allocator_t *allocator {
558 $1 = NULL;
561 /* -----------------------------------------------------------------------
562 Default pool handling for perl.
564 #ifdef SWIGPERL
565 apr_pool_t *current_pool;
567 #if SWIG_VERSION <= 0x010324
569 #define SVN_SWIGEXPORT(t) SWIGEXPORT(t)
571 #else
573 #define SVN_SWIGEXPORT(t) SWIGEXPORT t
575 #endif
579 static apr_pool_t *current_pool = 0;
581 SVN_SWIGEXPORT(apr_pool_t *)
582 svn_swig_pl_get_current_pool (void)
584 return current_pool;
587 SVN_SWIGEXPORT(void)
588 svn_swig_pl_set_current_pool (apr_pool_t *pool)
590 current_pool = pool;
595 #endif
597 /* -----------------------------------------------------------------------
598 wrap config functions
601 #ifdef SWIGPERL
602 %callback_typemap(svn_config_enumerator_t callback, void *baton,
604 svn_swig_pl_thunk_config_enumerator,
606 #endif
608 #ifdef SWIGRUBY
609 %callback_typemap(svn_config_enumerator2_t callback, void *baton,
612 svn_swig_rb_config_enumerator)
614 %callback_typemap(svn_config_section_enumerator2_t callback, void *baton,
617 svn_swig_rb_config_section_enumerator)
618 #endif
620 /* Allow None to be passed as config_dir argument */
621 #ifdef SWIGPYTHON
622 %typemap(in,parse="z") const char *config_dir "";
623 #endif
625 /* -----------------------------------------------------------------------
626 thunk the various authentication prompt functions.
627 PERL NOTE: store the inputed SV in _global_callback for use in the
628 later argout typemap
630 #ifdef SWIGPERL
631 %define %authprompt_callback_typemap(AuthType)
632 %typemap(in) (svn_auth_ ## AuthType ## _prompt_func_t prompt_func,
633 void *prompt_baton) {
634 $1 = svn_swig_pl_thunk_ ## AuthType ## _prompt;
635 $2 = $input;
636 _global_callback = $input;
638 %enddef
639 #else
640 %define %authprompt_callback_typemap(AuthType)
641 %callback_typemap(svn_auth_ ## AuthType ## _prompt_func_t prompt_func,
642 void *prompt_baton,
643 svn_swig_py_auth_ ## AuthType ## _prompt_func,,
644 svn_swig_rb_auth_ ## AuthType ## _prompt_func)
645 %enddef
646 #endif
648 %authprompt_callback_typemap(simple)
649 %authprompt_callback_typemap(username)
650 %authprompt_callback_typemap(ssl_server_trust)
651 %authprompt_callback_typemap(ssl_client_cert)
652 %authprompt_callback_typemap(ssl_client_cert_pw)
654 /* -----------------------------------------------------------------------
655 * For all the various functions that set a callback baton create a reference
656 * for the baton (which in this case is an SV pointing to the callback)
657 * and make that a return from the function. The perl side should
658 * then store the return in the object the baton is attached to.
659 * If the function already returns a value then this value is follows that
660 * function. In the case of the prompt functions auth_open_helper in Core.pm
661 * is used to split up these values.
663 #ifdef SWIGPERL
664 %typemap(argout) void *CALLBACK_BATON (SV * _global_callback) {
665 /* callback baton */
666 %append_output(sv_2mortal(newRV_inc(_global_callback)));
669 %typemap(in) void *CALLBACK_BATON (SV * _global_callback) {
670 _global_callback = $input;
671 $1 = (void *) _global_callback;
674 %apply void *CALLBACK_BATON {
675 void *prompt_baton
677 #endif
680 /* -----------------------------------------------------------------------
681 These APIs take an "inout" parameter that necessitates more careful
682 definition.
684 %ignore svn_mergeinfo_merge;
685 %ignore svn_mergeinfo_sort;
686 %ignore svn_rangelist_merge;
687 %ignore svn_rangelist_reverse;
689 #ifdef SWIGRUBY
690 %ignore svn_auth_open;
691 %ignore svn_diff_file_options_create;
692 %ignore svn_create_commit_info;
693 %ignore svn_commit_info_dup;
695 %ignore svn_opt_args_to_target_array2;
696 %ignore svn_opt_args_to_target_array3;
697 %ignore svn_opt_parse_num_args;
698 %ignore svn_opt_parse_all_args;
699 #endif
701 /* ----------------------------------------------------------------------- */
703 %include svn_error_codes_h.swg
704 %include svn_time_h.swg
705 %include svn_types_h.swg
706 %include svn_pools_h.swg
707 %include svn_version_h.swg
709 /* The constant SVN_PROP_REVISION_ALL_PROPS is a C fragment, not a single
710 data value, so the SWIG parser will raise a 305 warning if we don't
711 suppress it. */
712 #pragma SWIG nowarn=305
713 %include svn_props_h.swg
714 #pragma SWIG nowarn=+305
716 %include svn_opt_h.swg
717 %include svn_auth_h.swg
718 %include svn_config_h.swg
719 %include svn_utf_h.swg
720 %include svn_nls_h.swg
721 %include svn_path_h.swg
722 %include svn_mergeinfo_h.swg
723 %include svn_io_h.swg
725 #ifdef SWIGPERL
726 %include svn_md5_h.swg
727 %include svn_diff_h.swg
728 %include svn_error_h.swg
731 #include "svn_private_config.h"
733 %init %{
734 #if defined(SVN_AVOID_CIRCULAR_LINKAGE_AT_ALL_COSTS_HACK)
735 svn_swig_pl_bind_current_pool_fns (&svn_swig_pl_get_current_pool,
736 &svn_swig_pl_set_current_pool);
737 #endif
739 #endif
741 #ifdef SWIGPYTHON
743 void svn_swig_py_set_application_pool(PyObject *py_pool, apr_pool_t *pool);
744 void svn_swig_py_clear_application_pool();
746 %init %{
747 /* Theoretically, we should be checking for errors here,
748 but I do not know of any useful way to signal an error to Python
749 from within a module initialization function. */
750 svn_swig_py_initialize();
753 /* Proxy classes for APR classes */
754 %include proxy_apr.swg
756 #endif
758 #ifdef SWIGRUBY
759 %init %{
760 svn_swig_rb_initialize();
762 rb_define_const(mCore, "SVN_VER_NUM", rb_str_new2(SVN_VER_NUM));
763 rb_define_const(mCore, "SVN_VER_NUMBER", rb_str_new2(SVN_VER_NUMBER));
764 rb_define_const(mCore, "SVN_VERSION", rb_str_new2(SVN_VERSION));
767 %header %{
768 static void apr_pool_wrapper_destroy(apr_pool_wrapper_t *self);
769 static void apr_pool_wrapper_destroy_children(apr_pool_wrapper_t *self);
770 static void apr_pool_wrapper_remove_from_parent(apr_pool_wrapper_t *self);
773 /* Dummy declaration */
774 struct apr_pool_wrapper_t
778 /* Leave memory administration to ruby's GC */
779 %extend apr_pool_wrapper_t
781 static void destroy(VALUE object) {
782 svn_swig_rb_destroy_internal_pool(object);
785 apr_pool_wrapper_t(apr_pool_wrapper_t *parent) {
786 apr_pool_wrapper_t *self;
787 apr_pool_t *parent_pool;
789 self = ALLOC(apr_pool_wrapper_t);
790 if (parent) {
791 parent_pool = parent->pool;
792 APR_ARRAY_PUSH(parent->children, apr_pool_wrapper_t *) = self;
793 } else {
794 parent_pool = NULL;
796 self->pool = svn_pool_create_ex(parent_pool, NULL);
797 self->destroyed = FALSE;
798 self->parent = parent;
799 self->children = apr_array_make(self->pool, 0,
800 sizeof(apr_pool_wrapper_t *));
801 return self;
804 ~apr_pool_wrapper_t() {
805 apr_pool_wrapper_destroy(self);
806 xfree(self);
809 void _destroy(void) {
810 apr_pool_wrapper_destroy(self);
814 %ignore apr_pool_wrapper_destroy;
815 %ignore apr_pool_wrapper_destroy_children;
816 %ignore apr_pool_wrapper_remove_from_parent;
817 %inline %{
818 static void
819 apr_pool_wrapper_destroy(apr_pool_wrapper_t *self)
821 if (!self->destroyed) {
822 self->destroyed = TRUE;
823 apr_pool_wrapper_destroy_children(self);
824 apr_pool_wrapper_remove_from_parent(self);
825 apr_pool_destroy(self->pool);
829 static void
830 apr_pool_wrapper_destroy_children(apr_pool_wrapper_t *self)
832 apr_pool_wrapper_t **child;
834 while ((child = apr_array_pop(self->children))) {
835 if (*child) {
836 apr_pool_wrapper_destroy(*child);
841 static void
842 apr_pool_wrapper_remove_from_parent(apr_pool_wrapper_t *self)
844 if (self->parent) {
845 apr_pool_wrapper_t *child;
846 int i, len;
848 len = self->parent->children->nelts;
849 for (i = 0; i < len; i++) {
850 child = APR_ARRAY_IDX(self->parent->children, i, apr_pool_wrapper_t *);
851 if (child == self) {
852 APR_ARRAY_IDX(self->parent->children, i, apr_pool_wrapper_t *) = NULL;
853 self->parent = NULL;
854 break;
861 /* Dummy declaration */
862 struct svn_stream_t
866 %extend svn_stream_t
868 svn_stream_t(VALUE io) {
869 return svn_swig_rb_make_stream(io);
872 ~svn_stream_t() {
876 /* Dummy declaration */
877 struct svn_auth_baton_t
881 %extend svn_auth_baton_t
883 svn_auth_baton_t(apr_array_header_t *providers, apr_pool_t *pool) {
884 svn_auth_baton_t *self;
885 svn_auth_open(&self, providers, pool);
886 return self;
889 ~svn_auth_baton_t() {
893 %extend svn_diff_file_options_t
895 svn_diff_file_options_t(apr_pool_t *pool) {
896 return svn_diff_file_options_create(pool);
899 ~svn_diff_file_options_t() {
903 %extend svn_commit_info_t
905 svn_commit_info_t(apr_pool_t *pool) {
906 return svn_create_commit_info(pool);
909 ~svn_commit_info_t() {
912 svn_commit_info_t *dup(apr_pool_t *pool) {
913 return svn_commit_info_dup(self, pool);
917 %extend svn_merge_range_t
919 svn_merge_range_t(svn_revnum_t start, svn_revnum_t end,
920 svn_boolean_t inheritable, apr_pool_t *pool) {
921 svn_merge_range_t *self;
922 self = apr_palloc(pool, sizeof(svn_merge_range_t));
923 self->start = start;
924 self->end = end;
925 self->inheritable = inheritable;
926 return self;
929 ~svn_merge_range_t() {
932 svn_merge_range_t *dup(apr_pool_t *pool) {
933 return svn_merge_range_dup(self, pool);
937 %include svn_diff_h.swg
939 %inline %{
940 static VALUE
941 svn_default_charset(void)
943 return PTR2NUM(APR_DEFAULT_CHARSET);
946 static VALUE
947 svn_locale_charset(void)
949 return PTR2NUM(APR_LOCALE_CHARSET);
952 /* prompt providers return baton for protecting GC */
953 static VALUE
954 svn_swig_rb_auth_get_simple_prompt_provider(
955 svn_auth_provider_object_t **provider,
956 svn_auth_simple_prompt_func_t prompt_func,
957 void *prompt_baton,
958 int retry_limit,
959 apr_pool_t *pool)
961 svn_auth_get_simple_prompt_provider(provider, prompt_func, prompt_baton,
962 retry_limit, pool);
963 return rb_ary_new3(1, (VALUE)prompt_baton);
966 static VALUE
967 svn_swig_rb_auth_get_ssl_client_cert_prompt_provider(
968 svn_auth_provider_object_t **provider,
969 svn_auth_ssl_client_cert_prompt_func_t prompt_func,
970 void *prompt_baton,
971 int retry_limit,
972 apr_pool_t *pool)
974 svn_auth_get_ssl_client_cert_prompt_provider(provider, prompt_func,
975 prompt_baton, retry_limit,
976 pool);
977 return rb_ary_new3(1, (VALUE)prompt_baton);
980 static VALUE
981 svn_swig_rb_auth_get_ssl_client_cert_pw_prompt_provider(
982 svn_auth_provider_object_t **provider,
983 svn_auth_ssl_client_cert_pw_prompt_func_t prompt_func,
984 void *prompt_baton,
985 int retry_limit,
986 apr_pool_t *pool)
988 svn_auth_get_ssl_client_cert_pw_prompt_provider(provider, prompt_func,
989 prompt_baton, retry_limit,
990 pool);
991 return rb_ary_new3(1, (VALUE)prompt_baton);
994 static VALUE
995 svn_swig_rb_auth_get_ssl_server_trust_prompt_provider(
996 svn_auth_provider_object_t **provider,
997 svn_auth_ssl_server_trust_prompt_func_t prompt_func,
998 void *prompt_baton,
999 apr_pool_t *pool)
1001 svn_auth_get_ssl_server_trust_prompt_provider(provider, prompt_func,
1002 prompt_baton, pool);
1003 return rb_ary_new3(1, (VALUE)prompt_baton);
1006 static VALUE
1007 svn_swig_rb_auth_get_username_prompt_provider(
1008 svn_auth_provider_object_t **provider,
1009 svn_auth_username_prompt_func_t prompt_func,
1010 void *prompt_baton,
1011 int retry_limit,
1012 apr_pool_t *pool)
1014 svn_auth_get_username_prompt_provider(provider, prompt_func, prompt_baton,
1015 retry_limit, pool);
1016 return rb_ary_new3(1, (VALUE)prompt_baton);
1019 #endif
1021 #if defined(SWIGPYTHON) || defined(SWIGRUBY)
1022 %inline %{
1023 static svn_error_t *
1024 svn_swig_mergeinfo_merge(apr_hash_t **mergeinfo_inout,
1025 apr_hash_t *changes,
1026 apr_pool_t *pool)
1028 return svn_mergeinfo_merge(*mergeinfo_inout, changes, pool);
1031 static svn_error_t *
1032 svn_swig_mergeinfo_sort(apr_hash_t **mergeinfo_inout, apr_pool_t *pool)
1034 return svn_mergeinfo_sort(*mergeinfo_inout, pool);
1037 static svn_error_t *
1038 svn_swig_rangelist_merge(apr_array_header_t **rangelist_inout,
1039 apr_array_header_t *changes,
1040 apr_pool_t *pool)
1042 return svn_rangelist_merge(rangelist_inout, changes, pool);
1045 static svn_error_t *
1046 svn_swig_rangelist_reverse(apr_array_header_t **rangelist_inout,
1047 apr_pool_t *pool)
1049 return svn_rangelist_reverse(*rangelist_inout, pool);
1052 #endif