[RFC PATCH 2/3] Compile the date/time parser into notmuch library

Jani Nikula jani at nikula.org
Wed Aug 10 03:22:06 PDT 2011


From: Michal Sojka <sojkam1 at fel.cvut.cz>

---
 Makefile.local     |    3 +
 configure          |    8 ++
 lib/Makefile.local |    5 +-
 lib/config.h       |   45 +++++++++++++
 lib/getdate.c      |  185 +++++++++++++++++++++++++++-------------------------
 lib/getdate.h      |    9 +++
 lib/getdate.y      |   15 ++++-
 7 files changed, 178 insertions(+), 92 deletions(-)
 create mode 100644 lib/config.h

diff --git a/Makefile.local b/Makefile.local
index e3d4d03..3da9ad9 100644
--- a/Makefile.local
+++ b/Makefile.local
@@ -234,6 +234,9 @@ quiet ?= $($(shell echo $1 | sed -e s'/ .*//'))
 %.o: %.c $(global_deps)
 	$(call quiet,CC $(CFLAGS)) -c $(FINAL_CFLAGS) $< -o $@
 
+%.c: %.y
+	$(call quiet,YACC $(YFLAGS)) $(YFLAGS) $< -o $@
+
 .deps/%.d: %.c $(global_deps)
 	@set -e; rm -f $@; mkdir -p $$(dirname $@) ; \
 	$(CC) -M $(CPPFLAGS) $(FINAL_CFLAGS) $< > $@.$$$$ 2>/dev/null ; \
diff --git a/configure b/configure
index 3999ce8..f385c79 100755
--- a/configure
+++ b/configure
@@ -25,9 +25,11 @@ fi
 # environment variables)
 CC=${CC:-gcc}
 CXX=${CXX:-g++}
+YACC=${YACC:-yacc}
 CFLAGS=${CFLAGS:--O2}
 CXXFLAGS=${CXXFLAGS:-\$(CFLAGS)}
 LDFLAGS=${LDFLAGS:-}
+YFLAGS=${YFLAGS}
 XAPIAN_CONFIG=${XAPIAN_CONFIG:-xapian-config}
 
 # We don't allow the EMACS or GZIP Makefile variables inherit values
@@ -571,6 +573,9 @@ CC = ${CC}
 # The C++ compiler to use
 CXX = ${CXX}
 
+# The parser generator to use
+YACC = ${YACC}
+
 # Command to execute emacs from Makefiles
 EMACS = emacs --quick
 
@@ -589,6 +594,9 @@ WARN_CXXFLAGS=${WARN_CXXFLAGS}
 # Flags to enable warnings when using the C compiler
 WARN_CFLAGS=${WARN_CFLAGS}
 
+# Default FLAGS for parser generator (can be overridden by user such as "make YFLAGS=-y")
+YFLAGS = ${YFLAGS}
+
 # The prefix to which notmuch should be installed
 # Note: If you change this value here, be sure to ensure that the
 # LIBDIR_IN_LDCONFIG value below is still set correctly.
diff --git a/lib/Makefile.local b/lib/Makefile.local
index fbc2f6a..a1c234f 100644
--- a/lib/Makefile.local
+++ b/lib/Makefile.local
@@ -56,7 +56,10 @@ libnotmuch_c_srcs =		\
 	$(dir)/messages.c	\
 	$(dir)/sha1.c		\
 	$(dir)/tags.c		\
-	$(dir)/xutil.c
+	$(dir)/xutil.c		\
+	$(dir)/getdate.c	\
+	$(dir)/c-ctype.c	\
+	$(dir)/gettime.c
 
 libnotmuch_cxx_srcs =		\
 	$(dir)/database.cc	\
diff --git a/lib/config.h b/lib/config.h
new file mode 100644
index 0000000..e8bc5b7
--- /dev/null
+++ b/lib/config.h
@@ -0,0 +1,45 @@
+/* lib/config.h.  Generated from config.hin by configure.  */
+/* lib/config.hin.  Generated from configure.ac by autoheader.  */
+
+/* Define to 1 if you have the `clock_gettime' function. */
+#define HAVE_CLOCK_GETTIME 1
+
+/* Define if you have compound literals. */
+#define HAVE_COMPOUND_LITERALS 1
+
+/* Define to 1 if you have the declaration of `tzname', and to 0 if you don't.
+   */
+/* #undef HAVE_DECL_TZNAME */
+
+/* Define to 1 if you have the `nanotime' function. */
+/* #undef HAVE_NANOTIME */
+
+/* Define to 1 if `tm_zone' is a member of `struct tm'. */
+#define HAVE_STRUCT_TM_TM_ZONE 1
+
+/* Define if struct tm has the tm_gmtoff member. */
+#define HAVE_TM_GMTOFF 1
+
+/* Define to 1 if your `struct tm' has `tm_zone'. Deprecated, use
+   `HAVE_STRUCT_TM_TM_ZONE' instead. */
+#define HAVE_TM_ZONE 1
+
+/* Define to 1 if you don't have `tm_zone' but do have the external array
+   `tzname'. */
+/* #undef HAVE_TZNAME */
+
+/* Define to 1 if you have the `tzset' function. */
+#define HAVE_TZSET 1
+
+
+/* Define as a marker that can be attached to declarations that might not
+    be used.  This helps to reduce warnings, such as from
+    GCC -Wunused-parameter.  */
+#if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
+# define _GL_UNUSED __attribute__ ((__unused__))
+#else
+# define _GL_UNUSED
+#endif
+/* The name _UNUSED_PARAMETER_ is an earlier spelling, although the name
+   is a misnomer outside of parameter lists.  */
+#define _UNUSED_PARAMETER_ _GL_UNUSED
diff --git a/lib/getdate.c b/lib/getdate.c
index 5b20eeb..57f33e9 100644
--- a/lib/getdate.c
+++ b/lib/getdate.c
@@ -68,7 +68,7 @@
 /* Copy the first part of user declarations.  */
 
 /* Line 189 of yacc.c  */
-#line 1 "getdate.y"
+#line 1 "lib/getdate.y"
 
 /* Parse a string into an internal time stamp.
 
@@ -102,6 +102,8 @@
 /* FIXME: Check for arithmetic overflow in all cases, not just
    some of them.  */
 
+#include "notmuch-private.h"	/* For xmalloc() */
+
 #include <config.h>
 
 #include "getdate.h"
@@ -137,9 +139,6 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "xalloc.h"
-
-
 /* ISDIGIT differs from isdigit, as follows:
    - Its arg may be any int or unsigned int; it need not be an unsigned char
      or EOF.
@@ -344,7 +343,7 @@ set_hhmmss (parser_control *pc, long int hour, long int minutes,
 
 
 /* Line 189 of yacc.c  */
-#line 348 "getdate.c"
+#line 347 "lib/getdate.c"
 
 /* Enabling traces.  */
 #ifndef YYDEBUG
@@ -423,7 +422,7 @@ typedef union YYSTYPE
 {
 
 /* Line 214 of yacc.c  */
-#line 285 "getdate.y"
+#line 284 "lib/getdate.y"
 
   long int intval;
   textint textintval;
@@ -433,7 +432,7 @@ typedef union YYSTYPE
 
 
 /* Line 214 of yacc.c  */
-#line 437 "getdate.c"
+#line 436 "lib/getdate.c"
 } YYSTYPE;
 # define YYSTYPE_IS_TRIVIAL 1
 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
@@ -445,7 +444,7 @@ typedef union YYSTYPE
 
 
 /* Line 264 of yacc.c  */
-#line 449 "getdate.c"
+#line 448 "lib/getdate.c"
 
 #ifdef short
 # undef short
@@ -759,15 +758,15 @@ static const yytype_int8 yyrhs[] =
 /* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
 static const yytype_uint16 yyrline[] =
 {
-       0,   311,   311,   312,   316,   323,   325,   329,   331,   333,
-     335,   337,   339,   340,   341,   345,   350,   355,   362,   367,
-     377,   382,   390,   392,   395,   397,   399,   404,   409,   414,
-     419,   427,   432,   452,   459,   467,   475,   480,   486,   491,
-     500,   502,   504,   509,   511,   513,   515,   517,   519,   521,
-     523,   525,   527,   529,   531,   533,   535,   537,   539,   541,
-     543,   545,   547,   549,   553,   555,   557,   559,   561,   563,
-     568,   572,   572,   575,   576,   581,   582,   587,   592,   603,
-     604,   610,   611
+       0,   310,   310,   311,   315,   322,   324,   328,   330,   332,
+     334,   336,   338,   339,   340,   344,   349,   354,   361,   366,
+     376,   381,   389,   391,   394,   396,   398,   403,   408,   413,
+     418,   426,   431,   451,   458,   466,   474,   479,   485,   490,
+     499,   501,   503,   508,   510,   512,   514,   516,   518,   520,
+     522,   524,   526,   528,   530,   532,   534,   536,   538,   540,
+     542,   544,   546,   548,   552,   554,   556,   558,   560,   562,
+     567,   571,   571,   574,   575,   580,   581,   586,   591,   602,
+     603,   609,   610
 };
 #endif
 
@@ -1742,7 +1741,7 @@ yyreduce:
         case 4:
 
 /* Line 1455 of yacc.c  */
-#line 317 "getdate.y"
+#line 316 "lib/getdate.y"
     {
         pc->seconds = (yyvsp[(2) - (2)].timespec);
         pc->timespec_seen = true;
@@ -1752,42 +1751,42 @@ yyreduce:
   case 7:
 
 /* Line 1455 of yacc.c  */
-#line 330 "getdate.y"
+#line 329 "lib/getdate.y"
     { pc->times_seen++; }
     break;
 
   case 8:
 
 /* Line 1455 of yacc.c  */
-#line 332 "getdate.y"
+#line 331 "lib/getdate.y"
     { pc->local_zones_seen++; }
     break;
 
   case 9:
 
 /* Line 1455 of yacc.c  */
-#line 334 "getdate.y"
+#line 333 "lib/getdate.y"
     { pc->zones_seen++; }
     break;
 
   case 10:
 
 /* Line 1455 of yacc.c  */
-#line 336 "getdate.y"
+#line 335 "lib/getdate.y"
     { pc->dates_seen++; }
     break;
 
   case 11:
 
 /* Line 1455 of yacc.c  */
-#line 338 "getdate.y"
+#line 337 "lib/getdate.y"
     { pc->days_seen++; }
     break;
 
   case 15:
 
 /* Line 1455 of yacc.c  */
-#line 346 "getdate.y"
+#line 345 "lib/getdate.y"
     {
         set_hhmmss (pc, (yyvsp[(1) - (2)].textintval).value, 0, 0, 0);
         pc->meridian = (yyvsp[(2) - (2)].intval);
@@ -1797,7 +1796,7 @@ yyreduce:
   case 16:
 
 /* Line 1455 of yacc.c  */
-#line 351 "getdate.y"
+#line 350 "lib/getdate.y"
     {
         set_hhmmss (pc, (yyvsp[(1) - (4)].textintval).value, (yyvsp[(3) - (4)].textintval).value, 0, 0);
         pc->meridian = (yyvsp[(4) - (4)].intval);
@@ -1807,7 +1806,7 @@ yyreduce:
   case 17:
 
 /* Line 1455 of yacc.c  */
-#line 356 "getdate.y"
+#line 355 "lib/getdate.y"
     {
         set_hhmmss (pc, (yyvsp[(1) - (5)].textintval).value, (yyvsp[(3) - (5)].textintval).value, 0, 0);
         pc->meridian = MER24;
@@ -1819,7 +1818,7 @@ yyreduce:
   case 18:
 
 /* Line 1455 of yacc.c  */
-#line 363 "getdate.y"
+#line 362 "lib/getdate.y"
     {
         set_hhmmss (pc, (yyvsp[(1) - (6)].textintval).value, (yyvsp[(3) - (6)].textintval).value, (yyvsp[(5) - (6)].timespec).tv_sec, (yyvsp[(5) - (6)].timespec).tv_nsec);
         pc->meridian = (yyvsp[(6) - (6)].intval);
@@ -1829,7 +1828,7 @@ yyreduce:
   case 19:
 
 /* Line 1455 of yacc.c  */
-#line 368 "getdate.y"
+#line 367 "lib/getdate.y"
     {
         set_hhmmss (pc, (yyvsp[(1) - (7)].textintval).value, (yyvsp[(3) - (7)].textintval).value, (yyvsp[(5) - (7)].timespec).tv_sec, (yyvsp[(5) - (7)].timespec).tv_nsec);
         pc->meridian = MER24;
@@ -1841,7 +1840,7 @@ yyreduce:
   case 20:
 
 /* Line 1455 of yacc.c  */
-#line 378 "getdate.y"
+#line 377 "lib/getdate.y"
     {
         pc->local_isdst = (yyvsp[(1) - (1)].intval);
         pc->dsts_seen += (0 < (yyvsp[(1) - (1)].intval));
@@ -1851,7 +1850,7 @@ yyreduce:
   case 21:
 
 /* Line 1455 of yacc.c  */
-#line 383 "getdate.y"
+#line 382 "lib/getdate.y"
     {
         pc->local_isdst = 1;
         pc->dsts_seen += (0 < (yyvsp[(1) - (2)].intval)) + 1;
@@ -1861,14 +1860,14 @@ yyreduce:
   case 22:
 
 /* Line 1455 of yacc.c  */
-#line 391 "getdate.y"
+#line 390 "lib/getdate.y"
     { pc->time_zone = (yyvsp[(1) - (1)].intval); }
     break;
 
   case 23:
 
 /* Line 1455 of yacc.c  */
-#line 393 "getdate.y"
+#line 392 "lib/getdate.y"
     { pc->time_zone = (yyvsp[(1) - (2)].intval);
         apply_relative_time (pc, (yyvsp[(2) - (2)].rel), 1); }
     break;
@@ -1876,28 +1875,28 @@ yyreduce:
   case 24:
 
 /* Line 1455 of yacc.c  */
-#line 396 "getdate.y"
+#line 395 "lib/getdate.y"
     { pc->time_zone = (yyvsp[(1) - (3)].intval) + time_zone_hhmm (pc, (yyvsp[(2) - (3)].textintval), (yyvsp[(3) - (3)].intval)); }
     break;
 
   case 25:
 
 /* Line 1455 of yacc.c  */
-#line 398 "getdate.y"
+#line 397 "lib/getdate.y"
     { pc->time_zone = (yyvsp[(1) - (1)].intval) + 60; }
     break;
 
   case 26:
 
 /* Line 1455 of yacc.c  */
-#line 400 "getdate.y"
+#line 399 "lib/getdate.y"
     { pc->time_zone = (yyvsp[(1) - (2)].intval) + 60; }
     break;
 
   case 27:
 
 /* Line 1455 of yacc.c  */
-#line 405 "getdate.y"
+#line 404 "lib/getdate.y"
     {
         pc->day_ordinal = 0;
         pc->day_number = (yyvsp[(1) - (1)].intval);
@@ -1907,7 +1906,7 @@ yyreduce:
   case 28:
 
 /* Line 1455 of yacc.c  */
-#line 410 "getdate.y"
+#line 409 "lib/getdate.y"
     {
         pc->day_ordinal = 0;
         pc->day_number = (yyvsp[(1) - (2)].intval);
@@ -1917,7 +1916,7 @@ yyreduce:
   case 29:
 
 /* Line 1455 of yacc.c  */
-#line 415 "getdate.y"
+#line 414 "lib/getdate.y"
     {
         pc->day_ordinal = (yyvsp[(1) - (2)].intval);
         pc->day_number = (yyvsp[(2) - (2)].intval);
@@ -1927,7 +1926,7 @@ yyreduce:
   case 30:
 
 /* Line 1455 of yacc.c  */
-#line 420 "getdate.y"
+#line 419 "lib/getdate.y"
     {
         pc->day_ordinal = (yyvsp[(1) - (2)].textintval).value;
         pc->day_number = (yyvsp[(2) - (2)].intval);
@@ -1937,7 +1936,7 @@ yyreduce:
   case 31:
 
 /* Line 1455 of yacc.c  */
-#line 428 "getdate.y"
+#line 427 "lib/getdate.y"
     {
         pc->month = (yyvsp[(1) - (3)].textintval).value;
         pc->day = (yyvsp[(3) - (3)].textintval).value;
@@ -1947,7 +1946,7 @@ yyreduce:
   case 32:
 
 /* Line 1455 of yacc.c  */
-#line 433 "getdate.y"
+#line 432 "lib/getdate.y"
     {
         /* Interpret as YYYY/MM/DD if the first value has 4 or more digits,
            otherwise as MM/DD/YY.
@@ -1972,7 +1971,7 @@ yyreduce:
   case 33:
 
 /* Line 1455 of yacc.c  */
-#line 453 "getdate.y"
+#line 452 "lib/getdate.y"
     {
         /* ISO 8601 format.  YYYY-MM-DD.  */
         pc->year = (yyvsp[(1) - (3)].textintval);
@@ -1984,7 +1983,7 @@ yyreduce:
   case 34:
 
 /* Line 1455 of yacc.c  */
-#line 460 "getdate.y"
+#line 459 "lib/getdate.y"
     {
         /* e.g. 17-JUN-1992.  */
         pc->day = (yyvsp[(1) - (3)].textintval).value;
@@ -1997,7 +1996,7 @@ yyreduce:
   case 35:
 
 /* Line 1455 of yacc.c  */
-#line 468 "getdate.y"
+#line 467 "lib/getdate.y"
     {
         /* e.g. JUN-17-1992.  */
         pc->month = (yyvsp[(1) - (3)].intval);
@@ -2010,7 +2009,7 @@ yyreduce:
   case 36:
 
 /* Line 1455 of yacc.c  */
-#line 476 "getdate.y"
+#line 475 "lib/getdate.y"
     {
         pc->month = (yyvsp[(1) - (2)].intval);
         pc->day = (yyvsp[(2) - (2)].textintval).value;
@@ -2020,7 +2019,7 @@ yyreduce:
   case 37:
 
 /* Line 1455 of yacc.c  */
-#line 481 "getdate.y"
+#line 480 "lib/getdate.y"
     {
         pc->month = (yyvsp[(1) - (4)].intval);
         pc->day = (yyvsp[(2) - (4)].textintval).value;
@@ -2031,7 +2030,7 @@ yyreduce:
   case 38:
 
 /* Line 1455 of yacc.c  */
-#line 487 "getdate.y"
+#line 486 "lib/getdate.y"
     {
         pc->day = (yyvsp[(1) - (2)].textintval).value;
         pc->month = (yyvsp[(2) - (2)].intval);
@@ -2041,7 +2040,7 @@ yyreduce:
   case 39:
 
 /* Line 1455 of yacc.c  */
-#line 492 "getdate.y"
+#line 491 "lib/getdate.y"
     {
         pc->day = (yyvsp[(1) - (3)].textintval).value;
         pc->month = (yyvsp[(2) - (3)].intval);
@@ -2052,238 +2051,238 @@ yyreduce:
   case 40:
 
 /* Line 1455 of yacc.c  */
-#line 501 "getdate.y"
+#line 500 "lib/getdate.y"
     { apply_relative_time (pc, (yyvsp[(1) - (2)].rel), -1); }
     break;
 
   case 41:
 
 /* Line 1455 of yacc.c  */
-#line 503 "getdate.y"
+#line 502 "lib/getdate.y"
     { apply_relative_time (pc, (yyvsp[(1) - (1)].rel), 1); }
     break;
 
   case 42:
 
 /* Line 1455 of yacc.c  */
-#line 505 "getdate.y"
+#line 504 "lib/getdate.y"
     { apply_relative_time (pc, (yyvsp[(1) - (1)].rel), 1); }
     break;
 
   case 43:
 
 /* Line 1455 of yacc.c  */
-#line 510 "getdate.y"
+#line 509 "lib/getdate.y"
     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = (yyvsp[(1) - (2)].intval); }
     break;
 
   case 44:
 
 /* Line 1455 of yacc.c  */
-#line 512 "getdate.y"
+#line 511 "lib/getdate.y"
     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = (yyvsp[(1) - (2)].textintval).value; }
     break;
 
   case 45:
 
 /* Line 1455 of yacc.c  */
-#line 514 "getdate.y"
+#line 513 "lib/getdate.y"
     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = 1; }
     break;
 
   case 46:
 
 /* Line 1455 of yacc.c  */
-#line 516 "getdate.y"
+#line 515 "lib/getdate.y"
     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = (yyvsp[(1) - (2)].intval); }
     break;
 
   case 47:
 
 /* Line 1455 of yacc.c  */
-#line 518 "getdate.y"
+#line 517 "lib/getdate.y"
     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = (yyvsp[(1) - (2)].textintval).value; }
     break;
 
   case 48:
 
 /* Line 1455 of yacc.c  */
-#line 520 "getdate.y"
+#line 519 "lib/getdate.y"
     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = 1; }
     break;
 
   case 49:
 
 /* Line 1455 of yacc.c  */
-#line 522 "getdate.y"
+#line 521 "lib/getdate.y"
     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (2)].intval) * (yyvsp[(2) - (2)].intval); }
     break;
 
   case 50:
 
 /* Line 1455 of yacc.c  */
-#line 524 "getdate.y"
+#line 523 "lib/getdate.y"
     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (2)].textintval).value * (yyvsp[(2) - (2)].intval); }
     break;
 
   case 51:
 
 /* Line 1455 of yacc.c  */
-#line 526 "getdate.y"
+#line 525 "lib/getdate.y"
     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (1)].intval); }
     break;
 
   case 52:
 
 /* Line 1455 of yacc.c  */
-#line 528 "getdate.y"
+#line 527 "lib/getdate.y"
     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = (yyvsp[(1) - (2)].intval); }
     break;
 
   case 53:
 
 /* Line 1455 of yacc.c  */
-#line 530 "getdate.y"
+#line 529 "lib/getdate.y"
     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = (yyvsp[(1) - (2)].textintval).value; }
     break;
 
   case 54:
 
 /* Line 1455 of yacc.c  */
-#line 532 "getdate.y"
+#line 531 "lib/getdate.y"
     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = 1; }
     break;
 
   case 55:
 
 /* Line 1455 of yacc.c  */
-#line 534 "getdate.y"
+#line 533 "lib/getdate.y"
     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = (yyvsp[(1) - (2)].intval); }
     break;
 
   case 56:
 
 /* Line 1455 of yacc.c  */
-#line 536 "getdate.y"
+#line 535 "lib/getdate.y"
     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = (yyvsp[(1) - (2)].textintval).value; }
     break;
 
   case 57:
 
 /* Line 1455 of yacc.c  */
-#line 538 "getdate.y"
+#line 537 "lib/getdate.y"
     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = 1; }
     break;
 
   case 58:
 
 /* Line 1455 of yacc.c  */
-#line 540 "getdate.y"
+#line 539 "lib/getdate.y"
     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].intval); }
     break;
 
   case 59:
 
 /* Line 1455 of yacc.c  */
-#line 542 "getdate.y"
+#line 541 "lib/getdate.y"
     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].textintval).value; }
     break;
 
   case 60:
 
 /* Line 1455 of yacc.c  */
-#line 544 "getdate.y"
+#line 543 "lib/getdate.y"
     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].timespec).tv_sec; (yyval.rel).ns = (yyvsp[(1) - (2)].timespec).tv_nsec; }
     break;
 
   case 61:
 
 /* Line 1455 of yacc.c  */
-#line 546 "getdate.y"
+#line 545 "lib/getdate.y"
     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].timespec).tv_sec; (yyval.rel).ns = (yyvsp[(1) - (2)].timespec).tv_nsec; }
     break;
 
   case 62:
 
 /* Line 1455 of yacc.c  */
-#line 548 "getdate.y"
+#line 547 "lib/getdate.y"
     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = 1; }
     break;
 
   case 64:
 
 /* Line 1455 of yacc.c  */
-#line 554 "getdate.y"
+#line 553 "lib/getdate.y"
     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = (yyvsp[(1) - (2)].textintval).value; }
     break;
 
   case 65:
 
 /* Line 1455 of yacc.c  */
-#line 556 "getdate.y"
+#line 555 "lib/getdate.y"
     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = (yyvsp[(1) - (2)].textintval).value; }
     break;
 
   case 66:
 
 /* Line 1455 of yacc.c  */
-#line 558 "getdate.y"
+#line 557 "lib/getdate.y"
     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (2)].textintval).value * (yyvsp[(2) - (2)].intval); }
     break;
 
   case 67:
 
 /* Line 1455 of yacc.c  */
-#line 560 "getdate.y"
+#line 559 "lib/getdate.y"
     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = (yyvsp[(1) - (2)].textintval).value; }
     break;
 
   case 68:
 
 /* Line 1455 of yacc.c  */
-#line 562 "getdate.y"
+#line 561 "lib/getdate.y"
     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = (yyvsp[(1) - (2)].textintval).value; }
     break;
 
   case 69:
 
 /* Line 1455 of yacc.c  */
-#line 564 "getdate.y"
+#line 563 "lib/getdate.y"
     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].textintval).value; }
     break;
 
   case 70:
 
 /* Line 1455 of yacc.c  */
-#line 569 "getdate.y"
+#line 568 "lib/getdate.y"
     { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (1)].intval); }
     break;
 
   case 74:
 
 /* Line 1455 of yacc.c  */
-#line 577 "getdate.y"
+#line 576 "lib/getdate.y"
     { (yyval.timespec).tv_sec = (yyvsp[(1) - (1)].textintval).value; (yyval.timespec).tv_nsec = 0; }
     break;
 
   case 76:
 
 /* Line 1455 of yacc.c  */
-#line 583 "getdate.y"
+#line 582 "lib/getdate.y"
     { (yyval.timespec).tv_sec = (yyvsp[(1) - (1)].textintval).value; (yyval.timespec).tv_nsec = 0; }
     break;
 
   case 77:
 
 /* Line 1455 of yacc.c  */
-#line 588 "getdate.y"
+#line 587 "lib/getdate.y"
     { digits_to_date_time (pc, (yyvsp[(1) - (1)].textintval)); }
     break;
 
   case 78:
 
 /* Line 1455 of yacc.c  */
-#line 593 "getdate.y"
+#line 592 "lib/getdate.y"
     {
         /* Hybrid all-digit and relative offset, so that we accept e.g.,
            "YYYYMMDD +N days" as well as "YYYYMMDD N days".  */
@@ -2295,35 +2294,35 @@ yyreduce:
   case 79:
 
 /* Line 1455 of yacc.c  */
-#line 603 "getdate.y"
+#line 602 "lib/getdate.y"
     { (yyval.intval) = -1; }
     break;
 
   case 80:
 
 /* Line 1455 of yacc.c  */
-#line 605 "getdate.y"
+#line 604 "lib/getdate.y"
     { (yyval.intval) = (yyvsp[(2) - (2)].textintval).value; }
     break;
 
   case 81:
 
 /* Line 1455 of yacc.c  */
-#line 610 "getdate.y"
+#line 609 "lib/getdate.y"
     { (yyval.intval) = MER24; }
     break;
 
   case 82:
 
 /* Line 1455 of yacc.c  */
-#line 612 "getdate.y"
+#line 611 "lib/getdate.y"
     { (yyval.intval) = (yyvsp[(1) - (1)].intval); }
     break;
 
 
 
 /* Line 1455 of yacc.c  */
-#line 2327 "getdate.c"
+#line 2326 "lib/getdate.c"
       default: break;
     }
   YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
@@ -2535,7 +2534,7 @@ yyreturn:
 
 
 /* Line 1675 of yacc.c  */
-#line 615 "getdate.y"
+#line 614 "lib/getdate.y"
 
 
 static table const meridian_table[] =
@@ -3104,6 +3103,16 @@ mktime_ok (struct tm const *tm0, struct tm const *tm1, time_t t)
    Use heap allocation if TZ's length exceeds this.  */
 enum { TZBUFSIZE = 100 };
 
+/* Clone an object P of size S, with error checking.  There's no need
+   for xnmemdup (P, N, S), since xmemdup (P, N * S) works without any
+   need for an arithmetic overflow check.  */
+
+static void *
+xmemdup (void const *p, size_t s)
+{
+  return memcpy (xmalloc (s), p, s);
+}
+
 /* Return a copy of TZ, stored in TZBUF if it fits, and heap-allocated
    otherwise.  */
 static char *
diff --git a/lib/getdate.h b/lib/getdate.h
index 22cc2c0..ad1283c 100644
--- a/lib/getdate.h
+++ b/lib/getdate.h
@@ -19,4 +19,13 @@
 #include <stdbool.h>
 #include <time.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 bool get_date (struct timespec *, char const *, struct timespec const *);
+
+#ifdef __cplusplus
+}
+#endif
+
diff --git a/lib/getdate.y b/lib/getdate.y
index 445865b..d423f5b 100644
--- a/lib/getdate.y
+++ b/lib/getdate.y
@@ -31,6 +31,8 @@
 /* FIXME: Check for arithmetic overflow in all cases, not just
    some of them.  */
 
+#include "notmuch-private.h"	/* For xmalloc() */
+
 #include <config.h>
 
 #include "getdate.h"
@@ -66,9 +68,6 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "xalloc.h"
-
-
 /* ISDIGIT differs from isdigit, as follows:
    - Its arg may be any int or unsigned int; it need not be an unsigned char
      or EOF.
@@ -1180,6 +1179,16 @@ mktime_ok (struct tm const *tm0, struct tm const *tm1, time_t t)
    Use heap allocation if TZ's length exceeds this.  */
 enum { TZBUFSIZE = 100 };
 
+/* Clone an object P of size S, with error checking.  There's no need
+   for xnmemdup (P, N, S), since xmemdup (P, N * S) works without any
+   need for an arithmetic overflow check.  */
+
+static void *
+xmemdup (void const *p, size_t s)
+{
+  return memcpy (xmalloc (s), p, s);
+}
+
 /* Return a copy of TZ, stored in TZBUF if it fits, and heap-allocated
    otherwise.  */
 static char *
-- 
1.7.1



More information about the notmuch mailing list