[ruby/prism] Remove ssize_t usage

https://github.com/ruby/prism/commit/64c4f1268b
This commit is contained in:
Kevin Newton 2024-03-13 11:58:17 -04:00 committed by git
parent 572e791567
commit 4dd9602c6f
3 changed files with 11 additions and 9 deletions

View File

@ -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);
}
}

View File

@ -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) {

View File

@ -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.