[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 11/12] Guile-DBD-postgres: Avoid deprecated functions
From: |
Linas Vepstas |
Subject: |
[PATCH 11/12] Guile-DBD-postgres: Avoid deprecated functions |
Date: |
Fri, 19 Sep 2008 09:22:02 -0500 |
User-agent: |
Mutt/1.5.15+20070412 (2007-04-11) |
Don't use deprecated guile gh_ functions. Also, move
some string handling functions around so as to avoid memory leak.
Also, avoid some casting. Casting is bad, it can hide errors
from the compiler.
Signed-off-by: Linas Vepstas <address@hidden>
---
src/guile-dbd-postgresql.c | 67 ++++++++++++++++++++++-----------------------
1 file changed, 34 insertions(+), 33 deletions(-)
Index: guile-dbd-postgresql-2.0.0/src/guile-dbd-postgresql.c
===================================================================
--- guile-dbd-postgresql-2.0.0.orig/src/guile-dbd-postgresql.c 2008-09-16
19:31:37.000000000 -0500
+++ guile-dbd-postgresql-2.0.0/src/guile-dbd-postgresql.c 2008-09-16
19:46:13.000000000 -0500
@@ -23,7 +23,6 @@
#include <guile-dbi/guile-dbi.h>
#include <libguile.h>
-#include <guile/gh.h>
#include <postgresql/libpq-fe.h>
#include <string.h>
#include <errno.h>
@@ -59,7 +58,7 @@ __postgresql_make_g_db_handle(gdbi_db_ha
if(scm_equal_p(scm_string_p(dbh->constr), SCM_BOOL_F) == SCM_BOOL_T)
{
/* todo: error msg to be translated */
- dbh->status = (SCM) scm_cons(scm_from_int(1),
+ dbh->status = scm_cons(scm_from_int(1),
scm_from_locale_string("missing connection
string"));
return;
}
@@ -70,11 +69,7 @@ __postgresql_make_g_db_handle(gdbi_db_ha
if (items >= 5 && items < 8)
{
char* port = NULL;
- char* user = gh_scm2newstr(scm_list_ref(cp_list,scm_from_int(0)),NULL);
- char* pass = gh_scm2newstr(scm_list_ref(cp_list,scm_from_int(1)),NULL);
- char* db = gh_scm2newstr(scm_list_ref(cp_list,scm_from_int(2)),NULL);
- char* ctyp = gh_scm2newstr(scm_list_ref(cp_list,scm_from_int(3)),NULL);
- char* loc = gh_scm2newstr(scm_list_ref(cp_list,scm_from_int(4)),NULL);
+ char* user, *pass, *db, *ctyp, *loc;
pgsqlP = (gdbi_pgsql_ds_t*)malloc(sizeof(gdbi_pgsql_ds_t));
pgsqlP->retn = 0;
@@ -86,18 +81,24 @@ __postgresql_make_g_db_handle(gdbi_db_ha
return;
}
+ user = scm_to_locale_string(scm_list_ref(cp_list,scm_from_int(0)));
+ pass = scm_to_locale_string(scm_list_ref(cp_list,scm_from_int(1)));
+ db = scm_to_locale_string(scm_list_ref(cp_list,scm_from_int(2)));
+ ctyp = scm_to_locale_string(scm_list_ref(cp_list,scm_from_int(3)));
+ loc = scm_to_locale_string(scm_list_ref(cp_list,scm_from_int(4)));
+
pgsqlP->pgsql = NULL;
pgsqlP->res = NULL;
if (strcmp(ctyp,"tcp") == 0)
{
- port = (char*)
gh_scm2newstr(scm_list_ref(cp_list,scm_from_int(5)),NULL);
+ port = scm_to_locale_string(scm_list_ref(cp_list,scm_from_int(5)));
pgsqlP->pgsql = (PGconn*)
PQsetdbLogin(loc,port,NULL,NULL,db,user,pass);
if (items == 7)
{
- char* sretn =
gh_scm2newstr(scm_list_ref(cp_list,scm_from_int(6)),
- NULL);
+ char* sretn =
scm_to_locale_string(scm_list_ref(cp_list,scm_from_int(6)));
pgsqlP->retn = atoi(sretn);
+ free (sretn);
}
}
else
@@ -105,9 +106,9 @@ __postgresql_make_g_db_handle(gdbi_db_ha
pgsqlP->pgsql = (PGconn*)
PQsetdbLogin(loc,NULL,NULL,NULL,db,user,pass);
if (items == 6)
{
- char* sretn =
gh_scm2newstr(scm_list_ref(cp_list,scm_from_int(5)),
- NULL);
+ char* sretn =
scm_to_locale_string(scm_list_ref(cp_list,scm_from_int(5)));
pgsqlP->retn = atoi(sretn);
+ free (sretn);
}
}
@@ -139,7 +140,7 @@ __postgresql_make_g_db_handle(gdbi_db_ha
if(PQstatus(pgsqlP->pgsql) == CONNECTION_BAD)
{
- dbh->status = (SCM) scm_cons(scm_from_int(1),
+ dbh->status = scm_cons(scm_from_int(1),
scm_from_locale_string(PQerrorMessage(pgsqlP->pgsql)));
PQfinish(pgsqlP->pgsql);
pgsqlP->pgsql = NULL;
@@ -151,7 +152,7 @@ __postgresql_make_g_db_handle(gdbi_db_ha
else
{
/* todo: error msg to be translated */
- dbh->status = (SCM) scm_cons(scm_from_int(0),
+ dbh->status = scm_cons(scm_from_int(0),
scm_from_locale_string("db connected"));
dbh->db_info = pgsqlP;
dbh->closed = SCM_BOOL_F;
@@ -161,7 +162,7 @@ __postgresql_make_g_db_handle(gdbi_db_ha
else
{
/* todo: error msg to be translated */
- dbh->status = (SCM) scm_cons(scm_from_int(1),
+ dbh->status = scm_cons(scm_from_int(1),
scm_from_locale_string("invalid connection
string"));
dbh->db_info = NULL;
dbh->closed = SCM_BOOL_T;
@@ -181,14 +182,14 @@ __postgresql_close_g_db_handle(gdbi_db_h
if (pgsqlP == NULL)
{
/* todo: error msg to be translated */
- dbh->status = (SCM) scm_cons(scm_from_int(1),
+ dbh->status = scm_cons(scm_from_int(1),
scm_from_locale_string("dbd info not
found"));
return;
}
else if (pgsqlP->pgsql == NULL)
{
/* todo: error msg to be translated */
- dbh->status = (SCM) scm_cons(scm_from_int(1),
+ dbh->status = scm_cons(scm_from_int(1),
scm_from_locale_string("dbi connection
already closed"));
free(dbh->db_info);
dbh->db_info = NULL;
@@ -208,7 +209,7 @@ __postgresql_close_g_db_handle(gdbi_db_h
/* todo: error msg to be translated */
dbh->closed = SCM_BOOL_T;
- dbh->status = (SCM) scm_cons(scm_from_int(0),
+ dbh->status = scm_cons(scm_from_int(0),
scm_from_locale_string("dbi closed"));
return;
}
@@ -224,7 +225,7 @@ __postgresql_query_g_db_handle(gdbi_db_h
if(dbh->db_info == NULL)
{
/* todo: error msg to be translated */
- dbh->status = (SCM) scm_cons(scm_from_int(1),
+ dbh->status = scm_cons(scm_from_int(1),
scm_from_locale_string("invalid dbi
connection"));
return;
}
@@ -232,7 +233,7 @@ __postgresql_query_g_db_handle(gdbi_db_h
if (query == NULL)
{
/* todo: error msg to be translated */
- dbh->status = (SCM) scm_cons(scm_from_int(1),
+ dbh->status = scm_cons(scm_from_int(1),
scm_from_locale_string("invalid dbi query"));
return;
}
@@ -257,14 +258,14 @@ __postgresql_query_g_db_handle(gdbi_db_h
if (err == 1)
{
- dbh->status = (SCM) scm_cons(scm_from_int(0),
+ dbh->status = scm_cons(scm_from_int(0),
scm_from_locale_string("query ok"));
pgsqlP->lget = 0;
return;
}
else
{
- dbh->status = (SCM) scm_cons(scm_from_int(1),
+ dbh->status = scm_cons(scm_from_int(1),
scm_from_locale_string(PQerrorMessage(pgsqlP->pgsql)));
return;
}
@@ -285,7 +286,7 @@ __postgresql_getrow_g_db_handle(gdbi_db_
if(dbh->db_info == NULL)
{
/* todo: error msg to be translated */
- dbh->status = (SCM) scm_cons(scm_from_int(1),
+ dbh->status = scm_cons(scm_from_int(1),
scm_from_locale_string("invalid dbi
connection"));
return (SCM_BOOL_F);
}
@@ -294,7 +295,7 @@ __postgresql_getrow_g_db_handle(gdbi_db_
if (pgsqlP->res == NULL &&
(pgsqlP->res = PQgetResult(pgsqlP->pgsql)) == NULL)
{
- dbh->status = (SCM) scm_cons(scm_from_int(0),
+ dbh->status = scm_cons(scm_from_int(0),
scm_from_locale_string("row end"));
pgsqlP->lget = 0;
return (SCM_BOOL_F);
@@ -314,14 +315,14 @@ __postgresql_getrow_g_db_handle(gdbi_db_
type == 1700 ||
type == 26 )
{
- value_str = (char*) strndup(PQgetvalue(pgsqlP->res,pgsqlP->lget,f),
+ value_str = strndup(PQgetvalue(pgsqlP->res,pgsqlP->lget,f),
PQgetlength(pgsqlP->res,pgsqlP->lget,f));
value = scm_from_long(atoi(value_str));
}
else if (type == 700 ||
type == 701 )
{
- value_str = (char*) strndup(PQgetvalue(pgsqlP->res,pgsqlP->lget,f),
+ value_str = strndup(PQgetvalue(pgsqlP->res,pgsqlP->lget,f),
PQgetlength(pgsqlP->res,pgsqlP->lget,f));
value = scm_from_double(atof(value_str));
}
@@ -331,13 +332,13 @@ __postgresql_getrow_g_db_handle(gdbi_db_
type == 702 ||
(type >= 1042 && type <= 1114))
{
- value_str = (char*) strndup(PQgetvalue(pgsqlP->res,pgsqlP->lget,f),
+ value_str = strndup(PQgetvalue(pgsqlP->res,pgsqlP->lget,f),
PQgetlength(pgsqlP->res,pgsqlP->lget,f));
- value = (SCM)scm_from_locale_string(value_str);
+ value = scm_from_locale_string(value_str);
}
else
{
- dbh->status = (SCM) scm_cons(scm_from_int(1),
+ dbh->status = scm_cons(scm_from_int(1),
scm_from_locale_string("unknown field
type"));
pgsqlP->lget++;
return SCM_EOL;
@@ -362,12 +363,12 @@ __postgresql_getrow_g_db_handle(gdbi_db_
case PGRES_FATAL_ERROR:
if (pgsqlP->res == NULL)
{
- dbh->status = (SCM) scm_cons(scm_from_int(0),
+ dbh->status = scm_cons(scm_from_int(0),
scm_from_locale_string("row end"));
}
else
{
- dbh->status = (SCM) scm_cons(scm_from_int(1),
+ dbh->status = scm_cons(scm_from_int(1),
scm_from_locale_string(PQresStatus(PQresultStatus(pgsqlP->res))));
}
break;
@@ -376,11 +377,11 @@ __postgresql_getrow_g_db_handle(gdbi_db_
case PGRES_TUPLES_OK:
case PGRES_COPY_OUT:
case PGRES_COPY_IN:
- dbh->status = (SCM) scm_cons(scm_from_int(0),
+ dbh->status = scm_cons(scm_from_int(0),
scm_from_locale_string(PQresStatus(PQresultStatus(pgsqlP->res))));
break;
default:
- dbh->status = (SCM) scm_cons(scm_from_int(0),
+ dbh->status = scm_cons(scm_from_int(0),
scm_from_locale_string("unknown return query
status"));
break;
}
signature.asc
Description: Digital signature
- [PATCH 1/12] Guile-DBI: Avoid multiple init, (continued)
- [PATCH 1/12] Guile-DBI: Avoid multiple init, Linas Vepstas, 2008/09/19
- [PATCH 2/12] Guile-DBI: minor cleanup, Linas Vepstas, 2008/09/19
- [PATCH 3/12] Guile-DBI: Fix memory leak, Linas Vepstas, 2008/09/19
- [PATCH 4/12] Guile-DBII: replace deprecated gh_ functions, Linas Vepstas, 2008/09/19
- [PATCH 6/12] Guile-DBI: Fix crash, avoid recursive free, Linas Vepstas, 2008/09/19
- [PATCH 5/12] Guile-DBI: Use remember_upto_here, Linas Vepstas, 2008/09/19
- [PATCH 7/12] Guile-DBI: Don't cast away const, Linas Vepstas, 2008/09/19
- [PATCH 8/12] Guile-DBD-postgres: Fix handling of float point columns, Linas Vepstas, 2008/09/19
- [PATCH 9/12] Guile-DBD-postgres: Avoid discouraged functions, Linas Vepstas, 2008/09/19
- [PATCH 10/12] Guile-DBD-postgres: Fix off-by-one when fetching rows, Linas Vepstas, 2008/09/19
- [PATCH 11/12] Guile-DBD-postgres: Avoid deprecated functions,
Linas Vepstas <=
- [PATCH 12/12] Guile-DBD-postgres: Crash in GC, Linas Vepstas, 2008/09/19
- Re: PATCH [0/12]: Guile-DBI and Guile-DBD-Postgres, Neil Jerram, 2008/09/19
Re: PATCH [0/12]: Guile-DBI and Guile-DBD-Postgres, Mike Gran, 2008/09/19