Skip to content

Commit

Permalink
[ruby/prism] Remove ssize_t usage
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton authored and matzbot committed Mar 13, 2024
1 parent 572e791 commit 4dd9602
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions prism/static_literals.c
Expand Up @@ -460,9 +460,9 @@ pm_static_literal_inspect(pm_buffer_t *buffer, const pm_parser_t *parser, const
// %g will not insert a .0 for 1e100 (we'll get back 1e+100). So
// we check for the decimal point and add it in here if it's not
// present.
if (pm_buffer_index(buffer, '.') == -1) {
ssize_t exponent_index = pm_buffer_index(buffer, 'e');
size_t index = exponent_index == -1 ? pm_buffer_length(buffer) : (size_t) exponent_index;
if (pm_buffer_index(buffer, '.') == SIZE_MAX) {
size_t exponent_index = pm_buffer_index(buffer, 'e');
size_t index = exponent_index == SIZE_MAX ? pm_buffer_length(buffer) : exponent_index;
pm_buffer_insert(buffer, index, ".0", 2);
}
}
Expand Down
8 changes: 5 additions & 3 deletions prism/util/pm_buffer.c
Expand Up @@ -286,15 +286,17 @@ pm_buffer_rstrip(pm_buffer_t *buffer) {
/**
* Checks if the buffer includes the given value.
*/
ssize_t pm_buffer_index(const pm_buffer_t *buffer, char value) {
size_t
pm_buffer_index(const pm_buffer_t *buffer, char value) {
const char *first = memchr(buffer->value, value, buffer->length);
return (first == NULL) ? -1 : (ssize_t) (first - buffer->value);
return (first == NULL) ? SIZE_MAX : (size_t) (first - buffer->value);
}

/**
* Insert the given string into the buffer at the given index.
*/
void pm_buffer_insert(pm_buffer_t *buffer, size_t index, const char *value, size_t length) {
void
pm_buffer_insert(pm_buffer_t *buffer, size_t index, const char *value, size_t length) {
assert(index <= buffer->length);

if (index == buffer->length) {
Expand Down
6 changes: 3 additions & 3 deletions prism/util/pm_buffer.h
Expand Up @@ -201,10 +201,10 @@ void pm_buffer_rstrip(pm_buffer_t *buffer);
*
* @param buffer The buffer to check.
* @param value The value to check for.
* @returns The index of the first occurrence of the value in the buffer, or -1
* if the value is not found.
* @returns The index of the first occurrence of the value in the buffer, or
* SIZE_MAX if the value is not found.
*/
ssize_t pm_buffer_index(const pm_buffer_t *buffer, char value);
size_t pm_buffer_index(const pm_buffer_t *buffer, char value);

/**
* Insert the given string into the buffer at the given index.
Expand Down

0 comments on commit 4dd9602

Please sign in to comment.