-
Notifications
You must be signed in to change notification settings - Fork 5
fix: wchar handling #107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
fix: wchar handling #107
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes wide character (wchar) handling for cross-platform compatibility between Windows (UTF-16) and Unix-based systems (UTF-8). The fix addresses an issue where character buffer sizes were incorrectly calculated on Windows, which uses 2-byte UTF-16 encoding (wchar_t).
Key Changes:
- Added platform-specific character count calculation in C++ to properly handle UTF-16 on Windows
- Introduced a TypeScript helper function to allocate appropriately sized buffers based on platform encoding
- Applied these changes consistently across 30+ API functions
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 26 comments.
| File | Description |
|---|---|
| src/native/main.cpp | Added getCharCount() function to convert byte lengths to character counts (dividing by 2 on Windows for UTF-16), and updated all buffer length calculations to use this function with proper error handling |
| src/lexactivator-native.ts | Added getCArray() function to allocate buffers with correct byte sizes (doubled on Windows for UTF-16 encoding) |
| src/lexactivator.ts | Replaced all direct Uint8Array instantiations with calls to getCArray() to ensure proper buffer allocation across platforms |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Napi::Uint8Array array = info[0].As<Napi::Uint8Array>(); | ||
| size_t length = array.ElementLength(); | ||
| size_t length = getCharCount(env, array.ByteLength()); | ||
| if(env.IsExceptionPending()) { |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space between 'if' and '(' to match the existing code style in this file. The existing code consistently uses 'if (condition)' with a space.
| if(env.IsExceptionPending()) { | |
| if (env.IsExceptionPending()) { |
| Napi::Uint8Array array = info[0].As<Napi::Uint8Array>(); | ||
| size_t length = array.ElementLength(); | ||
| size_t length = getCharCount(env, array.ByteLength()); | ||
| if(env.IsExceptionPending()) { |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space between 'if' and '(' to match the existing code style in this file. The existing code consistently uses 'if (condition)' with a space.
| Napi::Uint8Array array = info[1].As<Napi::Uint8Array>(); | ||
| size_t length = array.ElementLength(); | ||
| size_t length = getCharCount(env, array.ByteLength()); | ||
| if(env.IsExceptionPending()) { |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space between 'if' and '(' to match the existing code style in this file. The existing code consistently uses 'if (condition)' with a space.
| Napi::Uint8Array array = info[0].As<Napi::Uint8Array>(); | ||
| size_t length = array.ElementLength(); | ||
| size_t length = getCharCount(env, array.ByteLength()); | ||
| if(env.IsExceptionPending()) { |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space between 'if' and '(' to match the existing code style in this file. The existing code consistently uses 'if (condition)' with a space.
| if(env.IsExceptionPending()) { | |
| if (env.IsExceptionPending()) { |
| Napi::Uint8Array array = info[0].As<Napi::Uint8Array>(); | ||
| size_t length = array.ElementLength(); | ||
| size_t length = getCharCount(env, array.ByteLength()); | ||
| if(env.IsExceptionPending()) { |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space between 'if' and '(' to match the existing code style in this file. The existing code consistently uses 'if (condition)' with a space.
| Napi::Uint8Array array = info[1].As<Napi::Uint8Array>(); | ||
| size_t length = array.ElementLength(); | ||
| size_t length = getCharCount(env, array.ByteLength()); | ||
| if(env.IsExceptionPending()) { |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space between 'if' and '(' to match the existing code style in this file. The existing code consistently uses 'if (condition)' with a space.
| if(env.IsExceptionPending()) { | |
| if (env.IsExceptionPending()) { |
| Napi::Uint8Array array = info[0].As<Napi::Uint8Array>(); | ||
| size_t length = array.ElementLength(); | ||
| size_t length = getCharCount(env, array.ByteLength()); | ||
| if(env.IsExceptionPending()) { |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space between 'if' and '(' to match the existing code style in this file. The existing code consistently uses 'if (condition)' with a space.
| Napi::Uint8Array array = info[0].As<Napi::Uint8Array>(); | ||
| size_t length = array.ElementLength(); | ||
| size_t length = getCharCount(env, array.ByteLength()); | ||
| if(env.IsExceptionPending()) { |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space between 'if' and '(' to match the existing code style in this file. The existing code consistently uses 'if (condition)' with a space.
| Napi::Uint8Array array = info[0].As<Napi::Uint8Array>(); | ||
| size_t length = array.ElementLength(); | ||
| size_t length = getCharCount(env, array.ByteLength()); | ||
| if(env.IsExceptionPending()) { |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space between 'if' and '(' to match the existing code style in this file. The existing code consistently uses 'if (condition)' with a space.
| Napi::Uint8Array array = info[0].As<Napi::Uint8Array>(); | ||
| size_t length = array.ElementLength(); | ||
| size_t length = getCharCount(env, array.ByteLength()); | ||
| if(env.IsExceptionPending()) { |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space between 'if' and '(' to match the existing code style in this file. The existing code consistently uses 'if (condition)' with a space.


No description provided.