Staging
v0.5.1
Revision ca1b4116483b397e78483376296bcd23916ab553 authored by Johannes Schindelin on 15 February 2019, 15:17:45 UTC, committed by Junio C Hamano on 15 February 2019, 18:25:28 UTC
Running up to v2.21.0, we fixed two bugs that were made prominent by the
Windows-specific change to retain copies of only the 30 latest getenv()
calls' returned strings, invalidating any copies of previous getenv()
calls' return values.

While this really shines a light onto bugs of the form where we hold
onto getenv()'s return values without copying them, it is also a real
problem for users.

And even if Jeff King's patches merged via 773e408881 (Merge branch
'jk/save-getenv-result', 2019-01-29) provide further work on that front,
we are far from done. Just one example: on Windows, we unset environment
variables when spawning new processes, which potentially invalidates
strings that were previously obtained via getenv(), and therefore we
have to duplicate environment values that are somehow involved in
spawning new processes (e.g. GIT_MAN_VIEWER in show_man_page()).

We do not have a chance to investigate, let address, all of those issues
in time for v2.21.0, so let's at least help Windows users by increasing
the number of getenv() calls' return values that are kept valid. The
number 64 was determined by looking at the average number of getenv()
calls per process in the entire test suite run on Windows (which is
around 40) and then adding a bit for good measure. And it is a power of
two (which would have hit yesterday's theme perfectly).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 2d08f3d
Raw File
line-range.h
#ifndef LINE_RANGE_H
#define LINE_RANGE_H

struct index_state;

/*
 * Parse one item in an -L begin,end option w.r.t. the notional file
 * object 'cb_data' consisting of 'lines' lines.
 *
 * The 'nth_line_cb' callback is used to determine the start of the
 * line 'lno' inside the 'cb_data'.  The caller is expected to already
 * have a suitable map at hand to make this a constant-time lookup.
 *
 * 'anchor' is the 1-based line at which relative range specifications
 * should be anchored. Absolute ranges are unaffected by this value.
 *
 * Returns 0 in case of success and -1 if there was an error.  The
 * actual range is stored in *begin and *end.  The counting starts
 * at 1!  In case of error, the caller should show usage message.
 */

typedef const char *(*nth_line_fn_t)(void *data, long lno);

int parse_range_arg(const char *arg,
		    nth_line_fn_t nth_line_cb,
		    void *cb_data, long lines, long anchor,
		    long *begin, long *end,
		    const char *path, struct index_state *istate);

/*
 * Scan past a range argument that could be parsed by
 * 'parse_range_arg', to help the caller determine the start of the
 * filename in '-L n,m:file' syntax.
 *
 * Returns a pointer to the first character after the 'n,m' part, or
 * NULL in case the argument is obviously malformed.
 */

const char *skip_range_arg(const char *arg, struct index_state *istate);

#endif /* LINE_RANGE_H */
back to top