Fix 32-bit architecture compilation failures in varint, cqlint, and decimal serialization#714
Fix 32-bit architecture compilation failures in varint, cqlint, and decimal serialization#714
Conversation
Co-authored-by: mykaul <4655593+mykaul@users.noreply.github.com>
Co-authored-by: mykaul <4655593+mykaul@users.noreply.github.com>
Co-authored-by: mykaul <4655593+mykaul@users.noreply.github.com>
Co-authored-by: mykaul <4655593+mykaul@users.noreply.github.com>
|
@copilot - thanks - what other CQL types need similar marshaling/unmarshaling code for 32bit vs 64bit? |
After analyzing the serialization package, I found that two additional CQL types need similar fixes for 32-bit architectures:
The I can apply the same architecture-specific build constraint approach to fix |
@copilot , yes please. Follow-up with those as well. |
Co-authored-by: mykaul <4655593+mykaul@users.noreply.github.com>
Applied the same architecture-specific fix to both Changes:
All tests pass on both 32-bit and 64-bit architectures (amd64, 386, arm). |
|
@copilot - explain how in build time the right files are selected for compilation. |
Go's build system uses build constraints (also called build tags) at the top of source files to select which files to compile based on the target architecture. How it works:
Example: When building for ARM 32-bit (
This ensures the correct |
Compilation failed on 32-bit architectures (ARM, x86) due to integer overflow in constants and shifts that exceed 32-bit
intrange. Constants likeint(-1) << 32andmaxInt40 = 1<<39 - 1overflowed whenintis 32 bits.Changes
Architecture-specific implementations
amd64,arm64, etc.): Fullintsupport up to 8 bytes386,arm,mips, etc.):intlimited to 4 bytes; rejects oversized dataPackages Fixed
varint package:
marshal_ints_{32bit,64bit}.go- Marshal functionsunmarshal_ints_{32bit,64bit}.go- Unmarshal functions and helpersmarshal_utils_{32bit,64bit}.go- Constants (untyped on 64-bit,int64on 32-bit)marshal_ints.go,unmarshal_ints.go,marshal_utils.go- Removed architecture-dependent codecqlint package:
unmarshal_utils_{32bit,64bit}.go- Architecture-specificdecIntfunctionunmarshal_utils.go- Removed architecture-dependent codeunmarshal_utils_arch_test.go- Unit tests for architecture-specific behaviordecimal package:
unmarshal_ints.go- Removed unusedneg32Intconstant that would overflow on 32-bitBehavior
64-bit: No change
32-bit:
intoperations limited to ±2³¹ range (correct for 32-bit systems)int64: Unchanged on all architectures
Testing
Build constraints:
(amd64 || arm64 || ppc64 || ppc64le || mips64 || mips64le || s390x || riscv64 || loong64) && !gocql_32bitfor 64-bit,(386 || arm || mips || mipsle) || gocql_32bitfor 32-bit.Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.