aboutsummaryrefslogtreecommitdiff
path: root/src/node.h
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2014-12-10 17:33:56 +0100
committerBen Noordhuis <info@bnoordhuis.nl>2014-12-14 16:01:47 +0100
commit56fde66c46653e5c0fbc6e8960d8a013af35f42b (patch)
treec73a2e4a7ddfea89b553c8af6746abe2c3623b0c /src/node.h
parenta60056df3cad2867d337fc1d7adeebe66f89031a (diff)
downloadandroid-node-v8-56fde66c46653e5c0fbc6e8960d8a013af35f42b.tar.gz
android-node-v8-56fde66c46653e5c0fbc6e8960d8a013af35f42b.tar.bz2
android-node-v8-56fde66c46653e5c0fbc6e8960d8a013af35f42b.zip
src: redo unaligned access workaround
Introduce two-byte overloads of node::Encode() and StringBytes::Encode() that ensure that the input is suitably aligned. Revisits commit 535fec8 from yesterday.
Diffstat (limited to 'src/node.h')
-rw-r--r--src/node.h18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/node.h b/src/node.h
index afca6bf0d3..80bb20d40a 100644
--- a/src/node.h
+++ b/src/node.h
@@ -142,6 +142,7 @@ NODE_EXTERN v8::Handle<v8::Value> MakeCallback(
#endif
#include <assert.h>
+#include <stdint.h>
#ifndef NODE_STRINGIFY
#define NODE_STRINGIFY(n) NODE_STRINGIFY_HELPER(n)
@@ -267,16 +268,29 @@ NODE_DEPRECATED("Use FatalException(isolate, ...)",
return FatalException(v8::Isolate::GetCurrent(), try_catch);
})
+// Don't call with encoding=UCS2.
NODE_EXTERN v8::Local<v8::Value> Encode(v8::Isolate* isolate,
- const void* buf,
+ const char* buf,
size_t len,
enum encoding encoding = BINARY);
+
+NODE_EXTERN v8::Local<v8::Value> Encode(v8::Isolate* isolate,
+ const uint16_t* buf,
+ size_t len);
+
NODE_DEPRECATED("Use Encode(isolate, ...)",
inline v8::Local<v8::Value> Encode(
const void* buf,
size_t len,
enum encoding encoding = BINARY) {
- return Encode(v8::Isolate::GetCurrent(), buf, len, encoding);
+ v8::Isolate* isolate = v8::Isolate::GetCurrent();
+ if (encoding == UCS2) {
+ assert(reinterpret_cast<uintptr_t>(buf) % sizeof(uint16_t) == 0 &&
+ "UCS2 buffer must be aligned on two-byte boundary.");
+ const uint16_t* that = static_cast<const uint16_t*>(buf);
+ return Encode(isolate, that, len / sizeof(*that));
+ }
+ return Encode(isolate, static_cast<const char*>(buf), len, encoding);
})
// Returns -1 if the handle was not valid for decoding