From beb65f2ccd4e79c750e3181faa9bb72fa81723a1 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 5 Jun 2025 21:36:54 +0200 Subject: [PATCH] Update after gnulib changed. * gettext-tools/src/msgl-iconv.h (convert_string_desc_directly): Change result type to rw_string_desc_t. * gettext-tools/src/msgl-iconv.c (convert_string_desc_directly): Likewise. * gettext-tools/src/its.c (_its_is_valid_simple_gen_xml): Omit casts to 'char *'. Don't use sd_c_casecmp, sd_cmp as function pointers. * gettext-tools/src/xg-encoding.h (string_desc_from_current_source_encoding): Change result type to rw_string_desc_t. * gettext-tools/src/xg-encoding.c (from_current_source_encoding): Return converted result directly, without a cast. (string_desc_from_current_source_encoding): Change result type to rw_string_desc_t. Return converted result directly, without a cast. Invoke sd_readwrite. * gettext-tools/src/x-perl.c (get_here_document): Add benign cast. (extract_quotelike_pass1, extract_quotelike_pass1_utf8): Change result type to rw_string_desc_t. (extract_quotelike, extract_triple_quotelike): Update. (extract_quotelike_pass3): Add benign casts. (interpolate_keywords): Don't call sd_set_char_at on a string_desc_t. * gettext-tools/src/x-d.c (handle_comments, is_string_literal, string_literal_accumulate_pieces, extract_from_function_call, extract_from_function_call_without_args, extract_from_template_instantation, extract_from_node): Omit casts to 'char *'. * gettext-tools/src/x-go.c (string_literal_accumulate_pieces, string_literal_value, scan_import_spec, get_type_from_type_identifier_node, get_type_from_type_node, store_type_declaration, get_mvtypes_of_expression, store_var_spec, store_const_spec, store_function_declaration, augment_for_type_declaration, augment_for_parameter_list, augment_for_var_spec, augment_for_const_spec, augment_for_short_variable_declaration, handle_comments, extract_from_function_call, extract_from_node): Omit casts to 'char *'. * gettext-tools/src/x-rust.c (handle_comments, string_literal_value): Omit casts to 'char *'. Add benign casts. (extract_from_function_call, extract_from_function_call_like, extract_from_node): Omit casts to 'char *'. * gettext-tools/src/x-typescript-impl.h (handle_comments, sbru_prepend_lone_surrogate): Omit casts to 'char *'. (sbru_xprepend_unicode): Add benign casts. (string_literal_accumulate_pieces, string_literal_value, extract_from_function_call, extract_from_node): Omit casts to 'char *'. --- gettext-tools/src/its.c | 14 +++--- gettext-tools/src/msgl-iconv.c | 4 +- gettext-tools/src/msgl-iconv.h | 4 +- gettext-tools/src/x-d.c | 22 ++++----- gettext-tools/src/x-go.c | 70 +++++++++++++-------------- gettext-tools/src/x-perl.c | 35 ++++++++------ gettext-tools/src/x-rust.c | 20 ++++---- gettext-tools/src/x-typescript-impl.h | 16 +++--- gettext-tools/src/xg-encoding.c | 12 ++--- gettext-tools/src/xg-encoding.h | 4 +- 10 files changed, 102 insertions(+), 99 deletions(-) diff --git a/gettext-tools/src/its.c b/gettext-tools/src/its.c index 4f6301dd0..d2cecb31d 100644 --- a/gettext-tools/src/its.c +++ b/gettext-tools/src/its.c @@ -2341,7 +2341,7 @@ _its_is_valid_simple_gen_xml (const char *contents, if (add_to_node != NULL && !slash_before_tag) { string_desc_t name = - sd_new_addr (name_end - name_start, (char *) name_start); + sd_new_addr (name_end - name_start, name_start); char *name_c = xsd_c (name); if (ignore_case) { @@ -2434,10 +2434,10 @@ _its_is_valid_simple_gen_xml (const char *contents, { string_desc_t attr_name = sd_new_addr (attr_name_end - attr_name_start, - (char *) attr_name_start); + attr_name_start); string_desc_t attr_value = sd_new_addr (attr_value_end - attr_value_start, - (char *) attr_value_start); + attr_value_start); char *attr_name_c = xsd_c (attr_name); char *attr_value_c = xsd_c (attr_value); xmlAttr *attr = @@ -2474,8 +2474,7 @@ _its_is_valid_simple_gen_xml (const char *contents, return false; /* Seen a complete <...> element start/end. */ /* Verify that the tag is allowed. */ - string_desc_t tag = - sd_new_addr (name_end - name_start, (char *) name_start); + string_desc_t tag = sd_new_addr (name_end - name_start, name_start); if (!(valid_element == NULL || valid_element (tag))) return false; if (slash_after_tag || (no_end_element != NULL && no_end_element (tag))) @@ -2499,8 +2498,9 @@ _its_is_valid_simple_gen_xml (const char *contents, if (open_elements_count == 0) /* The end of an element without a corresponding start. */ return false; - if ((ignore_case ? sd_c_casecmp : sd_cmp) - (open_elements[open_elements_count - 1], tag) + if ((ignore_case + ? sd_c_casecmp (open_elements[open_elements_count - 1], tag) + : sd_cmp (open_elements[open_elements_count - 1], tag)) != 0) return false; open_elements_count--; diff --git a/gettext-tools/src/msgl-iconv.c b/gettext-tools/src/msgl-iconv.c index 178940465..eaa36fe16 100644 --- a/gettext-tools/src/msgl-iconv.c +++ b/gettext-tools/src/msgl-iconv.c @@ -95,7 +95,7 @@ convert_string_directly (iconv_t cd, const char *string, return NULL; } -string_desc_t +rw_string_desc_t convert_string_desc_directly (iconv_t cd, string_desc_t string, const struct conversion_context* context) { @@ -108,7 +108,7 @@ convert_string_desc_directly (iconv_t cd, string_desc_t string, conversion_error (context, textmode_xerror_handler); /* NOTREACHED */ - return sd_new_empty (); + return sd_readwrite (sd_new_empty ()); } static char * diff --git a/gettext-tools/src/msgl-iconv.h b/gettext-tools/src/msgl-iconv.h index 955b05779..4d745b42e 100644 --- a/gettext-tools/src/msgl-iconv.h +++ b/gettext-tools/src/msgl-iconv.h @@ -1,5 +1,5 @@ /* Message list character set conversion. - Copyright (C) 2001-2024 Free Software Foundation, Inc. + Copyright (C) 2001-2025 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify @@ -49,7 +49,7 @@ struct conversion_context Assumes that either FROM_CODE or TO_CODE is UTF-8. */ extern char *convert_string_directly (iconv_t cd, const char *string, const struct conversion_context* context); -extern string_desc_t +extern rw_string_desc_t convert_string_desc_directly (iconv_t cd, string_desc_t string, const struct conversion_context* context); diff --git a/gettext-tools/src/x-d.c b/gettext-tools/src/x-d.c index 142ac62d4..09ec90a6e 100644 --- a/gettext-tools/src/x-d.c +++ b/gettext-tools/src/x-d.c @@ -333,7 +333,7 @@ static void handle_comments (TSNode node) { string_desc_t entire = sd_new_addr (ts_node_end_byte (node) - ts_node_start_byte (node), - (char *) contents + ts_node_start_byte (node)); + contents + ts_node_start_byte (node)); /* It should either start with two slashes... */ if (sd_length (entire) >= 2 && sd_char_at (entire, 0) == '/' @@ -430,7 +430,7 @@ is_string_literal (TSNode node) { string_desc_t node_contents = sd_new_addr (ts_node_end_byte (node) - ts_node_start_byte (node), - (char *) contents + ts_node_start_byte (node)); + contents + ts_node_start_byte (node)); #if DEBUG_D && 0 fprintf (stderr, "[%s]|%s|%.*s|\n", ts_node_type (node), ts_node_string (node), (int) sd_length (node_contents), sd_data (node_contents)); #if 0 @@ -441,7 +441,7 @@ is_string_literal (TSNode node) TSNode subnode = ts_node_named_child (node, i); string_desc_t subnode_contents = sd_new_addr (ts_node_end_byte (subnode) - ts_node_start_byte (subnode), - (char *) contents + ts_node_start_byte (subnode)); + contents + ts_node_start_byte (subnode)); fprintf (stderr, "%u -> [%s]|%s|%.*s|\n", i, ts_node_type (subnode), ts_node_string (subnode), (int) sd_length (subnode_contents), sd_data (subnode_contents)); uint32_t count2 = ts_node_child_count (subnode); uint32_t j; @@ -509,7 +509,7 @@ string_literal_accumulate_pieces (TSNode node, */ string_desc_t node_contents = sd_new_addr (ts_node_end_byte (node) - ts_node_start_byte (node), - (char *) contents + ts_node_start_byte (node)); + contents + ts_node_start_byte (node)); #if DEBUG_D && 0 fprintf (stderr, "[%s]|%s|%.*s|\n", ts_node_type (node), ts_node_string (node), (int) sd_length (node_contents), sd_data (node_contents)); #endif @@ -543,7 +543,7 @@ string_literal_accumulate_pieces (TSNode node, const char *escape_start = contents + ts_node_start_byte (escnode); const char *escape_end = contents + ts_node_end_byte (escnode); if (escape_end < ptr) - sbr_xprepend_desc (buffer, sd_new_addr (ptr - escape_end, (char *) escape_end)); + sbr_xprepend_desc (buffer, sd_new_addr (ptr - escape_end, escape_end)); /* The escape sequence must start with a backslash. */ if (!(escape_end - escape_start >= 2 && escape_start[0] == '\\')) @@ -643,7 +643,7 @@ string_literal_accumulate_pieces (TSNode node, int n = u8_uctomb (buf, value, sizeof (buf)); if (!(n > 0)) abort (); - sbr_xprepend_desc (buffer, sd_new_addr (n, (char *) buf)); + sbr_xprepend_desc (buffer, sd_new_addr (n, (const char *) buf)); } else invalid = true; @@ -652,7 +652,7 @@ string_literal_accumulate_pieces (TSNode node, { /* A named character entity. */ string_desc_t entity = - sd_new_addr (escape_end - escape_start - 3, (char *) escape_start + 2); + sd_new_addr (escape_end - escape_start - 3, escape_start + 2); const char *value = html5_lookup (entity); if (value != NULL) sbr_xprepend_c (buffer, value); @@ -890,7 +890,7 @@ extract_from_function_call (TSNode node, { string_desc_t function_name = sd_new_addr (ts_node_end_byte (function_node) - ts_node_start_byte (function_node), - (char *) contents + ts_node_start_byte (function_node)); + contents + ts_node_start_byte (function_node)); /* Context iterator. */ next_context_iter = @@ -1177,7 +1177,7 @@ extract_from_function_call_without_args (TSNode callee_node, { string_desc_t function_name = sd_new_addr (ts_node_end_byte (function_node) - ts_node_start_byte (function_node), - (char *) contents + ts_node_start_byte (function_node)); + contents + ts_node_start_byte (function_node)); /* Context iterator. */ next_context_iter = @@ -1335,7 +1335,7 @@ extract_from_template_instantation (TSNode node, string_desc_t template_name = sd_new_addr (ts_node_end_byte (identifier_node) - ts_node_start_byte (identifier_node), - (char *) contents + ts_node_start_byte (identifier_node)); + contents + ts_node_start_byte (identifier_node)); /* Handle the potential comments in node, between identifier_node and args_node. */ @@ -1626,7 +1626,7 @@ extract_from_node (TSNode node, { string_desc_t subnode_string = sd_new_addr (ts_node_end_byte (subnode) - ts_node_start_byte (subnode), - (char *) contents + ts_node_start_byte (subnode)); + contents + ts_node_start_byte (subnode)); if (sd_equals (subnode_string, sd_from_c ("gettext"))) { TSNode argsnode = ts_node_named_child (node, 1); diff --git a/gettext-tools/src/x-go.c b/gettext-tools/src/x-go.c index 9c7110760..e4241a3d8 100644 --- a/gettext-tools/src/x-go.c +++ b/gettext-tools/src/x-go.c @@ -1063,7 +1063,7 @@ string_literal_accumulate_pieces (TSNode node, { string_desc_t subnode_string = sd_new_addr (ts_node_end_byte (subnode) - ts_node_start_byte (subnode), - (char *) contents + ts_node_start_byte (subnode)); + contents + ts_node_start_byte (subnode)); /* Eliminate '\r' characters. */ for (;;) { @@ -1081,7 +1081,7 @@ string_literal_accumulate_pieces (TSNode node, { string_desc_t subnode_string = sd_new_addr (ts_node_end_byte (subnode) - ts_node_start_byte (subnode), - (char *) contents + ts_node_start_byte (subnode)); + contents + ts_node_start_byte (subnode)); sbr_xprepend_desc (buffer, subnode_string); } else if (ts_node_symbol (subnode) == ts_symbol_escape_sequence) @@ -1184,7 +1184,7 @@ string_literal_accumulate_pieces (TSNode node, uint8_t buf[6]; int n = u8_uctomb (buf, value, sizeof (buf)); if (n > 0) - sbr_xprepend_desc (buffer, sd_new_addr (n, (char *) buf)); + sbr_xprepend_desc (buffer, sd_new_addr (n, (const char *) buf)); else invalid = true; } @@ -1233,7 +1233,7 @@ string_literal_value (TSNode node) that is non-empty and has no escape sequences. */ string_desc_t subnode_string = sd_new_addr (ts_node_end_byte (subnode) - ts_node_start_byte (subnode), - (char *) contents + ts_node_start_byte (subnode)); + contents + ts_node_start_byte (subnode)); return xsd_c (subnode_string); } } @@ -1283,7 +1283,7 @@ scan_import_spec (TSNode import_spec_node) /* A package is imported with a name. */ shortname = sd_new_addr (ts_node_end_byte (name_node) - ts_node_start_byte (name_node), - (char *) contents + ts_node_start_byte (name_node)); + contents + ts_node_start_byte (name_node)); } else { @@ -1469,7 +1469,7 @@ get_type_from_type_identifier_node (TSNode type_node, type_env_t tenv, bool use_ { string_desc_t type_name = sd_new_addr (ts_node_end_byte (type_node) - ts_node_start_byte (type_node), - (char *) contents + ts_node_start_byte (type_node)); + contents + ts_node_start_byte (type_node)); return get_type_from_type_name (type_name, tenv, use_indirections); } @@ -1534,7 +1534,7 @@ get_type_from_type_node (TSNode type_node, type_env_t tenv, bool use_indirection #if DEBUG_GO && 0 string_desc_t type_node_name = sd_new_addr (ts_node_end_byte (type_node) - ts_node_start_byte (type_node), - (char *) contents + ts_node_start_byte (type_node)); + contents + ts_node_start_byte (type_node)); fprintf (stderr, "type_node = [%s]|%s| = %s\n", ts_node_type (type_node), ts_node_string (type_node), sd_c (type_node_name)); #endif while (ts_node_symbol (type_node) == ts_symbol_parenthesized_type @@ -1551,7 +1551,7 @@ get_type_from_type_node (TSNode type_node, type_env_t tenv, bool use_indirection TSNode shortname_node = ts_node_child_by_field_id (type_node, ts_field_package); string_desc_t shortname = sd_new_addr (ts_node_end_byte (shortname_node) - ts_node_start_byte (shortname_node), - (char *) contents + ts_node_start_byte (shortname_node)); + contents + ts_node_start_byte (shortname_node)); /* Look up the package's full name. */ void *found_package; if (hash_find_entry (&package_table, @@ -1565,7 +1565,7 @@ get_type_from_type_node (TSNode type_node, type_env_t tenv, bool use_indirection TSNode name_node = ts_node_child_by_field_id (type_node, ts_field_name); string_desc_t name = sd_new_addr (ts_node_end_byte (name_node) - ts_node_start_byte (name_node), - (char *) contents + ts_node_start_byte (name_node)); + contents + ts_node_start_byte (name_node)); void *found_type; if (hash_find_entry (&gotext_package.defined_types, sd_data (name), sd_length (name), @@ -1579,7 +1579,7 @@ get_type_from_type_node (TSNode type_node, type_env_t tenv, bool use_indirection TSNode name_node = ts_node_child_by_field_id (type_node, ts_field_name); string_desc_t name = sd_new_addr (ts_node_end_byte (name_node) - ts_node_start_byte (name_node), - (char *) contents + ts_node_start_byte (name_node)); + contents + ts_node_start_byte (name_node)); void *found_type; if (hash_find_entry (&snapcore_package.defined_types, sd_data (name), sd_length (name), @@ -1652,7 +1652,7 @@ get_type_from_type_node (TSNode type_node, type_env_t tenv, bool use_indirection members[n].name = xsd_c ( sd_new_addr (ts_node_end_byte (subnode) - ts_node_start_byte (subnode), - (char *) contents + ts_node_start_byte (subnode))); + contents + ts_node_start_byte (subnode))); members[n].type = eltype; n++; } @@ -1701,7 +1701,7 @@ get_type_from_type_node (TSNode type_node, type_env_t tenv, bool use_indirection abort (); string_desc_t name = sd_new_addr (ts_node_end_byte (name_node) - ts_node_start_byte (name_node), - (char *) contents + ts_node_start_byte (name_node)); + contents + ts_node_start_byte (name_node)); methods[nm].name = xsd_c (name); methods[nm].type = get_type_from_function_or_method_node (subnode, tenv, use_indirections); nm++; @@ -1762,7 +1762,7 @@ store_type_declaration (TSNode node) abort (); string_desc_t name = sd_new_addr (ts_node_end_byte (name_node) - ts_node_start_byte (name_node), - (char *) contents + ts_node_start_byte (name_node)); + contents + ts_node_start_byte (name_node)); #if DEBUG_GO && 0 fprintf (stderr, "Type name = %s\n", sd_c (name)); #endif @@ -2232,7 +2232,7 @@ get_mvtypes_of_expression (unsigned int mvcount, go_type_t **result, { string_desc_t name = sd_new_addr (ts_node_end_byte (node) - ts_node_start_byte (node), - (char *) contents + ts_node_start_byte (node)); + contents + ts_node_start_byte (node)); return1 (variable_env_lookup (name, venv)); } if (ts_node_symbol (node) == ts_symbol_unary_expression) @@ -2240,7 +2240,7 @@ get_mvtypes_of_expression (unsigned int mvcount, go_type_t **result, TSNode operator_node = ts_node_child_by_field_id (node, ts_field_operator); string_desc_t operator = sd_new_addr (ts_node_end_byte (operator_node) - ts_node_start_byte (operator_node), - (char *) contents + ts_node_start_byte (operator_node)); + contents + ts_node_start_byte (operator_node)); if (sd_equals (operator, sd_from_c ("*"))) { TSNode operand_node = ts_node_child_by_field_id (node, ts_field_operand); @@ -2273,14 +2273,14 @@ get_mvtypes_of_expression (unsigned int mvcount, go_type_t **result, abort (); string_desc_t field_name = sd_new_addr (ts_node_end_byte (field_node) - ts_node_start_byte (field_node), - (char *) contents + ts_node_start_byte (field_node)); + contents + ts_node_start_byte (field_node)); TSNode operand_node = ts_node_child_by_field_id (node, ts_field_operand); /* If the operand is a package name, we have in fact a qualified identifier. */ if (ts_node_symbol (operand_node) == ts_symbol_identifier) { string_desc_t shortname = sd_new_addr (ts_node_end_byte (operand_node) - ts_node_start_byte (operand_node), - (char *) contents + ts_node_start_byte (operand_node)); + contents + ts_node_start_byte (operand_node)); /* Look up the package's full name. */ void *found_package; if (hash_find_entry (&package_table, @@ -2401,7 +2401,7 @@ get_mvtypes_of_expression (unsigned int mvcount, go_type_t **result, { string_desc_t function_name = sd_new_addr (ts_node_end_byte (function_node) - ts_node_start_byte (function_node), - (char *) contents + ts_node_start_byte (function_node)); + contents + ts_node_start_byte (function_node)); if (sd_equals (function_name, sd_from_c ("new"))) { TSNode args_node = ts_node_child_by_field_id (node, ts_field_arguments); @@ -2496,7 +2496,7 @@ store_var_spec (TSNode node) TSNode name_node = subnode; string_desc_t name = sd_new_addr (ts_node_end_byte (name_node) - ts_node_start_byte (name_node), - (char *) contents + ts_node_start_byte (name_node)); + contents + ts_node_start_byte (name_node)); #if DEBUG_GO && 0 fprintf (stderr, "Var name = %s\n", sd_c (name)); #endif @@ -2547,7 +2547,7 @@ store_var_spec (TSNode node) TSNode name_node = subnode; string_desc_t name = sd_new_addr (ts_node_end_byte (name_node) - ts_node_start_byte (name_node), - (char *) contents + ts_node_start_byte (name_node)); + contents + ts_node_start_byte (name_node)); #if DEBUG_GO && 0 fprintf (stderr, "Var name = %s\n", sd_c (name)); #endif @@ -2600,7 +2600,7 @@ store_const_spec (TSNode node) TSNode name_node = ts_node_child_by_field_id (node, ts_field_name); string_desc_t name = sd_new_addr (ts_node_end_byte (name_node) - ts_node_start_byte (name_node), - (char *) contents + ts_node_start_byte (name_node)); + contents + ts_node_start_byte (name_node)); #if DEBUG_GO && 0 fprintf (stderr, "Const name = %s\n", sd_c (name)); #endif @@ -2633,7 +2633,7 @@ store_function_declaration (TSNode node) TSNode name_node = ts_node_child_by_field_id (node, ts_field_name); string_desc_t name = sd_new_addr (ts_node_end_byte (name_node) - ts_node_start_byte (name_node), - (char *) contents + ts_node_start_byte (name_node)); + contents + ts_node_start_byte (name_node)); #if DEBUG_GO && 0 fprintf (stderr, "Func name = %s\n", sd_c (name)); #endif @@ -2692,7 +2692,7 @@ augment_for_type_declaration (TSNode node, type_env_t tenv) abort (); string_desc_t name = sd_new_addr (ts_node_end_byte (name_node) - ts_node_start_byte (name_node), - (char *) contents + ts_node_start_byte (name_node)); + contents + ts_node_start_byte (name_node)); #if DEBUG_GO && 0 fprintf (stderr, "Local type name = %s\n", sd_c (name)); #endif @@ -2726,7 +2726,7 @@ augment_for_parameter_list (TSNode node, type_env_t tenv, variable_env_t venv) TSNode name_node = subsubnode; string_desc_t name = sd_new_addr (ts_node_end_byte (name_node) - ts_node_start_byte (name_node), - (char *) contents + ts_node_start_byte (name_node)); + contents + ts_node_start_byte (name_node)); #if DEBUG_GO && 0 fprintf (stderr, "Local parameter name = %s\n", sd_c (name)); #endif @@ -2748,7 +2748,7 @@ augment_for_parameter_list (TSNode node, type_env_t tenv, variable_env_t venv) TSNode name_node = subsubnode; string_desc_t name = sd_new_addr (ts_node_end_byte (name_node) - ts_node_start_byte (name_node), - (char *) contents + ts_node_start_byte (name_node)); + contents + ts_node_start_byte (name_node)); #if DEBUG_GO && 0 fprintf (stderr, "Local variadic parameter name = %s\n", sd_c (name)); #endif @@ -2783,7 +2783,7 @@ augment_for_var_spec (TSNode node, type_env_t tenv, variable_env_t venv) TSNode name_node = subnode; string_desc_t name = sd_new_addr (ts_node_end_byte (name_node) - ts_node_start_byte (name_node), - (char *) contents + ts_node_start_byte (name_node)); + contents + ts_node_start_byte (name_node)); #if DEBUG_GO && 0 fprintf (stderr, "Local var name = %s\n", sd_c (name)); #endif @@ -2831,7 +2831,7 @@ augment_for_var_spec (TSNode node, type_env_t tenv, variable_env_t venv) TSNode name_node = subnode; string_desc_t name = sd_new_addr (ts_node_end_byte (name_node) - ts_node_start_byte (name_node), - (char *) contents + ts_node_start_byte (name_node)); + contents + ts_node_start_byte (name_node)); #if DEBUG_GO && 0 fprintf (stderr, "Local var name = %s\n", sd_c (name)); #endif @@ -2887,7 +2887,7 @@ augment_for_const_spec (TSNode node, type_env_t tenv, variable_env_t venv) TSNode name_node = ts_node_child_by_field_id (node, ts_field_name); string_desc_t name = sd_new_addr (ts_node_end_byte (name_node) - ts_node_start_byte (name_node), - (char *) contents + ts_node_start_byte (name_node)); + contents + ts_node_start_byte (name_node)); #if DEBUG_GO && 0 fprintf (stderr, "Local const name = %s\n", sd_c (name)); #endif @@ -2943,7 +2943,7 @@ augment_for_short_variable_declaration (TSNode node, type_env_t tenv, variable_e { string_desc_t left_var_name = sd_new_addr (ts_node_end_byte (left_var_node) - ts_node_start_byte (left_var_node), - (char *) contents + ts_node_start_byte (left_var_node)); + contents + ts_node_start_byte (left_var_node)); if (!sd_equals (left_var_name, sd_from_c ("_"))) venv = variable_env_augment (venv, left_var_name, mvtypes[i]); } @@ -2998,7 +2998,7 @@ static void handle_comments (TSNode node) { string_desc_t entire = sd_new_addr (ts_node_end_byte (node) - ts_node_start_byte (node), - (char *) contents + ts_node_start_byte (node)); + contents + ts_node_start_byte (node)); /* It should either start with two slashes, or start and end with the C comment markers. */ if (sd_length (entire) >= 2 @@ -3097,7 +3097,7 @@ extract_from_function_call (TSNode callee_node, string_desc_t function_name = sd_new_addr (ts_node_end_byte (function_node) - ts_node_start_byte (function_node), - (char *) contents + ts_node_start_byte (function_node)); + contents + ts_node_start_byte (function_node)); /* Context iterator. */ flag_context_list_iterator_ty next_context_iter = @@ -3130,7 +3130,7 @@ extract_from_function_call (TSNode callee_node, { string_desc_t shortname = sd_new_addr (ts_node_end_byte (operand_node) - ts_node_start_byte (operand_node), - (char *) contents + ts_node_start_byte (operand_node)); + contents + ts_node_start_byte (operand_node)); /* Look up the package's full name. */ void *found_package; if (hash_find_entry (&package_table, @@ -3344,13 +3344,13 @@ extract_from_node (TSNode node, TSNode operand_node = ts_node_child_by_field_id (callee_node, ts_field_operand); string_desc_t operand_name = sd_new_addr (ts_node_end_byte (operand_node) - ts_node_start_byte (operand_node), - (char *) contents + ts_node_start_byte (operand_node)); + contents + ts_node_start_byte (operand_node)); fprintf (stderr, "operand_node = [%s]|%s| = %s\n", ts_node_type (operand_node), ts_node_string (operand_node), sd_c (operand_name)); TSNode field_node = ts_node_child_by_field_id (callee_node, ts_field_field); string_desc_t field_name = sd_new_addr (ts_node_end_byte (field_node) - ts_node_start_byte (field_node), - (char *) contents + ts_node_start_byte (field_node)); + contents + ts_node_start_byte (field_node)); fprintf (stderr, "field_node = [%s]|%s| = %s\n", ts_node_type (field_node), ts_node_string (field_node), sd_c (field_name)); } #endif @@ -3391,7 +3391,7 @@ extract_from_node (TSNode node, { string_desc_t subnode_string = sd_new_addr (ts_node_end_byte (subnode) - ts_node_start_byte (subnode), - (char *) contents + ts_node_start_byte (subnode)); + contents + ts_node_start_byte (subnode)); if (sd_equals (subnode_string, sd_from_c ("gettext"))) { TSNode argsnode = ts_node_child_by_field_id (node, ts_field_arguments); diff --git a/gettext-tools/src/x-perl.c b/gettext-tools/src/x-perl.c index dd640e08f..d286b10c1 100644 --- a/gettext-tools/src/x-perl.c +++ b/gettext-tools/src/x-perl.c @@ -509,7 +509,8 @@ get_here_document (struct perl_extractor *xp, const char *delimiter) my_linebuf[read_bytes - 1] = '\n'; /* Append this line to the accumulator. */ - sb_xappend_desc (&buffer, sd_new_addr (read_bytes, my_linebuf)); + sb_xappend_desc (&buffer, + sd_new_addr (read_bytes, (const char *) my_linebuf)); } /* Done accumulating the here document. */ @@ -736,7 +737,7 @@ free_token (token_ty *tp) of the semantics of the construct. Return the complete string, including the starting and the trailing delimiter, with backslashes removed where appropriate. */ -static string_desc_t +static rw_string_desc_t extract_quotelike_pass1 (struct perl_extractor *xp, int delim) { struct string_buffer buffer; @@ -782,8 +783,8 @@ extract_quotelike_pass1 (struct perl_extractor *xp, int delim) if (nested && c == delim) { - string_desc_t inner = extract_quotelike_pass1 (xp, delim); - sb_xappend_desc (&buffer, inner); + rw_string_desc_t inner = extract_quotelike_pass1 (xp, delim); + sb_xappend_desc (&buffer, sd_readonly (inner)); sd_free (inner); } else if (c == '\\') @@ -814,12 +815,12 @@ extract_quotelike_pass1 (struct perl_extractor *xp, int delim) /* Like extract_quotelike_pass1, but return the complete string in UTF-8 encoding. */ -static string_desc_t +static rw_string_desc_t extract_quotelike_pass1_utf8 (struct perl_extractor *xp, int delim) { - string_desc_t string = extract_quotelike_pass1 (xp, delim); - string_desc_t utf8_string = - string_desc_from_current_source_encoding (string, lc_string, + rw_string_desc_t string = extract_quotelike_pass1 (xp, delim); + rw_string_desc_t utf8_string = + string_desc_from_current_source_encoding (sd_readonly (string), lc_string, logical_file_name, xp->line_number); if (sd_data (utf8_string) != sd_data (string)) @@ -914,7 +915,7 @@ extract_oct (const char *string, size_t len, unsigned int *result) static void extract_quotelike (struct perl_extractor *xp, token_ty *tp, int delim) { - string_desc_t string = extract_quotelike_pass1_utf8 (xp, delim); + rw_string_desc_t string = extract_quotelike_pass1_utf8 (xp, delim); size_t len = sd_length (string); tp->type = token_type_string; @@ -934,13 +935,13 @@ static void extract_triple_quotelike (struct perl_extractor *xp, token_ty *tp, int delim, bool interpolate) { - string_desc_t string; + rw_string_desc_t string; tp->type = token_type_regex_op; string = extract_quotelike_pass1_utf8 (xp, delim); if (interpolate) - interpolate_keywords (xp, string, xp->line_number); + interpolate_keywords (xp, sd_readonly (string), xp->line_number); sd_free (string); if (delim == '(' || delim == '<' || delim == '{' || delim == '[') @@ -957,7 +958,7 @@ extract_triple_quotelike (struct perl_extractor *xp, token_ty *tp, int delim, } string = extract_quotelike_pass1_utf8 (xp, delim); if (interpolate) - interpolate_keywords (xp, string, xp->line_number); + interpolate_keywords (xp, sd_readonly (string), xp->line_number); sd_free (string); } @@ -1091,7 +1092,8 @@ extract_quotelike_pass3 (struct perl_extractor *xp, token_ty *tp) int length = u8_uctomb ((unsigned char *) tmpbuf, oct_number, 2); if (length > 0) - sb_xappend_desc (&buffer, sd_new_addr (length, tmpbuf)); + sb_xappend_desc (&buffer, + sd_new_addr (length, (const char *) tmpbuf)); } continue; case 'x': @@ -1140,7 +1142,8 @@ extract_quotelike_pass3 (struct perl_extractor *xp, token_ty *tp) int length = u8_uctomb ((unsigned char *) tmpbuf, hex_number, 6); if (length > 0) - sb_xappend_desc (&buffer, sd_new_addr (length, tmpbuf)); + sb_xappend_desc (&buffer, + sd_new_addr (length, (const char *) tmpbuf)); } continue; case 'c': @@ -1178,7 +1181,7 @@ extract_quotelike_pass3 (struct perl_extractor *xp, token_ty *tp) u8_uctomb ((unsigned char *) tmpbuf, unicode, 6); if (length > 0) sb_xappend_desc (&buffer, - sd_new_addr (length, tmpbuf)); + sd_new_addr (length, (const char *) tmpbuf)); } free (name); @@ -1878,7 +1881,7 @@ interpolate_keywords (struct perl_extractor *xp, string_desc_t string, { string_desc_t contents = sb_contents (&buffer); if (!maybe_hash_deref) - sd_set_char_at (contents, 0, '%'); + ((char *) sd_data (contents))[0] = '%'; if (hash_find_entry (&keywords, sd_data (contents), sd_length (contents), diff --git a/gettext-tools/src/x-rust.c b/gettext-tools/src/x-rust.c index baec5b9c3..87c78e3d1 100644 --- a/gettext-tools/src/x-rust.c +++ b/gettext-tools/src/x-rust.c @@ -282,7 +282,7 @@ static void handle_comments (TSNode node) { string_desc_t entire = sd_new_addr (ts_node_end_byte (node) - ts_node_start_byte (node), - (char *) contents + ts_node_start_byte (node)); + contents + ts_node_start_byte (node)); /* It should start with two slashes. */ if (!(sd_length (entire) >= 2 && sd_char_at (entire, 0) == '/' @@ -295,7 +295,7 @@ static void handle_comments (TSNode node) { string_desc_t entire = sd_new_addr (ts_node_end_byte (node) - ts_node_start_byte (node), - (char *) contents + ts_node_start_byte (node)); + contents + ts_node_start_byte (node)); /* It should start and end with the C comment markers. */ if (!(sd_length (entire) >= 4 && sd_char_at (entire, 0) == '/' @@ -342,7 +342,7 @@ string_literal_value (TSNode node) that is non-empty and has no escape sequences. */ string_desc_t subnode_string = sd_new_addr (ts_node_end_byte (subnode) - ts_node_start_byte (subnode), - (char *) contents + ts_node_start_byte (subnode)); + contents + ts_node_start_byte (subnode)); return xsd_c (subnode_string); } } @@ -360,7 +360,7 @@ string_literal_value (TSNode node) { string_desc_t subnode_string = sd_new_addr (ts_node_end_byte (subnode) - ts_node_start_byte (subnode), - (char *) contents + ts_node_start_byte (subnode)); + contents + ts_node_start_byte (subnode)); if (skip_leading_whitespace) { /* After backslash-newline, skip ASCII whitespace. */ @@ -433,7 +433,7 @@ string_literal_value (TSNode node) uint8_t buf[6]; int n = u8_uctomb (buf, value, sizeof (buf)); if (n > 0) - sb_xappend_desc (&buffer, sd_new_addr (n, (char *) buf)); + sb_xappend_desc (&buffer, sd_new_addr (n, (const char *) buf)); else invalid = true; } @@ -465,7 +465,7 @@ string_literal_value (TSNode node) uint8_t buf[6]; int n = u8_uctomb (buf, value, sizeof (buf)); if (n > 0) - sb_xappend_desc (&buffer, sd_new_addr (n, (char *) buf)); + sb_xappend_desc (&buffer, sd_new_addr (n, (const char *) buf)); else invalid = true; } @@ -530,7 +530,7 @@ extract_from_function_call (TSNode callee_node, string_desc_t callee_name = sd_new_addr (ts_node_end_byte (callee_node) - ts_node_start_byte (callee_node), - (char *) contents + ts_node_start_byte (callee_node)); + contents + ts_node_start_byte (callee_node)); /* Context iterator. */ flag_context_list_iterator_ty next_context_iter = @@ -682,7 +682,7 @@ extract_from_function_call_like (TSNode *callee_node, bool callee_is_macro, { string_desc_t callee_name = sd_new_addr (ts_node_end_byte (*callee_node) - ts_node_start_byte (*callee_node), - (char *) contents + ts_node_start_byte (*callee_node)); + contents + ts_node_start_byte (*callee_node)); next_context_iter = (args_count >= 2 @@ -1038,7 +1038,7 @@ extract_from_node (TSNode node, { string_desc_t subnode_string = sd_new_addr (ts_node_end_byte (subnode) - ts_node_start_byte (subnode), - (char *) contents + ts_node_start_byte (subnode)); + contents + ts_node_start_byte (subnode)); if (sd_equals (subnode_string, sd_from_c ("gettext"))) { TSNode argsnode = ts_node_child_by_field_id (node, ts_field_arguments); @@ -1058,7 +1058,7 @@ extract_from_node (TSNode node, { string_desc_t subnode_string = sd_new_addr (ts_node_end_byte (subnode) - ts_node_start_byte (subnode), - (char *) contents + ts_node_start_byte (subnode)); + contents + ts_node_start_byte (subnode)); fprintf (stderr, "identifier=%s\n", xsd_c (subnode_string)); if (sd_equals (subnode_string, sd_from_c ("println"))) { diff --git a/gettext-tools/src/x-typescript-impl.h b/gettext-tools/src/x-typescript-impl.h index a5f549857..525067d99 100644 --- a/gettext-tools/src/x-typescript-impl.h +++ b/gettext-tools/src/x-typescript-impl.h @@ -249,7 +249,7 @@ static void handle_comments (TSNode node) { string_desc_t entire = sd_new_addr (ts_node_end_byte (node) - ts_node_start_byte (node), - (char *) contents + ts_node_start_byte (node)); + contents + ts_node_start_byte (node)); /* It should either start with two slashes... */ if (sd_length (entire) >= 2 && sd_char_at (entire, 0) == '/' @@ -347,7 +347,7 @@ sbru_prepend_lone_surrogate (struct string_buffer_reversed_unicode *buffer, logical_file_name, line_number, (size_t)(-1), false, _("lone surrogate U+%04X"), uc); string_desc_t fffd = /* U+FFFD in UTF-8 encoding. */ - sd_new_addr (3, (char *) "\357\277\275"); + sd_new_addr (3, "\357\277\275"); sbr_xprepend_desc (&buffer->sbr, fffd); } @@ -402,7 +402,7 @@ sbru_xprepend_unicode (struct string_buffer_reversed_unicode *buffer, int n = u8_uctomb (buf, uc, sizeof (buf)); if (!(n > 0)) abort (); - sbr_xprepend_desc (&buffer->sbr, sd_new_addr (n, (char *) buf)); + sbr_xprepend_desc (&buffer->sbr, sd_new_addr (n, (const char *) buf)); buffer->utf16_surr = 0; } @@ -423,7 +423,7 @@ sbru_xprepend_unicode (struct string_buffer_reversed_unicode *buffer, int n = u8_uctomb (buf, c, sizeof (buf)); if (!(n > 0)) abort (); - sbr_xprepend_desc (&buffer->sbr, sd_new_addr (n, (char *) buf)); + sbr_xprepend_desc (&buffer->sbr, sd_new_addr (n, (const char *) buf)); } } } @@ -500,7 +500,7 @@ string_literal_accumulate_pieces (TSNode node, { string_desc_t subnode_string = sd_new_addr (ts_node_end_byte (subnode) - ts_node_start_byte (subnode), - (char *) contents + ts_node_start_byte (subnode)); + contents + ts_node_start_byte (subnode)); sbru_xprepend_desc (buffer, subnode_string); } else if (ts_node_symbol (subnode) == ts_symbol_escape_sequence) @@ -671,7 +671,7 @@ string_literal_value (TSNode node) that is non-empty and has no escape sequences. */ string_desc_t subnode_string = sd_new_addr (ts_node_end_byte (subnode) - ts_node_start_byte (subnode), - (char *) contents + ts_node_start_byte (subnode)); + contents + ts_node_start_byte (subnode)); return xsd_c (subnode_string); } } @@ -731,7 +731,7 @@ extract_from_function_call (TSNode callee_node, string_desc_t callee_name = sd_new_addr (ts_node_end_byte (callee_node) - ts_node_start_byte (callee_node), - (char *) contents + ts_node_start_byte (callee_node)); + contents + ts_node_start_byte (callee_node)); /* Context iterator. */ flag_context_list_iterator_ty next_context_iter = @@ -920,7 +920,7 @@ extract_from_node (TSNode node, { string_desc_t subnode_string = sd_new_addr (ts_node_end_byte (subnode) - ts_node_start_byte (subnode), - (char *) contents + ts_node_start_byte (subnode)); + contents + ts_node_start_byte (subnode)); if (sd_equals (subnode_string, sd_from_c ("gettext"))) { TSNode argsnode = ts_node_child_by_field_id (node, ts_field_arguments); diff --git a/gettext-tools/src/xg-encoding.c b/gettext-tools/src/xg-encoding.c index 148d8b382..08d3f8a32 100644 --- a/gettext-tools/src/xg-encoding.c +++ b/gettext-tools/src/xg-encoding.c @@ -184,8 +184,8 @@ from_current_source_encoding (const char *string, context.from_filename = file_name; context.message = NULL; - string = convert_string_directly (xgettext_current_source_iconv, string, - &context); + return convert_string_directly (xgettext_current_source_iconv, string, + &context); #else /* If we don't have iconv(), the only supported values for xgettext_global_source_encoding and thus also for @@ -199,7 +199,7 @@ from_current_source_encoding (const char *string, } /* Like from_current_source_encoding, for a string that may contain NULs. */ -string_desc_t +rw_string_desc_t string_desc_from_current_source_encoding (string_desc_t string, lexical_context_ty lcontext, const char *file_name, @@ -242,8 +242,8 @@ string_desc_from_current_source_encoding (string_desc_t string, context.from_filename = file_name; context.message = NULL; - string = convert_string_desc_directly (xgettext_current_source_iconv, - string, &context); + return convert_string_desc_directly (xgettext_current_source_iconv, + string, &context); #else /* If we don't have iconv(), the only supported values for xgettext_global_source_encoding and thus also for @@ -253,5 +253,5 @@ string_desc_from_current_source_encoding (string_desc_t string, #endif } - return string; + return sd_readwrite (string); } diff --git a/gettext-tools/src/xg-encoding.h b/gettext-tools/src/xg-encoding.h index 3991a1b98..81bc5e295 100644 --- a/gettext-tools/src/xg-encoding.h +++ b/gettext-tools/src/xg-encoding.h @@ -1,5 +1,5 @@ /* Keeping track of the encoding of strings to be extracted. - Copyright (C) 2001-2023 Free Software Foundation, Inc. + Copyright (C) 2001-2025 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -82,7 +82,7 @@ extern char *from_current_source_encoding (const char *string, size_t line_number); /* Like from_current_source_encoding, for a string that may contain NULs. */ -extern string_desc_t +extern rw_string_desc_t string_desc_from_current_source_encoding (string_desc_t string, lexical_context_ty lcontext, const char *file_name, -- 2.47.3