From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30272 invoked by alias); 1 Jun 2011 17:54:13 -0000 Received: (qmail 30264 invoked by uid 22791); 1 Jun 2011 17:54:13 -0000 X-SWARE-Spam-Status: No, hits=-0.8 required=5.0 tests=AWL,BAYES_00,RDNS_DYNAMIC,TVD_RCVD_IP X-Spam-Check-By: sourceware.org Received: from 195-14-0-142.nuxit.net (HELO de558.ispfr.net) (195.14.0.142) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 01 Jun 2011 17:53:57 +0000 Received: from ours.starynkevitch.net ([213.41.244.95] helo=glinka.lesours) by de558.ispfr.net with smtp (Exim 4.72) (envelope-from ) id 1QRpcA-00024f-T4; Wed, 01 Jun 2011 19:53:55 +0200 Date: Wed, 01 Jun 2011 17:54:00 -0000 From: Basile Starynkevitch To: Pierre Cc: gcc-patches@gcc.gnu.org, joseph@codesourcery.com Subject: Re: [PATCH] c-pragma: adding a data field to pragma_handler Message-Id: <20110601195353.b05f964a.basile@starynkevitch.net> In-Reply-To: <4DE66ECE.5030102@laposte.net> References: <4DE66ECE.5030102@laposte.net> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-06/txt/msg00080.txt.bz2 On Wed, 01 Jun 2011 18:54:38 +0200 Pierre wrote: > This patch is about the pragmas. > > In c-family/c-pragma.h, we declare a pragma_handler which is a function > accepting cpp_reader as parameter. > > I have changed this handler in order to accept a second parameter which > is a void *, allowing to give extra datas to the handler. I think this > data field might be of general use: we can have condition or data at > register time that we want to express in the handler. I guess this is a > common way to pass data to an handler function. I find this patch interesting and useful (& not only for MELT). A general coding rule in C seems to be that every time function can be variably called thru indirect pointers (which can have several different functions as value), they better take an extra data argument. This is the case, in particular, inside Glib & GTK, inside the Linux kernel, and on several other occurrences in GCC. A use case of such pragma handlers with data for pragmas would be a plugin which permit some messages to other channels than stdout/stderr (e.g. other files, or a pipe, or the D-Bus, or a widget, or a web service...). Then the same routine would handle #pragma GCCPLUGIN message_to_file "foo" and #pragma GCCPLUGIN message_to_pipe "bar" and the data pointer would be different (an fopen-ed or popen-ed FILE*, or even an std::ostream& if the plugin is coded in C++). I am not authorized to ok the patch (I believe the changelog had some typos), but I hope someone will review & ok it. Regards -- Basile STARYNKEVITCH http://starynkevitch.net/Basile/ email: basilestarynkevitchnet mobile: +33 6 8501 2359 8, rue de la Faiencerie, 92340 Bourg La Reine, France *** opinions {are only mine, sont seulement les miennes} ***