-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move _ctype to PROGMEM, update accessors #1
Move _ctype to PROGMEM, update accessors #1
Conversation
The _ctype array is included in most sketches automatically, taking up RAM. Move the array to ROM, freeing the 257 bytes it takes, and modify all accessor functions/macros to use pgm_read_byte to access it.
bd47675
to
95217d8
Compare
@@ -123,6 +123,7 @@ No supporting OS subroutines are required. | |||
#include <errno.h> | |||
#include <stdlib.h> | |||
#include <reent.h> | |||
#include "../machine/xtensa/pgmspace.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it necessary to include pgmspace in this file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When building newlib -Os the ctype functions evaluate to the macros, and those require pgm_read_byte. This function uses isupper() and isdigit().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that mean that every user of <ctype.h> now has to include this machine-specific header file? How about including the necessary header file from ctype.h?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, yes, but practically for the Arduino SDK at least, no, because the one in the Arduino SDK is always included beforehand....argh....well, in the main .ino anyway. Extra files do not get the same #include pre-treatment by the IDE/SDK if my quick and dirty test is to be believed. So, one more vote for includeing the pgm_read_byte() stuff somewhere in newlib proper...
edit Actually, a cleaner way, for ctype at least, would be to move it to a 32-bit array from byte arrays (cost: wasted 768b of PROGMEM), and then no pgm_read* required at all for the macros.
Closing in lieu of #5 . No changes required at all for any ctype-using code, it's handled in sys/ctype.h (a new include). |
This patch is related to esp8266/Arduino#3740 , increasing heap RAM on the ESP8266 by moving library constants into ROM.
The _ctype array is included in most sketches automatically, taking up RAM.
Move the array to ROM, freeing the 257 bytes it takes, and modify all
accessor functions/macros to use pgm_read_byte to access it.