summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2018-08-21 08:00:53 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2018-08-21 08:00:53 (GMT)
commit6abb2548315b9db2925194e54f09f01126182f81 (patch) (side-by-side diff)
tree327743c0e929933ae38a241770d08da0433561b4
parent3adba48f117f748dfb08a0dd4cdd42f214bae93f (diff)
downloadgamma-6abb2548315b9db2925194e54f09f01126182f81.tar.gz
gamma-6abb2548315b9db2925194e54f09f01126182f81.tar.bz2
Switch to Guile 2.2
Drop support for older Guile versions.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--configure.ac2
-rw-r--r--src/gamma-expat.c10
-rw-r--r--src/gsql_conn.c30
-rw-r--r--src/guile-sql.h2
-rw-r--r--src/mysql.c19
-rw-r--r--src/pgsql.c27
-rw-r--r--src/syslog-port.c124
7 files changed, 60 insertions, 154 deletions
diff --git a/configure.ac b/configure.ac
index 15aeb87..0695551 100644
--- a/configure.ac
+++ b/configure.ac
@@ -31,13 +31,13 @@ dnl Checks for programs.
AC_PROG_AWK
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_LN_S
AM_PROG_LIBTOOL
-GINT_INIT(gint,[1.8])
+GINT_INIT(gint,[2.2.0])
AC_SUBST(INCLUDEPATH)
AC_MSG_CHECKING(for additional includes)
AC_ARG_WITH([include-path],
AC_HELP_STRING([--with-include-path=PATH],
[specify additional include paths; PATH is a ':' separated list of directories]),
diff --git a/src/gamma-expat.c b/src/gamma-expat.c
index a81d30e..cd3efaa 100644
--- a/src/gamma-expat.c
+++ b/src/gamma-expat.c
@@ -29,21 +29,21 @@ struct gamma_xml_parser
static SCM
gamma_xml_parser_create(XML_Parser parser)
{
struct gamma_xml_parser *gp;
- gp = scm_malloc(sizeof (*gp));
+ gp = scm_gc_malloc(sizeof (*gp), "xml_parser");
gp->parser = parser;
SCM_RETURN_NEWSMOB(gamma_xml_parser_tag, gp);
}
#define GAMMA_XML_PARSER_PTR(smob) \
((struct gamma_xml_parser *)SCM_CDR(smob))
-static scm_sizet
+static size_t
gamma_xml_parser_free(SCM smob)
{
struct gamma_xml_parser *gp = GAMMA_XML_PARSER_PTR(smob);
if (gp->parser) {
struct gamma_expat_user_data *udata =
XML_GetUserData(gp->parser);
@@ -81,25 +81,25 @@ gamma_xml_parser_print(SCM smob, SCM port, scm_print_state *pstate)
scm_puts("#<XML_Parser>", port);
/* FIXME: show more details */
return 1;
}
static void
-gamma_xml_parser_init()
+gamma_xml_parser_init(void)
{
gamma_xml_parser_tag =
scm_make_smob_type("XML_Parser",
sizeof(struct gamma_xml_parser));
scm_set_smob_mark(gamma_xml_parser_tag, gamma_xml_parser_mark);
scm_set_smob_free(gamma_xml_parser_tag, gamma_xml_parser_free);
scm_set_smob_print(gamma_xml_parser_tag, gamma_xml_parser_print);
}
static struct gamma_expat_user_data *
-make_user_data ()
+make_user_data(void)
{
int i;
struct gamma_expat_user_data *p = scm_malloc(sizeof (*p));
for (i = 0; i < gamma_expat_handler_count; i++)
p->handler[i] = SCM_UNSPECIFIED;
@@ -150,13 +150,13 @@ SCM_DEFINE_PUBLIC(scm_xml_primitive_make_parser, "xml-primitive-make-parser",
SCM_VALIDATE_CHAR(2, sep);
separator = SCM_CHAR(sep);
parser = XML_ParserCreateNS(encoding, separator);
} else
parser = XML_ParserCreate(encoding);
if (!parser)
- scm_memory_error(FUNC_NAME);
+ scm_report_out_of_memory();
XML_SetUserData(parser, make_user_data());
free(encoding);
return gamma_xml_parser_create(parser);
}
#undef FUNC_NAME
diff --git a/src/gsql_conn.c b/src/gsql_conn.c
index 4d53a03..64cec27 100644
--- a/src/gsql_conn.c
+++ b/src/gsql_conn.c
@@ -28,32 +28,32 @@ static struct sql_iface sql_iftab[MAX_IFACES];
SCM_GLOBAL_SYMBOL (gamma_sql_error, "sql-error");
static long sql_connect_tag = -1;
/* SMOB functions: */
static SCM
-sql_connect_mark (SCM connect_smob)
+sql_connect_mark(SCM connect_smob)
{
struct sql_connect *conn = (struct sql_connect *)SCM_CDR(connect_smob);
- return sql_iftab[conn->iface].mark(conn);
+ if (sql_iftab[conn->iface].mark)
+ return sql_iftab[conn->iface].mark(conn);
}
-static scm_sizet
-sql_connect_free (SCM connect_smob)
+static size_t
+sql_connect_free(SCM connect_smob)
{
- scm_sizet size = sizeof(struct sql_connect);
struct sql_connect *conn = (struct sql_connect *)SCM_CDR(connect_smob);
- size += sql_iftab[conn->iface].free(conn);
+ sql_iftab[conn->iface].free(conn);
if (conn->hostname)
free(conn->hostname);
if (conn->username)
free(conn->username);
if (conn->database)
free(conn->database);
scm_gc_free(conn, sizeof *conn, "SQL connection");
- return size;
+ return 0;
}
static int
sql_connect_print (SCM connect_smob, SCM port, scm_print_state * pstate)
{
struct sql_connect *conn = (struct sql_connect *)SCM_CDR(connect_smob);
@@ -85,31 +85,31 @@ sql_find_iface(const char *name)
if (strcmp(sql_iftab[iface].name, name) == 0)
return iface;
return -1;
}
SCM
-sql_connect_create (char *name)
+sql_connect_create(char *name)
{
struct sql_connect *conn;
int iface = sql_find_iface(name);
if (iface < 0)
scm_misc_error("sql_connect_create",
"Unknown SQL interface ~S",
scm_list_1(scm_from_locale_string(name)));
- conn = scm_gc_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);
+ SCM_RETURN_NEWSMOB(sql_connect_tag, conn);
}
static int
-scm_is_sql_connect (SCM scm)
+scm_is_sql_connect(SCM scm)
{
- return SCM_NIMP (scm) && SCM_CAR (scm) == (SCM) sql_connect_tag;
+ return SCM_NIMP(scm) && SCM_CAR (scm) == (SCM) sql_connect_tag;
}
/* Interface */
static void
gamma_cvt_iface(SCM inval, void *outval, const char *func_name)
@@ -131,13 +131,13 @@ gamma_cvt_iface(SCM inval, void *outval, const char *func_name)
scm_list_2(scm_from_int(1),
inval));
*(int*)outval = iface;
}
-SCM_DEFINE_PUBLIC (sql_open_connection, "sql-open-connection", 1, 0, 0,
+SCM_DEFINE_PUBLIC(sql_open_connection, "sql-open-connection", 1, 0, 0,
(SCM param),
"Connect to a database. Take connection parameters from @var{param}, "
"which must be a list of conses. In each cons, the @samp{car} contains "
"a @dfn{key} identifying the parameter, and the @samp{cdr} supplies the "
"value for that parameter.\n"
"\n"
@@ -182,26 +182,26 @@ SCM_DEFINE_PUBLIC (sql_open_connection, "sql-open-connection", 1, 0, 0,
smob = sql_iftab[iface].connect(param, FUNC_NAME);
return smob;
}
#undef FUNC_NAME
-SCM_DEFINE_PUBLIC (sql_close_connection, "sql-close-connection", 1, 0, 0,
+SCM_DEFINE_PUBLIC(sql_close_connection, "sql-close-connection", 1, 0, 0,
(SCM conn),
"Close connection to a database.")
#define FUNC_NAME s_sql_close_connection
{
struct sql_connect *cp;
SCM_ASSERT(scm_is_sql_connect(conn), conn, SCM_ARG1, FUNC_NAME);
cp = (struct sql_connect *)SCM_CDR(conn);
sql_iftab[cp->iface].close(cp);
return SCM_UNSPECIFIED;
}
#undef FUNC_NAME
-SCM_DEFINE_PUBLIC (sql_query, "sql-query", 2, 0, 0,
+SCM_DEFINE_PUBLIC(sql_query, "sql-query", 2, 0, 0,
(SCM conn, SCM query),
"Send the SQL query @var{query} to the server using connection @var{conn} \
and return the result.\n\
If @var{query} is a @samp{SELECT}, or similar query, returning tuples, the \
return value is a list of rows. Each row is a list of values, one for each \
column. All values are returned as strings. NULL values are returned as \
diff --git a/src/guile-sql.h b/src/guile-sql.h
index 926aa74..f656fd4 100644
--- a/src/guile-sql.h
+++ b/src/guile-sql.h
@@ -36,13 +36,13 @@ struct sql_result {
void *data;
};
struct sql_iface {
char *name;
SCM (*mark) (struct sql_connect *);
- scm_sizet (*free) (struct sql_connect *);
+ size_t (*free) (struct sql_connect *);
SCM (*connect) (SCM parmlist, const char *func_name);
void (*close) (struct sql_connect *);
SCM (*query) (struct sql_connect *, const char *query);
};
extern SCM gamma_sql_error;
diff --git a/src/mysql.c b/src/mysql.c
index 1310212..dcc1847 100644
--- a/src/mysql.c
+++ b/src/mysql.c
@@ -18,30 +18,23 @@
# include <config.h>
#endif
#include <string.h>
#include <guile-sql.h>
#include <mysql/mysql.h>
-static SCM
-s_mysql_mark(struct sql_connect *conn)
-{
- return SCM_BOOL_F;
-}
-
-static scm_sizet
+static size_t
s_mysql_free(struct sql_connect *conn)
{
MYSQL *mysql = (MYSQL*) conn->data;
- if (!mysql)
- return 0;
- mysql_close(mysql);
- return sizeof(MYSQL);
+ if (mysql)
+ mysql_close(mysql);
+ return 0;
}
static SCM
-s_mysql_connect (SCM parmlist, const char *func_name)
+s_mysql_connect(SCM parmlist, const char *func_name)
{
char *hostname = NULL;
int port = 0;
char *dbname = NULL;
char *user = NULL;
char *pass = NULL;
@@ -222,13 +215,13 @@ s_mysql_close(struct sql_connect *conn)
mysql_close(conn->data);
conn->data = NULL;
}
struct sql_iface mysql_iface = {
"mysql",
- s_mysql_mark,
+ NULL, /* mark */
s_mysql_free,
s_mysql_connect,
s_mysql_close,
s_mysql_query,
};
diff --git a/src/pgsql.c b/src/pgsql.c
index c5cf51e..1421c40 100644
--- a/src/pgsql.c
+++ b/src/pgsql.c
@@ -18,30 +18,23 @@
# include <config.h>
#endif
#include <string.h>
#include <guile-sql.h>
#include <libpq-fe.h>
-static SCM
-s_pgsql_mark(struct sql_connect *conn)
-{
- return SCM_BOOL_F;
-}
-
-static scm_sizet
+static size_t
s_pgsql_free(struct sql_connect *conn)
{
PGconn *pgconn = (PGconn*) conn->data;
- if (!pgconn)
- return 0;
- PQfinish(pgconn);
- return sizeof(pgconn);
+ if (pgconn)
+ PQfinish(pgconn);
+ return 0;
}
static SCM
-s_pgsql_connect (SCM parmlist, const char *func_name)
+s_pgsql_connect(SCM parmlist, const char *func_name)
{
char *hostname = NULL;
char *port = NULL;
char *dbname = NULL;
char *user = NULL;
char *pass = NULL;
@@ -165,21 +158,21 @@ s_pgsql_query(struct sql_connect *conn, const char *query)
}
static void
s_pgsql_close(struct sql_connect *conn)
{
PGconn *pgconn = (PGconn*) conn->data;
- if (!pgconn)
- return;
- PQfinish(pgconn);
- conn->data = NULL;
+ if (pgconn) {
+ PQfinish(pgconn);
+ conn->data = NULL;
+ }
}
struct sql_iface pgsql_iface = {
"pgsql",
- s_pgsql_mark,
+ NULL, /* mark */
s_pgsql_free,
s_pgsql_connect,
s_pgsql_close,
s_pgsql_query,
};
diff --git a/src/syslog-port.c b/src/syslog-port.c
index 4b27ef9..4388c10 100644
--- a/src/syslog-port.c
+++ b/src/syslog-port.c
@@ -25,133 +25,55 @@
#ifndef HAVE_SCM_T_OFF
typedef off_t scm_t_off;
#endif
#define GAMMA_SYSLOG_PORT_BUFSIZE 1024
-static scm_t_bits scm_tc16_syslog_port;
+static scm_t_port_type *scm_syslog_port_type;
struct _gamma_syslog_port {
int prio;
};
static SCM
_make_syslog_port(int prio)
{
struct _gamma_syslog_port *dp;
- SCM port;
- scm_port *pt;
- dp = scm_gc_malloc (sizeof (struct _gamma_syslog_port), "syslog-port");
+ dp = scm_gc_typed_calloc (struct _gamma_syslog_port);
dp->prio = prio;
-
- port = scm_new_port_table_entry(scm_tc16_syslog_port);
- pt = SCM_PTAB_ENTRY(port);
- pt->rw_random = 0;
- pt->write_buf = scm_gc_malloc(GAMMA_SYSLOG_PORT_BUFSIZE,
- "syslog port buffer");
- pt->write_pos = pt->write_buf;
- pt->write_buf_size = GAMMA_SYSLOG_PORT_BUFSIZE;
- pt->write_end = pt->write_buf + pt->write_buf_size;
- SCM_SET_CELL_TYPE(port,
- (scm_tc16_syslog_port |
- SCM_OPN | SCM_WRTNG | SCM_BUFLINE));
- SCM_SETSTREAM(port, dp);
- return port;
+ return scm_c_make_port(scm_syslog_port_type,
+ SCM_OPN | SCM_WRTNG | SCM_BUFLINE,
+ (scm_t_bits) dp);
}
#define SYSLOG_PORT(x) ((struct _gamma_syslog_port *) SCM_STREAM (x))
-static SCM
-_syslog_port_mark(SCM port)
-{
- return SCM_BOOL_F;
-}
-
static void
-_syslog_port_flush(SCM port)
-{
- struct _gamma_syslog_port *dp = SYSLOG_PORT(port);
- scm_port *pt = SCM_PTAB_ENTRY(port);
- size_t size = pt->write_pos - pt->write_buf;
- unsigned char *nl = memchr(pt->write_buf, '\n', size);
- int wrsize;
-
- if (!nl)
- return;
-
- wrsize = nl - pt->write_buf;
-
- *nl = 0;
- syslog (dp->prio, "%s", (char *) pt->write_buf);
- *nl = '\n';
-
- if (wrsize < size) {
- size_t write_start;
-
- nl++;
- write_start = pt->write_pos - nl;
- memmove(pt->write_buf, nl, write_start);
- pt->write_pos = pt->write_buf + write_start;
- } else
- pt->write_pos = pt->write_buf;
-}
-
-static int
_syslog_port_close(SCM port)
{
struct _gamma_syslog_port *dp = SYSLOG_PORT(port);
-
- if (dp) {
- _syslog_port_flush(port);
- SCM_SETSTREAM(port, NULL);
- scm_gc_free(dp, sizeof(struct _gamma_syslog_port),
- "syslog-port");
- }
- return 0;
+ /* nothing */
}
-static scm_sizet
+static size_t
_syslog_port_free(SCM port)
+/* FIXME: basically, a no-op */
{
_syslog_port_close(port);
return 0;
}
-static int
-_syslog_port_fill_input(SCM port)
-{
- return EOF;
-}
-
-static void
-_syslog_port_write(SCM port, const void *data, size_t size)
+static size_t
+_syslog_port_write(SCM port, SCM src, size_t start, size_t count)
{
- scm_port *pt = SCM_PTAB_ENTRY (port);
- size_t space = pt->write_end - pt->write_pos;
- if (space < size) {
- size_t start = pt->write_pos - pt->write_buf;
- size_t new_size = pt->write_buf_size;
-
- do {
- /*FIXME*/
- new_size *= 2;
- } while (new_size - start < size);
-
- pt->write_buf = scm_gc_realloc(pt->write_buf,
- pt->write_buf_size,
- new_size,
- "syslog port buffer");
- pt->write_buf_size = new_size;
- pt->write_end = pt->write_buf + pt->write_buf_size;
- pt->write_pos = pt->write_buf + start;
- }
- memcpy(pt->write_pos, data, size);
- pt->write_pos += size;
-
- if (memchr (data, '\n', size))
- _syslog_port_flush(port);
+ struct _gamma_syslog_port *dp = SYSLOG_PORT(port);
+ syslog(dp->prio, "%*.*s",
+ (int) count,
+ (int) count,
+ SCM_BYTEVECTOR_CONTENTS(src) + start);
+ return count;
}
static scm_t_off
_syslog_port_seek(SCM port, scm_t_off offset, int whence)
{
return (scm_t_off) -1;
@@ -177,18 +99,16 @@ SCM_DEFINE_PUBLIC(scm_open_syslog_port, "open-syslog-port", 1, 0, 0,
}
#undef FUNC_NAME
void
_gamma_init_syslog_port()
{
- scm_tc16_syslog_port = scm_make_port_type("syslog-port",
- _syslog_port_fill_input,
+ scm_syslog_port_type = scm_make_port_type("syslog-port",
+ NULL,
_syslog_port_write);
- scm_set_port_mark(scm_tc16_syslog_port, _syslog_port_mark);
- scm_set_port_free(scm_tc16_syslog_port, _syslog_port_free);
- scm_set_port_print(scm_tc16_syslog_port, _syslog_port_print);
- scm_set_port_flush(scm_tc16_syslog_port, _syslog_port_flush);
- scm_set_port_close(scm_tc16_syslog_port, _syslog_port_close);
- scm_set_port_seek(scm_tc16_syslog_port, _syslog_port_seek);
+ scm_set_port_free(scm_syslog_port_type, _syslog_port_free);
+ scm_set_port_print(scm_syslog_port_type, _syslog_port_print);
+ scm_set_port_close(scm_syslog_port_type, _syslog_port_close);
+ scm_set_port_seek(scm_syslog_port_type, _syslog_port_seek);
#include <syslog-port.x>
}

Return to:

Send suggestions and report system problems to the System administrator.