Hi, a heads up to Emscripten developers who are marshalling strings between asm.js/C code and handwritten JavaScript: the built-in function writeStringToMemory() that could be used to copy a JavaScript side string to UTF-8 encoded string in asm.js heap is now deprecated.
The function is not removed in the newly tagged version 1.36.8 yet, but will be at some point in the future. When doing a build with 1.36.8 or newer, there will be a deprecation warning print that appears once in the console if writeStringToMemory() is called. The reason that the function is deprecated is that the function signature did not allow passing the maximum byte length that the function is allowed to write. This meant that calling the function would require the user to correctly count the string length (when encoded to UTF-8 bytes) in advance, and to correctly slice the string if truncation was desired. The safe replacement for writeStringToMemory() is another Emscripten built-in function stringToUTF8(), which behaves the same, except that it allows passing in the maximum bytes that the function can write out. To convert to using the safe API, replace instances of writeStringToMemory(myJavaScriptString, pointerToBufferInAsmJSHeap); with stringToUTF8(myJavaScriptString, pointerToBufferInAsmJSHeap, byteLengthOfTheBuffer); The function stringToUTF8() has existed for a long time, since Emscripten 1.29.4 from 1/21/2015, so even if you have not yet updated to 1.36.8, the safe form of the function should still certainly exist and be available to use. As a bonus, the function stringToUTF8 has been greatly optimized compared to writeStringToMemory, and it should allocate no garbage and be considerably faster than writeStringToMemory was. For more information, see https://github.com/kripken/emscripten/pull/4497. Cheers, Jukka -- You received this message because you are subscribed to the Google Groups "emscripten-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
