1 /* gi.h --- buffer against libguile interface churn
2  *
3  * Copyright (C) 2011-2013 Thien-Thi Nguyen
4  *
5  * This is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3, or (at your option)
8  * any later version.
9  *
10  * This software is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this package.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef __GI_H__
20 #define __GI_H__ 1
21 
22 #include "gi-sup/level.h"
23 #include "gi-sup/mkhash.h"
24 
25 extern void *gi_malloc (size_t len, const char *name);
26 extern void *gi_realloc (void *mem, size_t olen, size_t nlen,
27                          const char *name);
28 extern void gi_free (void *mem, size_t len, const char *name);
29 extern size_t gi_smob_free_rv (size_t len);
30 
31 extern SCM gi_gc_protect (SCM object);
32 extern SCM gi_gc_unprotect (SCM object);
33 
34 extern SCM gi_nstring2scm (size_t len, char const *s);
35 extern SCM gi_string2scm (char const * s);
36 extern SCM gi_symbol2scm (char const * name);
37 extern SCM gi_integer2scm (long int);
38 extern SCM gi_nnint2scm (unsigned long int n);
39 
40 extern SCM gi_list_3 (SCM a1, SCM a2, SCM a3);
41 extern SCM gi_list_5 (SCM a1, SCM a2, SCM a3, SCM a4, SCM a5);
42 
43 extern SCM gi_n_vector (size_t len, SCM fill);
44 
45 extern SCM gi_eval_string (char const *);
46 
47 extern SCM gi_lookup (char const *);
48 
49 extern int gi_scm2int (SCM number);
50 extern long gi_scm2long (SCM number);
51 extern unsigned long gi_scm2ulong (SCM number);
52 
53 size_t gi_string_length (SCM string);
54 
55 extern int gi_nfalsep (SCM obj);
56 extern int gi_stringp (SCM obj);
57 extern int gi_symbolp (SCM obj);
58 extern int gi_exactp (SCM obj);
59 
60 #define STRING_OR_SYMBOL_P(obj)                 \
61   (gi_stringp (obj) || gi_symbolp (obj))
62 
63 extern int gi_get_xrep (char *buf, size_t len, SCM symbol_or_string);
64 
65 #define GI_GET_XREP(buf,obj)                    \
66   gi_get_xrep (buf, sizeof buf, obj)
67 
68 #define GI_GET_XREP_MAYBE(buf,obj)              \
69   (STRING_OR_SYMBOL_P (obj)                     \
70    && 0 < GI_GET_XREP (buf, obj))
71 
72 extern void gi_define (const char *name, SCM value);
73 
74 extern SCM gi_primitive_eval (SCM form);
75 extern SCM gi_primitive_load (const char *filename);
76 
77 extern svz_smob_tag_t gi_make_tag (const char *description, size_t sz,
78                                    const void *fn_free,
79                                    const void *fn_print,
80                                    const void *fn_equalp);
81 
82 extern int gi_smob_tagged_p (SCM obj, svz_smob_tag_t tag);
83 extern SCM gi_make_smob (svz_smob_tag_t tag, void *data);
84 extern void *gi_smob_data (SCM smob);
85 
86 #define gi_make_hash_table(size)   MAKE_HASH_TABLE (size)
87 
88 extern SCM gi_hash_clear_x (SCM table);
89 
90 /* Idioms.  */
91 
92 #define BOUNDP(x)  (! SCM_UNBNDP (x))
93 
94 #define PACK_POINTER(x)    (scm_object_address (PTR2SCM (x)))
95 #define UNPACK_POINTER(x)  ((void *) gi_scm2ulong (x))
96 
97 #endif  /* !defined __GI_H__ */
98 
99 /* gi.h ends here */
100