Skip to content

Commit 3a7f7a6

Browse files
committed
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 parent 73df75d commit 3a7f7a6

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/config_file.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,10 +1507,10 @@ static int parse_variable(struct reader *reader, char **var_name, char **var_val
15071507

15081508
static int config_parse(
15091509
struct reader *reader,
1510-
int (*on_section)(struct reader **reader, const char *current_section, const char *line, size_t line_len, void *data),
1511-
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),
1512-
int (*on_comment)(struct reader **reader, const char *line, size_t line_len, void *data),
1513-
int (*on_eof)(struct reader **reader, const char *current_section, void *data),
1510+
int (*on_section)(struct reader *reader, const char *current_section, const char *line, size_t line_len, void *data),
1511+
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),
1512+
int (*on_comment)(struct reader *reader, const char *line, size_t line_len, void *data),
1513+
int (*on_eof)(struct reader *reader, const char *current_section, void *data),
15141514
void *data)
15151515
{
15161516
char *current_section = NULL, *var_name, *var_value, *line_start;
@@ -1536,7 +1536,7 @@ static int config_parse(
15361536

15371537
if ((result = parse_section_header(reader, &current_section)) == 0 && on_section) {
15381538
line_len = reader->read_ptr - line_start;
1539-
result = on_section(&reader, current_section, line_start, line_len, data);
1539+
result = on_section(reader, current_section, line_start, line_len, data);
15401540
}
15411541
break;
15421542

@@ -1547,21 +1547,21 @@ static int config_parse(
15471547

15481548
if (on_comment) {
15491549
line_len = reader->read_ptr - line_start;
1550-
result = on_comment(&reader, line_start, line_len, data);
1550+
result = on_comment(reader, line_start, line_len, data);
15511551
}
15521552
break;
15531553

15541554
default: /* assume variable declaration */
15551555
if ((result = parse_variable(reader, &var_name, &var_value)) == 0 && on_variable) {
15561556
line_len = reader->read_ptr - line_start;
1557-
result = on_variable(&reader, current_section, var_name, var_value, line_start, line_len, data);
1557+
result = on_variable(reader, current_section, var_name, var_value, line_start, line_len, data);
15581558
}
15591559
break;
15601560
}
15611561
}
15621562

15631563
if (on_eof)
1564-
result = on_eof(&reader, current_section, data);
1564+
result = on_eof(reader, current_section, data);
15651565

15661566
git__free(current_section);
15671567
return result;
@@ -1575,7 +1575,7 @@ struct parse_data {
15751575
};
15761576

15771577
static int read_on_variable(
1578-
struct reader **reader,
1578+
struct reader *reader,
15791579
const char *current_section,
15801580
char *var_name,
15811581
char *var_value,
@@ -1622,7 +1622,7 @@ static int read_on_variable(
16221622
git_buf path = GIT_BUF_INIT;
16231623
char *dir;
16241624

1625-
if ((result = git_path_dirname_r(&path, (*reader)->file->path)) < 0)
1625+
if ((result = git_path_dirname_r(&path, reader->file->path)) < 0)
16261626
return result;
16271627

16281628
dir = git_buf_detach(&path);
@@ -1632,7 +1632,7 @@ static int read_on_variable(
16321632
if (result < 0)
16331633
return result;
16341634

1635-
include = git_array_alloc((*reader)->file->includes);
1635+
include = git_array_alloc(reader->file->includes);
16361636
memset(include, 0, sizeof(*include));
16371637
git_array_init(include->includes);
16381638
include->path = git_buf_detach(&path);
@@ -1776,7 +1776,7 @@ static int write_value(struct write_data *write_data)
17761776
}
17771777

17781778
static int write_on_section(
1779-
struct reader **reader,
1779+
struct reader *reader,
17801780
const char *current_section,
17811781
const char *line,
17821782
size_t line_len,
@@ -1812,7 +1812,7 @@ static int write_on_section(
18121812
}
18131813

18141814
static int write_on_variable(
1815-
struct reader **reader,
1815+
struct reader *reader,
18161816
const char *current_section,
18171817
char *var_name,
18181818
char *var_value,
@@ -1862,7 +1862,7 @@ static int write_on_variable(
18621862
return write_value(write_data);
18631863
}
18641864

1865-
static int write_on_comment(struct reader **reader, const char *line, size_t line_len, void *data)
1865+
static int write_on_comment(struct reader *reader, const char *line, size_t line_len, void *data)
18661866
{
18671867
struct write_data *write_data;
18681868

@@ -1873,7 +1873,7 @@ static int write_on_comment(struct reader **reader, const char *line, size_t lin
18731873
}
18741874

18751875
static int write_on_eof(
1876-
struct reader **reader, const char *current_section, void *data)
1876+
struct reader *reader, const char *current_section, void *data)
18771877
{
18781878
struct write_data *write_data = (struct write_data *)data;
18791879
int result = 0;

0 commit comments

Comments
 (0)