Commit 4d588d9713bb558e45a8bdf6c41d232bb592b814

Carlos Martín Nieto 2013-08-08T11:24:47

Don't typedef a pointer Make the iterator structure opaque and make sure it compiles.

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(&regex, 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;