From f9bdaeeb346065fe45b8761217c869c80e1c89b4 Mon Sep 17 00:00:00 2001 From: Michael Meskes Date: Wed, 30 Nov 2005 12:51:07 +0000 Subject: [PATCH] - Made several variables "const char *" instead of "char *" as proposed by Qingqing Zhou . - Replaced all strdup() calls by ECPGstrdup(). --- src/interfaces/ecpg/ecpglib/connect.c | 26 ++++++++++++------------ src/interfaces/ecpg/ecpglib/descriptor.c | 12 +++++------ src/interfaces/ecpg/ecpglib/execute.c | 11 +++++----- src/interfaces/ecpg/ecpglib/prepare.c | 8 ++++---- src/interfaces/ecpg/include/ecpglib.h | 16 +++++++-------- 5 files changed, 37 insertions(+), 36 deletions(-) diff --git a/src/interfaces/ecpg/ecpglib/connect.c b/src/interfaces/ecpg/ecpglib/connect.c index 26997d9f6b1..3f0bc62fa5d 100644 --- a/src/interfaces/ecpg/ecpglib/connect.c +++ b/src/interfaces/ecpg/ecpglib/connect.c @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.24.4.1 2005/04/14 10:09:20 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.24.4.2 2005/11/30 12:51:06 meskes Exp $ */ #define POSTGRES_ECPG_INTERNAL #include "postgres_fe.h" @@ -260,7 +260,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p struct sqlca_t *sqlca = ECPGget_sqlca(); enum COMPAT_MODE compat = c; struct connection *this; - char *dbname = name ? strdup(name) : NULL, + char *dbname = name ? ECPGstrdup(name, lineno) : NULL, *host = NULL, *tmp, *port = NULL, @@ -282,7 +282,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p if (envname) { ECPGfree(dbname); - dbname = strdup(envname); + dbname = ECPGstrdup(envname, lineno); } } @@ -302,17 +302,17 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p tmp = strrchr(dbname, ':'); if (tmp != NULL) /* port number given */ { - port = strdup(tmp + 1); + port = ECPGstrdup(tmp + 1, lineno); *tmp = '\0'; } tmp = strrchr(dbname, '@'); if (tmp != NULL) /* host name given */ { - host = strdup(tmp + 1); + host = ECPGstrdup(tmp + 1, lineno); *tmp = '\0'; } - realname = strdup(dbname); + realname = ECPGstrdup(dbname, lineno); } else if (strncmp(dbname, "tcp:", 4) == 0 || strncmp(dbname, "unix:", 5) == 0) { @@ -340,14 +340,14 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p tmp = strrchr(dbname + offset, '?'); if (tmp != NULL) /* options given */ { - options = strdup(tmp + 1); + options = ECPGstrdup(tmp + 1, lineno); *tmp = '\0'; } tmp = last_dir_separator(dbname + offset); if (tmp != NULL) /* database name given */ { - realname = strdup(tmp + 1); + realname = ECPGstrdup(tmp + 1, lineno); *tmp = '\0'; } @@ -360,7 +360,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p if ((tmp2 = strchr(tmp + 1, ':')) != NULL) { *tmp2 = '\0'; - host = strdup(tmp + 1); + host = ECPGstrdup(tmp + 1, lineno); if (strncmp(dbname, "unix:", 5) != 0) { ECPGlog("connect: socketname %s given for TCP connection in line %d\n", host, lineno); @@ -379,7 +379,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p } } else - port = strdup(tmp + 1); + port = ECPGstrdup(tmp + 1, lineno); } if (strncmp(dbname, "unix:", 5) == 0) @@ -402,14 +402,14 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p } } else - host = strdup(dbname + offset); + host = ECPGstrdup(dbname + offset, lineno); } else - realname = strdup(dbname); + realname = ECPGstrdup(dbname, lineno); } else - realname = strdup(dbname); + realname = ECPGstrdup(dbname, lineno); } else realname = NULL; diff --git a/src/interfaces/ecpg/ecpglib/descriptor.c b/src/interfaces/ecpg/ecpglib/descriptor.c index 08c8d3479ce..687f452e098 100644 --- a/src/interfaces/ecpg/ecpglib/descriptor.c +++ b/src/interfaces/ecpg/ecpglib/descriptor.c @@ -1,6 +1,6 @@ /* dynamic SQL support routines * - * $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.12 2004/08/29 05:06:59 momjian Exp $ + * $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.12.4.1 2005/11/30 12:51:06 meskes Exp $ */ #define POSTGRES_ECPG_INTERNAL @@ -49,7 +49,7 @@ ECPGDynamicType_DDT(Oid type) } bool -ECPGget_desc_header(int lineno, char *desc_name, int *count) +ECPGget_desc_header(int lineno, const char *desc_name, int *count) { PGresult *ECPGresult; struct sqlca_t *sqlca = ECPGget_sqlca(); @@ -188,7 +188,7 @@ get_char_item(int lineno, void *var, enum ECPGttype vartype, char *value, int va } bool -ECPGget_desc(int lineno, char *desc_name, int index,...) +ECPGget_desc(int lineno, const char *desc_name, int index,...) { va_list args; PGresult *ECPGresult; @@ -383,7 +383,7 @@ ECPGget_desc(int lineno, char *desc_name, int index,...) /* Make sure we do NOT honor the locale for numeric input */ /* since the database gives the standard decimal point */ - oldlocale = strdup(setlocale(LC_NUMERIC, NULL)); + oldlocale = ECPGstrdup(setlocale(LC_NUMERIC, NULL), lineno); setlocale(LC_NUMERIC, "C"); memset(&stmt, 0, sizeof stmt); @@ -431,7 +431,7 @@ ECPGget_desc(int lineno, char *desc_name, int index,...) } bool -ECPGset_desc_header(int lineno, char *desc_name, int count) +ECPGset_desc_header(int lineno, const char *desc_name, int count) { struct descriptor *desc; @@ -452,7 +452,7 @@ ECPGset_desc_header(int lineno, char *desc_name, int count) } bool -ECPGset_desc(int lineno, char *desc_name, int index,...) +ECPGset_desc(int lineno, const char *desc_name, int index,...) { va_list args; struct descriptor *desc; diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c index bc46ddb34f0..f5c0e214e75 100644 --- a/src/interfaces/ecpg/ecpglib/execute.c +++ b/src/interfaces/ecpg/ecpglib/execute.c @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.38.4.2 2005/06/02 12:37:25 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.38.4.3 2005/11/30 12:51:06 meskes Exp $ */ /* * The aim is to get a simpler inteface to the database routines. @@ -148,7 +148,7 @@ ECPGget_variable(va_list APREF, enum ECPGttype type, struct variable * var, bool * 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) +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; @@ -156,7 +156,7 @@ create_statement(int lineno, int compat, int force_indicator, struct connection if (!(*stmt = (struct statement *) ECPGalloc(sizeof(struct statement), lineno))) return false; - (*stmt)->command = query; + (*stmt)->command = ECPGstrdup(query, lineno); (*stmt)->connection = connection; (*stmt)->lineno = lineno; (*stmt)->compat = compat; @@ -231,6 +231,7 @@ free_statement(struct statement * stmt) return; free_variable(stmt->inlist); free_variable(stmt->outlist); + ECPGfree(stmt->command); ECPGfree(stmt); } @@ -1369,7 +1370,7 @@ ECPGexecute(struct statement * stmt) } bool -ECPGdo(int lineno, int compat, int force_indicator, const char *connection_name, char *query,...) +ECPGdo(int lineno, int compat, int force_indicator, const char *connection_name, const char *query,...) { va_list args; struct statement *stmt; @@ -1379,7 +1380,7 @@ ECPGdo(int lineno, int compat, int force_indicator, const char *connection_name, /* Make sure we do NOT honor the locale for numeric input/output */ /* since the database wants the standard decimal point */ - oldlocale = strdup(setlocale(LC_NUMERIC, NULL)); + oldlocale = ECPGstrdup(setlocale(LC_NUMERIC, NULL), lineno); setlocale(LC_NUMERIC, "C"); if (!ECPGinit(con, connection_name, lineno)) diff --git a/src/interfaces/ecpg/ecpglib/prepare.c b/src/interfaces/ecpg/ecpglib/prepare.c index b6e79c6bbb6..67b690f9dfe 100644 --- a/src/interfaces/ecpg/ecpglib/prepare.c +++ b/src/interfaces/ecpg/ecpglib/prepare.c @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/prepare.c,v 1.13 2004/10/05 10:48:37 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/prepare.c,v 1.13.4.1 2005/11/30 12:51:06 meskes Exp $ */ #define POSTGRES_ECPG_INTERNAL #include "postgres_fe.h" @@ -60,7 +60,7 @@ replace_variables(char *text) /* handle the EXEC SQL PREPARE statement */ bool -ECPGprepare(int lineno, char *name, char *variable) +ECPGprepare(int lineno, const char *name, const char *variable) { struct statement *stmt; struct prepared_statement *this; @@ -112,7 +112,7 @@ ECPGprepare(int lineno, char *name, char *variable) /* handle the EXEC SQL DEALLOCATE PREPARE statement */ bool -ECPGdeallocate(int lineno, int c, char *name) +ECPGdeallocate(int lineno, int c, const char *name) { bool ret = ECPGdeallocate_one(lineno, name); enum COMPAT_MODE compat = c; @@ -133,7 +133,7 @@ ECPGdeallocate(int lineno, int c, char *name) } bool -ECPGdeallocate_one(int lineno, char *name) +ECPGdeallocate_one(int lineno, const char *name) { struct prepared_statement *this, *prev; diff --git a/src/interfaces/ecpg/include/ecpglib.h b/src/interfaces/ecpg/include/ecpglib.h index 6145e79cb4d..0bcaac1a86e 100644 --- a/src/interfaces/ecpg/include/ecpglib.h +++ b/src/interfaces/ecpg/include/ecpglib.h @@ -48,12 +48,12 @@ bool ECPGstatus(int, const char *); 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 ECPGdo(int, int, int, const char *, const 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 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,10 +75,10 @@ bool ECPGdeallocate_desc(int line, const char *name); 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,...); +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 *);