Changeset 12644 in project for chicken


Ignore:
Timestamp:
11/29/08 04:41:31 (11 years ago)
Author:
Kon Lovett
Message:

Make sure tzname, etc. variables are set before use. Doubtful if tzname will be used before a time.h proc is used but to be safe.

Location:
chicken/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • chicken/trunk/posixunix.scm

    r12625 r12644  
    3232  (usual-integrations)
    3333  (hide ##sys#stat group-member _get-groups _ensure-groups posix-error
    34         ##sys#terminal-check)
     34              ##sys#terminal-check
     35              check-time-vector)
    3536  (foreign-declare #<<EOF
    3637#include <signal.h>
     
    357358#endif
    358359
    359 #define C_tm_set_08(v) \
    360         (memset(&C_tm, 0, sizeof(struct tm)), \
    361         C_tm.tm_sec = C_unfix(C_block_item(v, 0)), \
    362         C_tm.tm_min = C_unfix(C_block_item(v, 1)), \
    363         C_tm.tm_hour = C_unfix(C_block_item(v, 2)), \
    364         C_tm.tm_mday = C_unfix(C_block_item(v, 3)), \
    365         C_tm.tm_mon = C_unfix(C_block_item(v, 4)), \
    366         C_tm.tm_year = C_unfix(C_block_item(v, 5)), \
    367         C_tm.tm_wday = C_unfix(C_block_item(v, 6)), \
    368         C_tm.tm_yday = C_unfix(C_block_item(v, 7)), \
    369         C_tm.tm_isdst = (C_block_item(v, 8) != C_SCHEME_FALSE))
    370 
    371 #define C_tm_set_9(v) \
    372         (C_tm.tm_gmtoff = C_unfix(C_block_item(v, 9)))
    373 
    374 #define C_tm_get_08(v) \
    375         (C_set_block_item(v, 0, C_fix(C_tm.tm_sec)), \
    376         C_set_block_item(v, 1, C_fix(C_tm.tm_min)), \
    377         C_set_block_item(v, 2, C_fix(C_tm.tm_hour)), \
    378         C_set_block_item(v, 3, C_fix(C_tm.tm_mday)), \
    379         C_set_block_item(v, 4, C_fix(C_tm.tm_mon)), \
    380         C_set_block_item(v, 5, C_fix(C_tm.tm_year)), \
    381         C_set_block_item(v, 6, C_fix(C_tm.tm_wday)), \
    382         C_set_block_item(v, 7, C_fix(C_tm.tm_yday)), \
    383         C_set_block_item(v, 8, (C_tm.tm_isdst ? C_SCHEME_TRUE : C_SCHEME_FALSE)))
    384 
    385 #define C_tm_get_9(v) \
    386         (C_set_block_item(v, 9, C_fix(C_tm.tm_gmtoff)))
     360#define cpy_tmvec_to_tmstc08(ptm, v) \
     361    (memset((ptm), 0, sizeof(struct tm)), \
     362    (ptm)->tm_sec = C_unfix(C_block_item((v), 0)), \
     363    (ptm)->tm_min = C_unfix(C_block_item((v), 1)), \
     364    (ptm)->tm_hour = C_unfix(C_block_item((v), 2)), \
     365    (ptm)->tm_mday = C_unfix(C_block_item((v), 3)), \
     366    (ptm)->tm_mon = C_unfix(C_block_item((v), 4)), \
     367    (ptm)->tm_year = C_unfix(C_block_item((v), 5)), \
     368    (ptm)->tm_wday = C_unfix(C_block_item((v), 6)), \
     369    (ptm)->tm_yday = C_unfix(C_block_item((v), 7)), \
     370    (ptm)->tm_isdst = (C_block_item((v), 8) != C_SCHEME_FALSE))
     371
     372#define cpy_tmvec_to_tmstc9(ptm, v) \
     373    (((struct tm *)ptm)->tm_gmtoff = C_unfix(C_block_item((v), 9)))
     374
     375#define cpy_tmstc08_to_tmvec(v, ptm) \
     376    (C_set_block_item((v), 0, C_fix(((struct tm *)ptm)->tm_sec)), \
     377    C_set_block_item((v), 1, C_fix((ptm)->tm_min)), \
     378    C_set_block_item((v), 2, C_fix((ptm)->tm_hour)), \
     379    C_set_block_item((v), 3, C_fix((ptm)->tm_mday)), \
     380    C_set_block_item((v), 4, C_fix((ptm)->tm_mon)), \
     381    C_set_block_item((v), 5, C_fix((ptm)->tm_year)), \
     382    C_set_block_item((v), 6, C_fix((ptm)->tm_wday)), \
     383    C_set_block_item((v), 7, C_fix((ptm)->tm_yday)), \
     384    C_set_block_item((v), 8, ((ptm)->tm_isdst ? C_SCHEME_TRUE : C_SCHEME_FALSE)))
     385
     386#define cpy_tmstc9_to_tmvec(v, ptm) \
     387    (C_set_block_item((v), 9, C_fix((ptm)->tm_gmtoff)))
     388
     389#define C_tm_set_08(v)  cpy_tmvec_to_tmstc08( &C_tm, (v) )
     390#define C_tm_set_9(v)   cpy_tmvec_to_tmstc9( &C_tm, (v) )
     391
     392#define C_tm_get_08(v)  cpy_tmstc08_to_tmvec( (v), &C_tm )
     393#define C_tm_get_9(v)   cpy_tmstc9_to_tmvec( (v), &C_tm )
    387394
    388395#if !defined(C_GNU_ENV) || defined(__CYGWIN__) || defined(__uClinux__)
    389396
    390397static struct tm *
    391 C_tm_set (C_word v)
     398C_tm_set( C_word v )
    392399{
    393   C_tm_set_08 (v);
     400  C_tm_set_08( v );
    394401  return &C_tm;
    395402}
    396403
    397404static C_word
    398 C_tm_get (C_word v)
     405C_tm_get( C_word v )
    399406{
    400   C_tm_get_08 (v);
     407  C_tm_get_08( v );
    401408  return v;
    402409}
     
    405412
    406413static struct tm *
    407 C_tm_set (C_word v)
     414C_tm_set( C_word v )
    408415{
    409   C_tm_set_08 (v);
    410   C_tm_set_9 (v);
     416  C_tm_set_08( v );
     417  C_tm_set_9( v );
    411418  return &C_tm;
    412419}
    413420
    414421static C_word
    415 C_tm_get (C_word v)
     422C_tm_get( C_word v )
    416423{
    417   C_tm_get_08 (v);
    418   C_tm_get_9 (v);
     424  C_tm_get_08( v );
     425  C_tm_get_9( v );
    419426  return v;
    420427}
     
    19391946;;; Time related things:
    19401947
     1948(define (check-time-vector loc tm)
     1949  (##sys#check-vector tm loc)
     1950  (when (fx< (##sys#size tm) 10)
     1951    (##sys#error loc "time vector too short" tm) ) )
     1952
    19411953(define (seconds->local-time secs)
    19421954  (##sys#check-number secs 'seconds->local-time)
     
    19501962  (let ([ctime (foreign-lambda c-string "C_ctime" integer)])
    19511963    (lambda (secs)
     1964      (##sys#check-number secs 'seconds->string)
    19521965      (let ([str (ctime secs)])
    19531966        (if str
     
    19591972        [strftime (foreign-lambda c-string "C_strftime" scheme-object scheme-object)])
    19601973    (lambda (tm #!optional fmt)
    1961       (##sys#check-vector tm 'time->string)
    1962       (when (fx< (##sys#size tm) 10) (##sys#error 'time->string "time vector too short" tm))
     1974      (check-time-vector 'time->string tm)
    19631975      (if fmt
    19641976          (begin
     
    19791991
    19801992(define (local-time->seconds tm)
    1981   (##sys#check-vector tm 'local-time->seconds)
    1982   (when (fx< (##sys#size tm) 10) (##sys#error 'local-time->seconds "time vector too short" tm))
     1993  (check-time-vector 'local-time->seconds tm)
    19831994  (if (##core#inline "C_mktime" tm)
    19841995      (##sys#cons-flonum)
     
    19861997
    19871998(define (utc-time->seconds tm)
    1988   (##sys#check-vector tm 'utc-time->seconds)
    1989   (when (fx< (##sys#size tm) 10) (##sys#error 'utc-time->seconds "time vector too short" tm))
     1999  (check-time-vector 'utc-time->seconds tm)
    19902000  (if (##core#inline "C_timegm" tm)
    19912001      (##sys#cons-flonum)
  • chicken/trunk/posixwin.scm

    r12342 r12644  
    7070  (usual-integrations)
    7171  (hide ##sys#stat posix-error
    72         $quote-args-list $exec-setup $exec-teardown)
     72        $quote-args-list $exec-setup $exec-teardown
     73        check-time-vector)
    7374  (foreign-declare #<<EOF
    7475#ifndef WIN32_LEAN_AND_MEAN
     
    16841685;;; Time related things:
    16851686
     1687(define (check-time-vector loc tm)
     1688  (##sys#check-vector tm loc)
     1689  (when (fx< (##sys#size tm) 10)
     1690    (##sys#error loc "time vector too short" tm) ) )
     1691
    16861692(define (seconds->local-time secs)
    16871693  (##sys#check-number secs 'seconds->local-time)
     
    17041710        [strftime (foreign-lambda c-string "C_strftime" scheme-object scheme-object)])
    17051711    (lambda (tm #!optional fmt)
    1706       (##sys#check-vector tm 'time->string)
    1707       (when (fx< (##sys#size tm) 10) (##sys#error 'time->string "time vector too short" tm))
     1712      (check-time-vector 'time->string tm)
    17081713      (if fmt
    17091714          (begin
     
    17171722
    17181723(define (local-time->seconds tm)
    1719   (##sys#check-vector tm 'local-time->seconds)
    1720   (when (fx< (##sys#size tm) 10) (##sys#error 'local-time->seconds "time vector too short" tm))
     1724  (check-time-vector 'local-time->seconds tm)
    17211725  (if (##core#inline "C_mktime" tm)
    17221726      (##sys#cons-flonum)
     
    17251729(define local-timezone-abbreviation
    17261730  (foreign-lambda* c-string ()
    1727    "char *z = (daylight ? _tzname[1] : _tzname[0]);"
     1731   "char *z = (_daylight ? _tzname[1] : _tzname[0]);\n"
    17281732   "return(z);") )
    17291733
  • chicken/trunk/runtime.c

    r12631 r12644  
    634634  int i;
    635635
    636 #ifndef C_NONUNIX
     636  /*FIXME Should have C_tzset in chicken.h? */
     637#ifdef C_NONUNIX
     638  C_startup_time_seconds = (time_t)0;
     639# if defined(_MSC_VER) || defined(__MINGW32__)
     640  /* Make sure _tzname, _timezone, and _daylight are set */
     641  _tzset();
     642# elif defined(__WATCOMC__) || defined(__DJGPP__)
     643  /* Make sure tzname, timezone, and daylight are set */
     644  tzset();
     645# endif
     646#else
    637647  struct timeval tv;
    638648  C_gettimeofday(&tv, NULL);
    639649  C_startup_time_seconds = tv.tv_sec;
    640 #else
    641   C_startup_time_seconds = (time_t)0;
     650  /* Make sure tzname, timezone, and daylight are set */
     651  tzset();
    642652#endif
    643653
Note: See TracChangeset for help on using the changeset viewer.