@@ -28,6 +28,31 @@ namespace mozart {
28
28
29
29
namespace {
30
30
31
+ namespace internal {
32
+ // Helpers to convert strings to nativeint
33
+ template <size_t Size>
34
+ struct StrTo {};
35
+
36
+ template <>
37
+ struct StrTo <4 > {
38
+ static int32_t strto (const char * start, char ** end, int base) {
39
+ return std::strtol (start, end, base);
40
+ }
41
+ };
42
+
43
+ template <>
44
+ struct StrTo <8 > {
45
+ static int64_t strto (const char * start, char ** end, int base) {
46
+ return std::strtoll (start, end, base);
47
+ }
48
+ };
49
+
50
+ template <typename T>
51
+ static T strto (const char * start, char ** end, int base) {
52
+ return StrTo<sizeof (T)>::strto (start, end, base);
53
+ }
54
+ }
55
+
31
56
// /////////////
32
57
// Unpickler //
33
58
// /////////////
@@ -96,9 +121,8 @@ class Unpickler {
96
121
std::string str = readString ();
97
122
char * end = nullptr ;
98
123
errno = 0 ; // reset errno since we need to know if strtoll() overflowed
99
- long long intResult = std::strtoll (str.c_str (), &end, 10 );
124
+ nativeint value = internal::strto<nativeint> (str.c_str (), &end, 10 );
100
125
assert (*end == ' \0 ' && " bad integer string" );
101
- nativeint value = (nativeint) intResult;
102
126
if ((value == SmallInt::min () || value == SmallInt::max ()) &&
103
127
errno == ERANGE) { // Overflow
104
128
return BigInt::build (vm, str);
0 commit comments