Hi > BTW, does this get rid of the compiler warning as well? The warning did not change. I build in gcc4.6.1 of Fedora15.
------- apcsmart.c: In function 'apcsmart_hostlist': apcsmart.c:725:34: error: cast discards '__attribute__((const))' qualifier from pointer target type [-Werror=cast-qual] cc1: all warnings being treated as errors ------ Regards, Tomo 2011/10/13 Lars Ellenberg <[email protected]> > On Wed, Oct 12, 2011 at 09:03:47PM +0200, Dejan Muhamedagic wrote: > > On Mon, Jul 04, 2011 at 09:42:55PM +0100, Pádraig Brady wrote: > > > On 01/07/11 11:23, Dejan Muhamedagic wrote: > > > > Hi, > > > > > > > > On Fri, Jul 01, 2011 at 01:37:32AM +0100, Pádraig Brady wrote: > > > >> On 30/06/11 20:33, Lars Ellenberg wrote: > > > >>> On Wed, Jun 29, 2011 at 12:55:08PM +0100, Pádraig Brady wrote: > > > >>>> On 29/06/11 11:56, Lars Ellenberg wrote: > > > >>>>> On Tue, Jun 28, 2011 at 01:44:23AM +0100, Pádraig Brady wrote: > > > >>>>>> The attached patch fixes compilation -Werrors with GCC 4.6 > > > >>>>>> > > > >>>>>> cheers, > > > >>>>>> Pádraig. > > > >>>>>> > > > >>>>> > > > >>>>>> Fix compilation with GCC 4.6 > > > >>>>>> > > > >>>>>> avoid -Werror=unused-but-set-variable issues > > > >>>>>> remove -Wcast-qual which caused issues with copyHostList() > > > >>>>> > > > >>>>> Care to explain or show those "issues"? > > > >>>> > > > >>>> All uses of copyHostList error like: > > > >>>> > > > >>>> apcsmart.c: In function 'apcsmart_hostlist': > > > >>>> apcsmart.c:722:34: error: to be safe all intermediate pointers in > cast from 'char **' to 'const char **' must be 'const' qualified > [-Werror=cast-qual] > > > >>> > > > >>> From the gcc 4.5 documentation: > > > >>> -Wcast-qual > > > >>> Warn whenever a pointer is cast so as to remove a type > qualifier from the target > > > >>> type. For example, warn if a const char * is cast to an > ordinary char *. > > > >>> Also warn when making a cast which introduces a type > qualifier in an unsafe > > > >>> way. For example, casting char ** to const char ** is > unsafe, as in this ex- > > > >>> ample: > > > >>> /* p is char ** value. */ > > > >>> const char **q = (const char **) p; > > > >>> /* Assignment of readonly string to const char * is > OK. > > > >>> *q = "string"; > > > >>> /* Now char** pointer points to read-only memory. > */ > > > >>> **p = ’b’; > > > >>> > > > >>> So apparently it needs to be > > > >>> > > > >>> include/stonith/stonith_plugin.h: > > > >>> struct StonithImports_s { > > > >>> ... > > > >>> - char **(*CopyHostList)(const char ** hlstring); > > > >>> + char **(*CopyHostList)(const char * const * hlstring); > > > >>> > > > >>> And the callers have to be adjusted accordingly? > > > >>> Could you check if that works? > > > >> > > > >> Sure, that would work but would involve a lot of changes I think. > > > >> I was unsure how changing this interface might affect users > > > >> outside this project, but if that's OK I'll go ahead > > > >> and change that (tomorrow when I'm more awake). > > > > > > > > It should be OK. It is a change which may break compilation, then > > > > if somebody's using the libraries they should fix their code > > > > accordingly. > > > > > > I had another look, and I think this introduces too much churn. > > > Sometimes new GCC warnings are a little intrusive for general use > > > and I think -Wcast-qual is in this category for the moment. > > > > It could be that we're just really unlucky with cast-qual and how > > some stonith internals were done. > > > > > The specific pattern at issue here is: > > > char ** array_of_strings; > > > > > > One should be able to cast to the appropriate > > > level of constness to: > > > > > > sort (const char**); > > > copy (const char* const*); > > > free (char **); > > > > > > So please consider my last patch instead. > > > > I did just now, very sorry for such a delay. Applied as two > > patches, one to disable cast-qual and another to drop unused > > vars. > > > > Many thanks for the patches. > > BTW, does this get rid of the compiler warning as well? > > - return OurImports->CopyHostList((const char **)ad->hostlist); > + return OurImports->CopyHostList((const char **)(const char * const > *)ad->hostlist); > > If it does, maybe introducing a > #define CONST_CHAR_PP_CAST(x) ((const char **)(const char * const *)(x)) > #define COPY_HOSTLIST_CAST(x) CONST_CHAR_PP_CAST(x) > would enable us to keep -Wcast-qual for now? > > Makes it easier as well, if we later chose to change the interface to > take const char * const *. > > -- > : Lars Ellenberg > : LINBIT | Your Way to High Availability > : DRBD/HA support and consulting http://www.linbit.com > _______________________________________________________ > Linux-HA-Dev: [email protected] > http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev > Home Page: http://linux-ha.org/ >
_______________________________________________________ Linux-HA-Dev: [email protected] http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev Home Page: http://linux-ha.org/
