Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b98255d

Browse filesBrowse files
authored
Completely inline the helper pure abstract __FlashStringHelper class (espressif#7941)
* Remove __FlashStringHelper from ESP32, it's not needed - all the files using it are different from their ESP8266 counterparts anyway. * Revert removal of class __FlashStringHelper forward for continued compatibility with external libs * Improved fix, works for libs that return const __FlashStringHelper* * Inline all wrappers using const __FlashStringHelper*.
1 parent 087ebe0 commit b98255d
Copy full SHA for b98255d

File tree

Expand file treeCollapse file tree

5 files changed

+26
-82
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+26
-82
lines changed

‎cores/esp32/Print.cpp

Copy file name to clipboardExpand all lines: cores/esp32/Print.cpp
-12Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,6 @@ size_t Print::printf(const char *format, ...)
7474
return len;
7575
}
7676

77-
size_t Print::print(const __FlashStringHelper *ifsh)
78-
{
79-
return print(reinterpret_cast<const char *>(ifsh));
80-
}
81-
8277
size_t Print::print(const String &s)
8378
{
8479
return write(s.c_str(), s.length());
@@ -152,13 +147,6 @@ size_t Print::print(double n, int digits)
152147
return printFloat(n, digits);
153148
}
154149

155-
size_t Print::println(const __FlashStringHelper *ifsh)
156-
{
157-
size_t n = print(ifsh);
158-
n += println();
159-
return n;
160-
}
161-
162150
size_t Print::print(const Printable& x)
163151
{
164152
return x.printTo(*this);

‎cores/esp32/Print.h

Copy file name to clipboardExpand all lines: cores/esp32/Print.h
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class Print
7878
// default to zero, meaning "a single write may block"
7979
// should be overriden by subclasses with buffering
8080
virtual int availableForWrite() { return 0; }
81-
size_t print(const __FlashStringHelper *);
81+
size_t print(const __FlashStringHelper *ifsh) { return print(reinterpret_cast<const char *>(ifsh)); }
8282
size_t print(const String &);
8383
size_t print(const char[]);
8484
size_t print(char);
@@ -93,7 +93,7 @@ class Print
9393
size_t print(const Printable&);
9494
size_t print(struct tm * timeinfo, const char * format = NULL);
9595

96-
size_t println(const __FlashStringHelper *);
96+
size_t println(const __FlashStringHelper *ifsh) { return println(reinterpret_cast<const char *>(ifsh)); }
9797
size_t println(const String &s);
9898
size_t println(const char[]);
9999
size_t println(char);

‎cores/esp32/WString.cpp

Copy file name to clipboardExpand all lines: cores/esp32/WString.cpp
-46Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ String::String(const String &value) {
4747
*this = value;
4848
}
4949

50-
String::String(const __FlashStringHelper *pstr) {
51-
init();
52-
*this = pstr; // see operator =
53-
}
54-
5550
#ifdef __GXX_EXPERIMENTAL_CXX0X__
5651
String::String(String &&rval) {
5752
init();
@@ -235,16 +230,6 @@ String & String::copy(const char *cstr, unsigned int length) {
235230
return *this;
236231
}
237232

238-
String & String::copy(const __FlashStringHelper *pstr, unsigned int length) {
239-
if (!reserve(length)) {
240-
invalidate();
241-
return *this;
242-
}
243-
memcpy_P(wbuffer(), (PGM_P)pstr, length + 1); // We know wbuffer() cannot ever be in PROGMEM, so memcpy safe here
244-
setLen(length);
245-
return *this;
246-
}
247-
248233
#ifdef __GXX_EXPERIMENTAL_CXX0X__
249234
void String::move(String &rhs) {
250235
if(buffer()) {
@@ -308,15 +293,6 @@ String & String::operator =(const char *cstr) {
308293
return *this;
309294
}
310295

311-
String & String::operator =(const __FlashStringHelper *pstr) {
312-
if(pstr)
313-
copy(pstr, strlen_P((PGM_P)pstr));
314-
else
315-
invalidate();
316-
317-
return *this;
318-
}
319-
320296
/*********************************************/
321297
/* concat */
322298
/*********************************************/
@@ -424,20 +400,6 @@ bool String::concat(double num) {
424400
return concat(string, strlen(string));
425401
}
426402

427-
bool String::concat(const __FlashStringHelper * str) {
428-
if (!str)
429-
return false;
430-
int length = strlen_P((PGM_P)str);
431-
if (length == 0)
432-
return true;
433-
unsigned int newlen = len() + length;
434-
if (!reserve(newlen))
435-
return false;
436-
memcpy_P(wbuffer() + len(), (PGM_P)str, length + 1);
437-
setLen(newlen);
438-
return true;
439-
}
440-
441403
/*********************************************/
442404
/* Concatenate */
443405
/*********************************************/
@@ -526,14 +488,6 @@ StringSumHelper & operator +(const StringSumHelper &lhs, unsigned long long num)
526488
return a;
527489
}
528490

529-
StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHelper *rhs)
530-
{
531-
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
532-
if (!a.concat(rhs))
533-
a.invalidate();
534-
return a;
535-
}
536-
537491
/*********************************************/
538492
/* Comparison */
539493
/*********************************************/

‎cores/esp32/WString.h

Copy file name to clipboardExpand all lines: cores/esp32/WString.h
+23-21Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
#include <ctype.h>
3232

3333

34-
// an abstract class used as a means to proide a unique pointer type
35-
// but really has no body
34+
// A pure abstract class forward used as a means to proide a unique pointer type
35+
// but really is never defined.
3636
class __FlashStringHelper;
37-
#define FPSTR(pstr_pointer) (reinterpret_cast<const __FlashStringHelper *>(pstr_pointer))
38-
#define F(string_literal) (FPSTR(PSTR(string_literal)))
37+
#define FPSTR(pstr_pointer) (pstr_pointer)
38+
#define F(string_literal) (string_literal)
3939

4040
// An inherited class for holding the result of a concatenation. These
4141
// result objects are assumed to be writable by subsequent concatenations.
@@ -59,10 +59,10 @@ class String {
5959
String(const char *cstr = "");
6060
String(const char *cstr, unsigned int length);
6161
#ifdef __GXX_EXPERIMENTAL_CXX0X__
62-
String(const uint8_t *cstr, unsigned int length) : String((const char*)cstr, length) {}
62+
String(const uint8_t *cstr, unsigned int length) : String(reinterpret_cast<const char*>(cstr), length) {}
6363
#endif
6464
String(const String &str);
65-
String(const __FlashStringHelper *str);
65+
String(const __FlashStringHelper *str) : String(reinterpret_cast<const char*>(str)) {}
6666
#ifdef __GXX_EXPERIMENTAL_CXX0X__
6767
String(String &&rval);
6868
String(StringSumHelper &&rval);
@@ -103,7 +103,7 @@ class String {
103103
// marked as invalid ("if (s)" will be false).
104104
String & operator =(const String &rhs);
105105
String & operator =(const char *cstr);
106-
String & operator = (const __FlashStringHelper *str);
106+
String & operator = (const __FlashStringHelper *str) {return *this = reinterpret_cast<const char*>(str);}
107107
#ifdef __GXX_EXPERIMENTAL_CXX0X__
108108
String & operator =(String &&rval);
109109
String & operator =(StringSumHelper &&rval);
@@ -117,7 +117,7 @@ class String {
117117
bool concat(const String &str);
118118
bool concat(const char *cstr);
119119
bool concat(const char *cstr, unsigned int length);
120-
bool concat(const uint8_t *cstr, unsigned int length) {return concat((const char*)cstr, length);}
120+
bool concat(const uint8_t *cstr, unsigned int length) {return concat(reinterpret_cast<const char*>(cstr), length);}
121121
bool concat(char c);
122122
bool concat(unsigned char c);
123123
bool concat(int num);
@@ -128,7 +128,7 @@ class String {
128128
bool concat(double num);
129129
bool concat(long long num);
130130
bool concat(unsigned long long num);
131-
bool concat(const __FlashStringHelper * str);
131+
bool concat(const __FlashStringHelper * str) {return concat(reinterpret_cast<const char*>(str));}
132132

133133
// if there's not enough memory for the concatenated value, the string
134134
// will be left unchanged (but this isn't signalled in any way)
@@ -180,10 +180,7 @@ class String {
180180
concat(num);
181181
return (*this);
182182
}
183-
String & operator += (const __FlashStringHelper *str){
184-
concat(str);
185-
return (*this);
186-
}
183+
String & operator += (const __FlashStringHelper *str) {return *this += reinterpret_cast<const char*>(str);}
187184

188185
friend StringSumHelper & operator +(const StringSumHelper &lhs, const String &rhs);
189186
friend StringSumHelper & operator +(const StringSumHelper &lhs, const char *cstr);
@@ -195,7 +192,6 @@ class String {
195192
friend StringSumHelper & operator +(const StringSumHelper &lhs, unsigned long num);
196193
friend StringSumHelper & operator +(const StringSumHelper &lhs, float num);
197194
friend StringSumHelper & operator +(const StringSumHelper &lhs, double num);
198-
friend StringSumHelper & operator +(const StringSumHelper &lhs, const __FlashStringHelper *rhs);
199195
friend StringSumHelper & operator +(const StringSumHelper &lhs, long long num);
200196
friend StringSumHelper & operator +(const StringSumHelper &lhs, unsigned long long num);
201197

@@ -229,15 +225,15 @@ class String {
229225
return this->startsWith(String(prefix));
230226
}
231227
bool startsWith(const __FlashStringHelper *prefix) const {
232-
return this->startsWith(String(prefix));
228+
return this->startsWith(reinterpret_cast<const char*>(prefix));
233229
}
234230
bool startsWith(const String &prefix, unsigned int offset) const;
235231
bool endsWith(const String &suffix) const;
236232
bool endsWith(const char *suffix) const {
237233
return this->endsWith(String(suffix));
238234
}
239235
bool endsWith(const __FlashStringHelper * suffix) const {
240-
return this->endsWith(String(suffix));
236+
return this->endsWith(reinterpret_cast<const char*>(suffix));
241237
}
242238

243239
// character access
@@ -276,16 +272,16 @@ class String {
276272
this->replace(String(find), replace);
277273
}
278274
void replace(const __FlashStringHelper *find, const String &replace) {
279-
this->replace(String(find), replace);
275+
this->replace(reinterpret_cast<const char*>(find), replace);
280276
}
281277
void replace(const char *find, const char *replace) {
282278
this->replace(String(find), String(replace));
283279
}
284280
void replace(const __FlashStringHelper *find, const char *replace) {
285-
this->replace(String(find), String(replace));
281+
this->replace(reinterpret_cast<const char*>(find), String(replace));
286282
}
287283
void replace(const __FlashStringHelper *find, const __FlashStringHelper *replace) {
288-
this->replace(String(find), String(replace));
284+
this->replace(reinterpret_cast<const char*>(find), reinterpret_cast<const char*>(replace));
289285
}
290286
void remove(unsigned int index);
291287
void remove(unsigned int index, unsigned int count);
@@ -340,7 +336,7 @@ class String {
340336
inline void setCapacity(int cap) { if (!isSSO()) ptr.cap = cap; }
341337
inline void setBuffer(char *buff) { if (!isSSO()) ptr.buff = buff; }
342338
// Buffer accessor functions
343-
inline const char *buffer() const { return (const char *)(isSSO() ? sso.buff : ptr.buff); }
339+
inline const char *buffer() const { return reinterpret_cast<const char *>(isSSO() ? sso.buff : ptr.buff); }
344340
inline char *wbuffer() const { return isSSO() ? const_cast<char *>(sso.buff) : ptr.buff; } // Writable version of buffer
345341

346342
protected:
@@ -350,7 +346,9 @@ class String {
350346

351347
// copy and move
352348
String & copy(const char *cstr, unsigned int length);
353-
String & copy(const __FlashStringHelper *pstr, unsigned int length);
349+
String & copy(const __FlashStringHelper *pstr, unsigned int length) {
350+
return copy(reinterpret_cast<const char*>(pstr), length);
351+
}
354352
#ifdef __GXX_EXPERIMENTAL_CXX0X__
355353
void move(String &rhs);
356354
#endif
@@ -395,6 +393,10 @@ class StringSumHelper: public String {
395393
String(num) {
396394
}
397395
};
396+
397+
inline StringSumHelper & operator +(const StringSumHelper &lhs, const __FlashStringHelper *rhs) {
398+
return lhs + reinterpret_cast<const char*>(rhs);
399+
}
398400

399401
extern const String emptyString;
400402

‎libraries/WebServer/src/Uri.h

Copy file name to clipboardExpand all lines: libraries/WebServer/src/Uri.h
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Uri {
1212
public:
1313
Uri(const char *uri) : _uri(uri) {}
1414
Uri(const String &uri) : _uri(uri) {}
15-
Uri(const __FlashStringHelper *uri) : _uri(String(uri)) {}
15+
Uri(const __FlashStringHelper *uri) : _uri((const char *)uri) {}
1616
virtual ~Uri() {}
1717

1818
virtual Uri* clone() const {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.