hughperman / pure-lang

Automatically exported from code.google.com/p/pure-lang
0 stars 0 forks source link

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

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
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."

Original issue reported on code.google.com by neuhau...@sigpipe.cz on 23 Apr 2010 at 1:52

GoogleCodeExporter commented 8 years ago
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.

Original comment by neuhau...@sigpipe.cz on 23 Apr 2010 at 7:33

GoogleCodeExporter commented 8 years ago
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?

Original comment by aggraef@gmail.com on 25 Apr 2010 at 11:32

GoogleCodeExporter commented 8 years ago
I'm in the same timezone, and see the same values with the attached patch 
applied.

Original comment by neuhau...@sigpipe.cz on 26 Apr 2010 at 8:41

Attachments:

GoogleCodeExporter commented 8 years ago
Applied in r3399. Thanks!

Original comment by aggraef@gmail.com on 27 Apr 2010 at 11:09