1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-10 22:10:21 +02:00

add scm_{to,from}_{u,}intptr_t

* libguile/numbers.h (scm_to_intptr_t, scm_from_intptr_t)
  (scm_to_uintptr_t, scm_from_uintptr_t): New defines.

* libguile/foreign.c: Remove definitions here; adapt callers to use new
  names with _t suffixes.
This commit is contained in:
Andy Wingo 2013-05-23 14:18:47 +02:00
parent d4da9ba9c0
commit 0b3b73698c
2 changed files with 31 additions and 13 deletions

View file

@ -65,16 +65,6 @@ SCM_SYMBOL (sym_null_pointer_error, "null-pointer-error");
/* The cell representing the null pointer. */
static SCM null_pointer;
#if SIZEOF_VOID_P == 4
# define scm_to_uintptr scm_to_uint32
# define scm_from_uintptr scm_from_uint32
#elif SIZEOF_VOID_P == 8
# define scm_to_uintptr scm_to_uint64
# define scm_from_uintptr scm_from_uint64
#else
# error unsupported pointer size
#endif
/* Raise a null pointer dereference error. */
static void
@ -125,7 +115,7 @@ SCM_DEFINE (scm_make_pointer, "make-pointer", 1, 1, 0,
void *c_finalizer;
scm_t_uintptr c_address;
c_address = scm_to_uintptr (address);
c_address = scm_to_uintptr_t (address);
if (SCM_UNBNDP (finalizer))
c_finalizer = NULL;
else
@ -173,7 +163,7 @@ SCM_DEFINE (scm_pointer_address, "pointer-address", 1, 0, 0,
{
SCM_VALIDATE_POINTER (1, pointer);
return scm_from_uintptr ((scm_t_uintptr) SCM_POINTER_VALUE (pointer));
return scm_from_uintptr_t ((scm_t_uintptr) SCM_POINTER_VALUE (pointer));
}
#undef FUNC_NAME
@ -324,7 +314,7 @@ void
scm_i_pointer_print (SCM pointer, SCM port, scm_print_state *pstate)
{
scm_puts_unlocked ("#<pointer 0x", port);
scm_uintprint (scm_to_uintptr (scm_pointer_address (pointer)), 16, port);
scm_uintprint (scm_to_uintptr_t (scm_pointer_address (pointer)), 16, port);
scm_putc_unlocked ('>', port);
}

View file

@ -514,6 +514,34 @@ SCM_API SCM scm_from_mpz (mpz_t rop);
#endif
#endif
#if SCM_SIZEOF_INTPTR_T == 0
/* No intptr_t; use size_t functions. */
#define scm_to_intptr_t scm_to_ssize_t
#define scm_from_intptr_t scm_from_ssize_t
#elif SCM_SIZEOF_INTPTR_T == 4
#define scm_to_intptr_t scm_to_int32
#define scm_from_intptr_t scm_from_int32
#elif SCM_SIZEOF_INTPTR_T == 8
#define scm_to_intptr_t scm_to_int64
#define scm_from_intptr_t scm_from_int64
#else
#error sizeof(intptr_t) is not 4 or 8.
#endif
#if SCM_SIZEOF_UINTPTR_T == 0
/* No uintptr_t; use size_t functions. */
#define scm_to_uintptr_t scm_to_size_t
#define scm_from_uintptr_t scm_from_size_t
#elif SCM_SIZEOF_UINTPTR_T == 4
#define scm_to_uintptr_t scm_to_uint32
#define scm_from_uintptr_t scm_from_uint32
#elif SCM_SIZEOF_UINTPTR_T == 8
#define scm_to_uintptr_t scm_to_uint64
#define scm_from_uintptr_t scm_from_uint64
#else
#error sizeof(uintptr_t) is not 4 or 8.
#endif
/* conversion functions for double */
SCM_API int scm_is_real (SCM val);