unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Setting TZ in set_time_zone_rule
@ 2012-11-28 18:12 Eli Zaretskii
  2012-11-28 20:21 ` Paul Eggert
  0 siblings, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2012-11-28 18:12 UTC (permalink / raw)
  To: emacs-devel; +Cc: Fabrice Popineau

Is there a good reason why we don't use 'putenv' in
set_time_zone_rule, and instead manipulate 'environ' directly?

Fabrice (CC'ed) reported that this causes crashes in Emacs compiled by
MSVC on Windows, because xmalloc on Windows allocates memory from a
different heap than what's used by the runtime library for 'environ'.

But even without that problem, it looks like we go out of our way to
solve a problem that is long solved by a standard library function.

What am I missing?



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Setting TZ in set_time_zone_rule
  2012-11-28 18:12 Setting TZ in set_time_zone_rule Eli Zaretskii
@ 2012-11-28 20:21 ` Paul Eggert
  2012-11-28 21:24   ` Andreas Schwab
  0 siblings, 1 reply; 12+ messages in thread
From: Paul Eggert @ 2012-11-28 20:21 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Fabrice Popineau, emacs-devel

On 11/28/12 10:12, Eli Zaretskii wrote:
> Is there a good reason why we don't use 'putenv' in
> set_time_zone_rule, and instead manipulate 'environ' directly?

putenv is not not in POSIX 1003.1-1988.  In the
current POSIX standard (2008), putenv is marked as an XSI
extension, which means it's not required for POSIX
conformance.  I don't offhand know of any Emacs porting
target that lacks putenv, though I would not be surprised
if there were one.

One possibility is to have the mainline code assume that
putenv works, and to use the gnulib putenv module for the rare
platforms that lack putenv.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Setting TZ in set_time_zone_rule
  2012-11-28 20:21 ` Paul Eggert
@ 2012-11-28 21:24   ` Andreas Schwab
  2012-11-29  1:21     ` Paul Eggert
  0 siblings, 1 reply; 12+ messages in thread
From: Andreas Schwab @ 2012-11-28 21:24 UTC (permalink / raw)
  To: Paul Eggert; +Cc: Eli Zaretskii, Fabrice Popineau, emacs-devel

Paul Eggert <eggert@cs.ucla.edu> writes:

> putenv is not not in POSIX 1003.1-1988.  In the
> current POSIX standard (2008), putenv is marked as an XSI
> extension, which means it's not required for POSIX
> conformance.

setenv is required since 2004.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Setting TZ in set_time_zone_rule
  2012-11-28 21:24   ` Andreas Schwab
@ 2012-11-29  1:21     ` Paul Eggert
  2012-11-29  3:44       ` Eli Zaretskii
  0 siblings, 1 reply; 12+ messages in thread
From: Paul Eggert @ 2012-11-29  1:21 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Eli Zaretskii, Fabrice Popineau, emacs-devel

On 11/28/2012 01:24 PM, Andreas Schwab wrote:
> setenv is required since 2004.

Yes, thanks, so that'd be a better choice than putenv.
There's a gnulib module for setenv too, for the hosts
that lack it.  Presumably Emacs's existing uses of
putenv could be modernized to use setenv.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Setting TZ in set_time_zone_rule
  2012-11-29  1:21     ` Paul Eggert
@ 2012-11-29  3:44       ` Eli Zaretskii
  2012-11-29 21:39         ` Paul Eggert
  0 siblings, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2012-11-29  3:44 UTC (permalink / raw)
  To: Paul Eggert; +Cc: fabrice.popineau, schwab, emacs-devel

> Date: Wed, 28 Nov 2012 17:21:10 -0800
> From: Paul Eggert <eggert@cs.ucla.edu>
> Cc: Eli Zaretskii <eliz@gnu.org>, Fabrice Popineau <fabrice.popineau@gmail.com>,
> 	emacs-devel@gnu.org
> 
> On 11/28/2012 01:24 PM, Andreas Schwab wrote:
> > setenv is required since 2004.
> 
> Yes, thanks, so that'd be a better choice than putenv.
> There's a gnulib module for setenv too, for the hosts
> that lack it.  Presumably Emacs's existing uses of
> putenv could be modernized to use setenv.

So would it be a problem to use 'setenv' in that function?



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Setting TZ in set_time_zone_rule
  2012-11-29  3:44       ` Eli Zaretskii
@ 2012-11-29 21:39         ` Paul Eggert
  2012-11-30  9:08           ` Eli Zaretskii
  0 siblings, 1 reply; 12+ messages in thread
From: Paul Eggert @ 2012-11-29 21:39 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: schwab, fabrice.popineau, emacs-devel

On 11/28/12 19:44, Eli Zaretskii wrote:
> So would it be a problem to use 'setenv' in that function?

I think setenv could be used.  It'd be a tiny bit tricky, though,
as I expect unsetenv would also need to be used, in some
cases.  There's a gnulib module for unsetenv too, so the
only real problem would be in the Emacs code proper.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Setting TZ in set_time_zone_rule
  2012-11-29 21:39         ` Paul Eggert
@ 2012-11-30  9:08           ` Eli Zaretskii
  2012-11-30  9:26             ` Fabrice Popineau
  0 siblings, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2012-11-30  9:08 UTC (permalink / raw)
  To: Paul Eggert; +Cc: schwab, fabrice.popineau, emacs-devel

> Date: Thu, 29 Nov 2012 13:39:24 -0800
> From: Paul Eggert <eggert@cs.ucla.edu>
> CC: fabrice.popineau@gmail.com, schwab@linux-m68k.org, 
>  emacs-devel@gnu.org
> 
> On 11/28/12 19:44, Eli Zaretskii wrote:
> > So would it be a problem to use 'setenv' in that function?
> 
> I think setenv could be used.  It'd be a tiny bit tricky, though,
> as I expect unsetenv would also need to be used, in some
> cases.

Is 'unsetenv's less wide-spread than 'setenv'?



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Setting TZ in set_time_zone_rule
  2012-11-30  9:08           ` Eli Zaretskii
@ 2012-11-30  9:26             ` Fabrice Popineau
  2012-11-30 10:02               ` Eli Zaretskii
  0 siblings, 1 reply; 12+ messages in thread
From: Fabrice Popineau @ 2012-11-30  9:26 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Paul Eggert, Andreas Schwab, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 719 bytes --]

Do we really need to unsetenv the TZ variable?
I had the impression that we need to set it forth and back,
to change it temporarily.

Also, is unsetenv("TZ") the same as putenv("TZ=") ?

Fabrice


2012/11/30 Eli Zaretskii <eliz@gnu.org>

> > Date: Thu, 29 Nov 2012 13:39:24 -0800
> > From: Paul Eggert <eggert@cs.ucla.edu>
> > CC: fabrice.popineau@gmail.com, schwab@linux-m68k.org,
> >  emacs-devel@gnu.org
> >
> > On 11/28/12 19:44, Eli Zaretskii wrote:
> > > So would it be a problem to use 'setenv' in that function?
> >
> > I think setenv could be used.  It'd be a tiny bit tricky, though,
> > as I expect unsetenv would also need to be used, in some
> > cases.
>
> Is 'unsetenv's less wide-spread than 'setenv'?
>

[-- Attachment #2: Type: text/html, Size: 1386 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Setting TZ in set_time_zone_rule
  2012-11-30  9:26             ` Fabrice Popineau
@ 2012-11-30 10:02               ` Eli Zaretskii
  2012-11-30 18:22                 ` Paul Eggert
  0 siblings, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2012-11-30 10:02 UTC (permalink / raw)
  To: Fabrice Popineau; +Cc: eggert, schwab, emacs-devel

> From: Fabrice Popineau <fabrice.popineau@gmail.com>
> Date: Fri, 30 Nov 2012 10:26:09 +0100
> Cc: Paul Eggert <eggert@cs.ucla.edu>, Andreas Schwab <schwab@linux-m68k.org>, emacs-devel@gnu.org
> 
> Do we really need to unsetenv the TZ variable?

Maybe not.  Paul, can you point out where would 'unsetenv' be needed,
and why?

> Also, is unsetenv("TZ") the same as putenv("TZ=") ?

Yes.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Setting TZ in set_time_zone_rule
  2012-11-30 10:02               ` Eli Zaretskii
@ 2012-11-30 18:22                 ` Paul Eggert
  2012-11-30 18:52                   ` Eli Zaretskii
  0 siblings, 1 reply; 12+ messages in thread
From: Paul Eggert @ 2012-11-30 18:22 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: schwab, Fabrice Popineau, emacs-devel

On 11/30/12 02:02, Eli Zaretskii wrote:
> Paul, can you point out where would 'unsetenv' be needed,
> and why?

set_time_zone_rule (0) needs to unset TZ.

>> > Also, is unsetenv("TZ") the same as putenv("TZ=") ?
> Yes.

Doesn't the former unset TZ, and the latter set TZ to the empty string?



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Setting TZ in set_time_zone_rule
  2012-11-30 18:22                 ` Paul Eggert
@ 2012-11-30 18:52                   ` Eli Zaretskii
  2012-11-30 20:47                     ` Paul Eggert
  0 siblings, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2012-11-30 18:52 UTC (permalink / raw)
  To: Paul Eggert; +Cc: schwab, fabrice.popineau, emacs-devel

> Date: Fri, 30 Nov 2012 10:22:35 -0800
> From: Paul Eggert <eggert@cs.ucla.edu>
> CC: Fabrice Popineau <fabrice.popineau@gmail.com>, schwab@linux-m68k.org, 
>  emacs-devel@gnu.org
> 
> On 11/30/12 02:02, Eli Zaretskii wrote:
> > Paul, can you point out where would 'unsetenv' be needed,
> > and why?
> 
> set_time_zone_rule (0) needs to unset TZ.

Do we ever call it that way?

> >> > Also, is unsetenv("TZ") the same as putenv("TZ=") ?
> > Yes.
> 
> Doesn't the former unset TZ, and the latter set TZ to the empty string?

The implementation I saw unset TZ in both cases.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Setting TZ in set_time_zone_rule
  2012-11-30 18:52                   ` Eli Zaretskii
@ 2012-11-30 20:47                     ` Paul Eggert
  0 siblings, 0 replies; 12+ messages in thread
From: Paul Eggert @ 2012-11-30 20:47 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: schwab, fabrice.popineau, emacs-devel

On 11/30/12 10:52, Eli Zaretskii wrote:

>> set_time_zone_rule (0) needs to unset TZ.
> 
> Do we ever call it that way?

Yes, if TZ is unset in the environment.

>>>>> Also, is unsetenv("TZ") the same as putenv("TZ=") ?
>>> Yes.
>>
>> Doesn't the former unset TZ, and the latter set TZ to the empty string?
> 
> The implementation I saw unset TZ in both cases.

Which implementation is that?  It does not conform to POSIX.
At any rate, we can't rely on that behavior.

I just thought of another problem: setenv has a memory leak,
by design: it leaks the memory holding the previous value of
the environment variable.  So I guess we should use putenv
after all.  We can use the gnulib putenv module for hosts that
lack putenv.  We'll also need unsetenv (but not setenv).

I'll look into drafting a patch along these lines this weekend.
The code is a bit of a mess in this area, unfortunately.
Among other things, the current uses of setenv and putenv
assume that they always succeed, but they can fail just as
malloc can fail, due to lack of memory.



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2012-11-30 20:47 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-28 18:12 Setting TZ in set_time_zone_rule Eli Zaretskii
2012-11-28 20:21 ` Paul Eggert
2012-11-28 21:24   ` Andreas Schwab
2012-11-29  1:21     ` Paul Eggert
2012-11-29  3:44       ` Eli Zaretskii
2012-11-29 21:39         ` Paul Eggert
2012-11-30  9:08           ` Eli Zaretskii
2012-11-30  9:26             ` Fabrice Popineau
2012-11-30 10:02               ` Eli Zaretskii
2012-11-30 18:22                 ` Paul Eggert
2012-11-30 18:52                   ` Eli Zaretskii
2012-11-30 20:47                     ` Paul Eggert

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).