From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Linas Vepstas Newsgroups: gmane.lisp.guile.user Subject: [PATCH 11/12] Guile-DBD-postgres: Avoid deprecated functions Date: Fri, 19 Sep 2008 09:22:02 -0500 Message-ID: <20080919142202.GK13684@linas.org> References: <3ae3aa420809190645o2fe2b746id80f53c5cb123e5b@mail.gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="45wMVEkw4XUbiYON" X-Trace: ger.gmane.org 1221834476 9908 80.91.229.12 (19 Sep 2008 14:27:56 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 19 Sep 2008 14:27:56 +0000 (UTC) Cc: Guile User Mailing List To: Maurizio Boriani Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri Sep 19 16:28:52 2008 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Kggvj-000343-MK for guile-user@m.gmane.org; Fri, 19 Sep 2008 16:26:04 +0200 Original-Received: from localhost ([127.0.0.1]:35054 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kggue-0003yp-Eo for guile-user@m.gmane.org; Fri, 19 Sep 2008 10:24:49 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KggsN-0002wH-1z for guile-user@gnu.org; Fri, 19 Sep 2008 10:22:27 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KggsL-0002vS-67 for guile-user@gnu.org; Fri, 19 Sep 2008 10:22:26 -0400 Original-Received: from [199.232.76.173] (port=46972 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KggsK-0002vL-VX for guile-user@gnu.org; Fri, 19 Sep 2008 10:22:25 -0400 Original-Received: from rv-out-0708.google.com ([209.85.198.249]:45017) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KggsJ-0007yQ-Ef for guile-user@gnu.org; Fri, 19 Sep 2008 10:22:24 -0400 Original-Received: by rv-out-0708.google.com with SMTP id k29so503163rvb.6 for ; Fri, 19 Sep 2008 07:22:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:to:cc:subject:message-id :references:mime-version:content-type:content-disposition :in-reply-to:user-agent:from; bh=HoqTDbp4h1eo55aO/NkcKDTntV7PYR4Th1r3e3/QRyE=; b=WYpBhNu4DWvTaIuTtEg1RKM0VuIIwbNLvo1gptx3ZSjqF0IUU1u7LAIezUN0Tbjm4/ ZrPK+Bbvwmwr/nxsjl4M9ArMkuhLV9qVtPoxhYfNvapSQKdNyOSWUqOHdPhwsZqoR0EJ xPzo6y9yY4gu8OwmavfDtWJrH+B2YbPrQDFxc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:to:cc:subject:message-id:references:mime-version:content-type :content-disposition:in-reply-to:user-agent:from; b=VPyNZkiJYtIBVcXDNGFBgOPPnYf7jt3HrIRUsxhczKyRckl/I1sGjo2d9wp8KZPIs1 E7lEHuhOL/YyjPlg9HiKQIsJaVXiGougxSV8YV90F0uRj85ZUiNYxdgHBLqE6PEJapdq VqfMI/Re1YtLMKTiXnqZklN0zjWXf8N+WhrF0= Original-Received: by 10.141.43.5 with SMTP id v5mr84955rvj.49.1221834141877; Fri, 19 Sep 2008 07:22:21 -0700 (PDT) Original-Received: from linas.org ( [67.100.217.179]) by mx.google.com with ESMTPS id 4sm1121181yxq.9.2008.09.19.07.22.12 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 19 Sep 2008 07:22:21 -0700 (PDT) Content-Disposition: inline In-Reply-To: <3ae3aa420809190645o2fe2b746id80f53c5cb123e5b@mail.gmail.com> User-Agent: Mutt/1.5.15+20070412 (2007-04-11) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:6794 Archived-At: --45wMVEkw4XUbiYON Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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=20 =66rom the compiler. Signed-off-by: Linas Vepstas --- 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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- guile-dbd-postgresql-2.0.0.orig/src/guile-dbd-postgresql.c 2008-09-16 1= 9: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 @@ =20 #include #include -#include #include #include #include @@ -59,7 +58,7 @@ __postgresql_make_g_db_handle(gdbi_db_ha if(scm_equal_p(scm_string_p(dbh->constr), SCM_BOOL_F) =3D=3D SCM_BOOL_T) { /* todo: error msg to be translated */ - dbh->status =3D (SCM) scm_cons(scm_from_int(1), + dbh->status =3D 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 >=3D 5 && items < 8) { char* port =3D NULL; - char* user =3D gh_scm2newstr(scm_list_ref(cp_list,scm_from_int(0)),N= ULL); - char* pass =3D gh_scm2newstr(scm_list_ref(cp_list,scm_from_int(1)),N= ULL); - char* db =3D gh_scm2newstr(scm_list_ref(cp_list,scm_from_int(2)),N= ULL); - char* ctyp =3D gh_scm2newstr(scm_list_ref(cp_list,scm_from_int(3)),N= ULL); - char* loc =3D gh_scm2newstr(scm_list_ref(cp_list,scm_from_int(4)),N= ULL); + char* user, *pass, *db, *ctyp, *loc; =20 pgsqlP =3D (gdbi_pgsql_ds_t*)malloc(sizeof(gdbi_pgsql_ds_t)); pgsqlP->retn =3D 0; @@ -86,18 +81,24 @@ __postgresql_make_g_db_handle(gdbi_db_ha return; } =20 + user =3D scm_to_locale_string(scm_list_ref(cp_list,scm_from_int(0))); + pass =3D scm_to_locale_string(scm_list_ref(cp_list,scm_from_int(1))); + db =3D scm_to_locale_string(scm_list_ref(cp_list,scm_from_int(2))); + ctyp =3D scm_to_locale_string(scm_list_ref(cp_list,scm_from_int(3))); + loc =3D scm_to_locale_string(scm_list_ref(cp_list,scm_from_int(4))); + pgsqlP->pgsql =3D NULL; pgsqlP->res =3D NULL; =20 if (strcmp(ctyp,"tcp") =3D=3D 0) { - port =3D (char*) gh_scm2newstr(scm_list_ref(cp_list,scm_from_int(5)),N= ULL); + port =3D scm_to_locale_string(scm_list_ref(cp_list,scm_from_int(5))); pgsqlP->pgsql =3D (PGconn*) PQsetdbLogin(loc,port,NULL,NULL,db,user,pas= s); if (items =3D=3D 7) { - char* sretn =3D gh_scm2newstr(scm_list_ref(cp_list,scm_from_int(6)= ), - NULL); + char* sretn =3D scm_to_locale_string(scm_list_ref(cp_list,scm_from= _int(6))); pgsqlP->retn =3D atoi(sretn); + free (sretn); } } else @@ -105,9 +106,9 @@ __postgresql_make_g_db_handle(gdbi_db_ha pgsqlP->pgsql =3D (PGconn*) PQsetdbLogin(loc,NULL,NULL,NULL,db,user,pas= s); if (items =3D=3D 6) { - char* sretn =3D gh_scm2newstr(scm_list_ref(cp_list,scm_from_int(5)= ), - NULL); + char* sretn =3D scm_to_locale_string(scm_list_ref(cp_list,scm_from= _int(5))); pgsqlP->retn =3D atoi(sretn); + free (sretn); } } =20 @@ -139,7 +140,7 @@ __postgresql_make_g_db_handle(gdbi_db_ha =20 if(PQstatus(pgsqlP->pgsql) =3D=3D CONNECTION_BAD) { - dbh->status =3D (SCM) scm_cons(scm_from_int(1), + dbh->status =3D scm_cons(scm_from_int(1), scm_from_locale_string(PQerrorMessage(pgsqlP->pgsql))); PQfinish(pgsqlP->pgsql); pgsqlP->pgsql =3D NULL; @@ -151,7 +152,7 @@ __postgresql_make_g_db_handle(gdbi_db_ha else { /* todo: error msg to be translated */ - dbh->status =3D (SCM) scm_cons(scm_from_int(0), + dbh->status =3D scm_cons(scm_from_int(0), scm_from_locale_string("db connected")); dbh->db_info =3D pgsqlP; dbh->closed =3D SCM_BOOL_F; @@ -161,7 +162,7 @@ __postgresql_make_g_db_handle(gdbi_db_ha else { /* todo: error msg to be translated */ - dbh->status =3D (SCM) scm_cons(scm_from_int(1), + dbh->status =3D scm_cons(scm_from_int(1), scm_from_locale_string("invalid connection string")); dbh->db_info =3D NULL; dbh->closed =3D SCM_BOOL_T; @@ -181,14 +182,14 @@ __postgresql_close_g_db_handle(gdbi_db_h if (pgsqlP =3D=3D NULL) { /* todo: error msg to be translated */ - dbh->status =3D (SCM) scm_cons(scm_from_int(1), + dbh->status =3D scm_cons(scm_from_int(1), scm_from_locale_string("dbd info not found")); return; } else if (pgsqlP->pgsql =3D=3D NULL) { /* todo: error msg to be translated */ - dbh->status =3D (SCM) scm_cons(scm_from_int(1), + dbh->status =3D scm_cons(scm_from_int(1), scm_from_locale_string("dbi connection already closed")); free(dbh->db_info); dbh->db_info =3D NULL; @@ -208,7 +209,7 @@ __postgresql_close_g_db_handle(gdbi_db_h =20 /* todo: error msg to be translated */ dbh->closed =3D SCM_BOOL_T; - dbh->status =3D (SCM) scm_cons(scm_from_int(0), + dbh->status =3D 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 =3D=3D NULL) { /* todo: error msg to be translated */ - dbh->status =3D (SCM) scm_cons(scm_from_int(1), + dbh->status =3D 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 =3D=3D NULL) { /* todo: error msg to be translated */ - dbh->status =3D (SCM) scm_cons(scm_from_int(1), + dbh->status =3D 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 =20 if (err =3D=3D 1) { - dbh->status =3D (SCM) scm_cons(scm_from_int(0), + dbh->status =3D scm_cons(scm_from_int(0), scm_from_locale_string("query ok")); pgsqlP->lget =3D 0; return; } else { - dbh->status =3D (SCM) scm_cons(scm_from_int(1), + dbh->status =3D 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 =3D=3D NULL) { /* todo: error msg to be translated */ - dbh->status =3D (SCM) scm_cons(scm_from_int(1), + dbh->status =3D 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 =3D=3D NULL &&=20 (pgsqlP->res =3D PQgetResult(pgsqlP->pgsql)) =3D=3D NULL) { - dbh->status =3D (SCM) scm_cons(scm_from_int(0), + dbh->status =3D scm_cons(scm_from_int(0), scm_from_locale_string("row end")); pgsqlP->lget =3D 0; return (SCM_BOOL_F); @@ -314,14 +315,14 @@ __postgresql_getrow_g_db_handle(gdbi_db_ type =3D=3D 1700 || type =3D=3D 26 ) { - value_str =3D (char*) strndup(PQgetvalue(pgsqlP->res,pgsqlP->lget,f), + value_str =3D strndup(PQgetvalue(pgsqlP->res,pgsqlP->lget,f), PQgetlength(pgsqlP->res,pgsqlP->lget,f)); value =3D scm_from_long(atoi(value_str)); } else if (type =3D=3D 700 || type =3D=3D 701 ) { - value_str =3D (char*) strndup(PQgetvalue(pgsqlP->res,pgsqlP->lget,f), + value_str =3D strndup(PQgetvalue(pgsqlP->res,pgsqlP->lget,f), PQgetlength(pgsqlP->res,pgsqlP->lget,f)); value =3D scm_from_double(atof(value_str)); } @@ -331,13 +332,13 @@ __postgresql_getrow_g_db_handle(gdbi_db_ type =3D=3D 702 || (type >=3D 1042 && type <=3D 1114)) { - value_str =3D (char*) strndup(PQgetvalue(pgsqlP->res,pgsqlP->lget,f), + value_str =3D strndup(PQgetvalue(pgsqlP->res,pgsqlP->lget,f), PQgetlength(pgsqlP->res,pgsqlP->lget,f)); - value =3D (SCM)scm_from_locale_string(value_str); + value =3D scm_from_locale_string(value_str); } else { - dbh->status =3D (SCM) scm_cons(scm_from_int(1), + dbh->status =3D 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 =3D=3D NULL) { - dbh->status =3D (SCM) scm_cons(scm_from_int(0), + dbh->status =3D scm_cons(scm_from_int(0), scm_from_locale_string("row end")); } else { - dbh->status =3D (SCM) scm_cons(scm_from_int(1), + dbh->status =3D 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 =3D (SCM) scm_cons(scm_from_int(0), + dbh->status =3D scm_cons(scm_from_int(0), scm_from_locale_string(PQresStatus(PQresultStatus(pgsqlP->res)))); break; default: - dbh->status =3D (SCM) scm_cons(scm_from_int(0), + dbh->status =3D scm_cons(scm_from_int(0), scm_from_locale_string("unknown return query status")); break; } --45wMVEkw4XUbiYON Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iQEVAwUBSNO1ioSDRXfAOJJBAQIWSAgAqlmX3uwEziTJfW6n9NLmcbsFhyDAfRiZ I8i0asGFMsIsKRv2HhVPYY2M9rrv1xd64a4wG1G7oMFPmttazhzfrdVdZmPCbZkR ar5JyMXaRoUKENHtrpgOW4ldRNxXTm7JmS5AM0BaE5Oh+yr4QA9rgecBWjT9/PJV wu/LIYSuFGZdpIOfgqW0Ba3CQ8RXFvjnpVvTnhwK9ic3axspf30PVvFNr7ym8IOT 2f28oFXc24i+8ZND4c/tTy9ZQobYkVCL8FnvsG3klvOvUorLkMT4JVv+lIPP+kN3 hrVJFgd2EVPl1TxDzk6mOduQIiXiNHkpPOuUC16AgGRLzZB1ypx6pg== =qiuS -----END PGP SIGNATURE----- --45wMVEkw4XUbiYON--