[pypy-svn] r45674 - in pypy/branch/pypy-more-rtti-inprogress: rpython/module translator/c/test
arigo at codespeak.net
arigo at codespeak.net
Wed Aug 15 13:33:36 CEST 2007
Author: arigo
Date: Wed Aug 15 13:33:35 2007
New Revision: 45674
Modified:
pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os_environ.py
pypy/branch/pypy-more-rtti-inprogress/translator/c/test/test_extfunc.py
pypy/branch/pypy-more-rtti-inprogress/translator/c/test/test_genc.py
Log:
Finish os.putenv().
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 13:33:35 2007
@@ -51,17 +51,24 @@
def r_putenv(name, value):
just_a_placeholder
+class EnvKeepalive:
+ pass
+envkeepalive = EnvKeepalive()
+envkeepalive.byname = {}
+
os_putenv = rffi.llexternal('putenv', [rffi.CCHARP], rffi.INT)
def putenv_lltypeimpl(name, value):
l_string = rffi.str2charp('%s=%s' % (name, value))
- l_result = os_putenv(l_name)
- if l_result:
- result = rffi.charp2str(l_result)
- else:
- result = None
- rffi.free_charp(l_string) <-------!
- return result
+ error = os_putenv(l_string)
+ if error:
+ raise OSError(rffi.get_errno(), "os_putenv failed")
+ # keep 'l_string' alive - we know that the C library needs it
+ # until the next call to putenv() with the same 'name'.
+ l_oldstring = envkeepalive.byname.get(name, lltype.nullptr(rffi.CCHARP.TO))
+ envkeepalive.byname[name] = l_string
+ if l_oldstring:
+ rffi.free_charp(l_oldstring)
_register_external(r_putenv, [str, str], annmodel.s_None,
export_name='ll_os.ll_os_putenv',
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 13:33:35 2007
@@ -693,11 +693,16 @@
assert result == os.environ['USER']
def test_dictlike_environ_setitem():
- def fn(s, t):
- os.environ[s] = t
- func = compile(fn, [str, str])
- func('PYPY_TEST_DICTLIKE_ENVIRON', '42')
- assert os.environ['PYPY_TEST_DICTLIKE_ENVIRON'] == '42'
+ def fn(s, t1, t2, t3, t4, t5):
+ os.environ[s] = t1
+ os.environ[s] = t2
+ os.environ[s] = t3
+ os.environ[s] = t4
+ os.environ[s] = t5
+ func = compile(fn, [str, str, str, str, str, str])
+ func('PYPY_TEST_DICTLIKE_ENVIRON', 'a', 'b', 'c', 'FOOBAR', '42',
+ expected_extra_mallocs = (1, 2, 3, 4)) # at least one, less than 5
+ assert _real_getenv('PYPY_TEST_DICTLIKE_ENVIRON') == '42'
def test_opendir_readdir():
Modified: pypy/branch/pypy-more-rtti-inprogress/translator/c/test/test_genc.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/c/test/test_genc.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/c/test/test_genc.py Wed Aug 15 13:33:35 2007
@@ -51,7 +51,10 @@
expected_extra_mallocs = 0
res = compiled_fn(*args, **kwds)
mallocs, frees = module.malloc_counters()
- assert mallocs - frees == expected_extra_mallocs
+ if isinstance(expected_extra_mallocs, int):
+ assert mallocs - frees == expected_extra_mallocs
+ else:
+ assert mallocs - frees in expected_extra_mallocs
return res
return checking_fn
More information about the Pypy-commit
mailing list