[12/13] msvcirt: Add support for ios state variables

Iván Matellanes matellanesivan at gmail.com
Fri Jul 17 09:37:18 CDT 2015


---
 dlls/msvcirt/msvcirt.c       | 23 +++++++++++++++++------
 dlls/msvcirt/msvcirt.spec    |  4 ++--
 dlls/msvcirt/tests/msvcirt.c | 33 ++++++++++++++++++++++++++++++++-
 dlls/msvcrt20/msvcrt20.spec  |  4 ++--
 dlls/msvcrt40/msvcrt40.spec  |  4 ++--
 5 files changed, 55 insertions(+), 13 deletions(-)

diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c
index 0ce9fff..eb4e3e4 100644
--- a/dlls/msvcirt/msvcirt.c
+++ b/dlls/msvcirt/msvcirt.c
@@ -30,6 +30,7 @@
 WINE_DEFAULT_DEBUG_CHANNEL(msvcirt);
 
 #define RESERVE_SIZE 512
+#define STATEBUF_SIZE 8
 
 /* ?adjustfield at ios@@2JB */
 const LONG ios_adjustfield = FLAGS_left | FLAGS_right | FLAGS_internal;
@@ -48,6 +49,10 @@ CRITICAL_SECTION_DEBUG ios_static_lock_debug =
 CRITICAL_SECTION ios_static_lock = { &ios_static_lock_debug, -1, 0, 0, 0, 0 };
 /* ?x_maxbit at ios@@0JA */
 LONG ios_maxbit = 0x8000;
+/* ?x_curindex at ios@@0HA */
+int ios_curindex = -1;
+/* ?x_statebuf at ios@@0PAJA */
+LONG ios_statebuf[STATEBUF_SIZE] = {0};
 
 /* class streambuf */
 typedef struct {
@@ -1018,8 +1023,8 @@ void __thiscall ios_init(ios *this, streambuf *sb)
 DEFINE_THISCALL_WRAPPER(ios_iword, 8)
 LONG* __thiscall ios_iword(const ios *this, int index)
 {
-    FIXME("(%p %d) stub\n", this, index);
-    return NULL;
+    TRACE("(%p %d)\n", this, index);
+    return &ios_statebuf[index];
 }
 
 /* ?lock at ios@@QAAXXZ */
@@ -1091,8 +1096,8 @@ int __thiscall ios_precision_get(const ios *this)
 DEFINE_THISCALL_WRAPPER(ios_pword, 8)
 void** __thiscall ios_pword(const ios *this, int index)
 {
-    FIXME("(%p %d) stub\n", this, index);
-    return NULL;
+    TRACE("(%p %d)\n", this, index);
+    return (void**)&ios_statebuf[index];
 }
 
 /* ?rdbuf at ios@@QBEPAVstreambuf@@XZ */
@@ -1245,8 +1250,14 @@ int __thiscall ios_width_get(const ios *this)
 /* ?xalloc at ios@@SAHXZ */
 int __cdecl ios_xalloc(void)
 {
-    FIXME("() stub\n");
-    return 0;
+    int ret;
+
+    TRACE("()\n");
+
+    ios_lockc();
+    ret = (ios_curindex < STATEBUF_SIZE-1) ? ++ios_curindex : -1;
+    ios_unlockc();
+    return ret;
 }
 
 /******************************************************************
diff --git a/dlls/msvcirt/msvcirt.spec b/dlls/msvcirt/msvcirt.spec
index b4dcdc2..4d15bdb 100644
--- a/dlls/msvcirt/msvcirt.spec
+++ b/dlls/msvcirt/msvcirt.spec
@@ -776,10 +776,10 @@
 @ stub -arch=win64 ?writepad at ostream@@AEAAAEAV1 at PEBD0@Z
 @ stub -arch=win32 ?ws@@YAAAVistream@@AAV1@@Z  # class istream & __cdecl ws(class istream &)
 @ stub -arch=win64 ?ws@@YAAEAVistream@@AEAV1@@Z
-# @ extern ?x_curindex at ios@@0HA  # static int ios::x_curindex
+@ extern ?x_curindex at ios@@0HA ios_curindex
 @ extern ?x_lockc at ios@@0U_CRT_CRITICAL_SECTION@@A ios_static_lock
 @ extern ?x_maxbit at ios@@0JA ios_maxbit
-# @ extern ?x_statebuf at ios@@0PAJA  # static long * ios::x_statebuf
+@ extern ?x_statebuf at ios@@0PAJA ios_statebuf
 @ cdecl ?xalloc at ios@@SAHXZ() ios_xalloc
 @ thiscall -arch=win32 ?xsgetn at streambuf@@UAEHPADH at Z(ptr ptr long) streambuf_xsgetn
 @ cdecl -arch=win64 ?xsgetn at streambuf@@UEAAHPEADH at Z(ptr ptr long) streambuf_xsgetn
diff --git a/dlls/msvcirt/tests/msvcirt.c b/dlls/msvcirt/tests/msvcirt.c
index 5fac801..e1390b5 100644
--- a/dlls/msvcirt/tests/msvcirt.c
+++ b/dlls/msvcirt/tests/msvcirt.c
@@ -149,6 +149,11 @@ static int (*__thiscall p_ios_fail)(const ios*);
 static void (*__thiscall p_ios_clear)(ios*, int);
 static LONG *p_ios_maxbit;
 static LONG (*__cdecl p_ios_bitalloc)(void);
+static int *p_ios_curindex;
+static LONG *p_ios_statebuf;
+static LONG* (*__thiscall p_ios_iword)(const ios*, int);
+static void** (*__thiscall p_ios_pword)(const ios*, int);
+static int (*__cdecl p_ios_xalloc)(void);
 
 /* Emulate a __thiscall */
 #ifdef __i386__
@@ -267,6 +272,8 @@ static BOOL init(void)
         SET(p_ios_eof, "?eof at ios@@QEBAHXZ");
         SET(p_ios_fail, "?fail at ios@@QEBAHXZ");
         SET(p_ios_clear, "?clear at ios@@QEAAXH at Z");
+        SET(p_ios_iword, "?iword at ios@@QEBAAEAJH at Z");
+        SET(p_ios_pword, "?pword at ios@@QEBAAEAPEAXH at Z");
     } else {
         p_operator_new = (void*)GetProcAddress(msvcrt, "??2 at YAPAXI@Z");
 
@@ -315,12 +322,17 @@ static BOOL init(void)
         SET(p_ios_eof, "?eof at ios@@QBEHXZ");
         SET(p_ios_fail, "?fail at ios@@QBEHXZ");
         SET(p_ios_clear, "?clear at ios@@QAEXH at Z");
+        SET(p_ios_iword, "?iword at ios@@QBEAAJH at Z");
+        SET(p_ios_pword, "?pword at ios@@QBEAAPAXH at Z");
     }
     SET(p_ios_static_lock, "?x_lockc at ios@@0U_CRT_CRITICAL_SECTION@@A");
     SET(p_ios_lockc, "?lockc at ios@@KAXXZ");
     SET(p_ios_unlockc, "?unlockc at ios@@KAXXZ");
     SET(p_ios_maxbit, "?x_maxbit at ios@@0JA");
     SET(p_ios_bitalloc, "?bitalloc at ios@@SAJXZ");
+    SET(p_ios_curindex, "?x_curindex at ios@@0HA");
+    SET(p_ios_statebuf, "?x_statebuf at ios@@0PAJA");
+    SET(p_ios_xalloc, "?xalloc at ios@@SAHXZ");
 
     init_thiscall_thunk();
     return TRUE;
@@ -893,7 +905,8 @@ static void test_ios(void)
     struct ios_lock_arg lock_arg;
     HANDLE thread;
     BOOL locked;
-    LONG expected, ret;
+    LONG *pret, expected, ret;
+    void **pret2;
     int i;
 
     memset(&ios_obj, 0xab, sizeof(ios));
@@ -1099,6 +1112,24 @@ static void test_ios(void)
         expected <<= 1;
     }
 
+    /* xalloc/pword/iword */
+    ok(*p_ios_curindex == -1, "expected -1 got %d\n", *p_ios_curindex);
+    expected = 0;
+    for (i = 0; i < 8; i++) {
+        ret = p_ios_xalloc();
+        ok(ret == expected, "expected %d got %d\n", expected, ret);
+        ok(*p_ios_curindex == expected, "expected %d got %d\n", expected, *p_ios_curindex);
+        pret = (LONG*) call_func2(p_ios_iword, &ios_obj, ret);
+        ok(pret == &p_ios_statebuf[ret], "expected %p got %p\n", &p_ios_statebuf[ret], pret);
+        ok(*pret == 0, "expected 0 got %d\n", *pret);
+        pret2 = (void**) call_func2(p_ios_pword, &ios_obj, ret);
+        ok(pret2 == (void**)&p_ios_statebuf[ret], "expected %p got %p\n", (void**)&p_ios_statebuf[ret], pret2);
+        expected++;
+    }
+    ret = p_ios_xalloc();
+    ok(ret == -1, "expected -1 got %d\n", ret);
+    ok(*p_ios_curindex == 7, "expected 7 got %d\n", *p_ios_curindex);
+
     SetEvent(lock_arg.release[1]);
     SetEvent(lock_arg.release[2]);
     WaitForSingleObject(thread, INFINITE);
diff --git a/dlls/msvcrt20/msvcrt20.spec b/dlls/msvcrt20/msvcrt20.spec
index 529c0d9..3b88f8b 100644
--- a/dlls/msvcrt20/msvcrt20.spec
+++ b/dlls/msvcrt20/msvcrt20.spec
@@ -764,10 +764,10 @@
 @ stub -arch=win64 ?writepad at ostream@@AEAAAEAV1 at PEBD0@Z
 @ stub -arch=win32 ?ws@@YAAAVistream@@AAV1@@Z
 @ stub -arch=win64 ?ws@@YAAEAVistream@@AEAV1@@Z
-# @ extern ?x_curindex at ios@@0HA
+@ extern ?x_curindex at ios@@0HA msvcirt.?x_curindex at ios@@0HA
 @ extern ?x_lockc at ios@@0U_CRT_CRITICAL_SECTION@@A msvcirt.?x_lockc at ios@@0U_CRT_CRITICAL_SECTION@@A
 @ extern ?x_maxbit at ios@@0JA msvcirt.?x_maxbit at ios@@0JA
-# @ extern ?x_statebuf at ios@@0QAJA
+@ extern ?x_statebuf at ios@@0QAJA msvcirt.?x_statebuf at ios@@0QAJA
 @ cdecl ?xalloc at ios@@SAHXZ() msvcirt.?xalloc at ios@@SAHXZ
 @ thiscall -arch=win32 ?xsgetn at streambuf@@UAEHPADH at Z(ptr ptr long) msvcirt.?xsgetn at streambuf@@UAEHPADH at Z
 @ cdecl -arch=win64 ?xsgetn at streambuf@@UEAAHPEADH at Z(ptr ptr long) msvcirt.?xsgetn at streambuf@@UEAAHPEADH at Z
diff --git a/dlls/msvcrt40/msvcrt40.spec b/dlls/msvcrt40/msvcrt40.spec
index e5a2852..afd9894 100644
--- a/dlls/msvcrt40/msvcrt40.spec
+++ b/dlls/msvcrt40/msvcrt40.spec
@@ -838,10 +838,10 @@
 @ stub -arch=win64 ?writepad at ostream@@AEAAAEAV1 at PEBD0@Z
 @ stub -arch=win32 ?ws@@YAAAVistream@@AAV1@@Z
 @ stub -arch=win64 ?ws@@YAAEAVistream@@AEAV1@@Z
-# @ extern ?x_curindex at ios@@0HA
+@ extern ?x_curindex at ios@@0HA msvcirt.?x_curindex at ios@@0HA
 @ extern ?x_lockc at ios@@0U_CRT_CRITICAL_SECTION@@A msvcirt.?x_lockc at ios@@0U_CRT_CRITICAL_SECTION@@A
 @ extern ?x_maxbit at ios@@0JA msvcirt.?x_maxbit at ios@@0JA
-# @ extern ?x_statebuf at ios@@0PAJA
+@ extern ?x_statebuf at ios@@0QAJA msvcirt.?x_statebuf at ios@@0QAJA
 @ cdecl ?xalloc at ios@@SAHXZ() msvcirt.?xalloc at ios@@SAHXZ
 @ thiscall -arch=win32 ?xsgetn at streambuf@@UAEHPADH at Z(ptr ptr long) msvcirt.?xsgetn at streambuf@@UAEHPADH at Z
 @ cdecl -arch=win64 ?xsgetn at streambuf@@UEAAHPEADH at Z(ptr ptr long) msvcirt.?xsgetn at streambuf@@UEAAHPEADH at Z
-- 
2.1.4




More information about the wine-patches mailing list