aboutsummaryrefslogtreecommitdiff
path: root/src/gsql_conn.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2007-12-26 21:54:07 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2007-12-26 21:54:07 +0000
commitf60b650e9acd449b142c37e4fcc55390c62f4832 (patch)
tree3f3e026b1db43a9344fb65e6a83d7534b7434ff0 /src/gsql_conn.c
parent06e6d0bcfcd33203091a817e4423fdd12e1bcd68 (diff)
downloadgamma-f60b650e9acd449b142c37e4fcc55390c62f4832.tar.gz
gamma-f60b650e9acd449b142c37e4fcc55390c62f4832.tar.bz2
* NEWS: Update.
* configure.ac: Version number 1.1 * COPYING: GPLv3. * Makefile.am: GPLv3. * examples/whoisd.scm: GPLv3. * m4/guile.m4: Require Guile v. 1.8 or later. * scripts/Makefile.am: GPLv3. * scripts/guile-doc-snarf.awk: GPLv3. * src/.cvsignore (gettext.inc, gettext.scm): Remove. * src/Makefile.am: Remove libguile-gettext. * src/app.h: GPLv3. * src/gsql_conn.c, src/gsql_lib.c, src/guile-sql.h, src/mysql.c, src/pgsql.c: GPLv3; Guile v.>=1.8. * src/gettext.sci, src/gettext.h, src/gettext.c: Remove. * src/gettext.scm: New file.
Diffstat (limited to 'src/gsql_conn.c')
-rw-r--r--src/gsql_conn.c88
1 files changed, 44 insertions, 44 deletions
diff --git a/src/gsql_conn.c b/src/gsql_conn.c
index 3a44c18..4a78094 100644
--- a/src/gsql_conn.c
+++ b/src/gsql_conn.c
@@ -1,19 +1,18 @@
/* This file is part of guile-sql.
Copyright (C) 2002, 2005 Sergey Poznyakoff
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation; either version 3 of the License, or (at your
+ option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
+ You should have received a copy of the GNU General Public License along
+ with this program. If not, see <http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
@@ -21,14 +20,14 @@
#include <string.h>
#include <guile-sql.h>
#include <app.h>
+#include <stdio.h>
static int num_iface;
-struct sql_iface sql_iftab[MAX_IFACES];
+static struct sql_iface sql_iftab[MAX_IFACES];
SCM_GLOBAL_SYMBOL (gsql_error, "gsql-error");
-
-long sql_connect_tag;
+static long sql_connect_tag = -1;
/* SMOB functions: */
static SCM
@@ -50,7 +49,7 @@ sql_connect_free (SCM connect_smob)
free(conn->username);
if (conn->database)
free(conn->database);
- free(conn);
+ scm_gc_free(conn, sizeof *conn, "SQL connection");
return size;
}
@@ -76,8 +75,8 @@ sql_connect_print (SCM connect_smob, SCM port, scm_print_state * pstate)
return 1;
}
-int
-sql_find_iface(char *name)
+static int
+sql_find_iface(const char *name)
{
int iface;
@@ -95,15 +94,15 @@ sql_connect_create (char *name)
if (iface < 0)
scm_misc_error("sql_connect_create",
"Unknown SQL interface ~S",
- SCM_LIST1(scm_makfrom0str(name)));
+ scm_list_1(scm_makfrom0str(name)));
- conn = scm_must_malloc (sizeof (*conn), "sql_connect");
+ conn = scm_gc_malloc (sizeof (*conn), "sql_connect");
memset(conn, 0, sizeof *conn);
conn->iface = iface;
SCM_RETURN_NEWSMOB (sql_connect_tag, conn);
}
-int
+static int
scm_is_sql_connect (SCM scm)
{
return SCM_NIMP (scm) && SCM_CAR (scm) == (SCM) sql_connect_tag;
@@ -117,18 +116,18 @@ SCM_DEFINE (sql_connect, "sql-connect", 5, 1, 0,
#define FUNC_NAME s_sql_connect
{
SCM smob;
- char *hostname;
+ const char *hostname;
int port;
- char *dbname;
- char *user;
- char *pass;
+ const char *dbname;
+ const char *user;
+ const char *pass;
int iface;
struct sql_connect *conn;
- if (SCM_IMP(IFACE) && SCM_INUMP(IFACE))
- iface = SCM_INUM(IFACE);
- else if (SCM_STRINGP(IFACE))
- iface = sql_find_iface(SCM_CHARS(IFACE));
+ if (scm_is_integer(IFACE))
+ iface = scm_to_int(IFACE);
+ else if (scm_is_string(IFACE))
+ iface = sql_find_iface(scm_i_string_chars(IFACE));
else {
SCM_ASSERT(IFACE == SCM_BOOL_T || IFACE == SCM_BOOL_F,
IFACE, SCM_ARG1, FUNC_NAME);
@@ -137,26 +136,25 @@ SCM_DEFINE (sql_connect, "sql-connect", 5, 1, 0,
if (iface < 0 || iface >= num_iface)
scm_misc_error(FUNC_NAME,
"Argument ~S (~S) out of range",
- SCM_LIST2(SCM_MAKINUM(1),
- IFACE));
+ scm_list_2(scm_from_int(1),
+ IFACE));
- SCM_ASSERT(SCM_STRINGP(HOST), HOST, SCM_ARG1, FUNC_NAME);
- hostname = SCM_ROCHARS(HOST);
+ SCM_ASSERT(scm_is_string(HOST), HOST, SCM_ARG1, FUNC_NAME);
+ hostname = scm_i_string_chars(HOST);
- SCM_ASSERT(SCM_IMP(PORT) && SCM_INUMP(PORT),
- PORT, SCM_ARG2, FUNC_NAME);
- port = SCM_INUM(PORT);
+ SCM_ASSERT(scm_is_number(PORT), PORT, SCM_ARG2, FUNC_NAME);
+ port = scm_to_int(PORT);
- SCM_ASSERT(SCM_STRINGP(DB), DB, SCM_ARG3, FUNC_NAME);
- dbname = SCM_ROCHARS(DB);
+ SCM_ASSERT(scm_is_string(DB), DB, SCM_ARG3, FUNC_NAME);
+ dbname = scm_i_string_chars(DB);
- SCM_ASSERT(SCM_STRINGP(USER), USER, SCM_ARG4, FUNC_NAME);
- user = SCM_ROCHARS(USER);
+ SCM_ASSERT(scm_is_string(USER), USER, SCM_ARG4, FUNC_NAME);
+ user = scm_i_string_chars(USER);
if (SCM_UNBNDP(PASS))
pass = NULL;
- else if (SCM_STRINGP(USER))
- pass = SCM_ROCHARS(PASS);
+ else if (scm_is_string(USER))
+ pass = scm_i_string_chars(PASS);
smob = sql_iftab[iface].connect(hostname, port,
dbname, user, pass,
@@ -192,12 +190,12 @@ SCM_DEFINE (sql_query, "sql-query", 2, 0, 0,
{
struct sql_connect *conn;
void *ptr;
- char *query;
+ const char *query;
SCM_ASSERT(scm_is_sql_connect(CONN), CONN, SCM_ARG1, FUNC_NAME);
- SCM_ASSERT(SCM_STRINGP(QUERY), QUERY, SCM_ARG2, FUNC_NAME);
+ SCM_ASSERT(scm_is_string(QUERY), QUERY, SCM_ARG2, FUNC_NAME);
conn = (struct sql_connect *)SCM_CDR(CONN);
- query = SCM_ROCHARS(QUERY);
+ query = scm_i_string_chars(QUERY);
return sql_iftab[conn->iface].query(conn, query);
}
#undef FUNC_NAME
@@ -220,11 +218,13 @@ sql_register_iface(struct sql_iface *ifp)
void
gsql_conn_init()
{
- sql_connect_tag = scm_make_smob_type ("sql_connect",
+ if (sql_connect_tag == -1) {
+ sql_connect_tag = scm_make_smob_type ("sql_connect",
sizeof (struct sql_connect));
- scm_set_smob_mark (sql_connect_tag, sql_connect_mark);
- scm_set_smob_free (sql_connect_tag, sql_connect_free);
- scm_set_smob_print (sql_connect_tag, sql_connect_print);
+ scm_set_smob_mark (sql_connect_tag, sql_connect_mark);
+ scm_set_smob_free (sql_connect_tag, sql_connect_free);
+ scm_set_smob_print (sql_connect_tag, sql_connect_print);
+ }
#ifndef SCM_MAGIC_SNARFER
# include <gsql_conn.x>
#endif

Return to:

Send suggestions and report system problems to the System administrator.