aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Meskes <meskes@postgresql.org>2005-11-30 12:50:37 +0000
committerMichael Meskes <meskes@postgresql.org>2005-11-30 12:50:37 +0000
commitdd13bf167b24fc497a7ce7f1897a89ae3ac40c9f (patch)
tree5cb0595ed4889482db3e9f8b91f2185bf948be25
parentc4279b45fd6031173adc8ae533a1f81942cfb027 (diff)
downloadpostgresql-dd13bf167b24fc497a7ce7f1897a89ae3ac40c9f.tar.gz
postgresql-dd13bf167b24fc497a7ce7f1897a89ae3ac40c9f.zip
- Made several variables "const char *" instead of "char *" as proposed by Qingqing Zhou <zhouqq@cs.toronto.edu>.
- Replaced all strdup() calls by ECPGstrdup().
-rw-r--r--src/interfaces/ecpg/ecpglib/connect.c26
-rw-r--r--src/interfaces/ecpg/ecpglib/descriptor.c12
-rw-r--r--src/interfaces/ecpg/ecpglib/execute.c11
-rw-r--r--src/interfaces/ecpg/ecpglib/prepare.c8
-rw-r--r--src/interfaces/ecpg/include/ecpglib.h16
5 files changed, 37 insertions, 36 deletions
diff --git a/src/interfaces/ecpg/ecpglib/connect.c b/src/interfaces/ecpg/ecpglib/connect.c
index 94d2f42ec17..69f81f2151c 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.26 2005/10/15 02:49:47 momjian Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.26.2.1 2005/11/30 12:50:37 meskes Exp $ */
#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"
@@ -265,7 +265,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,
@@ -287,7 +287,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);
}
}
@@ -307,17 +307,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)
{
@@ -345,14 +345,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';
}
@@ -365,7 +365,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);
@@ -384,7 +384,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)
@@ -407,14 +407,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..3a8d8ceb29e 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.6.1 2005/11/30 12:50:37 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 ac870f0cc82..870c9d2cc3c 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.43 2005/10/15 02:49:47 momjian Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.43.2.1 2005/11/30 12:50:37 meskes Exp $ */
/*
* The aim is to get a simpler inteface to the database routines.
@@ -141,7 +141,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;
@@ -149,7 +149,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;
@@ -224,6 +224,7 @@ free_statement(struct statement * stmt)
return;
free_variable(stmt->inlist);
free_variable(stmt->outlist);
+ ECPGfree(stmt->command);
ECPGfree(stmt);
}
@@ -1359,7 +1360,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;
@@ -1369,7 +1370,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 cd57c41914f..3140de73132 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.14 2005/10/15 02:49:47 momjian Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/prepare.c,v 1.14.2.1 2005/11/30 12:50:37 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 *);