This patch make it possible to play Tron 2.0.
Signed-off-by: Arkadiusz Hiler ahiler@codeweavers.com --- dlls/msvcirt/msvcirt.c | 36 ++++++++++++++++++ dlls/msvcirt/msvcirt.spec | 22 +++++------ dlls/msvcirt/tests/msvcirt.c | 74 ++++++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+), 11 deletions(-)
diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c index 6bd910e9a89..498af8189cb 100644 --- a/dlls/msvcirt/msvcirt.c +++ b/dlls/msvcirt/msvcirt.c @@ -200,6 +200,8 @@ extern const vtable_ptr MSVCP_iostream_vtable; extern const vtable_ptr MSVCP_strstream_vtable; /* ??_7stdiostream@@6B@ */ extern const vtable_ptr MSVCP_stdiostream_vtable; +/* ??_7fstream@@6B@ */ +extern const vtable_ptr MSVCP_fstream_vtable;
__ASM_BLOCK_BEGIN(vtables) __ASM_VTABLE(streambuf, @@ -272,6 +274,8 @@ __ASM_BLOCK_BEGIN(vtables) VTABLE_ADD_FUNC(iostream_vector_dtor)); __ASM_VTABLE(stdiostream, VTABLE_ADD_FUNC(iostream_vector_dtor)); + __ASM_VTABLE(fstream, + VTABLE_ADD_FUNC(iostream_vector_dtor)); __ASM_BLOCK_END
#define ALIGNED_SIZE(size, alignment) (((size)+((alignment)-1))/(alignment)*(alignment)) @@ -321,6 +325,9 @@ DEFINE_RTTI_DATA4(strstream, sizeof(iostream), DEFINE_RTTI_DATA4(stdiostream, sizeof(iostream), &istream_rtti_base_descriptor, &ios_rtti_base_descriptor, &ostream_rtti_base_descriptor, &ios_rtti_base_descriptor, ".?AVstdiostream@@") +DEFINE_RTTI_DATA4(fstream, sizeof(iostream), + &istream_rtti_base_descriptor, &ios_rtti_base_descriptor, + &ostream_rtti_base_descriptor, &ios_rtti_base_descriptor, ".?AVfstream@@")
/* ?cin@@3Vistream_withassign@@A */ struct { @@ -4369,6 +4376,8 @@ iostream* __thiscall iostream_copy_ctor(iostream *this, const iostream *copy, BO /* ??1stdiostream@@UEAA@XZ */ /* ??1strstream@@UAE@XZ */ /* ??1strstream@@UEAA@XZ */ +/* ??1fstream@@UAE@XZ */ +/* ??1fstream@@UEAA@XZ */ DEFINE_THISCALL_WRAPPER(iostream_dtor, 4) void __thiscall iostream_dtor(ios *base) { @@ -4601,6 +4610,32 @@ stdiobuf* __thiscall stdiostream_rdbuf(const iostream *this) return (stdiobuf*) istream_get_ios(&this->base1)->sb; }
+/* ??0fstream@@QAE@PBDHH@Z */ +/* ??0fstream@@QEAA@PEBDHH@Z */ +DEFINE_THISCALL_WRAPPER(fstream_open_ctor, 20) +iostream* __thiscall fstream_open_ctor(iostream *this, const char *name, ios_open_mode mode, int protection, BOOL virt_init) +{ + ios *base; + filebuf *fb = MSVCRT_operator_new(sizeof(filebuf)); + + TRACE("(%p %s %d %d %d)\n", this, name, mode, protection, virt_init); + + if (!fb) { + FIXME("out of memory\n"); + return NULL; + } + + filebuf_ctor(fb); + filebuf_open(fb, name, mode, protection); + + iostream_internal_sb_ctor(this, &fb->base, &MSVCP_fstream_vtable, virt_init); + + base = istream_get_ios(&this->base1); + base->delbuf = 1; + + return this; +} + /* ??0Iostream_init@@QAE@AAVios@@H@Z */ /* ??0Iostream_init@@QEAA@AEAVios@@H@Z */ DEFINE_THISCALL_WRAPPER(Iostream_init_ios_ctor, 12) @@ -4759,6 +4794,7 @@ static void init_io(void *base) init_iostream_rtti(base); init_strstream_rtti(base); init_stdiostream_rtti(base); + init_fstream_rtti(base); #endif
if ((fb = MSVCRT_operator_new(sizeof(filebuf)))) { diff --git a/dlls/msvcirt/msvcirt.spec b/dlls/msvcirt/msvcirt.spec index c2b4b9d30eb..21e4dcf3c60 100644 --- a/dlls/msvcirt/msvcirt.spec +++ b/dlls/msvcirt/msvcirt.spec @@ -22,8 +22,8 @@ @ stub -arch=win64 ??0fstream@@QEAA@H@Z @ stub -arch=win32 ??0fstream@@QAE@HPADH@Z # __thiscall fstream::fstream(int,char *,int) @ stub -arch=win64 ??0fstream@@QEAA@HPEADH@Z -@ stub -arch=win32 ??0fstream@@QAE@PBDHH@Z # __thiscall fstream::fstream(char const *,int,int) -@ stub -arch=win64 ??0fstream@@QEAA@PEBDHH@Z +@ thiscall -arch=win32 ??0fstream@@QAE@PBDHH@Z(ptr str long long long) fstream_open_ctor +@ cdecl -arch=win64 ??0fstream@@QEAA@PEBDHH@Z(ptr str long long long) fstream_open_ctor @ stub -arch=win32 ??0fstream@@QAE@XZ # __thiscall fstream::fstream(void) @ stub -arch=win64 ??0fstream@@QEAA@XZ @ thiscall -arch=win32 ??0ifstream@@QAE@ABV0@@Z(ptr ptr long) ifstream_copy_ctor @@ -136,8 +136,8 @@ @ cdecl -arch=win64 ??1exception@@UEAA@XZ(ptr) MSVCP_exception_dtor @ thiscall -arch=win32 ??1filebuf@@UAE@XZ(ptr) filebuf_dtor @ cdecl -arch=win64 ??1filebuf@@UEAA@XZ(ptr) filebuf_dtor -@ stub -arch=win32 ??1fstream@@UAE@XZ # virtual __thiscall fstream::~fstream(void) -@ stub -arch=win64 ??1fstream@@UEAA@XZ +@ thiscall -arch=win32 ??1fstream@@UAE@XZ(ptr) iostream_dtor +@ cdecl -arch=win64 ??1fstream@@UEAA@XZ(ptr) iostream_dtor @ thiscall -arch=win32 ??1ifstream@@UAE@XZ(ptr) istream_dtor @ cdecl -arch=win64 ??1ifstream@@UEAA@XZ(ptr) istream_dtor @ thiscall -arch=win32 ??1ios@@UAE@XZ(ptr) ios_dtor @@ -304,7 +304,7 @@ @ cdecl -arch=win64 ??Bios@@QEBAPEAXXZ(ptr) ios_op_void @ extern ??_7exception@@6B@ MSVCP_exception_vtable @ extern ??_7filebuf@@6B@ MSVCP_filebuf_vtable -# @ extern ??_7fstream@@6B@ # const fstream::`vftable' +@ extern ??_7fstream@@6B@ MSVCP_fstream_vtable @ extern ??_7ifstream@@6B@ MSVCP_ifstream_vtable @ extern ??_7ios@@6B@ MSVCP_ios_vtable @ extern ??_7iostream@@6B@ MSVCP_iostream_vtable @@ -321,8 +321,8 @@ @ extern ??_7streambuf@@6B@ MSVCP_streambuf_vtable @ extern ??_7strstream@@6B@ MSVCP_strstream_vtable @ extern ??_7strstreambuf@@6B@ MSVCP_strstreambuf_vtable -# @ extern ??_8fstream@@7Bistream@@@ # const fstream::`vbtable'{for `istream'} -# @ extern ??_8fstream@@7Bostream@@@ # const fstream::`vbtable'{for `ostream'} +@ extern ??_8fstream@@7Bistream@@@ iostream_vbtable_istream +@ extern ??_8fstream@@7Bostream@@@ iostream_vbtable_ostream @ extern ??_8ifstream@@7B@ istream_vbtable @ extern ??_8iostream@@7Bistream@@@ iostream_vbtable_istream @ extern ??_8iostream@@7Bostream@@@ iostream_vbtable_ostream @@ -337,8 +337,8 @@ @ extern ??_8stdiostream@@7Bostream@@@ iostream_vbtable_ostream @ extern ??_8strstream@@7Bistream@@@ iostream_vbtable_istream @ extern ??_8strstream@@7Bostream@@@ iostream_vbtable_ostream -@ stub -arch=win32 ??_Dfstream@@QAEXXZ # void __thiscall fstream::`vbase destructor'(void) -@ stub -arch=win64 ??_Dfstream@@QEAAXXZ +@ thiscall -arch=win32 ??_Dfstream@@QAEXXZ(ptr) iostream_vbase_dtor +@ cdecl -arch=win64 ??_Dfstream@@QEAAXXZ(ptr) iostream_vbase_dtor @ thiscall -arch=win32 ??_Difstream@@QAEXXZ(ptr) istream_vbase_dtor @ cdecl -arch=win64 ??_Difstream@@QEAAXXZ(ptr) istream_vbase_dtor @ thiscall -arch=win32 ??_Diostream@@QAEXXZ(ptr) iostream_vbase_dtor @@ -363,7 +363,7 @@ @ cdecl -arch=win64 ??_Dstrstream@@QEAAXXZ(ptr) iostream_vbase_dtor @ thiscall -arch=win32 ??_Eexception@@UAEPAXI@Z(ptr long) MSVCP_exception_vector_dtor @ thiscall -arch=win32 ??_Efilebuf@@UAEPAXI@Z(ptr long) filebuf_vector_dtor -@ stub -arch=win32 ??_Efstream@@UAEPAXI@Z # virtual void * __thiscall fstream::`vector deleting destructor'(unsigned int) +@ thiscall -arch=win32 ??_Efstream@@UAEPAXI@Z(ptr) iostream_vbase_dtor @ thiscall -arch=win32 ??_Eifstream@@UAEPAXI@Z(ptr long) istream_vector_dtor @ thiscall -arch=win32 ??_Eios@@UAEPAXI@Z(ptr long) ios_vector_dtor @ thiscall -arch=win32 ??_Eiostream@@UAEPAXI@Z(ptr long) iostream_vector_dtor @@ -382,7 +382,7 @@ @ thiscall -arch=win32 ??_Estrstreambuf@@UAEPAXI@Z(ptr long) strstreambuf_vector_dtor @ thiscall -arch=win32 ??_Gexception@@UAEPAXI@Z(ptr long) MSVCP_exception_scalar_dtor @ thiscall -arch=win32 ??_Gfilebuf@@UAEPAXI@Z(ptr long) filebuf_scalar_dtor -@ stub -arch=win32 ??_Gfstream@@UAEPAXI@Z # virtual void * __thiscall fstream::`scalar deleting destructor'(unsigned int) +@ thiscall -arch=win32 ??_Gfstream@@UAEPAXI@Z(ptr long) iostream_vector_dtor @ thiscall -arch=win32 ??_Gifstream@@UAEPAXI@Z(ptr long) istream_scalar_dtor @ thiscall -arch=win32 ??_Gios@@UAEPAXI@Z(ptr long) ios_scalar_dtor @ thiscall -arch=win32 ??_Giostream@@UAEPAXI@Z(ptr long) iostream_scalar_dtor diff --git a/dlls/msvcirt/tests/msvcirt.c b/dlls/msvcirt/tests/msvcirt.c index e1a62967835..4d395d7eaa6 100644 --- a/dlls/msvcirt/tests/msvcirt.c +++ b/dlls/msvcirt/tests/msvcirt.c @@ -232,6 +232,7 @@ static int (*__thiscall p_filebuf_sync)(filebuf*); static int (*__thiscall p_filebuf_overflow)(filebuf*, int); static int (*__thiscall p_filebuf_underflow)(filebuf*); static streampos (*__thiscall p_filebuf_seekoff)(filebuf*, streamoff, ios_seek_dir, int); +static int (*__thiscall p_filebuf_is_open)(filebuf*);
/* strstreambuf */ static strstreambuf* (*__thiscall p_strstreambuf_dynamic_ctor)(strstreambuf*, int); @@ -436,6 +437,11 @@ static void (*__thiscall p_stdiostream_dtor)(ios*); static void (*__thiscall p_stdiostream_vbase_dtor)(iostream*); static iostream* (*__thiscall p_stdiostream_assign)(iostream*, const iostream*);
+/* fstream */ +static iostream* (*__thiscall p_fstream_open_ctor)(iostream*, const char*, ios_open_mode, int, BOOL); +static void (*__thiscall p_fstream_dtor)(ios*); +static void (*__thiscall p_fstream_vbase_dtor)(iostream*); + /* Iostream_init */ static void* (*__thiscall p_Iostream_init_ios_ctor)(void*, ios*, int);
@@ -570,6 +576,7 @@ static BOOL init(void) SET(p_filebuf_overflow, "?overflow@filebuf@@UEAAHH@Z"); SET(p_filebuf_underflow, "?underflow@filebuf@@UEAAHXZ"); SET(p_filebuf_seekoff, "?seekoff@filebuf@@UEAAJJW4seek_dir@ios@@H@Z"); + SET(p_filebuf_is_open, "?is_open@filebuf@@QEBAHXZ");
SET(p_strstreambuf_dynamic_ctor, "??0strstreambuf@@QEAA@H@Z"); SET(p_strstreambuf_funcs_ctor, "??0strstreambuf@@QEAA@P6APEAXJ@ZP6AXPEAX@Z@Z"); @@ -750,6 +757,10 @@ static BOOL init(void) SET(p_stdiostream_vbase_dtor, "??_Dstdiostream@@QEAAXXZ"); SET(p_stdiostream_assign, "??4stdiostream@@QEAAAEAV0@AEAV0@@Z");
+ SET(p_fstream_open_ctor, "??0fstream@@QEAA@PEBDHH@Z"); + SET(p_fstream_dtor, "??1fstream@@UEAA@XZ"); + SET(p_fstream_vbase_dtor, "??_Dfstream@@QEAAXXZ"); + SET(p_Iostream_init_ios_ctor, "??0Iostream_init@@QEAA@AEAVios@@H@Z");
SET(p_exception_ctor, "??0exception@@QEAA@AEBQEBD@Z"); @@ -800,6 +811,7 @@ static BOOL init(void) SET(p_filebuf_overflow, "?overflow@filebuf@@UAEHH@Z"); SET(p_filebuf_underflow, "?underflow@filebuf@@UAEHXZ"); SET(p_filebuf_seekoff, "?seekoff@filebuf@@UAEJJW4seek_dir@ios@@H@Z"); + SET(p_filebuf_is_open, "?is_open@filebuf@@QBEHXZ");
SET(p_strstreambuf_dynamic_ctor, "??0strstreambuf@@QAE@H@Z"); SET(p_strstreambuf_funcs_ctor, "??0strstreambuf@@QAE@P6APAXJ@ZP6AXPAX@Z@Z"); @@ -980,6 +992,10 @@ static BOOL init(void) SET(p_stdiostream_vbase_dtor, "??_Dstdiostream@@QAEXXZ"); SET(p_stdiostream_assign, "??4stdiostream@@QAEAAV0@AAV0@@Z");
+ SET(p_fstream_open_ctor, "??0fstream@@QAE@PBDHH@Z"); + SET(p_fstream_dtor, "??1fstream@@UAE@XZ"); + SET(p_fstream_vbase_dtor, "??_Dfstream@@QAEXXZ"); + SET(p_Iostream_init_ios_ctor, "??0Iostream_init@@QAE@AAVios@@H@Z");
SET(p_exception_ctor, "??0exception@@QAE@ABQBD@Z"); @@ -7929,6 +7945,63 @@ static void test_std_streams(void) ok(p_cin->count == 0xabababab, "expected %d got %d\n", 0xabababab, p_cin->count); }
+static void test_fstream(void) +{ + iostream fs, *pfs; + filebuf *pfb; + ostream *pos; + istream *pis; + int i; + char st[8]; + const char *filename = "fstream_test"; + + /* constructors */ + pfs = call_func5(p_fstream_open_ctor, &fs, filename, OPENMODE_out, filebuf_openprot, TRUE); + ok(pfs == &fs, "constructor returned wrong pointer, expected %p got %p\n", &fs, pfs); + ok(fs.base_ios.state == IOSTATE_goodbit, "wrong stream state, expected %d got %d\n", IOSTATE_goodbit, fs.base_ios.state); + pfb = (filebuf*) fs.base_ios.sb; + ok((int) call_func1(p_filebuf_is_open, pfb) == TRUE, "expected filebuf to be open\n"); + ok(fs.base_ios.delbuf == 1, "internal filebuf not makred for deletion\n"); + + /* integration with ostream */ + pos = call_func2(p_ostream_print_str, (ostream*) &fs.base2, "ftest "); + ok(pos == (ostream*) &fs.base2, "stream operation returned wrong pointer, expected %p got %p\n", &fs, &fs.base2); + pos = call_func2(p_ostream_print_int, (ostream*) &fs.base2, 15); + ok(pos == (ostream*) &fs.base2, "stream operation returned wrong pointer, expected %p got %p\n", &fs, &fs.base2); + + /* make sure that OPENMODE_in is not implied */ + ok(_lseek(pfb->fd, 0, SEEK_SET) == 0, "_lseek failed\n"); + ok(_read(pfb->fd, st, 1) == -1, "_read succeded on OPENMODE_out only fstream\n"); + + /* reopen the file for reading */ + call_func1(p_fstream_vbase_dtor, &fs); + pfs = call_func5(p_fstream_open_ctor, &fs, filename, OPENMODE_in, filebuf_openprot, TRUE); + ok(pfs == &fs, "constructor returned wrong pointer, expected %p got %p\n", &fs, pfs); + ok(fs.base_ios.state == IOSTATE_goodbit, "wrong stream state, expected %d got %d\n", IOSTATE_goodbit, fs.base_ios.state); + pfb = (filebuf*) fs.base_ios.sb; + ok((int) call_func1(p_filebuf_is_open, pfb) == TRUE, "expected filebuf to be open\n"); + + /* integration with istream */ + memset(st, 'A', sizeof(st)); + pis = call_func2(p_istream_read_str, (istream*) &fs.base1, st); + ok(pis == (istream*) &fs.base1, "stream operation returned wrong pointer, expected %p got %p\n", &fs, &fs.base1); + st[7] = 0; + ok(!strcmp(st, "ftest"), "expected 'ftest' got '%s'\n", st); + + i = 12345; + pis = call_func2(p_istream_read_int, (istream*) &fs.base1, &i); + ok(pis == (istream*) &fs.base1, "stream operation returned wrong pointer, expected %p got %p\n", &fs, &fs.base1); + ok(i == 15, "expected 12 got %d\n", i); + + /* make sure that OPENMODE_out is not implied */ + ok(_lseek(pfb->fd, 0, SEEK_SET) == 0, "_lseek failed\n"); + ok(_write(pfb->fd, "blabla", 6) == -1, "_write succeded on OPENMODE_in fstream\n"); + + /* cleanup */ + call_func1(p_fstream_vbase_dtor, &fs); + ok(_unlink(filename) == 0, "Couldn't unlink file named '%s', some filedescs are still open?\n", filename); +} + static void test_exception(void) { const char *unknown = "Unknown exception"; @@ -7983,6 +8056,7 @@ START_TEST(msvcirt) test_stdiostream(); test_Iostream_init(); test_std_streams(); + test_fstream(); test_exception();
FreeLibrary(msvcrt);