Skip to content

Commit 9f88163

Browse files
Move to PROGMEM aware libc, allow PSTR in printf()
A Newlib (libc) patch is in progress to move the _P functions from inside Arduino into first-class citizens in libc. This Arduino patch cleans up code that's been migrated there. Binaries for the new libs are included because it seems they're part of the Arduino git tree, and should be replaced with @igrr built ones when/if the Newlib changes are accepted. Notable changes/additions for Arduino: Allow for use of PROGMEM based format and parameter strings in all *printf functions. No need for copying PSTR()s into RAM before printing them out (transparently saves heap space when using _P functions) and makes it easier to print out constant strings for applications. Add "%S" (capital-S) format that I've been told, but cannot verify, is used in Arduino to specify a PROGMEM string parameter in printfs, as an alias for "%s" since plain "%s" can now handle PROGMEM. Optimized the memcpy_P, strnlen_P, and strncpy_P functions to use 32-bit direct reads whenver possible (source and dest alignment mediated), but there is still room for improvement in others. Finally, move several constant arrays from RODATA into PROGMEM and update their accessors. Among these are the ctype array, ~260 bytes, mprec* arrays, ~300 bytes, and strings/daycounts in the time formatting functions, ~200 bytes. All told, sketches will see from 300 to 800 additional RAM heap free on startup (depending on their use of these routines).
1 parent 02259a4 commit 9f88163

File tree

13 files changed

+212
-467
lines changed

13 files changed

+212
-467
lines changed

cores/esp8266/libc_replacements.c

-37
Original file line numberDiff line numberDiff line change
@@ -121,40 +121,3 @@ void _exit(int status) {
121121
(void) status;
122122
abort();
123123
}
124-
125-
#if 0
126-
127-
int ICACHE_RAM_ATTR printf(const char* format, ...) {
128-
va_list arglist;
129-
va_start(arglist, format);
130-
int ret = ets_vprintf(ets_putc, format, arglist);
131-
va_end(arglist);
132-
return ret;
133-
}
134-
135-
int ICACHE_RAM_ATTR sprintf(char* buffer, const char* format, ...) {
136-
int ret;
137-
va_list arglist;
138-
va_start(arglist, format);
139-
ret = ets_vsprintf(buffer, format, arglist);
140-
va_end(arglist);
141-
return ret;
142-
}
143-
144-
int ICACHE_RAM_ATTR snprintf(char* buffer, size_t size, const char* format, ...) {
145-
int ret;
146-
va_list arglist;
147-
va_start(arglist, format);
148-
ret = ets_vsnprintf(buffer, size, format, arglist);
149-
va_end(arglist);
150-
return ret;
151-
}
152-
153-
int ICACHE_RAM_ATTR vprintf(const char * format, va_list arg) {
154-
return ets_vprintf(ets_putc, format, arg);
155-
}
156-
157-
int ICACHE_RAM_ATTR vsnprintf(char * buffer, size_t size, const char * format, va_list arg) {
158-
return ets_vsnprintf(buffer, size, format, arg);
159-
}
160-
#endif

cores/esp8266/pgmspace.cpp

-292
This file was deleted.

0 commit comments

Comments
 (0)