[v4 PATCH 1/3] ucrtbase: Implement _initialize_onexit_table()

Nikolay Sivov nsivov at codeweavers.com
Tue Apr 26 06:13:39 CDT 2016


Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
---

v4: fixed spec file, accidentally sent old version
v3: renamed test file

 .../api-ms-win-crt-runtime-l1-1-0.spec             |   2 +-
 dlls/msvcrt/exit.c                                 |  23 +++++
 dlls/ucrtbase/tests/Makefile.in                    |   1 +
 dlls/ucrtbase/tests/misc.c                         | 112 +++++++++++++++++++++
 dlls/ucrtbase/ucrtbase.spec                        |   2 +-
 5 files changed, 138 insertions(+), 2 deletions(-)
 create mode 100644 dlls/ucrtbase/tests/misc.c

diff --git a/dlls/api-ms-win-crt-runtime-l1-1-0/api-ms-win-crt-runtime-l1-1-0.spec b/dlls/api-ms-win-crt-runtime-l1-1-0/api-ms-win-crt-runtime-l1-1-0.spec
index 5a41548..9c36583 100644
--- a/dlls/api-ms-win-crt-runtime-l1-1-0/api-ms-win-crt-runtime-l1-1-0.spec
+++ b/dlls/api-ms-win-crt-runtime-l1-1-0/api-ms-win-crt-runtime-l1-1-0.spec
@@ -52,7 +52,7 @@
 @ cdecl _getdllprocaddr(long str long) ucrtbase._getdllprocaddr
 @ cdecl _getpid() ucrtbase._getpid
 @ cdecl _initialize_narrow_environment() ucrtbase._initialize_narrow_environment
-@ stub _initialize_onexit_table
+@ cdecl _initialize_onexit_table(ptr) ucrtbase._initialize_onexit_table
 @ cdecl _initialize_wide_environment() ucrtbase._initialize_wide_environment
 @ cdecl _initterm(ptr ptr) ucrtbase._initterm
 @ cdecl _initterm_e(ptr ptr) ucrtbase._initterm_e
diff --git a/dlls/msvcrt/exit.c b/dlls/msvcrt/exit.c
index 0f1343d..5317dd4 100644
--- a/dlls/msvcrt/exit.c
+++ b/dlls/msvcrt/exit.c
@@ -34,6 +34,13 @@ static int MSVCRT_atexit_table_size = 0;
 static int MSVCRT_atexit_registered = 0; /* Points to free slot */
 static MSVCRT_purecall_handler purecall_handler = NULL;
 
+typedef struct MSVCRT__onexit_table_t
+{
+    MSVCRT__onexit_t *_first;
+    MSVCRT__onexit_t *_last;
+    MSVCRT__onexit_t *_end;
+} MSVCRT__onexit_table_t;
+
 static const char szMsgBoxTitle[] = "Wine C++ Runtime Library";
 
 extern int MSVCRT_app_type;
@@ -334,6 +341,22 @@ int CDECL MSVCRT__crt_atexit(void (*func)(void))
   return MSVCRT__onexit((MSVCRT__onexit_t)func) == (MSVCRT__onexit_t)func ? 0 : -1;
 }
 
+
+/*********************************************************************
+ *		_initialize_onexit_table (UCRTBASE.@)
+ */
+int CDECL MSVCRT__initialize_onexit_table(MSVCRT__onexit_table_t *table)
+{
+    TRACE("(%p)\n", table);
+
+    if (!table)
+        return -1;
+
+    if (table->_first == table->_end)
+        table->_last = table->_end = table->_first = NULL;
+    return 0;
+}
+
 /*********************************************************************
  *		_set_purecall_handler (MSVCR71.@)
  */
diff --git a/dlls/ucrtbase/tests/Makefile.in b/dlls/ucrtbase/tests/Makefile.in
index 10e4f0d..bdd259d 100644
--- a/dlls/ucrtbase/tests/Makefile.in
+++ b/dlls/ucrtbase/tests/Makefile.in
@@ -3,5 +3,6 @@ APPMODE   = -mno-cygwin
 
 C_SRCS = \
 	cpp.c \
+	misc.c \
 	printf.c \
 	string.c
diff --git a/dlls/ucrtbase/tests/misc.c b/dlls/ucrtbase/tests/misc.c
new file mode 100644
index 0000000..5e22601
--- /dev/null
+++ b/dlls/ucrtbase/tests/misc.c
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2016 Nikolay Sivov for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <errno.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include <stdio.h>
+
+#include <windef.h>
+#include <winbase.h>
+#include "wine/test.h"
+
+typedef int (CDECL *MSVCRT__onexit_t)(void);
+
+typedef struct MSVCRT__onexit_table_t
+{
+    MSVCRT__onexit_t *_first;
+    MSVCRT__onexit_t *_last;
+    MSVCRT__onexit_t *_end;
+} MSVCRT__onexit_table_t;
+
+static int (CDECL *p_initialize_onexit_table)(MSVCRT__onexit_table_t *table);
+
+static void test__initialize_onexit_table(void)
+{
+    MSVCRT__onexit_table_t table, table2;
+    int ret;
+
+    if (!p_initialize_onexit_table)
+    {
+        win_skip("_initialize_onexit_table() is not available.\n");
+        return;
+    }
+
+    ret = p_initialize_onexit_table(NULL);
+    ok(ret == -1, "got %d\n", ret);
+
+    memset(&table, 0, sizeof(table));
+    ret = p_initialize_onexit_table(&table);
+    ok(ret == 0, "got %d\n", ret);
+    ok(table._first == table._last && table._first == table._end, "got first %p, last %p, end %p\n",
+        table._first, table._last, table._end);
+
+    memset(&table2, 0, sizeof(table2));
+    ret = p_initialize_onexit_table(&table2);
+    ok(ret == 0, "got %d\n", ret);
+    ok(table2._first == table._first, "got %p, %p\n", table2._first, table._first);
+
+    /* uninitialized table */
+    table._first = table._last = table._end = (void*)0x123;
+    ret = p_initialize_onexit_table(&table);
+    ok(ret == 0, "got %d\n", ret);
+    ok(table._first == table._last && table._first == table._end, "got first %p, last %p, end %p\n",
+        table._first, table._last, table._end);
+    ok(table._first != (void*)0x123, "got %p\n", table._first);
+
+    table._first = (void*)0x123;
+    table._last = (void*)0x456;
+    table._end = (void*)0x123;
+    ret = p_initialize_onexit_table(&table);
+    ok(ret == 0, "got %d\n", ret);
+    ok(table._first == table._last && table._first == table._end, "got first %p, last %p, end %p\n",
+        table._first, table._last, table._end);
+    ok(table._first != (void*)0x123, "got %p\n", table._first);
+
+    table._first = (void*)0x123;
+    table._last = (void*)0x456;
+    table._end = (void*)0x789;
+    ret = p_initialize_onexit_table(&table);
+    ok(ret == 0, "got %d\n", ret);
+    ok(table._first == (void*)0x123, "got %p\n", table._first);
+    ok(table._last == (void*)0x456, "got %p\n", table._last);
+    ok(table._end == (void*)0x789, "got %p\n", table._end);
+
+    table._first = NULL;
+    table._last = (void*)0x456;
+    table._end = NULL;
+    ret = p_initialize_onexit_table(&table);
+    ok(ret == 0, "got %d\n", ret);
+    ok(table._first == table._last && table._first == table._end, "got first %p, last %p, end %p\n",
+        table._first, table._last, table._end);
+}
+
+static void init(void)
+{
+    HMODULE module = LoadLibraryA("ucrtbase.dll");
+
+    p_initialize_onexit_table = (void*)GetProcAddress(module, "_initialize_onexit_table");
+}
+
+START_TEST(misc)
+{
+    init();
+
+    test__initialize_onexit_table();
+}
diff --git a/dlls/ucrtbase/ucrtbase.spec b/dlls/ucrtbase/ucrtbase.spec
index a54a71a..c436779 100644
--- a/dlls/ucrtbase/ucrtbase.spec
+++ b/dlls/ucrtbase/ucrtbase.spec
@@ -419,7 +419,7 @@
 @ cdecl _i64tow(int64 ptr long) ntdll._i64tow
 @ cdecl _i64tow_s(int64 ptr long long) MSVCRT__i64tow_s
 @ cdecl _initialize_narrow_environment()
-@ stub _initialize_onexit_table
+@ cdecl _initialize_onexit_table(ptr) MSVCRT__initialize_onexit_table
 @ cdecl _initialize_wide_environment()
 @ cdecl _initterm(ptr ptr)
 @ cdecl _initterm_e(ptr ptr)
-- 
2.8.0.rc3




More information about the wine-patches mailing list