* [PATCH 1/3] remote-testsvn.c: Avoid the getline() GNU extension function
@ 2012-08-25 17:13 Ramsay Jones
2012-08-25 19:03 ` Joachim Schmitz
2012-08-25 19:20 ` Erik Faye-Lund
0 siblings, 2 replies; 6+ messages in thread
From: Ramsay Jones @ 2012-08-25 17:13 UTC (permalink / raw)
To: florian.achleitner.2.6.31; +Cc: Junio C Hamano, GIT Mailing-list
The getline() function is a GNU extension (you need to define
_GNU_SOURCE before including stdio.h) and is, therefore, not
portable. In particular, getline() is not available on MinGW.
In order to support non-GNU systems, we replace the call to
getline() with (almost) equivalent code using strbuf_getline().
Note that, unlike getline(), strbuf_getline() removes the
newline terminator from the returned string. This difference
in semantics does not matter at this call-site. Also, we note
that the original code was leaking the memory allocated to
'line' by getline().
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
---
Hi Florian,
Could you please squash this into commit 0320cef0 ("remote-svn: add
marks-file regeneration", 22-08-2012).
ATB,
Ramsay Jones
remote-testsvn.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/remote-testsvn.c b/remote-testsvn.c
index 09dc304..d0b81d5 100644
--- a/remote-testsvn.c
+++ b/remote-testsvn.c
@@ -121,9 +121,8 @@ static void regenerate_marks(void)
static void check_or_regenerate_marks(int latestrev) {
FILE *marksfile;
- char *line = NULL;
- size_t linelen = 0;
struct strbuf sb = STRBUF_INIT;
+ struct strbuf line = STRBUF_INIT;
int found = 0;
if (latestrev < 1)
@@ -139,8 +138,8 @@ static void check_or_regenerate_marks(int latestrev) {
fclose(marksfile);
} else {
strbuf_addf(&sb, ":%d ", latestrev);
- while (getline(&line, &linelen, marksfile) != -1) {
- if (!prefixcmp(line, sb.buf)) {
+ while (strbuf_getline(&line, marksfile, '\n') != EOF) {
+ if (!prefixcmp(line.buf, sb.buf)) {
found++;
break;
}
@@ -151,6 +150,7 @@ static void check_or_regenerate_marks(int latestrev) {
}
free_notes(NULL);
strbuf_release(&sb);
+ strbuf_release(&line);
}
static int cmd_import(const char *line)
--
1.7.12
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/3] remote-testsvn.c: Avoid the getline() GNU extension function
2012-08-25 17:13 [PATCH 1/3] remote-testsvn.c: Avoid the getline() GNU extension function Ramsay Jones
@ 2012-08-25 19:03 ` Joachim Schmitz
2012-08-25 19:20 ` Erik Faye-Lund
1 sibling, 0 replies; 6+ messages in thread
From: Joachim Schmitz @ 2012-08-25 19:03 UTC (permalink / raw)
To: git
Ramsay Jones wrote:
> The getline() function is a GNU extension (you need to define
> _GNU_SOURCE before including stdio.h) and is, therefore, not
> portable. In particular, getline() is not available on MinGW.
>
> In order to support non-GNU systems, we replace the call to
> getline() with (almost) equivalent code using strbuf_getline().
> Note that, unlike getline(), strbuf_getline() removes the
> newline terminator from the returned string. This difference
> in semantics does not matter at this call-site. Also, we note
> that the original code was leaking the memory allocated to
> 'line' by getline().
>
> Signed-off-by: Ramsay Jones ramsay@ramsay1.demon.co.uk
Tested-by: Joachim Schmitz jojo@schmitz-digital.de
> ---
>
> Hi Florian,
>
> Could you please squash this into commit 0320cef0 ("remote-svn: add
> marks-file regeneration", 22-08-2012).
>
> ATB,
> Ramsay Jones
>
> remote-testsvn.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/remote-testsvn.c b/remote-testsvn.c
> index 09dc304..d0b81d5 100644
> --- a/remote-testsvn.c
> +++ b/remote-testsvn.c
> @@ -121,9 +121,8 @@ static void regenerate_marks(void)
>
> static void check_or_regenerate_marks(int latestrev) {
> FILE *marksfile;
> - char *line = NULL;
> - size_t linelen = 0;
> struct strbuf sb = STRBUF_INIT;
> + struct strbuf line = STRBUF_INIT;
> int found = 0;
>
> if (latestrev < 1)
> @@ -139,8 +138,8 @@ static void check_or_regenerate_marks(int
> latestrev) { fclose(marksfile);
> } else {
> strbuf_addf(&sb, ":%d ", latestrev);
> - while (getline(&line, &linelen, marksfile) != -1) {
> - if (!prefixcmp(line, sb.buf)) {
> + while (strbuf_getline(&line, marksfile, '\n') != EOF) {
> + if (!prefixcmp(line.buf, sb.buf)) {
> found++;
> break;
> }
> @@ -151,6 +150,7 @@ static void check_or_regenerate_marks(int
> latestrev) { }
> free_notes(NULL);
> strbuf_release(&sb);
> + strbuf_release(&line);
> }
>
> static int cmd_import(const char *line)
I'd like to second this request, having the same problem on HP NonStop and
this patch fixes it for me too.
Bye, Jojo
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/3] remote-testsvn.c: Avoid the getline() GNU extension function
2012-08-25 17:13 [PATCH 1/3] remote-testsvn.c: Avoid the getline() GNU extension function Ramsay Jones
2012-08-25 19:03 ` Joachim Schmitz
@ 2012-08-25 19:20 ` Erik Faye-Lund
2012-08-26 17:31 ` Junio C Hamano
2012-08-30 17:19 ` Ramsay Jones
1 sibling, 2 replies; 6+ messages in thread
From: Erik Faye-Lund @ 2012-08-25 19:20 UTC (permalink / raw)
To: Ramsay Jones; +Cc: florian.achleitner.2.6.31, Junio C Hamano, GIT Mailing-list
On Sat, Aug 25, 2012 at 7:13 PM, Ramsay Jones
<ramsay@ramsay1.demon.co.uk> wrote:
>
> The getline() function is a GNU extension (you need to define
> _GNU_SOURCE before including stdio.h) and is, therefore, not
> portable. In particular, getline() is not available on MinGW.
Actually, getline is a POSIX-2008 feature, so it's not (simply) a GNU extension:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/getline.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/3] remote-testsvn.c: Avoid the getline() GNU extension function
2012-08-25 19:20 ` Erik Faye-Lund
@ 2012-08-26 17:31 ` Junio C Hamano
2012-08-30 17:25 ` Ramsay Jones
2012-08-30 17:19 ` Ramsay Jones
1 sibling, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2012-08-26 17:31 UTC (permalink / raw)
To: kusmabite; +Cc: Ramsay Jones, florian.achleitner.2.6.31, GIT Mailing-list
Erik Faye-Lund <kusmabite@gmail.com> writes:
> On Sat, Aug 25, 2012 at 7:13 PM, Ramsay Jones
> <ramsay@ramsay1.demon.co.uk> wrote:
>>
>> The getline() function is a GNU extension (you need to define
>> _GNU_SOURCE before including stdio.h) and is, therefore, not
>> portable. In particular, getline() is not available on MinGW.
>
> Actually, getline is a POSIX-2008 feature, so it's not (simply) a GNU extension:
>
> http://pubs.opengroup.org/onlinepubs/9699919799/functions/getline.html
True, thanks for pointing it out. Justify the change with something
like this instead, perhaps?
The getline() function, even though is in POSIX.1-2008, is
not available on some platforms. Use strbuf_getline() for
portability.
By the way, the remainder of the proposed log message talks about
the difference between getline() that keeps the terminating LF vs
strbuf_getline() that drops it. Would strbuf_getwholeline() be a
better alternative?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/3] remote-testsvn.c: Avoid the getline() GNU extension function
2012-08-25 19:20 ` Erik Faye-Lund
2012-08-26 17:31 ` Junio C Hamano
@ 2012-08-30 17:19 ` Ramsay Jones
1 sibling, 0 replies; 6+ messages in thread
From: Ramsay Jones @ 2012-08-30 17:19 UTC (permalink / raw)
To: kusmabite; +Cc: florian.achleitner.2.6.31, Junio C Hamano, GIT Mailing-list
Erik Faye-Lund wrote:
> On Sat, Aug 25, 2012 at 7:13 PM, Ramsay Jones
> <ramsay@ramsay1.demon.co.uk> wrote:
>>
>> The getline() function is a GNU extension (you need to define
>> _GNU_SOURCE before including stdio.h) and is, therefore, not
>> portable. In particular, getline() is not available on MinGW.
>
> Actually, getline is a POSIX-2008 feature, so it's not (simply) a GNU extension:
>
> http://pubs.opengroup.org/onlinepubs/9699919799/functions/getline.html
Thanks for the reference. I hadn't noticed this being included into
POSIX. Well, it's only been four years ... :-D
Thanks again.
ATB,
Ramsay Jones
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/3] remote-testsvn.c: Avoid the getline() GNU extension function
2012-08-26 17:31 ` Junio C Hamano
@ 2012-08-30 17:25 ` Ramsay Jones
0 siblings, 0 replies; 6+ messages in thread
From: Ramsay Jones @ 2012-08-30 17:25 UTC (permalink / raw)
To: Junio C Hamano; +Cc: kusmabite, florian.achleitner.2.6.31, GIT Mailing-list
Junio C Hamano wrote:
> Erik Faye-Lund <kusmabite@gmail.com> writes:
>
>> On Sat, Aug 25, 2012 at 7:13 PM, Ramsay Jones
>> <ramsay@ramsay1.demon.co.uk> wrote:
>>>
>>> The getline() function is a GNU extension (you need to define
>>> _GNU_SOURCE before including stdio.h) and is, therefore, not
>>> portable. In particular, getline() is not available on MinGW.
>>
>> Actually, getline is a POSIX-2008 feature, so it's not (simply) a GNU extension:
>>
>> http://pubs.opengroup.org/onlinepubs/9699919799/functions/getline.html
>
> True, thanks for pointing it out. Justify the change with something
> like this instead, perhaps?
>
> The getline() function, even though is in POSIX.1-2008, is
> not available on some platforms. Use strbuf_getline() for
> portability.
>
> By the way, the remainder of the proposed log message talks about
> the difference between getline() that keeps the terminating LF vs
> strbuf_getline() that drops it. Would strbuf_getwholeline() be a
> better alternative?
I don't think it matters; I was just making sure Florian was aware
of the difference (it will not appear in the commit message anyway),
including the memory leak in the original code.
ATB,
Ramsay Jones
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-08-30 17:30 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-25 17:13 [PATCH 1/3] remote-testsvn.c: Avoid the getline() GNU extension function Ramsay Jones
2012-08-25 19:03 ` Joachim Schmitz
2012-08-25 19:20 ` Erik Faye-Lund
2012-08-26 17:31 ` Junio C Hamano
2012-08-30 17:25 ` Ramsay Jones
2012-08-30 17:19 ` Ramsay Jones
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.