From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 49497 invoked by alias); 27 Jul 2017 15:42:21 -0000 Mailing-List: contact elfutils-devel-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Post: List-Help: List-Subscribe: Sender: elfutils-devel-owner@sourceware.org Received: (qmail 49475 invoked by uid 89); 27 Jul 2017 15:42:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.99.2 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 spammy=jiang, Jiang, D*io X-Spam-Status: No, score=-26.4 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-HELO: mail-ua0-f177.google.com Received: from mail-ua0-f177.google.com (HELO mail-ua0-f177.google.com) (209.85.217.177) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 27 Jul 2017 15:42:17 +0000 Received: by mail-ua0-f177.google.com with SMTP id q25so124883108uah.1 for ; Thu, 27 Jul 2017 08:42:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=MHDPrePA6rUpf5lAVpnc/vO1O+Rl2G0X6WVfEIcOtTk=; b=YPYz8B+bcItSEdEVzSt6ruNgY7VKQLc0Fe3Ki7cWgV0DSIPYaI8S/a2ua2T1RbXfAT KmcxGR0acMGDhsTcHJH1AlQ5v1mQcMOz3tgxqDeX/LrXhuQryiBsmJSGu77xjj5GNpk3 f3g1kaS3RcSRSVTzXSO195HfDg0eA+YGPDEQxBSJaoXMK6axhWGXXAOiwOvisCOsJEF+ cgGcGkVHQD3773Nu59n4aq4Q41SoTRUooPAm4I2hP8KzCAvjegPDNMIpGFFzUjL5pSW0 XnQPuPF2RLS6GtnoRvONa2g1CWsfFdBf47lCLKCjGcKrsKl5X01/wgu+osXBeft9bObt e6hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=MHDPrePA6rUpf5lAVpnc/vO1O+Rl2G0X6WVfEIcOtTk=; b=Kbg2VTauuVo3wVugLg6vlVekj6X5NLeoUBwmmE8CAr0Flj0x/ApLuBv1U4R/OajhHn X/+2qXq9I6yx8EWPr5lh8rStNcWhJIplbJXyAJJ+URridIK6HmshXl3zyxZQcIpfuToy evtDf5TvX+xz2r63yLHteSxi8xp2M5WT4Ozt7T539RdE1cWn32XElaXFTc84fVrl9TLW IQxPKUgkNhrDjRltSUWmHhxtWyGDd96VG7jsVsvjsIBXoKH4sTVB70+vU3CksPHljBCp M+53JSIY7ObxKkJGsiZrdlhBeIS/Z4Cy0G13suPY07I3hK+AnK6Qs6TEKn2yIN9IZosu tuzg== X-Gm-Message-State: AIVw111eOxFZlmmeEutkpj1J7vA1t2Tn2Zu+OKVgJt/xyBpT2smEF7i0 mXLpzk8cHNsYD+tkxGZLyKCTrxp8o958LEEgKA== X-Received: by 10.159.55.49 with SMTP id z46mr2764378uad.131.1501170135487; Thu, 27 Jul 2017 08:42:15 -0700 (PDT) MIME-Version: 1.0 Received: by 10.176.24.144 with HTTP; Thu, 27 Jul 2017 08:42:15 -0700 (PDT) From: "Yunlian Jiang via elfutils-devel" Reply-To: Yunlian Jiang Date: Thu, 27 Jul 2017 15:42:00 -0000 Message-ID: Subject: [PATCH] libdwfl: Move nested functions in parse_opt to file scope. To: elfutils-devel@sourceware.org Content-Type: text/plain; charset="UTF-8" X-SW-Source: 2017-q3/txt/msg00056.txt.bz2 * Move nested function 'failure' to file scope to compile with clang. * Move nested function 'fail' to file scope to compile with clang. Signed-off-by: Yunlian Jiang --- libdwfl/argp-std.c | 55 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 26 deletions(-) index 9bce6b1e..83f03a8f 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,3 +1,7 @@ +2017-07-27 Yunlian Jiang + * Move nested function 'failure' to file scope to compile with clang. + * Move nested function 'fail' to file scope to compile with clang. + 2017-04-20 Ulf Hermann Mark Wielaard diff --git a/libdwfl/argp-std.c b/libdwfl/argp-std.c index 347a05b4..498ace21 100644 --- a/libdwfl/argp-std.c +++ b/libdwfl/argp-std.c @@ -104,25 +104,28 @@ struct parse_opt const char *core; }; +static inline void +failure (Dwfl *dwfl, int errnum, const char *msg, struct argp_state *state) +{ + if (dwfl != NULL) + dwfl_end (dwfl); + if (errnum == -1) + argp_failure (state, EXIT_FAILURE, 0, "%s: %s", + msg, INTUSE(dwfl_errmsg) (-1)); + else + argp_failure (state, EXIT_FAILURE, errnum, "%s", msg); +} + +static inline error_t +fail (Dwfl *dwfl, int errnum, const char *msg, struct argp_state *state) +{ + failure (dwfl, errnum, msg, state); + return errnum == -1 ? EIO : errnum; +} + static error_t parse_opt (int key, char *arg, struct argp_state *state) { - inline void failure (Dwfl *dwfl, int errnum, const char *msg) - { - if (dwfl != NULL) - dwfl_end (dwfl); - if (errnum == -1) - argp_failure (state, EXIT_FAILURE, 0, "%s: %s", - msg, INTUSE(dwfl_errmsg) (-1)); - else - argp_failure (state, EXIT_FAILURE, errnum, "%s", msg); - } - inline error_t fail (Dwfl *dwfl, int errnum, const char *msg) - { - failure (dwfl, errnum, msg); - return errnum == -1 ? EIO : errnum; - } - switch (key) { case ARGP_KEY_INIT: @@ -130,7 +133,7 @@ parse_opt (int key, char *arg, struct argp_state *state) assert (state->hook == NULL); struct parse_opt *opt = calloc (1, sizeof (*opt)); if (opt == NULL) - failure (NULL, DWFL_E_ERRNO, "calloc"); + failure (NULL, DWFL_E_ERRNO, "calloc", state); state->hook = opt; } break; @@ -147,7 +150,7 @@ parse_opt (int key, char *arg, struct argp_state *state) { dwfl = INTUSE(dwfl_begin) (&offline_callbacks); if (dwfl == NULL) - return fail (dwfl, -1, arg); + return fail (dwfl, -1, arg, state); opt->dwfl = dwfl; /* Start at zero so if there is just one -e foo.so, @@ -173,7 +176,7 @@ parse_opt (int key, char *arg, struct argp_state *state) Dwfl *dwfl = INTUSE(dwfl_begin) (&proc_callbacks); int result = INTUSE(dwfl_linux_proc_report) (dwfl, atoi (arg)); if (result != 0) - return fail (dwfl, result, arg); + return fail (dwfl, result, arg, state); /* Non-fatal to not be able to attach to process, ignore error. */ INTUSE(dwfl_linux_proc_attach) (dwfl, atoi (arg), false); @@ -202,7 +205,7 @@ parse_opt (int key, char *arg, struct argp_state *state) int result = INTUSE(dwfl_linux_proc_maps_report) (dwfl, f); fclose (f); if (result != 0) - return fail (dwfl, result, arg); + return fail (dwfl, result, arg, state); opt->dwfl = dwfl; } else @@ -231,11 +234,11 @@ parse_opt (int key, char *arg, struct argp_state *state) Dwfl *dwfl = INTUSE(dwfl_begin) (&kernel_callbacks); int result = INTUSE(dwfl_linux_kernel_report_kernel) (dwfl); if (result != 0) - return fail (dwfl, result, _("cannot load kernel symbols")); + return fail (dwfl, result, _("cannot load kernel symbols"), state); result = INTUSE(dwfl_linux_kernel_report_modules) (dwfl); if (result != 0) /* Non-fatal to have no modules since we do have the kernel. */ - failure (dwfl, result, _("cannot find kernel modules")); + failure (dwfl, result, _("cannot find kernel modules"), state); opt->dwfl = dwfl; } else @@ -252,7 +255,7 @@ parse_opt (int key, char *arg, struct argp_state *state) int result = INTUSE(dwfl_linux_kernel_report_offline) (dwfl, arg, NULL); if (result != 0) - return fail (dwfl, result, _("cannot find kernel or modules")); + return fail (dwfl, result, _("cannot find kernel or modules"), state); opt->dwfl = dwfl; } else @@ -271,7 +274,7 @@ parse_opt (int key, char *arg, struct argp_state *state) arg = "a.out"; dwfl = INTUSE(dwfl_begin) (&offline_callbacks); if (INTUSE(dwfl_report_offline) (dwfl, "", arg, -1) == NULL) - return fail (dwfl, -1, arg); + return fail (dwfl, -1, arg, state); opt->dwfl = dwfl; } @@ -301,7 +304,7 @@ parse_opt (int key, char *arg, struct argp_state *state) { elf_end (core); close (fd); - return fail (dwfl, result, opt->core); + return fail (dwfl, result, opt->core, state); } /* Non-fatal to not be able to attach to core, ignore error. */ @@ -331,7 +334,7 @@ parse_opt (int key, char *arg, struct argp_state *state) else if (opt->e) { if (INTUSE(dwfl_report_offline) (dwfl, "", opt->e, -1) == NULL) - return fail (dwfl, -1, opt->e); + return fail (dwfl, -1, opt->e, state); } /* One of the three flavors has done dwfl_begin and some reporting -- 2.14.0.rc0.400.g1c36432dff-goog