Lists: | pgsql-hackers |
---|
From: | Magnus Hagander <magnus(at)hagander(dot)net> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Questions about warnings |
Date: | 2007-01-25 12:18:34 |
Message-ID: | 20070125121834.GA27011@svr2.hagander.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
I'm looking over the VC build trying to eliminate what warnings are
left. One thing that appears in a couple of places is stuff like:
.\src\bin\psql\print.c(2014): warning C4090: 'function' : different
'const' qualifiers
This happens in psql when we do free() on a variable that's "const char
**". The same thing happens in oracle_compat.c in the backend with
pfree().
Is this a warning we should care about and remove (or change?) the const
qualifyer? Or should I just ignore it?
//Magnus
From: | Peter Eisentraut <peter_e(at)gmx(dot)net> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Cc: | Magnus Hagander <magnus(at)hagander(dot)net> |
Subject: | Re: Questions about warnings |
Date: | 2007-01-25 12:38:14 |
Message-ID: | 200701251338.15280.peter_e@gmx.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Magnus Hagander wrote:
> I'm looking over the VC build trying to eliminate what warnings are
> left. One thing that appears in a couple of places is stuff like:
>
> .\src\bin\psql\print.c(2014): warning C4090: 'function' : different
> 'const' qualifiers
>
> This happens in psql when we do free() on a variable that's "const
> char **". The same thing happens in oracle_compat.c in the backend
> with pfree().
The code in question is:
const char **headers;
[...]
free(headers);
> Is this a warning we should care about and remove (or change?) the
> const qualifyer? Or should I just ignore it?
My free() takes a pointer to void, which should be able to point to any
type of data, and certainly pointer to pointer to const char fits that
description. So I think the compiler is overly zealous.
Actually writing into the supposedly constant data pointed to by
a "const type *" pointer would be a potential bug, but GCC catches
that, so we can be reasonably assured that this is OK in the current
code.
--
Peter Eisentraut
http://developer.postgresql.org/~petere/
From: | Gregory Stark <stark(at)enterprisedb(dot)com> |
---|---|
To: | "Peter Eisentraut" <peter_e(at)gmx(dot)net> |
Cc: | <pgsql-hackers(at)postgresql(dot)org>, "Magnus Hagander" <magnus(at)hagander(dot)net> |
Subject: | Re: Questions about warnings |
Date: | 2007-01-25 13:11:15 |
Message-ID: | 873b5zckuk.fsf@stark.xeocode.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
"Peter Eisentraut" <peter_e(at)gmx(dot)net> writes:
> The code in question is:
>
> const char **headers;
>
> [...]
>
> free(headers);
Perhaps it ought not be declared "const char **headers" if you're planning on
freeing it? I mean, it's not like you can pass an actual pointer to constant
memory to this function and expect it to work, and who says free doesn't
modify the data the pointer points to anyways, plenty do.
--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
From: | Magnus Hagander <magnus(at)hagander(dot)net> |
---|---|
To: | Peter Eisentraut <peter_e(at)gmx(dot)net> |
Cc: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Questions about warnings |
Date: | 2007-01-25 13:18:57 |
Message-ID: | 20070125131857.GD27011@svr2.hagander.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Thu, Jan 25, 2007 at 01:38:14PM +0100, Peter Eisentraut wrote:
> Magnus Hagander wrote:
> > I'm looking over the VC build trying to eliminate what warnings are
> > left. One thing that appears in a couple of places is stuff like:
> >
> > .\src\bin\psql\print.c(2014): warning C4090: 'function' : different
> > 'const' qualifiers
> >
> > This happens in psql when we do free() on a variable that's "const
> > char **". The same thing happens in oracle_compat.c in the backend
> > with pfree().
>
> The code in question is:
>
> const char **headers;
>
> [...]
>
> free(headers);
Right, and similar code for pfree().
> > Is this a warning we should care about and remove (or change?) the
> > const qualifyer? Or should I just ignore it?
>
> My free() takes a pointer to void, which should be able to point to any
> type of data, and certainly pointer to pointer to const char fits that
> description. So I think the compiler is overly zealous.
>
> Actually writing into the supposedly constant data pointed to by
> a "const type *" pointer would be a potential bug, but GCC catches
> that, so we can be reasonably assured that this is OK in the current
> code.
I won't claim to know the inners good enough to comment on it. Does
"const char **" really mean that the point is const, or the pointer that
it points to is const?
Anyway, I'll just ignore the warnings then. I'll leave them enabled
in the compiler since they might catch other similar things that are
actually bugs in the future, and it's only 6 warnings in psql and 2 in
oracle_compat in total..
//Magnus
From: | Gregory Stark <stark(at)enterprisedb(dot)com> |
---|---|
To: | "Magnus Hagander" <magnus(at)hagander(dot)net> |
Cc: | "Peter Eisentraut" <peter_e(at)gmx(dot)net>, <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Questions about warnings |
Date: | 2007-01-25 13:20:10 |
Message-ID: | 87y7nrb5v9.fsf@stark.xeocode.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
"Magnus Hagander" <magnus(at)hagander(dot)net> writes:
> I won't claim to know the inners good enough to comment on it. Does
> "const char **" really mean that the point is const, or the pointer that
> it points to is const?
"const char **" means the character at the end of the pointer chain is
constant. Which means my previous message is misguided, ignore it, sorry. In
short, yes, this is a limitation of the const syntax in C and you have to cast
it away in this case.
--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
From: | Gavin Sherry <swm(at)alcove(dot)com(dot)au> |
---|---|
To: | Magnus Hagander <magnus(at)hagander(dot)net> |
Cc: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Questions about warnings |
Date: | 2007-01-25 13:26:45 |
Message-ID: | Pine.LNX.4.58.0701260020270.3382@linuxworld.com.au |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Thu, 25 Jan 2007, Magnus Hagander wrote:
> I'm looking over the VC build trying to eliminate what warnings are
> left. One thing that appears in a couple of places is stuff like:
>
> .\src\bin\psql\print.c(2014): warning C4090: 'function' : different
> 'const' qualifiers
Seems like other projects have encountered this problem. Looks like a
simple type difference. Casting to (void *) should fix it.
http://mirror.ethereal.com/lists/ethereal-dev/200502/msg00170.html
Gavin
From: | Magnus Hagander <magnus(at)hagander(dot)net> |
---|---|
To: | Gavin Sherry <swm(at)alcove(dot)com(dot)au> |
Cc: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Questions about warnings |
Date: | 2007-01-25 13:34:38 |
Message-ID: | 20070125133438.GE27011@svr2.hagander.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Fri, Jan 26, 2007 at 12:26:45AM +1100, Gavin Sherry wrote:
> On Thu, 25 Jan 2007, Magnus Hagander wrote:
>
> > I'm looking over the VC build trying to eliminate what warnings are
> > left. One thing that appears in a couple of places is stuff like:
> >
> > .\src\bin\psql\print.c(2014): warning C4090: 'function' : different
> > 'const' qualifiers
>
> Seems like other projects have encountered this problem. Looks like a
> simple type difference. Casting to (void *) should fix it.
>
> http://mirror.ethereal.com/lists/ethereal-dev/200502/msg00170.html
The question is if we care enough. I'll be happy to provide a patch or
just a list of locations where it happens if that's what's wanted.
//Magnus
From: | Martijn van Oosterhout <kleptog(at)svana(dot)org> |
---|---|
To: | Gregory Stark <stark(at)enterprisedb(dot)com> |
Cc: | Magnus Hagander <magnus(at)hagander(dot)net>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Questions about warnings |
Date: | 2007-01-25 13:49:49 |
Message-ID: | 20070125134949.GC13744@svana.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Thu, Jan 25, 2007 at 01:20:10PM +0000, Gregory Stark wrote:
> "const char **" means the character at the end of the pointer chain is
> constant. Which means my previous message is misguided, ignore it, sorry. In
> short, yes, this is a limitation of the const syntax in C and you have to cast
> it away in this case.
Well, you can say things like:
char * const *ptr
Which means that *ptr is const, but ptr and **ptr are not. Each of
those can be made const/not const as desired...
What is intended here is quite a different question, the use of pointers
in that part of psql is a bit haphazard at times. FWIW, Coverity
complains about stuff here too, but I just marked it all WONTFIX :).
Have anice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.
From: | Andrew Dunstan <andrew(at)dunslane(dot)net> |
---|---|
To: | Gavin Sherry <swm(at)alcove(dot)com(dot)au> |
Cc: | Magnus Hagander <magnus(at)hagander(dot)net>, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Questions about warnings |
Date: | 2007-01-25 14:05:28 |
Message-ID: | 45B8B928.9090801@dunslane.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Gavin Sherry wrote:
> On Thu, 25 Jan 2007, Magnus Hagander wrote:
>
>
>> I'm looking over the VC build trying to eliminate what warnings are
>> left. One thing that appears in a couple of places is stuff like:
>>
>> .\src\bin\psql\print.c(2014): warning C4090: 'function' : different
>> 'const' qualifiers
>>
>
> Seems like other projects have encountered this problem. Looks like a
> simple type difference. Casting to (void *) should fix it.
>
> http://mirror.ethereal.com/lists/ethereal-dev/200502/msg00170.html
>
>
>
But note that Tom recently (correctly) chided me thus:
> Oh, and casting away const gets no points for style.
cheers
andrew