summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorLeorize <leorize+oss@disroot.org>2020-06-04 17:41:53 -0500
committerAndreas Rumpf <rumpf_a@web.de>2020-06-06 21:11:53 +0200
commit3cd74c6408353aec97f04672140d5de226f3f3af (patch)
treefe6e89ed5656b5a2a2e48b5408b9b46aa4dee517
parentb323bccd8125e9fa4ff28330da1a3adf206b8d32 (diff)
downloadNim-3cd74c6408353aec97f04672140d5de226f3f3af.tar.gz
wrappers/openssl: mark casts as gcsafe
Nim will pretend that these proc are not gcsafe if they are not marked.
-rw-r--r--lib/wrappers/openssl.nim30
1 files changed, 13 insertions, 17 deletions
diff --git a/lib/wrappers/openssl.nim b/lib/wrappers/openssl.nim
index 82fcb2194..a3825b801 100644
--- a/lib/wrappers/openssl.nim
+++ b/lib/wrappers/openssl.nim
@@ -403,29 +403,25 @@ else:
 
   proc getOpenSSLVersion*(): culong =
     ## Return OpenSSL version as unsigned long or 0 if not available
-    let theProc = cast[proc(): culong {.cdecl.}](utilSymNullable("OpenSSL_version_num", "SSLeay"))
-    {.gcsafe.}:
-      result =
-        if theProc.isNil: 0.culong
-        else: theProc()
+    let theProc = cast[proc(): culong {.cdecl, gcsafe.}](utilSymNullable("OpenSSL_version_num", "SSLeay"))
+    result =
+      if theProc.isNil: 0.culong
+      else: theProc()
 
   proc SSL_in_init*(ssl: SslPtr): cint =
     # A compatibility wrapper for `SSL_in_init()` for OpenSSL 1.0, 1.1 and LibreSSL
     const MainProc = "SSL_in_init"
     let
-      theProc {.global.} = cast[proc(ssl: SslPtr): cint {.cdecl.}](sslSymNullable(MainProc))
+      theProc {.global.} = cast[proc(ssl: SslPtr): cint {.cdecl, gcsafe.}](sslSymNullable(MainProc))
       # Fallback
-      sslState {.global.} = cast[proc(ssl: SslPtr): cint {.cdecl.}](sslSymNullable("SSL_state"))
-
-    # FIXME: This shouldn't be needed, but the compiler is complaining about
-    #        `sslState` being GC-ed memory???
-    {.gcsafe.}:
-      if not theProc.isNil:
-        theProc(ssl)
-      elif not sslState.isNil:
-        sslState(ssl) and SSL_ST_INIT
-      else:
-        raiseInvalidLibrary MainProc
+      sslState {.global.} = cast[proc(ssl: SslPtr): cint {.cdecl, gcsafe.}](sslSymNullable("SSL_state"))
+
+    if not theProc.isNil:
+      theProc(ssl)
+    elif not sslState.isNil:
+      sslState(ssl) and SSL_ST_INIT
+    else:
+      raiseInvalidLibrary MainProc
 
 proc ERR_load_BIO_strings*(){.cdecl, dynlib: DLLUtilName, importc.}