From c2882800b26d83a7971e0b52d298c8214764f4bc Mon Sep 17 00:00:00 2001
From: Dan Kegel <dank@kegel.com>
Date: Sat, 29 Sep 2012 09:52:11 -0700
Subject: [PATCH 09/14] vcomp: better stubs for _vcomp_for_static_simple_init,
 _vcomp_for_static_end

---
 dlls/vcomp/Makefile.in  |    3 ++-
 dlls/vcomp/tests/main.c |   35 +++++++++++++++++++++++++++++++++++
 dlls/vcomp/vcomp.spec   |    4 ++--
 dlls/vcomp/work.c       |   41 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 80 insertions(+), 3 deletions(-)
 create mode 100644 dlls/vcomp/work.c

diff --git a/dlls/vcomp/Makefile.in b/dlls/vcomp/Makefile.in
index 971cf0f..9140945 100644
--- a/dlls/vcomp/Makefile.in
+++ b/dlls/vcomp/Makefile.in
@@ -2,6 +2,7 @@ MODULE = vcomp.dll
 
 C_SRCS = \
 	fork.c \
-	main.c
+	main.c \
+	work.c
 
 @MAKE_DLL_RULES@
diff --git a/dlls/vcomp/tests/main.c b/dlls/vcomp/tests/main.c
index 8dd66ed..96cfe4f 100644
--- a/dlls/vcomp/tests/main.c
+++ b/dlls/vcomp/tests/main.c
@@ -24,6 +24,8 @@ static int CDECL (*pomp_get_num_threads)(void);
 static int CDECL (*pomp_in_parallel)(void);
 static void CDECL (*pomp_set_num_threads)(int);
 static void WINAPIV (*p_vcomp_fork)(DWORD parallel, int nargs, void *helper, ...);
+static void CDECL (*p_vcomp_for_static_end)(void);
+static void CDECL (*p_vcomp_for_static_simple_init)(int first, int last, int mystep, int step, int *pfirst, int *plast);
 
 #define GETFUNC(x) do { p##x = (void*)GetProcAddress(vcomp, #x); ok(p##x != NULL, "Export '%s' not found\n", #x); } while(0)
 
@@ -39,6 +41,8 @@ static BOOL init(void)
     GETFUNC(omp_in_parallel);
     GETFUNC(omp_set_num_threads);
     GETFUNC(_vcomp_fork);
+    GETFUNC(_vcomp_for_static_end);
+    GETFUNC(_vcomp_for_static_simple_init);
 
     return TRUE;
 }
@@ -119,6 +123,36 @@ static void test_omp_in_parallel(void)
     pomp_set_num_threads(old_nt);
 }
 
+static LONG volatile nsum;
+
+static void __cdecl _test_vcomp_for_static_simple_init_worker(void)
+{
+    int i, my_limit;
+
+    InterlockedIncrement(&ncalls);
+
+    /* for (i=0; i<=12; i++) */
+    p_vcomp_for_static_simple_init(0, 12, 1, 1, &i, &my_limit);
+
+    while (i <= my_limit) {
+        int j;
+        for (j=0; j<i; j++)
+            InterlockedIncrement(&nsum);
+        i++;
+    }
+
+    p_vcomp_for_static_end();
+}
+
+static void test_vcomp_for_static_simple_init(void)
+{
+    ncalls = 0;
+    nsum = 0;
+    p_vcomp_fork(1, 0, _test_vcomp_for_static_simple_init_worker);
+    ok(ncalls >= 1, "expected >= 1 call, got %d\n", ncalls);
+    ok(nsum == 6*13, "expected sum 6*13, got %d\n", nsum);
+}
+
 START_TEST(main)
 {
     if (!init())
@@ -126,4 +160,5 @@ START_TEST(main)
 
     test_vcomp_fork();
     test_omp_in_parallel();
+    test_vcomp_for_static_simple_init();
 }
diff --git a/dlls/vcomp/vcomp.spec b/dlls/vcomp/vcomp.spec
index 39a1842..7d79259 100644
--- a/dlls/vcomp/vcomp.spec
+++ b/dlls/vcomp/vcomp.spec
@@ -59,10 +59,10 @@
 @ stub _vcomp_for_dynamic_init_i8
 @ stub _vcomp_for_dynamic_next
 @ stub _vcomp_for_dynamic_next_i8
-@ stub _vcomp_for_static_end
+@ cdecl _vcomp_for_static_end()
 @ stub _vcomp_for_static_init
 @ stub _vcomp_for_static_init_i8
-@ stub _vcomp_for_static_simple_init
+@ cdecl _vcomp_for_static_simple_init(long long long long ptr ptr)
 @ stub _vcomp_for_static_simple_init_i8
 @ varargs _vcomp_fork(long long ptr)
 @ stub _vcomp_get_thread_num
diff --git a/dlls/vcomp/work.c b/dlls/vcomp/work.c
new file mode 100644
index 0000000..0f9ff78
--- /dev/null
+++ b/dlls/vcomp/work.c
@@ -0,0 +1,41 @@
+/*
+ * vcomp work-sharing implementation
+ *
+ * Copyright 2012 Dan Kegel
+ *
+ * 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 "config.h"
+
+#include <stdarg.h>
+
+#include "windef.h"
+#include "winbase.h"
+#include "wine/debug.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(vcomp);
+
+void CDECL _vcomp_for_static_simple_init(int first, int last, int mystep, int step, int *pfirst, int *plast)
+{
+    TRACE("(%d, %d, %d, %d, %p, %p): stub\n", first, last, mystep, step, pfirst, plast);
+    *pfirst = first;
+    *plast = last;
+}
+
+void CDECL _vcomp_for_static_end(void)
+{
+    TRACE("stub\n");
+}
-- 
1.7.9.5

