From 3dd1ecbae4a08627ec619d3abd6ee1f7f24455a6 Mon Sep 17 00:00:00 2001 From: Araq Date: Thu, 26 Feb 2015 02:04:06 +0100 Subject: [PATCH] fixes #2074 --- lib/system/threads.nim | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/system/threads.nim b/lib/system/threads.nim index 4e07200072..81d9e5d73c 100644 --- a/lib/system/threads.nim +++ b/lib/system/threads.nim @@ -84,8 +84,18 @@ when defined(windows): importc: "TlsAlloc", stdcall, header: "".} proc threadVarSetValue(dwTlsIndex: TThreadVarSlot, lpTlsValue: pointer) {. importc: "TlsSetValue", stdcall, header: "".} - proc threadVarGetValue(dwTlsIndex: TThreadVarSlot): pointer {. + proc tlsGetValue(dwTlsIndex: TThreadVarSlot): pointer {. importc: "TlsGetValue", stdcall, header: "".} + + proc getLastError(): uint32 {. + importc: "GetLastError", stdcall, header: "".} + proc setLastError(x: uint32) {. + importc: "SetLastError", stdcall, header: "".} + + proc threadVarGetValue(dwTlsIndex: TThreadVarSlot): pointer = + let realLastError = getLastError() + result = tlsGetValue(dwTlsIndex) + setLastError(realLastError) else: proc threadVarAlloc(): TThreadVarSlot {. importc: "TlsAlloc", stdcall, dynlib: "kernel32".}