[pypy-svn] r45679 - in pypy/branch/pypy-more-rtti-inprogress: jit/codegen/demo jit/codegen/i386 jit/codegen/llvm module/posix module/sys rlib rpython rpython/module rpython/module/test translator/c translator/c/test translator/llvm/test
arigo at codespeak.net
arigo at codespeak.net
Wed Aug 15 15:03:45 CEST 2007
Author: arigo
Date: Wed Aug 15 15:03:44 2007
New Revision: 45679
Removed:
pypy/branch/pypy-more-rtti-inprogress/rlib/ros.py
Modified:
pypy/branch/pypy-more-rtti-inprogress/jit/codegen/demo/support.py
pypy/branch/pypy-more-rtti-inprogress/jit/codegen/i386/codebuf.py
pypy/branch/pypy-more-rtti-inprogress/jit/codegen/llvm/logger.py
pypy/branch/pypy-more-rtti-inprogress/module/posix/interp_posix.py
pypy/branch/pypy-more-rtti-inprogress/module/sys/state.py
pypy/branch/pypy-more-rtti-inprogress/rpython/extfunctable.py
pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os.py
pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os_environ.py
pypy/branch/pypy-more-rtti-inprogress/rpython/module/test/test_ll_os.py
pypy/branch/pypy-more-rtti-inprogress/translator/c/extfunc.py
pypy/branch/pypy-more-rtti-inprogress/translator/c/test/test_extfunc.py
pypy/branch/pypy-more-rtti-inprogress/translator/llvm/test/test_extfunc.py
Log:
- support for 'os.environ.get(name)'.
- kill rlib/ros.py. Yay!
Modified: pypy/branch/pypy-more-rtti-inprogress/jit/codegen/demo/support.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/jit/codegen/demo/support.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/jit/codegen/demo/support.py Wed Aug 15 15:03:44 2007
@@ -1,7 +1,6 @@
import os, sys
import py
from pypy.tool.udir import udir
-from pypy.rlib.ros import putenv
from pypy.jit.codegen.graph2rgenop import rcompile
from pypy.rpython.lltypesystem import lltype
@@ -83,7 +82,7 @@
os.unlink(logfile)
except OSError:
pass
- putenv('PYPYJITLOG=' + logfile)
+ os.environ['PYPYJITLOG'] = logfile
if benchmark:
py.test.skip("benchmarking: working in progress")
Modified: pypy/branch/pypy-more-rtti-inprogress/jit/codegen/i386/codebuf.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/jit/codegen/i386/codebuf.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/jit/codegen/i386/codebuf.py Wed Aug 15 15:03:44 2007
@@ -78,8 +78,7 @@
def open(self):
if self.log_fd < 0:
# check the environment for a file name
- from pypy.rlib.ros import getenv
- s = getenv('PYPYJITLOG')
+ s = os.environ.get('PYPYJITLOG')
if not s:
self.enabled = False
return False
Modified: pypy/branch/pypy-more-rtti-inprogress/jit/codegen/llvm/logger.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/jit/codegen/llvm/logger.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/jit/codegen/llvm/logger.py Wed Aug 15 15:03:44 2007
@@ -23,8 +23,7 @@
return False
if self.log_fd < 0:
# check the environment for a file name
- from pypy.rlib.ros import getenv
- s = getenv('PYPYJITLOG')
+ s = os.environ.get('PYPYJITLOG')
if not s:
self.enabled = False
return False
Modified: pypy/branch/pypy-more-rtti-inprogress/module/posix/interp_posix.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/module/posix/interp_posix.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/module/posix/interp_posix.py Wed Aug 15 15:03:44 2007
@@ -1,6 +1,5 @@
from pypy.interpreter.baseobjspace import ObjSpace, W_Root
from pypy.rlib.rarithmetic import intmask
-from pypy.rlib import ros
from pypy.interpreter.error import OperationError, wrap_oserror
from pypy.rpython.module.ll_os import RegisterOs
@@ -243,7 +242,6 @@
class State:
def __init__(self, space):
- self.posix_putenv_garbage = {}
self.w_environ = space.newdict()
def startup(self, space):
_convertenviron(space, self.w_environ)
@@ -252,38 +250,23 @@
return space.fromcache(State)
def _convertenviron(space, w_env):
- idx = 0
- while 1:
- s = ros.environ(idx)
- if s is None:
- break
- p = s.find('=')
- if p >= 0:
- key = s[:p]
- value = s[p+1:]
- space.setitem(w_env, space.wrap(key), space.wrap(value))
- idx += 1
+ for key, value in os.environ.items():
+ space.setitem(w_env, space.wrap(key), space.wrap(value))
def putenv(space, name, value):
"""Change or add an environment variable."""
- txt = '%s=%s' % (name, value)
- ros.putenv(txt)
- # Install the first arg and newstr in posix_putenv_garbage;
- # this will cause previous value to be collected. This has to
- # happen after the real putenv() call because the old value
- # was still accessible until then.
- get(space).posix_putenv_garbage[name] = txt
+ try:
+ os.environ[name] = value
+ except OSError, e:
+ raise wrap_oserror(space, e)
putenv.unwrap_spec = [ObjSpace, str, str]
def unsetenv(space, name):
"""Delete an environment variable."""
- if name in get(space).posix_putenv_garbage:
+ try:
os.unsetenv(name)
- # Remove the key from posix_putenv_garbage;
- # this will cause it to be collected. This has to
- # happen after the real unsetenv() call because the
- # old value was still accessible until then.
- del get(space).posix_putenv_garbage[name]
+ except OSError, e:
+ raise wrap_oserror(space, e)
unsetenv.unwrap_spec = [ObjSpace, str]
Modified: pypy/branch/pypy-more-rtti-inprogress/module/sys/state.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/module/sys/state.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/module/sys/state.py Wed Aug 15 15:03:44 2007
@@ -36,7 +36,6 @@
# build the initial path from the srcdir, which is the path of
# the "dist" directory of a PyPy checkout.
from pypy.module.sys.version import CPYTHON_VERSION
- from pypy.rlib import ros
dirname = '%d.%d.%d' % (CPYTHON_VERSION[0],
CPYTHON_VERSION[1],
@@ -52,7 +51,7 @@
checkdir(pypy_lib)
importlist = ['']
- pythonpath = ros.getenv('PYTHONPATH')
+ pythonpath = os.environ.get('PYTHONPATH')
if pythonpath:
for p in pythonpath.split(os.pathsep):
if p:
Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/extfunctable.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/extfunctable.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/extfunctable.py Wed Aug 15 15:03:44 2007
@@ -204,16 +204,6 @@
declare(rarithmetic.formatd, str, 'll_strtod/formatd')
# ___________________________________________________________
-# special helpers for os with no equivalent
-from pypy.rlib import ros
-declare(ros.putenv, noneannotation, 'll_os/putenv')
-declare(ros.environ, strnullannotation, 'll_os/environ')
-declare(ros.opendir, ros.DIR, 'll_os/opendir')
-declareptrtype(ros.DIR, "DIR",
- readdir = (strnullannotation, 'll_os/readdir'),
- closedir = (noneannotation, 'll_os/closedir'))
-
-# ___________________________________________________________
# stackless
from pypy.rlib import rstack
declare(rstack.stack_frames_depth, int, 'll_stackless/stack_frames_depth')
Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os.py Wed Aug 15 15:03:44 2007
@@ -9,7 +9,6 @@
from pypy.rpython.module.support import ll_strcpy, OOSupport
from pypy.rpython.module.support import to_opaque_object, from_opaque_object
from pypy.tool.sourcetools import func_with_new_name
-from pypy.rlib import ros
from pypy.rlib.rarithmetic import r_longlong
from pypy.tool.staticmethods import ClassMethods
import stat
@@ -729,20 +728,6 @@
os.rmdir(cls.from_rstr(path))
ll_os_rmdir.suggested_primitive = True
- # this function is not really the os thing, but the internal one.
- def ll_os_putenv(cls, name_eq_value):
- ros.putenv(cls.from_rstr(name_eq_value))
- ll_os_putenv.suggested_primitive = True
-
- def ll_os_unsetenv(cls, name):
- os.unsetenv(cls.from_rstr(name))
- ll_os_unsetenv.suggested_primitive = True
-
- # get the initial environment by indexing
- def ll_os_environ(cls, idx):
- return ros.environ(idx)
- ll_os_environ.suggested_primitive = True
-
def ll_os_chmod(cls, path, mode):
os.chmod(cls.from_rstr(path), mode)
ll_os_chmod.suggested_primitive = True
@@ -778,22 +763,3 @@
def ll_os__exit(cls, status):
os._exit(status)
ll_os__exit.suggested_primitive = True
-
- # ____________________________________________________________
- # opendir/readdir
-
- def ll_os_opendir(cls, dirname):
- dir = ros.opendir(cls.from_rstr(dirname))
- return to_opaque_object(dir)
- ll_os_opendir.suggested_primitive = True
-
- def ll_os_readdir(cls, opaquedir):
- dir = from_opaque_object(opaquedir)
- nextentry = dir.readdir()
- return cls.to_rstr(nextentry)
- ll_os_readdir.suggested_primitive = True
-
- def ll_os_closedir(cls, opaquedir):
- dir = from_opaque_object(opaquedir)
- dir.closedir()
- ll_os_closedir.suggested_primitive = True
Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os_environ.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os_environ.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os_environ.py Wed Aug 15 15:03:44 2007
@@ -16,7 +16,10 @@
def getitem(self, obj, key):
# in the RPython program reads of 'os.environ[key]' are redirected here
- return r_getenv(key)
+ result = r_getenv(key)
+ if result is None:
+ raise KeyError
+ return result
def setitem(self, obj, key, value):
# in the RPython program, 'os.environ[key] = value' is redirected here
@@ -35,12 +38,16 @@
# 'os.environ.items' is redirected here (not the actual method call!)
return r_envitems
+ def get_get(self, obj):
+ # 'os.environ.get' is redirected here (not the actual method call!)
+ return r_getenv
+
# ____________________________________________________________
#
# Lower-level interface: dummy placeholders and external registations
def r_getenv(name):
- just_a_placeholder
+ just_a_placeholder # should return None if name not found
os_getenv = rffi.llexternal('getenv', [rffi.CCHARP], rffi.CCHARP)
Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/module/test/test_ll_os.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/module/test/test_ll_os.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/module/test/test_ll_os.py Wed Aug 15 15:03:44 2007
@@ -37,75 +37,6 @@
assert file(filename).read().strip() == '2'
os.unlink(filename)
-def test_putenv_unsetenv():
- filename = str(udir.join('test_putenv.txt'))
- arg = impl.to_rstr('abcdefgh=12345678')
- impl.ll_os_putenv(arg)
- cmd = '''python -c "import os; print os.environ['abcdefgh']" > %s''' % filename
- os.system(cmd)
- f = file(filename)
- result = f.read().strip()
- assert result == '12345678'
- f.close()
- os.unlink(filename)
- posix = __import__(os.name)
- if hasattr(posix, "unsetenv"):
- impl.ll_os_unsetenv(impl.to_rstr("abcdefgh"))
- cmd = '''python -c "import os; print repr(os.getenv('abcdefgh'))" > %s''' % filename
- os.system(cmd)
- f = file(filename)
- result = f.read().strip()
- assert result == 'None'
- f.close()
- os.unlink(filename)
-
-test_src = """
-import os
-from pypy.tool.udir import udir
-#from pypy.rpython.module.ll_os import
-
-def test_environ():
- count = 0
- while 1:
- l
- if not impl.ll_os_environ(count):
- break
- count += 1
- channel.send(count == len(os.environ.keys()))
-test_environ()
-"""
-
-def test_environ():
- import py
- py.test.skip("Test hangs, should be rewritten to new-style")
- gw = py.execnet.PopenGateway()
- chan = gw.remote_exec(py.code.Source(test_src))
- res = chan.receive()
- assert res
- chan.close()
-
-def test_opendir_readdir():
- dirname = str(udir)
- rsdirname = impl.to_rstr(dirname)
- result = []
- DIR = impl.ll_os_opendir(rsdirname)
- try:
- while True:
- nextentry = impl.ll_os_readdir(DIR)
- if not nextentry: # null pointer check
- break
- result.append(impl.from_rstr(nextentry))
- finally:
- impl.ll_os_closedir(DIR)
- assert '.' in result
- assert '..' in result
- result.remove('.')
- result.remove('..')
- result.sort()
- compared_with = os.listdir(dirname)
- compared_with.sort()
- assert result == compared_with
-
def test_os_wstar():
from pypy.rpython.module.ll_os import RegisterOs
for name in RegisterOs.w_star:
Modified: pypy/branch/pypy-more-rtti-inprogress/translator/c/extfunc.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/c/extfunc.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/c/extfunc.py Wed Aug 15 15:03:44 2007
@@ -9,7 +9,6 @@
from pypy.rpython.module import ll_stackless, ll_stack
from pypy.rpython.module.ll_os import BaseOS as impl
from pypy.rpython.lltypesystem.module import ll_strtod
-from pypy.rlib import ros
try:
from pypy.module.thread.rpython import ll_thread
@@ -30,12 +29,6 @@
impl.ll_os_chdir.im_func: 'LL_os_chdir',
impl.ll_os_mkdir.im_func: 'LL_os_mkdir',
impl.ll_os_rmdir.im_func: 'LL_os_rmdir',
- impl.ll_os_putenv.im_func: 'LL_os_putenv',
- impl.ll_os_unsetenv.im_func:'LL_os_unsetenv',
- impl.ll_os_environ.im_func: 'LL_os_environ',
- impl.ll_os_opendir.im_func: 'LL_os_opendir',
- impl.ll_os_readdir.im_func: 'LL_os_readdir',
- impl.ll_os_closedir.im_func:'LL_os_closedir',
impl.ll_os_chmod.im_func: 'LL_os_chmod',
impl.ll_os_rename.im_func: 'LL_os_rename',
impl.ll_os_umask.im_func: 'LL_os_umask',
Modified: pypy/branch/pypy-more-rtti-inprogress/translator/c/test/test_extfunc.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/c/test/test_extfunc.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/c/test/test_extfunc.py Wed Aug 15 15:03:44 2007
@@ -4,7 +4,7 @@
from pypy.tool.udir import udir
from pypy.translator.c.test.test_genc import compile
from pypy.translator.c.extfunc import EXTERNALS
-from pypy.rlib import ros
+posix = __import__(os.name)
def test_all_suggested_primitives():
for modulename in ['ll_os', 'll_os_path', 'll_time']:
@@ -629,68 +629,30 @@
else:
raise ValueError, 'probing for env var returned %r' % (output,)
-def _real_envkeys():
- cmd = '''%s -c "import os; print os.environ.keys()"''' % sys.executable
- g = os.popen(cmd, 'r')
- output = g.read().strip()
- g.close()
- if output.startswith('[') and output.endswith(']'):
- return eval(output)
- else:
- raise ValueError, 'probing for all env vars returned %r' % (output,)
-
-def test_putenv():
- def put(s):
- ros.putenv(s)
- func = compile(put, [str])
- func('abcdefgh=12345678')
- assert _real_getenv('abcdefgh') == '12345678'
-
-def test_environ():
- def env(idx):
- # need to as if the result is NULL, or we crash
- ret = ros.environ(idx)
- if ret is None:
- return False
- return ret
- func = compile(env, [int])
- keys = []
- while 1:
- s = func(len(keys))
- if not s:
- break
- name, value = s.split('=', 1)
- keys.append(name)
- expected = _real_envkeys()
- keys.sort()
- expected.sort()
- py.test.skip("XXX fails for me, $OLDPWD doesn't show up in the subprocess")
- assert keys == expected
-
-posix = __import__(os.name)
-if hasattr(posix, "unsetenv"):
- def test_unsetenv():
- def unsetenv():
- os.unsetenv("ABCDEF")
- f = compile(unsetenv, [])
- os.putenv("ABCDEF", "a")
- assert _real_getenv('ABCDEF') == 'a'
- f()
- assert _real_getenv('ABCDEF') is None
- f()
- assert _real_getenv('ABCDEF') is None
-
-
def test_dictlike_environ_getitem():
def fn(s):
- res = os.environ[s]
- if res is None:
- res = '--missing--'
+ try:
+ return os.environ[s]
+ except KeyError:
+ return '--missing--'
+ func = compile(fn, [str])
+ os.environ.setdefault('USER', 'UNNAMED_USER')
+ result = func('USER')
+ assert result == os.environ['USER']
+ result = func('PYPY_TEST_DICTLIKE_MISSING')
+ assert result == '--missing--'
+
+def test_dictlike_environ_get():
+ def fn(s):
+ res = os.environ.get(s)
+ if res is None: res = '--missing--'
return res
func = compile(fn, [str])
os.environ.setdefault('USER', 'UNNAMED_USER')
result = func('USER')
assert result == os.environ['USER']
+ result = func('PYPY_TEST_DICTLIKE_MISSING')
+ assert result == '--missing--'
def test_dictlike_environ_setitem():
def fn(s, t1, t2, t3, t4, t5):
@@ -772,33 +734,6 @@
assert ('USER/%s' % (os.environ['USER'],)) in result2
assert 'PYPY_TEST_DICTLIKE_ENVITEMS/783' in result2
-
-def test_opendir_readdir():
- py.test.skip("deprecated")
- def mylistdir(s):
- result = []
- dir = ros.opendir(s)
- try:
- while True:
- nextentry = dir.readdir()
- if nextentry is None:
- break
- result.append(nextentry)
- finally:
- dir.closedir()
- return '\x00'.join(result)
- func = compile(mylistdir, [str])
- result = func(str(udir))
- result = result.split('\x00')
- assert '.' in result
- assert '..' in result
- result.remove('.')
- result.remove('..')
- result.sort()
- compared_with = os.listdir(str(udir))
- compared_with.sort()
- assert result == compared_with
-
def test_listdir():
def mylistdir(s):
try:
Modified: pypy/branch/pypy-more-rtti-inprogress/translator/llvm/test/test_extfunc.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/llvm/test/test_extfunc.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/llvm/test/test_extfunc.py Wed Aug 15 15:03:44 2007
@@ -6,9 +6,9 @@
import py
from pypy.tool.udir import udir
from pypy.rlib.rarithmetic import r_uint
-from pypy.rlib import ros
py.test.skip("Extfunc support in llvm needs refactoring")
+# XXX in particular, try to share the tests from c/test/test_extfunc!
from pypy.translator.llvm.test.runtest import *
@@ -320,80 +320,6 @@
# more from translator/c/test/test_extfunc.py Revision: 19054
-def _real_getenv(var):
- cmd = '''%s -c "import os; x=os.environ.get('%s'); print (x is None) and 'F' or ('T'+x)"''' % (
- sys.executable, var)
- g = os.popen(cmd, 'r')
- output = g.read().strip()
- g.close()
- if output == 'F':
- return None
- elif output.startswith('T'):
- return output[1:]
- else:
- raise ValueError, 'probing for env var returned %r' % (output,)
-
-def _real_envkeys():
- cmd = '''%s -c "import os; print os.environ.keys()"''' % sys.executable
- g = os.popen(cmd, 'r')
- output = g.read().strip()
- g.close()
- if output.startswith('[') and output.endswith(']'):
- return eval(output)
- else:
- raise ValueError, 'probing for all env vars returned %r' % (output,)
-
-def test_putenv():
- s = 'abcdefgh=12345678'
- def put():
- ros.putenv(s)
- return 0
- func = compile_function(put, [], isolate=False)
- func()
- assert _real_getenv('abcdefgh') == '12345678'
-
-posix = __import__(os.name)
-if hasattr(posix, "unsetenv"):
- def test_unsetenv():
- def unsetenv():
- os.unsetenv("ABCDEF")
- return 0
- f = compile_function(unsetenv, [], isolate=False)
- os.putenv("ABCDEF", "a")
- assert _real_getenv('ABCDEF') == 'a'
- f()
- assert _real_getenv('ABCDEF') is None
- f()
- assert _real_getenv('ABCDEF') is None
-
-def test_opendir_readdir():
- s = str(udir)
- result = []
- def mylistdir():
- dir = ros.opendir(s)
- try:
- while True:
- nextentry = dir.readdir()
- if nextentry is None:
- break
- result.append(nextentry)
- finally:
- dir.closedir()
- return 0
- func = compile_function(mylistdir, [])
- result = func()
- py.test.skip("XXX need to check result - somehow")
-
- result = result.split('\x00')
- assert '.' in result
- assert '..' in result
- result.remove('.')
- result.remove('..')
- result.sort()
- compared_with = os.listdir(str(udir))
- compared_with.sort()
- assert result == compared_with
-
def test_lock():
py.test.skip("XXX does not work with exception transform (why not?)")
import thread
More information about the pypy-svn
mailing list