Skip site navigation (1) Skip section navigation (2)

Re: Add missing const qualifier in ECPG

From: Qingqing Zhou <zhouqq(at)cs(dot)toronto(dot)edu>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Subject: Re: Add missing const qualifier in ECPG
Date: 2005-11-16 00:59:38
Message-ID: Pine.LNX.4.58.0511151955340.2772@eon.cs (view raw or flat)
Thread:
Lists: pgsql-patches

On Sun, 13 Nov 2005, Peter Eisentraut wrote:
> >
> > ! 	(*stmt)->command = (char *)query;
> >   	(*stmt)->connection = connection;
> >   	(*stmt)->lineno = lineno;
> >   	(*stmt)->compat = compat;
>
> This sort of "cheating" should be avoided.
>

According to Peter's comment, revised patch is attached. It duplicates the
values of the query string and free it at the end of the query. There is
another question -- seems we allow strdup() fails silently in various
places. Shall we do something about it?

Regards,
Qingqing

---

Index: ecpglib/descriptor.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v
retrieving revision 1.12
diff -c -r1.12 descriptor.c
*** ecpglib/descriptor.c	29 Aug 2004 05:06:59 -0000	1.12
--- ecpglib/descriptor.c	16 Nov 2005 00:40:57 -0000
***************
*** 49,55 ****
  }

  bool
! ECPGget_desc_header(int lineno, char *desc_name, int *count)
  {
  	PGresult   *ECPGresult;
  	struct sqlca_t *sqlca = ECPGget_sqlca();
--- 49,55 ----
  }

  bool
! ECPGget_desc_header(int lineno, const char *desc_name, int *count)
  {
  	PGresult   *ECPGresult;
  	struct sqlca_t *sqlca = ECPGget_sqlca();
***************
*** 188,194 ****
  }

  bool
! ECPGget_desc(int lineno, char *desc_name, int index,...)
  {
  	va_list		args;
  	PGresult   *ECPGresult;
--- 188,194 ----
  }

  bool
! ECPGget_desc(int lineno, const char *desc_name, int index,...)
  {
  	va_list		args;
  	PGresult   *ECPGresult;
***************
*** 431,437 ****
  }

  bool
! ECPGset_desc_header(int lineno, char *desc_name, int count)
  {
  	struct descriptor *desc;

--- 431,437 ----
  }

  bool
! ECPGset_desc_header(int lineno, const char *desc_name, int count)
  {
  	struct descriptor *desc;

***************
*** 452,458 ****
  }

  bool
! ECPGset_desc(int lineno, char *desc_name, int index,...)
  {
  	va_list		args;
  	struct descriptor *desc;
--- 452,458 ----
  }

  bool
! ECPGset_desc(int lineno, const char *desc_name, int index,...)
  {
  	va_list		args;
  	struct descriptor *desc;
Index: ecpglib/execute.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v
retrieving revision 1.43
diff -c -r1.43 execute.c
*** ecpglib/execute.c	15 Oct 2005 02:49:47 -0000	1.43
--- ecpglib/execute.c	16 Nov 2005 00:40:57 -0000
***************
*** 141,147 ****
   * ind_offset - indicator offset
   */
  static bool
! create_statement(int lineno, int compat, int force_indicator, struct connection * connection, struct statement ** stmt, char *query, va_list ap)
  {
  	struct variable **list = &((*stmt)->inlist);
  	enum ECPGttype type;
--- 141,148 ----
   * ind_offset - indicator offset
   */
  static bool
! create_statement(int lineno, int compat, int force_indicator, struct connection * connection, struct statement ** stmt, const char
! *query, va_list ap)
  {
  	struct variable **list = &((*stmt)->inlist);
  	enum ECPGttype type;
***************
*** 149,155 ****
  	if (!(*stmt = (struct statement *) ECPGalloc(sizeof(struct statement), lineno)))
  		return false;

! 	(*stmt)->command = query;
  	(*stmt)->connection = connection;
  	(*stmt)->lineno = lineno;
  	(*stmt)->compat = compat;
--- 150,156 ----
  	if (!(*stmt = (struct statement *) ECPGalloc(sizeof(struct statement), lineno)))
  		return false;

! 	(*stmt)->command = strdup(query);
  	(*stmt)->connection = connection;
  	(*stmt)->lineno = lineno;
  	(*stmt)->compat = compat;
***************
*** 224,229 ****
--- 225,231 ----
  		return;
  	free_variable(stmt->inlist);
  	free_variable(stmt->outlist);
+ 	ECPGfree(stmt->command);
  	ECPGfree(stmt);
  }

***************
*** 1359,1365 ****
  }

  bool
! ECPGdo(int lineno, int compat, int force_indicator, const char *connection_name, char *query,...)
  {
  	va_list		args;
  	struct statement *stmt;
--- 1361,1367 ----
  }

  bool
! ECPGdo(int lineno, int compat, int force_indicator, const char *connection_name, const char *query,...)
  {
  	va_list		args;
  	struct statement *stmt;
***************
*** 1417,1423 ****
  ECPGdo_descriptor(int line, const char *connection,
  				  const char *descriptor, const char *query)
  {
! 	return ECPGdo(line, ECPG_COMPAT_PGSQL, true, connection, (char *) query, ECPGt_EOIT,
  				  ECPGt_descriptor, descriptor, 0L, 0L, 0L,
  				  ECPGt_NO_INDICATOR, NULL, 0L, 0L, 0L, ECPGt_EORT);
  }
--- 1419,1425 ----
  ECPGdo_descriptor(int line, const char *connection,
  				  const char *descriptor, const char *query)
  {
! 	return ECPGdo(line, ECPG_COMPAT_PGSQL, true, connection, query, ECPGt_EOIT,
  				  ECPGt_descriptor, descriptor, 0L, 0L, 0L,
  				  ECPGt_NO_INDICATOR, NULL, 0L, 0L, 0L, ECPGt_EORT);
  }
Index: ecpglib/memory.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/interfaces/ecpg/ecpglib/memory.c,v
retrieving revision 1.7
diff -c -r1.7 memory.c
*** ecpglib/memory.c	15 Oct 2005 02:49:47 -0000	1.7
--- ecpglib/memory.c	16 Nov 2005 00:40:57 -0000
***************
*** 11,17 ****
  void
  ECPGfree(void *ptr)
  {
! 	free(ptr);
  }

  char *
--- 11,18 ----
  void
  ECPGfree(void *ptr)
  {
! 	if (ptr)
! 		free(ptr);
  }

  char *
Index: ecpglib/prepare.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/interfaces/ecpg/ecpglib/prepare.c,v
retrieving revision 1.14
diff -c -r1.14 prepare.c
*** ecpglib/prepare.c	15 Oct 2005 02:49:47 -0000	1.14
--- ecpglib/prepare.c	16 Nov 2005 00:40:57 -0000
***************
*** 60,66 ****

  /* handle the EXEC SQL PREPARE statement */
  bool
! ECPGprepare(int lineno, char *name, char *variable)
  {
  	struct statement *stmt;
  	struct prepared_statement *this;
--- 60,66 ----

  /* handle the EXEC SQL PREPARE statement */
  bool
! ECPGprepare(int lineno, const char *name, const char *variable)
  {
  	struct statement *stmt;
  	struct prepared_statement *this;
***************
*** 112,118 ****

  /* handle the EXEC SQL DEALLOCATE PREPARE statement */
  bool
! ECPGdeallocate(int lineno, int c, char *name)
  {
  	bool		ret = ECPGdeallocate_one(lineno, name);
  	enum COMPAT_MODE compat = c;
--- 112,118 ----

  /* handle the EXEC SQL DEALLOCATE PREPARE statement */
  bool
! ECPGdeallocate(int lineno, int c, const char *name)
  {
  	bool		ret = ECPGdeallocate_one(lineno, name);
  	enum COMPAT_MODE compat = c;
***************
*** 133,139 ****
  }

  bool
! ECPGdeallocate_one(int lineno, char *name)
  {
  	struct prepared_statement *this,
  			   *prev;
--- 133,139 ----
  }

  bool
! ECPGdeallocate_one(int lineno, const char *name)
  {
  	struct prepared_statement *this,
  			   *prev;
Index: include/ecpglib.h
===================================================================
RCS file: /projects/cvsroot/pgsql/src/interfaces/ecpg/include/ecpglib.h,v
retrieving revision 1.63
diff -c -r1.63 ecpglib.h
*** include/ecpglib.h	5 Jul 2004 09:45:53 -0000	1.63
--- include/ecpglib.h	16 Nov 2005 00:40:57 -0000
***************
*** 48,59 ****
  bool		ECPGsetcommit(int, const char *, const char *);
  bool		ECPGsetconn(int, const char *);
  bool		ECPGconnect(int, int, const char *, const char *, const char *, const char *, int);
! bool		ECPGdo(int, int, int, const char *, char *,...);
  bool		ECPGtrans(int, const char *, const char *);
  bool		ECPGdisconnect(int, const char *);
! bool		ECPGprepare(int, char *, char *);
! bool		ECPGdeallocate(int, int, char *);
! bool		ECPGdeallocate_one(int, char *);
  bool		ECPGdeallocate_all(int);
  char	   *ECPGprepared_statement(const char *);

--- 48,59 ----
  bool		ECPGsetcommit(int, const char *, const char *);
  bool		ECPGsetconn(int, const char *);
  bool		ECPGconnect(int, int, const char *, const char *, const char *, const char *, int);
! bool		ECPGdo(int, int, int, const char *, const char *,...);
  bool		ECPGtrans(int, const char *, const char *);
  bool		ECPGdisconnect(int, const char *);
! bool		ECPGprepare(int, const char *, const char *);
! bool		ECPGdeallocate(int, int, const char *);
! bool		ECPGdeallocate_one(int, const char *);
  bool		ECPGdeallocate_all(int);
  char	   *ECPGprepared_statement(const char *);

***************
*** 75,84 ****
  bool		ECPGallocate_desc(int line, const char *name);
  void		ECPGraise(int line, int code, const char *sqlstate, const char *str);
  void		ECPGraise_backend(int line, PGresult *result, PGconn *conn, int compat);
! bool		ECPGget_desc_header(int, char *, int *);
! bool		ECPGget_desc(int, char *, int,...);
! bool		ECPGset_desc_header(int, char *, int);
! bool		ECPGset_desc(int, char *, int,...);

  void		ECPGset_noind_null(enum ECPGttype, void *);
  bool		ECPGis_noind_null(enum ECPGttype, void *);
--- 75,84 ----
  bool		ECPGallocate_desc(int line, const char *name);
  void		ECPGraise(int line, int code, const char *sqlstate, const char *str);
  void		ECPGraise_backend(int line, PGresult *result, PGconn *conn, int compat);
! bool		ECPGget_desc_header(int, const char *, int *);
! bool		ECPGget_desc(int, const char *, int,...);
! bool		ECPGset_desc_header(int, const char *, int);
! bool		ECPGset_desc(int, const char *, int,...);

  void		ECPGset_noind_null(enum ECPGttype, void *);
  bool		ECPGis_noind_null(enum ECPGttype, void *);

In response to

pgsql-patches by date

Next:From: Bruce MomjianDate: 2005-11-16 03:52:51
Subject: Re: pl/pgSQL doco patch
Previous:From: Alvaro HerreraDate: 2005-11-16 00:58:44
Subject: Re: [HACKERS] Per-table freeze limit proposal

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group