libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit ef3bdbd92e107624899300351840bd8f787480c7
parent 49b0e0ce8f929b326b6e926e26dede64f29756d0
Author: Christian Grothoff <christian@grothoff.org>
Date:   Wed, 30 Jan 2013 12:26:27 +0000

Hello,

could be possible to change declarations for arrays of strings in the file reason_phrase.c?

Currently it is static const char * []. This places all strings into .rodata section and pointers to them into LMA of .text and also into .data in VMA.

E.g. for an ARM Cortex M3 (flash + SRAM) compiled with a arm-none-eabi-gcc
static const char *one_hundred[] = {
  "Continue",
  "Switching Protocols",
  "Processing"
};


Strings "Continue", "Switching Protocols", "Processing" are stored in flash. Also an array with pointers to strings is stored in flash. In addition, this array is copied into SRAM (+16 bytes). If you would change it to "static const char * const one_hundred[]" ... it would occupy only flash.

and
struct MHD_Reason_Block
{
......
  const char * const * data;
};

I agree, it is not relevant on a PC but on most microcontroller the SRAM is a limiting factor not the rom(flash).

Best
Martin Velek







Diffstat:
MChangeLog | 4++++
Msrc/daemon/reason_phrase.c | 12++++++------
2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,7 @@ +Wed Jan 30 13:09:30 CET 2013 + Adding more 'const' to allow keeping of reason phrases in ROM. + (see mailinglist). -CG/MV + Tue Jan 29 21:27:56 CET 2013 Make code work with PlibC 0.1.7 (which removed plibc_init_utf8). Only relevant for W32. Fixes #2734. -CG diff --git a/src/daemon/reason_phrase.c b/src/daemon/reason_phrase.c @@ -33,13 +33,13 @@ static const char *invalid_hundred[] = { NULL }; -static const char *one_hundred[] = { +static const char *const one_hundred[] = { "Continue", "Switching Protocols", "Processing" }; -static const char *two_hundred[] = { +static const char *const two_hundred[] = { "OK", "Created", "Accepted", @@ -50,7 +50,7 @@ static const char *two_hundred[] = { "Multi Status" }; -static const char *three_hundred[] = { +static const char *const three_hundred[] = { "Multiple Choices", "Moved Permanently", "Moved Temporarily", @@ -61,7 +61,7 @@ static const char *three_hundred[] = { "Temporary Redirect" }; -static const char *four_hundred[] = { +static const char *const four_hundred[] = { "Bad Request", "Unauthorized", "Payment Required", @@ -116,7 +116,7 @@ static const char *four_hundred[] = { "Unavailable For Legal Reasons" }; -static const char *five_hundred[] = { +static const char *const five_hundred[] = { "Internal Server Error", "Not Implemented", "Bad Gateway", @@ -134,7 +134,7 @@ static const char *five_hundred[] = { struct MHD_Reason_Block { unsigned int max; - const char **data; + const char *const*data; }; #define BLOCK(m) { (sizeof(m) / sizeof(char*)), m }