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

* numbers.c (scm_sys_check_number_conversions): new function,

defined if Guile is compiled in debugging mode.  currently checks
`scm_num2ulong', should check much much more.

* num2integral.i.c (NUM2INTEGRAL): when converting a bignum to
unsigned, ensure that it's positive.  thanks to Martin Baulig!
This commit is contained in:
Michael Livshin 2001-09-01 17:17:50 +00:00
parent 6f84677a95
commit b10586f098
3 changed files with 60 additions and 3 deletions

View file

@ -4407,6 +4407,52 @@ check_sanity ()
#endif
}
#undef CHECK
#define CHECK \
scm_internal_catch (SCM_BOOL_T, check_body, &data, check_handler, &data); \
if (!SCM_FALSEP (data)) abort();
static SCM
check_body (void *data)
{
SCM num = *(SCM *) data;
scm_num2ulong (num, 1, NULL);
return SCM_UNSPECIFIED;
}
static SCM
check_handler (void *data, SCM tag, SCM throw_args)
{
SCM *num = (SCM *) data;
*num = SCM_BOOL_F;
return SCM_UNSPECIFIED;
}
SCM_DEFINE (scm_sys_check_number_conversions, "%check-number-conversions", 0, 0, 0,
(),
"Number conversion sanity checking.")
#define FUNC_NAME s_scm_sys_check_number_conversions
{
SCM data = SCM_MAKINUM (-1);
CHECK;
data = scm_int2num (INT_MIN);
CHECK;
data = scm_ulong2num (ULONG_MAX);
data = scm_difference (SCM_INUM0, data);
CHECK;
data = scm_ulong2num (ULONG_MAX);
data = scm_sum (SCM_MAKINUM (1), data); data = scm_difference (SCM_INUM0, data);
CHECK;
data = scm_int2num (-10000); data = scm_product (data, data); data = scm_product (data, data);
CHECK;
return SCM_UNSPECIFIED;
}
#undef FUNC_NAME
#endif
void