Fix big-endian handling for ttext type and refactor code to remove redundancy#718
Merged
mschoema merged 4 commits intoMobilityDB:masterfrom Sep 22, 2025
Merged
Fix big-endian handling for ttext type and refactor code to remove redundancy#718mschoema merged 4 commits intoMobilityDB:masterfrom
mschoema merged 4 commits intoMobilityDB:masterfrom
Conversation
There was a lot of duplicated code in the _from_wkb_state functions. Remove this redundancy with new inline functions read_wkb_value and swap_bytes. Also, remove unused point_from_wkb_state function.
Following the previous PR to remove redundancy from _from_wkb_state functions, do the same with _to_wkb_buf, using typed_value_to_wkb_buf. Also, make static the endian_to_wkb_buf and bytes_to_wkb_buf functions, as they are only used in this file, and remove the unneeded casts, to be consistent with the corresponding functions in PostGIS.
text_to_wkb_buf was using bytes_to_wkb_buf, which swaps the byte order according to the endianness. However, this is only needed for multi-byte int or float types (and date/time types, which are large ints). Text values are simply arrays of chars, so there should be no byte-swapping going on. The initial int64 indicating the size of the string should be swapped if needed, but this is correctly handled by int64_to_wkb_buf. Also, we can avoid a call to text2cstring, which does an unnecessary memory allocation. Use the VARSIZE_ANY_EXHDR and VARDATA macros to copy from the text pointer directly. Lastly, the old function was allocating space for the null terminator as well, which is wrong, as we don't write the null terminator in the wkb output. Fix this, and also correctly add the null terminator in text_from_wkb_state. Palloc doesn't zero-out the memory, so this is necessary or cstring2text could fail.
The error fixed in the previous commit was not detected as the tests for the tbool, tint, tfloat, and ttext types did not test both the little- and big-endian combinations of asBinary or asHexWKB. This commit fixes this.
estebanzimanyi
approved these changes
Sep 20, 2025
Member
Author
|
Well the commits look nice after the rebase and merge, but github doesn't automatically add a link to the PR in their message. I don't think that's ideal in our case. I will stick with squash and merge in the future but will try to write a clean commit message with each PR. |
Member
|
Thanks for this analysis ! From now on, I will expand on the commit messages for the PRs. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Each individual commit in this PR contains a specific code change and has a detailed comment. I will try to merge this PR using 'rebase and merge', which avoids an undesirable squash when the commits in a PR have each their own scope and comment.
I'm not sure if this is better than squashing all commits of a PR into a single commit with a single message, but let's try it out and see.