From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752599AbbLNQFk (ORCPT ); Mon, 14 Dec 2015 11:05:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49076 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751887AbbLNQFj (ORCPT ); Mon, 14 Dec 2015 11:05:39 -0500 Date: Mon, 14 Dec 2015 10:05:37 -0600 From: Josh Poimboeuf To: Arnaldo Carvalho de Melo Cc: Peter Zijlstra , Ingo Molnar , linux-kernel@vger.kernel.org, Jiri Olsa , Namhyung Kim Subject: Re: [PATCH v3 14/17] perf: Remove subcmd dependencies on strbuf Message-ID: <20151214160537.GE11552@treble.redhat.com> References: <3454b82dcc683d8ae581ca123de47578ee5a5e3c.1449965119.git.jpoimboe@redhat.com> <20151214154421.GO6843@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20151214154421.GO6843@kernel.org> User-Agent: Mutt/1.5.23.1-rc1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 14, 2015 at 12:44:21PM -0300, Arnaldo Carvalho de Melo wrote: > Em Sun, Dec 13, 2015 at 10:18:14PM -0600, Josh Poimboeuf escreveu: > > Introduce and use new astrcat() and astrcatf() functions which replace > > the strbuf functionality for subcmd. > > > > > diff --git a/tools/perf/util/subcmd-util.h b/tools/perf/util/subcmd-util.h > > new file mode 100644 > > index 0000000..98fb9f9 > > --- /dev/null > > +++ b/tools/perf/util/subcmd-util.h > > @@ -0,0 +1,24 @@ > > +#ifndef __PERF_SUBCMD_UTIL_H > > +#define __PERF_SUBCMD_UTIL_H > > + > > +#include > > + > > +#define astrcatf(out, fmt, ...) \ > > +({ \ > > + char *tmp = *(out); \ > > + if (asprintf((out), "%s" fmt, tmp ?: "", ## __VA_ARGS__) == -1) \ > > + die("asprintf failed"); \ > > + free(tmp); \ > > +}) > > Hey, don't add die() calls, please. > > > + > > +static inline void astrcat(char **out, const char *add) > > +{ > > + char *tmp = *out; > > + > > + if (asprintf(out, "%s%s", tmp ?: "", add) == -1) > > + die("asprintf failed"); > > + > > + free(tmp); > > Ditto. This replaces strbuf, which also calls die() when allocations fail. So this duplicates the existing die-on-allocation-error functionality and is nothing "new" from my perspective. Do you want me to change all the callers (and callers' callers, etc) of these functions to check for errors? > And I think that this should go into tools/include/string.h and > tools/lib/string.c, no? If these functions simply duplicate some of strbuf's functionality and they aren't used outside of libsubcmd then I don't see any reason to do that. > We should try to look at the kernel and try to follow naming, semantics, > etc as much as possible. The kernel doesn't have a astrcat, just > kasprintf() (that is in linux/kernel.h, perhaps because in userland > asprintf is in stdio.h, not in string.h) , wonder how something like > astrcat is done there... Doing some research now. Ok. -- Josh