mirror of
https://github.com/esphome/esphome.git
synced 2026-05-23 03:06:05 +08:00
[core] Move heap-allocating helpers to alloc_helpers.h/cpp (#15623)
This commit is contained in:
+15
-1
@@ -722,18 +722,22 @@ def lint_trailing_whitespace(fname, match):
|
||||
# Heap-allocating helpers that cause fragmentation on long-running embedded devices.
|
||||
# These return std::string and should be replaced with stack-based alternatives.
|
||||
HEAP_ALLOCATING_HELPERS = {
|
||||
"base64_encode": "base64_encode_to() with a pre-allocated buffer",
|
||||
"format_bin": "format_bin_to() with a stack buffer",
|
||||
"format_hex": "format_hex_to() with a stack buffer",
|
||||
"format_hex_pretty": "format_hex_pretty_to() with a stack buffer",
|
||||
"format_mac_address_pretty": "format_mac_addr_upper() with a stack buffer",
|
||||
"get_mac_address": "get_mac_address_into_buffer() with a stack buffer",
|
||||
"get_mac_address_pretty": "get_mac_address_pretty_into_buffer() with a stack buffer",
|
||||
"str_lower_case": "manual tolower() with a stack buffer",
|
||||
"str_sanitize": "str_sanitize_to() with a stack buffer",
|
||||
"str_truncate": "removal (function is unused)",
|
||||
"str_until": "manual strchr()/find() with a StringRef or stack buffer",
|
||||
"str_upper_case": "removal (function is unused)",
|
||||
"str_snake_case": "removal (function is unused)",
|
||||
"str_sprintf": "snprintf() with a stack buffer",
|
||||
"str_snprintf": "snprintf() with a stack buffer",
|
||||
"value_accuracy_to_string": "value_accuracy_to_buf() with a stack buffer",
|
||||
}
|
||||
|
||||
|
||||
@@ -743,24 +747,33 @@ HEAP_ALLOCATING_HELPERS = {
|
||||
# get_mac_address(?!_) ensures we don't match get_mac_address_into_buffer, etc.
|
||||
# CPP_RE_EOL captures rest of line so NOLINT comments are detected
|
||||
r"[^\w]("
|
||||
r"base64_encode(?!_)|"
|
||||
r"format_bin(?!_)|"
|
||||
r"format_hex(?!_)|"
|
||||
r"format_hex_pretty(?!_)|"
|
||||
r"format_mac_address_pretty|"
|
||||
r"get_mac_address_pretty(?!_)|"
|
||||
r"get_mac_address(?!_)|"
|
||||
r"str_lower_case|"
|
||||
r"str_sanitize(?!_)|"
|
||||
r"str_truncate|"
|
||||
r"str_until|"
|
||||
r"str_upper_case|"
|
||||
r"str_snake_case|"
|
||||
r"str_sprintf|"
|
||||
r"str_snprintf"
|
||||
r"str_snprintf|"
|
||||
r"value_accuracy_to_string"
|
||||
r")\s*\(" + CPP_RE_EOL,
|
||||
include=cpp_include,
|
||||
exclude=[
|
||||
# The definitions themselves
|
||||
"esphome/core/alloc_helpers.h",
|
||||
"esphome/core/alloc_helpers.cpp",
|
||||
# Backward compatibility re-exports (remove before 2026.11.0)
|
||||
"esphome/core/helpers.h",
|
||||
"esphome/core/helpers.cpp",
|
||||
# Vendored third-party library
|
||||
"esphome/components/http_request/httplib.h",
|
||||
],
|
||||
)
|
||||
def lint_no_heap_allocating_helpers(fname, match):
|
||||
@@ -812,6 +825,7 @@ def lint_no_sprintf(fname, match):
|
||||
"esphome/components/http_request/httplib.h",
|
||||
# Deprecated helpers that return std::string
|
||||
"esphome/core/helpers.cpp",
|
||||
"esphome/core/alloc_helpers.cpp",
|
||||
# The using declaration itself
|
||||
"esphome/core/helpers.h",
|
||||
# Test fixtures - not production embedded code
|
||||
|
||||
Reference in New Issue
Block a user