From ac6f7b0d3e554a6dd1e3346387363043fd64be03 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 13 Jan 2022 07:55:56 -0800 Subject: cptr-int: allow full unsigned range. The cptr-int function requries an address to be expressed as a signed integer, which is incovenient. E.g. -2147483648 to 2147483647 in a 32 bit address space. Let's fix it to accept an extended range. * lib.c (cptr_int): Convert the argument value to a ucnum if it is positive according to plusp, otherwise to cnum. Then either one to the mem_t * pointer. Thus we can accept either signed or unsigned values. * txr.1: Document the extended range of cptr-int. --- lib.c | 5 ++++- txr.1 | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib.c b/lib.c index fa03e7c0..91768c3a 100644 --- a/lib.c +++ b/lib.c @@ -9817,7 +9817,10 @@ val cptr_int(val n, val type_sym_in) { val self = lit("cptr-int"); val type_sym = default_null_arg(type_sym_in); - return cptr_typed(coerce(mem_t *, c_num(n, self)), type_sym, 0); + return cptr_typed(if3(plusp(n), + coerce(mem_t *, c_unum(n, self)), + coerce(mem_t *, c_num(n, self))), + type_sym, 0); } val cptr_obj(val obj, val type_sym_in) diff --git a/txr.1 b/txr.1 index ef9f7f5e..6ef01d69 100644 --- a/txr.1 +++ b/txr.1 @@ -62058,13 +62058,26 @@ object. The .meta integer -parameter must be an integer which is in range for a pointer value. +argument must be an integer which is in range for a pointer value. Note: this range is wider than the .code fixnum range; a portion of the range of .code bignum integers can denote pointers. +An extended range of values is accepted. The entire addressable space may be +expressed by non-negative values. A range of negative values also expresses a +portion of the address space, in accordance with the platform's concept of a +signed integer. + +For instance, on a system with 32 bit addresses, the values 0 to 4294967295 +express all of the addresses as a pure binary value. Furthermore, the values +-2147483648 to -1 also express the upper part of this range, corresponding, +respectively, to the addresses 2147483648 to 4294967295. On that platform, +values of +.meta integer +outside of the range -2147483648 to 4294967295 are invalid. + The .meta type-symbol argument should be a symbol. If omitted, it defaults to -- cgit v1.2.3