Skip to content

Commit

Permalink
Disable MP_SMALL_STACK_SIZE on MSVC
Browse files Browse the repository at this point in the history
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
  • Loading branch information
sjaeckel committed Apr 3, 2024
1 parent 298a218 commit 1ea2413
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
8 changes: 1 addition & 7 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@ image:
environment:
matrix:
- CFLAGS_VAR: ""
CFLAGS_VAR_DLL: "CFLAGS=\"/Ox /Oi /MD /DLTM_TEST_DYNAMIC\""

- CFLAGS_VAR: "CFLAGS=\"/Ox /Oi /DMP_SMALL_STACK_SIZE\""
CFLAGS_VAR_DLL: "CFLAGS=\"/Ox /Oi /MD /DLTM_TEST_DYNAMIC /DMP_SMALL_STACK_SIZE\""

- CFLAGS_VAR: "CFLAGS=\"/Ox /Oi /DMP_SMALL_STACK_SIZE /DLTM_TEST_MULTITHREAD\""
CFLAGS_VAR_DLL: "CFLAGS=\"/Ox /Oi /MD /DLTM_TEST_DYNAMIC /DMP_SMALL_STACK_SIZE /DLTM_TEST_MULTITHREAD\""
CFLAGS_VAR_DLL: "CFLAGS=\"/Ox /MD /DLTM_TEST_DYNAMIC\""
build_script:
- cmd: >-
if "Visual Studio 2022"=="%APPVEYOR_BUILD_WORKER_IMAGE%" call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
Expand Down
2 changes: 1 addition & 1 deletion makefile.msvc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

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

#Compilation flags
Expand Down
23 changes: 19 additions & 4 deletions tommath_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,23 @@ MP_PRIVATE mp_err s_mp_fp_log(const mp_int *a, mp_int *c) MP_WUR;
MP_PRIVATE mp_err s_mp_fp_log_d(const mp_int *a, mp_word *c) MP_WUR;

#ifdef MP_SMALL_STACK_SIZE

#if defined(__GNUC__)
/* We use TLS (Thread Local Storage) to manage the instance of the WARRAY
* per thread.
* The compilers we're usually looking at are GCC, Clang and MSVC.
* Both GCC and Clang are straight-forward with TLS, so it's enabled there.
* Using MSVC the tests were OK with the static library, but failed when
* the library was built as a DLL. As a result we completely disable
* support for MSVC.
* If your compiler can handle TLS properly without too much hocus pocus,
* feel free to open a PR to add support for it.
*/
#define mp_thread __thread
#else
#error "MP_SMALL_STACK_SIZE not supported with your compiler"
#endif

#define MP_SMALL_STACK_SIZE_C
#define MP_ALLOC_WARRAY(name) *name = s_mp_warray_get()
#define MP_FREE_WARRAY(name) s_mp_warray_put(name)
Expand All @@ -245,10 +262,8 @@ MP_PRIVATE mp_err s_mp_fp_log_d(const mp_int *a, mp_word *c) MP_WUR;
#define MP_CHECK_WARRAY(name)
#endif

#if defined(_MSC_VER)
#define mp_thread __declspec(thread)
#elif defined(__GNUC__)
#define mp_thread __thread
#ifndef mp_thread
#define mp_thread
#endif

typedef struct {
Expand Down

0 comments on commit 1ea2413

Please sign in to comment.