Dump progmem strings straight into the dump buffer, assert the scratch define is gone

This commit is contained in:
J. Nick Koston
2026-10-08 21:34:31 -10:00
parent 8378c935d6
commit 40460f3e01
3 changed files with 12 additions and 6 deletions
+5 -3
View File
@@ -135,11 +135,13 @@ static void dump_progmem_bytes_field(DumpBuffer &out, const char *field_name, co
dump_bytes_field(out, field_name, data_buf, len, indent);
}
// Helper for string fields in flash: copies the shown characters out with progmem_memcpy first
// Helper for string fields in flash: copies straight into the dump buffer, which bounds the length
static void dump_progmem_string_field(DumpBuffer &out, const char *field_name, const ProgmemStringRef &value,
int indent = 2) {
char buf[DUMP_BYTES_MAX];
dump_field(out, field_name, StringRef(buf, value.write_to(buf, sizeof(buf))), indent);
append_field_prefix(out, field_name, indent);
out.append("'");
out.set_pos(out.pos() + value.write_to(out.data() + out.pos(), DumpBuffer::CAPACITY - out.pos()));
out.append("'\n");
}
#pragma GCC diagnostic pop
+5 -3
View File
@@ -3391,11 +3391,13 @@ static void dump_progmem_bytes_field(DumpBuffer &out, const char *field_name, co
dump_bytes_field(out, field_name, data_buf, len, indent);
}
// Helper for string fields in flash: copies the shown characters out with progmem_memcpy first
// Helper for string fields in flash: copies straight into the dump buffer, which bounds the length
static void dump_progmem_string_field(DumpBuffer &out, const char *field_name, const ProgmemStringRef &value,
int indent = 2) {
char buf[DUMP_BYTES_MAX];
dump_field(out, field_name, StringRef(buf, value.write_to(buf, sizeof(buf))), indent);
append_field_prefix(out, field_name, indent);
out.append("'");
out.set_pos(out.pos() + value.write_to(out.data() + out.pos(), DumpBuffer::CAPACITY - out.pos()));
out.append("'\\n");
}
#pragma GCC diagnostic pop
@@ -14,6 +14,7 @@ from esphome.config_validation import Invalid
from esphome.core import CORE
from esphome.cpp_generator import safe_exp
from esphome.helpers import fnv1_hash
from tests.component_tests.helpers import get_define_value
CONFIG = "tests/component_tests/api/test_action_metadata.yaml"
CONFIG_ESP8266 = "tests/component_tests/api/test_action_metadata_esp8266.yaml"
@@ -58,6 +59,7 @@ def test_esp8266_encodes_action_strings_from_flash(
main_cpp = generate_main(CONFIG_ESP8266)
assert "api_action0_strings[] PROGMEM" in main_cpp
assert get_define_value("API_USER_ACTION_STRINGS_SCRATCH_SIZE") is None
def test_shorthand_variables_emit_no_metadata(