summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Wette <matt.wette@gmail.com>2017-11-22 16:32:39 +0100
committerLudovic Courtès <ludo@gnu.org>2017-11-22 16:33:57 +0100
commitbb5d316b161add31612e6afe41e5a6ea5851c277 (patch)
tree835e4781a0ec8a9a0844d8c74ce6a1bb379702c6
parent3e7c80a62f760d2110dc19975eb588dd7526a326 (diff)
downloadguile-bb5d316b161add31612e6afe41e5a6ea5851c277.tar.gz
foreign: Add 'uintptr_t' and 'intptr_t'.
* libguile/foreign.c (scm_uintptr_t, scm_intptr_t): New variables. (scm_init_foreign): Define them. * module/system/foreign.scm: Export 'intptr_t' and 'uintptr_t'. * doc/ref/api-foreign.texi (Foreign Types): Document them. Co-authored-by: Ludovic Courtès <ludo@gnu.org>
-rw-r--r--doc/ref/api-foreign.texi2
-rw-r--r--libguile/foreign.c22
-rw-r--r--module/system/foreign.scm1
3 files changed, 25 insertions, 0 deletions
diff --git a/doc/ref/api-foreign.texi b/doc/ref/api-foreign.texi
index bb93d6d1f..d99a33300 100644
--- a/doc/ref/api-foreign.texi
+++ b/doc/ref/api-foreign.texi
@@ -498,6 +498,8 @@ platform-dependent size:
@defvrx {Scheme Variable} size_t
@defvrx {Scheme Variable} ssize_t
@defvrx {Scheme Variable} ptrdiff_t
+@defvrx {Scheme Variable} intptr_t
+@defvrx {Scheme Variable} uintptr_t
Values exported by the @code{(system foreign)} module, representing C
numeric types. For example, @code{long} may be @code{equal?} to
@code{int64} on a 64-bit platform.
diff --git a/libguile/foreign.c b/libguile/foreign.c
index 17af10180..927c46fad 100644
--- a/libguile/foreign.c
+++ b/libguile/foreign.c
@@ -56,6 +56,8 @@ SCM_SYMBOL (sym_unsigned_long, "unsigned-long");
SCM_SYMBOL (sym_size_t, "size_t");
SCM_SYMBOL (sym_ssize_t, "ssize_t");
SCM_SYMBOL (sym_ptrdiff_t, "ptrdiff_t");
+SCM_SYMBOL (sym_intptr_t, "intptr_t");
+SCM_SYMBOL (sym_uintptr_t, "uintptr_t");
/* that's for pointers, you know. */
SCM_SYMBOL (sym_asterisk, "*");
@@ -1248,6 +1250,26 @@ scm_init_foreign (void)
#endif
);
+ scm_define (sym_intptr_t,
+#if SCM_SIZEOF_INTPTR_T == 8
+ scm_from_uint8 (SCM_FOREIGN_TYPE_INT64)
+#elif SCM_SIZEOF_INTPTR_T == 4
+ scm_from_uint8 (SCM_FOREIGN_TYPE_INT32)
+#else
+# error unsupported sizeof (scm_t_intptr)
+#endif
+ );
+
+ scm_define (sym_uintptr_t,
+#if SCM_SIZEOF_UINTPTR_T == 8
+ scm_from_uint8 (SCM_FOREIGN_TYPE_UINT64)
+#elif SCM_SIZEOF_UINTPTR_T == 4
+ scm_from_uint8 (SCM_FOREIGN_TYPE_UINT32)
+#else
+# error unsupported sizeof (scm_t_uintptr)
+#endif
+ );
+
null_pointer = scm_cell (scm_tc7_pointer, 0);
scm_define (sym_null, null_pointer);
}
diff --git a/module/system/foreign.scm b/module/system/foreign.scm
index 3304eb015..d1c2ceb96 100644
--- a/module/system/foreign.scm
+++ b/module/system/foreign.scm
@@ -30,6 +30,7 @@
uint16 int16
uint32 int32
uint64 int64
+ intptr_t uintptr_t
sizeof alignof