[1/3] msvcirt: Add implementation of streambuf::snextc

Iván Matellanes matellanesivan at gmail.com
Thu Jun 25 12:02:05 CDT 2015


---
 dlls/msvcirt/msvcirt.c       | 18 +++++++++++++++
 dlls/msvcirt/msvcirt.spec    |  4 ++--
 dlls/msvcirt/tests/msvcirt.c | 54 ++++++++++++++++++++++++++++++++++++++++++++
 dlls/msvcrt20/msvcrt20.spec  |  4 ++--
 dlls/msvcrt40/msvcrt40.spec  |  4 ++--
 5 files changed, 78 insertions(+), 6 deletions(-)

diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c
index 35777e3..77dc089 100644
--- a/dlls/msvcirt/msvcirt.c
+++ b/dlls/msvcirt/msvcirt.c
@@ -597,6 +597,24 @@ int __thiscall streambuf_sputn(streambuf *this, const char *data, int length)
     return call_streambuf_xsputn(this, data, length);
 }
 
+/* ?snextc at streambuf@@QAEHXZ */
+/* ?snextc at streambuf@@QEAAHXZ */
+DEFINE_THISCALL_WRAPPER(streambuf_snextc, 4)
+int __thiscall streambuf_snextc(streambuf *this)
+{
+    TRACE("(%p)\n", this);
+    if (this->unbuffered) {
+        if (this->stored_char == EOF)
+            call_streambuf_underflow(this);
+        return this->stored_char = call_streambuf_underflow(this);
+    } else {
+        if (this->gptr >= this->egptr)
+            call_streambuf_underflow(this);
+        this->gptr++;
+        return (this->gptr < this->egptr) ? *this->gptr : call_streambuf_underflow(this);
+    }
+}
+
 /******************************************************************
  *		 ??1ios@@UAE at XZ (MSVCRTI.@)
  *        class ios & __thiscall ios::-ios<<(void)
diff --git a/dlls/msvcirt/msvcirt.spec b/dlls/msvcirt/msvcirt.spec
index 2a65e2f..e49fd53 100644
--- a/dlls/msvcirt/msvcirt.spec
+++ b/dlls/msvcirt/msvcirt.spec
@@ -700,8 +700,8 @@
 # @ extern ?sh_none at filebuf@@2HB  # static int const filebuf::sh_none
 # @ extern ?sh_read at filebuf@@2HB  # static int const filebuf::sh_read
 # @ extern ?sh_write at filebuf@@2HB  # static int const filebuf::sh_write
-@ stub -arch=win32 ?snextc at streambuf@@QAEHXZ  # int __thiscall streambuf::snextc(void)
-@ stub -arch=win64 ?snextc at streambuf@@QEAAHXZ
+@ thiscall -arch=win32 ?snextc at streambuf@@QAEHXZ(ptr) streambuf_snextc
+@ cdecl -arch=win64 ?snextc at streambuf@@QEAAHXZ(ptr) streambuf_snextc
 @ stub -arch=win32 ?sputbackc at streambuf@@QAEHD at Z  # int __thiscall streambuf::sputbackc(char)
 @ stub -arch=win64 ?sputbackc at streambuf@@QEAAHD at Z
 @ thiscall -arch=win32 ?sputc at streambuf@@QAEHH at Z(ptr long) streambuf_sputc
diff --git a/dlls/msvcirt/tests/msvcirt.c b/dlls/msvcirt/tests/msvcirt.c
index a175531..3d6e6ad 100644
--- a/dlls/msvcirt/tests/msvcirt.c
+++ b/dlls/msvcirt/tests/msvcirt.c
@@ -62,6 +62,7 @@ static void (*__thiscall p_streambuf_setb)(streambuf*, char*, char*, int);
 static void (*__thiscall p_streambuf_setlock)(streambuf*);
 static streambuf* (*__thiscall p_streambuf_setbuf)(streambuf*, char*, int);
 static int (*__thiscall p_streambuf_sgetc)(streambuf*);
+static int (*__thiscall p_streambuf_snextc)(streambuf*);
 static int (*__thiscall p_streambuf_sputc)(streambuf*, int);
 static int (*__thiscall p_streambuf_sync)(streambuf*);
 static void (*__thiscall p_streambuf_unlock)(streambuf*);
@@ -150,6 +151,7 @@ static BOOL init(void)
         SET(p_streambuf_setbuf, "?setbuf at streambuf@@UEAAPEAV1 at PEADH@Z");
         SET(p_streambuf_setlock, "?setlock at streambuf@@QEAAXXZ");
         SET(p_streambuf_sgetc, "?sgetc at streambuf@@QEAAHXZ");
+        SET(p_streambuf_snextc, "?snextc at streambuf@@QEAAHXZ");
         SET(p_streambuf_sputc, "?sputc at streambuf@@QEAAHH at Z");
         SET(p_streambuf_sync, "?sync at streambuf@@UEAAHXZ");
         SET(p_streambuf_unlock, "?unlock at streambuf@@QEAAXXZ");
@@ -169,6 +171,7 @@ static BOOL init(void)
         SET(p_streambuf_setbuf, "?setbuf at streambuf@@UAEPAV1 at PADH@Z");
         SET(p_streambuf_setlock, "?setlock at streambuf@@QAEXXZ");
         SET(p_streambuf_sgetc, "?sgetc at streambuf@@QAEHXZ");
+        SET(p_streambuf_snextc, "?snextc at streambuf@@QAEHXZ");
         SET(p_streambuf_sputc, "?sputc at streambuf@@QAEHH at Z");
         SET(p_streambuf_sync, "?sync at streambuf@@UAEHXZ");
         SET(p_streambuf_unlock, "?unlock at streambuf@@QAEXXZ");
@@ -564,6 +567,57 @@ static void test_streambuf(void)
     ok(sb3.stored_char == 'G', "wrong stored character, expected 'G' got %c\n", sb3.stored_char);
     ok(overflow_count == 14, "expected 3 calls to overflow, got %d\n", overflow_count - 11);
 
+    /* snextc */
+    strcpy(sb.eback, "Test");
+    ret = (int) call_func1(p_streambuf_snextc, &sb);
+    ok(ret == 'e', "expected 'e' got '%c'\n", ret);
+    ok(sb.gptr == sb.eback + 1, "wrong get pointer, expected %p got %p\n", sb.eback + 1, sb.gptr);
+    test_this = &sb2;
+    ret = (int) call_func1(p_streambuf_snextc, &sb2);
+    ok(ret == EOF, "expected EOF got '%c'\n", ret);
+    ok(sb2.gptr == sb2.egptr + 1, "wrong get pointer, expected %p got %p\n", sb2.egptr + 1, sb2.gptr);
+    ok(underflow_count == 39, "expected 2 calls to underflow, got %d\n", underflow_count - 37);
+    sb2.gptr = sb2.egptr - 1;
+    ret = (int) call_func1(p_streambuf_snextc, &sb2);
+    ok(ret == EOF, "expected EOF got '%c'\n", ret);
+    ok(sb2.gptr == sb2.egptr, "wrong get pointer, expected %p got %p\n", sb2.egptr, sb2.gptr);
+    ok(underflow_count == 40, "expected call to underflow\n");
+    get_end = 0;
+    ret = (int) call_func1(p_streambuf_snextc, &sb2);
+    ok(ret == 'o', "expected 'o' got '%c'\n", ret);
+    ok(sb2.gptr == sb2.eback + 1, "wrong get pointer, expected %p got %p\n", sb2.eback + 1, sb2.gptr);
+    ok(underflow_count == 41, "expected call to underflow\n");
+    sb2.gptr = sb2.egptr - 1;
+    ret = (int) call_func1(p_streambuf_snextc, &sb2);
+    ok(ret == 'W', "expected 'W' got '%c'\n", ret);
+    ok(sb2.gptr == sb2.eback, "wrong get pointer, expected %p got %p\n", sb2.eback, sb2.gptr);
+    ok(underflow_count == 42, "expected call to underflow\n");
+    sb2.gptr = sb2.egptr;
+    test_this = &sb3;
+    ret = (int) call_func1(p_streambuf_snextc, &sb3);
+    ok(ret == 'l', "expected 'l' got '%c'\n", ret);
+    ok(sb3.stored_char == 'l', "wrong stored character, expected 'l' got %c\n", sb3.stored_char);
+    ok(underflow_count == 43, "expected call to underflow\n");
+    buffer_pos = 22;
+    ret = (int) call_func1(p_streambuf_snextc, &sb3);
+    ok(ret == 't', "expected 't' got '%c'\n", ret);
+    ok(sb3.stored_char == 't', "wrong stored character, expected 't' got %c\n", sb3.stored_char);
+    ok(underflow_count == 44, "expected call to underflow\n");
+    ret = (int) call_func1(p_streambuf_snextc, &sb3);
+    ok(ret == EOF, "expected EOF got '%c'\n", ret);
+    ok(sb3.stored_char == EOF, "wrong stored character, expected EOF got %c\n", sb3.stored_char);
+    ok(underflow_count == 45, "expected call to underflow\n");
+    buffer_pos = 0;
+    ret = (int) call_func1(p_streambuf_snextc, &sb3);
+    ok(ret == 'o', "expected 'o' got '%c'\n", ret);
+    ok(sb3.stored_char == 'o', "wrong stored character, expected 'o' got %c\n", sb3.stored_char);
+    ok(underflow_count == 47, "expected 2 calls to underflow, got %d\n", underflow_count - 45);
+    sb3.stored_char = EOF;
+    ret = (int) call_func1(p_streambuf_snextc, &sb3);
+    ok(ret == 'p', "expected 'p' got '%c'\n", ret);
+    ok(sb3.stored_char == 'p', "wrong stored character, expected 'p' got %c\n", sb3.stored_char);
+    ok(underflow_count == 49, "expected 2 calls to underflow, got %d\n", underflow_count - 47);
+
     SetEvent(lock_arg.test[3]);
     WaitForSingleObject(thread, INFINITE);
 
diff --git a/dlls/msvcrt20/msvcrt20.spec b/dlls/msvcrt20/msvcrt20.spec
index 1be499b..5786fc4 100644
--- a/dlls/msvcrt20/msvcrt20.spec
+++ b/dlls/msvcrt20/msvcrt20.spec
@@ -688,8 +688,8 @@
 # @ extern ?sh_none at filebuf@@2HB
 # @ extern ?sh_read at filebuf@@2HB
 # @ extern ?sh_write at filebuf@@2HB
-@ stub -arch=win32 ?snextc at streambuf@@QAEHXZ
-@ stub -arch=win64 ?snextc at streambuf@@QEAAHXZ
+@ thiscall -arch=win32 ?snextc at streambuf@@QAEHXZ(ptr) msvcirt.?snextc at streambuf@@QAEHXZ
+@ cdecl -arch=win64 ?snextc at streambuf@@QEAAHXZ(ptr) msvcirt.?snextc at streambuf@@QEAAHXZ
 @ stub -arch=win32 ?sputbackc at streambuf@@QAEHD at Z
 @ stub -arch=win64 ?sputbackc at streambuf@@QEAAHD at Z
 @ thiscall -arch=win32 ?sputc at streambuf@@QAEHH at Z(ptr long) msvcirt.?sputc at streambuf@@QAEHH at Z
diff --git a/dlls/msvcrt40/msvcrt40.spec b/dlls/msvcrt40/msvcrt40.spec
index 94d9035..de6364a 100644
--- a/dlls/msvcrt40/msvcrt40.spec
+++ b/dlls/msvcrt40/msvcrt40.spec
@@ -760,8 +760,8 @@
 # @ extern ?sh_none at filebuf@@2HB
 # @ extern ?sh_read at filebuf@@2HB
 # @ extern ?sh_write at filebuf@@2HB
-@ stub -arch=win32 ?snextc at streambuf@@QAEHXZ
-@ stub -arch=win64 ?snextc at streambuf@@QEAAHXZ
+@ thiscall -arch=win32 ?snextc at streambuf@@QAEHXZ(ptr) msvcirt.?snextc at streambuf@@QAEHXZ
+@ cdecl -arch=win64 ?snextc at streambuf@@QEAAHXZ(ptr) msvcirt.?snextc at streambuf@@QEAAHXZ
 @ stub -arch=win32 ?sputbackc at streambuf@@QAEHD at Z
 @ stub -arch=win64 ?sputbackc at streambuf@@QEAAHD at Z
 @ thiscall -arch=win32 ?sputc at streambuf@@QAEHH at Z(ptr long) msvcirt.?sputc at streambuf@@QAEHH at Z
-- 
2.1.4




More information about the wine-patches mailing list