Overview
| Artifact ID: | 832e90529eb14fcb6a209aa438c1d2a6c721e895 |
|---|---|
| Ticket: | 424119ffffffffffffffffffffffffffffffffff |
| Date: | 2001-05-15 09:04:47 |
| User: | hobbs |
| Artifact Attached: | 0bf668e3adbaf0b946c08321b5bd6c225613690a |
| Filename: | rentrant_time_functions_patch.txt |
| Description: | Patch to make time functions reentrant |
Content:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460diff -c -r orig/tcl8.3.2/generic/tclClock.c t832/tcl8.3.2/generic/tclClock.c *** orig/tcl8.3.2/generic/tclClock.c Mon Aug 7 23:30:56 2000 --- t832/tcl8.3.2/generic/tclClock.c Wed Apr 11 23:45:34 2001 *************** *** 257,263 **** int useGMT; /* Boolean */ char *format; /* Format string */ { ! struct tm *timeDataPtr; Tcl_DString buffer, uniBuffer; int bufSize; char *p; --- 257,263 ---- int useGMT; /* Boolean */ char *format; /* Format string */ { ! struct tm timeData; Tcl_DString buffer, uniBuffer; int bufSize; char *p; *************** *** 313,319 **** #endif tclockVal = clockVal; ! timeDataPtr = TclpGetDate((TclpTime_t) &tclockVal, useGMT); /* * Make a guess at the upper limit on the substituted string size --- 313,319 ---- #endif tclockVal = clockVal; ! TclpGetDate((TclpTime_t) &tclockVal, useGMT,&timeData); /* * Make a guess at the upper limit on the substituted string size *************** *** 332,338 **** Tcl_MutexLock(&clockMutex); result = TclpStrftime(buffer.string, (unsigned int) bufSize, format, ! timeDataPtr); Tcl_MutexUnlock(&clockMutex); #ifndef HAVE_TM_ZONE --- 332,338 ---- Tcl_MutexLock(&clockMutex); result = TclpStrftime(buffer.string, (unsigned int) bufSize, format, ! &timeData); Tcl_MutexUnlock(&clockMutex); #ifndef HAVE_TM_ZONE diff -c -r orig/tcl8.3.2/generic/tclDate.c t832/tcl8.3.2/generic/tclDate.c *** orig/tcl8.3.2/generic/tclDate.c Mon Aug 7 23:30:36 2000 --- t832/tcl8.3.2/generic/tclDate.c Wed Apr 11 23:37:17 2001 *************** *** 452,457 **** --- 452,458 ---- time_t tod; time_t Julian; int i; + struct tm tms; /* Figure out how many days are in February for the given year. * Every year divisible by 4 is a leap year. *************** *** 489,496 **** Julian += tod; /* Perform a preliminary DST compensation ?? */ if (DSTmode == DSTon ! || (DSTmode == DSTmaybe && TclpGetDate((TclpTime_t)&Julian, 0)->tm_isdst)) Julian -= 60 * 60; *TimePtr = Julian; return 0; --- 490,500 ---- Julian += tod; /* Perform a preliminary DST compensation ?? */ + + TclpGetDate((TclpTime_t)&Julian,0,&tms); + if (DSTmode == DSTon ! || (DSTmode == DSTmaybe && tms.tm_isdst)) Julian -= 60 * 60; *TimePtr = Julian; return 0; *************** *** 504,511 **** { time_t StartDay; time_t FutureDay; ! StartDay = (TclpGetDate((TclpTime_t)&Start, 0)->tm_hour + 1) % 24; ! FutureDay = (TclpGetDate((TclpTime_t)&Future, 0)->tm_hour + 1) % 24; return (Future - Start) + (StartDay - FutureDay) * 60L * 60L; } --- 508,519 ---- { time_t StartDay; time_t FutureDay; ! struct tm tms; ! ! TclpGetDate((TclpTime_t)&Start,0,&tms); ! StartDay = (tms.tm_hour + 1) % 24; ! TclpGetDate((TclpTime_t)&Future,0,&tms); ! FutureDay = (tms.tm_hour + 1) % 24; return (Future - Start) + (StartDay - FutureDay) * 60L * 60L; } *************** *** 516,527 **** time_t DayOrdinal; time_t DayNumber; { ! struct tm *tm; time_t now; now = Start; ! tm = TclpGetDate((TclpTime_t)&now, 0); ! now += SECSPERDAY * ((DayNumber - tm->tm_wday + 7) % 7); now += 7 * SECSPERDAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1); return DSTcorrect(Start, now); } --- 524,535 ---- time_t DayOrdinal; time_t DayNumber; { ! struct tm tm; time_t now; now = Start; ! TclpGetDate((TclpTime_t)&now, 0,&tm); ! now += SECSPERDAY * ((DayNumber - tm.tm_wday + 7) % 7); now += 7 * SECSPERDAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1); return DSTcorrect(Start, now); } *************** *** 532,554 **** time_t MonthOrdinal; time_t MonthNumber; { ! struct tm *tm; time_t now; int result; now = Start; ! tm = TclpGetDate((TclpTime_t)&now, 0); /* To compute the next n'th month, we use this alg: * add n to year value * if currentMonth < requestedMonth decrement year value by 1 (so that * doing next february from january gives us february of the current year) * set day to 1, time to 0 */ ! tm->tm_year += MonthOrdinal; ! if (tm->tm_mon < MonthNumber - 1) { ! tm->tm_year--; } ! result = Convert(MonthNumber, (time_t) 1, tm->tm_year + TM_YEAR_BASE, (time_t) 0, (time_t) 0, (time_t) 0, MER24, DSTmaybe, &now); if (result < 0) { return 0; --- 540,562 ---- time_t MonthOrdinal; time_t MonthNumber; { ! struct tm tm; time_t now; int result; now = Start; ! TclpGetDate((TclpTime_t)&now, 0, &tm); /* To compute the next n'th month, we use this alg: * add n to year value * if currentMonth < requestedMonth decrement year value by 1 (so that * doing next february from january gives us february of the current year) * set day to 1, time to 0 */ ! tm.tm_year += MonthOrdinal; ! if (tm.tm_mon < MonthNumber - 1) { ! tm.tm_year--; } ! result = Convert(MonthNumber, (time_t) 1, tm.tm_year + TM_YEAR_BASE, (time_t) 0, (time_t) 0, (time_t) 0, MER24, DSTmaybe, &now); if (result < 0) { return 0; *************** *** 562,568 **** time_t RelMonth; time_t *TimePtr; { ! struct tm *tm; time_t Month; time_t Year; time_t Julian; --- 570,576 ---- time_t RelMonth; time_t *TimePtr; { ! struct tm tm; time_t Month; time_t Year; time_t Julian; *************** *** 572,583 **** *TimePtr = 0; return 0; } ! tm = TclpGetDate((TclpTime_t)&Start, 0); ! Month = 12 * (tm->tm_year + TM_YEAR_BASE) + tm->tm_mon + RelMonth; Year = Month / 12; Month = Month % 12 + 1; ! result = Convert(Month, (time_t) tm->tm_mday, Year, ! (time_t) tm->tm_hour, (time_t) tm->tm_min, (time_t) tm->tm_sec, MER24, DSTmaybe, &Julian); /* * The following iteration takes into account the case were we jump --- 580,591 ---- *TimePtr = 0; return 0; } ! TclpGetDate((TclpTime_t)&Start, 0,&tm); ! Month = 12 * (tm.tm_year + TM_YEAR_BASE) + tm.tm_mon + RelMonth; Year = Month / 12; Month = Month % 12 + 1; ! result = Convert(Month, (time_t) tm.tm_mday, Year, ! (time_t) tm.tm_hour, (time_t) tm.tm_min, (time_t) tm.tm_sec, MER24, DSTmaybe, &Julian); /* * The following iteration takes into account the case were we jump *************** *** 587,596 **** * 28 (which always works unless the date is bad in another way). */ ! while ((result != 0) && (tm->tm_mday > 28)) { ! tm->tm_mday--; ! result = Convert(Month, (time_t) tm->tm_mday, Year, ! (time_t) tm->tm_hour, (time_t) tm->tm_min, (time_t) tm->tm_sec, MER24, DSTmaybe, &Julian); } if (result != 0) { --- 595,604 ---- * 28 (which always works unless the date is bad in another way). */ ! while ((result != 0) && (tm.tm_mday > 28)) { ! tm.tm_mday--; ! result = Convert(Month, (time_t) tm.tm_mday, Year, ! (time_t) tm.tm_hour, (time_t) tm.tm_min, (time_t) tm.tm_sec, MER24, DSTmaybe, &Julian); } if (result != 0) { *************** *** 819,825 **** long zone; unsigned long *timePtr; { ! struct tm *tm; time_t Start; time_t Time; time_t tod; --- 827,833 ---- long zone; unsigned long *timePtr; { ! struct tm tm; time_t Start; time_t Time; time_t tod; *************** *** 828,838 **** TclDateInput = p; /* now has to be cast to a time_t for 64bit compliance */ Start = now; ! tm = TclpGetDate((TclpTime_t) &Start, 0); ! thisyear = tm->tm_year + TM_YEAR_BASE; TclDateYear = thisyear; ! TclDateMonth = tm->tm_mon + 1; ! TclDateDay = tm->tm_mday; TclDateTimezone = zone; if (zone == -50000) { TclDateDSTmode = DSToff; /* assume GMT */ --- 836,846 ---- TclDateInput = p; /* now has to be cast to a time_t for 64bit compliance */ Start = now; ! TclpGetDate((TclpTime_t) &Start, 0, &tm); ! thisyear = tm.tm_year + TM_YEAR_BASE; TclDateYear = thisyear; ! TclDateMonth = tm.tm_mon + 1; ! TclDateDay = tm.tm_mday; TclDateTimezone = zone; if (zone == -50000) { TclDateDSTmode = DSToff; /* assume GMT */ *************** *** 889,896 **** } else { Start = now; if (!TclDateHaveRel) { ! Start -= ((tm->tm_hour * 60L * 60L) + ! tm->tm_min * 60L) + tm->tm_sec; } } --- 897,904 ---- } else { Start = now; if (!TclDateHaveRel) { ! Start -= ((tm.tm_hour * 60L * 60L) + ! tm.tm_min * 60L) + tm.tm_sec; } } diff -c -r orig/tcl8.3.2/generic/tclIntDecls.h t832/tcl8.3.2/generic/tclIntDecls.h *** orig/tcl8.3.2/generic/tclIntDecls.h Thu Jul 27 03:39:18 2000 --- t832/tcl8.3.2/generic/tclIntDecls.h Wed Apr 11 23:37:25 2001 *************** *** 450,456 **** /* 132 */ EXTERN int TclpHasSockets _ANSI_ARGS_((Tcl_Interp * interp)); /* 133 */ ! EXTERN struct tm * TclpGetDate _ANSI_ARGS_((TclpTime_t time, int useGMT)); /* 134 */ EXTERN size_t TclpStrftime _ANSI_ARGS_((char * s, size_t maxsize, CONST char * format, CONST struct tm * t)); --- 450,456 ---- /* 132 */ EXTERN int TclpHasSockets _ANSI_ARGS_((Tcl_Interp * interp)); /* 133 */ ! EXTERN struct tm * TclpGetDate _ANSI_ARGS_((TclpTime_t time, int useGMT, struct tm * t)); /* 134 */ EXTERN size_t TclpStrftime _ANSI_ARGS_((char * s, size_t maxsize, CONST char * format, CONST struct tm * t)); diff -c -r orig/tcl8.3.2/unix/tclUnixTime.c t832/tcl8.3.2/unix/tclUnixTime.c *** orig/tcl8.3.2/unix/tclUnixTime.c Fri Jan 14 23:15:52 2000 --- t832/tcl8.3.2/unix/tclUnixTime.c Wed Apr 11 23:37:31 2001 *************** *** 114,125 **** #if defined(HAVE_TM_TZADJ) # define TCL_GOT_TIMEZONE time_t curTime = (time_t) currentTime; ! struct tm *timeDataPtr = localtime(&curTime); int timeZone; ! timeZone = timeDataPtr->tm_tzadj / 60; ! if (timeDataPtr->tm_isdst) { timeZone += 60; } --- 114,126 ---- #if defined(HAVE_TM_TZADJ) # define TCL_GOT_TIMEZONE + struct tm timeData; time_t curTime = (time_t) currentTime; ! localtime_r(&curTime,&timeData); int timeZone; ! timeZone = timeData.tm_tzadj / 60; ! if (timeData.tm_isdst) { timeZone += 60; } *************** *** 129,139 **** #if defined(HAVE_TM_GMTOFF) && !defined (TCL_GOT_TIMEZONE) # define TCL_GOT_TIMEZONE time_t curTime = (time_t) currentTime; ! struct tm *timeDataPtr = localtime(&curTime); int timeZone; ! timeZone = -(timeDataPtr->tm_gmtoff / 60); ! if (timeDataPtr->tm_isdst) { timeZone += 60; } --- 130,141 ---- #if defined(HAVE_TM_GMTOFF) && !defined (TCL_GOT_TIMEZONE) # define TCL_GOT_TIMEZONE time_t curTime = (time_t) currentTime; ! struct tm timeData; int timeZone; ! localtime_r(&curTime,&timeData); ! timeZone = -(timeData.tm_gmtoff / 60); ! if (timeData.tm_isdst) { timeZone += 60; } *************** *** 150,160 **** int timeZone; time_t tt; ! struct tm *stm; tt = 849268800L; /* 1996-11-29 12:00:00 GMT */ ! stm = localtime(&tt); /* eg 1996-11-29 6:00:00 CST6CDT */ /* The calculation below assumes a max of +12 or -12 hours from GMT */ ! timeZone = (12 - stm->tm_hour)*60 + (0 - stm->tm_min); return timeZone; /* eg +360 for CST6CDT */ #endif --- 152,163 ---- int timeZone; time_t tt; ! struct tm stm; ! tt = 849268800L; /* 1996-11-29 12:00:00 GMT */ ! localtime_r(&tt,&stm); /* eg 1996-11-29 6:00:00 CST6CDT */ /* The calculation below assumes a max of +12 or -12 hours from GMT */ ! timeZone = (12 - stm.tm_hour)*60 + (0 - stm.tm_min); return timeZone; /* eg +360 for CST6CDT */ #endif *************** *** 260,277 **** *---------------------------------------------------------------------- */ ! struct tm * ! TclpGetDate(time, useGMT) TclpTime_t time; int useGMT; { CONST time_t *tp = (CONST time_t *)time; if (useGMT) { ! return gmtime(tp); } else { ! return localtime(tp); } } /* --- 263,282 ---- *---------------------------------------------------------------------- */ ! struct tm * ! TclpGetDate(time, useGMT,tmptr) TclpTime_t time; int useGMT; + struct tm *tmptr; { CONST time_t *tp = (CONST time_t *)time; if (useGMT) { ! gmtime_r(tp,tmptr); } else { ! localtime_r(tp,tmptr); } + return tmptr; } /*