[v2 5/7] msvcirt: Implement ostream::operator<< for pointers

Iván Matellanes matellanesivan at gmail.com
Wed Jun 22 04:53:06 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 7d0696a..1a06adf 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 16f5bc3..902b220 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,6 +3031,7 @@ 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;
@@ -3040,8 +3044,9 @@ static void test_ostream_print(void)
         13.14159f, 0.00013f, 0.000013f, 1.0f / 0.0f, -1.0f / 0.0f, 0.0f / 0.0f};
     double param_double[] = {1.0, 3.141592653589793238, 314.1592653589793238, 314.159265358979,
         1231314.269811862199, 9.961472e6, DBL_MAX};
+    void* param_ptr[] = {NULL, (void*) 0xdeadbeef, (void*) 0x1234cdef, (void*) 0x1, (void*) 0xffffffff};
     struct ostream_print_test {
-        enum { CHAR, STR, INT, FLOAT, DOUBLE } type;
+        enum { CHAR, STR, INT, FLOAT, DOUBLE, PTR } type;
         int param_index;
         ios_io_state state;
         ios_flags flags;
@@ -3165,7 +3170,36 @@ static void test_ostream_print(void)
         {DOUBLE, /* 314.159265358979 */ 3, IOSTATE_goodbit, FLAGS_fixed, 12, ' ', 0, "314.159265358979", IOSTATE_goodbit},
         {DOUBLE, /* 1231314.269811862199 */ 4, IOSTATE_goodbit, FLAGS_fixed, 10, ' ', 0, "1231314.2698118621", IOSTATE_goodbit},
         {DOUBLE, /* 9.961472e6 */ 5, IOSTATE_goodbit, FLAGS_fixed, 500, ' ', 0, "9961472.000000000000000", IOSTATE_goodbit},
-        {DOUBLE, /* DBL_MAX */ 6, IOSTATE_goodbit, FLAGS_showpoint, 500, ' ', 0, "1.79769313486232e+308", IOSTATE_goodbit}
+        {DOUBLE, /* DBL_MAX */ 6, IOSTATE_goodbit, FLAGS_showpoint, 500, ' ', 0, "1.79769313486232e+308", IOSTATE_goodbit},
+        /* void* */
+        {PTR, /* NULL */ 0, IOSTATE_badbit, 0, 6, ' ', 0, "", IOSTATE_badbit|IOSTATE_failbit},
+        {PTR, /* NULL */ 0, IOSTATE_eofbit, 0, 6, ' ', 0, "", IOSTATE_eofbit|IOSTATE_failbit},
+        {PTR, /* NULL */ 0, IOSTATE_goodbit, 0, 6, ' ', 0,
+            is_64 ? "0x0000000000000000" : "0x00000000", IOSTATE_goodbit},
+        {PTR, /* 0xdeadbeef */ 1, IOSTATE_goodbit, 0, 6, ' ', 0,
+            is_64 ? "0x00000000DEADBEEF" : "0xDEADBEEF", IOSTATE_goodbit},
+        {PTR, /* 0xdeadbeef */ 1, IOSTATE_goodbit, 0, 6, '*', 12,
+            is_64 ? "0x00000000DEADBEEF" : "**0xDEADBEEF", IOSTATE_goodbit},
+        {PTR, /* 0xdeadbeef */ 1, IOSTATE_goodbit, FLAGS_internal, 6, ' ', 14,
+            is_64 ? "0x00000000DEADBEEF" : "0x    DEADBEEF", IOSTATE_goodbit},
+        {PTR, /* 0xdeadbeef */ 1, IOSTATE_goodbit, FLAGS_left, 6, 'x', 11,
+            is_64 ? "0x00000000DEADBEEF" : "0xDEADBEEFx", IOSTATE_goodbit},
+        {PTR, /* 0x1234cdef */ 2, IOSTATE_goodbit, FLAGS_dec|FLAGS_showpos, 6, ' ', 0,
+            is_64 ? "0x000000001234CDEF" : "0x1234CDEF", IOSTATE_goodbit},
+        {PTR, /* 0x1 */ 3, IOSTATE_goodbit, FLAGS_oct|FLAGS_showbase, 6, ' ', 0,
+            is_64 ? "0x0000000000000001" : "0x00000001", IOSTATE_goodbit},
+        {PTR, /* 0xffffffff */ 4, IOSTATE_goodbit, FLAGS_hex|FLAGS_showpoint, 6, ' ', 0,
+            is_64 ? "0x00000000FFFFFFFF" : "0xFFFFFFFF", IOSTATE_goodbit},
+        {PTR, /* 0xffffffff */ 4, IOSTATE_goodbit, FLAGS_uppercase|FLAGS_fixed, 6, ' ', 0,
+            is_64 ? "0X00000000FFFFFFFF" : "0XFFFFFFFF", IOSTATE_goodbit},
+        {PTR, /* 0x1 */ 3, IOSTATE_goodbit, FLAGS_uppercase, 6, ' ', 0,
+            is_64 ? "0X0000000000000001" : "0X00000001", IOSTATE_goodbit},
+        {PTR, /* NULL */ 0, IOSTATE_goodbit, FLAGS_uppercase, 6, ' ', 0,
+            is_64 ? "0x0000000000000000" : "0x00000000", IOSTATE_goodbit},
+        {PTR, /* NULL */ 0, IOSTATE_goodbit, FLAGS_uppercase|FLAGS_showbase, 12, 'x', 12,
+            is_64 ? "0x0000000000000000" : "xx0x00000000", IOSTATE_goodbit},
+        {PTR, /* NULL */ 0, IOSTATE_goodbit, FLAGS_internal|FLAGS_uppercase|FLAGS_showbase, 6, '?', 20,
+            is_64 ? "0x??0000000000000000" : "0x??????????00000000", IOSTATE_goodbit}
     };
 
     pssb = call_func1(p_strstreambuf_ctor, &ssb);
@@ -3192,6 +3226,8 @@ static void test_ostream_print(void)
             pos = call_func2_ptr_flt(p_ostream_print_float, &os, param_float[tests[i].param_index]); break;
         case DOUBLE:
             pos = call_func2_ptr_dbl(p_ostream_print_double, &os, param_double[tests[i].param_index]); break;
+        case PTR:
+            pos = call_func2(p_ostream_print_ptr, &os, param_ptr[tests[i].param_index]); break;
         }
 
         length = ssb.base.pptr - ssb.base.pbase;
-- 
2.7.4




More information about the wine-patches mailing list