-
Notifications
You must be signed in to change notification settings - Fork 30.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
a60056d
commit 56fde66
Showing
6 changed files
with
100 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
bnoordhuis
Author
Member
|
||
} | ||
return Encode(isolate, static_cast<const char*>(buf), len, encoding); | ||
}) | ||
|
||
// Returns -1 if the handle was not valid for decoding | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Yay, LGTM