Skip to content

Commit 3570e12

Browse files
committed
Disable MP_SMALL_STACK_SIZE on MSVC
Signed-off-by: Steffen Jaeckel <[email protected]>
1 parent 6c70ef1 commit 3570e12

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

appveyor.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,7 @@ image:
1414
environment:
1515
matrix:
1616
- CFLAGS_VAR: ""
17-
CFLAGS_VAR_DLL: "CFLAGS=\"/Ox /Oi /MD /DLTM_TEST_DYNAMIC\""
18-
19-
- CFLAGS_VAR: "CFLAGS=\"/Ox /Oi /DMP_SMALL_STACK_SIZE\""
20-
CFLAGS_VAR_DLL: "CFLAGS=\"/Ox /Oi /MD /DLTM_TEST_DYNAMIC /DMP_SMALL_STACK_SIZE\""
21-
22-
- CFLAGS_VAR: "CFLAGS=\"/Ox /Oi /DMP_SMALL_STACK_SIZE /DLTM_TEST_MULTITHREAD\""
23-
CFLAGS_VAR_DLL: "CFLAGS=\"/Ox /Oi /MD /DLTM_TEST_DYNAMIC /DMP_SMALL_STACK_SIZE /DLTM_TEST_MULTITHREAD\""
17+
CFLAGS_VAR_DLL: "CFLAGS=\"/Ox /MD /DLTM_TEST_DYNAMIC\""
2418
build_script:
2519
- cmd: >-
2620
if "Visual Studio 2022"=="%APPVEYOR_BUILD_WORKER_IMAGE%" call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"

makefile.msvc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#The following can be overridden from command line e.g. make -f makefile.msvc CC=gcc ARFLAGS=rcs
1313
PREFIX = c:\devel
14-
CFLAGS = /Ox /Oi
14+
CFLAGS = /Ox
1515
LDFLAGS =
1616

1717
#Compilation flags

tommath_private.h

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,23 @@ MP_PRIVATE mp_err s_mp_fp_log(const mp_int *a, mp_int *c) MP_WUR;
235235
MP_PRIVATE mp_err s_mp_fp_log_d(const mp_int *a, mp_word *c) MP_WUR;
236236

237237
#ifdef MP_SMALL_STACK_SIZE
238+
239+
#if defined(__GNUC__)
240+
/* We use TLS (Thread Local Storage) to manage the instance of the WARRAY
241+
* per thread.
242+
* The compilers we're usually looking at are GCC, Clang and MSVC.
243+
* Both GCC and Clang are straight-forward with TLS, so it's enabled there.
244+
* Using MSVC the tests were OK with the static library, but failed when
245+
* the library was built as a DLL. As a result we completely disable
246+
* support for MSVC.
247+
* If your compiler can handle TLS properly without too much hocus pocus,
248+
* feel free to open a PR to add support for it.
249+
*/
250+
#define mp_thread __thread
251+
#else
252+
#error "MP_SMALL_STACK_SIZE not supported with your compiler"
253+
#endif
254+
238255
#define MP_SMALL_STACK_SIZE_C
239256
#define MP_ALLOC_WARRAY(name) *name = s_mp_warray_get()
240257
#define MP_FREE_WARRAY(name) s_mp_warray_put(name)
@@ -245,10 +262,8 @@ MP_PRIVATE mp_err s_mp_fp_log_d(const mp_int *a, mp_word *c) MP_WUR;
245262
#define MP_CHECK_WARRAY(name)
246263
#endif
247264

248-
#if defined(_MSC_VER)
249-
#define mp_thread __declspec(thread)
250-
#elif defined(__GNUC__)
251-
#define mp_thread __thread
265+
#ifndef mp_thread
266+
#define mp_thread
252267
#endif
253268

254269
typedef struct {

0 commit comments

Comments
 (0)