Skip to content

Commit b1837bf

Browse files
authored
Merge pull request esp8266#15 from esp8266/master
memmove_P
2 parents 30627b7 + 8dd068e commit b1837bf

File tree

11 files changed

+68
-40
lines changed

11 files changed

+68
-40
lines changed

cores/esp8266/StreamString.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ size_t StreamString::write(const uint8_t *data, size_t size) {
3232
*(wbuffer() + newlen) = 0x00; // add null for string end
3333
return size;
3434
}
35+
DEBUGV(":stream2string: OOM (%d->%d)\n", length(), newlen+1);
3536
}
3637
return 0;
3738
}

cores/esp8266/WString.cpp

+14-19
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ unsigned char String::changeBuffer(unsigned int maxStrLen) {
185185
size_t oldSize = capacity() + 1; // include NULL.
186186
if (isSSO()) {
187187
// Copy the SSO buffer into allocated space
188-
memmove(newbuffer, sso.buff, sizeof(sso.buff));
188+
memmove_P(newbuffer, sso.buff, sizeof(sso.buff));
189189
}
190190
if (newSize > oldSize)
191191
{
@@ -210,7 +210,7 @@ String & String::copy(const char *cstr, unsigned int length) {
210210
return *this;
211211
}
212212
setLen(length);
213-
memmove(wbuffer(), cstr, length + 1);
213+
memmove_P(wbuffer(), cstr, length + 1);
214214
return *this;
215215
}
216216

@@ -228,7 +228,7 @@ String & String::copy(const __FlashStringHelper *pstr, unsigned int length) {
228228
void String::move(String &rhs) {
229229
if(buffer()) {
230230
if(capacity() >= rhs.len()) {
231-
memmove(wbuffer(), rhs.buffer(), rhs.length() + 1);
231+
memmove_P(wbuffer(), rhs.buffer(), rhs.length() + 1);
232232
setLen(rhs.len());
233233
rhs.invalidate();
234234
return;
@@ -241,7 +241,7 @@ void String::move(String &rhs) {
241241
}
242242
if (rhs.isSSO()) {
243243
setSSO(true);
244-
memmove(sso.buff, rhs.sso.buff, sizeof(sso.buff));
244+
memmove_P(sso.buff, rhs.sso.buff, sizeof(sso.buff));
245245
} else {
246246
setSSO(false);
247247
setBuffer(rhs.wbuffer());
@@ -313,7 +313,7 @@ unsigned char String::concat(const String &s) {
313313
return 1;
314314
if (!reserve(newlen))
315315
return 0;
316-
memmove(wbuffer() + len(), buffer(), len());
316+
memmove_P(wbuffer() + len(), buffer(), len());
317317
setLen(newlen);
318318
wbuffer()[len()] = 0;
319319
return 1;
@@ -330,12 +330,7 @@ unsigned char String::concat(const char *cstr, unsigned int length) {
330330
return 1;
331331
if(!reserve(newlen))
332332
return 0;
333-
if (cstr >= wbuffer() && cstr < wbuffer() + len())
334-
// compatible with SSO in ram #6155 (case "x += x.c_str()")
335-
memmove(wbuffer() + len(), cstr, length + 1);
336-
else
337-
// compatible with source in flash #6367
338-
memcpy_P(wbuffer() + len(), cstr, length + 1);
333+
memmove_P(wbuffer() + len(), cstr, length + 1);
339334
setLen(newlen);
340335
return 1;
341336
}
@@ -739,21 +734,21 @@ void String::replace(const String& find, const String& replace) {
739734
char *foundAt;
740735
if(diff == 0) {
741736
while((foundAt = strstr(readFrom, find.buffer())) != NULL) {
742-
memmove(foundAt, replace.buffer(), replace.len());
737+
memmove_P(foundAt, replace.buffer(), replace.len());
743738
readFrom = foundAt + replace.len();
744739
}
745740
} else if(diff < 0) {
746741
char *writeTo = wbuffer();
747742
while((foundAt = strstr(readFrom, find.buffer())) != NULL) {
748743
unsigned int n = foundAt - readFrom;
749-
memmove(writeTo, readFrom, n);
744+
memmove_P(writeTo, readFrom, n);
750745
writeTo += n;
751-
memmove(writeTo, replace.buffer(), replace.len());
746+
memmove_P(writeTo, replace.buffer(), replace.len());
752747
writeTo += replace.len();
753748
readFrom = foundAt + find.len();
754749
setLen(len() + diff);
755750
}
756-
memmove(writeTo, readFrom, strlen(readFrom)+1);
751+
memmove_P(writeTo, readFrom, strlen(readFrom)+1);
757752
} else {
758753
unsigned int size = len(); // compute size needed for result
759754
while((foundAt = strstr(readFrom, find.buffer())) != NULL) {
@@ -767,9 +762,9 @@ void String::replace(const String& find, const String& replace) {
767762
int index = len() - 1;
768763
while(index >= 0 && (index = lastIndexOf(find, index)) >= 0) {
769764
readFrom = wbuffer() + index + find.len();
770-
memmove(readFrom + diff, readFrom, len() - (readFrom - buffer()));
765+
memmove_P(readFrom + diff, readFrom, len() - (readFrom - buffer()));
771766
int newLen = len() + diff;
772-
memmove(wbuffer() + index, replace.buffer(), replace.len());
767+
memmove_P(wbuffer() + index, replace.buffer(), replace.len());
773768
setLen(newLen);
774769
wbuffer()[newLen] = 0;
775770
index--;
@@ -797,7 +792,7 @@ void String::remove(unsigned int index, unsigned int count) {
797792
char *writeTo = wbuffer() + index;
798793
unsigned int newlen = len() - count;
799794
setLen(newlen);
800-
memmove(writeTo, wbuffer() + index + count, newlen - index);
795+
memmove_P(writeTo, wbuffer() + index + count, newlen - index);
801796
wbuffer()[newlen] = 0;
802797
}
803798

@@ -829,7 +824,7 @@ void String::trim(void) {
829824
unsigned int newlen = end + 1 - begin;
830825
setLen(newlen);
831826
if(begin > buffer())
832-
memmove(wbuffer(), begin, newlen);
827+
memmove_P(wbuffer(), begin, newlen);
833828
wbuffer()[newlen] = 0;
834829
}
835830

libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ const String& HTTPClient::getString(void)
10071007

10081008
_payload.reset(new StreamString());
10091009

1010-
if(_size) {
1010+
if(_size > 0) {
10111011
// try to reserve needed memmory
10121012
if(!_payload->reserve((_size + 1))) {
10131013
DEBUG_HTTPCLIENT("[HTTP-Client][getString] not enough memory to reserve a string! need: %d\n", (_size + 1));
@@ -1456,10 +1456,10 @@ int HTTPClient::writeToStreamDataBlock(Stream * stream, int size)
14561456

14571457
free(buff);
14581458

1459-
DEBUG_HTTPCLIENT("[HTTP-Client][writeToStreamDataBlock] connection closed or file end (written: %d).\n", bytesWritten);
1459+
DEBUG_HTTPCLIENT("[HTTP-Client][writeToStreamDataBlock] end of chunk or data (transferred: %d).\n", bytesWritten);
14601460

14611461
if((size > 0) && (size != bytesWritten)) {
1462-
DEBUG_HTTPCLIENT("[HTTP-Client][writeToStreamDataBlock] bytesWritten %d and size %d mismatch!.\n", bytesWritten, size);
1462+
DEBUG_HTTPCLIENT("[HTTP-Client][writeToStreamDataBlock] transferred size %d and request size %d mismatch!.\n", bytesWritten, size);
14631463
return HTTPC_ERROR_STREAM_WRITE;
14641464
}
14651465

package/package_esp8266com_index.template.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
"tools": [
139139
{
140140
"version": "3.7.2-post1",
141-
"name": "python",
141+
"name": "python3",
142142
"systems": [
143143
{
144144
"host": "x86_64-mingw32",

platform.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ compiler.elf2hex.extra_flags=
8585
## generate file with git version number
8686
## needs git
8787
recipe.hooks.sketch.prebuild.pattern="{runtime.tools.python3.path}/python3" "{runtime.tools.signing}" --mode header --publickey "{build.source.path}/public.key" --out "{build.path}/core/Updater_Signing.h"
88-
recipe.hooks.core.prebuild.pattern="{runtime.tools.python3.path}/python3" "{runtime.tools.makecorever}" --build_path "{build.path}" --platform_path "{runtime.platform.path}" --version "unix-{version}"
88+
# This is quite a working hack. This form of prebuild hook, while intuitive, is not explicitly documented.
89+
recipe.hooks.prebuild.10.pattern="{runtime.tools.python3.path}/python3" "{runtime.tools.makecorever}" --build_path "{build.path}" --platform_path "{runtime.platform.path}" --version "unix-{version}"
8990

9091
## Build the app.ld linker file
9192
recipe.hooks.linking.prelink.1.pattern="{compiler.path}{compiler.c.cmd}" -CC -E -P {build.vtable_flags} "{runtime.platform.path}/tools/sdk/ld/eagle.app.v6.common.ld.h" -o "{build.path}/local.eagle.app.v6.common.ld"

tests/host/common/ArduinoMain.cpp

+18-13
Original file line numberDiff line numberDiff line change
@@ -129,24 +129,26 @@ void help (const char* argv0, int exitcode)
129129
" -b - blocking tty/mocked-uart (default: not blocking tty)\n"
130130
" -S - spiffs size in KBytes (default: %zd)\n"
131131
" -L - littlefs size in KBytes (default: %zd)\n"
132-
" -v - mock verbose\n"
133-
" (negative value will force mismatched size)\n"
132+
"\t (spiffs, littlefs: negative value will force mismatched size)\n"
133+
" -T - show timestamp on output\n"
134+
" -v - verbose\n"
134135
, argv0, MOCK_PORT_SHIFTER, spiffs_kb, littlefs_kb);
135136
exit(exitcode);
136137
}
137138

138139
static struct option options[] =
139140
{
140-
{ "help", no_argument, NULL, 'h' },
141-
{ "fast", no_argument, NULL, 'f' },
142-
{ "local", no_argument, NULL, 'l' },
143-
{ "sigint", no_argument, NULL, 'c' },
144-
{ "blockinguart", no_argument, NULL, 'b' },
145-
{ "verbose", no_argument, NULL, 'v' },
146-
{ "interface", required_argument, NULL, 'i' },
147-
{ "spiffskb", required_argument, NULL, 'S' },
148-
{ "littlefskb", required_argument, NULL, 'L' },
149-
{ "portshifter", required_argument, NULL, 's' },
141+
{ "help", no_argument, NULL, 'h' },
142+
{ "fast", no_argument, NULL, 'f' },
143+
{ "local", no_argument, NULL, 'l' },
144+
{ "sigint", no_argument, NULL, 'c' },
145+
{ "blockinguart", no_argument, NULL, 'b' },
146+
{ "verbose", no_argument, NULL, 'v' },
147+
{ "timestamp", no_argument, NULL, 'T' },
148+
{ "interface", required_argument, NULL, 'i' },
149+
{ "spiffskb", required_argument, NULL, 'S' },
150+
{ "littlefskb", required_argument, NULL, 'L' },
151+
{ "portshifter", required_argument, NULL, 's' },
150152
};
151153

152154
void cleanup ()
@@ -182,7 +184,7 @@ int main (int argc, char* const argv [])
182184

183185
for (;;)
184186
{
185-
int n = getopt_long(argc, argv, "hlcfbvi:S:s:L:", options, NULL);
187+
int n = getopt_long(argc, argv, "hlcfbvTi:S:s:L:", options, NULL);
186188
if (n < 0)
187189
break;
188190
switch (n)
@@ -217,6 +219,9 @@ int main (int argc, char* const argv [])
217219
case 'v':
218220
mockdebug = true;
219221
break;
222+
case 'T':
223+
serial_timestamp = true;
224+
break;
220225
default:
221226
help(argv[0], EXIT_FAILURE);
222227
}

tests/host/common/MockUART.cpp

+26-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
*/
3030

3131
#include <unistd.h> // write
32+
#include <sys/time.h> // gettimeofday
33+
#include <time.h> // localtime
3234

3335
#include "Arduino.h"
3436
#include "uart.h"
@@ -59,13 +61,35 @@ struct uart_
5961
struct uart_rx_buffer_ * rx_buffer;
6062
};
6163

64+
bool serial_timestamp = false;
65+
6266
// write one byte to the emulated UART
6367
static void
6468
uart_do_write_char(const int uart_nr, char c)
6569
{
70+
static bool w = false;
71+
6672
if (uart_nr >= UART0 && uart_nr <= UART1)
67-
if (1 != write(uart_nr + 1, &c, 1))
68-
fprintf(stderr, "Unable to write character to emulated UART stream: %d\n", c);
73+
{
74+
if (serial_timestamp && (c == '\n' || c == '\r'))
75+
{
76+
if (w)
77+
{
78+
FILE* out = uart_nr == UART0? stdout: stderr;
79+
timeval tv;
80+
gettimeofday(&tv, nullptr);
81+
const tm* tm = localtime(&tv.tv_sec);
82+
fprintf(out, "\r\n%d:%02d:%02d.%06d: ", tm->tm_hour, tm->tm_min, tm->tm_sec, (int)tv.tv_usec);
83+
fflush(out);
84+
w = false;
85+
}
86+
}
87+
else
88+
{
89+
write(uart_nr + 1, &c, 1);
90+
w = true;
91+
}
92+
}
6993
}
7094

7195
// write a new byte into the RX FIFO buffer

tests/host/common/mock.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ int ets_printf (const char* fmt, ...) __attribute__ ((format (printf, 1, 2)));
8585
int mockverbose (const char* fmt, ...) __attribute__ ((format (printf, 1, 2)));
8686

8787
extern const char* host_interface; // cmdline parameter
88-
88+
extern bool serial_timestamp;
8989
extern int mock_port_shifter;
9090

9191
#define NO_GLOBAL_BINDING 0xffffffff

tests/host/sys/pgmspace.h

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ inline size_t strlen_P(const char *s) { return strlen(s); }
6060
inline int vsnprintf_P(char *str, size_t size, const char *format, va_list ap) { return vsnprintf(str, size, format, ap); }
6161

6262
#define memcpy_P memcpy
63+
#define memmove_P memmove
6364
#define strncpy_P strncpy
6465
#define strcmp_P strcmp
6566
#define memccpy_P memccpy

tools/sdk/libc/xtensa-lx106-elf/include/sys/string.h

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ extern "C" {
2525
int _EXFUN(memcmp_P,(const _PTR, const _PTR, size_t));
2626
_PTR _EXFUN(memmem_P, (const _PTR, size_t, const _PTR, size_t));
2727
_PTR _EXFUN(memcpy_P,(_PTR __restrict, const _PTR __restrict, size_t));
28+
_PTR _EXFUN(memmove_P,(_PTR __restrict, const _PTR __restrict, size_t));
2829
_PTR _EXFUN(memccpy_P,(_PTR __restrict, const _PTR __restrict, int, size_t));
2930
_PTR _EXFUN(memchr_P,(const _PTR, int, size_t));
3031

1.24 KB
Binary file not shown.

0 commit comments

Comments
 (0)