comparison src/database.c @ 5495:1f0b15040456

Merge.
author Aidan Kehoe <kehoea@parhasard.net>
date Sun, 01 May 2011 18:44:03 +0100
parents 308d34e9f07d
children 56144c8593a8
comparison
equal deleted inserted replaced
5494:861f2601a38b 5495:1f0b15040456
1 /* Database access routines 1 /* Database access routines
2 Copyright (C) 1996, William M. Perry 2 Copyright (C) 1996, William M. Perry
3 Copyright (C) 2001, 2002, 2005 Ben Wing. 3 Copyright (C) 2001, 2002, 2005, 2010 Ben Wing.
4 4
5 This file is part of XEmacs. 5 This file is part of XEmacs.
6 6
7 XEmacs is free software; you can redistribute it and/or modify it 7 XEmacs is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the 8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any 9 Free Software Foundation, either version 3 of the License, or (at your
10 later version. 10 option) any later version.
11 11
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT 12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details. 15 for more details.
16 16
17 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
18 along with XEmacs; see the file COPYING. If not, write to 18 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21 19
22 /* Synched up with: Not in FSF. */ 20 /* Synched up with: Not in FSF. */
23 21
24 /* Written by Bill Perry */ 22 /* Written by Bill Perry */
25 /* Substantially rewritten by Martin Buchholz */ 23 /* Substantially rewritten by Martin Buchholz */
145 Lisp_Object (*last_error) (Lisp_Database *); 143 Lisp_Object (*last_error) (Lisp_Database *);
146 } DB_FUNCS; 144 } DB_FUNCS;
147 145
148 struct Lisp_Database 146 struct Lisp_Database
149 { 147 {
150 struct LCRECORD_HEADER header; 148 NORMAL_LISP_OBJECT_HEADER header;
151 Lisp_Object fname; 149 Lisp_Object fname;
152 int mode; 150 int mode;
153 int access_; 151 int access_;
154 int dberrno; 152 int dberrno;
155 int live_p; 153 int live_p;
178 176
179 177
180 static Lisp_Database * 178 static Lisp_Database *
181 allocate_database (void) 179 allocate_database (void)
182 { 180 {
183 Lisp_Database *db = ALLOC_LCRECORD_TYPE (Lisp_Database, &lrecord_database); 181 Lisp_Object obj = ALLOC_NORMAL_LISP_OBJECT (database);
182 Lisp_Database *db = XDATABASE (obj);
184 183
185 db->fname = Qnil; 184 db->fname = Qnil;
186 db->live_p = 0; 185 db->live_p = 0;
187 #ifdef HAVE_BERKELEY_DB 186 #ifdef HAVE_BERKELEY_DB
188 db->db_handle = NULL; 187 db->db_handle = NULL;
214 int UNUSED (escapeflag)) 213 int UNUSED (escapeflag))
215 { 214 {
216 Lisp_Database *db = XDATABASE (obj); 215 Lisp_Database *db = XDATABASE (obj);
217 216
218 if (print_readably) 217 if (print_readably)
219 printing_unreadable_lcrecord (obj, 0); 218 printing_unreadable_lisp_object (obj, 0);
220 219
221 write_fmt_string_lisp (printcharfun, "#<database \"%s\" (%s/%s/", 220 write_fmt_string_lisp (printcharfun, "#<database \"%s\" (%s/%s/",
222 3, db->fname, db->funcs->get_type (db), 221 3, db->fname, db->funcs->get_type (db),
223 db->funcs->get_subtype (db)); 222 db->funcs->get_subtype (db));
224 223
229 228
230 write_fmt_string_lisp (printcharfun, "coding: %s ", 1, 229 write_fmt_string_lisp (printcharfun, "coding: %s ", 1,
231 XSYMBOL_NAME (XCODING_SYSTEM_NAME 230 XSYMBOL_NAME (XCODING_SYSTEM_NAME
232 (db->coding_system))); 231 (db->coding_system)));
233 232
234 write_fmt_string (printcharfun, "0x%x>", db->header.uid); 233 write_fmt_string (printcharfun, "0x%x>", LISP_OBJECT_UID (obj));
235 } 234 }
236 235
237 static void 236 static void
238 finalize_database (void *header, int for_disksave) 237 finalize_database (Lisp_Object obj)
239 { 238 {
240 Lisp_Database *db = (Lisp_Database *) header; 239 Lisp_Database *db = XDATABASE (obj);
241 240
242 if (for_disksave)
243 {
244 invalid_operation
245 ("Can't dump an emacs containing database objects",
246 wrap_database (db));
247 }
248 db->funcs->close (db); 241 db->funcs->close (db);
249 } 242 }
250 243
251 DEFINE_LRECORD_IMPLEMENTATION ("database", database, 244 DEFINE_NODUMP_LISP_OBJECT ("database", database,
252 0, /*dumpable-flag*/ 245 mark_database, print_database,
253 mark_database, print_database, 246 finalize_database, 0, 0,
254 finalize_database, 0, 0, 247 database_description,
255 database_description, 248 Lisp_Database);
256 Lisp_Database);
257 249
258 DEFUN ("close-database", Fclose_database, 1, 1, 0, /* 250 DEFUN ("close-database", Fclose_database, 1, 1, 0, /*
259 Close database DATABASE. 251 Close database DATABASE.
260 */ 252 */
261 (database)) 253 (database))
858 } 850 }
859 851
860 void 852 void
861 syms_of_database (void) 853 syms_of_database (void)
862 { 854 {
863 INIT_LRECORD_IMPLEMENTATION (database); 855 INIT_LISP_OBJECT (database);
864 856
865 DEFSYMBOL (Qdatabasep); 857 DEFSYMBOL (Qdatabasep);
866 #ifdef HAVE_DBM 858 #ifdef HAVE_DBM
867 DEFSYMBOL (Qdbm); 859 DEFSYMBOL (Qdbm);
868 #endif 860 #endif