Skip to content

Commit

Permalink
[build] Use explicit posix.putenv() methods, etc.
Browse files Browse the repository at this point in the history
We don't have the 'os' module in the release build; we have a fork of
the lower level 'posix' module in native/posixmodule.c.

Bad: I shouldn't have to manually edit posix_methods.def ...
  • Loading branch information
Andy Chu committed Mar 19, 2020
1 parent eba6506 commit 172e654
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ static PyMethodDef posix_methods[] = {
{"fdopen", posix_fdopen, METH_VARARGS},
{"isatty", posix_isatty, METH_VARARGS},
{"pipe", posix_pipe, METH_NOARGS},
{"putenv", posix_putenv, METH_VARARGS},
{"strerror", posix_strerror, METH_VARARGS},

/* job control stuff */
Expand Down
9 changes: 5 additions & 4 deletions osh/builtin_printf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import sys
import time
import os

from asdl import runtime
from core import error
Expand All @@ -29,6 +28,8 @@
from osh import string_ops
from osh import word_compile

import posix_ as posix

from typing import Dict, List, TYPE_CHECKING, cast

if TYPE_CHECKING:
Expand Down Expand Up @@ -335,9 +336,9 @@ def Run(self, cmd_val):
tzcell = self.mem.GetCell('TZ')
if tzcell and tzcell.exported and tzcell.val.tag_() == value_e.Str:
tzval = cast(value__Str, tzcell.val)
os.environ['TZ'] = tzval.s
elif 'TZ' in os.environ:
del os.environ['TZ']
posix.putenv('TZ', tzval.s)
elif posix.getenv('TZ'):
posix.unsetenv('TZ')
time.tzset()

# Handle special values:
Expand Down

0 comments on commit 172e654

Please sign in to comment.