]> www.ginac.de Git - cln.git/commitdiff
64-bit mingw port: Extend fprintdecimal and fprinthexadecimal up to 'long long'.
authorBruno Haible <bruno@clisp.org>
Sun, 27 Oct 2019 18:47:04 +0000 (19:47 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 27 Oct 2019 18:47:04 +0000 (19:47 +0100)
include/cln/io.h
src/base/cl_as_exception.cc
src/base/cl_debug.cc
src/base/output/cl_output_dec.cc
src/base/output/cl_output_hex.cc
src/base/ring/cl_no_ring.cc

index 361c9276a414c72b680b846be54f043107b35e11..0b73636d212410d3f49b64642f565d78c5d5210b 100644 (file)
@@ -37,30 +37,80 @@ inline void fprint (std::ostream& stream, const char * string)
 }
 
 
-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;
index 42713c25df9ecbecf5c1db07bc9766b049c3a35a..51dcf6800038caec45c95300f66d56a68f1b9edd 100644 (file)
@@ -30,9 +30,9 @@ as_error_msg (const cl_number& obj, const char * typestring, const char * filena
        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();
 }
index 6c034cdb0b93196909e11709095853dd5ed06ea9..9c284983987e8fca6584613c52c692afb8615238 100644 (file)
@@ -17,18 +17,18 @@ namespace cln {
 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, ">");
 }
 
index f39edc74f09c61d90a56f11888058a06ecc6bfe3..37413277d76d2496733dd07d352b462b8321fc4b 100644 (file)
@@ -14,15 +14,15 @@ namespace cln {
 // 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);
@@ -30,14 +30,44 @@ void fprintdecimal (std::ostream& stream, unsigned long x)
        #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
index ea3888bf38d9fbc294d818fbf99e857bd904f3dd..a463da85c581d36c0d9af3c354a51ccbf137ba19 100644 (file)
 
 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);
@@ -27,14 +27,44 @@ void fprinthexadecimal (std::ostream& stream, unsigned long x)
        #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
index d15be0fd3187b061114381afff5df9a45aa26704..a5df996713a46e68f7f9719fb9f09e75a37e1b52 100644 (file)
@@ -23,9 +23,9 @@ uninitialized_error_msg (const _cl_ring_element& obj)
 {
        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();
 }
 
@@ -34,13 +34,13 @@ uninitialized_error_msg (const _cl_ring_element& obj_x, const _cl_ring_element&
 {
        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();
 }