summaryrefslogtreecommitdiff
path: root/pack.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-11-22 14:30:33 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-11-22 14:30:33 +0000
commit7f62113f4d4e29795561df9a0d52a6960e207252 (patch)
tree7b4929124e6add95ef37c61bb7303cf5094b9a2a /pack.c
parent0b2c50f3a7c952a518330ac22c16a72089e613a8 (diff)
* sprintf.c (rb_f_sprintf): preceding ".." for negative
hexadecimal numbers should not appear if prec (e.g. %.4) is specified. * pack.c (NUM2I32): support platforms which does not have 32bit integers (e.g. Cray). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3081 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'pack.c')
-rw-r--r--pack.c41
1 files changed, 38 insertions, 3 deletions
diff --git a/pack.c b/pack.c
index 0ec3741a46..a880083d6f 100644
--- a/pack.c
+++ b/pack.c
@@ -309,11 +309,46 @@ typedef long I32;
typedef unsigned long U32;
#define NUM2I32(x) NUM2LONG(x)
#define NUM2U32(x) NUM2ULONG(x)
-#elif SIZEOF_INT == SIZE32
+#else
typedef int I32;
typedef unsigned int U32;
-#define NUM2I32(x) NUM2INT(x)
-#define NUM2U32(x) NUM2UINT(x)
+# if SIZEOF_INT == SIZE32
+# define NUM2I32(x) NUM2INT(x)
+# define NUM2U32(x) NUM2UINT(x)
+# else
+
+#define I32_MAX 2147483647
+#define I32_MIN (-I32_MAX-1)
+
+static I32
+num2i32(x)
+ VALUE x;
+{
+ long num = NUM2LONG(x);
+
+ if (num < I32_MIN || I32_MAX < num) {
+ rb_raise(rb_eRangeError, "integer %ld too big to convert to `I32'", num);
+ }
+ return (I32)num;
+}
+
+#define U32_MAX 4294967295
+
+static U32
+num2u32(x)
+ VALUE x;
+{
+ unsigned long num = NUM2ULONG(x);
+
+ if (U32_MAX < num) {
+ rb_raise(rb_eRangeError, "integer %ld too big to convert to `U32'", num);
+ }
+ return (U32)num;
+}
+
+# define NUM2I32(x) num2i32(x)
+# define NUM2U32(x) num2u32(x)
+# endif
#endif
#ifdef HAVE_LONG_LONG