From patchwork Tue Jan 19 17:36:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Jackson X-Patchwork-Id: 8064241 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 053F8BEEE5 for ; Tue, 19 Jan 2016 17:40:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0FD2420450 for ; Tue, 19 Jan 2016 17:40:09 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2C0D320265 for ; Tue, 19 Jan 2016 17:40:08 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aLaD9-0002cF-T4; Tue, 19 Jan 2016 17:36:55 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aLaD7-0002cA-Ky for xen-devel@lists.xen.org; Tue, 19 Jan 2016 17:36:53 +0000 Received: from [85.158.143.35] by server-2.bemta-4.messagelabs.com id A6/6F-08977-4347E965; Tue, 19 Jan 2016 17:36:52 +0000 X-Env-Sender: prvs=81941a82a=Ian.Jackson@citrix.com X-Msg-Ref: server-9.tower-21.messagelabs.com!1453225010!10960591!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 50043 invoked from network); 19 Jan 2016 17:36:51 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-9.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 19 Jan 2016 17:36:51 -0000 X-IronPort-AV: E=Sophos;i="5.22,318,1449532800"; d="scan'208";a="332489256" From: Ian Jackson MIME-Version: 1.0 Message-ID: <22174.29744.755487.990490@mariner.uk.xensource.com> Date: Tue, 19 Jan 2016 17:36:48 +0000 To: Ian Campbell , Andrew Cooper , Xen-devel , Wei Liu In-Reply-To: <22174.28455.949231.257126@mariner.uk.xensource.com> References: <1452802425-32603-1-git-send-email-andrew.cooper3@citrix.com> <1453220650.29930.107.camel@citrix.com> <569E66F8.2020407@citrix.com> <1453223091.26343.12.camel@citrix.com> <22174.28455.949231.257126@mariner.uk.xensource.com> X-Mailer: VM 8.1.0 under 23.4.1 (i486-pc-linux-gnu) X-DLP: MIA1 Subject: Re: [Xen-devel] [PATCH] tools/toollog: Drop XTL_NEW_LOGGER() X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Ian Jackson writes ("Re: [PATCH] tools/toollog: Drop XTL_NEW_LOGGER()"): > Ian Campbell writes ("Re: [PATCH] tools/toollog: Drop XTL_NEW_LOGGER()"): > > The underlying issue with all of these is the _undocumented_ nature of the > > assumptions, which is certainly a bug, however those assumptions are not in > > themselves "unreasonable" as was claimed. > > Maybe I should submit a counter-patch providing documentation. I think this macro is useful because if you wanted to write (say) xtl_logger_syslog, you would want to use it to help you with some boilerplate. Ian. From f749eea51c35c787b8ca7514a21ac145e2946ff8 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 19 Jan 2016 17:29:30 +0000 Subject: [PATCH] xentoollog: Document XTL_NEW_LOGGER convenience macro Signed-off-by: Ian Jackson --- tools/libs/toollog/include/xentoollog.h | 53 +++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tools/libs/toollog/include/xentoollog.h b/tools/libs/toollog/include/xentoollog.h index 853e9c7..95f7482 100644 --- a/tools/libs/toollog/include/xentoollog.h +++ b/tools/libs/toollog/include/xentoollog.h @@ -113,6 +113,59 @@ void xtl_progress(struct xentoollog_logger *logger, const char *xtl_level_to_string(xentoollog_level); /* never fails */ +/* + * To use this macro: + * + * Define your own logger struct, containing the vtable. + * + * typedef struct { + * xentoollog_logger vtable; // must come first + * [ state your logger needs ] + * } xentoolog_logger_mine; + * + * Write the logging functions: + * + * static void mine_vmessage([ see above ]); + * static void mine_progress([ see above ]); + * static void mine_destroy(struct xentoollog_logger *logger); + * + * Write a constructor: + * + * mine_xentoollog_logger *tl_createlogger_mine([whatever]) { + * mine_xentoolllog_logger newlogger; + * + * [ fill in fields of newlogger ] + * + * return XTL_NEW_LOGGER(mine, newlogger); + * } + * + * If newlogger contains resources that might need to be released, + * the constructor must check the return value from XTL_NEW_LOGGER: + * if it is NULL, the constructor must release the resources. + * + * + * Formally: + * + * xentoollog_logger_MINE* + * XTL_NEW_LOGGER(MINE, xentoollog_logger_MINE contents); + * + * Fills in contents.vtable. Allocates a new struct. Copies + * contents into it. Finally, returns a pointer to the copy. + * + * If allocation fails, uses contents to report this failure, and + * returns NULL. + * + * Expects that xentoollog_logger_MINE is a struct whose + * first member is + * xentoollog_logger vtable; + * + * Expects that + * MINE_vmessage + * MINE_progress + * MINE_destroy + * are in scope, with types compatible with the vtable members. + * + */ #define XTL_NEW_LOGGER(LOGGER,buffer) ({ \ xentoollog_logger_##LOGGER *new_consumer; \ \