diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2021-05-01 02:12:13 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-01 11:12:13 +0200 |
commit | ee6d56141c11cf9273d3671eb9dd54097361cc1b (patch) | |
tree | 8433fd5c86c7800147488b639cebfb0393de1fd4 /lib/system.nim | |
parent | fb86271556b4ea4485195febaa02b972149ca088 (diff) | |
download | Nim-ee6d56141c11cf9273d3671eb9dd54097361cc1b.tar.gz |
fix #17911 rawProc for cpp (#17912)
Diffstat (limited to 'lib/system.nim')
-rw-r--r-- | lib/system.nim | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/system.nim b/lib/system.nim index e9c036b8a..aecda4a70 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -2414,17 +2414,22 @@ when notJSnotNims: proc rawProc*[T: proc](x: T): pointer {.noSideEffect, inline.} = ## Retrieves the raw proc pointer of the closure `x`. This is - ## useful for interfacing closures with C. + ## useful for interfacing closures with C/C++, hash compuations, etc. when T is "closure": + #[ + The conversion from function pointer to `void*` is a tricky topic, but this + should work at least for c++ >= c++11, e.g. for `dlsym` support. + refs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57869, + https://stackoverflow.com/questions/14125474/casts-between-pointer-to-function-and-pointer-to-object-in-c-and-c + ]# {.emit: """ - `result` = `x`.ClP_0; + `result` = (void*)`x`.ClP_0; """.} else: {.error: "Only closure function and iterator are allowed!".} proc rawEnv*[T: proc](x: T): pointer {.noSideEffect, inline.} = - ## Retrieves the raw environment pointer of the closure `x`. This is - ## useful for interfacing closures with C. + ## Retrieves the raw environment pointer of the closure `x`. See also `rawProc`. when T is "closure": {.emit: """ `result` = `x`.ClE_0; |