[6/8] msvcirt: Implement ostream::operator<< for pointers

Iván Matellanes matellanesivan at gmail.com
Tue Jun 21 04:54:25 CDT 2016


Signed-off-by: Iván Matellanes <matellanes.ivan at gmail.com>
---
 dlls/msvcirt/msvcirt.c       | 16 +++++++++++++++-
 dlls/msvcirt/tests/msvcirt.c | 40 ++++++++++++++++++++++++++++++++++++++--
 2 files changed, 53 insertions(+), 3 deletions(-)

diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c
index 6ffdace..e12e4e4 100644
--- a/dlls/msvcirt/msvcirt.c
+++ b/dlls/msvcirt/msvcirt.c
@@ -2780,7 +2780,21 @@ ostream* __thiscall ostream_print_double(ostream *this, double d)
 DEFINE_THISCALL_WRAPPER(ostream_print_ptr, 8)
 ostream* __thiscall ostream_print_ptr(ostream *this, const void *ptr)
 {
-    FIXME("(%p %p) stub\n", this, ptr);
+    ios *base = ostream_get_ios(this);
+    char prefix_str[3] = {'0','x',0}, pointer_str[17];
+
+    TRACE("(%p %p)\n", this, ptr);
+
+    if (ostream_opfx(this)) {
+        if (ptr && base->flags & FLAGS_uppercase)
+            prefix_str[1] = 'X';
+
+        if (sprintf(pointer_str, "%p", ptr) > 0)
+            ostream_writepad(this, prefix_str, pointer_str);
+        else
+            base->state |= IOSTATE_failbit;
+        ostream_osfx(this);
+    }
     return this;
 }
 
diff --git a/dlls/msvcirt/tests/msvcirt.c b/dlls/msvcirt/tests/msvcirt.c
index 096b773..b2f5c8f 100644
--- a/dlls/msvcirt/tests/msvcirt.c
+++ b/dlls/msvcirt/tests/msvcirt.c
@@ -276,6 +276,7 @@ static ostream* (*__thiscall p_ostream_print_str)(ostream*, const char*);
 static ostream* (*__thiscall p_ostream_print_int)(ostream*, int);
 static ostream* (*__thiscall p_ostream_print_float)(ostream*, float);
 static ostream* (*__thiscall p_ostream_print_double)(ostream*, double);
+static ostream* (*__thiscall p_ostream_print_ptr)(ostream*, const void*);
 
 /* Emulate a __thiscall */
 #ifdef __i386__
@@ -463,6 +464,7 @@ static BOOL init(void)
         SET(p_ostream_print_int, "??6ostream@@QEAAAEAV0 at H@Z");
         SET(p_ostream_print_float, "??6ostream@@QEAAAEAV0 at M@Z");
         SET(p_ostream_print_double, "??6ostream@@QEAAAEAV0 at N@Z");
+        SET(p_ostream_print_ptr, "??6ostream@@QEAAAEAV0 at PEBX@Z");
     } else {
         p_operator_new = (void*)GetProcAddress(msvcrt, "??2 at YAPAXI@Z");
         p_operator_delete = (void*)GetProcAddress(msvcrt, "??3 at YAXPAX@Z");
@@ -572,6 +574,7 @@ static BOOL init(void)
         SET(p_ostream_print_int, "??6ostream@@QAEAAV0 at H@Z");
         SET(p_ostream_print_float, "??6ostream@@QAEAAV0 at M@Z");
         SET(p_ostream_print_double, "??6ostream@@QAEAAV0 at N@Z");
+        SET(p_ostream_print_ptr, "??6ostream@@QAEAAV0 at PBX@Z");
     }
     SET(p_ios_static_lock, "?x_lockc at ios@@0U_CRT_CRITICAL_SECTION@@A");
     SET(p_ios_lockc, "?lockc at ios@@KAXXZ");
@@ -3028,19 +3031,21 @@ if (0) /* crashes on native */
 
 static void test_ostream_print(void)
 {
+    const BOOL is_64 = (sizeof(void*) == 8);
     ostream os, *pos;
     strstreambuf ssb, *pssb;
     LONG length, expected_length;
     int i;
 
     struct ostream_print_test {
-        enum { CHAR, STR, INT, FLOAT, DOUBLE } type;
+        enum { CHAR, STR, INT, FLOAT, DOUBLE, PTR } type;
         union {
             char c;
             const char *str;
             int i;
             float f;
             double d;
+            void *ptr;
         } param;
         ios_io_state state;
         ios_flags flags;
@@ -3166,7 +3171,36 @@ static void test_ostream_print(void)
         {DOUBLE, {.d = 9.961472e6}, IOSTATE_goodbit, FLAGS_fixed, 500, ' ', 0, "9961472.000000000000000", IOSTATE_goodbit},
         {DOUBLE, {.d = 8.98846567431157953864652595395e307}, IOSTATE_goodbit, FLAGS_fixed|FLAGS_showpos, 500, ' ', 0, "", IOSTATE_goodbit},
         {DOUBLE, {.d = DBL_MAX}, IOSTATE_goodbit, FLAGS_fixed|FLAGS_showpos, 500, ' ', 5, "     ", IOSTATE_goodbit},
-        {DOUBLE, {.d = DBL_MAX}, IOSTATE_goodbit, FLAGS_showpoint, 500, ' ', 0, "1.79769313486232e+308", IOSTATE_goodbit}
+        {DOUBLE, {.d = DBL_MAX}, IOSTATE_goodbit, FLAGS_showpoint, 500, ' ', 0, "1.79769313486232e+308", IOSTATE_goodbit},
+        /* void* */
+        {PTR, {.ptr = NULL}, IOSTATE_badbit, 0, 6, ' ', 0, "", IOSTATE_badbit|IOSTATE_failbit},
+        {PTR, {.ptr = NULL}, IOSTATE_eofbit, 0, 6, ' ', 0, "", IOSTATE_eofbit|IOSTATE_failbit},
+        {PTR, {.ptr = NULL}, IOSTATE_goodbit, 0, 6, ' ', 0,
+            is_64 ? "0x0000000000000000" : "0x00000000", IOSTATE_goodbit},
+        {PTR, {.ptr = (void*) 0xdeadbeef}, IOSTATE_goodbit, 0, 6, ' ', 0,
+            is_64 ? "0x00000000DEADBEEF" : "0xDEADBEEF", IOSTATE_goodbit},
+        {PTR, {.ptr = (void*) 0xdeadbeef}, IOSTATE_goodbit, 0, 6, '*', 12,
+            is_64 ? "0x00000000DEADBEEF" : "**0xDEADBEEF", IOSTATE_goodbit},
+        {PTR, {.ptr = (void*) 0xdeadbeef}, IOSTATE_goodbit, FLAGS_internal, 6, ' ', 14,
+            is_64 ? "0x00000000DEADBEEF" : "0x    DEADBEEF", IOSTATE_goodbit},
+        {PTR, {.ptr = (void*) 0xdeadbeef}, IOSTATE_goodbit, FLAGS_left, 6, 'x', 11,
+            is_64 ? "0x00000000DEADBEEF" : "0xDEADBEEFx", IOSTATE_goodbit},
+        {PTR, {.ptr = (void*) 0x1234cdef}, IOSTATE_goodbit, FLAGS_dec|FLAGS_showpos, 6, ' ', 0,
+            is_64 ? "0x000000001234CDEF" : "0x1234CDEF", IOSTATE_goodbit},
+        {PTR, {.ptr = (void*) 0x1}, IOSTATE_goodbit, FLAGS_oct|FLAGS_showbase, 6, ' ', 0,
+            is_64 ? "0x0000000000000001" : "0x00000001", IOSTATE_goodbit},
+        {PTR, {.ptr = (void*) 0xffffffff}, IOSTATE_goodbit, FLAGS_hex|FLAGS_showpoint, 6, ' ', 0,
+            is_64 ? "0x00000000FFFFFFFF" : "0xFFFFFFFF", IOSTATE_goodbit},
+        {PTR, {.ptr = (void*) 0xffffffff}, IOSTATE_goodbit, FLAGS_uppercase|FLAGS_fixed, 6, ' ', 0,
+            is_64 ? "0X00000000FFFFFFFF" : "0XFFFFFFFF", IOSTATE_goodbit},
+        {PTR, {.ptr = (void*) 0x1}, IOSTATE_goodbit, FLAGS_uppercase, 6, ' ', 0,
+            is_64 ? "0X0000000000000001" : "0X00000001", IOSTATE_goodbit},
+        {PTR, {.ptr = NULL}, IOSTATE_goodbit, FLAGS_uppercase, 6, ' ', 0,
+            is_64 ? "0x0000000000000000" : "0x00000000", IOSTATE_goodbit},
+        {PTR, {.ptr = NULL}, IOSTATE_goodbit, FLAGS_uppercase|FLAGS_showbase, 12, 'x', 12,
+            is_64 ? "0x0000000000000000" : "xx0x00000000", IOSTATE_goodbit},
+        {PTR, {.ptr = NULL}, IOSTATE_goodbit, FLAGS_internal|FLAGS_uppercase|FLAGS_showbase, 6, '?', 20,
+            is_64 ? "0x??0000000000000000" : "0x??????????00000000", IOSTATE_goodbit}
     };
 
     pssb = (strstreambuf*) call_func1(p_strstreambuf_ctor, &ssb);
@@ -3193,6 +3227,8 @@ static void test_ostream_print(void)
             pos = (ostream*) call_func2_ptr_flt(p_ostream_print_float, &os, tests[i].param.f); break;
         case DOUBLE:
             pos = (ostream*) call_func2_ptr_dbl(p_ostream_print_double, &os, tests[i].param.d); break;
+        case PTR:
+            pos = (ostream*) call_func2(p_ostream_print_ptr, &os, tests[i].param.ptr); break;
         }
 
         length = ssb.base.pptr - ssb.base.pbase;
-- 
2.7.4




More information about the wine-patches mailing list