Re: Adding some const keywords to external interfaces

Поиск
Список
Период
Сортировка
От Bruce Momjian
Тема Re: Adding some const keywords to external interfaces
Дата
Msg-id 199902040322.WAA06411@candle.pha.pa.us
обсуждение исходный текст
Ответ на Adding some const keywords to external interfaces  ("D'Arcy" "J.M." Cain <darcy@druid.net>)
Список pgsql-hackers
I have applied this.  D'Arcy feels it is safe, and I think I agree now.

If anyone has a problem, let us know.  He believes it completes
constification of the libpq API.


> I am sending this patch to hackers because I think it needs some
> discussion before being added.  I'm not 100% sure that there
> isn't some internal issue with making these changes but so far
> it seems to work for me.
> 
> In interfaces/libpq/libpq-fe.h there are some structures that include
> char pointers.  Often one would expect the user to send const strings
> to the functions using these pointers.  The following keeps external
> programs from failing when full error checking is enabled.
> 
> 
> *** ../src.original/./interfaces/libpq/libpq-fe.h    Sat Jan 16 07:33:49 1999
> --- ./interfaces/libpq/libpq-fe.h    Fri Jan 22 07:14:21 1999
> ***************
> *** 100,108 ****
>           pqbool        html3;        /* output html tables */
>           pqbool        expanded;    /* expand tables */
>           pqbool        pager;        /* use pager for output if needed */
> !         char       *fieldSep;    /* field separator */
> !         char       *tableOpt;    /* insert to HTML <table ...> */
> !         char       *caption;    /* HTML <caption> */
>           char      **fieldName;    /* null terminated array of repalcement
>                                    * field names */
>       } PQprintOpt;
> --- 100,108 ----
>           pqbool        html3;        /* output html tables */
>           pqbool        expanded;    /* expand tables */
>           pqbool        pager;        /* use pager for output if needed */
> !         const char *fieldSep;    /* field separator */
> !         const char *tableOpt;    /* insert to HTML <table ...> */
> !         const char *caption;    /* HTML <caption> */
>           char      **fieldName;    /* null terminated array of repalcement
>                                    * field names */
>       } PQprintOpt;
> ***************
> *** 113,124 ****
>    */
>       typedef struct _PQconninfoOption
>       {
> !         char       *keyword;    /* The keyword of the option            */
> !         char       *envvar;    /* Fallback environment variable name    */
> !         char       *compiled;    /* Fallback compiled in default value    */
> !         char       *val;        /* Options value                        */
> !         char       *label;        /* Label for field in connect dialog    */
> !         char       *dispchar;    /* Character to display for this field    */
>                                   /* in a connect dialog. Values are:        */
>                                   /* ""    Display entered value as is  */
>                                   /* "*"    Password field - hide value  */
> --- 113,124 ----
>    */
>       typedef struct _PQconninfoOption
>       {
> !         const char    *keyword;    /* The keyword of the option            */
> !         const char    *envvar;    /* Fallback environment variable name    */
> !         const char    *compiled;    /* Fallback compiled in default value    */
> !         char        *val;        /* Options value                        */
> !         const char    *label;        /* Label for field in connect dialog    */
> !         const char    *dispchar;    /* Character to display for this field    */
>                                   /* in a connect dialog. Values are:        */
>                                   /* ""    Display entered value as is  */
>                                   /* "*"    Password field - hide value  */
> *** ../src.original/./interfaces/libpq/fe-print.c    Fri Jan 22 07:02:10 1999
> --- ./interfaces/libpq/fe-print.c    Fri Jan 22 07:03:09 1999
> ***************
> *** 681,687 ****
>           p = border;
>           if (po->standard)
>           {
> !             char       *fs = po->fieldSep;
>   
>               while (*fs++)
>                   *p++ = '+';
> --- 681,687 ----
>           p = border;
>           if (po->standard)
>           {
> !             const char       *fs = po->fieldSep;
>   
>               while (*fs++)
>                   *p++ = '+';
> ***************
> *** 693,699 ****
>               for (len = fieldMax[j] + (po->standard ? 2 : 0); len--; *p++ = '-');
>               if (po->standard || (j + 1) < nFields)
>               {
> !                 char       *fs = po->fieldSep;
>   
>                   while (*fs++)
>                       *p++ = '+';
> --- 693,699 ----
>               for (len = fieldMax[j] + (po->standard ? 2 : 0); len--; *p++ = '-');
>               if (po->standard || (j + 1) < nFields)
>               {
> !                 const char       *fs = po->fieldSep;
>   
>                   while (*fs++)
>                       *p++ = '+';
> *** ../src.original/./interfaces/libpq/fe-connect.c    Fri Jan 22 07:04:03 1999
> --- ./interfaces/libpq/fe-connect.c    Fri Jan 22 07:13:09 1999
> ***************
> *** 48,54 ****
>   static void freePGconn(PGconn *conn);
>   static void closePGconn(PGconn *conn);
>   static int    conninfo_parse(const char *conninfo, char *errorMessage);
> ! static char *conninfo_getval(char *keyword);
>   static void conninfo_free(void);
>   static void defaultNoticeProcessor(void *arg, const char *message);
>   
> --- 48,54 ----
>   static void freePGconn(PGconn *conn);
>   static void closePGconn(PGconn *conn);
>   static int    conninfo_parse(const char *conninfo, char *errorMessage);
> ! static const char *conninfo_getval(const char *keyword);
>   static void conninfo_free(void);
>   static void defaultNoticeProcessor(void *arg, const char *message);
>   
> ***************
> *** 172,179 ****
>   PGconn *
>   PQconnectdb(const char *conninfo)
>   {
> !     PGconn       *conn;
> !     char       *tmp;
>   
>       /* ----------
>        * Allocate memory for the conn structure
> --- 172,179 ----
>   PGconn *
>   PQconnectdb(const char *conninfo)
>   {
> !     PGconn           *conn;
> !     const char       *tmp;
>   
>       /* ----------
>        * Allocate memory for the conn structure
> ***************
> *** 284,291 ****
>   PGconn *
>   PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, const char *pgtty, const char *dbName,
constchar *login, const char *pwd)
 
>   {
> !     PGconn       *conn;
> !     char       *tmp;
>   
>       /* An error message from some service we call. */
>       bool        error = FALSE;
> --- 284,291 ----
>   PGconn *
>   PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, const char *pgtty, const char *dbName,
constchar *login, const char *pwd)
 
>   {
> !     PGconn        *conn;
> !     const char    *tmp;
>   
>       /* An error message from some service we call. */
>       bool        error = FALSE;
> ***************
> *** 1137,1143 ****
>       char       *pname;
>       char       *pval;
>       char       *buf;
> !     char       *tmp;
>       char       *cp;
>       char       *cp2;
>       PQconninfoOption *option;
> --- 1137,1143 ----
>       char       *pname;
>       char       *pval;
>       char       *buf;
> !     const char *tmp;
>       char       *cp;
>       char       *cp2;
>       PQconninfoOption *option;
> ***************
> *** 1343,1350 ****
>   }
>   
>   
> ! static char *
> ! conninfo_getval(char *keyword)
>   {
>       PQconninfoOption *option;
>   
> --- 1343,1350 ----
>   }
>   
>   
> ! static const char *
> ! conninfo_getval(const char *keyword)
>   {
>       PQconninfoOption *option;
>   
> 
> -- 
> D'Arcy J.M. Cain <darcy@{druid|vex}.net>   |  Democracy is three wolves
> http://www.druid.net/darcy/                |  and a sheep voting on
> +1 416 424 2871     (DoD#0082)    (eNTP)   |  what's for dinner.
> 
> 


--  Bruce Momjian                        |  http://www.op.net/~candle maillist@candle.pha.pa.us            |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026
 


В списке pgsql-hackers по дате отправления:

Предыдущее
От: The Hermit Hacker
Дата:
Сообщение: Re: [HACKERS] template/alpha_cc
Следующее
От: "Hiroshi Inoue"
Дата:
Сообщение: RE: [HACKERS] 6.5 beta and ORDER BY patch