Re: libpq: PQcmdStatus, PQcmdTuples signatures can be painlessly improved
От | Alex Goncharov |
---|---|
Тема | Re: libpq: PQcmdStatus, PQcmdTuples signatures can be painlessly improved |
Дата | |
Msg-id | E1Rkh5R-000IlI-ES@hans3 обсуждение исходный текст |
Ответ на | Re: libpq: PQcmdStatus, PQcmdTuples signatures can be painlessly improved (Peter Eisentraut <peter_e@gmx.net>) |
Ответы |
Re: libpq: PQcmdStatus, PQcmdTuples signatures can be
painlessly improved
|
Список | pgsql-hackers |
,--- You/Peter (Tue, 10 Jan 2012 19:13:42 +0200) ----* | On tis, 2011-12-13 at 07:55 -0500, Alex Goncharov wrote: | > char *PQcmdStatus(PGresult *res); | > char *PQcmdTuples(PGresult *res); | > | > Unreasonable: | > | > a. What, these two can modify 'res' I pass in?.. | > | > b. Oh, yes, because they return 'char *' pointing to | > 'res->cmdStatus+n', so, a libpq user may write: | > | > char *s = PQcmdStatus(res); | > *s = 'x'; | > | > and have 'res' modified. (Would be the user's fault, of course.) | > | Note that const PGresult * would only warn against changing the | fields It would not warn, it would err (the compilation should fail). | of the PGresult struct. It doesn't do anything about changing the data | pointed to by pointers in the PGresult struct. So what you are saying | doesn't follow. By this logic, passing 'const struct foo *' doesn't have any point and value, for any function. But we know that this is done (and thank you for that) in many cases -- a good style, self-documentation and some protection. E.g. here: ,--- I/Alex (Tue, 13 Dec 2011 07:55:45 -0500) ----* | Compare: | | int PQntuples(const PGresult *res) | | Reasonable: doesn't modify 'res'. `-------------------------------------------------* BTW, I have not submitted the context differences, as suggested, only because of extreme overload at work and the need to do a careful caller and documentation analysis. I still hope to be able to do it in a reasonably near future. -- Alex -- alex-goncharov@comcast.net --
В списке pgsql-hackers по дате отправления: