From 3075cc93bb80d65e54e3f0cc1872e8139d9084b3 Mon Sep 17 00:00:00 2001 From: Nick Briggs Date: Mon, 15 Aug 2022 13:26:53 -0700 Subject: [PATCH] Fix types for smallp manipulation in arith.h Introduce GetPosSmallp for converting an unsigned value to smallp Use [unsigned] long as input to Get...Smallp to avoid shortening input --- inc/arith.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/inc/arith.h b/inc/arith.h index 35c7299..4d877f2 100644 --- a/inc/arith.h +++ b/inc/arith.h @@ -22,6 +22,9 @@ #define MAX_FIXP 2147483647 /* == 0x7FFFFFFF */ #define MIN_FIXP (-2147483648) /* == 0x80000000 */ +/** + * extract an integer value from a smallp + */ static inline int GetSmalldata(LispPTR x) { if ((SEGMASK & (int)x) == S_POSITIVE) return (int)(x & 0xFFFF); if ((SEGMASK & (int)x) == S_NEGATIVE) return (int)(x | 0xFFFF0000); @@ -29,7 +32,11 @@ static inline int GetSmalldata(LispPTR x) { return (0); } -static inline LispPTR GetSmallp(int x) { +/** + * construct a smallp from an integer value + */ + +static inline LispPTR GetSmallp(long x) { if (x >= 0) { if (x <= MAX_SMALL) return (LispPTR)(S_POSITIVE | x); } else { @@ -39,6 +46,15 @@ static inline LispPTR GetSmallp(int x) { return (S_POSITIVE | 0); } +/** + * construct a smallp from an unsigned value + */ +static inline LispPTR GetPosSmallp(unsigned long x) { + if (x <= MAX_SMALL) return (LispPTR)(S_POSITIVE | x); + error("Not Smallp data"); + return (S_POSITIVE | 0); +} + #define FIXP_VALUE(dest) *((int *)Addr68k_from_LADDR(dest)) #define FLOATP_VALUE(dest) *((float *)Addr68k_from_LADDR(dest))