Add missing const qualifier in ECPG
Add missing const qualifier to (char *) parameters in ECPG. Per reported
by Tomasz Ostrowski.
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 12 Nov 2005 22:11:18 -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 12 Nov 2005 22:11:18 -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 = (char *)query;
(*stmt)->connection = connection;
(*stmt)->lineno = lineno;
(*stmt)->compat = compat;
***************
*** 1359,1365 ****
}
bool
! ECPGdo(int lineno, int compat, int force_indicator, const char *connection_name, char *query,...)
{
va_list args;
struct statement *stmt;
--- 1360,1366 ----
}
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);
}
--- 1418,1424 ----
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/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 12 Nov 2005 22:11:18 -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 12 Nov 2005 22:11:18 -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 *);
Qingqing Zhou wrote:
***************
*** 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 = (char *)query;
(*stmt)->connection = connection;
(*stmt)->lineno = lineno;
(*stmt)->compat = compat;
This sort of "cheating" should be avoided.
--
Peter Eisentraut
http://developer.postgresql.org/~petere/
On Sat, 12 Nov 2005, Peter Eisentraut wrote:
Qingqing Zhou wrote:
***************
*** 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 = (char *)query;
(*stmt)->connection = connection;
(*stmt)->lineno = lineno;
(*stmt)->compat = compat;This sort of "cheating" should be avoided.
Yeah ... this is a "cheating" trade ... :-)
*** 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);
}
--- 1418,1424 ----
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);
}
Regards,
Qingqing
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 *);
I just applied most of your patch to 8.0, 8.1 and HEAD. The only thing I
didn't is:
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 *
Is there a reason why you changed this? Acocrding to the docs free(NULL)
does nothing anyway.
Also you mentioned:
...
seems we allow strdup() fails silently in various
places. Shall we do something about it?
...
Yes! Thanks for pointing this out. I already committed a patch that
changes alls strdup() calls to ECPGstrdup() calls that correctly raise
an error condition.
Michael
--
Michael Meskes
Email: Michael at Fam-Meskes dot De, Michael at Meskes dot (De|Com|Net|Org)
ICQ: 179140304, AIM/Yahoo: michaelmeskes, Jabber: meskes@jabber.org
Go SF 49ers! Go Rhein Fire! Use Debian GNU/Linux! Use PostgreSQL!
Import Notes
Resolved by subject fallback