Skip to content
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

Fix buffer push uint max #1457

Merged
merged 1 commit into from
Jun 15, 2024
Merged

Conversation

pnelson
Copy link
Contributor

@pnelson pnelson commented Jun 15, 2024

I was using the newer buffer/push-uint[16|32|64] functions and ran up against issues with upper limits.

error: bad slot #2, expected 32 bit signed integer, got 3927367768
  in buffer/push-uint32 [src/core/buffer.c] on line 388

This fixes the issue. I think it is fair that negative numbers here raise bad slot errors so I modified those tests to test the upper bounds instead.

Well, buffer/push-uint16 anything 0xFFFF <= x <= 0xFFFFFFF will push "\xff\xff" without error until it exceeds uint32_t. We could add a similar janet_getuinteger16, janet_checkuint16 , and janet_checkuint16range if that's an issue. Might look better to rename the 32-bit functions for consistency as well in that case so I thought I'd get feedback first if this is enough or what path we should take.

@bakpakin
Copy link
Member

The old behavior was certainly confusing. I also thing the behavior of pushing the uint16 integers is wrong, too - we should fix that.

@bakpakin bakpakin merged commit 0f60115 into janet-lang:master Jun 15, 2024
8 checks passed
@bakpakin
Copy link
Member

That said, I should point out that the FFI module has a much more general implementation of pushing bytes to buffers.

For example,

(ffi/write :uint16 100 @"") # -> @"d\0"
(ffi/read :uint16 @"d\0") # -> 100

@pnelson
Copy link
Contributor Author

pnelson commented Jun 15, 2024

Thanks for the quick turnaround! Control over endianness was required for my use case but I didn't see a way to do so with the FFI module.

@pnelson pnelson deleted the buffer-push-uint branch June 15, 2024 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants