Skip to content

Commit e87a9b6

Browse files
committed
Merge branch 'master' into convergence
2 parents cd40f21 + be02af0 commit e87a9b6

File tree

5 files changed

+125
-25
lines changed

5 files changed

+125
-25
lines changed

cores/esp8266/WString.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ bool String::reserve(unsigned int size) {
200200
#ifdef DEBUG_ESP_PORT
201201
static void identifyString (const String& badOne)
202202
{
203-
DEBUGV("[String] '%." STR(OOM_STRING_BORDER_DISPLAY) "s ... %." STR(OOM_STRING_BORDER_DISPLAY) "s': ",
203+
DEBUG_ESP_PORT.printf("[String] '%." STR(OOM_STRING_BORDER_DISPLAY) "s ... %." STR(OOM_STRING_BORDER_DISPLAY) "s': ",
204204
badOne.c_str(),
205205
badOne.length() > OOM_STRING_BORDER_DISPLAY? badOne.c_str() + std::max((int)badOne.length() - OOM_STRING_BORDER_DISPLAY, OOM_STRING_BORDER_DISPLAY): "");
206206
}
@@ -231,14 +231,14 @@ bool String::changeBuffer(unsigned int maxStrLen) {
231231
if (!isSSO() && capacity() >= OOM_STRING_THRESHOLD_REALLOC_WARN && maxStrLen > capacity()) {
232232
// warn when badly re-allocating
233233
identifyString(*this);
234-
DEBUGV("Reallocating large String(%d -> %d bytes)\n", len(), maxStrLen);
234+
DEBUG_ESP_PORT.printf("Reallocating large String(%d -> %d bytes)\n", len(), maxStrLen);
235235
}
236236
#endif
237237
// Make sure we can fit newsize in the buffer
238238
if (newSize > CAPACITY_MAX) {
239239
#ifdef DEBUG_ESP_PORT
240240
identifyString(*this);
241-
DEBUGV("Maximum capacity reached (" STR(CAPACITY_MAX) ")\n");
241+
DEBUG_ESP_PORT.printf("Maximum capacity reached (" STR(CAPACITY_MAX) ")\n");
242242
#endif
243243
return false;
244244
}
@@ -261,7 +261,7 @@ bool String::changeBuffer(unsigned int maxStrLen) {
261261
}
262262
#ifdef DEBUG_ESP_PORT
263263
identifyString(*this);
264-
DEBUGV("OOM: %d -> %d bytes\n", isSSO() ? 0: capacity(), newSize);
264+
DEBUG_ESP_PORT.printf("OOM: %d -> %zu bytes\n", isSSO() ? 0: capacity(), newSize);
265265
#endif
266266
return false;
267267
}

cores/esp8266/core_esp8266_phy.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,7 @@ void user_rf_pre_init()
360360
{
361361
// *((volatile uint32_t*) 0x60000710) = 0;
362362
spoof_init_data = false;
363-
volatile uint32_t* rtc_reg = (volatile uint32_t*) 0x60001000;
364-
rtc_reg[30] = 0;
365363

366-
system_set_os_print(0);
367364
int rf_mode = __get_rf_mode();
368365
if (rf_mode >= 0) {
369366
system_phy_set_rfoption(rf_mode);

libraries/ESP8266WebServer/src/ESP8266WebServer-impl.h

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,35 @@ void ESP8266WebServerTemplate<ServerType>::handleClient() {
296296
bool keepCurrentClient = false;
297297
bool callYield = false;
298298

299-
DBGWS("http-server loop: conn=%d avail=%d status=%s\n",
300-
_currentClient.connected(), _currentClient.available(),
301-
_currentStatus==HC_NONE?"none":
302-
_currentStatus==HC_WAIT_READ?"wait-read":
303-
_currentStatus==HC_WAIT_CLOSE?"wait-close":
304-
"??");
299+
#ifdef DEBUG_ESP_HTTP_SERVER
300+
301+
struct compare_s
302+
{
303+
uint8_t connected;
304+
int available;
305+
HTTPClientStatus status;
306+
bool operator != (const compare_s& o)
307+
{
308+
return o.connected != connected
309+
|| o.available != available
310+
|| o.status != status;
311+
}
312+
};
313+
static compare_s last { false, 0, HC_NONE };
314+
compare_s now { _currentClient.connected(), _currentClient.available(), _currentStatus };
315+
316+
if (last != now)
317+
{
318+
DBGWS("http-server loop: conn=%d avail=%d status=%s\n",
319+
_currentClient.connected(), _currentClient.available(),
320+
_currentStatus==HC_NONE?"none":
321+
_currentStatus==HC_WAIT_READ?"wait-read":
322+
_currentStatus==HC_WAIT_CLOSE?"wait-close":
323+
"??");
324+
last = now;
325+
}
326+
327+
#endif // DEBUG_ESP_HTTP_SERVER
305328

306329
if (_currentClient.connected() || _currentClient.available()) {
307330
if (_currentClient.available() && _keepAlive) {

tools/mkbuildoptglobals.py

Lines changed: 80 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,13 @@
187187
import glob
188188
import os
189189
import platform
190+
import traceback
190191
import sys
191192
import textwrap
192193
import time
193194

195+
import locale
196+
194197
# Need to work on signature line used for match to avoid conflicts with
195198
# existing embedded documentation methods.
196199
build_opt_signature = "/*@create-file:build.opt@"
@@ -201,6 +204,7 @@
201204
err_print_flag = False
202205
msg_print_buf = ""
203206
debug_enabled = False
207+
default_encoding = None
204208

205209
# Issues trying to address through buffered printing
206210
# 1. Arduino IDE 2.0 RC5 does not show stderr text in color. Text printed does
@@ -295,16 +299,16 @@ def copy_create_build_file(source_fqfn, build_target_fqfn):
295299
pass
296300
return True # file changed
297301

298-
299302
def add_include_line(build_opt_fqfn, include_fqfn):
303+
global default_encoding
300304
if not os.path.exists(include_fqfn):
301305
# If file is missing, we need an place holder
302-
with open(include_fqfn, 'w', encoding="utf-8"):
306+
with open(include_fqfn, 'w', encoding=default_encoding):
303307
pass
304-
print("add_include_line: Created " + include_fqfn)
305-
with open(build_opt_fqfn, 'a', encoding="utf-8") as build_opt:
306-
build_opt.write('-include "' + include_fqfn.replace('\\', '\\\\') + '"\n')
308+
print_msg("add_include_line: Created " + include_fqfn)
307309

310+
with open(build_opt_fqfn, 'a', encoding=default_encoding) as build_opt:
311+
build_opt.write('-include "' + include_fqfn.replace('\\', '\\\\') + '"\n')
308312

309313
def extract_create_build_opt_file(globals_h_fqfn, file_name, build_opt_fqfn):
310314
"""
@@ -313,8 +317,9 @@ def extract_create_build_opt_file(globals_h_fqfn, file_name, build_opt_fqfn):
313317
copy of Sketch.ino.globals.h.
314318
"""
315319
global build_opt_signature
320+
global default_encoding
316321

317-
build_opt = open(build_opt_fqfn, 'w', encoding="utf-8")
322+
build_opt = open(build_opt_fqfn, 'w', encoding=default_encoding)
318323
if not os.path.exists(globals_h_fqfn) or (0 == os.path.getsize(globals_h_fqfn)):
319324
build_opt.close()
320325
return False
@@ -605,12 +610,63 @@ def parse_args():
605610
# ref nargs='*'', https://stackoverflow.com/a/4480202
606611
# ref no '--n' parameter, https://stackoverflow.com/a/21998252
607612

613+
614+
# retrieve *system* encoding, not the one used by python internally
615+
if sys.version_info >= (3, 11):
616+
def get_encoding():
617+
return locale.getencoding()
618+
else:
619+
def get_encoding():
620+
return locale.getdefaultlocale()[1]
621+
622+
623+
def show_value(desc, value):
624+
print_dbg(f'{desc:<40} {value}')
625+
return
626+
627+
def locale_dbg():
628+
show_value("get_encoding()", get_encoding())
629+
show_value("locale.getdefaultlocale()", locale.getdefaultlocale())
630+
show_value('sys.getfilesystemencoding()', sys.getfilesystemencoding())
631+
show_value("sys.getdefaultencoding()", sys.getdefaultencoding())
632+
show_value("locale.getpreferredencoding(False)", locale.getpreferredencoding(False))
633+
try:
634+
show_value("locale.getpreferredencoding()", locale.getpreferredencoding())
635+
except:
636+
pass
637+
show_value("sys.stdout.encoding", sys.stdout.encoding)
638+
639+
# use current setting
640+
show_value("locale.setlocale(locale.LC_ALL, None)", locale.setlocale(locale.LC_ALL, None))
641+
try:
642+
show_value("locale.getencoding()", locale.getencoding())
643+
except:
644+
pass
645+
show_value("locale.getlocale()", locale.getlocale())
646+
647+
# use user setting
648+
show_value("locale.setlocale(locale.LC_ALL, '')", locale.setlocale(locale.LC_ALL, ''))
649+
# show_value("locale.getencoding()", locale.getencoding())
650+
show_value("locale.getlocale()", locale.getlocale())
651+
return
652+
653+
608654
def main():
609655
global build_opt_signature
610656
global docs_url
611657
global debug_enabled
658+
global default_encoding
612659
num_include_lines = 1
613660

661+
# Given that GCC will handle lines from an @file as if they were on
662+
# the command line. I assume that the contents of @file need to be encoded
663+
# to match that of the shell running GCC runs. I am not 100% sure this API
664+
# gives me that, but it appears to work.
665+
#
666+
# However, elsewhere when dealing with source code we continue to use 'utf-8',
667+
# ref. https://gcc.gnu.org/onlinedocs/cpp/Character-sets.html
668+
default_encoding = get_encoding()
669+
614670
args = parse_args()
615671
debug_enabled = args.debug
616672
runtime_ide_path = os.path.normpath(args.runtime_ide_path)
@@ -623,6 +679,13 @@ def main():
623679
build_path_core, build_opt_name = os.path.split(build_opt_fqfn)
624680
globals_h_fqfn = os.path.join(build_path_core, globals_name)
625681

682+
if debug_enabled:
683+
locale_dbg()
684+
685+
default_locale = locale.getdefaultlocale()
686+
print_msg(f'default locale: {default_locale}')
687+
print_msg(f'default_encoding: {default_encoding}')
688+
626689
print_dbg(f"runtime_ide_path: {runtime_ide_path}")
627690
print_dbg(f"runtime_ide_version: {args.runtime_ide_version}")
628691
print_dbg(f"build_path: {build_path}")
@@ -655,6 +718,10 @@ def main():
655718
print_dbg(f"first_time: {first_time}")
656719
print_dbg(f"use_aggressive_caching_workaround: {use_aggressive_caching_workaround}")
657720

721+
if not os.path.exists(build_path_core):
722+
os.makedirs(build_path_core)
723+
print_msg("Clean build, created dir " + build_path_core)
724+
658725
if first_time or \
659726
not use_aggressive_caching_workaround or \
660727
not os.path.exists(commonhfile_fqfn):
@@ -667,10 +734,6 @@ def main():
667734
touch(commonhfile_fqfn)
668735
print_err(f"Neutralized future timestamp on build file: {commonhfile_fqfn}")
669736

670-
if not os.path.exists(build_path_core):
671-
os.makedirs(build_path_core)
672-
print_msg("Clean build, created dir " + build_path_core)
673-
674737
if os.path.exists(source_globals_h_fqfn):
675738
print_msg("Using global include from " + source_globals_h_fqfn)
676739

@@ -750,4 +813,10 @@ def main():
750813
handle_error(0) # commit print buffer
751814

752815
if __name__ == '__main__':
753-
sys.exit(main())
816+
rc = 1
817+
try:
818+
rc = main()
819+
except:
820+
print_err(traceback.format_exc())
821+
handle_error(0)
822+
sys.exit(rc)

tools/sizes.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,20 @@
2121
import os
2222
import subprocess
2323
import sys
24+
import locale
2425

2526
sys.stdout = sys.stderr
2627

28+
29+
# retrieve *system* encoding, not the one used by python internally
30+
if sys.version_info >= (3, 11):
31+
def get_encoding():
32+
return locale.getencoding()
33+
else:
34+
def get_encoding():
35+
return locale.getdefaultlocale()[1]
36+
37+
2738
def get_segment_sizes(elf, path, mmu):
2839
iram_size = 0
2940
iheap_size = 0
@@ -73,7 +84,7 @@ def get_segment_sizes(elf, path, mmu):
7384
)
7485

7586
cmd = [os.path.join(path, "xtensa-lx106-elf-size"), "-A", elf]
76-
with subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True) as proc:
87+
with subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True, encoding=get_encoding()) as proc:
7788
lines = proc.stdout.readlines()
7889
for line in lines:
7990
words = line.split()

0 commit comments

Comments
 (0)