GNOME Bugzilla – Bug 318176
Const and static additions, reduce per-process memory use
Last modified: 2007-04-16 06:54:18 UTC
The attached patch liberally adds the const (and static inside libical) keywords to arrays, turning them from (public) read-write arrays to (private) read-only arrays. Not only is this the intention of the code, but it also makes linking faster and reduces memory usage. Some of the arrays in libical are 25K each, so every time libical is used another 25K disappears.
Created attachment 53166 [details] [review] Add const If this patch is too unweidly as a single file I can split it per component.
adding memory keyword.
Comment on attachment 53166 [details] [review] Add const >Index: camel/camel-mime-filter-tohtml.c >=================================================================== >--- camel/camel-mime-filter-tohtml.c (revision 227) >+++ camel/camel-mime-filter-tohtml.c (working copy) >@@ -47,9 +47,9 @@ > #define CONVERT_WEB_URLS CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS > #define CONVERT_ADDRSPEC CAMEL_MIME_FILTER_TOHTML_CONVERT_ADDRESSES > >-static struct { >- unsigned int mask; >- urlpattern_t pattern; >+static const struct { >+ const unsigned int mask; >+ const urlpattern_t pattern; > } patterns[] = { > { CONVERT_WEB_URLS, { "file://", "", camel_url_file_start, camel_url_file_end } }, > { CONVERT_WEB_URLS, { "ftp://", "", camel_url_web_start, camel_url_web_end } }, >Index: camel/camel-mime-utils.c >=================================================================== >--- camel/camel-mime-utils.c (revision 227) >+++ camel/camel-mime-utils.c (working copy) >@@ -3519,7 +3519,7 @@ > } > > /* hrm, is there a library for this shit? */ >-static struct { >+static const struct { > char *name; > int offset; > } tz_offsets [] = { >Index: camel/broken-date-parser.c >=================================================================== >--- camel/broken-date-parser.c (revision 227) >+++ camel/broken-date-parser.c (working copy) >@@ -74,7 +74,7 @@ > }; > > /* hrm, is there a library for this shit? */ >-static struct { >+static const struct { > char *name; > int offset; > } tz_offsets [] = { >Index: camel/camel-html-parser.c >=================================================================== >--- camel/camel-html-parser.c (revision 227) >+++ camel/camel-html-parser.c (working copy) >@@ -179,8 +179,8 @@ > } > > /* this map taken out of libxml */ >-static struct { >- unsigned int val; >+static const struct { >+ const unsigned int val; > const char *name; > } entity_map[] = { > /* >Index: camel/camel-charset-map.c >=================================================================== >--- camel/camel-charset-map.c (revision 227) >+++ camel/camel-charset-map.c (working copy) >@@ -141,7 +141,7 @@ > } > if (j < 256) { > /* yes, dump it */ >- printf("static unsigned char m%02x%x[256] = {\n\t", i, k); >+ printf("static const unsigned char m%02x%x[256] = {\n\t", i, k); > for (j=0;j<256;j++) { > printf("0x%02x, ", (encoding_map[i*256+j] >> (k*8)) & 0xff ); > if (((j+1)&7) == 0 && j<255) >@@ -152,9 +152,9 @@ > } > } > >- printf("struct {\n"); >+ printf("const struct {\n"); > for (k=0;k<bytes;k++) { >- printf("\tunsigned char *bits%d;\n", k); >+ printf("\tconst unsigned char *bits%d;\n", k); > } > printf("} camel_charmap[256] = {\n\t"); > for (i=0;i<256;i++) { >@@ -177,7 +177,7 @@ > } > printf("\n};\n\n"); > >- printf("struct {\n\tconst char *name;\n\tunsigned int bit;\n} camel_charinfo[] = {\n"); >+ printf("const struct {\n\tconst char *name;\n\tunsigned int bit;\n} camel_charinfo[] = {\n"); > for (j=0;tables[j].name;j++) { > printf("\t{ \"%s\", 0x%04x },\n", tables[j].name, tables[j].bit); > } >Index: camel/camel-mime-filter-enriched.c >=================================================================== >--- camel/camel-mime-filter-enriched.c (revision 227) >+++ camel/camel-mime-filter-enriched.c (working copy) >@@ -40,11 +40,11 @@ > static char *param_parse_font (const char *inptr, int inlen); > static char *param_parse_lang (const char *inptr, int inlen); > >-static struct { >- char *enriched; >- char *html; >- gboolean needs_param; >- EnrichedParamParser parse_param; /* parses *and* validates the input */ >+static const struct { >+ const char *enriched; >+ const char *html; >+ const gboolean needs_param; >+ const EnrichedParamParser parse_param; /* parses *and* validates the input */ > } enriched_tags[] = { > { "bold", "<b>", FALSE, NULL }, > { "/bold", "</b>", FALSE, NULL }, >Index: camel/camel-charset-map-private.h >=================================================================== >--- camel/camel-charset-map-private.h (revision 227) >+++ camel/camel-charset-map-private.h (working copy) >@@ -16,7 +16,7 @@ > 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, > 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, > 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, >- 0xbf, 0xbf, 0x9f, 0x9f, 0x9f, 0x9f, 0x9f, 0x9f, >+ 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0x9f, 0x9f, 0x9f, > 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, > 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, > 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, >@@ -191,7 +191,7 @@ > 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, > 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, > 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, >- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, >+ 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, > 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0x00, > 0x20, 0x20, 0x20, 0x00, 0x20, 0x00, 0x20, 0x20, > 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, >@@ -337,6 +337,7 @@ > 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, > 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, > 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, >+ 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x20, > 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, > 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, > 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, >@@ -347,7 +348,6 @@ > 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, > 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, > 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, >- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, > }; > > static const unsigned char m201[256] = { >@@ -560,7 +560,7 @@ > 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, > }; > >-struct { >+const struct { > const unsigned char *bits0; > const unsigned char *bits1; > } camel_charmap[256] = { >@@ -598,7 +598,7 @@ > { 0, 0, }, { 0, 0, }, { 0, 0, }, { 0, 0, }, { 0, 0, }, { 0, 0, }, { 0, 0, }, { 0, 0, }, > }; > >-struct { >+const struct { > const char *name; > unsigned int bit; > } camel_charinfo[] = { >Index: libedataserver/e-iconv.c >=================================================================== >--- libedataserver/e-iconv.c (revision 227) >+++ libedataserver/e-iconv.c (working copy) >@@ -96,7 +96,7 @@ > static char *locale_charset = NULL; > static char *locale_lang = NULL; > >-struct { >+const struct { > char *charset; > char *iconv_name; > } known_iconv_charsets[] = { >@@ -587,7 +587,7 @@ > /* NOTE: only support charset names that will be returned by > * e_iconv_charset_name() so that we don't have to keep track of all > * the aliases too. */ >-static struct { >+static const struct { > char *charset; > char *lang; > } cjkr_lang_map[] = { >Index: addressbook/libebook/e-name-western-tables.h >=================================================================== >--- addressbook/libebook/e-name-western-tables.h (revision 227) >+++ addressbook/libebook/e-name-western-tables.h (working copy) >@@ -3,7 +3,7 @@ > > G_BEGIN_DECLS > >-char *e_name_western_pfx_table[] = { >+const char *e_name_western_pfx_table[] = { > > /* > * English. >Index: addressbook/libebook/e-contact.c >=================================================================== >--- addressbook/libebook/e-contact.c (revision 227) >+++ addressbook/libebook/e-contact.c (working copy) >@@ -98,7 +98,7 @@ > #define ATTR2_TYPE_STR_FIELD(id,vc,n,pn,ro,at1,at2,nth) { E_CONTACT_FIELD_TYPE_ATTR_TYPE | E_CONTACT_FIELD_TYPE_SYNTHETIC | E_CONTACT_FIELD_TYPE_STRING, (id), (vc), (n), (pn), (ro), (nth), (at1), (at2) } > #define ATTR_TYPE_STRUCT_FIELD(id,vc,n,pn,ro,at,get,set,ty) { E_CONTACT_FIELD_TYPE_ATTR_TYPE | E_CONTACT_FIELD_TYPE_SYNTHETIC | E_CONTACT_FIELD_TYPE_GETSET | E_CONTACT_FIELD_TYPE_STRUCT, (id), (vc), (n), (pn), (ro), 0, (at), NULL, (get), (set), (ty) } > >-static EContactFieldInfo field_info[] = { >+static const EContactFieldInfo field_info[] = { > STRING_FIELD (E_CONTACT_UID, EVC_UID, "id", N_("Unique ID"), FALSE), > STRING_FIELD (E_CONTACT_FILE_AS, EVC_X_FILE_AS, "file_as", N_("File Under"), FALSE), > >@@ -672,7 +672,7 @@ > { > EContact *contact = E_CONTACT (object); > int i; >- EContactFieldInfo *info = NULL; >+ const EContactFieldInfo *info = NULL; > > if (prop_id < 1 || prop_id >= E_CONTACT_FIELD_LAST) { > G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); >@@ -1104,7 +1104,7 @@ > { > EContact *contact = E_CONTACT (object); > int i; >- EContactFieldInfo *info = NULL; >+ const EContactFieldInfo *info = NULL; > > if (prop_id < 1 || prop_id >= E_CONTACT_FIELD_LAST) { > G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); >@@ -1620,7 +1620,7 @@ > GList *l = NULL; > GList *attrs, *a; > int i; >- EContactFieldInfo *info = NULL; >+ const EContactFieldInfo *info = NULL; > > g_return_val_if_fail (contact && E_IS_CONTACT (contact), NULL); > g_return_val_if_fail (field_id >= 1 && field_id <= E_CONTACT_FIELD_LAST, NULL); >@@ -1664,7 +1664,7 @@ > void > e_contact_set_attributes (EContact *contact, EContactField field_id, GList *attributes) > { >- EContactFieldInfo *info = NULL; >+ const EContactFieldInfo *info = NULL; > GList *l; > int i; > >Index: addressbook/libebook/e-name-western.c >=================================================================== >--- addressbook/libebook/e-name-western.c (revision 227) >+++ addressbook/libebook/e-name-western.c (working copy) >@@ -28,7 +28,7 @@ > } ENameWesternIdxs; > > static int >-e_name_western_str_count_words (char *str) >+e_name_western_str_count_words (const char *str) > { > int word_count; > char *p; >Index: calendar/libical/src/libical/icalrestriction.c.in >=================================================================== >--- calendar/libical/src/libical/icalrestriction.c.in (revision 227) >+++ calendar/libical/src/libical/icalrestriction.c.in (working copy) >@@ -30,7 +30,7 @@ > > struct icalrestriction_property_record; > >-typedef char* (*restriction_func)(struct icalrestriction_property_record* rec,icalcomponent* comp,icalproperty* prop); >+typedef char* (*restriction_func)(const struct icalrestriction_property_record* rec,icalcomponent* comp,icalproperty* prop); > > > typedef struct icalrestriction_property_record { >@@ -50,17 +50,17 @@ > restriction_func function; > } icalrestriction_component_record; > >-icalrestriction_property_record* >+static const icalrestriction_property_record* > icalrestriction_get_property_restriction(icalproperty_method method, > icalcomponent_kind component, > icalproperty_kind property); >-icalrestriction_component_record* >+static const icalrestriction_component_record* > icalrestriction_get_component_restriction(icalproperty_method method, > icalcomponent_kind component, > icalcomponent_kind subcomponent); > >-icalrestriction_component_record icalrestriction_component_records[]; >-icalrestriction_property_record icalrestriction_property_records[]; >+static const icalrestriction_component_record icalrestriction_component_records[]; >+static const icalrestriction_property_record icalrestriction_property_records[]; > > icalrestriction_property_record null_prop_record = {ICAL_METHOD_NONE,ICAL_NO_COMPONENT,ICAL_NO_PROPERTY,ICAL_RESTRICTION_UNKNOWN,0}; > icalrestriction_component_record null_comp_record = {ICAL_METHOD_NONE,ICAL_NO_COMPONENT,ICAL_NO_COMPONENT,ICAL_RESTRICTION_UNKNOWN,0}; >@@ -84,7 +84,7 @@ > { 1, 1, 1} /*ICAL_RESTRICTION_UNKNOWN*/ > }; > >-char restr_string_map[ICAL_RESTRICTION_UNKNOWN+1][60] = { >+const char restr_string_map[ICAL_RESTRICTION_UNKNOWN+1][60] = { > "unknown number",/*ICAL_RESTRICTION_NONE*/ > "0",/*ICAL_RESTRICTION_ZERO*/ > "1",/*ICAL_RESTRICTION_ONE*/ >@@ -116,7 +116,7 @@ > /* Special case routines */ > > char* icalrestriction_may_be_draft_final_canceled( >- icalrestriction_property_record *rec, >+ const icalrestriction_property_record *rec, > icalcomponent* comp, > icalproperty* prop) > { >@@ -135,7 +135,7 @@ > } > > char* icalrestriction_may_be_comp_need_process( >- icalrestriction_property_record *rec, >+ const icalrestriction_property_record *rec, > icalcomponent* comp, > icalproperty* prop) > { >@@ -151,7 +151,7 @@ > > return 0; > } >-char* icalrestriction_may_be_tent_conf(icalrestriction_property_record *rec, >+char* icalrestriction_may_be_tent_conf(const icalrestriction_property_record *rec, > icalcomponent* comp, > icalproperty* prop){ > icalproperty_status stat = icalproperty_get_status(prop); >@@ -166,7 +166,7 @@ > return 0; > } > char* icalrestriction_may_be_tent_conf_cancel( >- icalrestriction_property_record *rec, >+ const icalrestriction_property_record *rec, > icalcomponent* comp, > icalproperty* prop) > { >@@ -184,7 +184,7 @@ > } > > char* icalrestriction_must_be_cancel_if_present( >- icalrestriction_property_record *rec, >+ const icalrestriction_property_record *rec, > icalcomponent* comp, > icalproperty* prop) > { >@@ -202,7 +202,7 @@ > } > > char* icalrestriction_must_be_canceled_no_attendee( >- icalrestriction_property_record *rec, >+ const icalrestriction_property_record *rec, > icalcomponent* comp, > icalproperty* prop) > { >@@ -212,13 +212,13 @@ > > return 0; > } >-char* icalrestriction_must_be_recurring(icalrestriction_property_record *rec, >+char* icalrestriction_must_be_recurring(const icalrestriction_property_record *rec, > icalcomponent* comp, > icalproperty* prop){ > /* Hack */ > return 0; > } >-char* icalrestriction_must_have_duration(icalrestriction_property_record *rec, >+char* icalrestriction_must_have_duration(const icalrestriction_property_record *rec, > icalcomponent* comp, > icalproperty* prop){ > >@@ -230,7 +230,7 @@ > > return 0; > } >-char* icalrestriction_must_have_repeat(icalrestriction_property_record *rec, >+char* icalrestriction_must_have_repeat(const icalrestriction_property_record *rec, > icalcomponent* comp, > icalproperty* prop){ > if( !icalcomponent_get_first_property(comp,ICAL_REPEAT_PROPERTY)){ >@@ -241,14 +241,14 @@ > > return 0; > } >-char* icalrestriction_must_if_tz_ref(icalrestriction_property_record *rec, >+char* icalrestriction_must_if_tz_ref(const icalrestriction_property_record *rec, > icalcomponent* comp, > icalproperty* prop){ > > /* Hack */ > return 0; > } >-char* icalrestriction_no_dtend(icalrestriction_property_record *rec, >+char* icalrestriction_no_dtend(const icalrestriction_property_record *rec, > icalcomponent* comp, > icalproperty* prop){ > >@@ -260,7 +260,7 @@ > > return 0; > } >-char* icalrestriction_no_duration(icalrestriction_property_record *rec, >+char* icalrestriction_no_duration(const icalrestriction_property_record *rec, > icalcomponent* comp, > icalproperty* prop){ > >@@ -268,7 +268,7 @@ > return 0; > } > char* icalrestriction_must_be_email( >- icalrestriction_property_record *rec, >+ const icalrestriction_property_record *rec, > icalcomponent* comp, > icalproperty* prop) > { >@@ -289,8 +289,8 @@ > icalproperty_kind kind; > icalcomponent_kind comp_kind; > icalrestriction_kind restr; >- icalrestriction_property_record *prop_record; >- char* funcr = 0; >+ const icalrestriction_property_record *prop_record; >+ const char* funcr = 0; > icalproperty *prop; > > int count; >@@ -419,7 +419,7 @@ > > } > >-icalrestriction_property_record* >+static const icalrestriction_property_record* > icalrestriction_get_property_restriction(icalproperty_method method, > icalcomponent_kind component, > icalproperty_kind property) >@@ -441,7 +441,7 @@ > } > > >-icalrestriction_component_record* >+static const icalrestriction_component_record* > icalrestriction_get_component_restriction(icalproperty_method method, > icalcomponent_kind component, > icalcomponent_kind subcomponent) >Index: calendar/libical/src/libical/icalrecur.c >=================================================================== >--- calendar/libical/src/libical/icalrecur.c (revision 227) >+++ calendar/libical/src/libical/icalrecur.c (working copy) >@@ -666,7 +666,7 @@ > short map[8]; > }; > >-static struct expand_split_map_struct expand_map[] = >+static const struct expand_split_map_struct expand_map[] = > { > {ICAL_SECONDLY_RECURRENCE,{1,1,1,1,1,1,1,1}}, > {ICAL_MINUTELY_RECURRENCE,{2,1,1,1,1,1,1,1}}, >Index: calendar/libical/src/libical/icalcomponent.c >=================================================================== >--- calendar/libical/src/libical/icalcomponent.c (revision 227) >+++ calendar/libical/src/libical/icalcomponent.c (working copy) >@@ -1240,7 +1240,7 @@ > > > >-static struct icalcomponent_kind_map component_map[] = >+static const struct icalcomponent_kind_map component_map[] = > { > { ICAL_VEVENT_COMPONENT, "VEVENT" }, > { ICAL_VTODO_COMPONENT, "VTODO" }, >Index: calendar/libical/src/libical/icalmime.c >=================================================================== >--- calendar/libical/src/libical/icalmime.c (revision 227) >+++ calendar/libical/src/libical/icalmime.c (working copy) >@@ -138,7 +138,7 @@ > > > >-struct sspm_action_map icalmime_local_action_map[] = >+static const struct sspm_action_map icalmime_local_action_map[] = > { > {SSPM_TEXT_MAJOR_TYPE,SSPM_CALENDAR_MINOR_TYPE,icalmime_text_new_part,icalmime_text_add_line,icalmime_textcalendar_end_part,icalmime_text_free_part}, > {SSPM_TEXT_MAJOR_TYPE,SSPM_ANY_MINOR_TYPE,icalmime_text_new_part,icalmime_text_add_line,icalmime_text_end_part,icalmime_text_free_part}, >Index: calendar/libical/src/libical/icalenums.c >=================================================================== >--- calendar/libical/src/libical/icalenums.c (revision 227) >+++ calendar/libical/src/libical/icalenums.c (working copy) >@@ -38,7 +38,7 @@ > > /*** @brief Allowed request status values > */ >-static struct { >+static const struct { > enum icalrequeststatus kind; > int major; > int minor; >Index: calendar/libical/src/libical/icalerror.c >=================================================================== >--- calendar/libical/src/libical/icalerror.c (revision 227) >+++ calendar/libical/src/libical/icalerror.c (working copy) >@@ -141,7 +141,7 @@ > char name[160]; > }; > >-static struct icalerror_string_map string_map[] = >+static const struct icalerror_string_map string_map[] = > { > {"BADARG",ICAL_BADARG_ERROR,"BADARG: Bad argument to function"}, > { "NEWFAILED",ICAL_NEWFAILED_ERROR,"NEWFAILED: Failed to create a new object via a *_new() routine"}, >@@ -183,7 +183,7 @@ > return es; > } > >-char* icalerror_perror() >+const char* icalerror_perror() > { > return icalerror_strerror(icalerrno); > } >@@ -229,7 +229,7 @@ > > > >-char* icalerror_strerror(icalerrorenum e) { >+const char* icalerror_strerror(icalerrorenum e) { > > int i; > >Index: calendar/libical/src/libical/icalerror.h >=================================================================== >--- calendar/libical/src/libical/icalerror.h (revision 227) >+++ calendar/libical/src/libical/icalerror.h (working copy) >@@ -90,8 +90,8 @@ > ICAL_ERROR_UNKNOWN /* Asked state for an unknown error type */ > } icalerrorstate ; > >-char* icalerror_strerror(icalerrorenum e); >-char* icalerror_perror(); >+const char* icalerror_strerror(icalerrorenum e); >+const char* icalerror_perror(); > void icalerror_set_error_state( icalerrorenum error, icalerrorstate); > icalerrorstate icalerror_get_error_state( icalerrorenum error); > >Index: calendar/libical/src/libicalss/icalclassify.c >=================================================================== >--- calendar/libical/src/libicalss/icalclassify.c (revision 227) >+++ calendar/libical/src/libicalss/icalclassify.c (working copy) >@@ -642,7 +642,7 @@ > icalclassify_post > } > >-struct icalclassify_map { >+static const struct icalclassify_map { > icalproperty_method method; > int (*fn)(struct icalclassify_parts *comp,struct icalclassify_parts *match, const char* user); > icalproperty_xlicclass class; >Index: calendar/libical/src/libicalvcal/icalvcal.c >=================================================================== >--- calendar/libical/src/libicalvcal/icalvcal.c (revision 227) >+++ calendar/libical/src/libicalvcal/icalvcal.c (working copy) >@@ -80,7 +80,7 @@ > int icaltype; > }; > >-struct conversion_table_struct conversion_table[]; >+static const struct conversion_table_struct conversion_table[]; > void* dc_prop(int icaltype, VObject *object, icalcomponent *comp, > icalvcal_defaults *defaults); > >@@ -1417,7 +1417,7 @@ > table, so you'll have to find the missing properties the hard way -- > the code will assert */ > >-struct conversion_table_struct conversion_table[] = >+static const struct conversion_table_struct conversion_table[] = > { > {VCCalProp, COMPONENT, comp, ICAL_VCALENDAR_COMPONENT}, > {VCTodoProp, COMPONENT, comp, ICAL_VTODO_COMPONENT}, >Index: calendar/libical/src/libicalvcal/vobject.c >=================================================================== >--- calendar/libical/src/libicalvcal/vobject.c (revision 227) >+++ calendar/libical/src/libicalvcal/vobject.c (working copy) >@@ -767,7 +767,7 @@ > 0 > }; > >-static struct PreDefProp propNames[] = { >+static const struct PreDefProp propNames[] = { > { VC7bitProp, 0, 0, 0 }, > { VC8bitProp, 0, 0, 0 }, > { VCAAlarmProp, 0, AAlarmFields, 0 }, >@@ -930,7 +930,7 @@ > }; > > >-static struct PreDefProp* lookupPropInfo(const char* str) >+static const struct PreDefProp* lookupPropInfo(const char* str) > { > /* brute force for now, could use a hash table here. */ > int i; >@@ -1229,7 +1229,7 @@ > static void writeAttrValue(OFile *fp, VObject *o) > { > if (NAME_OF(o)) { >- struct PreDefProp *pi; >+ const struct PreDefProp *pi; > pi = lookupPropInfo(NAME_OF(o)); > if (pi && ((pi->flags & PD_INTERNAL) != 0)) return; > appendcOFile(fp,';'); >@@ -1272,7 +1272,7 @@ > { > int isQuoted=0; > if (NAME_OF(o)) { >- struct PreDefProp *pi; >+ const struct PreDefProp *pi; > VObjectIterator t; > const char **fields_ = 0; > pi = lookupPropInfo(NAME_OF(o)); >@@ -1329,7 +1329,7 @@ > static void writeVObject_(OFile *fp, VObject *o) > { > if (NAME_OF(o)) { >- struct PreDefProp *pi; >+ const struct PreDefProp *pi; > pi = lookupPropInfo(NAME_OF(o)); > > if (pi && ((pi->flags & PD_BEGIN) != 0)) { >Index: calendar/libical/scripts/mkrestrictiontable.pl >=================================================================== >--- calendar/libical/scripts/mkrestrictiontable.pl (revision 227) >+++ calendar/libical/scripts/mkrestrictiontable.pl (working copy) >@@ -31,7 +31,7 @@ > } > > # First build the property restriction table >-print "icalrestriction_property_record icalrestriction_property_records[] = {\n"; >+print "static const icalrestriction_property_record icalrestriction_property_records[] = {\n"; > > while(<F>) > { >@@ -62,7 +62,7 @@ > > print "};\n"; > >-print "icalrestriction_component_record icalrestriction_component_records[] = {\n"; >+print "static const icalrestriction_component_record icalrestriction_component_records[] = {\n"; > > > # Go back through the entire file and build the component restriction table >Index: calendar/libical/scripts/mkderivedproperties.pl >=================================================================== >--- calendar/libical/scripts/mkderivedproperties.pl (revision 227) >+++ calendar/libical/scripts/mkderivedproperties.pl (working copy) >@@ -65,7 +65,7 @@ > my $count = scalar(@props); > > >- print "static struct icalproperty_map property_map[$count] = {\n"; >+ print "static const struct icalproperty_map property_map[$count] = {\n"; > > foreach $prop (@props) { > >@@ -124,7 +124,7 @@ > } > > $count++; >- print "static struct icalproperty_enum_map enum_map[$count] = {\n"; >+ print "static const struct icalproperty_enum_map enum_map[$count] = {\n"; > print $out; > print " {ICAL_NO_PROPERTY,0,\"\"}\n};\n\n"; > >Index: calendar/libical/scripts/mkderivedvalues.pl >=================================================================== >--- calendar/libical/scripts/mkderivedvalues.pl (revision 227) >+++ calendar/libical/scripts/mkderivedvalues.pl (working copy) >@@ -130,7 +130,7 @@ > # print out the value to string map > > my $count = scalar(keys %h) + 1; >- print "static struct icalvalue_kind_map value_map[$count]={\n"; >+ print "static const struct icalvalue_kind_map value_map[$count]={\n"; > > foreach $value (keys %h) { > >Index: calendar/libical/scripts/mkderivedparameters.pl >=================================================================== >--- calendar/libical/scripts/mkderivedparameters.pl (revision 227) >+++ calendar/libical/scripts/mkderivedparameters.pl (working copy) >@@ -118,7 +118,7 @@ > } > > $count+=2; >- print "static struct icalparameter_value_kind_map value_kind_map[$count] = {\n"; >+ print "static const struct icalparameter_value_kind_map value_kind_map[$count] = {\n"; > print $out; > print " {ICAL_VALUE_X,ICAL_X_VALUE},\n"; > print " {ICAL_VALUE_NONE,ICAL_NO_VALUE}\n};\n\n"; >@@ -141,7 +141,7 @@ > > } > $count+=1; >- print "static struct icalparameter_kind_map parameter_map[$count] = { \n"; >+ print "static const struct icalparameter_kind_map parameter_map[$count] = { \n"; > print $out; > print " { ICAL_NO_PARAMETER, \"\"}\n};\n\n"; > >@@ -171,7 +171,7 @@ > } > > $count+=3; >- print "static struct icalparameter_map icalparameter_map[] = {\n"; >+ print "static const struct icalparameter_map icalparameter_map[] = {\n"; > print "{ICAL_ANY_PARAMETER,0,\"\"},\n"; > print $out; > print " {ICAL_NO_PARAMETER,0,\"\"}};\n\n"; >Index: calendar/libecal-dbus/e-cal.c >=================================================================== >--- calendar/libecal-dbus/e-cal.c (revision 227) >+++ calendar/libecal-dbus/e-cal.c (working copy) >@@ -358,8 +358,8 @@ > return TRUE; > > if (!connection) { >- if (!g_thread_supported ()) g_thread_init (NULL); >- dbus_g_thread_init (); >+ //if (!g_thread_supported ()) g_thread_init (NULL); >+ //dbus_g_thread_init (); > connection = dbus_g_bus_get (DBUS_BUS_SESSION, error); > if (!connection) > return FALSE; >Index: calendar/backends/file/e-cal-backend-file.c >=================================================================== >--- calendar/backends/file/e-cal-backend-file.c (revision 227) >+++ calendar/backends/file/e-cal-backend-file.c (working copy) >@@ -29,7 +29,6 @@ > #include <sys/stat.h> > #include <fcntl.h> > #include <glib/gi18n-lib.h> >-#include <libgnomevfs/gnome-vfs.h> > #include <libedataserver/e-util.h> > #include <libedataserver/e-xml-hash-utils.h> > #include <libecal-dbus/e-cal-recur.h> >@@ -38,6 +37,7 @@ > #include <libedata-cal-dbus/e-cal-backend-util.h> > #include <libedata-cal-dbus/e-cal-backend-sexp.h> > #include "e-cal-backend-file-events.h" >+#include <libgnomevfs/gnome-vfs.h> > > > >@@ -310,6 +310,14 @@ > return obj_data ? obj_data->full_object : NULL; > } > >+static const char * >+find_path_from_uri (const char *uri) >+{ >+ g_assert (strncasecmp (uri, "file://", 7) == 0); >+ >+ return uri + 7; >+} >+ > > > /* Calendar backend methods */ >@@ -592,7 +600,7 @@ > } > } > >-static char * >+G_GNUC_DEPRECATED static char * > get_uri_string_for_gnome_vfs (ECalBackend *backend) > { > ECalBackendFile *cbfile; >@@ -609,7 +617,6 @@ > /* FIXME Check the error conditions a little more elegantly here */ > if (g_strrstr ("tasks.ics", master_uri) || g_strrstr ("calendar.ics", master_uri)) { > g_warning (G_STRLOC ": Existing file name %s", master_uri); >- > return NULL; > } > >@@ -637,16 +644,35 @@ > return str_uri; > } > >+/** >+ * Get the full path to this calendar file. >+ */ >+static char * >+get_path (ECalBackend *backend) >+{ >+ ECalBackendFile *cbfile; >+ const char *topuri, *dirname; >+ char *filename; >+ >+ g_return_val_if_fail (E_IS_CAL_BACKEND_FILE (backend), NULL); >+ >+ cbfile = E_CAL_BACKEND_FILE (backend); >+ topuri = e_cal_backend_get_uri (backend); >+ dirname = find_path_from_uri (topuri); >+ filename = g_build_filename (dirname, cbfile->priv->file_name, NULL); >+ return filename; >+} >+ > /* Parses an open iCalendar file and loads it into the backend */ > static ECalBackendSyncStatus >-open_cal (ECalBackendFile *cbfile, const char *uristr) >+open_cal (ECalBackendFile *cbfile, const char *path) > { > ECalBackendFilePrivate *priv; > icalcomponent *icalcomp; > > priv = cbfile->priv; > >- icalcomp = e_cal_util_parse_ics_file (uristr); >+ icalcomp = e_cal_util_parse_ics_file (path); > if (!icalcomp) > return GNOME_Evolution_Calendar_OtherError; > >@@ -759,7 +785,7 @@ > } > > static ECalBackendSyncStatus >-reload_cal (ECalBackendFile *cbfile, const char *uristr) >+reload_cal (ECalBackendFile *cbfile, const char *path) > { > ECalBackendFilePrivate *priv; > icalcomponent *icalcomp, *icalcomp_old; >@@ -767,7 +793,7 @@ > > priv = cbfile->priv; > >- icalcomp = e_cal_util_parse_ics_file (uristr); >+ icalcomp = e_cal_util_parse_ics_file (path); > if (!icalcomp) > return GNOME_Evolution_Calendar_OtherError; > >@@ -811,7 +837,7 @@ > } > > static ECalBackendSyncStatus >-create_cal (ECalBackendFile *cbfile, const char *uristr) >+create_cal (ECalBackendFile *cbfile, const char *path) > { > char *dirname; > ECalBackendFilePrivate *priv; >@@ -819,7 +845,7 @@ > priv = cbfile->priv; > > /* Create the directory to contain the file */ >- dirname = g_path_get_dirname (uristr); >+ dirname = g_path_get_dirname (path); > if (e_util_mkdir_hier (dirname, 0700) != 0) { > g_free (dirname); > return GNOME_Evolution_Calendar_NoSuchCal; >@@ -840,18 +866,6 @@ > return GNOME_Evolution_Calendar_Success; > } > >-static char * >-get_uri_string (ECalBackend *backend) >-{ >- gchar *str_uri, *full_uri; >- >- str_uri = get_uri_string_for_gnome_vfs (backend); >- full_uri = gnome_vfs_unescape_string (str_uri, ""); >- g_free (str_uri); >- >- return full_uri; >-} >- > /* Open handler for the file backend */ > static ECalBackendSyncStatus > e_cal_backend_file_open (ECalBackendSync *backend, EDataCal *cal, gboolean only_if_exists, >@@ -859,7 +873,7 @@ > { > ECalBackendFile *cbfile; > ECalBackendFilePrivate *priv; >- char *str_uri; >+ char *filename; > ECalBackendSyncStatus status; > > cbfile = E_CAL_BACKEND_FILE (backend); >@@ -869,22 +883,20 @@ > if (priv->uri && priv->comp_uid_hash) > return GNOME_Evolution_Calendar_Success; > >- str_uri = get_uri_string (E_CAL_BACKEND (backend)); >- if (!str_uri) >- return GNOME_Evolution_Calendar_OtherError; >- >- if (access (str_uri, R_OK) == 0) { >- status = open_cal (cbfile, str_uri); >- if (access (str_uri, W_OK) != 0) >+ filename = get_path (E_CAL_BACKEND (backend)); >+ >+ if (access (filename, R_OK) == 0) { >+ status = open_cal (cbfile, filename); >+ if (access (filename, W_OK) != 0) > priv->read_only = TRUE; > } else { > if (only_if_exists) > status = GNOME_Evolution_Calendar_NoSuchCal; > else >- status = create_cal (cbfile, str_uri); >+ status = create_cal (cbfile, filename); // TODO? > } > >- g_free (str_uri); >+ g_free (filename); > > return status; > } >@@ -894,7 +906,7 @@ > { > ECalBackendFile *cbfile; > ECalBackendFilePrivate *priv; >- char *str_uri, *dirname; >+ char *filename, *dirname; > const char *fname; > GDir *dir; > GError *error = NULL; >@@ -903,21 +915,21 @@ > cbfile = E_CAL_BACKEND_FILE (backend); > priv = cbfile->priv; > >- str_uri = get_uri_string (E_CAL_BACKEND (backend)); >- if (!str_uri) >+ filename = get_path (E_CAL_BACKEND (backend)); >+ if (!filename) > return GNOME_Evolution_Calendar_OtherError; > >- if (access (str_uri, W_OK) != 0) { >- g_free (str_uri); >+ if (access (filename, W_OK) != 0) { >+ g_free (filename); > > return GNOME_Evolution_Calendar_PermissionDenied; > } > > /* remove all files in the directory */ >- dirname = g_path_get_dirname (str_uri); >+ dirname = g_path_get_dirname (filename); > dir = g_dir_open (dirname, 0, &error); > if (!dir) { >- g_free (str_uri); >+ g_free (filename); > g_free (dirname); > > return GNOME_Evolution_Calendar_PermissionDenied; >@@ -929,7 +941,7 @@ > full_path = g_build_filename (dirname, fname, NULL); > if (unlink (full_path) != 0) { > g_free (full_path); >- g_free (str_uri); >+ g_free (filename); > g_free (dirname); > g_dir_close (dir); > >@@ -943,7 +955,7 @@ > success = rmdir (dirname) == 0; > > g_dir_close (dir); >- g_free (str_uri); >+ g_free (filename); > g_free (dirname); > > return success ? GNOME_Evolution_Calendar_Success : GNOME_Evolution_Calendar_OtherError; >@@ -2577,23 +2589,23 @@ > e_cal_backend_file_reload (ECalBackendFile *cbfile) > { > ECalBackendFilePrivate *priv; >- char *str_uri; >+ char *filename; > ECalBackendSyncStatus status; > > priv = cbfile->priv; > >- str_uri = get_uri_string (E_CAL_BACKEND (cbfile)); >- if (!str_uri) >+ filename = get_path (E_CAL_BACKEND (cbfile)); >+ if (!filename) > return GNOME_Evolution_Calendar_OtherError; > >- if (access (str_uri, R_OK) == 0) { >- status = reload_cal (cbfile, str_uri); >- if (access (str_uri, W_OK) != 0) >+ if (access (filename, R_OK) == 0) { >+ status = reload_cal (cbfile, filename); >+ if (access (filename, W_OK) != 0) > priv->read_only = TRUE; > } else { > status = GNOME_Evolution_Calendar_NoSuchCal; > } > >- g_free (str_uri); >+ g_free (filename); > return status; > } >Index: calendar/libecal/e-cal-recur.c >=================================================================== >--- calendar/libecal/e-cal-recur.c (revision 227) >+++ calendar/libecal/e-cal-recur.c (working copy) >@@ -4022,7 +4022,7 @@ > #undef e_cal_recur_nth > static > #endif >-const char *e_cal_recur_nth[31] = { >+const const char *e_cal_recur_nth[31] = { One constant too many here, i suppose. > N_("1st"), > N_("2nd"), > N_("3rd"),
oops...clicked the wrong option...did not mean a 32 KB file to be pasted on the bug page as a comment. The rest looks fine though. Ross, in the light of some strange problems reported on Solaris when I attempted adding a constant, I would like to test the patch once on OpenSolaris before approving the same..thanks for your patience.
harish, any news on opensolaris here?
Created attachment 66922 [details] [review] Revised patch This patch removes the "const const" mistake you noticed (which I think was the only comment you made)
-static struct { +static const struct { char *name; int offset; } tz_offsets [] = { this kind of changes has no effect. The easiest way to optimize this is to use fixed sized char arrays. -static struct { - char *name; +static const struct { + char name[4];
ross: comments to benoît's comments?
Created attachment 68297 [details] [review] Addressbook const patch
Created attachment 68298 [details] [review] Calendar const patch This patch is the good one: knocking a large amount of memory (25K arrays) into shared data.
These new patches don't include the not-great changes, and are split into calendar and addressbook for easy of review.
-char *e_name_western_pfx_table[] = { +const char *e_name_western_pfx_table[] = { has no effect at all. even const char * const ...
const char * const will move the array from .data to .data.rel.ro, so that it can be shared after prelinking.
So, are these patches good to go?
The addressbook patch has been entirely integrated now via other patches. Only the calendar patch is remaining, and this is the patch that actually makes a noticeable difference to memory usage. I've verified that it applies to svn trunk.
Harish/Chen: Can one of you review the calendar patch?
Patch looks good to commit.
Committed, thanks.