Commit 22d2062d954dcb88fa3dc65281d3f3d88ae87d68

Edward Thomson 2019-01-09T18:25:10

Introduce GIT_CALLBACK macro to enforce cdecl Since we now always build the library with cdecl calling conventions, our callbacks should be decorated as such so that users will not be able to provide callbacks defined with other calling conventions. The `GIT_CALLBACK` macro will inject the `__cdecl` attribute as appropriate.

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
diff --git a/include/git2/apply.h b/include/git2/apply.h
index 7cc1c22..91f93d7 100644
--- a/include/git2/apply.h
+++ b/include/git2/apply.h
@@ -33,7 +33,7 @@ GIT_BEGIN_DECL
  * @param delta The delta to be applied
  * @param payload User-specified payload
  */
-typedef int (*git_apply_delta_cb)(
+typedef int GIT_CALLBACK(git_apply_delta_cb)(
 	const git_diff_delta *delta,
 	void *payload);
 
@@ -49,7 +49,7 @@ typedef int (*git_apply_delta_cb)(
  * @param hunk The hunk to be applied
  * @param payload User-specified payload
  */
-typedef int (*git_apply_hunk_cb)(
+typedef int GIT_CALLBACK(git_apply_hunk_cb)(
 	const git_diff_hunk *hunk,
 	void *payload);
 
diff --git a/include/git2/attr.h b/include/git2/attr.h
index 651454a..3752b99 100644
--- a/include/git2/attr.h
+++ b/include/git2/attr.h
@@ -202,7 +202,7 @@ GIT_EXTERN(int) git_attr_get_many(
  * @return 0 to continue looping, non-zero to stop. This value will be returned
  *         from git_attr_foreach.
  */
-typedef int (*git_attr_foreach_cb)(const char *name, const char *value, void *payload);
+typedef int GIT_CALLBACK(git_attr_foreach_cb)(const char *name, const char *value, void *payload);
 
 /**
  * Loop over all the git attributes for a path.
diff --git a/include/git2/checkout.h b/include/git2/checkout.h
index 485bae6..2953637 100644
--- a/include/git2/checkout.h
+++ b/include/git2/checkout.h
@@ -220,7 +220,7 @@ typedef struct {
 } git_checkout_perfdata;
 
 /** Checkout notification callback function */
-typedef int (*git_checkout_notify_cb)(
+typedef int GIT_CALLBACK(git_checkout_notify_cb)(
 	git_checkout_notify_t why,
 	const char *path,
 	const git_diff_file *baseline,
@@ -229,14 +229,14 @@ typedef int (*git_checkout_notify_cb)(
 	void *payload);
 
 /** Checkout progress notification function */
-typedef void (*git_checkout_progress_cb)(
+typedef void GIT_CALLBACK(git_checkout_progress_cb)(
 	const char *path,
 	size_t completed_steps,
 	size_t total_steps,
 	void *payload);
 
 /** Checkout perfdata notification function */
-typedef void (*git_checkout_perfdata_cb)(
+typedef void GIT_CALLBACK(git_checkout_perfdata_cb)(
 	const git_checkout_perfdata *perfdata,
 	void *payload);
 
diff --git a/include/git2/clone.h b/include/git2/clone.h
index 4690317..4a64aac 100644
--- a/include/git2/clone.h
+++ b/include/git2/clone.h
@@ -66,7 +66,7 @@ typedef enum {
  * @param payload an opaque payload
  * @return 0, GIT_EINVALIDSPEC, GIT_EEXISTS or an error code
  */
-typedef int (*git_remote_create_cb)(
+typedef int GIT_CALLBACK(git_remote_create_cb)(
 	git_remote **out,
 	git_repository *repo,
 	const char *name,
@@ -87,7 +87,7 @@ typedef int (*git_remote_create_cb)(
  * @param payload payload specified by the options
  * @return 0, or a negative value to indicate error
  */
-typedef int (*git_repository_create_cb)(
+typedef int GIT_CALLBACK(git_repository_create_cb)(
 	git_repository **out,
 	const char *path,
 	int bare,
diff --git a/include/git2/common.h b/include/git2/common.h
index b97f9ef..8d3d3c1 100644
--- a/include/git2/common.h
+++ b/include/git2/common.h
@@ -48,6 +48,13 @@ typedef size_t size_t;
 # define GIT_EXTERN(type) extern type
 #endif
 
+/** Declare a callback function for application use. */
+#if defined(_MSC_VER)
+# define GIT_CALLBACK(name) (__cdecl *name)
+#else
+# define GIT_CALLBACK(name) (*name)
+#endif
+
 /** Declare a function as deprecated. */
 #if defined(__GNUC__)
 # define GIT_DEPRECATED(func) \
diff --git a/include/git2/config.h b/include/git2/config.h
index f32f7af..0bea323 100644
--- a/include/git2/config.h
+++ b/include/git2/config.h
@@ -66,7 +66,7 @@ typedef struct git_config_entry {
 	const char *value; /**< String value of the entry */
 	unsigned int include_depth; /**< Depth of includes where this variable was found */
 	git_config_level_t level; /**< Which config file this was found in */
-	void (*free)(struct git_config_entry *entry); /**< Free function for this entry */
+	void GIT_CALLBACK(free)(struct git_config_entry *entry); /**< Free function for this entry */
 	void *payload; /**< Opaque value for the free function. Do not read or write */
 } git_config_entry;
 
@@ -81,7 +81,7 @@ GIT_EXTERN(void) git_config_entry_free(git_config_entry *);
  * @param entry the entry currently being enumerated
  * @param payload a user-specified pointer
  */
-typedef int  (*git_config_foreach_cb)(const git_config_entry *entry, void *payload);
+typedef int GIT_CALLBACK(git_config_foreach_cb)(const git_config_entry *entry, void *payload);
 
 /**
  * An opaque structure for a configuration iterator
diff --git a/include/git2/diff.h b/include/git2/diff.h
index b64bf20..b920385 100644
--- a/include/git2/diff.h
+++ b/include/git2/diff.h
@@ -328,7 +328,7 @@ typedef struct {
  * - returns 0, the delta is inserted into the diff, and the diff process
  *		continues.
  */
-typedef int (*git_diff_notify_cb)(
+typedef int GIT_CALLBACK(git_diff_notify_cb)(
 	const git_diff *diff_so_far,
 	const git_diff_delta *delta_to_add,
 	const char *matched_pathspec,
@@ -344,7 +344,7 @@ typedef int (*git_diff_notify_cb)(
  * @param new_path The path to the new file or NULL.
  * @return Non-zero to abort the diff.
  */
-typedef int (*git_diff_progress_cb)(
+typedef int GIT_CALLBACK(git_diff_progress_cb)(
 	const git_diff *diff_so_far,
 	const char *old_path,
 	const char *new_path,
@@ -462,7 +462,7 @@ GIT_EXTERN(int) git_diff_init_options(
  * @param progress Goes from 0 to 1 over the diff
  * @param payload User-specified pointer from foreach function
  */
-typedef int (*git_diff_file_cb)(
+typedef int GIT_CALLBACK(git_diff_file_cb)(
 	const git_diff_delta *delta,
 	float progress,
 	void *payload);
@@ -528,7 +528,7 @@ typedef struct {
  * When iterating over a diff, callback that will be made for
  * binary content within the diff.
  */
-typedef int(*git_diff_binary_cb)(
+typedef int GIT_CALLBACK(git_diff_binary_cb)(
 	const git_diff_delta *delta,
 	const git_diff_binary *binary,
 	void *payload);
@@ -554,7 +554,7 @@ typedef struct {
 /**
  * When iterating over a diff, callback that will be made per hunk.
  */
-typedef int (*git_diff_hunk_cb)(
+typedef int GIT_CALLBACK(git_diff_hunk_cb)(
 	const git_diff_delta *delta,
 	const git_diff_hunk *hunk,
 	void *payload);
@@ -615,7 +615,7 @@ typedef struct {
  * of text.  This uses some extra GIT_DIFF_LINE_... constants for output
  * of lines of file and hunk headers.
  */
-typedef int (*git_diff_line_cb)(
+typedef int GIT_CALLBACK(git_diff_line_cb)(
 	const git_diff_delta *delta, /**< delta that contains this data */
 	const git_diff_hunk *hunk,   /**< hunk containing this data */
 	const git_diff_line *line,   /**< line data */
@@ -699,14 +699,14 @@ typedef enum {
  * Pluggable similarity metric
  */
 typedef struct {
-	int (*file_signature)(
+	int GIT_CALLBACK(file_signature)(
 		void **out, const git_diff_file *file,
 		const char *fullpath, void *payload);
-	int (*buffer_signature)(
+	int GIT_CALLBACK(buffer_signature)(
 		void **out, const git_diff_file *file,
 		const char *buf, size_t buflen, void *payload);
-	void (*free_signature)(void *sig, void *payload);
-	int (*similarity)(int *score, void *siga, void *sigb, void *payload);
+	void GIT_CALLBACK(free_signature)(void *sig, void *payload);
+	int GIT_CALLBACK(similarity)(int *score, void *siga, void *sigb, void *payload);
 	void *payload;
 } git_diff_similarity_metric;
 
diff --git a/include/git2/index.h b/include/git2/index.h
index 9d73ce2..80e15c6 100644
--- a/include/git2/index.h
+++ b/include/git2/index.h
@@ -132,7 +132,7 @@ typedef enum {
 
 
 /** Callback for APIs that add/remove/update files matching pathspec */
-typedef int (*git_index_matched_path_cb)(
+typedef int GIT_CALLBACK(git_index_matched_path_cb)(
 	const char *path, const char *matched_pathspec, void *payload);
 
 /** Flags for APIs that add files matching pathspec */
diff --git a/include/git2/net.h b/include/git2/net.h
index 04dff34..391cdee 100644
--- a/include/git2/net.h
+++ b/include/git2/net.h
@@ -52,7 +52,7 @@ struct git_remote_head {
 /**
  * Callback for listing the remote heads
  */
-typedef int (*git_headlist_cb)(git_remote_head *rhead, void *payload);
+typedef int GIT_CALLBACK(git_headlist_cb)(git_remote_head *rhead, void *payload);
 
 /** @} */
 GIT_END_DECL
diff --git a/include/git2/notes.h b/include/git2/notes.h
index 853e5de..c36149e 100644
--- a/include/git2/notes.h
+++ b/include/git2/notes.h
@@ -26,7 +26,7 @@ GIT_BEGIN_DECL
  * - annotated_object_id: Oid of the git object being annotated
  * - payload: Payload data passed to `git_note_foreach`
  */
-typedef int (*git_note_foreach_cb)(
+typedef int GIT_CALLBACK(git_note_foreach_cb)(
 	const git_oid *blob_id, const git_oid *annotated_object_id, void *payload);
 
 /**
diff --git a/include/git2/odb.h b/include/git2/odb.h
index b752b90..0008eee 100644
--- a/include/git2/odb.h
+++ b/include/git2/odb.h
@@ -24,7 +24,7 @@ GIT_BEGIN_DECL
 /**
  * Function type for callbacks from git_odb_foreach.
  */
-typedef int (*git_odb_foreach_cb)(const git_oid *id, void *payload);
+typedef int GIT_CALLBACK(git_odb_foreach_cb)(const git_oid *id, void *payload);
 
 /**
  * Create a new object database with no backends.
diff --git a/include/git2/odb_backend.h b/include/git2/odb_backend.h
index 9199538..614d0d4 100644
--- a/include/git2/odb_backend.h
+++ b/include/git2/odb_backend.h
@@ -92,12 +92,12 @@ struct git_odb_stream {
 	/**
 	 * Write at most `len` bytes into `buffer` and advance the stream.
 	 */
-	int (*read)(git_odb_stream *stream, char *buffer, size_t len);
+	int GIT_CALLBACK(read)(git_odb_stream *stream, char *buffer, size_t len);
 
 	/**
 	 * Write `len` bytes from `buffer` into the stream.
 	 */
-	int (*write)(git_odb_stream *stream, const char *buffer, size_t len);
+	int GIT_CALLBACK(write)(git_odb_stream *stream, const char *buffer, size_t len);
 
 	/**
 	 * Store the contents of the stream as an object with the id
@@ -109,7 +109,7 @@ struct git_odb_stream {
 	 * - the final number of received bytes differs from the size declared
 	 *   with `git_odb_open_wstream()`
 	 */
-	int (*finalize_write)(git_odb_stream *stream, const git_oid *oid);
+	int GIT_CALLBACK(finalize_write)(git_odb_stream *stream, const git_oid *oid);
 
 	/**
 	 * Free the stream's memory.
@@ -117,16 +117,16 @@ struct git_odb_stream {
 	 * This method might be called without a call to `finalize_write` if
 	 * an error occurs or if the object is already present in the ODB.
 	 */
-	void (*free)(git_odb_stream *stream);
+	void GIT_CALLBACK(free)(git_odb_stream *stream);
 };
 
 /** A stream to write a pack file to the ODB */
 struct git_odb_writepack {
 	git_odb_backend *backend;
 
-	int (*append)(git_odb_writepack *writepack, const void *data, size_t size, git_transfer_progress *stats);
-	int (*commit)(git_odb_writepack *writepack, git_transfer_progress *stats);
-	void (*free)(git_odb_writepack *writepack);
+	int GIT_CALLBACK(append)(git_odb_writepack *writepack, const void *data, size_t size, git_transfer_progress *stats);
+	int GIT_CALLBACK(commit)(git_odb_writepack *writepack, git_transfer_progress *stats);
+	void GIT_CALLBACK(free)(git_odb_writepack *writepack);
 };
 
 GIT_END_DECL
diff --git a/include/git2/pack.h b/include/git2/pack.h
index 2dfd825..beb9f4b 100644
--- a/include/git2/pack.h
+++ b/include/git2/pack.h
@@ -178,7 +178,7 @@ GIT_EXTERN(int) git_packbuilder_write(
 */
 GIT_EXTERN(const git_oid *) git_packbuilder_hash(git_packbuilder *pb);
 
-typedef int (*git_packbuilder_foreach_cb)(void *buf, size_t size, void *payload);
+typedef int GIT_CALLBACK(git_packbuilder_foreach_cb)(void *buf, size_t size, void *payload);
 
 /**
  * Create the new pack and pass each object to the callback
@@ -207,7 +207,7 @@ GIT_EXTERN(size_t) git_packbuilder_object_count(git_packbuilder *pb);
 GIT_EXTERN(size_t) git_packbuilder_written(git_packbuilder *pb);
 
 /** Packbuilder progress notification function */
-typedef int (*git_packbuilder_progress)(
+typedef int GIT_CALLBACK(git_packbuilder_progress)(
 	int stage,
 	uint32_t current,
 	uint32_t total,
diff --git a/include/git2/refs.h b/include/git2/refs.h
index 5504c30..909edea 100644
--- a/include/git2/refs.h
+++ b/include/git2/refs.h
@@ -422,8 +422,8 @@ GIT_EXTERN(int) git_reference_remove(git_repository *repo, const char *name);
  */
 GIT_EXTERN(int) git_reference_list(git_strarray *array, git_repository *repo);
 
-typedef int (*git_reference_foreach_cb)(git_reference *reference, void *payload);
-typedef int (*git_reference_foreach_name_cb)(const char *name, void *payload);
+typedef int GIT_CALLBACK(git_reference_foreach_cb)(git_reference *reference, void *payload);
+typedef int GIT_CALLBACK(git_reference_foreach_name_cb)(const char *name, void *payload);
 
 /**
  * Perform a callback on each reference in the repository.
diff --git a/include/git2/remote.h b/include/git2/remote.h
index 3e8292f..0b6e92a 100644
--- a/include/git2/remote.h
+++ b/include/git2/remote.h
@@ -422,7 +422,7 @@ typedef enum git_remote_completion_type {
 } git_remote_completion_type;
 
 /** Push network progress notification function */
-typedef int (*git_push_transfer_progress)(
+typedef int GIT_CALLBACK(git_push_transfer_progress)(
 	unsigned int current,
 	unsigned int total,
 	size_t bytes,
@@ -457,7 +457,7 @@ typedef struct {
  * @param len number of elements in `updates`
  * @param payload Payload provided by the caller
  */
-typedef int (*git_push_negotiation)(const git_push_update **updates, size_t len, void *payload);
+typedef int GIT_CALLBACK(git_push_negotiation)(const git_push_update **updates, size_t len, void *payload);
 
 /**
  * Callback used to inform of the update status from the remote.
@@ -471,7 +471,7 @@ typedef int (*git_push_negotiation)(const git_push_update **updates, size_t len,
  * @param data data provided by the caller
  * @return 0 on success, otherwise an error
  */
-typedef int (*git_push_update_reference_cb)(const char *refname, const char *status, void *data);
+typedef int GIT_CALLBACK(git_push_update_reference_cb)(const char *refname, const char *status, void *data);
 
 /**
  * The callback settings structure
@@ -492,7 +492,7 @@ struct git_remote_callbacks {
 	 * Completion is called when different parts of the download
 	 * process are done (currently unused).
 	 */
-	int (*completion)(git_remote_completion_type type, void *data);
+	int GIT_CALLBACK(completion)(git_remote_completion_type type, void *data);
 
 	/**
 	 * This will be called if the remote host requires
@@ -522,7 +522,7 @@ struct git_remote_callbacks {
 	 * Each time a reference is updated locally, this function
 	 * will be called with information about it.
 	 */
-	int (*update_tips)(const char *refname, const git_oid *a, const git_oid *b, void *data);
+	int GIT_CALLBACK(update_tips)(const char *refname, const git_oid *a, const git_oid *b, void *data);
 
 	/**
 	 * Function to call with progress information during pack
diff --git a/include/git2/repository.h b/include/git2/repository.h
index 344c203..0386916 100644
--- a/include/git2/repository.h
+++ b/include/git2/repository.h
@@ -627,7 +627,7 @@ GIT_EXTERN(int) git_repository_message_remove(git_repository *repo);
  */
 GIT_EXTERN(int) git_repository_state_cleanup(git_repository *repo);
 
-typedef int (*git_repository_fetchhead_foreach_cb)(const char *ref_name,
+typedef int GIT_CALLBACK(git_repository_fetchhead_foreach_cb)(const char *ref_name,
 	const char *remote_url,
 	const git_oid *oid,
 	unsigned int is_merge,
@@ -649,7 +649,7 @@ GIT_EXTERN(int) git_repository_fetchhead_foreach(
 	git_repository_fetchhead_foreach_cb callback,
 	void *payload);
 
-typedef int (*git_repository_mergehead_foreach_cb)(const git_oid *oid,
+typedef int GIT_CALLBACK(git_repository_mergehead_foreach_cb)(const git_oid *oid,
 	void *payload);
 
 /**
diff --git a/include/git2/revwalk.h b/include/git2/revwalk.h
index 901570e..9cb0d0a 100644
--- a/include/git2/revwalk.h
+++ b/include/git2/revwalk.h
@@ -274,7 +274,7 @@ GIT_EXTERN(git_repository *) git_revwalk_repository(git_revwalk *walk);
  * @param commit_id oid of Commit
  * @param payload User-specified pointer to data to be passed as data payload
  */
-typedef int(*git_revwalk_hide_cb)(
+typedef int GIT_CALLBACK(git_revwalk_hide_cb)(
 	const git_oid *commit_id,
 	void *payload);
 
diff --git a/include/git2/stash.h b/include/git2/stash.h
index 1fdbeb6..c4dcf68 100644
--- a/include/git2/stash.h
+++ b/include/git2/stash.h
@@ -112,7 +112,7 @@ typedef enum {
  * Return 0 to continue processing, or a negative value to
  * abort the stash application.
  */
-typedef int (*git_stash_apply_progress_cb)(
+typedef int GIT_CALLBACK(git_stash_apply_progress_cb)(
 	git_stash_apply_progress_t progress,
 	void *payload);
 
@@ -198,7 +198,7 @@ GIT_EXTERN(int) git_stash_apply(
  * @param payload Extra parameter to callback function.
  * @return 0 to continue iterating or non-zero to stop.
  */
-typedef int (*git_stash_cb)(
+typedef int GIT_CALLBACK(git_stash_cb)(
 	size_t index,
 	const char* message,
 	const git_oid *stash_id,
diff --git a/include/git2/status.h b/include/git2/status.h
index bba0d05..06229ed 100644
--- a/include/git2/status.h
+++ b/include/git2/status.h
@@ -60,7 +60,7 @@ typedef enum {
  *
  * `payload` is the value you passed to the foreach function as payload.
  */
-typedef int (*git_status_cb)(
+typedef int GIT_CALLBACK(git_status_cb)(
 	const char *path, unsigned int status_flags, void *payload);
 
 /**
diff --git a/include/git2/submodule.h b/include/git2/submodule.h
index c5cf006..ac6344e 100644
--- a/include/git2/submodule.h
+++ b/include/git2/submodule.h
@@ -115,7 +115,7 @@ typedef enum {
  * @param payload value you passed to the foreach function as payload
  * @return 0 on success or error code
  */
-typedef int (*git_submodule_cb)(
+typedef int GIT_CALLBACK(git_submodule_cb)(
 	git_submodule *sm, const char *name, void *payload);
 
 /**
diff --git a/include/git2/sys/alloc.h b/include/git2/sys/alloc.h
index 4bc5323..642740d 100644
--- a/include/git2/sys/alloc.h
+++ b/include/git2/sys/alloc.h
@@ -22,54 +22,54 @@ GIT_BEGIN_DECL
  */
 typedef struct {
 	/* Allocate `n` bytes of memory */
-	void *(*gmalloc)(size_t n, const char *file, int line);
+	void * GIT_CALLBACK(gmalloc)(size_t n, const char *file, int line);
 
 	/*
 	 * Allocate memory for an array of `nelem` elements, where each element
 	 * has a size of `elsize`. Returned memory shall be initialized to
 	 * all-zeroes
 	 */
-	void *(*gcalloc)(size_t nelem, size_t elsize, const char *file, int line);
+	void * GIT_CALLBACK(gcalloc)(size_t nelem, size_t elsize, const char *file, int line);
 
 	/* Allocate memory for the string `str` and duplicate its contents. */
-	char *(*gstrdup)(const char *str, const char *file, int line);
+	char * GIT_CALLBACK(gstrdup)(const char *str, const char *file, int line);
 
 	/*
 	 * Equivalent to the `gstrdup` function, but only duplicating at most
 	 * `n + 1` bytes
 	 */
-	char *(*gstrndup)(const char *str, size_t n, const char *file, int line);
+	char * GIT_CALLBACK(gstrndup)(const char *str, size_t n, const char *file, int line);
 
 	/*
 	 * Equivalent to `gstrndup`, but will always duplicate exactly `n` bytes
 	 * of `str`. Thus, out of bounds reads at `str` may happen.
 	 */
-	char *(*gsubstrdup)(const char *str, size_t n, const char *file, int line);
+	char * GIT_CALLBACK(gsubstrdup)(const char *str, size_t n, const char *file, int line);
 
 	/*
 	 * This function shall deallocate the old object `ptr` and return a
 	 * pointer to a new object that has the size specified by `size`. In
 	 * case `ptr` is `NULL`, a new array shall be allocated.
 	 */
-	void *(*grealloc)(void *ptr, size_t size, const char *file, int line);
+	void * GIT_CALLBACK(grealloc)(void *ptr, size_t size, const char *file, int line);
 
 	/*
 	 * This function shall be equivalent to `grealloc`, but allocating
 	 * `neleme * elsize` bytes.
 	 */
-	void *(*greallocarray)(void *ptr, size_t nelem, size_t elsize, const char *file, int line);
+	void * GIT_CALLBACK(greallocarray)(void *ptr, size_t nelem, size_t elsize, const char *file, int line);
 
 	/*
 	 * This function shall allocate a new array of `nelem` elements, where
 	 * each element has a size of `elsize` bytes.
 	 */
-	void *(*gmallocarray)(size_t nelem, size_t elsize, const char *file, int line);
+	void * GIT_CALLBACK(gmallocarray)(size_t nelem, size_t elsize, const char *file, int line);
 
 	/*
 	 * This function shall free the memory pointed to by `ptr`. In case
 	 * `ptr` is `NULL`, this shall be a no-op.
 	 */
-	void (*gfree)(void *ptr);
+	void GIT_CALLBACK(gfree)(void *ptr);
 } git_allocator;
 
 /**
diff --git a/include/git2/sys/commit.h b/include/git2/sys/commit.h
index 627d3ae..ba67106 100644
--- a/include/git2/sys/commit.h
+++ b/include/git2/sys/commit.h
@@ -50,7 +50,7 @@ GIT_EXTERN(int) git_commit_create_from_ids(
  * along with the user supplied payload.  This should return a git_oid of
  * the next parent or NULL if all parents have been provided.
  */
-typedef const git_oid *(*git_commit_parent_callback)(size_t idx, void *payload);
+typedef const git_oid * GIT_CALLBACK(git_commit_parent_callback)(size_t idx, void *payload);
 
 /**
  * Create a new commit in the repository with an callback to supply parents.
diff --git a/include/git2/sys/config.h b/include/git2/sys/config.h
index ed20322..0a9005e 100644
--- a/include/git2/sys/config.h
+++ b/include/git2/sys/config.h
@@ -39,12 +39,12 @@ struct git_config_iterator {
 	 * Return the current entry and advance the iterator. The
 	 * memory belongs to the library.
 	 */
-	int (*next)(git_config_entry **entry, git_config_iterator *iter);
+	int GIT_CALLBACK(next)(git_config_entry **entry, git_config_iterator *iter);
 
 	/**
 	 * Free the iterator
 	 */
-	void (*free)(git_config_iterator *iter);
+	void GIT_CALLBACK(free)(git_config_iterator *iter);
 };
 
 /**
@@ -58,15 +58,15 @@ struct git_config_backend {
 	struct git_config *cfg;
 
 	/* Open means open the file/database and parse if necessary */
-	int (*open)(struct git_config_backend *, git_config_level_t level, const git_repository *repo);
-	int (*get)(struct git_config_backend *, const char *key, git_config_entry **entry);
-	int (*set)(struct git_config_backend *, const char *key, const char *value);
-	int (*set_multivar)(git_config_backend *cfg, const char *name, const char *regexp, const char *value);
-	int (*del)(struct git_config_backend *, const char *key);
-	int (*del_multivar)(struct git_config_backend *, const char *key, const char *regexp);
-	int (*iterator)(git_config_iterator **, struct git_config_backend *);
+	int GIT_CALLBACK(open)(struct git_config_backend *, git_config_level_t level, const git_repository *repo);
+	int GIT_CALLBACK(get)(struct git_config_backend *, const char *key, git_config_entry **entry);
+	int GIT_CALLBACK(set)(struct git_config_backend *, const char *key, const char *value);
+	int GIT_CALLBACK(set_multivar)(git_config_backend *cfg, const char *name, const char *regexp, const char *value);
+	int GIT_CALLBACK(del)(struct git_config_backend *, const char *key);
+	int GIT_CALLBACK(del_multivar)(struct git_config_backend *, const char *key, const char *regexp);
+	int GIT_CALLBACK(iterator)(git_config_iterator **, struct git_config_backend *);
 	/** Produce a read-only version of this backend */
-	int (*snapshot)(struct git_config_backend **, struct git_config_backend *);
+	int GIT_CALLBACK(snapshot)(struct git_config_backend **, struct git_config_backend *);
 	/**
 	 * Lock this backend.
 	 *
@@ -74,14 +74,14 @@ struct git_config_backend {
 	 * backend. Any updates must not be visible to any other
 	 * readers.
 	 */
-	int (*lock)(struct git_config_backend *);
+	int GIT_CALLBACK(lock)(struct git_config_backend *);
 	/**
 	 * Unlock the data store backing this backend. If success is
 	 * true, the changes should be committed, otherwise rolled
 	 * back.
 	 */
-	int (*unlock)(struct git_config_backend *, int success);
-	void (*free)(struct git_config_backend *);
+	int GIT_CALLBACK(unlock)(struct git_config_backend *, int success);
+	void GIT_CALLBACK(free)(struct git_config_backend *);
 };
 #define GIT_CONFIG_BACKEND_VERSION 1
 #define GIT_CONFIG_BACKEND_INIT {GIT_CONFIG_BACKEND_VERSION}
diff --git a/include/git2/sys/filter.h b/include/git2/sys/filter.h
index 6d575d4..e43fde5 100644
--- a/include/git2/sys/filter.h
+++ b/include/git2/sys/filter.h
@@ -138,7 +138,7 @@ GIT_EXTERN(uint32_t) git_filter_source_flags(const git_filter_source *src);
  * initialization operations (in case libgit2 is being used in a way that
  * doesn't need the filter).
  */
-typedef int (*git_filter_init_fn)(git_filter *self);
+typedef int GIT_CALLBACK(git_filter_init_fn)(git_filter *self);
 
 /**
  * Shutdown callback on filter
@@ -150,7 +150,7 @@ typedef int (*git_filter_init_fn)(git_filter *self);
  *
  * Typically this function will free the `git_filter` object itself.
  */
-typedef void (*git_filter_shutdown_fn)(git_filter *self);
+typedef void GIT_CALLBACK(git_filter_shutdown_fn)(git_filter *self);
 
 /**
  * Callback to decide if a given source needs this filter
@@ -172,7 +172,7 @@ typedef void (*git_filter_shutdown_fn)(git_filter *self);
  * callback can use it.  If a filter allocates and assigns a value to the
  * `payload`, it will need a `cleanup` callback to free the payload.
  */
-typedef int (*git_filter_check_fn)(
+typedef int GIT_CALLBACK(git_filter_check_fn)(
 	git_filter  *self,
 	void       **payload, /* points to NULL ptr on entry, may be set */
 	const git_filter_source *src,
@@ -190,14 +190,14 @@ typedef int (*git_filter_check_fn)(
  * The `payload` value will refer to any payload that was set by the
  * `check` callback.  It may be read from or written to as needed.
  */
-typedef int (*git_filter_apply_fn)(
+typedef int GIT_CALLBACK(git_filter_apply_fn)(
 	git_filter    *self,
 	void         **payload, /* may be read and/or set */
 	git_buf       *to,
 	const git_buf *from,
 	const git_filter_source *src);
 
-typedef int (*git_filter_stream_fn)(
+typedef int GIT_CALLBACK(git_filter_stream_fn)(
 	git_writestream **out,
 	git_filter *self,
 	void **payload,
@@ -212,7 +212,7 @@ typedef int (*git_filter_stream_fn)(
  * allocated a `payload` to keep per-source filter state, use this
  * callback to free that payload and release resources as required.
  */
-typedef void (*git_filter_cleanup_fn)(
+typedef void GIT_CALLBACK(git_filter_cleanup_fn)(
 	git_filter *self,
 	void       *payload);
 
diff --git a/include/git2/sys/merge.h b/include/git2/sys/merge.h
index f07997d..bd0a8a4 100644
--- a/include/git2/sys/merge.h
+++ b/include/git2/sys/merge.h
@@ -73,7 +73,7 @@ GIT_EXTERN(const git_merge_file_options *) git_merge_driver_source_file_options(
  * initialization operations (in case libgit2 is being used in a way that
  * doesn't need the merge driver).
  */
-typedef int (*git_merge_driver_init_fn)(git_merge_driver *self);
+typedef int GIT_CALLBACK(git_merge_driver_init_fn)(git_merge_driver *self);
 
 /**
  * Shutdown callback on merge driver
@@ -85,7 +85,7 @@ typedef int (*git_merge_driver_init_fn)(git_merge_driver *self);
  *
  * Typically this function will free the `git_merge_driver` object itself.
  */
-typedef void (*git_merge_driver_shutdown_fn)(git_merge_driver *self);
+typedef void GIT_CALLBACK(git_merge_driver_shutdown_fn)(git_merge_driver *self);
 
 /**
  * Callback to perform the merge.
@@ -105,7 +105,7 @@ typedef void (*git_merge_driver_shutdown_fn)(git_merge_driver *self);
  *
  * The `src` contains the data about the file to be merged.
  */
-typedef int (*git_merge_driver_apply_fn)(
+typedef int GIT_CALLBACK(git_merge_driver_apply_fn)(
 	git_merge_driver *self,
 	const char **path_out,
 	uint32_t *mode_out,
diff --git a/include/git2/sys/odb_backend.h b/include/git2/sys/odb_backend.h
index 75341e8..1a74757 100644
--- a/include/git2/sys/odb_backend.h
+++ b/include/git2/sys/odb_backend.h
@@ -32,37 +32,37 @@ struct git_odb_backend {
 	 * will be freed later. The buffer should be allocated using
 	 * the function git_odb_backend_malloc to ensure that it can
 	 * be safely freed later. */
-	int (* read)(
+	int GIT_CALLBACK(read)(
 		void **, size_t *, git_object_t *, git_odb_backend *, const git_oid *);
 
 	/* To find a unique object given a prefix of its oid.  The oid given
 	 * must be so that the remaining (GIT_OID_HEXSZ - len)*4 bits are 0s.
 	 */
-	int (* read_prefix)(
+	int GIT_CALLBACK(read_prefix)(
 		git_oid *, void **, size_t *, git_object_t *,
 		git_odb_backend *, const git_oid *, size_t);
 
-	int (* read_header)(
+	int GIT_CALLBACK(read_header)(
 		size_t *, git_object_t *, git_odb_backend *, const git_oid *);
 
 	/**
 	 * Write an object into the backend. The id of the object has
 	 * already been calculated and is passed in.
 	 */
-	int (* write)(
+	int GIT_CALLBACK(write)(
 		git_odb_backend *, const git_oid *, const void *, size_t, git_object_t);
 
-	int (* writestream)(
+	int GIT_CALLBACK(writestream)(
 		git_odb_stream **, git_odb_backend *, git_off_t, git_object_t);
 
-	int (* readstream)(
+	int GIT_CALLBACK(readstream)(
 		git_odb_stream **, size_t *, git_object_t *,
 		git_odb_backend *, const git_oid *);
 
-	int (* exists)(
+	int GIT_CALLBACK(exists)(
 		git_odb_backend *, const git_oid *);
 
-	int (* exists_prefix)(
+	int GIT_CALLBACK(exists_prefix)(
 		git_oid *, git_odb_backend *, const git_oid *, size_t);
 
 	/**
@@ -75,12 +75,12 @@ struct git_odb_backend {
 	 * implementation to achieve this could be to internally invoke this
 	 * endpoint on failed lookups (ie. `exists()`, `read()`, `read_header()`).
 	 */
-	int (* refresh)(git_odb_backend *);
+	int GIT_CALLBACK(refresh)(git_odb_backend *);
 
-	int (* foreach)(
+	int GIT_CALLBACK(foreach)(
 		git_odb_backend *, git_odb_foreach_cb cb, void *payload);
 
-	int (* writepack)(
+	int GIT_CALLBACK(writepack)(
 		git_odb_writepack **, git_odb_backend *, git_odb *odb,
 		git_transfer_progress_cb progress_cb, void *progress_payload);
 
@@ -93,13 +93,13 @@ struct git_odb_backend {
 	 * If callers implement this, they should return `0` if the object
 	 * exists and was freshened, and non-zero otherwise.
 	 */
-	int (* freshen)(git_odb_backend *, const git_oid *);
+	int GIT_CALLBACK(freshen)(git_odb_backend *, const git_oid *);
 
 	/**
 	 * Frees any resources held by the odb (including the `git_odb_backend`
 	 * itself). An odb backend implementation must provide this function.
 	 */
-	void (* free)(git_odb_backend *);
+	void GIT_CALLBACK(free)(git_odb_backend *);
 };
 
 #define GIT_ODB_BACKEND_VERSION 1
diff --git a/include/git2/sys/refdb_backend.h b/include/git2/sys/refdb_backend.h
index 5129ad8..2ed6efd 100644
--- a/include/git2/sys/refdb_backend.h
+++ b/include/git2/sys/refdb_backend.h
@@ -38,21 +38,21 @@ struct git_reference_iterator {
 	/**
 	 * Return the current reference and advance the iterator.
 	 */
-	int (*next)(
+	int GIT_CALLBACK(next)(
 		git_reference **ref,
 		git_reference_iterator *iter);
 
 	/**
 	 * Return the name of the current reference and advance the iterator
 	 */
-	int (*next_name)(
+	int GIT_CALLBACK(next_name)(
 		const char **ref_name,
 		git_reference_iterator *iter);
 
 	/**
 	 * Free the iterator
 	 */
-	void (*free)(
+	void GIT_CALLBACK(free)(
 		git_reference_iterator *iter);
 };
 
@@ -64,7 +64,7 @@ struct git_refdb_backend {
 	 * Queries the refdb backend to determine if the given ref_name
 	 * exists.  A refdb implementation must provide this function.
 	 */
-	int (*exists)(
+	int GIT_CALLBACK(exists)(
 		int *exists,
 		git_refdb_backend *backend,
 		const char *ref_name);
@@ -73,7 +73,7 @@ struct git_refdb_backend {
 	 * Queries the refdb backend for a given reference.  A refdb
 	 * implementation must provide this function.
 	 */
-	int (*lookup)(
+	int GIT_CALLBACK(lookup)(
 		git_reference **out,
 		git_refdb_backend *backend,
 		const char *ref_name);
@@ -83,7 +83,7 @@ struct git_refdb_backend {
 	 *
 	 * A refdb implementation must provide this function.
 	 */
-	int (*iterator)(
+	int GIT_CALLBACK(iterator)(
 		git_reference_iterator **iter,
 		struct git_refdb_backend *backend,
 		const char *glob);
@@ -92,12 +92,12 @@ struct git_refdb_backend {
 	 * Writes the given reference to the refdb.  A refdb implementation
 	 * must provide this function.
 	 */
-	int (*write)(git_refdb_backend *backend,
+	int GIT_CALLBACK(write)(git_refdb_backend *backend,
 		     const git_reference *ref, int force,
 		     const git_signature *who, const char *message,
 		     const git_oid *old, const char *old_target);
 
-	int (*rename)(
+	int GIT_CALLBACK(rename)(
 		git_reference **out, git_refdb_backend *backend,
 		const char *old_name, const char *new_name, int force,
 		const git_signature *who, const char *message);
@@ -107,7 +107,7 @@ struct git_refdb_backend {
 	 * from the refdb.  A refdb implementation must provide this
 	 * function.
 	 */
-	int (*del)(git_refdb_backend *backend, const char *ref_name, const git_oid *old_id, const char *old_target);
+	int GIT_CALLBACK(del)(git_refdb_backend *backend, const char *ref_name, const git_oid *old_id, const char *old_target);
 
 	/**
 	 * Suggests that the given refdb compress or optimize its references.
@@ -116,56 +116,56 @@ struct git_refdb_backend {
 	 * implementation may provide this function; if it is not provided,
 	 * nothing will be done.
 	 */
-	int (*compress)(git_refdb_backend *backend);
+	int GIT_CALLBACK(compress)(git_refdb_backend *backend);
 
 	/**
 	 * Query whether a particular reference has a log (may be empty)
 	 */
-	int (*has_log)(git_refdb_backend *backend, const char *refname);
+	int GIT_CALLBACK(has_log)(git_refdb_backend *backend, const char *refname);
 
 	/**
 	 * Make sure a particular reference will have a reflog which
 	 * will be appended to on writes.
 	 */
-	int (*ensure_log)(git_refdb_backend *backend, const char *refname);
+	int GIT_CALLBACK(ensure_log)(git_refdb_backend *backend, const char *refname);
 
 	/**
 	 * Frees any resources held by the refdb (including the `git_refdb_backend`
 	 * itself). A refdb backend implementation must provide this function.
 	 */
-	void (*free)(git_refdb_backend *backend);
+	void GIT_CALLBACK(free)(git_refdb_backend *backend);
 
 	/**
 	 * Read the reflog for the given reference name.
 	 */
-	int (*reflog_read)(git_reflog **out, git_refdb_backend *backend, const char *name);
+	int GIT_CALLBACK(reflog_read)(git_reflog **out, git_refdb_backend *backend, const char *name);
 
 	/**
 	 * Write a reflog to disk.
 	 */
-	int (*reflog_write)(git_refdb_backend *backend, git_reflog *reflog);
+	int GIT_CALLBACK(reflog_write)(git_refdb_backend *backend, git_reflog *reflog);
 
 	/**
 	 * Rename a reflog
 	 */
-	int (*reflog_rename)(git_refdb_backend *_backend, const char *old_name, const char *new_name);
+	int GIT_CALLBACK(reflog_rename)(git_refdb_backend *_backend, const char *old_name, const char *new_name);
 
 	/**
 	 * Remove a reflog.
 	 */
-	int (*reflog_delete)(git_refdb_backend *backend, const char *name);
+	int GIT_CALLBACK(reflog_delete)(git_refdb_backend *backend, const char *name);
 
 	/**
 	 * Lock a reference. The opaque parameter will be passed to the unlock function
 	 */
-	int (*lock)(void **payload_out, git_refdb_backend *backend, const char *refname);
+	int GIT_CALLBACK(lock)(void **payload_out, git_refdb_backend *backend, const char *refname);
 
 	/**
 	 * Unlock a reference. Only one of target or symbolic_target
 	 * will be set. success indicates whether to update the
 	 * reference or discard the lock (if it's false)
 	 */
-	int (*unlock)(git_refdb_backend *backend, void *payload, int success, int update_reflog,
+	int GIT_CALLBACK(unlock)(git_refdb_backend *backend, void *payload, int success, int update_reflog,
 		      const git_reference *ref, const git_signature *sig, const char *message);
 };
 
diff --git a/include/git2/sys/stream.h b/include/git2/sys/stream.h
index 9387931..255c93e 100644
--- a/include/git2/sys/stream.h
+++ b/include/git2/sys/stream.h
@@ -31,13 +31,13 @@ typedef struct git_stream {
 
 	int encrypted;
 	int proxy_support;
-	int (*connect)(struct git_stream *);
-	int (*certificate)(git_cert **, struct git_stream *);
-	int (*set_proxy)(struct git_stream *, const git_proxy_options *proxy_opts);
-	ssize_t (*read)(struct git_stream *, void *, size_t);
-	ssize_t (*write)(struct git_stream *, const char *, size_t, int);
-	int (*close)(struct git_stream *);
-	void (*free)(struct git_stream *);
+	int GIT_CALLBACK(connect)(struct git_stream *);
+	int GIT_CALLBACK(certificate)(git_cert **, struct git_stream *);
+	int GIT_CALLBACK(set_proxy)(struct git_stream *, const git_proxy_options *proxy_opts);
+	ssize_t GIT_CALLBACK(read)(struct git_stream *, void *, size_t);
+	ssize_t GIT_CALLBACK(write)(struct git_stream *, const char *, size_t, int);
+	int GIT_CALLBACK(close)(struct git_stream *);
+	void GIT_CALLBACK(free)(struct git_stream *);
 } git_stream;
 
 typedef struct {
@@ -54,7 +54,7 @@ typedef struct {
 	 *             service name
 	 * @return 0 or an error code
 	 */
-	int (*init)(git_stream **out, const char *host, const char *port);
+	int GIT_CALLBACK(init)(git_stream **out, const char *host, const char *port);
 
 	/**
 	 * Called to create a new connection on top of the given stream.  If
@@ -68,7 +68,7 @@ typedef struct {
 	 *             for certificate validation
 	 * @return 0 or an error code
 	 */
-	int (*wrap)(git_stream **out, git_stream *in, const char *host);
+	int GIT_CALLBACK(wrap)(git_stream **out, git_stream *in, const char *host);
 } git_stream_registration;
 
 /**
@@ -111,7 +111,7 @@ GIT_EXTERN(int) git_stream_register(
  * @deprecated Provide a git_stream_registration to git_stream_register
  * @see git_stream_registration
  */
-typedef int (*git_stream_cb)(git_stream **out, const char *host, const char *port);
+typedef int GIT_CALLBACK(git_stream_cb)(git_stream **out, const char *host, const char *port);
 
 /**
  * Register a TLS stream constructor for the library to use.  This stream
diff --git a/include/git2/sys/transport.h b/include/git2/sys/transport.h
index aac6f9f..92cb32b 100644
--- a/include/git2/sys/transport.h
+++ b/include/git2/sys/transport.h
@@ -35,7 +35,7 @@ typedef enum {
 struct git_transport {
 	unsigned int version;
 	/* Set progress and error callbacks */
-	int (*set_callbacks)(
+	int GIT_CALLBACK(set_callbacks)(
 		git_transport *transport,
 		git_transport_message_cb progress_cb,
 		git_transport_message_cb error_cb,
@@ -43,13 +43,13 @@ struct git_transport {
 		void *payload);
 
 	/* Set custom headers for HTTP requests */
-	int (*set_custom_headers)(
+	int GIT_CALLBACK(set_custom_headers)(
 		git_transport *transport,
 		const git_strarray *custom_headers);
 
 	/* Connect the transport to the remote repository, using the given
 	 * direction. */
-	int (*connect)(
+	int GIT_CALLBACK(connect)(
 		git_transport *transport,
 		const char *url,
 		git_cred_acquire_cb cred_acquire_cb,
@@ -61,18 +61,18 @@ struct git_transport {
 	/* This function may be called after a successful call to
 	 * connect(). The array returned is owned by the transport and
 	 * is guaranteed until the next call of a transport function. */
-	int (*ls)(
+	int GIT_CALLBACK(ls)(
 		const git_remote_head ***out,
 		size_t *size,
 		git_transport *transport);
 
 	/* Executes the push whose context is in the git_push object. */
-	int(*push)(git_transport *transport, git_push *push, const git_remote_callbacks *callbacks);
+	int GIT_CALLBACK(push)(git_transport *transport, git_push *push, const git_remote_callbacks *callbacks);
 
 	/* This function may be called after a successful call to connect(), when
 	 * the direction is FETCH. The function performs a negotiation to calculate
 	 * the wants list for the fetch. */
-	int (*negotiate_fetch)(
+	int GIT_CALLBACK(negotiate_fetch)(
 		git_transport *transport,
 		git_repository *repo,
 		const git_remote_head * const *refs,
@@ -81,7 +81,7 @@ struct git_transport {
 	/* This function may be called after a successful call to negotiate_fetch(),
 	 * when the direction is FETCH. This function retrieves the pack file for
 	 * the fetch from the remote end. */
-	int (*download_pack)(
+	int GIT_CALLBACK(download_pack)(
 		git_transport *transport,
 		git_repository *repo,
 		git_transfer_progress *stats,
@@ -89,20 +89,20 @@ struct git_transport {
 		void *progress_payload);
 
 	/* Checks to see if the transport is connected */
-	int (*is_connected)(git_transport *transport);
+	int GIT_CALLBACK(is_connected)(git_transport *transport);
 
 	/* Reads the flags value previously passed into connect() */
-	int (*read_flags)(git_transport *transport, int *flags);
+	int GIT_CALLBACK(read_flags)(git_transport *transport, int *flags);
 
 	/* Cancels any outstanding transport operation */
-	void (*cancel)(git_transport *transport);
+	void GIT_CALLBACK(cancel)(git_transport *transport);
 
 	/* This function is the reverse of connect() -- it terminates the
 	 * connection to the remote end. */
-	int (*close)(git_transport *transport);
+	int GIT_CALLBACK(close)(git_transport *transport);
 
 	/* Frees/destructs the git_transport object. */
-	void (*free)(git_transport *transport);
+	void GIT_CALLBACK(free)(git_transport *transport);
 };
 
 #define GIT_TRANSPORT_VERSION 1
@@ -292,25 +292,25 @@ struct git_smart_subtransport_stream {
 	/* The owning subtransport */
 	git_smart_subtransport *subtransport;
 
-	int (*read)(
+	int GIT_CALLBACK(read)(
 		git_smart_subtransport_stream *stream,
 		char *buffer,
 		size_t buf_size,
 		size_t *bytes_read);
 
-	int (*write)(
+	int GIT_CALLBACK(write)(
 		git_smart_subtransport_stream *stream,
 		const char *buffer,
 		size_t len);
 
-	void (*free)(
+	void GIT_CALLBACK(free)(
 		git_smart_subtransport_stream *stream);
 };
 
 /* An implementation of a subtransport which carries data for the
  * smart transport */
 struct git_smart_subtransport {
-	int (* action)(
+	int GIT_CALLBACK(action)(
 			git_smart_subtransport_stream **out,
 			git_smart_subtransport *transport,
 			const char *url,
@@ -322,13 +322,13 @@ struct git_smart_subtransport {
 	 *
 	 * 1. UPLOADPACK_LS -> UPLOADPACK
 	 * 2. RECEIVEPACK_LS -> RECEIVEPACK */
-	int (*close)(git_smart_subtransport *transport);
+	int GIT_CALLBACK(close)(git_smart_subtransport *transport);
 
-	void (*free)(git_smart_subtransport *transport);
+	void GIT_CALLBACK(free)(git_smart_subtransport *transport);
 };
 
 /* A function which creates a new subtransport for the smart transport */
-typedef int (*git_smart_subtransport_cb)(
+typedef int GIT_CALLBACK(git_smart_subtransport_cb)(
 	git_smart_subtransport **out,
 	git_transport* owner,
 	void* param);
diff --git a/include/git2/tag.h b/include/git2/tag.h
index 12683e4..1ca3348 100644
--- a/include/git2/tag.h
+++ b/include/git2/tag.h
@@ -318,7 +318,7 @@ GIT_EXTERN(int) git_tag_list_match(
 	git_repository *repo);
 
 
-typedef int (*git_tag_foreach_cb)(const char *name, git_oid *oid, void *payload);
+typedef int GIT_CALLBACK(git_tag_foreach_cb)(const char *name, git_oid *oid, void *payload);
 
 /**
  * Call callback `cb' for each tag in the repository
diff --git a/include/git2/trace.h b/include/git2/trace.h
index f9b4d6f..f8bbfb2 100644
--- a/include/git2/trace.h
+++ b/include/git2/trace.h
@@ -49,7 +49,7 @@ typedef enum {
 /**
  * An instance for a tracing function
  */
-typedef void (*git_trace_callback)(git_trace_level_t level, const char *msg);
+typedef void GIT_CALLBACK(git_trace_callback)(git_trace_level_t level, const char *msg);
 
 /**
  * Sets the system tracing configuration to the specified level with the
diff --git a/include/git2/transport.h b/include/git2/transport.h
index 9264251..2ba2d7e 100644
--- a/include/git2/transport.h
+++ b/include/git2/transport.h
@@ -21,7 +21,7 @@
 GIT_BEGIN_DECL
 
 /** Signature of a function which creates a transport */
-typedef int (*git_transport_cb)(git_transport **out, git_remote *owner, void *param);
+typedef int GIT_CALLBACK(git_transport_cb)(git_transport **out, git_remote *owner, void *param);
 
 /**
  * Type of SSH host fingerprint
@@ -144,7 +144,7 @@ typedef struct git_cred git_cred;
  */
 struct git_cred {
 	git_credtype_t credtype; /**< A type of credential */
-	void (*free)(git_cred *cred);
+	void GIT_CALLBACK(free)(git_cred *cred);
 };
 
 /** A plaintext username and password */
@@ -165,8 +165,8 @@ typedef struct _LIBSSH2_USERAUTH_KBDINT_PROMPT LIBSSH2_USERAUTH_KBDINT_PROMPT;
 typedef struct _LIBSSH2_USERAUTH_KBDINT_RESPONSE LIBSSH2_USERAUTH_KBDINT_RESPONSE;
 #endif
 
-typedef int (*git_cred_sign_callback)(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, const unsigned char *data, size_t data_len, void **abstract);
-typedef void (*git_cred_ssh_interactive_callback)(const char* name, int name_len, const char* instruction, int instruction_len, int num_prompts, const LIBSSH2_USERAUTH_KBDINT_PROMPT* prompts, LIBSSH2_USERAUTH_KBDINT_RESPONSE* responses, void **abstract);
+typedef int GIT_CALLBACK(git_cred_sign_callback)(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, const unsigned char *data, size_t data_len, void **abstract);
+typedef void GIT_CALLBACK(git_cred_ssh_interactive_callback)(const char* name, int name_len, const char* instruction, int instruction_len, int num_prompts, const LIBSSH2_USERAUTH_KBDINT_PROMPT* prompts, LIBSSH2_USERAUTH_KBDINT_RESPONSE* responses, void **abstract);
 
 /**
  * A ssh key from disk
@@ -359,7 +359,7 @@ GIT_EXTERN(void) git_cred_free(git_cred *cred);
  * @return 0 for success, < 0 to indicate an error, > 0 to indicate
  *       no credential was acquired
  */
-typedef int (*git_cred_acquire_cb)(
+typedef int GIT_CALLBACK(git_cred_acquire_cb)(
 	git_cred **cred,
 	const char *url,
 	const char *username_from_url,
diff --git a/include/git2/tree.h b/include/git2/tree.h
index e98a4c6..aca5d75 100644
--- a/include/git2/tree.h
+++ b/include/git2/tree.h
@@ -344,7 +344,7 @@ GIT_EXTERN(int) git_treebuilder_remove(
  * entry should be left alone and any non-zero value meaning that the
  * entry should be removed from the treebuilder list (i.e. filtered out).
  */
-typedef int (*git_treebuilder_filter_cb)(
+typedef int GIT_CALLBACK(git_treebuilder_filter_cb)(
 	const git_tree_entry *entry, void *payload);
 
 /**
@@ -391,7 +391,7 @@ GIT_EXTERN(int) git_treebuilder_write_with_buffer(
 	git_oid *oid, git_treebuilder *bld, git_buf *tree);
 
 /** Callback for the tree traversal method */
-typedef int (*git_treewalk_cb)(
+typedef int GIT_CALLBACK(git_treewalk_cb)(
 	const char *root, const git_tree_entry *entry, void *payload);
 
 /** Tree traversal modes */
diff --git a/include/git2/types.h b/include/git2/types.h
index 2074ca9..a9c2865 100644
--- a/include/git2/types.h
+++ b/include/git2/types.h
@@ -272,7 +272,7 @@ typedef struct git_transfer_progress {
  * @param stats Structure containing information about the state of the transfer
  * @param payload Payload provided by caller
  */
-typedef int (*git_transfer_progress_cb)(const git_transfer_progress *stats, void *payload);
+typedef int GIT_CALLBACK(git_transfer_progress_cb)(const git_transfer_progress *stats, void *payload);
 
 /**
  * Type for messages delivered by the transport.  Return a negative value
@@ -282,7 +282,7 @@ typedef int (*git_transfer_progress_cb)(const git_transfer_progress *stats, void
  * @param len The length of the message
  * @param payload Payload provided by the caller
  */
-typedef int (*git_transport_message_cb)(const char *str, int len, void *payload);
+typedef int GIT_CALLBACK(git_transport_message_cb)(const char *str, int len, void *payload);
 
 
 /**
@@ -335,7 +335,7 @@ typedef struct {
  *         or > 0 to indicate that the callback refused to act and that
  *         the existing validity determination should be honored
  */
-typedef int (*git_transport_certificate_check_cb)(git_cert *cert, int valid, const char *host, void *payload);
+typedef int GIT_CALLBACK(git_transport_certificate_check_cb)(git_cert *cert, int valid, const char *host, void *payload);
 
 /**
  * Opaque structure representing a submodule.
@@ -433,9 +433,9 @@ typedef struct git_writestream git_writestream;
 
 /** A type to write in a streaming fashion, for example, for filters. */
 struct git_writestream {
-	int (*write)(git_writestream *stream, const char *buffer, size_t len);
-	int (*close)(git_writestream *stream);
-	void (*free)(git_writestream *stream);
+	int GIT_CALLBACK(write)(git_writestream *stream, const char *buffer, size_t len);
+	int GIT_CALLBACK(close)(git_writestream *stream);
+	void GIT_CALLBACK(free)(git_writestream *stream);
 };
 
 /** Representation of .mailmap file state. */