

Marc G. Fournier                                
Systems Administrator @ hub.org 
primary: scrappy@hub.org           secondary: scrappy@{freebsd|postgresql}.org 

---------- Forwarded message ----------
Date: Sat, 23 Jan 1999 07:42:19 -0500 (EST)
From: D'Arcy J.M. Cain <darcy@druid.net>
To: pgsql-hackers@postgreSQL.org
Subject: [HACKERS] Adding some const keywords to external interfaces

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, const char *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, const char *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.


Sun, 24 Jan 1999 04:13:01 -0400 (AST)
The Hermit Hacker <scrappy@hub.org>
[HACKERS] Adding some const keywords to external interfaces (fwd)