All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jim Meyering <jim@meyering.net>
To: Alex Riesen <raa.lkml@gmail.com>
Cc: git list <git@vger.kernel.org>
Subject: Re: [PATCH] use xstrdup, not strdup in ll-merge.c
Date: Mon, 15 Jun 2009 13:49:09 +0200	[thread overview]
Message-ID: <877hzdlnt6.fsf@meyering.net> (raw)
In-Reply-To: <81b0412b0906150439r755a7498ldddbca911b2fd36e@mail.gmail.com> (Alex Riesen's message of "Mon, 15 Jun 2009 13:39:08 +0200")

Alex Riesen wrote:

> 2009/6/15 Jim Meyering <jim@meyering.net>:
>> Alex Riesen wrote:
>>> 2009/6/15 Jim Meyering <jim@meyering.net>:
>>>> Alex Riesen wrote:
>>>>> 2009/6/14 Jim Meyering <jim@meyering.net>:
>>>>>> @@ -231,7 +231,7 @@ static int read_merge_config(const char *var, const char *value, void *cb)
>>>>>>
>>>>>>        if (!strcmp(var, "merge.default")) {
>>>>>>                if (value)
>>>>>> -                       default_ll_merge = strdup(value);
>>>>>> +                       default_ll_merge = xstrdup(value);
>>>>>
>>>>> read_merge_config has a failure mode (where it returns -1), why not use it?
>>>>
>>>> I didn't even consider it, because it would be inconsistent with
>>>> the other heap-allocation functions used there (xcalloc, xmemdupz).
>>>>
>>>> However, now that I do, it looks like that would mean adding four times
>>>> the same code (including conditionals and code to generate a diagnostic via
>>>> a call to error -- or a goto). Why bother, when all of that is already
>>>> encapsulated in xmalloc?
>>>
>>> So that a useful error message can be given in the _caller_ (it knows
>>> more about context)?
>>
>> So you want to tell the user that we failed
>> to strdup the "merge.default" value?
>> Or the "driver" value?
>
> "merge: recursive: error loading configuration (last seen:
> merge.default): Out of memory\n"
>
>> Of more general interest, when xstrdup fails, it might be useful to
>> include in the diagnostic how long the would-be-dup'd string was.  I.e.,
>> rather than saying
>>
>>    die("Out of memory, strdup failed");
>> say
>>    die("Out of memory, failed to strdup a %lu-byte string",
>>        (unsigned long int) strlen(str));
>
> Yes. Still lacks higher level information, though.
>
>>> Otherwise the error message ("Out of memory, strdup failed") does not
>>> have anything about the place nor situation in it. As the situations
>>> when a modern system really runs out of memory are very rare,
>>> mostly such reports just point at some inconsistency elsewhere
>>
>> Exactly.  This is why I think it's not worthwhile to invest in
>> a more precise diagnostic, here.
>
> I disagree. It is already hard to find starting point for debugging if
> the failed code is just a layer: the config of ll-merge is called not only
> from the merge drivers, but also indirectly from the programs which
> call the merge itself. Now, go figure where has it failed...

If you're convinced of the value of such a change, go for it.
Though it sounds like you're saying you'd prefer a stack trace.

  reply	other threads:[~2009-06-15 11:49 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-14 19:47 [PATCH] use xstrdup, not strdup in ll-merge.c Jim Meyering
2009-06-14 22:03 ` Alex Riesen
2009-06-15  8:02   ` Jim Meyering
2009-06-15  8:45     ` Alex Riesen
2009-06-15  9:23       ` Jim Meyering
2009-06-15 11:39         ` Alex Riesen
2009-06-15 11:49           ` Jim Meyering [this message]
2009-06-15 12:46             ` Alex Riesen
2009-06-15 14:26               ` Shawn O. Pearce
2009-06-15 15:21                 ` Alex Riesen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877hzdlnt6.fsf@meyering.net \
    --to=jim@meyering.net \
    --cc=git@vger.kernel.org \
    --cc=raa.lkml@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.