Don't typedef a pointer Make the iterator structure opaque and make sure it compiles.
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
diff --git a/include/git2/config.h b/include/git2/config.h
index f6fc74e..43bc194 100644
--- a/include/git2/config.h
+++ b/include/git2/config.h
@@ -61,7 +61,7 @@ typedef struct {
} git_config_entry;
typedef int (*git_config_foreach_cb)(const git_config_entry *, void *);
-typedef struct git_config_backend_iter* git_config_backend_iter;
+typedef struct git_config_backend_iter git_config_backend_iter;
typedef enum {
GIT_CVAR_FALSE = 0,
diff --git a/include/git2/sys/config.h b/include/git2/sys/config.h
index 61dcce5..f617623 100644
--- a/include/git2/sys/config.h
+++ b/include/git2/sys/config.h
@@ -37,7 +37,7 @@ struct git_config_backend {
int (*del)(struct git_config_backend *, const char *key);
int (*iterator_new)(git_config_backend_iter **, struct git_config_backend *);
void (*iterator_free)(git_config_backend_iter *);
- int (*next)(git_config_backend_iter *, git_config_entry *, struct git_config_backend *);
+ int (*next)(git_config_entry *, git_config_backend_iter *);
int (*refresh)(struct git_config_backend *);
void (*free)(struct git_config_backend *);
};
diff --git a/src/config.c b/src/config.c
index b421b3b..2f800a8 100644
--- a/src/config.c
+++ b/src/config.c
@@ -328,7 +328,7 @@ int git_config_backend_foreach_match(
void *data)
{
git_config_entry entry;
- git_config_backend_iter iter;
+ git_config_backend_iter* iter;
regex_t regex;
int result = 0;
@@ -343,7 +343,7 @@ int git_config_backend_foreach_match(
if (backend->iterator_new(&iter, backend) < 0)
return 0;
- while(!(backend->next(&iter, &entry, backend) < 0)) {
+ while(!(backend->next(&entry, iter) < 0)) {
/* skip non-matching keys if regexp was provided */
if (regexp && regexec(®ex, entry.name, 0, NULL, 0) != 0)
continue;
diff --git a/src/config.h b/src/config.h
index c5c11ae..ea150e9 100644
--- a/src/config.h
+++ b/src/config.h
@@ -24,6 +24,11 @@ struct git_config {
git_vector files;
};
+typedef struct {
+ git_config_backend *backend;
+ unsigned int flags;
+} git_config_backend_iter;
+
extern int git_config_find_global_r(git_buf *global_config_path);
extern int git_config_find_xdg_r(git_buf *system_config_path);
extern int git_config_find_system_r(git_buf *system_config_path);
diff --git a/src/config_file.c b/src/config_file.c
index ff8f8fc..ea571e9 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -28,6 +28,8 @@ typedef struct cvar_t {
} cvar_t;
typedef struct git_config_file_iter {
+ git_config_backend *backend;
+ unsigned int flags;
git_strmap_iter iter;
cvar_t* next;
} git_config_file_iter;
@@ -254,7 +256,7 @@ static void backend_free(git_config_backend *_backend)
}
static int config_iterator_new(
- git_config_backend_iter *iter,
+ git_config_backend_iter **iter,
struct git_config_backend* backend)
{
diskfile_backend *b = (diskfile_backend *)backend;
@@ -266,6 +268,7 @@ static int config_iterator_new(
*it = git__calloc(1, sizeof(git_config_file_iter));
GITERR_CHECK_ALLOC(it);
+ (*it)->backend = backend;
(*it)->iter = git_strmap_begin(b->values);
(*it)->next = NULL;
@@ -273,18 +276,17 @@ static int config_iterator_new(
}
static void config_iterator_free(
- git_config_backend_iter iter)
+ git_config_backend_iter* iter)
{
git__free(iter);
}
-static int config_next(
- git_config_backend_iter *iter,
- git_config_entry* entry,
- struct git_config_backend* backend)
+static int config_iterator_next(
+ git_config_entry *entry,
+ git_config_backend_iter *iter)
{
- diskfile_backend *b = (diskfile_backend *)backend;
git_config_file_iter *it = *((git_config_file_iter**) iter);
+ diskfile_backend *b = (diskfile_backend *)it->backend;
int err;
cvar_t * var;
const char* key;
@@ -611,7 +613,7 @@ int git_config_file__ondisk(git_config_backend **out, const char *path)
backend->parent.del = config_delete;
backend->parent.iterator_new = config_iterator_new;
backend->parent.iterator_free = config_iterator_free;
- backend->parent.next = config_next;
+ backend->parent.next = config_iterator_next;
backend->parent.refresh = config_refresh;
backend->parent.free = backend_free;