of address and date fields by only inserting calls to the parse
functions (FT_PARSEADDR and FT_PARSEDATE) for a given component once.
The problem with this method is that the initial invocation may
actually be on a code path that is conditionally executed. This can
result cached copies of data from the fields in previous messages to
be used.
My solution is to move this optimization from compile time to run time.
Address and Date parsing calls (FT_PARSEADDR and FT_PARSEDATE) will
always be included. Run time flags are used to prevent these functions
from being run more than once per component per message.
The c_flags field has being converted from a boolean to a bit-field to
facilitate maintenance of the new CT_PARSED value. The result value
that used to be in this field is now the bit CF_TRUE and the
overloaded use of this field by scan() is now the CT_DATEFAB bit.
Some unneeded flags (CT_ADDRPARSE, CT_MYMBOX) have also been removed.
+2003-08-10 Jeffrey C Honig <jch@honig.net>
+
+ * Fix problem where parsing of address/date fields in fmt_compile
+ is optimized to the first instance. The first instance may be in
+ contitional code which will result in cached data to
+ be used. Instead, convert c_flags to a flags field from a boolean
+ and parse on the first use.
+ * Remove some unused flag bits.
+
Fri Jul 01 22:02:00 2003 Glenn Burkhardt <glenn@aoi-industries.com>
* Applied fixes for configuration problems with Solaris and
Fri Jul 01 22:02:00 2003 Glenn Burkhardt <glenn@aoi-industries.com>
* Applied fixes for configuration problems with Solaris and
*/
#define CT_ADDR (1<<0) /* referenced as address */
#define CT_DATE (1<<1) /* referenced as date */
*/
#define CT_ADDR (1<<0) /* referenced as address */
#define CT_DATE (1<<1) /* referenced as date */
-#define CT_MYMBOX (1<<2) /* "mymbox" test being done */
-#define CT_ADDRPARSE (1<<3) /* address parse being done */
+
+/*
+ * c_flags bits
+ */
+#define CF_TRUE (1<<0) /* usually means component is present */
+#define CF_PARSED (1<<1) /* address/date has been parsed */
+#define CF_DATEFAB (1<<2) /* datefield fabricated */
if (cm->c_type & CT_ADDR) {
CERROR("component used as both date and address");
}
if (cm->c_type & CT_ADDR) {
CERROR("component used as both date and address");
}
- if (! (cm->c_type & CT_DATE)) {
- cm->c_tws = (struct tws *)
- calloc((size_t) 1, sizeof(*cm->c_tws));
- fp->f_type = preprocess;
- PUTCOMP(sp);
- cm->c_type |= CT_DATE;
- }
+ cm->c_tws = (struct tws *)
+ calloc((size_t) 1, sizeof(*cm->c_tws));
+ fp->f_type = preprocess;
+ PUTCOMP(sp);
+ cm->c_type |= CT_DATE;
ismymbox ((struct mailname *) 0);
primed++;
}
ismymbox ((struct mailname *) 0);
primed++;
}
- cm->c_type |= CT_MYMBOX;
/* fall through */
case FT_PARSEADDR:
if (cm->c_type & CT_DATE) {
CERROR("component used as both date and address");
}
/* fall through */
case FT_PARSEADDR:
if (cm->c_type & CT_DATE) {
CERROR("component used as both date and address");
}
- if (! (cm->c_type & CT_ADDRPARSE)) {
- cm->c_mn = &fmt_mnull;
- fp->f_type = preprocess;
- PUTCOMP(sp);
- cm->c_type |= (CT_ADDR | CT_ADDRPARSE);
- }
+ cm->c_mn = &fmt_mnull;
+ fp->f_type = preprocess;
+ PUTCOMP(sp);
+ cm->c_type |= CT_ADDR;
break;
case FT_FORMATADDR:
break;
case FT_FORMATADDR:
cp = scanl;
ep = scanl + width - 1;
cp = scanl;
ep = scanl + width - 1;
+
+ for (fmt = format; fmt->f_type != FT_DONE; fmt++)
+ switch (fmt->f_type) {
+ case FT_PARSEADDR:
+ case FT_PARSEDATE:
+ fmt->f_comp->c_flags &= ~CF_PARSED;
+ break;
+ }
+
fmt = format;
while (cp < ep) {
fmt = format;
while (cp < ep) {
break;
case FT_LV_COMPFLAG:
break;
case FT_LV_COMPFLAG:
- value = fmt->f_comp->c_flags;
+ value = (fmt->f_comp->c_flags & CF_TRUE) != 0;
break;
case FT_LV_COMP:
value = (comp = fmt->f_comp)->c_text ? atoi(comp->c_text) : 0;
break;
case FT_LV_COMP:
value = (comp = fmt->f_comp)->c_text ? atoi(comp->c_text) : 0;
case FT_PARSEDATE:
comp = fmt->f_comp;
case FT_PARSEDATE:
comp = fmt->f_comp;
+ if (comp->c_flags & CF_PARSED)
+ break;
if ((sp = comp->c_text) && (tws = dparsetime(sp))) {
*comp->c_tws = *tws;
if ((sp = comp->c_text) && (tws = dparsetime(sp))) {
*comp->c_tws = *tws;
- comp->c_flags = 0;
- } else if (comp->c_flags >= 0) {
+ comp->c_flags &= ~CF_TRUE;
+ } else if ((comp->c_flags & CF_DATEFAB) == 0) {
memset ((char *) comp->c_tws, 0, sizeof *comp->c_tws);
memset ((char *) comp->c_tws, 0, sizeof *comp->c_tws);
+ comp->c_flags = CF_TRUE;
+ comp->c_flags |= CF_PARSED;
break;
case FT_FORMATADDR:
break;
case FT_FORMATADDR:
case FT_PARSEADDR:
comp = fmt->f_comp;
case FT_PARSEADDR:
comp = fmt->f_comp;
+ if (comp->c_flags & CF_PARSED)
+ break;
if (comp->c_mn != &fmt_mnull)
mnfree (comp->c_mn);
if ((sp = comp->c_text) && (sp = getname(sp)) &&
if (comp->c_mn != &fmt_mnull)
mnfree (comp->c_mn);
if ((sp = comp->c_text) && (sp = getname(sp)) &&
comp->c_mn = mn;
while (getname(""))
;
comp->c_mn = mn;
while (getname(""))
;
+ comp->c_flags |= CF_PARSED;
} else {
while (getname("")) /* XXX */
;
} else {
while (getname("")) /* XXX */
;
if ((sp = comp->c_text) && (sp = getname(sp)) &&
(mn = getm (sp, NULL, 0, AD_NAME, NULL))) {
comp->c_mn = mn;
if ((sp = comp->c_text) && (sp = getname(sp)) &&
(mn = getm (sp, NULL, 0, AD_NAME, NULL))) {
comp->c_mn = mn;
- comp->c_flags = ismymbox(mn);
+ if (ismymbox(mn))
+ comp->c_flags |= CF_TRUE;
+ else
+ comp->c_flags &= ~CF_TRUE;
while ((sp = getname(sp)))
while ((sp = getname(sp)))
- if (comp->c_flags == 0 &&
+ if ((comp->c_flags & CF_TRUE) == 0 &&
(mn = getm (sp, NULL, 0, AD_NAME, NULL)))
(mn = getm (sp, NULL, 0, AD_NAME, NULL)))
- comp->c_flags |= ismymbox(mn);
+ if (ismymbox(mn))
+ comp->c_flags |= CF_TRUE;
} else {
while (getname("")) /* XXX */
;
} else {
while (getname("")) /* XXX */
;
- comp->c_flags = (comp->c_text == 0);
+ if (comp->c_text == 0)
+ comp->c_flags |= CF_TRUE;
+ else
+ comp->c_flags &= ~CF_TRUE;
comp->c_mn = &fmt_mnull;
}
break;
comp->c_mn = &fmt_mnull;
}
break;
static void assignlabel(struct format *);
static char *f_typestr(int);
static char *c_typestr(int);
static void assignlabel(struct format *);
static char *f_typestr(int);
static char *c_typestr(int);
+static char *c_flagsstr(int);
static void litputs(char *);
static void litputc(char);
static void litputs(char *);
static void litputc(char);
if (fmt->f_comp->c_type)
printf(", c_type %s", c_typestr(fmt->f_comp->c_type));
if (fmt->f_comp->c_flags)
if (fmt->f_comp->c_type)
printf(", c_type %s", c_typestr(fmt->f_comp->c_type));
if (fmt->f_comp->c_flags)
- printf(", c_flags %d", fmt->f_comp->c_flags);
+ printf(", c_flags %s", c_flagsstr(fmt->f_comp->c_flags));
if (fmt->f_comp->c_type)
printf(", c_type %s", c_typestr(fmt->f_comp->c_type));
if (fmt->f_comp->c_flags)
if (fmt->f_comp->c_type)
printf(", c_type %s", c_typestr(fmt->f_comp->c_type));
if (fmt->f_comp->c_flags)
- printf(", c_flags %d", fmt->f_comp->c_flags);
+ printf(", c_flags %s", c_flagsstr(fmt->f_comp->c_flags));
if (fmt->f_comp->c_type)
printf(", c_type %s", c_typestr(fmt->f_comp->c_type));
if (fmt->f_comp->c_flags)
if (fmt->f_comp->c_type)
printf(", c_type %s", c_typestr(fmt->f_comp->c_type));
if (fmt->f_comp->c_flags)
- printf(", c_flags %d", fmt->f_comp->c_flags);
+ printf(", c_flags %s", c_flagsstr(fmt->f_comp->c_flags));
if (fmt->f_comp->c_type)
printf(", c_type %s", c_typestr(fmt->f_comp->c_type));
if (fmt->f_comp->c_flags)
if (fmt->f_comp->c_type)
printf(", c_type %s", c_typestr(fmt->f_comp->c_type));
if (fmt->f_comp->c_flags)
- printf(", c_flags %d", fmt->f_comp->c_flags);
+ printf(", c_flags %s", c_flagsstr(fmt->f_comp->c_flags));
static char buf[64];
buf[0] = '\0';
static char buf[64];
buf[0] = '\0';
- if (t & ~(CT_ADDR|CT_DATE|CT_MYMBOX|CT_ADDRPARSE))
+ if (t & ~(CT_ADDR|CT_DATE))
printf(buf, "0x%x ", t);
strcat(buf, "<");
i = 0;
FNORD(CT_ADDR, "ADDR");
FNORD(CT_DATE, "DATE");
printf(buf, "0x%x ", t);
strcat(buf, "<");
i = 0;
FNORD(CT_ADDR, "ADDR");
FNORD(CT_DATE, "DATE");
- FNORD(CT_MYMBOX, "MYMBOX");
- FNORD(CT_ADDRPARSE, "ADDRPARSE");
strcat(buf, ">");
return(buf);
strcat(buf, ">");
return(buf);
+static char *
+c_flagsstr(int t)
+{
+ register int i;
+ static char buf[64];
+
+ buf[0] = '\0';
+ if (t & ~(CF_TRUE|CF_PARSED|CF_DATEFAB))
+ printf(buf, "0x%x ", t);
+ strcat(buf, "<");
+ i = 0;
+ FNORD(CF_TRUE, "TRUE");
+ FNORD(CF_PARSED, "PARSED");
+ FNORD(CF_DATEFAB, "DATEFAB");
+ strcat(buf, ">");
+ return(buf);
+}
+#undef FNORD
+
static void
litputs(char *s)
{
static void
litputs(char *s)
{
if (datecomp->c_tws == NULL)
adios (NULL, "unable to allocate tws buffer");
*datecomp->c_tws = *dlocaltime ((time_t *) &st.st_mtime);
if (datecomp->c_tws == NULL)
adios (NULL, "unable to allocate tws buffer");
*datecomp->c_tws = *dlocaltime ((time_t *) &st.st_mtime);
- datecomp->c_flags = -1;
+ datecomp->c_flags |= CF_DATEFAB|CF_TRUE;
+ datecomp->c_flags &= ~CF_DATEFAB;