}
-extern void fprintdecimal (std::ostream& stream, unsigned long x);
-extern void fprintdecimal (std::ostream& stream, long x);
+extern void fprintdecimal_impl (std::ostream& stream, uintptr_t x);
+extern void fprintdecimal_impl (std::ostream& stream, intptr_t x);
inline void fprintdecimal (std::ostream& stream, unsigned int x)
{
- fprintdecimal(stream,(unsigned long)x);
+ fprintdecimal_impl(stream,(uintptr_t)x);
}
inline void fprintdecimal (std::ostream& stream, int x)
{
- fprintdecimal(stream,(long)x);
+ fprintdecimal_impl(stream,(intptr_t)x);
}
-extern void fprinthexadecimal (std::ostream& stream, unsigned long x);
-extern void fprinthexadecimal (std::ostream& stream, long x);
+inline void fprintdecimal (std::ostream& stream, unsigned long x)
+{
+ fprintdecimal_impl(stream,(uintptr_t)x);
+}
+inline void fprintdecimal (std::ostream& stream, long x)
+{
+ fprintdecimal_impl(stream,(intptr_t)x);
+}
+
+#ifdef HAVE_LONGLONG
+#if long_long_bitsize <= pointer_bitsize
+inline void fprintdecimal (std::ostream& stream, unsigned long long x)
+{
+ fprintdecimal_impl(stream,(uintptr_t)x);
+}
+inline void fprintdecimal (std::ostream& stream, long long x)
+{
+ fprintdecimal_impl(stream,(intptr_t)x);
+}
+#else
+extern void fprintdecimal (std::ostream& stream, unsigned long long x);
+extern void fprintdecimal (std::ostream& stream, long long x);
+#endif
+#endif
+
+extern void fprinthexadecimal_impl (std::ostream& stream, uintptr_t x);
+extern void fprinthexadecimal_impl (std::ostream& stream, intptr_t x);
inline void fprinthexadecimal (std::ostream& stream, unsigned int x)
{
- fprinthexadecimal(stream,(unsigned long)x);
+ fprinthexadecimal_impl(stream,(uintptr_t)x);
}
inline void fprinthexadecimal (std::ostream& stream, int x)
{
- fprinthexadecimal(stream,(long)x);
+ fprinthexadecimal_impl(stream,(intptr_t)x);
}
+inline void fprinthexadecimal (std::ostream& stream, unsigned long x)
+{
+ fprinthexadecimal_impl(stream,(uintptr_t)x);
+}
+inline void fprinthexadecimal (std::ostream& stream, long x)
+{
+ fprinthexadecimal_impl(stream,(intptr_t)x);
+}
+
+#ifdef HAVE_LONGLONG
+#if long_long_bitsize <= pointer_bitsize
+inline void fprinthexadecimal (std::ostream& stream, unsigned long long x)
+{
+ fprinthexadecimal_impl(stream,(uintptr_t)x);
+}
+inline void fprinthexadecimal (std::ostream& stream, long long x)
+{
+ fprinthexadecimal_impl(stream,(intptr_t)x);
+}
+#else
+extern void fprinthexadecimal (std::ostream& stream, unsigned long long x);
+extern void fprinthexadecimal (std::ostream& stream, long long x);
+#endif
+#endif
+
struct cl_print_flags;
struct cl_print_number_flags;
fprint(buf, obj);
#else
fprint(buf, "@0x");
- fprinthexadecimal(buf, (unsigned long)(void*)&obj);
+ fprinthexadecimal(buf, (uintptr_t)(void*)&obj);
fprint(buf, ": 0x");
- fprinthexadecimal(buf, (unsigned long)obj.word);
+ fprinthexadecimal(buf, (uintptr_t)obj.word);
#endif
return buf.str();
}
void cl_dprint_unknown (cl_heap* pointer)
{
fprint(cl_debugout, "<unknown @0x");
- fprinthexadecimal(cl_debugout, (unsigned long) pointer);
+ fprinthexadecimal(cl_debugout, (uintptr_t) pointer);
fprint(cl_debugout, " refcount=");
fprintdecimal(cl_debugout, pointer->refcount);
fprint(cl_debugout, " type=");
- fprinthexadecimal(cl_debugout, (unsigned long) pointer->type);
+ fprinthexadecimal(cl_debugout, (uintptr_t) pointer->type);
fprint(cl_debugout, ">");
}
static void cl_dprint_unknown_immediate (cl_heap* pointer)
{
fprint(cl_debugout, "<unknown @0x");
- fprinthexadecimal(cl_debugout, (unsigned long) pointer);
+ fprinthexadecimal(cl_debugout, (uintptr_t) pointer);
fprint(cl_debugout, ">");
}
// We don't use `stream << x' or `stream << dec << x', because an ostream
// carries so many attributes, and we don't want to modifies these attributes.
-void fprintdecimal (std::ostream& stream, unsigned long x)
+void fprintdecimal_impl (std::ostream& stream, uintptr_t x)
{
- #define bufsize 20
+ #define bufsize (((sizeof(uintptr_t)*53)/22)+1) // 53/22 > 8*log(2)/log(10)
var char buf[bufsize+1];
var char* bufptr = &buf[bufsize];
*bufptr = '\0';
do {
- unsigned long q = x / 10;
- unsigned long r = x % 10;
+ uintptr_t q = x / 10;
+ uintptr_t r = x % 10;
*--bufptr = '0'+r;
x = q;
} while (x > 0);
#undef bufsize
}
-void fprintdecimal (std::ostream& stream, long x)
+void fprintdecimal_impl (std::ostream& stream, intptr_t x)
{
if (x >= 0)
- fprintdecimal(stream,(unsigned long)x);
+ fprintdecimal(stream,(uintptr_t)x);
else {
fprintchar(stream,'-');
- fprintdecimal(stream,(unsigned long)(-1-x)+1);
+ fprintdecimal(stream,(uintptr_t)(-1-x)+1);
}
}
+#if defined(HAVE_LONGLONG) && (long_long_bitsize > pointer_bitsize)
+
+void fprintdecimal (std::ostream& stream, unsigned long long x)
+{
+ #define bufsize (((sizeof(unsigned long long)*53)/22)+1) // 53/22 > 8*log(2)/log(10)
+ var char buf[bufsize+1];
+ var char* bufptr = &buf[bufsize];
+ *bufptr = '\0';
+ do {
+ unsigned long long q = x / 10;
+ unsigned long long r = x % 10;
+ *--bufptr = '0'+r;
+ x = q;
+ } while (x > 0);
+ fprint(stream,bufptr);
+ #undef bufsize
+}
+
+void fprintdecimal (std::ostream& stream, long long x)
+{
+ if (x >= 0)
+ fprintdecimal(stream,(unsigned long long)x);
+ else {
+ fprintchar(stream,'-');
+ fprintdecimal(stream,(unsigned long long)(-1-x)+1);
+ }
+}
+
+#endif
+
} // namespace cln
namespace cln {
-void fprinthexadecimal (std::ostream& stream, unsigned long x)
+void fprinthexadecimal_impl (std::ostream& stream, uintptr_t x)
{
- #define bufsize 16
+ #define bufsize (sizeof(uintptr_t)*2)
var char buf[bufsize+1];
var char* bufptr = &buf[bufsize];
*bufptr = '\0';
do {
- unsigned long q = x / 16;
- unsigned long r = x % 16;
+ uintptr_t q = x / 16;
+ uintptr_t r = x % 16;
*--bufptr = (r<10 ? '0'+r : 'A'-10+r);
x = q;
} while (x > 0);
#undef bufsize
}
-void fprinthexadecimal (std::ostream& stream, long x)
+void fprinthexadecimal_impl (std::ostream& stream, intptr_t x)
{
if (x >= 0)
- fprintdecimal(stream,(unsigned long)x);
+ fprintdecimal(stream,(uintptr_t)x);
else {
fprintchar(stream,'-');
- fprintdecimal(stream,(unsigned long)(-1-x)+1);
+ fprintdecimal(stream,(uintptr_t)(-1-x)+1);
}
}
+#if defined(HAVE_LONGLONG) && (long_long_bitsize > pointer_bitsize)
+
+void fprinthexadecimal (std::ostream& stream, unsigned long long x)
+{
+ #define bufsize (sizeof(unsigned long long)*2)
+ var char buf[bufsize+1];
+ var char* bufptr = &buf[bufsize];
+ *bufptr = '\0';
+ do {
+ unsigned long long q = x / 16;
+ unsigned long long r = x % 16;
+ *--bufptr = (r<10 ? '0'+r : 'A'-10+r);
+ x = q;
+ } while (x > 0);
+ fprint(stream,bufptr);
+ #undef bufsize
+}
+
+void fprinthexadecimal (std::ostream& stream, long long x)
+{
+ if (x >= 0)
+ fprintdecimal(stream,(unsigned long long)x);
+ else {
+ fprintchar(stream,'-');
+ fprintdecimal(stream,(unsigned long long)(-1-x)+1);
+ }
+}
+
+#endif
+
} // namespace cln
{
std::ostringstream buf;
fprint(buf, "Uninitialized ring element @0x");
- fprinthexadecimal(buf, (unsigned long)(void*)&obj);
+ fprinthexadecimal(buf, (uintptr_t)(void*)&obj);
fprint(buf, ": 0x");
- fprinthexadecimal(buf, (unsigned long)obj.rep.word);
+ fprinthexadecimal(buf, (uintptr_t)obj.rep.word);
return buf.str();
}
{
std::ostringstream buf;
fprint(buf, "Uninitialized ring elements @0x");
- fprinthexadecimal(buf, (unsigned long)(void*)&obj_x);
+ fprinthexadecimal(buf, (uintptr_t)(void*)&obj_x);
fprint(buf, ": 0x");
- fprinthexadecimal(buf, (unsigned long)obj_x.rep.word);
+ fprinthexadecimal(buf, (uintptr_t)obj_x.rep.word);
fprint(buf, ", @0x");
- fprinthexadecimal(buf, (unsigned long)(void*)&obj_y);
+ fprinthexadecimal(buf, (uintptr_t)(void*)&obj_y);
fprint(buf, ": 0x");
- fprinthexadecimal(buf, (unsigned long)obj_y.rep.word);
+ fprinthexadecimal(buf, (uintptr_t)obj_y.rep.word);
return buf.str();
}