Skip to content
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

Conversation

earlephilhower
Copy link

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.

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.
@@ -123,6 +123,7 @@ No supporting OS subroutines are required.
#include <errno.h>
#include <stdlib.h>
#include <reent.h>
#include "../machine/xtensa/pgmspace.h"
Copy link
Owner

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?

Copy link
Author

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().

Copy link
Owner

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?

Copy link
Author

@earlephilhower earlephilhower Jan 11, 2018

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.

@earlephilhower
Copy link
Author

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants