Hi. I've spotted some opportunities to mark more static data as const. Patch is against the current CVS version. The first change, to charmap.pl, simply mimics a constness change which somebody already made to an autogenerated header file. Savings are modest: I've avoided changes that conflict in any way with public structure or function definitions.
I wrote another patch (not included) to kill ~10K of constant pointer tables in the crypto/objects code. They're replaced by indices into nid_objs. This should let processes share more memory: the indices are constant, whereas the pointers are not (when we build relocatable code). Unfortunately, I haven't had a chance to measure real-world memory savings. The change is also more invasive and could harm performance of the lookup functions {sn,ln,obj}2nid. I still think the change is a good idea. Please let me know whether it would be accepted. Index: crypto/asn1/charmap.pl =================================================================== RCS file: /v/openssl/cvs/openssl/crypto/asn1/charmap.pl,v retrieving revision 1.1 diff -u -r1.1 charmap.pl --- crypto/asn1/charmap.pl 28 Jul 2000 01:58:11 -0000 1.1 +++ crypto/asn1/charmap.pl 11 Jan 2009 20:10:32 -0000 @@ -68,7 +68,7 @@ * Mask of various character properties */ -static unsigned char char_type[] = { +static const unsigned char char_type[] = { EOF for($i = 0; $i < 128; $i++) { Index: crypto/asn1/asn1_gen.c =================================================================== RCS file: /v/openssl/cvs/openssl/crypto/asn1/asn1_gen.c,v retrieving revision 1.20 diff -u -r1.20 asn1_gen.c --- crypto/asn1/asn1_gen.c 12 Nov 2008 03:57:49 -0000 1.20 +++ crypto/asn1/asn1_gen.c 11 Jan 2009 20:10:31 -0000 @@ -538,7 +538,8 @@ static int asn1_str2tag(const char *tagstr, int len) { unsigned int i; - static const struct tag_name_st *tntmp, tnst [] = { + const struct tag_name_st *tntmp; + static const struct tag_name_st tnst [] = { ASN1_GEN_STR("BOOL", V_ASN1_BOOLEAN), ASN1_GEN_STR("BOOLEAN", V_ASN1_BOOLEAN), ASN1_GEN_STR("NULL", V_ASN1_NULL), Index: crypto/asn1/tasn_prn.c =================================================================== RCS file: /v/openssl/cvs/openssl/crypto/asn1/tasn_prn.c,v retrieving revision 1.15 diff -u -r1.15 tasn_prn.c --- crypto/asn1/tasn_prn.c 5 Nov 2008 18:38:53 -0000 1.15 +++ crypto/asn1/tasn_prn.c 11 Jan 2009 20:10:32 -0000 @@ -401,7 +401,7 @@ const char *fname, const char *sname, const ASN1_PCTX *pctx) { - static char spaces[] = " "; + static const char spaces[] = " "; const int nspaces = sizeof(spaces) - 1; #if 0 Index: crypto/conf/conf_def.h =================================================================== RCS file: /v/openssl/cvs/openssl/crypto/conf/conf_def.h,v retrieving revision 1.2 diff -u -r1.2 conf_def.h --- crypto/conf/conf_def.h 2 Jan 2002 11:06:02 -0000 1.2 +++ crypto/conf/conf_def.h 11 Jan 2009 20:10:33 -0000 @@ -77,7 +77,7 @@ #define CONF_ALPHA_NUMERIC_PUNCT (CONF_ALPHA|CONF_NUMBER|CONF_UNDER| \ CONF_PUNCTUATION) -#define KEYTYPES(c) ((unsigned short *)((c)->meth_data)) +#define KEYTYPES(c) ((const unsigned short *)((c)->meth_data)) #ifndef CHARSET_EBCDIC #define IS_COMMENT(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_COMMENT) #define IS_FCOMMENT(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_FCOMMENT) @@ -108,7 +108,7 @@ #define IS_HIGHBIT(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_HIGHBIT) #endif /*CHARSET_EBCDIC*/ -static unsigned short CONF_type_default[256]={ +static const unsigned short CONF_type_default[256]={ 0x0008,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0010,0x0010,0x0000,0x0000,0x0010,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, @@ -143,7 +143,7 @@ 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000, }; -static unsigned short CONF_type_win32[256]={ +static const unsigned short CONF_type_win32[256]={ 0x0008,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0010,0x0010,0x0000,0x0000,0x0010,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, Index: crypto/conf/keysets.pl =================================================================== RCS file: /v/openssl/cvs/openssl/crypto/conf/keysets.pl,v retrieving revision 1.3 diff -u -r1.3 keysets.pl --- crypto/conf/keysets.pl 2 Jan 2002 11:06:02 -0000 1.3 +++ crypto/conf/keysets.pl 11 Jan 2009 20:10:33 -0000 @@ -131,7 +131,7 @@ #define CONF_ALPHA_NUMERIC_PUNCT (CONF_ALPHA|CONF_NUMBER|CONF_UNDER| \\ CONF_PUNCTUATION) -#define KEYTYPES(c) ((unsigned short *)((c)->meth_data)) +#define KEYTYPES(c) ((const unsigned short *)((c)->meth_data)) #ifndef CHARSET_EBCDIC #define IS_COMMENT(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_COMMENT) #define IS_FCOMMENT(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_FCOMMENT) @@ -164,7 +164,7 @@ EOF -print "static unsigned short CONF_type_default[256]={"; +print "static const unsigned short CONF_type_default[256]={"; for ($i=0; $i<256; $i++) { @@ -174,7 +174,7 @@ print "\n\t};\n\n"; -print "static unsigned short CONF_type_win32[256]={"; +print "static const unsigned short CONF_type_win32[256]={"; for ($i=0; $i<256; $i++) { Index: crypto/engine/eng_openssl.c =================================================================== RCS file: /v/openssl/cvs/openssl/crypto/engine/eng_openssl.c,v retrieving revision 1.16 diff -u -r1.16 eng_openssl.c --- crypto/engine/eng_openssl.c 31 Oct 2008 20:20:53 -0000 1.16 +++ crypto/engine/eng_openssl.c 11 Jan 2009 20:10:34 -0000 @@ -219,8 +219,8 @@ */ #include <openssl/rc4.h> #define TEST_RC4_KEY_SIZE 16 -static int test_cipher_nids[] = {NID_rc4,NID_rc4_40}; -static int test_cipher_nids_number = 2; +static const int test_cipher_nids[] = {NID_rc4,NID_rc4_40}; +static const int test_cipher_nids_number = 2; typedef struct { unsigned char key[TEST_RC4_KEY_SIZE]; RC4_KEY ks; @@ -304,8 +304,8 @@ #ifdef TEST_ENG_OPENSSL_SHA /* Much the same sort of comment as for TEST_ENG_OPENSSL_RC4 */ #include <openssl/sha.h> -static int test_digest_nids[] = {NID_sha1}; -static int test_digest_nids_number = 1; +static const int test_digest_nids[] = {NID_sha1}; +static const int test_digest_nids_number = 1; static int test_sha1_init(EVP_MD_CTX *ctx) { #ifdef TEST_ENG_OPENSSL_SHA_P_INIT Index: crypto/evp/openbsd_hw.c =================================================================== RCS file: /v/openssl/cvs/openssl/crypto/evp/openbsd_hw.c,v retrieving revision 1.14 diff -u -r1.14 openbsd_hw.c --- crypto/evp/openbsd_hw.c 25 Sep 2001 21:37:02 -0000 1.14 +++ crypto/evp/openbsd_hw.c 11 Jan 2009 20:10:35 -0000 @@ -316,7 +316,7 @@ static int do_digest(int ses,unsigned char *md,const void *data,int len) { struct crypt_op cryp; - static unsigned char md5zero[16]= + static const unsigned char md5zero[16]= { 0xd4,0x1d,0x8c,0xd9,0x8f,0x00,0xb2,0x04, 0xe9,0x80,0x09,0x98,0xec,0xf8,0x42,0x7e Index: crypto/ts/ts_rsp_print.c =================================================================== RCS file: /v/openssl/cvs/openssl/crypto/ts/ts_rsp_print.c,v retrieving revision 1.2 diff -u -r1.2 ts_rsp_print.c --- crypto/ts/ts_rsp_print.c 5 Mar 2006 20:19:04 -0000 1.2 +++ crypto/ts/ts_rsp_print.c 11 Jan 2009 20:10:36 -0000 @@ -71,7 +71,7 @@ /* Local function declarations. */ -static int TS_status_map_print(BIO *bio, struct status_map_st *a, +static int TS_status_map_print(BIO *bio, const struct status_map_st *a, ASN1_BIT_STRING *v); static int TS_ACCURACY_print_bio(BIO *bio, const TS_ACCURACY *accuracy); @@ -105,7 +105,7 @@ "Revocation warning.", "Revoked." }; - static struct status_map_st failure_map[] = + static const struct status_map_st failure_map[] = { { TS_INFO_BAD_ALG, "unrecognized or unsupported algorithm identifier" }, @@ -162,7 +162,7 @@ return 1; } -static int TS_status_map_print(BIO *bio, struct status_map_st *a, +static int TS_status_map_print(BIO *bio, const struct status_map_st *a, ASN1_BIT_STRING *v) { int lines = 0; Index: engines/e_padlock.c =================================================================== RCS file: /v/openssl/cvs/openssl/engines/e_padlock.c,v retrieving revision 1.6 diff -u -r1.6 e_padlock.c --- engines/e_padlock.c 12 Nov 2008 18:47:24 -0000 1.6 +++ engines/e_padlock.c 11 Jan 2009 20:10:42 -0000 @@ -649,7 +649,7 @@ #endif /* List of supported ciphers. */ -static int padlock_cipher_nids[] = { +static const int padlock_cipher_nids[] = { NID_aes_128_ecb, NID_aes_128_cbc, NID_aes_128_cfb, Index: ssl/d1_both.c =================================================================== RCS file: /v/openssl/cvs/openssl/ssl/d1_both.c,v retrieving revision 1.14 diff -u -r1.14 d1_both.c --- ssl/d1_both.c 17 Oct 2007 21:15:48 -0000 1.14 +++ ssl/d1_both.c 11 Jan 2009 20:10:45 -0000 @@ -125,7 +125,7 @@ /* XDTLS: figure out the right values */ -static unsigned int g_probable_mtu[] = {1500 - 28, 512 - 28, 256 - 28}; +static const unsigned int g_probable_mtu[] = {1500 - 28, 512 - 28, 256 - 28}; static unsigned int dtls1_min_mtu(void); static unsigned int dtls1_guess_mtu(unsigned int curr_mtu); Index: ssl/s3_enc.c =================================================================== RCS file: /v/openssl/cvs/openssl/ssl/s3_enc.c,v retrieving revision 1.55 diff -u -r1.55 s3_enc.c --- ssl/s3_enc.c 29 Dec 2008 16:11:57 -0000 1.55 +++ ssl/s3_enc.c 11 Jan 2009 20:10:47 -0000 @@ -140,7 +140,7 @@ #include <openssl/evp.h> #include <openssl/md5.h> -static unsigned char ssl3_pad_1[48]={ +static const unsigned char ssl3_pad_1[48]={ 0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36, 0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36, 0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36, @@ -148,7 +148,7 @@ 0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36, 0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36 }; -static unsigned char ssl3_pad_2[48]={ +static const unsigned char ssl3_pad_2[48]={ 0x5c,0x5c,0x5c,0x5c,0x5c,0x5c,0x5c,0x5c, 0x5c,0x5c,0x5c,0x5c,0x5c,0x5c,0x5c,0x5c, 0x5c,0x5c,0x5c,0x5c,0x5c,0x5c,0x5c,0x5c, Index: ssl/ssl_ciph.c =================================================================== RCS file: /v/openssl/cvs/openssl/ssl/ssl_ciph.c,v retrieving revision 1.85 diff -u -r1.85 ssl_ciph.c --- ssl/ssl_ciph.c 5 Jan 2009 14:43:05 -0000 1.85 +++ ssl/ssl_ciph.c 11 Jan 2009 20:10:49 -0000 @@ -198,7 +198,7 @@ 0,0,0,0 }; -static int ssl_handshake_digest_flag[SSL_MD_NUM_IDX]={ +static const int ssl_handshake_digest_flag[SSL_MD_NUM_IDX]={ SSL_HANDSHAKE_MAC_MD5,SSL_HANDSHAKE_MAC_SHA, SSL_HANDSHAKE_MAC_GOST94,0 }; Index: ssl/t1_lib.c =================================================================== RCS file: /v/openssl/cvs/openssl/ssl/t1_lib.c,v retrieving revision 1.64 diff -u -r1.64 t1_lib.c --- ssl/t1_lib.c 29 Dec 2008 16:15:27 -0000 1.64 +++ ssl/t1_lib.c 11 Jan 2009 20:10:51 -0000 @@ -170,7 +170,7 @@ } #ifndef OPENSSL_NO_EC -static int nid_list[] = +static const int nid_list[] = { NID_sect163k1, /* sect163k1 (1) */ NID_sect163r1, /* sect163r1 (2) */ ______________________________________________________________________ OpenSSL Project http://www.openssl.org Development Mailing List openssl-dev@openssl.org Automated List Manager majord...@openssl.org