diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-05-22 13:13:06 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-05-22 13:13:16 -0700 |
commit | 809742576c8223286bc2e94b649df4c7f72d6150 (patch) | |
tree | 34b211e2107506bcb64bf9da3a21b6b067aa2c3a | |
parent | 876ae8a8b3867f146aaf545466c6170ad5407897 (diff) |
note on ccall/cwrap behavior on strings
-rw-r--r-- | src/preamble.js | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/preamble.js b/src/preamble.js index f46119c7..e0ed8786 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -352,6 +352,13 @@ var cwrap, ccall; // C calling interface. A convenient way to call C functions (in C files, or // defined with extern "C"). // + // Note: ccall/cwrap use the C stack for temporary values. If you pass a string + // then it is only alive until the call is complete. If the code being + // called saves the pointer to be used later, it may point to invalid + // data. If you need a string to live forever, you can create it (and + // must later delete it manually!) using malloc and writeStringToMemory, + // for example. + // // Note: LLVM optimizations can inline and remove functions, after which you will not be // able to call them. Closure can also do so. To avoid that, add your function to // the exports using something like |