[Patch v2 1/4] build: integrate building ruby bindings into notmuch build process
[notmuch-archives.git] / 02 / d780adf25b0dfef8e3dac59a0911a899a95145
1 Return-Path: <tomi.ollila@iki.fi>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 322CE431FB6\r
6         for <notmuch@notmuchmail.org>; Mon,  5 Nov 2012 04:09:35 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id B6OED79nH9wW for <notmuch@notmuchmail.org>;\r
16         Mon,  5 Nov 2012 04:09:34 -0800 (PST)\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
18         by olra.theworths.org (Postfix) with ESMTP id 0B550431FAE\r
19         for <notmuch@notmuchmail.org>; Mon,  5 Nov 2012 04:09:34 -0800 (PST)\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
21         by guru.guru-group.fi (Postfix) with ESMTP id 98973100094;\r
22         Mon,  5 Nov 2012 14:09:33 +0200 (EET)\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>\r
24 To: Blake Jones <blakej@foo.net>, Jani Nikula <jani@nikula.org>\r
25 Subject: Re: [PATCH 10/10] timegm: add portable implementation (Solaris\r
26         support)\r
27 In-Reply-To: <12349.1352043650@foo.net>\r
28 References: <12349.1352043650@foo.net>\r
29 User-Agent: Notmuch/0.14+81~gb8371cd (http://notmuchmail.org) Emacs/24.2.1\r
30         (x86_64-unknown-linux-gnu)\r
31 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
32         $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
33         !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
34 Date: Mon, 05 Nov 2012 14:09:33 +0200\r
35 Message-ID: <m2txt4jloi.fsf@guru.guru-group.fi>\r
36 MIME-Version: 1.0\r
37 Content-Type: multipart/mixed; boundary="=-=-="\r
38 Cc: notmuch@notmuchmail.org\r
39 X-BeenThere: notmuch@notmuchmail.org\r
40 X-Mailman-Version: 2.1.13\r
41 Precedence: list\r
42 List-Id: "Use and development of the notmuch mail system."\r
43         <notmuch.notmuchmail.org>\r
44 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
45         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
46 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
47 List-Post: <mailto:notmuch@notmuchmail.org>\r
48 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
49 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
50         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
51 X-List-Received-Date: Mon, 05 Nov 2012 12:09:35 -0000\r
52 \r
53 --=-=-=\r
54 Content-Type: text/plain\r
55 \r
56 On Sun, Nov 04 2012, Blake Jones wrote:\r
57 \r
58 > Hi Jani,\r
59 >\r
60 >> I'd prefer to use timegm() where available, and the suggested\r
61 >> alternative [1] elsewhere.\r
62 >> \r
63 >> [1] http://www.kernel.org/doc/man-pages/online/pages/man3/timegm.3.html\r
64 >\r
65 > I considered this alternative, but decided against it because it's\r
66 > completely MT-unsafe.  I don't know whether libnotmuch itself is\r
67 > MT-safe, but a process which called this routine in one thread would\r
68 > temporarily throw off any timezone-related work that any other threads\r
69 > were doing, even if they weren't using libnotmuch.\r
70 \r
71 Yet another idea for an alternative. Compile by entering 'sh xtimegm.c'\r
72 and then run ./xtimegm\r
73 \r
74 Simple cases seems to work. Dst change may (or then may not) give one\r
75 hour difference to the expected. The test "coverage" could be easily\r
76 expanded to that ;)\r
77 \r
78 Hmm, I also found this:\r
79 http://lists.gnu.org/archive/html/bug-gnulib/2003-09/msg00004.html\r
80 which does 2 mktime's and one gmtime_r (without allocating tg!)...\r
81 Pick any of these 3 -- or something different (e.g. less NIH if there is)\r
82 \r
83 > Blake\r
84 \r
85 \r
86 Tomi\r
87 \r
88 \r
89 --=-=-=\r
90 Content-Type: text/plain; charset=utf-8\r
91 Content-Disposition: inline; filename=xtimegm.c\r
92 Content-Transfer-Encoding: quoted-printable\r
93 Content-Description: yet another attempt for timegm() implementation\r
94 \r
95 #if 0 /* -*- mode: c; c-file-style: "stroustrup"; tab-width: 8; -*-\r
96  set -eu; trg=3D`basename "$0" .c`; rm -f "$trg"\r
97  WARN=3D"-Wall -Wno-long-long -Wstrict-prototypes -pedantic"\r
98  WARN=3D"$WARN -Wcast-align -Wpointer-arith " # -Wfloat-equal #-Werror\r
99  WARN=3D"$WARN -W -Wwrite-strings -Wcast-qual -Wshadow" # -Wconversion\r
100  case ${1-} in '') set x -O2; shift; esac\r
101  #case ${1-} in '') set x -ggdb; shift; esac\r
102  set -x; exec ${CC:-gcc} -std=3Dc99 $WARN "$@" -o "$trg" "$0"\r
103  exit $?\r
104  */\r
105 #endif\r
106 /*\r
107  * $ xtimegm.c $\r
108  *\r
109  * Author: Tomi Ollila -- too =C3=A4t iki piste fi\r
110  *\r
111  * Created: Mon 05 Nov 2012 07:54:35 EET too\r
112  * Last modified: Mon 05 Nov 2012 08:27:52 EET too\r
113  *\r
114  * Public domain.\r
115  */\r
116 \r
117 #define _POSIX_SOURCE\r
118 \r
119 #include <time.h>\r
120 \r
121 time_t xtimegm(struct tm * atm)\r
122 {\r
123     struct tm ltm;\r
124     time_t t =3D mktime(atm);\r
125     int sd;\r
126     int dd;\r
127 \r
128     (void)gmtime_r(&t, &ltm);\r
129 \r
130     sd =3D (atm->tm_hour - ltm.tm_hour) * 3600 + (atm->tm_min - ltm.tm_min)=\r
131  * 60\r
132         + (atm->tm_sec - ltm.tm_sec);\r
133 \r
134     dd =3D (atm->tm_mday - ltm.tm_mday);\r
135 \r
136     if (dd =3D=3D 0)\r
137         ;\r
138     else if (dd =3D=3D -1) sd -=3D 86400;  /* e.g. 3, 2 */\r
139     else if (dd =3D=3D 1)  sd +=3D 86400;  /* e.g. 2, 3 */\r
140     else if (dd > 1)   sd -=3D 86400;  /* e.g. 1, 31 */\r
141     else /* dd < 1 */  sd +=3D 86400;  /* e.g. 31, 1 */\r
142 \r
143     printf("sd: %d\n", sd); // test line.\r
144 \r
145     return t + sd;\r
146 }\r
147 \r
148 #include <stdio.h>\r
149 void test(int hour, int mday)\r
150 {\r
151     struct tm mtm;\r
152     time_t t;\r
153     struct tm * otm;\r
154 \r
155     mtm.tm_sec =3D 0;\r
156     mtm.tm_min =3D 0;\r
157     mtm.tm_hour =3D hour;\r
158 \r
159     mtm.tm_mday =3D mday;\r
160     mtm.tm_mon =3D 11;\r
161     mtm.tm_year =3D 100;\r
162     mtm.tm_isdst =3D -1;\r
163 \r
164     t =3D xtimegm(&mtm);\r
165     otm =3D gmtime(&t);\r
166 \r
167     printf("%2d %02d:%02d:%02d\n", otm->tm_mday,\r
168            otm->tm_hour, otm->tm_min, otm->tm_sec);\r
169 }\r
170 \r
171 void tests(const char * tz)\r
172 {\r
173     printf("TZ: %s\n", tz);\r
174     setenv("TZ", tz, 1);\r
175     tzset();\r
176     test(23, 30);\r
177     test(23, 31);\r
178     test(23, 1);\r
179     test(23, 2);\r
180     printf("--\n");\r
181     test(1, 30);\r
182     test(1, 31);\r
183     test(1, 1);\r
184     test(1, 2);\r
185 \r
186 }\r
187 \r
188 int main(int argc, char * argv[])\r
189 {\r
190     // ls /usr/share/zoneinfo...\r
191     tests("EET");\r
192     tests("MST");\r
193     tests("HST");\r
194     tests("NZ");\r
195 \r
196     return 0;\r
197 }\r
198 \r
199 --=-=-=--\r