Export to GitHub

pure-lang - issue #30

tzset()-related code in runtime.cc doesn't compile on FreeBSD


Posted on Apr 23, 2010 by Grumpy Dog

What steps will reproduce the problem? 1. svn co .../trunk pure 2. patch it 3. ./configure ... && gmake

What is the expected output? What do you see instead? runtime.cc: In function 'void pure_tzset()': runtime.cc:10933: error: invalid conversion from 'char* ()(int, int)' to 'int32_t' runtime.cc:10933: error: initializing argument 1 of 'pure_expr pure_int(int32_t)' runtime.cc:10934: error: 'daylight' was not declared in this scope

What version of the product are you using? On what operating system? HEAD of trunk on FreeBSD 9

Please provide any additional information below. FreeBSD doesn't conform to SUSv3 on this one, a few workarounds are listed at http://www.mail-archive.com/freebsd-questions@freebsd.org/msg188691.html

http://www.opengroup.org/onlinepubs/000095399/functions/tzset.html http://www.freebsd.org/cgi/man.cgi?query=tzset http://www.freebsd.org/cgi/man.cgi?query=timezone http://www.freebsd.org/cgi/man.cgi?query=ctime

the ctime(3) man page concludes with "Use of the external variable tzname is discouraged; the tm_zone entry in the tm structure is preferred."

Comment #1

Posted on Apr 23, 2010 by Grumpy Dog

I have a partial tentative patch, runtime.cc compiles, and with -DHAVE_TM_ZONE_IN_TM does what I'd expect:

diff -r c6ed3922588c pure/runtime.cc --- a/pure/runtime.cc Fri Apr 23 14:01:52 2010 +0200 +++ b/pure/runtime.cc Fri Apr 23 20:00:18 2010 +0200 @@ -10929,6 +10929,16 @@ void pure_tzset(void) { interpreter& interp = interpreter::g_interp; +#ifndef HAVE_DAYLIGHT_IN_TZSET + int32_t timezone = 0; + int32_t daylight = 0; +# ifdef HAVE_TM_ZONE_IN_TM + time_t t = time(NULL); + tm lt = localtime(&t); + timezone = lt->tm_gmtoff; + daylight = lt->tm_isdst; +# endif +#endif tzset(); df(interp, "timezone", pure_int(timezone)); df(interp, "daylight", pure_int(daylight));

If you think it's ok I'll follow up with the implied autoconf machinery.

Comment #2

Posted on Apr 25, 2010 by Massive Panda

Roman, I think that the timezone value should actually be -lt.tm_gmtoff + lt.tm_isdst * 3600, as the tm_gmtoff value is positive and includes the dst offset. (At least it's that way on my Linux system, I don't have a *BSD system to try it there.) This is also what the cited post at freebsd-questions suggests.

Just for the record, here is what the Pure interpreter gives me for these values, so that you can check it against your results (that's CET a.k.a. central european time, with daylight savings in effect):

$ pure

using system; timezone,daylight,tzname; -3600,1,["CET","CEST"]

Otherwise, your patch looks good to me. Can you please post the entire patch including the configury so that I can apply it?

Comment #3

Posted on Apr 26, 2010 by Grumpy Dog

I'm in the same timezone, and see the same values with the attached patch applied.

Attachments

Comment #4

Posted on Apr 27, 2010 by Massive Panda

Applied in r3399. Thanks!

Status: Fixed

Labels:
Type-Defect Priority-Medium