At 2006-03-28T02:33:16+05:30, N. Raghavendra wrote:

> However, when I evaluate
>
> (%localtime (sys:int-sap 0))
>
> I get an "Error in function UNIX::SIGSEGV-HANDLER: Segmentation
> Violation at #x2810C728.  [Condition of type SIMPLE-ERROR]".

I realized later that I was calling the function wrongly.  I also
found some messages on the Web about segmentation faults produced by
the default `optimize' settings.  This works fine now:

(eval-when (:compile-toplevel :load-toplevel :execute)
  (proclaim '(optimize (speed 0) (safety 3))))

(defpackage #:time-zone-alien
  (:nicknames #:tz-alien)
  (:use #:common-lisp
        #:alien
        #:c-call))

(in-package #:time-zone-alien)

(def-alien-type nil
    (struct tm
            (tm-sec int)
            (tm-min int)
            (tm-hour int)
            (tm-mday int)
            (tm-mon int)
            (tm-year int)
            (tm-wday int)
            (tm-yday int)
            (tm-isdst int)
            (tm-gmtoff long)
            (tm-zone c-string)))

(def-alien-type time-t (integer 32))

(def-alien-routine ("time" %time) time-t
  (tp (* time-t)))

(def-alien-routine ("localtime" %localtime) (* (struct tm))
  (tp (* time-t)))

TZ-ALIEN> (with-alien ((now time-t (%time (sys:int-sap 0))))
           (%localtime (addr now)))
#<Alien (*
         (STRUCT TM (TM-SEC (SIGNED 32)) (TM-MIN (SIGNED 32))
          (TM-HOUR (SIGNED 32)) (TM-MDAY (SIGNED 32)) (TM-MON (SIGNED
           32))
          (TM-YEAR (SIGNED 32)) (TM-WDAY (SIGNED 32)) (TM-YDAY (SIGNED
           32))
          (TM-ISDST (SIGNED 32)) (TM-GMTOFF (SIGNED 32))
          (TM-ZONE C-STRING))) at #x28145A40>

Raghavendra.

-- 
N. Raghavendra <[EMAIL PROTECTED]> | See message headers for contact
Harish-Chandra Research Institute   | and OpenPGP details.


Reply via email to