summaryrefslogtreecommitdiffabout
Unidiff
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
@@ -34,7 +34,7 @@ AC_PROG_INSTALL
34AC_PROG_LN_S 34AC_PROG_LN_S
35AM_PROG_LIBTOOL 35AM_PROG_LIBTOOL
36 36
37GINT_INIT(gint,[1.8]) 37GINT_INIT(gint,[2.2.0])
38 38
39AC_SUBST(INCLUDEPATH) 39AC_SUBST(INCLUDEPATH)
40AC_MSG_CHECKING(for additional includes) 40AC_MSG_CHECKING(for additional includes)
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
@@ -32,7 +32,7 @@ gamma_xml_parser_create(XML_Parser parser)
32{ 32{
33 struct gamma_xml_parser *gp; 33 struct gamma_xml_parser *gp;
34 34
35 gp = scm_malloc(sizeof (*gp)); 35 gp = scm_gc_malloc(sizeof (*gp), "xml_parser");
36 gp->parser = parser; 36 gp->parser = parser;
37 SCM_RETURN_NEWSMOB(gamma_xml_parser_tag, gp); 37 SCM_RETURN_NEWSMOB(gamma_xml_parser_tag, gp);
38} 38}
@@ -40,7 +40,7 @@ gamma_xml_parser_create(XML_Parser parser)
40 #define GAMMA_XML_PARSER_PTR(smob) \ 40 #define GAMMA_XML_PARSER_PTR(smob) \
41 ((struct gamma_xml_parser *)SCM_CDR(smob)) 41 ((struct gamma_xml_parser *)SCM_CDR(smob))
42 42
43static scm_sizet 43static size_t
44gamma_xml_parser_free(SCM smob) 44gamma_xml_parser_free(SCM smob)
45{ 45{
46 struct gamma_xml_parser *gp = GAMMA_XML_PARSER_PTR(smob); 46 struct gamma_xml_parser *gp = GAMMA_XML_PARSER_PTR(smob);
@@ -84,7 +84,7 @@ gamma_xml_parser_print(SCM smob, SCM port, scm_print_state *pstate)
84} 84}
85 85
86static void 86static void
87gamma_xml_parser_init() 87gamma_xml_parser_init(void)
88{ 88{
89 gamma_xml_parser_tag = 89 gamma_xml_parser_tag =
90 scm_make_smob_type("XML_Parser", 90 scm_make_smob_type("XML_Parser",
@@ -96,7 +96,7 @@ gamma_xml_parser_init()
96 96
97 97
98static struct gamma_expat_user_data * 98static struct gamma_expat_user_data *
99make_user_data () 99make_user_data(void)
100{ 100{
101 int i; 101 int i;
102 102
@@ -153,7 +153,7 @@ SCM_DEFINE_PUBLIC(scm_xml_primitive_make_parser, "xml-primitive-make-parser",
153 } else 153 } else
154 parser = XML_ParserCreate(encoding); 154 parser = XML_ParserCreate(encoding);
155 if (!parser) 155 if (!parser)
156 scm_memory_error(FUNC_NAME); 156 scm_report_out_of_memory();
157 XML_SetUserData(parser, make_user_data()); 157 XML_SetUserData(parser, make_user_data());
158 free(encoding); 158 free(encoding);
159 return gamma_xml_parser_create(parser); 159 return gamma_xml_parser_create(parser);
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
@@ -31,18 +31,18 @@ static long sql_connect_tag = -1;
31 31
32/* SMOB functions: */ 32/* SMOB functions: */
33static SCM 33static SCM
34sql_connect_mark (SCM connect_smob) 34sql_connect_mark(SCM connect_smob)
35{ 35{
36 struct sql_connect *conn = (struct sql_connect *)SCM_CDR(connect_smob); 36 struct sql_connect *conn = (struct sql_connect *)SCM_CDR(connect_smob);
37 return sql_iftab[conn->iface].mark(conn); 37 if (sql_iftab[conn->iface].mark)
38 return sql_iftab[conn->iface].mark(conn);
38} 39}
39 40
40static scm_sizet 41static size_t
41sql_connect_free (SCM connect_smob) 42sql_connect_free(SCM connect_smob)
42{ 43{
43 scm_sizet size = sizeof(struct sql_connect);
44 struct sql_connect *conn = (struct sql_connect *)SCM_CDR(connect_smob); 44 struct sql_connect *conn = (struct sql_connect *)SCM_CDR(connect_smob);
45 size += sql_iftab[conn->iface].free(conn); 45 sql_iftab[conn->iface].free(conn);
46 if (conn->hostname) 46 if (conn->hostname)
47 free(conn->hostname); 47 free(conn->hostname);
48 if (conn->username) 48 if (conn->username)
@@ -50,7 +50,7 @@ sql_connect_free (SCM connect_smob)
50 if (conn->database) 50 if (conn->database)
51 free(conn->database); 51 free(conn->database);
52 scm_gc_free(conn, sizeof *conn, "SQL connection"); 52 scm_gc_free(conn, sizeof *conn, "SQL connection");
53 return size; 53 return 0;
54} 54}
55 55
56static int 56static int
@@ -88,7 +88,7 @@ sql_find_iface(const char *name)
88} 88}
89 89
90SCM 90SCM
91sql_connect_create (char *name) 91sql_connect_create(char *name)
92{ 92{
93 struct sql_connect *conn; 93 struct sql_connect *conn;
94 int iface = sql_find_iface(name); 94 int iface = sql_find_iface(name);
@@ -97,16 +97,16 @@ sql_connect_create (char *name)
97 "Unknown SQL interface ~S", 97 "Unknown SQL interface ~S",
98 scm_list_1(scm_from_locale_string(name))); 98 scm_list_1(scm_from_locale_string(name)));
99 99
100 conn = scm_gc_malloc (sizeof (*conn), "sql_connect"); 100 conn = scm_gc_malloc(sizeof (*conn), "sql_connect");
101 memset(conn, 0, sizeof *conn); 101 memset(conn, 0, sizeof *conn);
102 conn->iface = iface; 102 conn->iface = iface;
103 SCM_RETURN_NEWSMOB (sql_connect_tag, conn); 103 SCM_RETURN_NEWSMOB(sql_connect_tag, conn);
104} 104}
105 105
106static int 106static int
107scm_is_sql_connect (SCM scm) 107scm_is_sql_connect(SCM scm)
108{ 108{
109 return SCM_NIMP (scm) && SCM_CAR (scm) == (SCM) sql_connect_tag; 109 return SCM_NIMP(scm) && SCM_CAR (scm) == (SCM) sql_connect_tag;
110} 110}
111 111
112/* Interface */ 112/* Interface */
@@ -134,7 +134,7 @@ gamma_cvt_iface(SCM inval, void *outval, const char *func_name)
134} 134}
135 135
136 136
137SCM_DEFINE_PUBLIC (sql_open_connection, "sql-open-connection", 1, 0, 0, 137SCM_DEFINE_PUBLIC(sql_open_connection, "sql-open-connection", 1, 0, 0,
138 (SCM param), 138 (SCM param),
139"Connect to a database. Take connection parameters from @var{param}, " 139"Connect to a database. Take connection parameters from @var{param}, "
140"which must be a list of conses. In each cons, the @samp{car} contains " 140"which must be a list of conses. In each cons, the @samp{car} contains "
@@ -185,7 +185,7 @@ SCM_DEFINE_PUBLIC (sql_open_connection, "sql-open-connection", 1, 0, 0,
185} 185}
186#undef FUNC_NAME 186#undef FUNC_NAME
187 187
188SCM_DEFINE_PUBLIC (sql_close_connection, "sql-close-connection", 1, 0, 0, 188SCM_DEFINE_PUBLIC(sql_close_connection, "sql-close-connection", 1, 0, 0,
189 (SCM conn), 189 (SCM conn),
190 "Close connection to a database.") 190 "Close connection to a database.")
191#define FUNC_NAME s_sql_close_connection 191#define FUNC_NAME s_sql_close_connection
@@ -198,7 +198,7 @@ SCM_DEFINE_PUBLIC (sql_close_connection, "sql-close-connection", 1, 0, 0,
198} 198}
199#undef FUNC_NAME 199#undef FUNC_NAME
200 200
201SCM_DEFINE_PUBLIC (sql_query, "sql-query", 2, 0, 0, 201SCM_DEFINE_PUBLIC(sql_query, "sql-query", 2, 0, 0,
202 (SCM conn, SCM query), 202 (SCM conn, SCM query),
203"Send the SQL query @var{query} to the server using connection @var{conn} \ 203"Send the SQL query @var{query} to the server using connection @var{conn} \
204and return the result.\n\ 204and return the result.\n\
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
@@ -39,7 +39,7 @@ struct sql_result {
39struct sql_iface { 39struct sql_iface {
40 char *name; 40 char *name;
41 SCM (*mark) (struct sql_connect *); 41 SCM (*mark) (struct sql_connect *);
42 scm_sizet (*free) (struct sql_connect *); 42 size_t (*free) (struct sql_connect *);
43 SCM (*connect) (SCM parmlist, const char *func_name); 43 SCM (*connect) (SCM parmlist, const char *func_name);
44 void (*close) (struct sql_connect *); 44 void (*close) (struct sql_connect *);
45 SCM (*query) (struct sql_connect *, const char *query); 45 SCM (*query) (struct sql_connect *, const char *query);
diff --git a/src/mysql.c b/src/mysql.c
index 1310212..dcc1847 100644
--- a/src/mysql.c
+++ b/src/mysql.c
@@ -21,24 +21,17 @@
21#include <guile-sql.h> 21#include <guile-sql.h>
22#include <mysql/mysql.h> 22#include <mysql/mysql.h>
23 23
24static SCM 24static size_t
25s_mysql_mark(struct sql_connect *conn)
26{
27 return SCM_BOOL_F;
28}
29
30static scm_sizet
31s_mysql_free(struct sql_connect *conn) 25s_mysql_free(struct sql_connect *conn)
32{ 26{
33 MYSQL *mysql = (MYSQL*) conn->data; 27 MYSQL *mysql = (MYSQL*) conn->data;
34 if (!mysql) 28 if (mysql)
35 return 0; 29 mysql_close(mysql);
36 mysql_close(mysql); 30 return 0;
37 return sizeof(MYSQL);
38} 31}
39 32
40static SCM 33static SCM
41s_mysql_connect (SCM parmlist, const char *func_name) 34s_mysql_connect(SCM parmlist, const char *func_name)
42{ 35{
43 char *hostname = NULL; 36 char *hostname = NULL;
44 int port = 0; 37 int port = 0;
@@ -225,7 +218,7 @@ s_mysql_close(struct sql_connect *conn)
225 218
226struct sql_iface mysql_iface = { 219struct sql_iface mysql_iface = {
227 "mysql", 220 "mysql",
228 s_mysql_mark, 221 NULL, /* mark */
229 s_mysql_free, 222 s_mysql_free,
230 s_mysql_connect, 223 s_mysql_connect,
231 s_mysql_close, 224 s_mysql_close,
diff --git a/src/pgsql.c b/src/pgsql.c
index c5cf51e..1421c40 100644
--- a/src/pgsql.c
+++ b/src/pgsql.c
@@ -21,24 +21,17 @@
21#include <guile-sql.h> 21#include <guile-sql.h>
22#include <libpq-fe.h> 22#include <libpq-fe.h>
23 23
24static SCM 24static size_t
25s_pgsql_mark(struct sql_connect *conn)
26{
27 return SCM_BOOL_F;
28}
29
30static scm_sizet
31s_pgsql_free(struct sql_connect *conn) 25s_pgsql_free(struct sql_connect *conn)
32{ 26{
33 PGconn *pgconn = (PGconn*) conn->data; 27 PGconn *pgconn = (PGconn*) conn->data;
34 if (!pgconn) 28 if (pgconn)
35 return 0; 29 PQfinish(pgconn);
36 PQfinish(pgconn); 30 return 0;
37 return sizeof(pgconn);
38} 31}
39 32
40static SCM 33static SCM
41s_pgsql_connect (SCM parmlist, const char *func_name) 34s_pgsql_connect(SCM parmlist, const char *func_name)
42{ 35{
43 char *hostname = NULL; 36 char *hostname = NULL;
44 char *port = NULL; 37 char *port = NULL;
@@ -168,15 +161,15 @@ static void
168s_pgsql_close(struct sql_connect *conn) 161s_pgsql_close(struct sql_connect *conn)
169{ 162{
170 PGconn *pgconn = (PGconn*) conn->data; 163 PGconn *pgconn = (PGconn*) conn->data;
171 if (!pgconn) 164 if (pgconn) {
172 return; 165 PQfinish(pgconn);
173 PQfinish(pgconn); 166 conn->data = NULL;
174 conn->data = NULL; 167 }
175} 168}
176 169
177struct sql_iface pgsql_iface = { 170struct sql_iface pgsql_iface = {
178 "pgsql", 171 "pgsql",
179 s_pgsql_mark, 172 NULL, /* mark */
180 s_pgsql_free, 173 s_pgsql_free,
181 s_pgsql_connect, 174 s_pgsql_connect,
182 s_pgsql_close, 175 s_pgsql_close,
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
@@ -28,7 +28,7 @@ typedef off_t scm_t_off;
28#endif 28#endif
29 29
30#define GAMMA_SYSLOG_PORT_BUFSIZE 1024 30#define GAMMA_SYSLOG_PORT_BUFSIZE 1024
31static scm_t_bits scm_tc16_syslog_port; 31static scm_t_port_type *scm_syslog_port_type;
32struct _gamma_syslog_port { 32struct _gamma_syslog_port {
33 int prio; 33 int prio;
34}; 34};
@@ -37,118 +37,40 @@ static SCM
37_make_syslog_port(int prio) 37_make_syslog_port(int prio)
38{ 38{
39 struct _gamma_syslog_port *dp; 39 struct _gamma_syslog_port *dp;
40 SCM port;
41 scm_port *pt;
42 40
43 dp = scm_gc_malloc (sizeof (struct _gamma_syslog_port), "syslog-port"); 41 dp = scm_gc_typed_calloc (struct _gamma_syslog_port);
44 dp->prio = prio; 42 dp->prio = prio;
45 43 return scm_c_make_port(scm_syslog_port_type,
46 port = scm_new_port_table_entry(scm_tc16_syslog_port); 44 SCM_OPN | SCM_WRTNG | SCM_BUFLINE,
47 pt = SCM_PTAB_ENTRY(port); 45 (scm_t_bits) dp);
48 pt->rw_random = 0;
49 pt->write_buf = scm_gc_malloc(GAMMA_SYSLOG_PORT_BUFSIZE,
50 "syslog port buffer");
51 pt->write_pos = pt->write_buf;
52 pt->write_buf_size = GAMMA_SYSLOG_PORT_BUFSIZE;
53 pt->write_end = pt->write_buf + pt->write_buf_size;
54 SCM_SET_CELL_TYPE(port,
55 (scm_tc16_syslog_port |
56 SCM_OPN | SCM_WRTNG | SCM_BUFLINE));
57 SCM_SETSTREAM(port, dp);
58 return port;
59} 46}
60 47
61#define SYSLOG_PORT(x) ((struct _gamma_syslog_port *) SCM_STREAM (x)) 48#define SYSLOG_PORT(x) ((struct _gamma_syslog_port *) SCM_STREAM (x))
62 49
63static SCM
64_syslog_port_mark(SCM port)
65{
66 return SCM_BOOL_F;
67}
68
69static void 50static void
70_syslog_port_flush(SCM port)
71{
72 struct _gamma_syslog_port *dp = SYSLOG_PORT(port);
73 scm_port *pt = SCM_PTAB_ENTRY(port);
74 size_t size = pt->write_pos - pt->write_buf;
75 unsigned char *nl = memchr(pt->write_buf, '\n', size);
76 int wrsize;
77
78 if (!nl)
79 return;
80
81 wrsize = nl - pt->write_buf;
82
83 *nl = 0;
84 syslog (dp->prio, "%s", (char *) pt->write_buf);
85 *nl = '\n';
86
87 if (wrsize < size) {
88 size_t write_start;
89
90 nl++;
91 write_start = pt->write_pos - nl;
92 memmove(pt->write_buf, nl, write_start);
93 pt->write_pos = pt->write_buf + write_start;
94 } else
95 pt->write_pos = pt->write_buf;
96}
97
98static int
99_syslog_port_close(SCM port) 51_syslog_port_close(SCM port)
100{ 52{
101 struct _gamma_syslog_port *dp = SYSLOG_PORT(port); 53 struct _gamma_syslog_port *dp = SYSLOG_PORT(port);
102 54 /* nothing */
103 if (dp) {
104 _syslog_port_flush(port);
105 SCM_SETSTREAM(port, NULL);
106 scm_gc_free(dp, sizeof(struct _gamma_syslog_port),
107 "syslog-port");
108 }
109 return 0;
110} 55}
111 56
112static scm_sizet 57static size_t
113_syslog_port_free(SCM port) 58_syslog_port_free(SCM port)
59/* FIXME: basically, a no-op */
114{ 60{
115 _syslog_port_close(port); 61 _syslog_port_close(port);
116 return 0; 62 return 0;
117} 63}
118 64
119static int 65static size_t
120_syslog_port_fill_input(SCM port) 66_syslog_port_write(SCM port, SCM src, size_t start, size_t count)
121{
122 return EOF;
123}
124
125static void
126_syslog_port_write(SCM port, const void *data, size_t size)
127{ 67{
128 scm_port *pt = SCM_PTAB_ENTRY (port); 68 struct _gamma_syslog_port *dp = SYSLOG_PORT(port);
129 size_t space = pt->write_end - pt->write_pos; 69 syslog(dp->prio, "%*.*s",
130 if (space < size) { 70 (int) count,
131 size_t start = pt->write_pos - pt->write_buf; 71 (int) count,
132 size_t new_size = pt->write_buf_size; 72 SCM_BYTEVECTOR_CONTENTS(src) + start);
133 73 return count;
134 do {
135 /*FIXME*/
136 new_size *= 2;
137 } while (new_size - start < size);
138
139 pt->write_buf = scm_gc_realloc(pt->write_buf,
140 pt->write_buf_size,
141 new_size,
142 "syslog port buffer");
143 pt->write_buf_size = new_size;
144 pt->write_end = pt->write_buf + pt->write_buf_size;
145 pt->write_pos = pt->write_buf + start;
146 }
147 memcpy(pt->write_pos, data, size);
148 pt->write_pos += size;
149
150 if (memchr (data, '\n', size))
151 _syslog_port_flush(port);
152} 74}
153 75
154static scm_t_off 76static scm_t_off
@@ -180,15 +102,13 @@ SCM_DEFINE_PUBLIC(scm_open_syslog_port, "open-syslog-port", 1, 0, 0,
180void 102void
181_gamma_init_syslog_port() 103_gamma_init_syslog_port()
182{ 104{
183 scm_tc16_syslog_port = scm_make_port_type("syslog-port", 105 scm_syslog_port_type = scm_make_port_type("syslog-port",
184 _syslog_port_fill_input, 106 NULL,
185 _syslog_port_write); 107 _syslog_port_write);
186 scm_set_port_mark(scm_tc16_syslog_port, _syslog_port_mark); 108 scm_set_port_free(scm_syslog_port_type, _syslog_port_free);
187 scm_set_port_free(scm_tc16_syslog_port, _syslog_port_free); 109 scm_set_port_print(scm_syslog_port_type, _syslog_port_print);
188 scm_set_port_print(scm_tc16_syslog_port, _syslog_port_print); 110 scm_set_port_close(scm_syslog_port_type, _syslog_port_close);
189 scm_set_port_flush(scm_tc16_syslog_port, _syslog_port_flush); 111 scm_set_port_seek(scm_syslog_port_type, _syslog_port_seek);
190 scm_set_port_close(scm_tc16_syslog_port, _syslog_port_close);
191 scm_set_port_seek(scm_tc16_syslog_port, _syslog_port_seek);
192 #include <syslog-port.x> 112 #include <syslog-port.x>
193} 113}
194 114

Return to:

Send suggestions and report system problems to the System administrator.