-
Notifications
You must be signed in to change notification settings - Fork 137
Fix default wstring length #862
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: rolling
Are you sure you want to change the base?
Conversation
2360fe6
to
6eba9f8
Compare
6eba9f8
to
8c50d41
Compare
Signed-off-by: Anthony Welte <[email protected]>
# ASCII characters are encoded as-is | ||
# Non-ASCII characters are encoded as UTF-8 | ||
if c < 0x80: | ||
result += chr(c) | ||
else: | ||
result += '\\x%02x' % c |
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.
nit. comments stays where the code is implemented?
# ASCII characters are encoded as-is | |
# Non-ASCII characters are encoded as UTF-8 | |
if c < 0x80: | |
result += chr(c) | |
else: | |
result += '\\x%02x' % c | |
if c < 0x80: | |
# ASCII characters are encoded as-is | |
result += chr(c) | |
else: | |
# Non-ASCII characters are encoded as UTF-8 | |
result += '\\x%02x' % c |
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.
this looks good to me, just a minor nitpick.
i would like to have an another review for this PR before merge.
Pulls: #862 |
8c50d41
to
0c29c98
Compare
Pulls: #862 |
Signed-off-by: Anthony Welte <[email protected]>
0c29c98
to
52876f4
Compare
Looks like the RHEL build uses an older Python version (before 3.12) which doesn't like strings within fstrings. I've pushed the following modification: """Statically define a runtime Sequence or String type."""
if values:
if isinstance(values, str):
- return f'{{{varname}, {len(values.encode('utf-8'))}, {len(values.encode('utf-8'))}}}'
+ utf8_values = values.encode('utf-8')
+ return f'{{{varname}, {len(utf8_values)}, {len(utf8_values)}}}'
else:
return f'{{{varname}, {len(values)}, {len(values)}}}'
return '{NULL, 0, 0}' |
Pulls: #862 |
This PR fixes strings containing unicode characters not being escaped properly and their size being inaccurate. For instance on WString it results in the following change
It also fixes
"
and'
being over escaped (and some other escaped characters). For instance on https://github.com/Tonywelte/test_interface_files/blob/rolling/msg/Strings.msg (see ros2/test_interface_files#25)Additional notes
+1
instatic_seq
but fortoplevel_type_raw_source
it should be-1
. I'm not sure what's the difference.\'
and\"
are mentioned in https://design.ros2.org/articles/legacy_interface_definition.html but other (\\
and\t
) worked in rosidl_generator_cpp but rosidl_generator_c didn't escape them properly.\n
doesn't work at all.Fixes #855