Skip to content

Commit bd24fc2

Browse files
Merge branch 'master' into ssdp-fixes
2 parents c8d855c + 5cec334 commit bd24fc2

File tree

7 files changed

+113
-93
lines changed

7 files changed

+113
-93
lines changed

cores/esp8266/Esp.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -466,15 +466,7 @@ bool EspClass::updateSketch(Stream& in, uint32_t size, bool restartOnFail, bool
466466
return true;
467467
}
468468

469-
// Interrupts which are masked by flash access routines
470-
static const int FLASH_INT_MASK =
471-
(1 << ETS_SLC_INUM) |
472-
(1 << ETS_SPI_INUM) |
473-
(1 << ETS_GPIO_INUM) |
474-
(1 << ETS_UART_INUM) |
475-
(1 << ETS_CCOMPARE0_INUM) |
476-
(1 << ETS_FRC_TIMER1_INUM);
477-
469+
static const int FLASH_INT_MASK = ((B10 << 8) | B00111010);
478470

479471
bool EspClass::flashEraseSector(uint32_t sector) {
480472
ets_isr_mask(FLASH_INT_MASK);

cores/esp8266/pgmspace.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
*/
1919

2020
#include <ctype.h>
21+
#include <stdint.h>
22+
#include <stddef.h>
23+
#include <stdbool.h>
24+
#include <stdarg.h>
2125
#include "pgmspace.h"
2226

2327
size_t strnlen_P(PGM_P s, size_t size) {
@@ -26,6 +30,33 @@ size_t strnlen_P(PGM_P s, size_t size) {
2630
return (size_t) (cp - s);
2731
}
2832

33+
char* strstr_P(const char* haystack, PGM_P needle)
34+
{
35+
const char* pn = reinterpret_cast<const char*>(needle);
36+
if (haystack[0] == 0) {
37+
if (pgm_read_byte(pn)) {
38+
return NULL;
39+
}
40+
return (char*) haystack;
41+
}
42+
43+
while (*haystack) {
44+
size_t i = 0;
45+
while (true) {
46+
char n = pgm_read_byte(pn + i);
47+
if (n == 0) {
48+
return (char *) haystack;
49+
}
50+
if (n != haystack[i]) {
51+
break;
52+
}
53+
++i;
54+
}
55+
++haystack;
56+
}
57+
return NULL;
58+
}
59+
2960
void* memcpy_P(void* dest, PGM_VOID_P src, size_t count) {
3061
const uint8_t* read = reinterpret_cast<const uint8_t*>(src);
3162
uint8_t* write = reinterpret_cast<uint8_t*>(dest);
@@ -203,7 +234,7 @@ int printf_P(PGM_P formatP, ...) {
203234
char* format = new char[fmtLen + 1];
204235
strcpy_P(format, formatP);
205236

206-
ret = os_printf(format, arglist);
237+
ret = printf(format, arglist);
207238

208239
delete[] format;
209240

@@ -240,7 +271,7 @@ int vsnprintf_P(char* str, size_t strSize, PGM_P formatP, va_list ap) {
240271
char* format = new char[fmtLen + 1];
241272
strcpy_P(format, formatP);
242273

243-
ret = ets_vsnprintf(str, strSize, format, ap);
274+
ret = vsnprintf(str, strSize, format, ap);
244275

245276
delete[] format;
246277

cores/esp8266/pgmspace.h

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#ifndef __PGMSPACE_H_
22
#define __PGMSPACE_H_
33

4+
#include <stdint.h>
5+
#include <stdio.h>
6+
7+
#ifdef __ets__
8+
49
#ifdef __cplusplus
510
extern "C" {
611
#endif
7-
#include <stdint.h>
8-
#include <stdio.h>
912
#include "ets_sys.h"
1013
#include "osapi.h"
1114
#ifdef __cplusplus
@@ -16,6 +19,13 @@ extern "C" {
1619
#define PGM_P const char *
1720
#define PGM_VOID_P const void *
1821
#define PSTR(s) (__extension__({static const char __c[] PROGMEM = (s); &__c[0];}))
22+
#else //__ets__
23+
#define PROGMEM
24+
#define PGM_P const char *
25+
#define PGM_VOID_P const void *
26+
#define PSTR(s) (s)
27+
28+
#endif // __ets__
1929

2030

2131
#define _SFR_BYTE(n) (n)
@@ -62,6 +72,8 @@ int strncasecmp_P(const char* str1, PGM_P str2P, size_t size);
6272
size_t strnlen_P(PGM_P s, size_t size);
6373
#define strlen_P(strP) strnlen_P((strP), SIZE_IRRELEVANT)
6474

75+
char* strstr_P(const char* haystack, PGM_P needle);
76+
6577
int printf_P(PGM_P formatP, ...) __attribute__((format(printf, 1, 2)));
6678
int sprintf_P(char *str, PGM_P formatP, ...) __attribute__((format(printf, 2, 3)));
6779
int snprintf_P(char *str, size_t strSize, PGM_P formatP, ...) __attribute__((format(printf, 3, 4)));
@@ -74,6 +86,7 @@ int vsnprintf_P(char *str, size_t strSize, PGM_P formatP, va_list ap) __attribut
7486
// b3, b2, b1, b0
7587
// w1, w0
7688

89+
#ifdef __ets__
7790
#define pgm_read_byte(addr) \
7891
(__extension__({ \
7992
PGM_P __local = (PGM_P)(addr); /* isolate varible for macro expansion */ \
@@ -91,6 +104,10 @@ int vsnprintf_P(char *str, size_t strSize, PGM_P formatP, va_list ap) __attribut
91104
uint16_t __result = ((*__addr32) >> (__offset * 8)); \
92105
__result; \
93106
}))
107+
#else //__ets__
108+
#define pgm_read_byte(addr) (*reinterpret_cast<const uint8_t*>(addr))
109+
#define pgm_read_word(addr) (*reinterpret_cast<const uint16_t*>(addr))
110+
#endif //__ets__
94111

95112
#define pgm_read_dword(addr) (*reinterpret_cast<const uint32_t*>(addr))
96113
#define pgm_read_float(addr) (*reinterpret_cast<const float*>(addr))

tests/host/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ CORE_CPP_FILES := $(addprefix $(CORE_PATH)/,\
1717
Print.cpp \
1818
FS.cpp \
1919
spiffs_api.cpp \
20+
pgmspace.cpp \
2021
)
2122

2223
CORE_C_FILES := $(addprefix $(CORE_PATH)/,\
@@ -41,6 +42,7 @@ INC_PATHS += $(addprefix -I, \
4142

4243
TEST_CPP_FILES := \
4344
fs/test_fs.cpp \
45+
core/test_pgmspace.cpp \
4446

4547
CXXFLAGS += -std=c++11 -Wall -coverage -O0
4648
CFLAGS += -std=c99 -Wall -coverage -O0

tests/host/common/pgmspace.h

Lines changed: 0 additions & 78 deletions
This file was deleted.

tests/host/core/test_pgmspace.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
test_pgmspace.cpp - pgmspace tests
3+
Copyright © 2016 Ivan Grokhotkov
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
*/
15+
16+
#include <catch.hpp>
17+
#include <string.h>
18+
#include <pgmspace.h>
19+
20+
TEST_CASE("strstr_P works as strstr", "[core][pgmspace]")
21+
{
22+
auto t = [](const char* h, const char* n) {
23+
const char* strstr_P_result = strstr_P(h, n);
24+
const char* strstr_result = strstr(h, n);
25+
REQUIRE(strstr_P_result == strstr_result);
26+
};
27+
28+
// Test case data is from avr-libc, original copyright (c) 2007 Dmitry Xmelkov
29+
// See avr-libc/tests/simulate/pmstring/strstr_P.c
30+
t ("", "");
31+
t("12345", "");
32+
t("ababac", "abac");
33+
t("", "a");
34+
t("b", "a");
35+
t("a", "a");
36+
t("abcbef", "a");
37+
t(".a", "a");
38+
t(".a.", "a");
39+
t("ABCDEFGH", "H");
40+
t("", "12");
41+
t("13", "12");
42+
t("32", "12");
43+
t("12", "12");
44+
t("123", "12");
45+
t("012", "12");
46+
t("01200", "12");
47+
t("a_ab_abc_abcd_abcde", "abcdef");
48+
t("a_ab_abc_abcd_abcde_abcdef", "abcdef");
49+
t("aababcabcdabcde", "abcdef");
50+
t("aababcabcdabcdeabcdef", "abcdef");
51+
t("abaabaaabaaaab", "aaaaab");
52+
t("abaabaaabaaaabaaaaab", "aaaaab");
53+
t("_foo_foo", "foo");
54+
t("A", "a");
55+
}

tools/build.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
def compile(tmp_dir, sketch, tools_dir, hardware_dir, ide_path, f, args):
3333
cmd = ide_path + '/arduino-builder '
3434
cmd += '-compile -logger=human '
35-
for lib_dir in args.library_path:
36-
cmd += '-libraries "' + lib_dir + '" '
35+
if args.library_path:
36+
for lib_dir in args.library_path:
37+
cmd += '-libraries "' + lib_dir + '" '
3738
cmd += '-build-path "' + tmp_dir + '" '
3839
cmd += '-hardware "' + ide_path + '/hardware" '
3940
cmd += '-hardware ' + hardware_dir + ' '

0 commit comments

Comments
 (0)