1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 03:30:27 +02:00

Add %null-pointer' to (system foreign)'.

* libguile/foreign.c (sym_null, null_pointer): New variables.
  (scm_foreign_to_bytevector): Raise an error when PTR is NULL.
  (scm_init_foreign): Define SYM_NULL.

* module/system/foreign.scm (%null-pointer): New exported binding.
This commit is contained in:
Ludovic Courtès 2010-03-18 00:27:38 +01:00
parent 5595bd7641
commit 54eb59cf49
2 changed files with 15 additions and 1 deletions

View file

@ -51,6 +51,14 @@ SCM_SYMBOL (sym_size_t, "size_t");
/* that's for pointers, you know. */
SCM_SYMBOL (sym_asterisk, "*");
SCM_SYMBOL (sym_null, "%null-pointer");
/* The cell representing the null pointer. */
static const scm_t_bits null_pointer[2] =
{
scm_tc7_foreign | (SCM_FOREIGN_TYPE_VOID << 8UL),
0
};
static SCM cif_to_procedure (SCM cif, SCM func_ptr);
@ -231,7 +239,10 @@ SCM_DEFINE (scm_foreign_to_bytevector, "foreign->bytevector", 1, 3, 0,
SCM_VALIDATE_FOREIGN_TYPED (1, foreign, VOID);
ptr = SCM_FOREIGN_POINTER (foreign, scm_t_int8);
if (SCM_UNLIKELY (ptr == NULL))
scm_misc_error (FUNC_NAME, "null pointer dereference", SCM_EOL);
if (SCM_UNBNDP (uvec_type))
btype = SCM_ARRAY_ELEMENT_TYPE_VU8;
else
@ -1039,6 +1050,8 @@ scm_init_foreign (void)
# error unsupported sizeof (size_t)
#endif
);
scm_define (sym_null, PTR2SCM (&null_pointer));
}
void

View file

@ -25,6 +25,7 @@
uint16 int16
uint32 int32
uint64 int64
%null-pointer
sizeof alignof