fix(test): handle big-endian encoding in EncodeUCS2 test - #1023
abhayagarwal-dev wants to merge 2 commits into
Conversation
0ff6f56 to
07e3205
Compare
|
@kkoopa Could you approve the github workflow action when you get a chance? Thank you! |
|
@kkoopa could you take a look at this PR and merge it if everything looks ok? Thank you. |
|
Hi, I am wondering about what to do with ancient versions of Node and
whether this could be accommodated somehow.
…On Sun, Sep 27, 2026, 00:18 abhayagarwal-dev ***@***.***> wrote:
*abhayagarwal-dev* left a comment (nodejs/nan#1023)
<#1023 (comment)>
@kkoopa <https://github.com/kkoopa> could you take a look at this PR and
merge it if everything looks ok? Thank you.
—
Reply to this email directly, view it on GitHub
<#1023?email_source=notifications&email_token=AA7JXKJEMM5BHWSPAMV7JND5RAXBJA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKOBUHE4TMNJTGY42M4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#issuecomment-5849965369>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA7JXKNFFZRQIODCBPB2R335RAXBJAVCNFSNUABEKJSXA33TNF2G64TZHMYTCNJUGU4TEOB3JFZXG5LFHM2TINZVGMYDQMZVHGQXMAQ>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/AA7JXKPXZIVPJAZFYF4X7BT5RAXBJA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKOBUHE4TMNJTGY42M4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJKTGN5XXIZLSL5UW64Y>
and Android
<https://github.com/notifications/mobile/android/AA7JXKKDAFPKLYWNLHCKSJ35RAXBJA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKOBUHE4TMNJTGY42M4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLTGN5XXIZLSL5QW4ZDSN5UWI>.
Download it today!
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
|
Hi @kkoopa, thanks for the review!
|
|
I If I remember correctly, C++11 was not required before V8 4.3, and then
there is Encode in nan_string_bytes.h, might well be some other things
lurking as well. The behavior has changed several times over the years.
…On Sun, Sep 27, 2026, 11:06 Abhay Agarwal ***@***.***> wrote:
*abhayagarwal-dev* left a comment (nodejs/nan#1023)
<#1023 (comment)>
Hi @kkoopa <https://github.com/kkoopa>, thanks for the review!
__BYTE_ORDER__ and__ORDER_BIG_ENDIAN__are GCC/Clang predefined macros
available since GCC 4.6 , well within any Node version NAN has ever
supported. On LE platforms the #if branch is never taken so behaviour is
unchanged. On MSVC (Windows, always LE), the macro isn't defined so the
#else path is taken. No new compiler requirements beyond what C++11
already mandates for the existing char16_t/u"" literals in this file.
—
Reply to this email directly, view it on GitHub
<#1023?email_source=notifications&email_token=AA7JXKJY5IKJUUAKDJS3LWL5RDC77A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKOBVGQYDMMZZGQYKM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#issuecomment-5854063940>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA7JXKKH6URQAZ4225SRREL5RDC77AVCNFSNUABEKJSXA33TNF2G64TZHMYTCNJUGU4TEOB3JFZXG5LFHM2TINZVGMYDQMZVHGQXMAQ>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/AA7JXKJOEIWPY6RRXJCOMR35RDC77A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKOBVGQYDMMZZGQYKM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJKTGN5XXIZLSL5UW64Y>
and Android
<https://github.com/notifications/mobile/android/AA7JXKMDMPCWI77A5KL7YTL5RDC77A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKOBVGQYDMMZZGQYKM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLTGN5XXIZLSL5QW4ZDSN5UWI>.
Download it today!
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
|
Thanks for the context! Would that address your concern? |
|
I would like the behavior to be consistent across versions without the need
for doing conditionals in user code, if it is needed in tests, it is needed
in user code. Would not the proper fix be to backport the new endianness
swap behavior via NAN, thereby fixing it for all without needing a bunch of
#ifs in tests or user code?
…On Sun, Sep 27, 2026, 11:27 Abhay Agarwal ***@***.***> wrote:
*abhayagarwal-dev* left a comment (nodejs/nan#1023)
<#1023 (comment)>
Thanks for the context!
Looking at nan.h, for NODE_MODULE_VERSION <= NODE_0_10_MODULE_VERSION the
call falls through to imp::Encode in nan_string_bytes.h which does no
endianness swap and expects host byte order ,so the swap I added would be
wrong there.
I can add a NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION guard to the
#if condition to be safe.
Would that address your concern?
—
Reply to this email directly, view it on GitHub
<#1023?email_source=notifications&email_token=AA7JXKLIIPN2VTB2GEHF6PT5RDFQ3A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKOBVGQZDAMJSGY2KM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#issuecomment-5854201264>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA7JXKNYLKMEZHNCNLGDWRD5RDFQ3AVCNFSNUABEKJSXA33TNF2G64TZHMYTCNJUGU4TEOB3JFZXG5LFHM2TINZVGMYDQMZVHGQXMAQ>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/AA7JXKJ3SWWJPV3CTACMNHT5RDFQ3A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKOBVGQZDAMJSGY2KM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJKTGN5XXIZLSL5UW64Y>
and Android
<https://github.com/notifications/mobile/android/AA7JXKLS7PXJA2SOOQR6JBT5RDFQ3A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKOBVGQZDAMJSGY2KM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLTGN5XXIZLSL5QW4ZDSN5UWI>.
Download it today!
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
|
That makes complete sense. I have moved the endianness handling directly into This ensures consistent behavior across all Node versions without requiring any I've updated the PR branch with this change. |
|
Could you approve the workflow for the changes so it can be tested? Thank you. |
|
@kkoopa, all 23 checks are passing |
Problem
The
EncodeUCS2test in test/cpp/strings.cpp fails on big-endian architectures (s390x).char16_t stringliterals (likeu"hello") are stored in host byte order (BE on s390x), butnode::Encode(..., UCS2)expects LE input and applies an internal endianness swap on BE systems.Solution
Convert each 16-bit code unit from BE to LE on big-endian platforms
(__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)before passing tonode::Encode.Compute buffer size dynamically (
kNumChars * sizeof(uint16_t)).Little-endian platforms (x86_64, arm64) are unaffected.
Test results
s390x (Big-Endian):
arm64(Little-Endian)
Full test suite: