summaryrefslogtreecommitdiff
path: root/subversion/bindings/swig/include/svn_types.swg
blob: 7c933b1ac7a75a83c2ae8acac1c9e55d8d7b2221 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
/*
 * ====================================================================
 *    Licensed to the Apache Software Foundation (ASF) under one
 *    or more contributor license agreements.  See the NOTICE file
 *    distributed with this work for additional information
 *    regarding copyright ownership.  The ASF licenses this file
 *    to you under the Apache License, Version 2.0 (the
 *    "License"); you may not use this file except in compliance
 *    with the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing,
 *    software distributed under the License is distributed on an
 *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *    KIND, either express or implied.  See the License for the
 *    specific language governing permissions and limitations
 *    under the License.
 * ====================================================================
 *
 * svn_types.swg: This is the main file of the Subversion typemap
 *   library.  Certain categories of typemaps are removed into child
 *   files that are then %included into this one, solely to promote
 *   code comprehensibility by grouping related parts.
 */

%include apr.swg
%include svn_string.swg
%include svn_containers.swg

/* -----------------------------------------------------------------------
   Generic handling for "type **" parameters.  Almost all such parameters
   are OUTPUT parameters.  Handling is as follows:
   - "in" typemap which allocates storage for a pointer, and points the
     argument to that storage.
   - Default "argout" typemap which complains at compile time, and raises
     an exception at runtime.
   - OUTPARAM "argout" typemap which wraps (SWIG_NewPointerObj) a C
     pointer for return to the scripting language.
   - Application of the OUTPARAM typemap to those types for which it makes
     sense (key examples for which it does not are strings, arrays, and
     hashes - which need to be turned into their scripting language
     equivalent).
   Known instances of "type **" which are *not* OUTPUT parameters are:
   - svn_stream_checksummed(..., const unsigned char **read_digest,
                                 const unsigned char **write_digest, ...)
   - svn_*_change_rev_prop2(..., const svn_string_t *const *old_value_p, ...)
*/
%typemap(in, numinputs=0) SWIGTYPE ** ($*1_ltype temp) "$1 = &temp;";

/* We have a long standing bug where svn_client_commit_info_t and
   svn_commit_info_t output parameters are not properly initialized to NULL
   when there is nothing to commit.  This is a workaround.  Yes, it is
   unspeakably evil that this was not just fixed at source when it was
   discovered initially. */
%typemap(in, numinputs=0) BAD_OUTPUT_INIT_HACK ** ($*1_ltype temp = NULL)
  "$1 = &temp;";
%apply BAD_OUTPUT_INIT_HACK ** {
  svn_commit_info_t **,
  svn_client_commit_info_t **
};

%typemap(argout,warning="900:FIXME: Missing argout typemap") SWIGTYPE ** {
  /* FIXME: Missing argout typemap: $symname arg $argnum ($1_type) */
#if defined(SWIGRUBY) && SWIG_VERSION <= 0x010329
  /* Ruby fails to define $symname. */
  SWIG_exception(SWIG_ValueError, "Function is not implemented yet");
#else
  SWIG_exception(SWIG_ValueError, "$symname is not implemented yet");
#endif
}

%typemap(in,warning="901:FIXME: Missing old_value_p typemap") const svn_string_t *const *old_value_p {
#if defined(SWIGRUBY) && SWIG_VERSION <= 0x010329
  /* Ruby fails to define $symname. */
  SWIG_exception(SWIG_ValueError, "Function is not implemented yet");
#else
  SWIG_exception(SWIG_ValueError, "$symname is not implemented yet");
#endif
}

#ifdef SWIGPYTHON
%typemap(argout) SWIGTYPE **OUTPARAM {
  %append_output(svn_swig_py_new_pointer_obj(*$1, $*1_descriptor,
                                             _global_py_pool, args));
}
#else
%typemap(argout) SWIGTYPE **OUTPARAM {
  %append_output(SWIG_NewPointerObj(*$1, $*1_descriptor, 0));
}
#endif

%apply SWIGTYPE **OUTPARAM {
  /* apr */
  apr_file_t **,
  apr_hash_t **,
  /* svn_types.h */
  svn_commit_info_t **,
  svn_dirent_t **,
  svn_lock_t **,
  svn_stream_t **,
  svn_commit_callback2_t *,
  void **callback2_baton,
  /* core */
  svn_auth_baton_t **,
  svn_auth_cred_simple_t **cred,
  svn_auth_cred_username_t **cred,
  svn_auth_cred_ssl_client_cert_pw_t **cred,
  svn_auth_cred_ssl_client_cert_t **cred,
  svn_auth_cred_ssl_server_trust_t **cred,
  svn_auth_iterstate_t **,
  svn_auth_provider_object_t **,
  svn_config_t **,
  svn_diff_t **,
  svn_patch_file_t **,
  svn_patch_t **,
  void **credentials,
  void **iter_baton,
  void **token,
  /* svn_checksum */
  svn_checksum_t **,
  /* svn_client */
  svn_client_commit_info_t **,
  svn_client_conflict_t **,
  svn_client_conflict_option_t **,
  svn_client_ctx_t **,
  const svn_client_commit_item3_t **,
  svn_client__shelf_t **,
  svn_client__shelf_version_t **,
  /* svn_delta */
  const svn_delta_editor_t **,
  svn_txdelta_stream_t **,
  svn_txdelta_window_t **,
#ifndef SWIGPYTHON
  /* Python wraps this as a CALLABLE_CALLBACK instead */
  svn_txdelta_window_handler_t *,
#endif
  void **handler_baton,
  void **handler2_baton,
  void **root_baton,
  void **child_baton,
  void **file_baton,
  void **edit_baton,
  void **dir_baton,
  /* svn_fs */
  svn_fs_t **,
  svn_fs_access_t **,
  svn_fs_history_t **,
  svn_fs_id_t **,
  svn_fs_root_t **,
  svn_fs_txn_t **,
  void **contents_baton_p,
  /* svn_io */
  svn_io_dirent2_t **,
  svn_stream_mark_t **,
  /* svn_ra */
  svn_ra_callbacks2_t **,
  svn_ra_plugin_t **,
  const svn_ra_reporter_t **,
  const svn_ra_reporter2_t **,
  const svn_ra_reporter3_t **,
  svn_ra_session_t **,
  void **delta_baton,
  void **report_baton,
  void **ra_baton,
  void **session_baton,
  /* svn_repos */
  svn_authz_t **,
  svn_repos_t **,
  const svn_repos_parse_fns3_t **,
  const svn_repos_parser_fns2_t **,
  const svn_repos_parser_fns_t **,
  void **parse_baton,
  void **revision_baton,
  void **node_baton,
  /* svn_wc */
  svn_wc_adm_access_t **,
  svn_wc_external_item2_t **,
  svn_wc_entry_t **,
  svn_wc_revision_status_t **,
  svn_wc_status_t **,
  svn_wc_status2_t **,
  svn_wc_committed_queue_t **,
#ifdef SWIGRUBY
  /* Only tested for Ruby */
  svn_wc_context_t **,
#endif
  void **set_locks_baton
};

#ifdef SWIGRUBY
%typemap(argout) SWIGTYPE **OUTPARAM_WITH_BLOCK {
  VALUE tmp;
  tmp = SWIG_NewPointerObj(*$1, $*1_descriptor, 0);
  if (rb_block_given_p()) {
    rb_yield(tmp);
    svn_swig_rb_destroy_pool(_global_svn_swig_rb_pool);
    DATA_PTR(tmp) = NULL;
  } else {
    %append_output(tmp);
  }
}

%apply SWIGTYPE **OUTPARAM_WITH_BLOCK {
  /* svn_fs */
  svn_fs_t **,
  /* svn_repos */
  svn_repos_t **
};
#endif


/* -----------------------------------------------------------------------
   Check whether fs/repos was closed or not.
*/
#ifdef SWIGRUBY
%define %raise_if_null(TYPE)
%typemap(check) svn_ ## TYPE ## _t *
{
  if (!$1) {
    svn_swig_rb_raise_svn_ ## TYPE ## _already_close();
  }
}
%enddef

%raise_if_null(fs);
%raise_if_null(repos);

%define %define_close_related_methods(TYPE)
%ignore svn_ ## TYPE ## _swig_rb_close;
%ignore svn_ ## TYPE ## _swig_rb_closed;

%inline %{
static VALUE
svn_ ## TYPE ## _swig_rb_close(VALUE self)
{
  if (!DATA_PTR(self)) {
    svn_swig_rb_raise_svn_ ## TYPE ## _already_close();
  }

  svn_swig_rb_destroy_internal_pool(self);
  DATA_PTR(self) = NULL;

  return Qnil;
}

static VALUE
svn_ ## TYPE ## _swig_rb_closed(VALUE self)
{
  return DATA_PTR(self) ? Qfalse : Qtrue;
}
%}

%init %{
  {
    VALUE cSvn ## TYPE;
    cSvn ## TYPE = rb_const_get(_mSWIG, rb_intern("TYPE_p_svn_" #TYPE "_t"));
    rb_define_method(cSvn ## TYPE, "close",
                     svn_ ## TYPE ## _swig_rb_close, 0);
    rb_define_method(cSvn ## TYPE, "closed?",
                     svn_ ## TYPE ## _swig_rb_closed, 0);
  }
%}
%enddef
#endif

/* -----------------------------------------------------------------------
   %apply-ing of typemaps
*/

%apply int *OUTPUT {
  int *,
  svn_boolean_t *,
  enum svn_wc_merge_outcome_t *
};
%apply long *OUTPUT { svn_revnum_t *, svn_node_kind_t * };
%apply long long *OUTPUT { svn_filesize_t * }

/* -----------------------------------------------------------------------
   Generic macros for callback typemaps
*/

#ifdef SWIGPYTHON
%define %callback_typemap(CallbackFunction, CallbackBaton,
                          PythonThunk, PerlThunk, RubyThunk)
%typemap(in) (CallbackFunction, CallbackBaton) {
  $1 = ($1_ltype) PythonThunk;
  $2 = $input;
}
%enddef
%define %callback_typemap_maybenull(CallbackFunction, CallbackBaton,
                                    PythonThunk, PerlThunk, RubyThunk)
%typemap(in) (CallbackFunction, CallbackBaton) {
  /* FIXME: Handle the NULL case. */
  $1 = ($1_ltype) PythonThunk;
  $2 = $input;
}
%enddef
#endif

#ifdef SWIGPERL
%define %callback_typemap(CallbackFunction, CallbackBaton,
                          PythonThunk, PerlThunk, RubyThunk)
%typemap(in) (CallbackFunction, CallbackBaton) {
  $1 = ($1_ltype) PerlThunk;
  $2 = $input;
}
%enddef
%define %callback_typemap_maybenull(CallbackFunction, CallbackBaton,
                                    PythonThunk, PerlThunk, RubyThunk)
%typemap(in) (CallbackFunction, CallbackBaton) {
  if (SvOK($input)) {
    $1 = ($1_ltype) PerlThunk;
    $2 = $input;
  } else {
    $1 = ($1_ltype) NULL;
    $2 = NULL;
  }
}
%enddef
#endif

#ifdef SWIGRUBY
%define %callback_typemap(CallbackFunction, CallbackBaton,
                          PythonThunk, PerlThunk, RubyThunk)
%typemap(in) (CallbackFunction, CallbackBaton) {
  $1 = ($1_ltype) RubyThunk;
  $2 = (void *)svn_swig_rb_make_baton($input, _global_svn_swig_rb_pool);
}
%enddef
%define %callback_typemap_maybenull(CallbackFunction, CallbackBaton,
                                    PythonThunk, PerlThunk, RubyThunk)
%typemap(in) (CallbackFunction, CallbackBaton) {
  if (NIL_P($input)) {
    $1 = ($1_ltype) NULL;
    $2 = NULL;
  } else {
    $1 = ($1_ltype) RubyThunk;
    $2 = (void *)svn_swig_rb_make_baton($input, _global_svn_swig_rb_pool);
  }
}
%enddef
#endif

/* -----------------------------------------------------------------------
   Create a typemap for specifying string args that may be NULL.
*/
#ifdef SWIGPYTHON
%typemap(in) const char *MAY_BE_NULL
{
    $1 = svn_swig_py_string_to_cstring($input, TRUE, "$symname", "$1_name");
    if (PyErr_Occurred()) SWIG_fail;
}
#endif

#ifdef SWIGPERL
%apply const char * { const char *MAY_BE_NULL };
#endif

#ifdef SWIGRUBY
%typemap(in) const char *MAY_BE_NULL
{
  if (NIL_P($input)) {
    $1 = NULL;
  } else {
    $1 = StringValuePtr($input);
  }
}

%typemap(in) const char *NOT_NULL
{
  $1 = StringValueCStr($input);
}

%typemap(out) const char *
{
  if ($1) {
    $result = rb_str_new2($1);
  } else {
    $result = Qnil;
  }
}
#endif

/* -----------------------------------------------------------------------
   const char *header_encoding
   svn_diff_file_output_unified2
   svn_client_diff3
*/
#ifdef SWIGRUBY
%typemap(in) const char *header_encoding
{
  $1 = NULL;

  if (NIL_P($input)) {
  } else if (TYPE($input) == T_FIXNUM) {
    $1 = (char *)NUM2INT($input);
    if (!($1 == APR_LOCALE_CHARSET || $1 == APR_DEFAULT_CHARSET)) {
      $1 = NULL;
    }
  } else {
    $1 = StringValuePtr($input);
  }

  if (!$1) {
    $1 = (char *)APR_LOCALE_CHARSET;
  }
}
#endif

/* -----------------------------------------------------------------------
   Define a more refined 'memberin' typemap for 'const char *' members. This
   is used in place of the 'char *' handler defined automatically.

   We need to do the free/malloc/strcpy special because of the const
*/
%typemap(memberin) const char * {
    apr_size_t len = strlen($input) + 1;
    char *copied;
    if ($1) free((char *)$1);
    copied = malloc(len);
    memcpy(copied, $input, len);
    $1 = copied;
}

/* -----------------------------------------------------------------------
   Specify how svn_error_t returns are turned into exceptions.
*/
#ifdef SWIGPYTHON
%typemap(out) svn_error_t * {
    if ($1 != NULL) {
        if ($1->apr_err != SVN_ERR_SWIG_PY_EXCEPTION_SET)
            svn_swig_py_svn_exception($1);
        else
            svn_error_clear($1);
        SWIG_fail;
    }
    Py_INCREF(Py_None);
    $result = Py_None;
}
#endif

#ifdef SWIGPERL
%typemap(out) svn_error_t * {
    if ($1) {
        SV *exception_handler = perl_get_sv ("SVN::Error::handler", FALSE);

        if (SvOK(exception_handler)) {
            SV *callback_result;

            PUTBACK;
            svn_swig_pl_callback_thunk (CALL_SV, exception_handler,
                                        &callback_result, "S", $1,
                                        $1_descriptor);
            SPAGAIN;
        } else {
            $result = SWIG_NewPointerObj($1, $1_descriptor, 0);
            argvi++;
        }
    }
}
#endif

#ifdef SWIGRUBY
%typemap(out) svn_error_t *
{
  if ($1) {
    svn_swig_rb_destroy_pool(_global_svn_swig_rb_pool);
    svn_swig_rb_pop_pool(_global_svn_swig_rb_pool);
    svn_swig_rb_handle_svn_error($1);
  }
  $result = Qnil;
}
#endif

/* -----------------------------------------------------------------------
   Define a general ptr/len typemap. This takes a single script argument
   and expands it into a ptr/len pair for the native call.
*/
#ifdef SWIGPYTHON
%typemap(in) (const char *PTR, apr_size_t LEN) {
    Py_ssize_t pyStrLen;
    if (!PyBytes_Check($input)) {
        PyErr_SetString(PyExc_TypeError, "expecting a bytes");
        SWIG_fail;
    }
    if (PyBytes_AsStringAndSize($input, &$1, &pyStrLen) == -1) {
        SWIG_fail;
    }
    $2 = pyStrLen;
}
#endif

#ifdef SWIGPERL
%typemap(in) (const char *PTR, apr_size_t LEN) {
    if (SvPOK($input)) {
        $1 = SvPV($input, $2);
    } else {
        /* set to 0 to avoid warning */
        $1 = 0;
        $2 = 0;
        SWIG_croak("Expecting a string");
    }
}
#endif

#ifdef SWIGRUBY
%typemap(in) (const char *PTR, apr_size_t LEN)
{
  if (!RTEST(rb_obj_is_kind_of($input, rb_cString))) {
    rb_raise(rb_eArgError, "Expecting a string");
  }
  $1 = StringValuePtr($input);
  $2 = RSTRING_LEN(StringValue($input));
}
#endif

%apply (const char *PTR, apr_size_t LEN) {
    (const char *data, apr_size_t len)
}

/* -----------------------------------------------------------------------
   Handle retrieving the error message from svn_strerror
*/

#ifdef SWIGPERL
%typemap(in,numinputs=0) (char *buf, apr_size_t bufsize) ( char temp[128] ) {
    memset (temp,0,128); /* paranoia */
    $1 = temp;
    $2 = 128;
}
#endif

/* -----------------------------------------------------------------------
   Define a generic arginit mapping for pools.
*/

#ifdef SWIGPYTHON

%typemap(in) POINTER_TYPES
{
  $1 = ($1_ltype)svn_swig_py_must_get_ptr($input, $descriptor, $svn_argnum);
  if (PyErr_Occurred()) {
    SWIG_fail;
  }
}

%typemap(out) POINTER_TYPES
    "$result = svn_swig_py_new_pointer_obj((void*)($1), $descriptor,
                                           _global_py_pool, args);";

%apply POINTER_TYPES { void *, SWIGTYPE *, SWIGTYPE [] };

%typemap(default, noblock=1) apr_pool_t
  *(apr_pool_t *_global_pool = NULL, PyObject *_global_py_pool = NULL)
{
  if (svn_swig_py_get_pool_arg(args, $descriptor,
      &_global_py_pool, &_global_pool))
    SWIG_fail;
  $1 = _global_pool;
}

%typemap(in, noblock=1) apr_pool_t * {
  /* Verify that the user supplied a valid pool */
  if ($input != Py_None && $input != _global_py_pool) {
    SWIG_Python_TypeError(SWIG_TypePrettyName($descriptor), $input);
    SWIG_arg_fail($svn_argnum);
    SWIG_fail;
  }
}

%typemap(freearg) apr_pool_t * {
  Py_XDECREF(_global_py_pool);
}
#endif

#ifdef SWIGPERL
%typemap(in) apr_pool_t *pool "";
%typemap(default) apr_pool_t *pool(apr_pool_t *_global_pool) {
    _global_pool = $1 = svn_swig_pl_make_pool (ST(items-1));
    SPAGAIN;
}
#endif
#ifdef SWIGRUBY
%typemap(in) apr_pool_t *pool "";
%typemap(default) apr_pool_t *pool
    (VALUE _global_svn_swig_rb_pool, apr_pool_t *_global_pool)
{
  svn_swig_rb_get_pool(argc, argv, self, &_global_svn_swig_rb_pool, &$1);
  _global_pool = $1;
  svn_swig_rb_push_pool(_global_svn_swig_rb_pool);
}

%typemap(default) (svn_client_ctx_t *ctx, apr_pool_t *pool)
     (VALUE _global_svn_swig_rb_pool, apr_pool_t *_global_pool)
{
  int adjusted_argc = argc;
  VALUE *adjusted_argv = argv;

  svn_swig_rb_adjust_arg_for_client_ctx_and_pool(&adjusted_argc,
                                                 &adjusted_argv);
  svn_swig_rb_get_pool(adjusted_argc, adjusted_argv, self,
                       &_global_svn_swig_rb_pool, &$2);
  _global_pool = $2;
  svn_swig_rb_push_pool(_global_svn_swig_rb_pool);
}

%typemap(freearg) apr_pool_t *pool
{
  VALUE target;
  target = _global_vresult_address == &vresult ? self : vresult;
  if (!svn_swig_rb_set_pool(target, _global_svn_swig_rb_pool))
    svn_swig_rb_destroy_pool(_global_svn_swig_rb_pool);
  svn_swig_rb_pop_pool(_global_svn_swig_rb_pool);
}
#endif

#ifdef SWIGPERL
%apply apr_pool_t *pool {
    apr_pool_t *dir_pool,
    apr_pool_t *file_pool,
    apr_pool_t *node_pool,
    apr_pool_t *result_pool,
    apr_pool_t *scratch_pool
};
#endif

#ifdef SWIGRUBY
%apply apr_pool_t *pool {
    apr_pool_t *dir_pool,
    apr_pool_t *file_pool,
    apr_pool_t *node_pool,
    apr_pool_t *result_pool,
    apr_pool_t *scratch_pool
};
#endif

/* -----------------------------------------------------------------------
 * The CALLABLE_CALLBACK typemap wraps callback types as objects which
 * can be called directly from Python. header_wrappers.py automatically
 * tags all callback types (in Python) with this callback.
 *
 * header_wrappers.py also generates a '__call__' function for the
 * callback objects, using the funcptr_proxy macro. See proxy.swg
 */

#ifdef SWIGPYTHON

/* Allocate memory for a pointer to the function pointer. */
%typemap(in, numinputs=0) CALLABLE_CALLBACK *
  (apr_pool_t *_global_pool = NULL, PyObject *_global_py_pool = NULL)
{
  if (_global_pool == NULL)
  {
    if (svn_swig_py_get_parent_pool(args, $descriptor(apr_pool_t *),
                                    &_global_py_pool, &_global_pool))
      SWIG_fail;
  }
  $1 = ($ltype) apr_pcalloc(_global_pool, sizeof($*ltype));
  if ($1 == NULL) SWIG_fail;
}


/* Return a pointer to the function pointer.
 * This level of indirection makes it easier for SWIG to treat
 * this callback like an object (which can be extended using SWIG).
 */

%typemap(argout) CALLABLE_CALLBACK * {
  %append_output(svn_swig_py_new_pointer_obj($1, $descriptor,
                                             _global_py_pool, args));
}

/* Convert the pointer to a function pointer back into a regular
 * function pointer
 */

%typemap(in) CALLABLE_CALLBACK {
  $&ltype tmp =
    svn_swig_py_must_get_ptr($input, $&descriptor, $svn_argnum);
  if (tmp == NULL || PyErr_Occurred()) {
    SWIG_fail;
  }
  $1 = *tmp;
}

/* Ensure that return values use a level of indirection.
 *
 * Allocate space on the heap for a pointer to the callback.
 * The memory gets freed when the return value itself is
 * freed.
 */

%typemap(out) CALLABLE_CALLBACK {
  PyObject *py_pool = NULL;
  apr_pool_t *pool = NULL;

  if (svn_swig_py_get_parent_pool(args, $descriptor(apr_pool_t *),
                                  &py_pool, &pool))
    SWIG_fail;
  if ($1 == NULL) {
    $result = Py_None;
    Py_INCREF($result);
  } else {
    $&ltype tmp = apr_palloc(pool, sizeof($ltype));
    if (tmp == NULL) {
      SWIG_fail;
    }
    *tmp = ($ltype) $1;
    $result = svn_swig_py_new_pointer_obj(tmp, $&1_descriptor,
                                          py_pool, args);
  }
}


/* Ensure that constant callbacks use a level of indirection.
 *
 * Allocate space on the heap for a pointer to the callback.
 * Since this constant is always in scope, we don't need to
 * worry about ever freeing the memory.
 */

%typemap(constcode) CALLABLE_CALLBACK {

  $&ltype tmp = malloc(sizeof($ltype));
  *tmp = ($ltype) $value;

  %set_constant("$symname",
    svn_swig_py_new_pointer_obj(tmp, $&descriptor, NULL, NULL)
  );

}

#endif

/* -----------------------------------------------------------------------
   Callback: svn_log_message_receiver_t
   svn_client_log()
   svn_ra get_log()
   svn_repos_get_logs()
*/

%callback_typemap(svn_log_message_receiver_t receiver, void *receiver_baton,
                  svn_swig_py_log_receiver,
                  svn_swig_pl_thunk_log_receiver,
                  svn_swig_rb_log_receiver)

/* -----------------------------------------------------------------------
   Callback: svn_log_entry_receiver_t
   svn_client_log4()
   svn_ra_get_log2()
   svn_repos_get_logs4()
*/

%callback_typemap(svn_log_entry_receiver_t receiver, void *receiver_baton,
                  svn_swig_py_log_entry_receiver,
                  svn_swig_pl_thunk_log_entry_receiver,
                  svn_swig_rb_log_entry_receiver)

/* -----------------------------------------------------------------------
   Callback: svn_commit_callback_t
   svn_ra get_commit_editor()
   svn_repos_get_commit_editor()
*/

#ifdef SWIGPERL
%typemap(in) (svn_commit_callback_t callback, void *callback_baton) {
    $1 = svn_swig_pl_thunk_commit_callback;
    $2 = (void *)$input;
    svn_swig_pl_hold_ref_in_pool (_global_pool, $input);
};
#endif

#ifdef SWIGRUBY
%typemap(in) (svn_commit_callback_t callback, void *callback_baton)
{
  $1 = svn_swig_rb_commit_callback;
  $2 = (void *)svn_swig_rb_make_baton($input, _global_svn_swig_rb_pool);
};

%typemap(argout) (svn_commit_callback_t callback, void *callback_baton)
{
  svn_swig_rb_set_baton($result, (VALUE)$2);
};
#endif

#ifdef SWIGPYTHON
%typemap(in) (svn_commit_callback_t callback, void *callback_baton)
{
  $1 = svn_swig_py_commit_callback;
  $2 = (void *)$input;
}
#endif

/* -----------------------------------------------------------------------
   Callback: svn_commit_callback2_t
   svn_ra get_commit_editor2()
   svn_repos_get_commit_editor4()
   svn_client_mkdir4() 
   svn_client_delete4() 
   svn_client_import4() 
   svn_client_commit5() 
   svn_client_copy6() 
   svn_client_move6() 
   svn_client_propset_remote() 
*/

#ifdef SWIGPERL
%typemap(in) (svn_commit_callback2_t commit_callback, void *commit_baton) {
    $1 = svn_swig_pl_thunk_commit_callback2;
    $2 = (void *)$input;
    svn_swig_pl_hold_ref_in_pool (_global_pool, $input);
};
#endif

#ifdef SWIGRUBY
%typemap(in) (svn_commit_callback2_t commit_callback, void *commit_baton)
{
  $1 = svn_swig_rb_commit_callback2;
  $2 = (void *)svn_swig_rb_make_baton($input, _global_svn_swig_rb_pool);
};

%typemap(argout) (svn_commit_callback2_t commit_callback, void *commit_baton)
{
  svn_swig_rb_set_baton($result, (VALUE)$2);
};
#endif

#ifdef SWIGPYTHON
%typemap(in) (svn_commit_callback2_t commit_callback, void *commit_baton)
{
  $1 = svn_swig_py_commit_callback2;
  $2 = (void *)$input;
}
#endif

/* -----------------------------------------------------------------------
   Callback: svn_cancel_func_t
*/

%callback_typemap(svn_cancel_func_t cancel_func, void *cancel_baton,
                  svn_swig_py_cancel_func,
                  svn_swig_pl_cancel_func,
                  svn_swig_rb_cancel_func)

#ifdef SWIGRUBY
%typemap(argout) (svn_cancel_func_t cancel_func, void *cancel_baton)
{
  svn_swig_rb_set_baton($result, (VALUE)$2);
};
#endif

#ifdef SWIGRUBY
%typemap(in) (svn_wc_conflict_resolver_func_t conflict_func, void *conflict_baton)
{
  $1 = svn_swig_rb_conflict_resolver_func;
  $2 = (void *)svn_swig_rb_make_baton($input, _global_svn_swig_rb_pool);
}

%typemap(argout) (svn_wc_conflict_resolver_func_t conflict_func, void *conflict_baton)
{
  svn_swig_rb_set_baton($result, (VALUE)$2);
};
#endif

#ifdef SWIGRUBY
%typemap(in) (svn_wc_get_file_t fetch_func, void *fetch_baton)
{
  /* ### TODO(rb support fetch_fun): implement
  $1 = svn_swig_rb_fetch_func;
  $2 = (void *)svn_swig_rb_make_baton($input, _global_svn_swig_rb_pool);
  */
  $1 = NULL;
  $2 = NULL;
}

%typemap(argout) (svn_wc_get_file_t fetch_func, void *fetch_baton)
{
  svn_swig_rb_set_baton($result, (VALUE)$2);
};
#endif

/* -----------------------------------------------------------------------
   Callback: svn_info_receiver_t
*/

#ifdef SWIGPERL
%typemap(in) (svn_info_receiver_t receiver, void *receiver_baton)
{
  $1 = svn_swig_pl_info_receiver;
  $2 = (void *)$input;
}
#endif

#ifdef SWIGRUBY
%typemap(in) (svn_info_receiver_t receiver, void *receiver_baton)
{
  $1 = svn_swig_rb_info_receiver;
  $2 = (void *)svn_swig_rb_make_baton($input, _global_svn_swig_rb_pool);
}
#endif

/* -----------------------------------------------------------------------
   Callback: svn_repos_freeze_func_t
*/
#ifdef SWIGPYTHON
%typemap(in) (svn_repos_freeze_func_t freeze_func, void *freeze_baton)
{
  $1 = svn_swig_py_repos_freeze_func;
  $2 = (void *)$input;
}
#endif

/* -----------------------------------------------------------------------
   Callback: svn_fs_freeze_func_t
*/
#ifdef SWIGPYTHON
%typemap(in) (svn_fs_freeze_func_t freeze_func, void *freeze_baton)
{
  $1 = svn_swig_py_fs_freeze_func;
  $2 = (void *)$input;
}
#endif

/* -----------------------------------------------------------------------
   Callback: svn_proplist_receiver2_t
*/
#ifdef SWIGPYTHON
%typemap(in) (svn_proplist_receiver2_t receiver, void *receiver_baton)
{
  $1 = svn_swig_py_proplist_receiver2;
  $2 = (void *)$input;
}
#endif

/* -----------------------------------------------------------------------
   Callback: svn_fs_warning_callback_t
*/

#ifdef SWIGRUBY
%typemap(in) (svn_fs_warning_callback_t warning, void *warning_baton)
{
  VALUE baton = svn_swig_rb_make_baton($input, _global_svn_swig_rb_pool);
  svn_swig_rb_fs_warning_callback_baton_register(baton, _global_pool);
  $1 = svn_swig_rb_fs_warning_callback;
  $2 = (void *)baton;
}
#endif
#ifdef SWIGPERL
%ignore svn_fs_set_warning_func;
#endif
#ifdef SWIGPYTHON
%ignore svn_fs_set_warning_func;
#endif

/* -----------------------------------------------------------------------
   svn_stream_t interoperability with language native io handles
*/

#ifdef SWIGPYTHON
%typemap(in) svn_stream_t *WRAPPED_STREAM {
    if ($input == Py_None) {
        $1 = NULL;
    }
    else {
        $1 = svn_swig_py_make_stream ($input, _global_pool);
        if ($1 == NULL) {
            SWIG_fail;
        }
    }
}
#endif

#ifdef SWIGPERL
%typemap(in) svn_stream_t * {
    svn_swig_pl_make_stream (&$1, $input);
    SPAGAIN;
}

%typemap(out) svn_stream_t * {
    SV* tmp;
    PUTBACK;
    tmp = svn_swig_pl_from_stream ($1);
    SPAGAIN;
    $result = tmp;
    argvi++;
}

%typemap(argout) svn_stream_t ** {
    SV *tmp;
    PUTBACK;
    tmp = svn_swig_pl_from_stream(*$1);
    SPAGAIN;
    %append_output(tmp);
}
#endif

#ifdef SWIGRUBY
%typemap(in) svn_stream_t * {
  $1 = svn_swig_rb_make_stream($input);
}

%typemap(in) svn_stream_t *MAY_BE_NULL {
  if (NIL_P($input)) {
    $1 = NULL;
  } else {
    $1 = svn_swig_rb_make_stream($input);
  }
}
#endif

/* -----------------------------------------------------------------------
   Mapper to automatically turn Python objects into void* batons on assignment
*/

#ifdef SWIGPYTHON

%typemap(in) void *PY_AS_VOID {
  if ($input == Py_None) {
    $1 = NULL;
  } else if (SWIG_ConvertPtr($input, (void **) &$1, 0, 0) == -1) {
    $1 = (void *) $input;
    PyErr_Clear();
  }
}


%typemap(out) void *PY_AS_VOID {
  PyObject *ownerObj = obj0;
  PyObject *members = PyObject_GetAttrString(ownerObj, "_members");

  $result = NULL;
  if (members != NULL) {
    $result = PyDict_GetItemString(members, "$1_name");
    Py_XINCREF($result);
    Py_DECREF(members);
  }

  if ($result == NULL) {
    if ($1 == NULL) {
      $result = Py_None;
      Py_INCREF($result);
    } else {
      /* We don't know the type of this reference, so we'll have to
       * treat it as an opaque void pointer.
       */
      $result = svn_swig_py_new_pointer_obj($1, $descriptor,
                                            _global_py_pool, args);
    }
  }

}

#endif

/* -----------------------------------------------------------------------
   MD5 Digest Parameters: in the Subversion C API, there are:
   - 'char' digests, which are hexadecimal-encoded strings.
   - 'unsigned char' digests, which are raw blocks of bytes.
   This section of typemaps relates to the second variety.
   The number of subtly different forms in which these appear in our
   APIs is absolutely scary, and we desperately must introduce some sanity
   when we do Subversion 2.0.

   Function Parameters (Category 1):

   'unsigned char digest[]'
   'unsigned char *digest':

     Output parameter in: svn_fs_file_md5_checksum(), svn_io_file_checksum(),
                          svn_wc_transmit_text_deltas2()

     *but* appears as an input parameter in svn_base64_from_md5() -
     practically, this means that svn_base64_from_md5 is in error, and
     should be using 'const unsigned char digest[]', but fortunately, we
     do not wrap the svn_base64_* APIs, so do not have to care here.


   (Category 2):

   There is no category 2!


   Function Parameters (No typemaps):

   'const unsigned char **read_digest' (also, 'write_digest'):
     These are *delayed* output parameters in svn_stream_checksummed().
     Would be quite complex to wrap, so this function is %ignore-d in the
     svn_io.h cherrypicking section.

   'unsigned char *result_digest'
     This parameter serves as a buffer for the digest results of
     svn_txdelta_apply. As you supply data to this function via
     the handler callback, this digest gets filled. Since
     filling of this buffer is delayed, it is quite difficult
     to wrap.

    FIXME: Both Ruby and Perl have broken typemaps for result_digest.
    The Python bindings ignore this parameter altogether.

   Function Parameters (Category 3):

   'const unsigned char digest[]' (also, 'd1', 'd2'):
   'const unsigned char *digest':
     Input parameters in:
     svn_md5_digest_to_cstring_display()
     svn_md5_digest_to_cstring()
     svn_md5_digests_match()

   Function return values (Category 4):

   'const unsigned char *' in svn_txdelta_md5_digest()
*/

/* Category 1 */

%typemap(in, numinputs=0) unsigned char digest[ANY]
  ($*1_type temp[APR_MD5_DIGESTSIZE]) "$1 = temp;";

#ifdef SWIGPYTHON
%typemap(argout) unsigned char digest[ANY]
{
  %append_output(PyBytes_FromStringAndSize((const char *)$1, APR_MD5_DIGESTSIZE));
}
#endif

#ifdef SWIGPERL
%typemap(argout) unsigned char digest[ANY] {
  %append_output(sv_2mortal(newSVpv(svn_md5_digest_to_cstring($1,
                                                              _global_pool),
                                    0)));
}
#endif
#ifdef SWIGRUBY
%typemap(argout) unsigned char digest[ANY] {
  char *digest_string = (char *)svn_md5_digest_to_cstring($1, _global_pool);
  %append_output(rb_str_new2(digest_string ? digest_string : ""));
}
#endif

%apply unsigned char digest[ANY] { unsigned char *digest };

#ifdef SWIGRUBY
/*
 * Skip the md5sum
 * FIXME: Wrap the md5sum
 */
%typemap(in, numinputs=0) unsigned char *result_digest
  "$1 = NULL;";
#endif

#ifdef SWIGPYTHON
/*
 * Skip the md5sum
 * FIXME: Wrap the md5sum
 */
%typemap(in, numinputs=0) unsigned char *result_digest
  ($*1_type temp[APR_MD5_DIGESTSIZE]) "$1 = NULL;";
#endif

#ifdef SWIGPERL
%typemap(in, numinputs=0) unsigned char *result_digest {
    $1 = (unsigned char *)apr_palloc(_global_pool, APR_MD5_DIGESTSIZE);
}

%typemap(argout) unsigned char *result_digest {
    SV *tmp;
    PUTBACK;
    tmp = svn_swig_pl_from_md5($1);
    SPAGAIN;
    %append_output(tmp);
}
#endif

/* Category 3 */

/* Override the non-const typemaps defined for category 1, which would
   otherwise apply by default, and contribute nonsensical wrappings. */
%typemap(in)     const unsigned char digest[], const unsigned char *digest "";
%typemap(argout) const unsigned char digest[], const unsigned char *digest "";

/* FIXME: There is a lot of coverage missing here */

#ifdef SWIGPERL
%typemap(in) const unsigned char digest[] {
    SWIG_ConvertPtr($input, (void **)&$1, $1_descriptor, 0);
}
#endif

#ifdef SWIGPYTHON
/* ### Verify if this should use '[]' like perl and ruby */
%typemap(in) const unsigned char *digest {
    if ($input == Py_None) {
        $1 = NULL;
    } else {
        $1 = (unsigned char *) PyBytes_AsString($input);
        if ($1 == NULL) SWIG_fail;
    }
}
#endif

#ifdef SWIGRUBY
%typemap(in) const unsigned char digest[]
{
  if (NIL_P($input)) {
    $1 = NULL;
  } else if (RSTRING_LEN($input) != APR_MD5_DIGESTSIZE) {
    rb_raise(rb_eArgError, "digest size (%d) must be %d",
             RSTRING_LEN($input), APR_MD5_DIGESTSIZE);
  } else {
    $1 = ($1_ltype)StringValuePtr($input);
  }
}
#endif

/* Category 4 */
/* FIXME: Write a typemap for category 4 */

/* -----------------------------------------------------------------------
  useful convertors for svn_opt_revision_t
*/
#ifdef SWIGPERL
%typemap(in) svn_opt_revision_t * 
  (svn_opt_revision_t rev, apr_pool_t *_global_pool = NULL)
{
  if (_global_pool == NULL) {
    _global_pool = svn_swig_pl_make_pool((SV *)NULL);
    SPAGAIN;
  }
  $1 = svn_swig_pl_set_revision(&rev, $input, TRUE, _global_pool);
}
#endif

#ifdef SWIGRUBY
%typemap(in) svn_opt_revision_t * (svn_opt_revision_t rev) {
  $1 = &rev;
  svn_swig_rb_set_revision(&rev, $input);
}
#endif

/* -----------------------------------------------------------------------
   useful convertors for svn_depth_t
*/

#ifdef SWIGRUBY
%typemap(in) svn_depth_t {
  $1 = svn_swig_rb_to_depth($input);
}
#endif


/* -----------------------------------------------------------------------
   useful convertors for svn_mergeinfo_inheritance_t
*/

#ifdef SWIGRUBY
%typemap(in) svn_mergeinfo_inheritance_t {
  $1 = svn_swig_rb_to_mergeinfo_inheritance($input);
}
#endif


/* -----------------------------------------------------------------------
   useful convertors for svn_merge_range_inheritance_t
*/

#ifdef SWIGRUBY
%typemap(in) svn_merge_range_inheritance_t {
  $1 = svn_swig_rb_to_merge_range_inheritance($input);
}
#endif


/* -----------------------------------------------------------------------
   Special boolean mapping for ruby.
*/

#ifdef SWIGRUBY
%typemap(in) svn_boolean_t "$1 = RTEST($input);";
%typemap(out) svn_boolean_t "$result = $1 ? Qtrue : Qfalse;";

%typemap(in, numinputs=0) svn_boolean_t * (svn_boolean_t temp) "$1 = &temp;";
%typemap(argout) svn_boolean_t * {
  %append_output(*$1 ? Qtrue : Qfalse);
}
#endif

/* -----------------------------------------------------------------------
   Filename to temporary file mapping for ruby.
*/

#ifdef SWIGRUBY
%typemap(argout) const char **TO_TEMP_FILE
{
  %append_output(svn_swig_rb_filename_to_temp_file(*$1));
}
#endif

/* -----------------------------------------------------------------------
   Handle python thread locking.

   Swig doesn't allow us to specify a language in the %exception command,
   so we have to use #ifdefs for the python-specific parts.
*/

%exception {
#ifdef SWIGPYTHON
    svn_swig_py_release_py_lock();
#endif
    $action
#ifdef SWIGPYTHON
    svn_swig_py_acquire_py_lock();
#endif
}