config_file: pass reader directly to callbacks Previously, the callbacks passed to `config_parse` got the reader via a pointer to a pointer. This allowed the callbacks to update the callers `reader` variable when the array holding it has been reallocated. As the array is no longer present, we can simply the code by making the reader a simple pointer.
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
diff --git a/src/config_file.c b/src/config_file.c
index 91ed353..32bce1e 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -1507,10 +1507,10 @@ on_error:
static int config_parse(
struct reader *reader,
- int (*on_section)(struct reader **reader, const char *current_section, const char *line, size_t line_len, void *data),
- int (*on_variable)(struct reader **reader, const char *current_section, char *var_name, char *var_value, const char *line, size_t line_len, void *data),
- int (*on_comment)(struct reader **reader, const char *line, size_t line_len, void *data),
- int (*on_eof)(struct reader **reader, const char *current_section, void *data),
+ int (*on_section)(struct reader *reader, const char *current_section, const char *line, size_t line_len, void *data),
+ int (*on_variable)(struct reader *reader, const char *current_section, char *var_name, char *var_value, const char *line, size_t line_len, void *data),
+ int (*on_comment)(struct reader *reader, const char *line, size_t line_len, void *data),
+ int (*on_eof)(struct reader *reader, const char *current_section, void *data),
void *data)
{
char *current_section = NULL, *var_name, *var_value, *line_start;
@@ -1536,7 +1536,7 @@ static int config_parse(
if ((result = parse_section_header(reader, ¤t_section)) == 0 && on_section) {
line_len = reader->read_ptr - line_start;
- result = on_section(&reader, current_section, line_start, line_len, data);
+ result = on_section(reader, current_section, line_start, line_len, data);
}
break;
@@ -1547,21 +1547,21 @@ static int config_parse(
if (on_comment) {
line_len = reader->read_ptr - line_start;
- result = on_comment(&reader, line_start, line_len, data);
+ result = on_comment(reader, line_start, line_len, data);
}
break;
default: /* assume variable declaration */
if ((result = parse_variable(reader, &var_name, &var_value)) == 0 && on_variable) {
line_len = reader->read_ptr - line_start;
- result = on_variable(&reader, current_section, var_name, var_value, line_start, line_len, data);
+ result = on_variable(reader, current_section, var_name, var_value, line_start, line_len, data);
}
break;
}
}
if (on_eof)
- result = on_eof(&reader, current_section, data);
+ result = on_eof(reader, current_section, data);
git__free(current_section);
return result;
@@ -1575,7 +1575,7 @@ struct parse_data {
};
static int read_on_variable(
- struct reader **reader,
+ struct reader *reader,
const char *current_section,
char *var_name,
char *var_value,
@@ -1622,7 +1622,7 @@ static int read_on_variable(
git_buf path = GIT_BUF_INIT;
char *dir;
- if ((result = git_path_dirname_r(&path, (*reader)->file->path)) < 0)
+ if ((result = git_path_dirname_r(&path, reader->file->path)) < 0)
return result;
dir = git_buf_detach(&path);
@@ -1632,7 +1632,7 @@ static int read_on_variable(
if (result < 0)
return result;
- include = git_array_alloc((*reader)->file->includes);
+ include = git_array_alloc(reader->file->includes);
memset(include, 0, sizeof(*include));
git_array_init(include->includes);
include->path = git_buf_detach(&path);
@@ -1776,7 +1776,7 @@ static int write_value(struct write_data *write_data)
}
static int write_on_section(
- struct reader **reader,
+ struct reader *reader,
const char *current_section,
const char *line,
size_t line_len,
@@ -1812,7 +1812,7 @@ static int write_on_section(
}
static int write_on_variable(
- struct reader **reader,
+ struct reader *reader,
const char *current_section,
char *var_name,
char *var_value,
@@ -1862,7 +1862,7 @@ static int write_on_variable(
return write_value(write_data);
}
-static int write_on_comment(struct reader **reader, const char *line, size_t line_len, void *data)
+static int write_on_comment(struct reader *reader, const char *line, size_t line_len, void *data)
{
struct write_data *write_data;
@@ -1873,7 +1873,7 @@ static int write_on_comment(struct reader **reader, const char *line, size_t lin
}
static int write_on_eof(
- struct reader **reader, const char *current_section, void *data)
+ struct reader *reader, const char *current_section, void *data)
{
struct write_data *write_data = (struct write_data *)data;
int result = 0;