- Made several variables "const char *" instead of "char *" as proposed by Qingqing...
authorMichael Meskes <meskes@postgresql.org>
Wed, 30 Nov 2005 12:51:07 +0000 (12:51 +0000)
committerMichael Meskes <meskes@postgresql.org>
Wed, 30 Nov 2005 12:51:07 +0000 (12:51 +0000)
- Replaced all strdup() calls by ECPGstrdup().

src/interfaces/ecpg/ecpglib/connect.c
src/interfaces/ecpg/ecpglib/descriptor.c
src/interfaces/ecpg/ecpglib/execute.c
src/interfaces/ecpg/ecpglib/prepare.c
src/interfaces/ecpg/include/ecpglib.h

index 26997d9f6b1b3e93c0fbb5ef3e00b01af6929448..3f0bc62fa5dd2dd74b66db69fa321410b27a44dc 100644 (file)
@@ -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;
index 08c8d3479ceb8465c6c65a139553d425cf5b925d..687f452e0983529f384d36f975d78e18631feb58 100644 (file)
@@ -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;
index bc46ddb34f01b382d25f8704cbd96ea9b52c3379..f5c0e214e7596f7ab4306784c1bc12a28a36f6db 100644 (file)
@@ -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))
index b6e79c6bbb6b7dca39cb80f6380ee06a69e99624..67b690f9dfe9de4ec11e52eb1d5e2651c6c0d695 100644 (file)
@@ -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;
index 6145e79cb4df05910ed0cd711a3335ff85e5d83f..0bcaac1a86e96e8289675ff1c29b4a5fd3b13126 100644 (file)
@@ -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 *);