1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-21 10:26:06 +03:00

Replace ASM block w/C macro for PSTR (#6577)

* Replace ASM block w/C marco for PSTR

GAS doesn't support the C language idiom of catenating two strings
together with quotes (i.e. "x" "y" === "xy").

Specify the section attribute fully in the section attribute, instead,
to allow this.

* Fix WString optimization

PR #6573 introduced a corner case where a blind String() without any
initialization was in an in invalid state because the buffer and len
would not be updated properly.  Concatenating to the empty string could
cause a failure.

Now, set the default state in ::init() to SSO (which is what happened
before when we were using String(char *s="")) and fix the crash.
This commit is contained in:
Earle F. Philhower, III 2019-10-01 13:02:02 -07:00 committed by GitHub
parent 1aeea124b3
commit 215459fda4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 9 deletions

View File

@ -129,10 +129,9 @@ String::~String() {
// /*********************************************/ // /*********************************************/
inline void String::init(void) { inline void String::init(void) {
setSSO(false); setSSO(true);
setCapacity(0);
setLen(0); setLen(0);
setBuffer(nullptr); wbuffer()[0] = 0;
} }
void String::invalidate(void) { void String::invalidate(void) {

View File

@ -23,7 +23,6 @@ extern "C" {
// Ref: https://gcc.gnu.org/onlinedocs/gcc-3.2/gcc/Variable-Attributes.html // Ref: https://gcc.gnu.org/onlinedocs/gcc-3.2/gcc/Variable-Attributes.html
// Place each progmem object into its own named section, avoiding conflicts // Place each progmem object into its own named section, avoiding conflicts
#define PROGMEM __attribute__((section( "\".irom.text." __FILE__ "." __STRINGIZE(__LINE__) "." __STRINGIZE(__COUNTER__) "\""))) #define PROGMEM __attribute__((section( "\".irom.text." __FILE__ "." __STRINGIZE(__LINE__) "." __STRINGIZE(__COUNTER__) "\"")))
#define PROGMEM_PSTR "\".irom0.pstr." __FILE__ "." __STRINGIZE(__LINE__) "." __STRINGIZE(__COUNTER__) "\""
#endif #endif
#ifndef PGM_P #ifndef PGM_P
#define PGM_P const char * #define PGM_P const char *
@ -36,11 +35,8 @@ extern "C" {
// 1.5 bytes/string, but in return memcpy_P and strcpy_P will work 4~8x faster // 1.5 bytes/string, but in return memcpy_P and strcpy_P will work 4~8x faster
#ifndef PSTR #ifndef PSTR
// Adapted from AVR-specific code at https://forum.arduino.cc/index.php?topic=194603.0 // Adapted from AVR-specific code at https://forum.arduino.cc/index.php?topic=194603.0
#define PSTR(str) (__extension__({ \ // Uses C attribute section instead of ASM block to allow for C language string concatenation ("x" "y" === "xy")
PGM_P ptr; \ #define PSTR(s) (__extension__({static const char __c[] __attribute__((__aligned__(4))) __attribute__((section( "\".irom0.pstr." __FILE__ "." __STRINGIZE(__LINE__) "." __STRINGIZE(__COUNTER__) "\", \"aSM\", @progbits, 1 #"))) = (s); &__c[0];}))
asm volatile ( ".pushsection " PROGMEM_PSTR ", \"aSM\", @progbits, 1 \n .align 4 \n 0: .string " __STRINGIZE(str) "\n .popsection \n" ); \
asm volatile ( "movi %0, 0b" : "=r" (ptr) ); \
ptr; }))
#endif #endif
// Flash memory must be read using 32 bit aligned addresses else a processor // Flash memory must be read using 32 bit aligned addresses else a processor