[pypy-svn] r66326 - in pypy/branch/parser-compiler/pypy: annotation annotation/test doc/jit interpreter lang/smalltalk lang/smalltalk/tool module/__builtin__ module/__builtin__/test module/mmap/test module/posix objspace/std objspace/std/test rlib rlib/rsre rlib/rsre/test rlib/test rpython rpython/lltypesystem rpython/lltypesystem/test rpython/module rpython/module/test rpython/test rpython/tool rpython/tool/test translator translator/backendopt/test translator/c translator/c/test translator/cli/src translator/goal translator/jvm translator/platform translator/platform/test
benjamin at codespeak.net
benjamin at codespeak.net
Fri Jul 17 21:56:03 CEST 2009
Author: benjamin
Date: Fri Jul 17 21:55:59 2009
New Revision: 66326
Added:
pypy/branch/parser-compiler/pypy/rlib/bitmanipulation.py
- copied unchanged from r66325, pypy/trunk/pypy/rlib/bitmanipulation.py
pypy/branch/parser-compiler/pypy/rlib/test/test_bitmanipulation.py
- copied unchanged from r66325, pypy/trunk/pypy/rlib/test/test_bitmanipulation.py
pypy/branch/parser-compiler/pypy/translator/c/dlltool.py
- copied unchanged from r66325, pypy/trunk/pypy/translator/c/dlltool.py
pypy/branch/parser-compiler/pypy/translator/c/test/test_dlltool.py
- copied unchanged from r66325, pypy/trunk/pypy/translator/c/test/test_dlltool.py
pypy/branch/parser-compiler/pypy/translator/goal/sharedpypy.py
- copied unchanged from r66325, pypy/trunk/pypy/translator/goal/sharedpypy.py
Removed:
pypy/branch/parser-compiler/pypy/lang/smalltalk/tool/bitmanipulation.py
pypy/branch/parser-compiler/pypy/lang/smalltalk/tool/test_bitmanipulation.py
Modified:
pypy/branch/parser-compiler/pypy/annotation/specialize.py
pypy/branch/parser-compiler/pypy/annotation/test/test_annrpython.py
pypy/branch/parser-compiler/pypy/annotation/unaryop.py
pypy/branch/parser-compiler/pypy/doc/jit/pyjitpl5.txt
pypy/branch/parser-compiler/pypy/interpreter/pyopcode.py
pypy/branch/parser-compiler/pypy/lang/smalltalk/model.py
pypy/branch/parser-compiler/pypy/lang/smalltalk/squeakimage.py
pypy/branch/parser-compiler/pypy/module/__builtin__/functional.py
pypy/branch/parser-compiler/pypy/module/__builtin__/test/test_classobj.py
pypy/branch/parser-compiler/pypy/module/__builtin__/test/test_functional.py
pypy/branch/parser-compiler/pypy/module/__builtin__/test/test_range.py
pypy/branch/parser-compiler/pypy/module/mmap/test/test_mmap.py
pypy/branch/parser-compiler/pypy/module/posix/__init__.py
pypy/branch/parser-compiler/pypy/objspace/std/dictmultiobject.py
pypy/branch/parser-compiler/pypy/objspace/std/dictobject.py
pypy/branch/parser-compiler/pypy/objspace/std/fake.py
pypy/branch/parser-compiler/pypy/objspace/std/stringobject.py
pypy/branch/parser-compiler/pypy/objspace/std/test/test_dictmultiobject.py
pypy/branch/parser-compiler/pypy/objspace/std/test/test_dictobject.py
pypy/branch/parser-compiler/pypy/objspace/std/test/test_stringobject.py
pypy/branch/parser-compiler/pypy/objspace/std/test/test_typeobject.py
pypy/branch/parser-compiler/pypy/objspace/std/typeobject.py
pypy/branch/parser-compiler/pypy/rlib/libffi.py
pypy/branch/parser-compiler/pypy/rlib/rsre/rsre.py
pypy/branch/parser-compiler/pypy/rlib/rsre/test/test_rsre.py
pypy/branch/parser-compiler/pypy/rlib/runicode.py
pypy/branch/parser-compiler/pypy/rlib/streamio.py
pypy/branch/parser-compiler/pypy/rpython/lltypesystem/ll2ctypes.py
pypy/branch/parser-compiler/pypy/rpython/lltypesystem/rstr.py
pypy/branch/parser-compiler/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
pypy/branch/parser-compiler/pypy/rpython/module/ll_os.py
pypy/branch/parser-compiler/pypy/rpython/module/test/test_ll_os.py
pypy/branch/parser-compiler/pypy/rpython/rstr.py
pypy/branch/parser-compiler/pypy/rpython/test/test_rfloat.py
pypy/branch/parser-compiler/pypy/rpython/test/test_rstr.py
pypy/branch/parser-compiler/pypy/rpython/test/test_runicode.py
pypy/branch/parser-compiler/pypy/rpython/tool/rffi_platform.py
pypy/branch/parser-compiler/pypy/rpython/tool/test/test_rffi_platform.py
pypy/branch/parser-compiler/pypy/translator/backendopt/test/test_merge_if_blocks.py
pypy/branch/parser-compiler/pypy/translator/c/genc.py
pypy/branch/parser-compiler/pypy/translator/c/node.py
pypy/branch/parser-compiler/pypy/translator/c/test/test_genc.py
pypy/branch/parser-compiler/pypy/translator/c/test/test_newgc.py
pypy/branch/parser-compiler/pypy/translator/c/test/test_standalone.py
pypy/branch/parser-compiler/pypy/translator/cli/src/ll_os.cs
pypy/branch/parser-compiler/pypy/translator/driver.py
pypy/branch/parser-compiler/pypy/translator/goal/targetpypystandalone.py
pypy/branch/parser-compiler/pypy/translator/goal/translate.py
pypy/branch/parser-compiler/pypy/translator/jvm/genjvm.py
pypy/branch/parser-compiler/pypy/translator/platform/__init__.py
pypy/branch/parser-compiler/pypy/translator/platform/darwin.py
pypy/branch/parser-compiler/pypy/translator/platform/linux.py
pypy/branch/parser-compiler/pypy/translator/platform/test/test_maemo.py
pypy/branch/parser-compiler/pypy/translator/platform/test/test_platform.py
pypy/branch/parser-compiler/pypy/translator/platform/windows.py
Log:
merge from the trunk -r65588:66325
Modified: pypy/branch/parser-compiler/pypy/annotation/specialize.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/annotation/specialize.py (original)
+++ pypy/branch/parser-compiler/pypy/annotation/specialize.py Fri Jul 17 21:55:59 2009
@@ -123,10 +123,10 @@
example_args, example_value = self.table.iteritems().next()
nbargs = len(example_args)
# list of sets of possible argument values -- one set per argument index
- sets = [{} for i in range(nbargs)]
+ sets = [set() for i in range(nbargs)]
for args in self.table:
for i in range(nbargs):
- sets[i][args[i]] = True
+ sets[i].add(args[i])
bookkeeper = self.funcdesc.bookkeeper
annotator = bookkeeper.annotator
@@ -233,8 +233,8 @@
# schedule this new graph for being annotated
args_s = []
- for set in sets:
- values_s = [bookkeeper.immutablevalue(x) for x in set]
+ for arg_types in sets:
+ values_s = [bookkeeper.immutablevalue(x) for x in arg_types]
args_s.append(unionof(*values_s))
annotator.addpendinggraph(self.graph, args_s)
Modified: pypy/branch/parser-compiler/pypy/annotation/test/test_annrpython.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/annotation/test/test_annrpython.py (original)
+++ pypy/branch/parser-compiler/pypy/annotation/test/test_annrpython.py Fri Jul 17 21:55:59 2009
@@ -425,6 +425,14 @@
s_meth = s_example.getattr(iv(methname))
assert isinstance(s_constmeth, annmodel.SomeBuiltin)
+ def test_str_splitlines(self):
+ a = self.RPythonAnnotator()
+ def f(a_str):
+ return a_str.splitlines()
+ s = a.build_types(f, [str])
+ assert isinstance(s, annmodel.SomeList)
+ assert s.listdef.listitem.resized
+
def test_simple_slicing(self):
a = self.RPythonAnnotator()
s = a.build_types(snippet.simple_slice, [list])
@@ -3068,7 +3076,6 @@
a = self.RPythonAnnotator()
a.translator.config.translation.list_comprehension_operations = True
py.test.raises(TooLateForChange, a.build_types, fn, [int])
-
def test_listitem_never_resize(self):
from pypy.rlib.debug import check_annotation
Modified: pypy/branch/parser-compiler/pypy/annotation/unaryop.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/annotation/unaryop.py (original)
+++ pypy/branch/parser-compiler/pypy/annotation/unaryop.py Fri Jul 17 21:55:59 2009
@@ -521,6 +521,13 @@
def method_lower(str):
return SomeString()
+ def method_splitlines(str, s_keep_newlines=None):
+ s_list = getbookkeeper().newlist(str.basestringclass())
+ # Force the list to be resizable because ll_splitlines doesn't
+ # preallocate the list.
+ s_list.listdef.listitem.resize()
+ return s_list
+
def method_decode(str, s_enc):
if not s_enc.is_constant():
raise TypeError("Non-constant encoding not supported")
Modified: pypy/branch/parser-compiler/pypy/doc/jit/pyjitpl5.txt
==============================================================================
--- pypy/branch/parser-compiler/pypy/doc/jit/pyjitpl5.txt (original)
+++ pypy/branch/parser-compiler/pypy/doc/jit/pyjitpl5.txt Fri Jul 17 21:55:59 2009
@@ -17,3 +17,5 @@
* http://morepypy.blogspot.com/2009/03/jit-bit-of-look-inside.html
* http://morepypy.blogspot.com/2009/03/good-news-everyone.html
* http://morepypy.blogspot.com/2009/04/roadmap-for-jit.html
+* http://morepypy.blogspot.com/2009/04/4-weeks-of-gdb.html
+* http://morepypy.blogspot.com/2009/05/icooolps-submissions.html
Modified: pypy/branch/parser-compiler/pypy/interpreter/pyopcode.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/pyopcode.py (original)
+++ pypy/branch/parser-compiler/pypy/interpreter/pyopcode.py Fri Jul 17 21:55:59 2009
@@ -1,7 +1,7 @@
"""
Implementation of a part of the standard Python opcodes.
-The rest, dealing with variables in optimized ways, is in
-pyfastscope.py and pynestedscope.py.
+
+The rest, dealing with variables in optimized ways, is in nestedscope.py.
"""
import sys
@@ -304,9 +304,9 @@
################################################################
## Implementation of the "operational" opcodes
- ## See also pyfastscope.py and pynestedscope.py for the rest.
+ ## See also nestedscope.py for the rest.
##
-
+
# the 'self' argument of opcode implementations is called 'f'
# for historical reasons
Modified: pypy/branch/parser-compiler/pypy/lang/smalltalk/model.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/lang/smalltalk/model.py (original)
+++ pypy/branch/parser-compiler/pypy/lang/smalltalk/model.py Fri Jul 17 21:55:59 2009
@@ -20,7 +20,7 @@
from pypy.lang.smalltalk import constants, error
from pypy.tool.pairtype import extendabletype
from pypy.rlib.objectmodel import instantiate
-from pypy.lang.smalltalk.tool.bitmanipulation import splitter
+from pypy.rlib.bitmanipulation import splitter
class W_Object(object):
"""Root of Squeak model, abstract."""
Modified: pypy/branch/parser-compiler/pypy/lang/smalltalk/squeakimage.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/lang/smalltalk/squeakimage.py (original)
+++ pypy/branch/parser-compiler/pypy/lang/smalltalk/squeakimage.py Fri Jul 17 21:55:59 2009
@@ -3,7 +3,7 @@
from pypy.lang.smalltalk import constants
from pypy.lang.smalltalk import model
from pypy.rlib import objectmodel
-from pypy.lang.smalltalk.tool.bitmanipulation import splitter
+from pypy.rlib.bitmanipulation import splitter
def chrs2int(b):
assert len(b) == 4
Modified: pypy/branch/parser-compiler/pypy/module/__builtin__/functional.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/module/__builtin__/functional.py (original)
+++ pypy/branch/parser-compiler/pypy/module/__builtin__/functional.py Fri Jul 17 21:55:59 2009
@@ -61,33 +61,27 @@
get a list in decending order."""
try:
- # save duplication by redirecting every error to applevel
- x = space.int_w(w_x)
+ x = space.int_w(space.int(w_x))
if space.is_w(w_y, space.w_None):
start, stop = 0, x
else:
- start, stop = x, space.int_w(w_y)
- step = space.int_w(w_step)
+ start, stop = x, space.int_w(space.int(w_y))
+ step = space.int_w(space.int(w_step))
howmany = get_len_of_range(start, stop, step)
- except OperationError, e:
- if not e.match(space, space.w_TypeError):
- pass
- else:
- raise
- except (ValueError, OverflowError):
- pass
- else:
- if (space.config.objspace.std.withmultilist or
- space.config.objspace.std.withrangelist):
- return range_withspecialized_implementation(space, start,
- step, howmany)
- res_w = [None] * howmany
- v = start
- for idx in range(howmany):
- res_w[idx] = space.wrap(v)
- v += step
- return space.newlist(res_w)
- return range_fallback(space, w_x, w_y, w_step)
+ except (ValueError, OverflowError, OperationError):
+ # save duplication by redirecting every error to applevel
+ return range_fallback(space, w_x, w_y, w_step)
+
+ if (space.config.objspace.std.withmultilist or
+ space.config.objspace.std.withrangelist):
+ return range_withspecialized_implementation(space, start,
+ step, howmany)
+ res_w = [None] * howmany
+ v = start
+ for idx in range(howmany):
+ res_w[idx] = space.wrap(v)
+ v += step
+ return space.newlist(res_w)
range_int = range
range_int.unwrap_spec = [ObjSpace, W_Root, W_Root, W_Root]
del range # don't hide the builtin one
@@ -207,7 +201,7 @@
def _toint(space, w_obj):
# trying to support float arguments, just because CPython still does
try:
- return space.int_w(w_obj)
+ return space.int_w(space.int(w_obj))
except OperationError, e:
if space.is_true(space.isinstance(w_obj, space.w_float)):
return space.int_w(space.int(w_obj))
Modified: pypy/branch/parser-compiler/pypy/module/__builtin__/test/test_classobj.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/module/__builtin__/test/test_classobj.py (original)
+++ pypy/branch/parser-compiler/pypy/module/__builtin__/test/test_classobj.py Fri Jul 17 21:55:59 2009
@@ -505,6 +505,7 @@
raises(TypeError, cmp, a, b)
def test_hash(self):
+ import sys
class A:
pass
hash(A()) # does not crash
@@ -528,11 +529,12 @@
return 1
a = A()
raises(TypeError, hash, a)
+ bigint = sys.maxint + 1
class A: # can return long
def __hash__(self):
- return long(2**31)
+ return long(bigint)
a = A()
- assert hash(a) == -2147483648
+ assert hash(a) == -bigint
def test_index(self):
import sys
Modified: pypy/branch/parser-compiler/pypy/module/__builtin__/test/test_functional.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/module/__builtin__/test/test_functional.py (original)
+++ pypy/branch/parser-compiler/pypy/module/__builtin__/test/test_functional.py Fri Jul 17 21:55:59 2009
@@ -117,6 +117,25 @@
# test again, to make sure that xrange() is not its own iterator
assert iter(x).next() == 2
+ def test_xrange_object_with___int__(self):
+ class A(object):
+ def __int__(self):
+ return 5
+
+ assert list(xrange(A())) == [0, 1, 2, 3, 4]
+ assert list(xrange(0, A())) == [0, 1, 2, 3, 4]
+ assert list(xrange(0, 10, A())) == [0, 5]
+
+ def test_xrange_float(self):
+ assert list(xrange(0.1, 2.0, 1.1)) == [0, 1]
+
+ def test_xrange_long(self):
+ import sys
+ a = long(10 * sys.maxint)
+ raises(OverflowError, xrange, a)
+ raises(OverflowError, xrange, 0, a)
+ raises(OverflowError, xrange, 0, 1, a)
+
class AppTestReversed:
def test_reversed(self):
r = reversed("hello")
Modified: pypy/branch/parser-compiler/pypy/module/__builtin__/test/test_range.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/module/__builtin__/test/test_range.py (original)
+++ pypy/branch/parser-compiler/pypy/module/__builtin__/test/test_range.py Fri Jul 17 21:55:59 2009
@@ -17,7 +17,6 @@
def test_range_negstartisstop(self):
assert range(-1, -1) == []
-
def test_range_zero(self):
assert range(0) == []
@@ -60,10 +59,34 @@
def test_range_zerostep(self):
raises(ValueError, range, 1, 5, 0)
- def DONT_test_range_float(self):
- "How CPython does it - UGLY, ignored for now."
+ def test_range_float(self):
+ "How CPython does it - UGLY."
assert range(0.1, 2.0, 1.1) == [0, 1]
def test_range_wrong_type(self):
raises(TypeError, range, "42")
+ def test_range_object_with___int__(self):
+ class A(object):
+ def __int__(self):
+ return 5
+
+ assert range(A()) == [0, 1, 2, 3, 4]
+ assert range(0, A()) == [0, 1, 2, 3, 4]
+ assert range(0, 10, A()) == [0, 5]
+
+ def test_range_long(self):
+ import sys
+ assert range(-2**100) == []
+ assert range(0, -2**100) == []
+ assert range(0, 2**100, -1) == []
+ assert range(0, 2**100, -1) == []
+
+ a = long(10 * sys.maxint)
+ b = long(100 * sys.maxint)
+ c = long(50 * sys.maxint)
+
+ assert range(a, a+2) == [a, a+1]
+ assert range(a+2, a, -1L) == [a+2, a+1]
+ assert range(a+4, a, -2) == [a+4, a+2]
+
Modified: pypy/branch/parser-compiler/pypy/module/mmap/test/test_mmap.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/module/mmap/test/test_mmap.py (original)
+++ pypy/branch/parser-compiler/pypy/module/mmap/test/test_mmap.py Fri Jul 17 21:55:59 2009
@@ -42,7 +42,7 @@
raises(TypeError, mmap, 0, 1, 2, 3, 4, 5)
raises(TypeError, mmap, 0, 1, 2, 3, "foo", 5)
raises(TypeError, mmap, 0, 1, foo="foo")
- raises(TypeError, mmap, 0, -1)
+ raises((TypeError, OverflowError), mmap, 0, -1)
raises(OverflowError, mmap, 0, sys.maxint ** 3)
raises(ValueError, mmap, 0, 1, flags=2, access=3)
raises(ValueError, mmap, 0, 1, access=123)
@@ -410,7 +410,7 @@
def fn(m): m *= 1 # but it
raises((SystemError, TypeError), fn, m) # doesn't
def fn(): 1 * m # make much sense
- raises(TypeError, fn)
+ raises((SystemError, TypeError), fn)
m.close()
f.close()
#
Modified: pypy/branch/parser-compiler/pypy/module/posix/__init__.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/module/posix/__init__.py (original)
+++ pypy/branch/parser-compiler/pypy/module/posix/__init__.py Fri Jul 17 21:55:59 2009
@@ -120,6 +120,14 @@
if hasattr(os, name):
interpleveldefs[name] = 'interp_posix.' + name
+ def __init__(self, space, w_name):
+ backend = space.config.translation.backend
+ # the Win32 urandom implementation isn't going to translate on JVM or CLI
+ # so we have to remove it
+ if backend == 'cli' or backend == 'jvm':
+ del self.interpleveldefs['urandom']
+ MixedModule.__init__(self, space, w_name)
+
def startup(self, space):
from pypy.module.posix import interp_posix
interp_posix.get(space).startup(space)
Modified: pypy/branch/parser-compiler/pypy/objspace/std/dictmultiobject.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/objspace/std/dictmultiobject.py (original)
+++ pypy/branch/parser-compiler/pypy/objspace/std/dictmultiobject.py Fri Jul 17 21:55:59 2009
@@ -1049,6 +1049,7 @@
w_self.implementation = SharedDictImplementation(space)
else:
w_self.implementation = space.emptydictimpl
+ w_self.space = space
def initialize_content(w_self, list_pairs_w):
impl = w_self.implementation
@@ -1056,6 +1057,11 @@
impl = impl.setitem(w_k, w_v)
w_self.implementation = impl
+ def initialize_from_strdict_shared(w_self, strdict):
+ impl = StrDictImplementation(w_self.space)
+ impl.content = strdict
+ w_self.implementation = impl
+
def __repr__(w_self):
""" representation for debugging purposes """
return "%s(%s)" % (w_self.__class__.__name__, w_self.implementation)
Modified: pypy/branch/parser-compiler/pypy/objspace/std/dictobject.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/objspace/std/dictobject.py (original)
+++ pypy/branch/parser-compiler/pypy/objspace/std/dictobject.py Fri Jul 17 21:55:59 2009
@@ -13,11 +13,18 @@
w_self.content = r_dict(space.eq_w, space.hash_w)
else:
w_self.content = w_otherdict.content.copy()
+ w_self.space = space
def initialize_content(w_self, list_pairs_w):
for w_k, w_v in list_pairs_w:
w_self.content[w_k] = w_v
+ def initialize_from_strdict_shared(w_self, strdict):
+ # XXX the stuff below is slightly broken, as the dict is not really shared
+ # this would be very very annoying to fix with non-multidicts
+ for key, w_value in strdict.items():
+ w_self.content[w_self.space.wrap(key)] = w_value
+
def __repr__(w_self):
""" representation for debugging purposes """
return "%s(%s)" % (w_self.__class__.__name__, w_self.content)
Modified: pypy/branch/parser-compiler/pypy/objspace/std/fake.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/objspace/std/fake.py (original)
+++ pypy/branch/parser-compiler/pypy/objspace/std/fake.py Fri Jul 17 21:55:59 2009
@@ -10,11 +10,10 @@
# this file automatically generates non-reimplementations of CPython
# types that we do not yet implement in the standard object space
-# (files being the biggy)
def fake_object(space, x):
- if isinstance(x, file):
+ if isinstance(x, file):
debug_print("fake-wrapping interp file %s" % x)
if isinstance(x, type):
ft = fake_type(x)
@@ -61,10 +60,9 @@
def really_build_fake_type(cpy_type):
"NOT_RPYTHON (not remotely so!)."
- #assert not issubclass(cpy_type, file), cpy_type
debug_print('faking %r'%(cpy_type,))
kw = {}
-
+
if cpy_type.__name__ == 'SRE_Pattern':
import re
import __builtin__
@@ -92,7 +90,7 @@
for (key, w_value) in kwds_w.items():
kwds[key] = space.unwrap(w_value)
try:
- r = apply(cpy_type.__new__, [cpy_type]+args, kwds)
+ r = cpy_type.__new__(*[cpy_type]+args, **kwds)
except:
wrap_exception(space)
raise
@@ -118,11 +116,7 @@
w_self.val = val
def unwrap(w_self, space):
return w_self.val
-
- # cannot write to W_Fake.__name__ in Python 2.2!
- W_Fake = type(W_Object)('W_Fake%s'%(cpy_type.__name__.capitalize()),
- (W_Object,),
- dict(W_Fake.__dict__.items()))
+ W_Fake.__name__ = 'W_Fake%s'%(cpy_type.__name__.capitalize())
W_Fake.typedef.fakedcpytype = cpy_type
return W_Fake
@@ -159,7 +153,7 @@
def getfastscope(self):
raise OperationError(self.space.w_TypeError,
- self.space.wrap("cannot get fastscope of a CPythonFakeFrame"))
+ self.space.wrap("cannot get fastscope of a CPythonFakeFrame"))
def run(self):
code = self.fakecode
assert isinstance(code, CPythonFakeCode)
Modified: pypy/branch/parser-compiler/pypy/objspace/std/stringobject.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/objspace/std/stringobject.py (original)
+++ pypy/branch/parser-compiler/pypy/objspace/std/stringobject.py Fri Jul 17 21:55:59 2009
@@ -701,10 +701,9 @@
def str_splitlines__String_ANY(space, w_self, w_keepends):
- data = w_self._value
u_keepends = space.int_w(w_keepends) # truth value, but type checked
+ data = w_self._value
selflen = len(data)
-
strs_w = []
i = j = 0
while i < selflen:
@@ -723,7 +722,6 @@
if j < selflen:
strs_w.append(sliced(space, data, j, len(data), w_self))
-
return space.newlist(strs_w)
def str_zfill__String_ANY(space, w_self, w_width):
Modified: pypy/branch/parser-compiler/pypy/objspace/std/test/test_dictmultiobject.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/objspace/std/test/test_dictmultiobject.py (original)
+++ pypy/branch/parser-compiler/pypy/objspace/std/test/test_dictmultiobject.py Fri Jul 17 21:55:59 2009
@@ -12,6 +12,17 @@
def setup_class(cls):
cls.space = gettestobjspace(**{"objspace.std.withmultidict": True})
+ def test_initialize_from_strdict_really_shared(self):
+ space = self.space
+ w = space.wrap
+ d = {"a": w(1), "b": w(2)}
+ w_d = space.DictObjectCls(space)
+ w_d.initialize_from_strdict_shared(d)
+ assert self.space.eq_w(space.getitem(w_d, w("a")), w(1))
+ assert self.space.eq_w(space.getitem(w_d, w("b")), w(2))
+ d["c"] = w(41)
+ assert self.space.eq_w(space.getitem(w_d, w("c")), w(41))
+
class AppTest_DictMultiObject(test_dictobject.AppTest_DictObject):
def setup_class(cls):
cls.space = gettestobjspace(**{"objspace.std.withmultidict": True})
Modified: pypy/branch/parser-compiler/pypy/objspace/std/test/test_dictobject.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/objspace/std/test/test_dictobject.py (original)
+++ pypy/branch/parser-compiler/pypy/objspace/std/test/test_dictobject.py Fri Jul 17 21:55:59 2009
@@ -123,6 +123,16 @@
assert self.space.eq_w(space.call_function(get, w("33")), w(None))
assert self.space.eq_w(space.call_function(get, w("33"), w(44)), w(44))
+ def test_initialize_from_strdict_shared(self):
+ space = self.space
+ w = space.wrap
+ d = {"a": w(1), "b": w(2)}
+ w_d = space.DictObjectCls(space)
+ w_d.initialize_from_strdict_shared(d)
+ assert self.space.eq_w(space.getitem(w_d, w("a")), w(1))
+ assert self.space.eq_w(space.getitem(w_d, w("b")), w(2))
+
+
class AppTest_DictObject:
Modified: pypy/branch/parser-compiler/pypy/objspace/std/test/test_stringobject.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/objspace/std/test/test_stringobject.py (original)
+++ pypy/branch/parser-compiler/pypy/objspace/std/test/test_stringobject.py Fri Jul 17 21:55:59 2009
@@ -723,6 +723,9 @@
raises(TypeError, len, iter(iterable))
def test_overflow_replace(self):
+ import sys
+ if sys.maxint > 2**31-1:
+ skip("Wrong platform")
x = "A" * (2**16)
raises(OverflowError, x.replace, '', x)
Modified: pypy/branch/parser-compiler/pypy/objspace/std/test/test_typeobject.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/objspace/std/test/test_typeobject.py (original)
+++ pypy/branch/parser-compiler/pypy/objspace/std/test/test_typeobject.py Fri Jul 17 21:55:59 2009
@@ -915,14 +915,19 @@
return 0
raises(TypeError, X)
+class AppTestWithMultidictTypes:
+ def setup_class(cls):
+ cls.space = gettestobjspace(**{"objspace.std.withmultidict": True})
+
def test_dictproxy_is_updated(self):
- skip("fix me")
class A(object):
x = 1
d = A.__dict__
assert d["x"] == 1
A.y = 2
assert d["y"] == 2
+ assert ("x", 1) in d.items()
+ assert ("y", 2) in d.items()
class AppTestMutableBuiltintypes:
Modified: pypy/branch/parser-compiler/pypy/objspace/std/typeobject.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/objspace/std/typeobject.py (original)
+++ pypy/branch/parser-compiler/pypy/objspace/std/typeobject.py Fri Jul 17 21:55:59 2009
@@ -246,14 +246,8 @@
if w_self.lazyloaders:
w_self._freeze_() # force un-lazification
space = w_self.space
- dictspec = []
- for key, w_value in w_self.dict_w.items():
- dictspec.append((space.wrap(key), w_value))
- # speed hack: instantiate a dict object cls directly
- # NB: cannot use newdict, because that could return something else
- # than an instance of DictObjectCls
newdic = space.DictObjectCls(space)
- newdic.initialize_content(dictspec)
+ newdic.initialize_from_strdict_shared(w_self.dict_w)
return W_DictProxyObject(newdic)
def unwrap(w_self, space):
Modified: pypy/branch/parser-compiler/pypy/rlib/libffi.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/rlib/libffi.py (original)
+++ pypy/branch/parser-compiler/pypy/rlib/libffi.py Fri Jul 17 21:55:59 2009
@@ -255,6 +255,8 @@
pass # No check
libc_name = ctypes.util.find_library('c')
+ assert libc_name is not None, "Cannot find C library, ctypes.util.find_library('c') returned None"
+
def get_libc_name():
return libc_name
Modified: pypy/branch/parser-compiler/pypy/rlib/rsre/rsre.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/rlib/rsre/rsre.py (original)
+++ pypy/branch/parser-compiler/pypy/rlib/rsre/rsre.py Fri Jul 17 21:55:59 2009
@@ -12,6 +12,7 @@
rsre_core_filename = rsre_core_filename[:-1]
rsre_core_filename = os.path.abspath(rsre_core_filename)
del rsre_core
+from pypy.rlib.rsre.rsre_char import getlower
def insert_sre_methods(locals, name):
"""A hack that inserts the SRE entry point methods into the 'locals'
@@ -58,3 +59,6 @@
def get_char_ord(self, p):
return ord(self.string[p])
+
+ def lower(self, char_ord):
+ return getlower(char_ord, 0)
Modified: pypy/branch/parser-compiler/pypy/rlib/rsre/test/test_rsre.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/rlib/rsre/test/test_rsre.py (original)
+++ pypy/branch/parser-compiler/pypy/rlib/rsre/test/test_rsre.py Fri Jul 17 21:55:59 2009
@@ -80,6 +80,11 @@
def test_getlower():
assert rsre_char.getlower(ord("A"), 0) == ord("a")
+def test_SimpleStringState():
+ state = SimpleStringState("A", 0, -1)
+ assert state.get_char_ord(0) == ord("A")
+ assert state.lower(state.get_char_ord(0)) == ord("a")
+
def test_get_byte_array():
if sys.byteorder == "big":
if rsre_char.CODESIZE == 2:
Modified: pypy/branch/parser-compiler/pypy/rlib/runicode.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/rlib/runicode.py (original)
+++ pypy/branch/parser-compiler/pypy/rlib/runicode.py Fri Jul 17 21:55:59 2009
@@ -1,5 +1,5 @@
import sys
-from pypy.lang.smalltalk.tool.bitmanipulation import splitter
+from pypy.rlib.bitmanipulation import splitter
from pypy.rpython.lltypesystem import lltype, rffi
from pypy.rlib.objectmodel import we_are_translated
Modified: pypy/branch/parser-compiler/pypy/rlib/streamio.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/rlib/streamio.py (original)
+++ pypy/branch/parser-compiler/pypy/rlib/streamio.py Fri Jul 17 21:55:59 2009
@@ -176,6 +176,10 @@
compilation_info=_eci)
SetEndOfFile = rffi.llexternal('SetEndOfFile', [rffi.LONG], rwin32.BOOL,
compilation_info=_eci)
+
+ # HACK: These implementations are specific to MSVCRT and the C backend.
+ # When generating on CLI or JVM, these are patched out.
+ # See PyPyTarget.target() in targetpypystandalone.py
def _setfd_binary(fd):
_setmode(fd, os.O_BINARY)
Modified: pypy/branch/parser-compiler/pypy/rpython/lltypesystem/ll2ctypes.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/rpython/lltypesystem/ll2ctypes.py (original)
+++ pypy/branch/parser-compiler/pypy/rpython/lltypesystem/ll2ctypes.py Fri Jul 17 21:55:59 2009
@@ -19,6 +19,7 @@
from pypy.rpython.lltypesystem.rclass import OBJECT
from pypy.rpython.annlowlevel import base_ptr_lltype
from pypy.rpython import raddress
+from pypy.translator.platform import platform
def uaddressof(obj):
return fixid(ctypes.addressof(obj))
@@ -813,22 +814,46 @@
cfunc = get_on_lib(ctypes.windll.kernel32, funcname)
else:
cfunc = None
+ not_found = []
for libname in libraries:
- libpath = ctypes.util.find_library(libname)
- if not libpath and os.path.isabs(libname):
- libpath = libname
+ libpath = None
+ ext = platform.so_ext
+ prefixes = platform.so_prefixes
+ for dir in eci.library_dirs:
+ if libpath:
+ break
+ for prefix in prefixes:
+ tryfile = os.path.join(dir, prefix + libname + '.' + ext)
+ if os.path.isfile(tryfile):
+ libpath = tryfile
+ break
+ if not libpath:
+ libpath = ctypes.util.find_library(libname)
+ if not libpath and os.path.isabs(libname):
+ libpath = libname
if libpath:
dllclass = getattr(ctypes, calling_conv + 'dll')
- # urgh, cannot pass the flag to dllclass.LoadLibrary
- clib = dllclass._dlltype(libpath, ctypes.RTLD_GLOBAL)
+ # on ie slackware there was need for RTLD_GLOBAL here.
+ # this breaks a lot of things, since passing RTLD_GLOBAL
+ # creates symbol conflicts on C level.
+ clib = dllclass.LoadLibrary(libpath)
cfunc = get_on_lib(clib, funcname)
if cfunc is not None:
break
+ else:
+ not_found.append(libname)
if cfunc is None:
# function name not found in any of the libraries
if not libraries:
place = 'the standard C library (missing libraries=...?)'
+ elif len(not_found) == len(libraries):
+ if len(not_found) == 1:
+ raise NotImplementedError(
+ 'cannot find the library %r' % (not_found[0],))
+ else:
+ raise NotImplementedError(
+ 'cannot find any of the libraries %r' % (not_found,))
elif len(libraries) == 1:
place = 'library %r' % (libraries[0],)
else:
Modified: pypy/branch/parser-compiler/pypy/rpython/lltypesystem/rstr.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/rpython/lltypesystem/rstr.py (original)
+++ pypy/branch/parser-compiler/pypy/rpython/lltypesystem/rstr.py Fri Jul 17 21:55:59 2009
@@ -674,6 +674,7 @@
s1.copy_contents(s1, newstr, 0, 0, newlen)
return newstr
+
def ll_split_chr(LIST, s, c):
chars = s.chars
strlen = len(chars)
Modified: pypy/branch/parser-compiler/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/rpython/lltypesystem/test/test_ll2ctypes.py (original)
+++ pypy/branch/parser-compiler/pypy/rpython/lltypesystem/test/test_ll2ctypes.py Fri Jul 17 21:55:59 2009
@@ -15,6 +15,7 @@
from pypy.rpython.test.test_llinterp import interpret
from pypy.annotation.annrpython import RPythonAnnotator
from pypy.rpython.rtyper import RPythonTyper
+from pypy.tool.udir import udir
class TestLL2Ctypes(object):
@@ -994,3 +995,46 @@
v2 = ctypes2lltype(llmemory.GCREF, ctypes.c_void_p(1235))
assert v2 != v
+class TestPlatform(object):
+ def test_lib_on_libpaths(self):
+ from pypy.translator.platform import platform
+ from pypy.translator.tool.cbuild import ExternalCompilationInfo
+
+ tmpdir = udir.join('lib_on_libppaths')
+ tmpdir.ensure(dir=1)
+ c_file = tmpdir.join('c_file.c')
+ c_file.write('int f(int a, int b) { return (a + b); }')
+ eci = ExternalCompilationInfo(export_symbols=['f'])
+ so = platform.compile([c_file], eci, standalone=False)
+ eci = ExternalCompilationInfo(
+ libraries = ['c_file'],
+ library_dirs = [str(so.dirpath())]
+ )
+ f = rffi.llexternal('f', [rffi.INT, rffi.INT], rffi.INT,
+ compilation_info=eci)
+ assert f(3, 4) == 7
+
+ def test_prefix(self):
+
+ if sys.platform != 'linux2':
+ py.test.skip("Not supported")
+
+ from pypy.translator.platform import platform
+ from pypy.translator.tool.cbuild import ExternalCompilationInfo
+
+ tmpdir = udir.join('lib_on_libppaths_prefix')
+ tmpdir.ensure(dir=1)
+ c_file = tmpdir.join('c_file.c')
+ c_file.write('int f(int a, int b) { return (a + b); }')
+ eci = ExternalCompilationInfo()
+ so = platform.compile([c_file], eci, standalone=False)
+ sopath = py.path.local(so)
+ sopath.move(sopath.dirpath().join('libc_file.so'))
+ eci = ExternalCompilationInfo(
+ libraries = ['c_file'],
+ library_dirs = [str(so.dirpath())]
+ )
+ f = rffi.llexternal('f', [rffi.INT, rffi.INT], rffi.INT,
+ compilation_info=eci)
+ assert f(3, 4) == 7
+
Modified: pypy/branch/parser-compiler/pypy/rpython/module/ll_os.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/rpython/module/ll_os.py (original)
+++ pypy/branch/parser-compiler/pypy/rpython/module/ll_os.py Fri Jul 17 21:55:59 2009
@@ -88,10 +88,31 @@
def __init__(self):
self.configure(CConfig)
+ # on some platforms, e.g. OS X Leopard, the following constants which
+ # may be defined in pyconfig.h triggers "legacy" behaviour for functions
+ # like setpgrp():
+ #
+ # _POSIX_C_SOURCE 200112L
+ # _XOPEN_SOURCE 600
+ # _DARWIN_C_SOURCE 1
+ #
+ # since the translation currently includes pyconfig.h, the checkcompiles
+ # call below include the pyconfig.h file so that the same behaviour is
+ # present in both the check and the final translation...
+
if hasattr(os, 'getpgrp'):
- self.GETPGRP_HAVE_ARG = platform.checkcompiles("getpgrp(0)", "#include <unistd.h>")
+ self.GETPGRP_HAVE_ARG = platform.checkcompiles(
+ "getpgrp(0)",
+ '#include "pyconfig.h"\n#include <unistd.h>',
+ [platform.get_python_include_dir()]
+ )
+
if hasattr(os, 'setpgrp'):
- self.SETPGRP_HAVE_ARG = platform.checkcompiles("setpgrp(0,0)", "#include <unistd.h>")
+ self.SETPGRP_HAVE_ARG = platform.checkcompiles(
+ "setpgrp(0,0)",
+ '#include "pyconfig.h"\n#include <unistd.h>',
+ [platform.get_python_include_dir()]
+ )
# we need an indirection via c functions to get macro calls working on llvm XXX still?
if hasattr(os, 'WCOREDUMP'):
Modified: pypy/branch/parser-compiler/pypy/rpython/module/test/test_ll_os.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/rpython/module/test/test_ll_os.py (original)
+++ pypy/branch/parser-compiler/pypy/rpython/module/test/test_ll_os.py Fri Jul 17 21:55:59 2009
@@ -84,7 +84,13 @@
ll_execve = getllimpl(os.execve)
- def run_execve(program, env):
+ def run_execve(program, args=None, env=None, do_path_lookup=False):
+ if args is None:
+ args = [program]
+ else:
+ args = [program] + args
+ if env is None:
+ env = {}
# we cannot directly call ll_execve() because it replaces the
# current process.
fd_read, fd_write = os.pipe()
@@ -94,7 +100,10 @@
os.close(fd_read)
os.dup2(fd_write, 1) # stdout
os.close(fd_write)
- ll_execve(program, [program], env)
+ if do_path_lookup:
+ os.execvp(program, args)
+ else:
+ ll_execve(program, args, env)
assert 0, "should not arrive here"
else:
# in the parent
@@ -109,15 +118,17 @@
return status, ''.join(child_stdout)
# Test exit status and code
- result, child_stdout = run_execve("/bin/true", {})
+ result, child_stdout = run_execve("/usr/bin/which", ["true"], do_path_lookup=True)
+ result, child_stdout = run_execve(child_stdout.strip()) # /bin/true or /usr/bin/true
assert os.WIFEXITED(result)
assert os.WEXITSTATUS(result) == 0
- result, child_stdout = run_execve("/bin/false", {})
+ result, child_stdout = run_execve("/usr/bin/which", ["false"], do_path_lookup=True)
+ result, child_stdout = run_execve(child_stdout.strip()) # /bin/false or /usr/bin/false
assert os.WIFEXITED(result)
assert os.WEXITSTATUS(result) == 1
# Test environment
- result, child_stdout = run_execve("/usr/bin/env", EXECVE_ENV)
+ result, child_stdout = run_execve("/usr/bin/env", env=EXECVE_ENV)
assert os.WIFEXITED(result)
assert os.WEXITSTATUS(result) == 0
assert dict([line.split('=') for line in child_stdout.splitlines()]) == EXECVE_ENV
Modified: pypy/branch/parser-compiler/pypy/rpython/rstr.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/rpython/rstr.py (original)
+++ pypy/branch/parser-compiler/pypy/rpython/rstr.py Fri Jul 17 21:55:59 2009
@@ -7,7 +7,7 @@
from pypy.rpython.rtuple import AbstractTupleRepr
from pypy.rpython import rint
from pypy.rpython.lltypesystem.lltype import Signed, Bool, Void, UniChar,\
- cast_primitive
+ cast_primitive, typeOf
class AbstractStringRepr(Repr):
pass
@@ -213,6 +213,20 @@
raise TyperError("sep.join() of non-string list: %r" % r_lst)
return hop.gendirectcall(llfn, v_str, v_length, v_items)
+ def rtype_method_splitlines(self, hop):
+ rstr = hop.args_r[0].repr
+ if hop.nb_args == 2:
+ args = hop.inputargs(rstr.repr, Bool)
+ else:
+ args = [hop.inputarg(rstr.repr, 0), hop.inputconst(Bool, False)]
+ try:
+ list_type = hop.r_result.lowleveltype.TO
+ except AttributeError:
+ list_type = hop.r_result.lowleveltype
+ cLIST = hop.inputconst(Void, list_type)
+ hop.exception_cannot_occur()
+ return hop.gendirectcall(self.ll.ll_splitlines, cLIST, *args)
+
def rtype_method_split(self, hop):
rstr = hop.args_r[0].repr
v_str, v_chr = hop.inputargs(rstr.repr, rstr.char_repr)
@@ -718,3 +732,36 @@
raise ValueError
return parts_to_float(sign, before_point, after_point, exponent)
+
+ def ll_splitlines(cls, LIST, ll_str, keep_newlines):
+ from pypy.rpython.annlowlevel import hlstr
+ s = hlstr(ll_str)
+ STR = typeOf(ll_str)
+ strlen = len(s)
+ i = 0
+ j = 0
+ # The annotator makes sure this list is resizable.
+ res = LIST.ll_newlist(0)
+ while j < strlen:
+ while i < strlen and s[i] != '\n' and s[i] != '\r':
+ i += 1
+ eol = i
+ if i < strlen:
+ if s[i] == '\r' and i + 1 < strlen and s[i + 1] == '\n':
+ i += 2
+ else:
+ i += 1
+ if keep_newlines:
+ eol = i
+ list_length = res.ll_length()
+ res._ll_resize_ge(list_length + 1)
+ item = cls.ll_stringslice_startstop(ll_str, j, eol)
+ res.ll_setitem_fast(list_length, item)
+ j = i
+ if j < strlen:
+ list_length = res.ll_length()
+ res._ll_resize_ge(list_length + 1)
+ item = cls.ll_stringslice_startstop(ll_str, j, strlen)
+ res.ll_setitem_fast(list_length, item)
+ return res
+ ll_splitlines = classmethod(ll_splitlines)
Modified: pypy/branch/parser-compiler/pypy/rpython/test/test_rfloat.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/rpython/test/test_rfloat.py (original)
+++ pypy/branch/parser-compiler/pypy/rpython/test/test_rfloat.py Fri Jul 17 21:55:59 2009
@@ -2,7 +2,7 @@
from pypy.translator.translator import TranslationContext
from pypy.rpython.test import snippet
from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin, OORtypeMixin
-from pypy.rlib.rarithmetic import r_uint, r_longlong, r_singlefloat,\
+from pypy.rlib.rarithmetic import r_int, r_uint, r_longlong, r_singlefloat,\
isnan, isinf
class TestSnippet(object):
@@ -76,12 +76,17 @@
assert res == fn(2.34)
def test_longlong_conversion(self):
+ import sys
def fn(f):
return r_longlong(f)
res = self.interpret(fn, [1.0])
assert res == 1
- assert self.is_of_type(res, r_longlong)
+ # r_longlong is int on a 64 bit system
+ if sys.maxint == 2**63 - 1:
+ assert self.is_of_type(res, int)
+ else:
+ assert self.is_of_type(res, r_longlong)
res = self.interpret(fn, [2.34])
assert res == fn(2.34)
big = float(0x7fffffffffffffff)
Modified: pypy/branch/parser-compiler/pypy/rpython/test/test_rstr.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/rpython/test/test_rstr.py (original)
+++ pypy/branch/parser-compiler/pypy/rpython/test/test_rstr.py Fri Jul 17 21:55:59 2009
@@ -554,6 +554,21 @@
res = self.ll_to_string(self.interpret(dummy, []))
assert res == expected
+ def test_splitlines(self):
+ const = self.const
+ def f(i, newlines):
+ s = [const(''), const("\n"), const("\n\n"), const("hi\n"),
+ const("random data\r\n"), const("\r\n"), const("\rdata")]
+ test_string = s[i]
+ if newlines:
+ return len(test_string.splitlines(True))
+ else:
+ return len(test_string.splitlines())
+ for newlines in (True, False):
+ for i in xrange(5):
+ res = self.interpret(f, [i, newlines])
+ assert res == f(i, newlines)
+
def test_split(self):
const = self.const
def fn(i):
Modified: pypy/branch/parser-compiler/pypy/rpython/test/test_runicode.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/rpython/test/test_runicode.py (original)
+++ pypy/branch/parser-compiler/pypy/rpython/test/test_runicode.py Fri Jul 17 21:55:59 2009
@@ -200,6 +200,7 @@
test_char_isxxx = unsupported
test_upper = unsupported
test_lower = unsupported
+ test_splitlines = unsupported
test_strformat = unsupported
test_strformat_instance = unsupported
test_strformat_nontuple = unsupported
Modified: pypy/branch/parser-compiler/pypy/rpython/tool/rffi_platform.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/rpython/tool/rffi_platform.py (original)
+++ pypy/branch/parser-compiler/pypy/rpython/tool/rffi_platform.py Fri Jul 17 21:55:59 2009
@@ -14,9 +14,12 @@
#
# Helpers for simple cases
-def eci_from_header(c_header_source):
+def eci_from_header(c_header_source, include_dirs=None):
+ if include_dirs is None:
+ include_dirs = []
return ExternalCompilationInfo(
- pre_include_bits=[c_header_source]
+ pre_include_bits=[c_header_source],
+ include_dirs=include_dirs
)
def getstruct(name, c_header_source, interesting_fields):
@@ -43,9 +46,9 @@
DEFINED = Defined(macro)
return configure(CConfig)['DEFINED']
-def has(name, c_header_source):
+def has(name, c_header_source, include_dirs=None):
class CConfig:
- _compilation_info_ = eci_from_header(c_header_source)
+ _compilation_info_ = eci_from_header(c_header_source, include_dirs)
HAS = Has(name)
return configure(CConfig)['HAS']
@@ -57,9 +60,9 @@
WORKS = Works()
configure(CConfig)
-def checkcompiles(expression, c_header_source):
+def checkcompiles(expression, c_header_source, include_dirs=None):
"""Check if expression compiles. If not, returns False"""
- return has(expression, c_header_source)
+ return has(expression, c_header_source, include_dirs)
def sizeof(name, eci, **kwds):
class CConfig:
Modified: pypy/branch/parser-compiler/pypy/rpython/tool/test/test_rffi_platform.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/rpython/tool/test/test_rffi_platform.py (original)
+++ pypy/branch/parser-compiler/pypy/rpython/tool/test/test_rffi_platform.py Fri Jul 17 21:55:59 2009
@@ -4,6 +4,7 @@
from pypy.rpython.lltypesystem import rffi
from pypy.tool.udir import udir
from pypy.translator.tool.cbuild import ExternalCompilationInfo
+from pypy.translator.platform import platform
def import_ctypes():
try:
@@ -234,3 +235,24 @@
a = rffi_platform.memory_alignment()
print a
assert a % struct.calcsize("P") == 0
+
+def test_external_lib():
+ # XXX this one seems to be a bit too platform-specific. Check
+ # how to test it on windows correctly (using so_prefix?)
+ # and what are alternatives to LD_LIBRARY_PATH
+ eci = ExternalCompilationInfo()
+ c_source = """
+ int f(int a, int b)
+ {
+ return (a + b);
+ }
+ """
+ tmpdir = udir.join('external_lib').ensure(dir=1)
+ c_file = tmpdir.join('libc_lib.c')
+ c_file.write(c_source)
+ l = platform.compile([c_file], eci, standalone=False)
+ eci = ExternalCompilationInfo(
+ libraries = ['c_lib'],
+ library_dirs = [str(tmpdir)]
+ )
+ rffi_platform.verify_eci(eci)
Modified: pypy/branch/parser-compiler/pypy/translator/backendopt/test/test_merge_if_blocks.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/translator/backendopt/test/test_merge_if_blocks.py (original)
+++ pypy/branch/parser-compiler/pypy/translator/backendopt/test/test_merge_if_blocks.py Fri Jul 17 21:55:59 2009
@@ -122,6 +122,16 @@
assert res == 6
+def test_merge_with_or():
+ def merge(n):
+ if n == 5:
+ return 4
+ elif n == 14 or n == 2:
+ return 16
+ else:
+ return 7
+ do_test_merge(merge, [5, 6, 14, 2, 3, 123])
+
def test_dont_merge():
def merge(n, m):
Modified: pypy/branch/parser-compiler/pypy/translator/c/genc.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/translator/c/genc.py (original)
+++ pypy/branch/parser-compiler/pypy/translator/c/genc.py Fri Jul 17 21:55:59 2009
@@ -105,7 +105,7 @@
def __init__(self, translator, entrypoint, config, gcpolicy=None):
self.translator = translator
self.entrypoint = entrypoint
- self.entrypoint_name = self.entrypoint.func_name
+ self.entrypoint_name = getattr(self.entrypoint, 'func_name', None)
self.originalentrypoint = entrypoint
self.config = config
self.gcpolicy = gcpolicy # for tests only, e.g. rpython/memory/
@@ -156,8 +156,13 @@
# build entrypoint and eventually other things to expose
pf = self.getentrypointptr()
- pfname = db.get(pf)
- self.c_entrypoint_name = pfname
+ if isinstance(pf, list):
+ for one_pf in pf:
+ db.get(one_pf)
+ self.c_entrypoint_name = None
+ else:
+ pfname = db.get(pf)
+ self.c_entrypoint_name = pfname
db.complete()
self.collect_compilation_info(db)
@@ -209,7 +214,6 @@
if db is None:
db = self.build_database()
pf = self.getentrypointptr()
- pfname = db.get(pf)
if self.modulename is None:
self.modulename = uniquemodulename('testing')
modulename = self.modulename
@@ -229,6 +233,7 @@
self.eci,
defines = defines)
else:
+ pfname = db.get(pf)
if self.config.translation.instrument:
defines['INSTRUMENT'] = 1
if CBuilder.have___thread:
Modified: pypy/branch/parser-compiler/pypy/translator/c/node.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/translator/c/node.py (original)
+++ pypy/branch/parser-compiler/pypy/translator/c/node.py Fri Jul 17 21:55:59 2009
@@ -13,6 +13,7 @@
from pypy.rlib.rarithmetic import isinf, isnan
from pypy.translator.c import extfunc
from pypy.translator.tool.cbuild import ExternalCompilationInfo
+from py.builtin import BaseException
def needs_gcheader(T):
if not isinstance(T, ContainerType):
@@ -691,7 +692,11 @@
self.db = db
self.T = T
self.obj = obj
- if getattr(obj, 'external', None) == 'C' and not db.need_sandboxing(obj):
+ callable = getattr(obj, '_callable', None)
+ if (callable is not None and
+ getattr(callable, 'c_name', None) is not None):
+ self.name = forcename or obj._callable.c_name
+ elif getattr(obj, 'external', None) == 'C' and not db.need_sandboxing(obj):
self.name = forcename or self.basename()
else:
self.name = (forcename or
@@ -888,7 +893,7 @@
return 'Py_None'
import types, py
if isinstance(value, (type, types.ClassType)):
- if (issubclass(value, Exception) and
+ if (issubclass(value, BaseException) and
(value.__module__ == 'exceptions'
or value is py.magic.AssertionError)):
return 'PyExc_' + value.__name__
Modified: pypy/branch/parser-compiler/pypy/translator/c/test/test_genc.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/translator/c/test/test_genc.py (original)
+++ pypy/branch/parser-compiler/pypy/translator/c/test/test_genc.py Fri Jul 17 21:55:59 2009
@@ -12,7 +12,6 @@
from pypy.translator.gensupp import uniquemodulename
from pypy.translator.backendopt.all import backend_optimizations
from pypy.translator.interactive import Translation
-from pypy import conftest
def compile(fn, argtypes, view=False, gcpolicy="ref", backendopt=True,
annotatorpolicy=None):
@@ -24,7 +23,7 @@
# XXX fish
t.driver.config.translation.countmallocs = True
compiled_fn = t.compile_c()
- if conftest.option.view:
+ if py.test.config.option.view:
t.view()
malloc_counters = t.driver.cbuilder.get_malloc_counters()
def checking_fn(*args, **kwds):
@@ -393,3 +392,16 @@
fn = compile(f, [])
fn()
+
+def test_name():
+ def f():
+ return 3
+
+ f.c_name = 'pypy_xyz_f'
+
+ t = Translation(f, [], backend="c")
+ t.annotate()
+ compiled_fn = t.compile_c()
+ if py.test.config.option.view:
+ t.view()
+ assert 'pypy_xyz_f' in t.driver.cbuilder.c_source_filename.read()
Modified: pypy/branch/parser-compiler/pypy/translator/c/test/test_newgc.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/translator/c/test/test_newgc.py (original)
+++ pypy/branch/parser-compiler/pypy/translator/c/test/test_newgc.py Fri Jul 17 21:55:59 2009
@@ -655,19 +655,6 @@
res = fn()
assert res == 123
- def test_framework_malloc_gc(self):
- py.test.skip('in-progress')
- A = lltype.GcStruct('A', ('value', lltype.Signed))
-
- def f():
- p = lltype.malloc(A, flavor='gc')
- p.value = 123
- llop.gc__collect(lltype.Void)
- return p.value
- fn = self.getcompiled(f)
- res = fn()
- assert res == 123
-
def test_framework_del_seeing_new_types(self):
class B(object):
pass
Modified: pypy/branch/parser-compiler/pypy/translator/c/test/test_standalone.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/translator/c/test/test_standalone.py (original)
+++ pypy/branch/parser-compiler/pypy/translator/c/test/test_standalone.py Fri Jul 17 21:55:59 2009
@@ -77,11 +77,11 @@
cbuilder.compile()
counters_fname = udir.join("_counters_")
- os.putenv('_INSTRUMENT_COUNTERS', str(counters_fname))
+ os.environ['_INSTRUMENT_COUNTERS'] = str(counters_fname)
try:
data = cbuilder.cmdexec()
finally:
- os.unsetenv('_INSTRUMENT_COUNTERS')
+ del os.environ['_INSTRUMENT_COUNTERS']
f = counters_fname.open('rb')
counters_data = f.read()
Modified: pypy/branch/parser-compiler/pypy/translator/cli/src/ll_os.cs
==============================================================================
--- pypy/branch/parser-compiler/pypy/translator/cli/src/ll_os.cs (original)
+++ pypy/branch/parser-compiler/pypy/translator/cli/src/ll_os.cs Fri Jul 17 21:55:59 2009
@@ -261,7 +261,8 @@
public static void ll_os_close(int fd)
{
FileStream stream = getfd(fd).GetStream();
- stream.Close();
+ if (stream != null) // stdin/stdout/stderr files don't have a stream
+ stream.Close();
FileDescriptors.Remove(fd);
}
Modified: pypy/branch/parser-compiler/pypy/translator/driver.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/translator/driver.py (original)
+++ pypy/branch/parser-compiler/pypy/translator/driver.py Fri Jul 17 21:55:59 2009
@@ -304,6 +304,7 @@
assert self.libdef is not None
for func, inputtypes in self.libdef.functions:
annotator.build_types(func, inputtypes)
+ func.c_name = func.func_name
self.sanity_check_annotation()
annotator.simplify()
#
@@ -422,15 +423,20 @@
if translator.annotator is not None:
translator.frozen = True
- standalone = self.standalone
-
- if standalone:
- from pypy.translator.c.genc import CStandaloneBuilder as CBuilder
+ if self.libdef is not None:
+ cbuilder = self.libdef.getcbuilder(self.translator, self.config)
+ self.standalone = False
+ standalone = False
else:
- from pypy.translator.c.genc import CExtModuleBuilder as CBuilder
- cbuilder = CBuilder(self.translator, self.entry_point,
- config=self.config)
- cbuilder.stackless = self.config.translation.stackless
+ standalone = self.standalone
+
+ if standalone:
+ from pypy.translator.c.genc import CStandaloneBuilder as CBuilder
+ else:
+ from pypy.translator.c.genc import CExtModuleBuilder as CBuilder
+ cbuilder = CBuilder(self.translator, self.entry_point,
+ config=self.config)
+ cbuilder.stackless = self.config.translation.stackless
if not standalone: # xxx more messy
cbuilder.modulename = self.extmod_name
database = cbuilder.build_database()
@@ -477,7 +483,7 @@
def task_compile_c(self): # xxx messy
cbuilder = self.cbuilder
cbuilder.compile()
-
+
if self.standalone:
self.c_entryp = cbuilder.executable_name
self.create_exe()
Modified: pypy/branch/parser-compiler/pypy/translator/goal/targetpypystandalone.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/translator/goal/targetpypystandalone.py (original)
+++ pypy/branch/parser-compiler/pypy/translator/goal/targetpypystandalone.py Fri Jul 17 21:55:59 2009
@@ -199,6 +199,16 @@
wrapstr = 'space.wrap(%r)' % (options)
pypy.module.sys.Module.interpleveldefs['pypy_translation_info'] = wrapstr
+ if config.translation.backend in ["cli", "jvm"] and sys.platform == "win32":
+ # HACK: The ftruncate implementation in streamio.py which is used for the Win32 platform
+ # is specific for the C backend and can't be generated on CLI or JVM. Because of that,
+ # we have to patch it out.
+ from pypy.rlib import streamio
+ def ftruncate_win32_dummy(fd, size): pass
+ def _setfd_binary_dummy(fd): pass
+ streamio.ftruncate_win32 = ftruncate_win32_dummy
+ streamio._setfd_binary = _setfd_binary_dummy
+
return self.get_entry_point(config)
def jitpolicy(self, driver):
Modified: pypy/branch/parser-compiler/pypy/translator/goal/translate.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/translator/goal/translate.py (original)
+++ pypy/branch/parser-compiler/pypy/translator/goal/translate.py Fri Jul 17 21:55:59 2009
@@ -54,6 +54,10 @@
"cProfile (to debug the speed of the translation process)",
default=False,
cmdline="--profile"),
+ BoolOption("pdb",
+ "Always run pdb even if the translation succeeds",
+ default=False,
+ cmdline="--pdb"),
BoolOption("batch", "Don't run interactive helpers", default=False,
cmdline="--batch", negation=False),
IntOption("huge", "Threshold in the number of functions after which "
@@ -279,7 +283,8 @@
debug(True)
raise SystemExit(1)
else:
- debug(False)
+ if translateconfig.pdb:
+ debug(False)
if __name__ == '__main__':
Modified: pypy/branch/parser-compiler/pypy/translator/jvm/genjvm.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/translator/jvm/genjvm.py (original)
+++ pypy/branch/parser-compiler/pypy/translator/jvm/genjvm.py Fri Jul 17 21:55:59 2009
@@ -3,6 +3,7 @@
"""
import sys
+import os
import py
from py.compat import subprocess
@@ -197,7 +198,7 @@
cmd = [getoption('java'),
'-Xmx256M', # increase the heapsize so the microbenchmarks run
'-cp',
- str(self.javadir)+":"+str(self.jnajar),
+ str(self.javadir)+os.pathsep+str(self.jnajar),
self.package+".Main"] + strargs
print "Invoking java to run the code"
stdout, stderr, retval = self._invoke(cmd, True)
Modified: pypy/branch/parser-compiler/pypy/translator/platform/__init__.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/translator/platform/__init__.py (original)
+++ pypy/branch/parser-compiler/pypy/translator/platform/__init__.py Fri Jul 17 21:55:59 2009
@@ -52,6 +52,8 @@
name = "abstract platform"
c_environ = None
+ so_prefixes = ['']
+
def __init__(self, cc):
if self.__class__ is Platform:
raise TypeError("You should not instantiate Platform class directly")
@@ -70,7 +72,12 @@
ofiles.append(self._compile_c_file(self.cc, cfile, compile_args))
return ofiles
- def execute(self, executable, args=None, env=None):
+ def execute(self, executable, args=None, env=None, compilation_info=None):
+ if env is None:
+ env = os.environ.copy()
+ if compilation_info is not None:
+ env['LD_LIBRARY_PATH'] = ':'.join(
+ [str(i) for i in compilation_info.library_dirs])
returncode, stdout, stderr = _run_subprocess(str(executable), args,
env)
return ExecutionResult(returncode, stdout, stderr)
@@ -120,7 +127,7 @@
cflags = self.cflags + extra
return (cflags + list(eci.compile_extra) + args)
- def _link_args_from_eci(self, eci):
+ def _link_args_from_eci(self, eci, standalone):
library_dirs = self._libdirs(eci.library_dirs)
libraries = self._libs(eci.libraries)
link_files = self._linkfiles(eci.link_files)
@@ -137,8 +144,8 @@
exe_name += '.' + self.exe_ext
else:
exe_name += '.' + self.so_ext
- return self._link(self.cc, ofiles, self._link_args_from_eci(eci),
- standalone, exe_name)
+ largs = self._link_args_from_eci(eci, standalone)
+ return self._link(self.cc, ofiles, largs, standalone, exe_name)
# below are some detailed informations for platforms
Modified: pypy/branch/parser-compiler/pypy/translator/platform/darwin.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/translator/platform/darwin.py (original)
+++ pypy/branch/parser-compiler/pypy/translator/platform/darwin.py Fri Jul 17 21:55:59 2009
@@ -38,8 +38,8 @@
args.append(f)
return args
- def _link_args_from_eci(self, eci):
- args = super(Darwin, self)._link_args_from_eci(eci)
+ def _link_args_from_eci(self, eci, standalone):
+ args = super(Darwin, self)._link_args_from_eci(eci, standalone)
frameworks = self._frameworks(eci.frameworks)
include_dirs = self._includedirs(eci.include_dirs)
return (args + frameworks + include_dirs)
Modified: pypy/branch/parser-compiler/pypy/translator/platform/linux.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/translator/platform/linux.py (original)
+++ pypy/branch/parser-compiler/pypy/translator/platform/linux.py Fri Jul 17 21:55:59 2009
@@ -13,6 +13,7 @@
standalone_only = []
shared_only = []
so_ext = 'so'
+ so_prefixes = ['lib', '']
def _args_for_shared(self, args):
return ['-shared'] + args
Modified: pypy/branch/parser-compiler/pypy/translator/platform/test/test_maemo.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/translator/platform/test/test_maemo.py (original)
+++ pypy/branch/parser-compiler/pypy/translator/platform/test/test_maemo.py Fri Jul 17 21:55:59 2009
@@ -31,3 +31,6 @@
executable = self.platform.compile([cfile], eci)
res = self.platform.execute(executable)
self.check_res(res)
+
+ def test_environment_inheritance(self):
+ py.test.skip("FIXME")
Modified: pypy/branch/parser-compiler/pypy/translator/platform/test/test_platform.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/translator/platform/test/test_platform.py (original)
+++ pypy/branch/parser-compiler/pypy/translator/platform/test/test_platform.py Fri Jul 17 21:55:59 2009
@@ -1,5 +1,5 @@
-import py, sys
+import py, sys, ctypes, os
from pypy.tool.udir import udir
from pypy.translator.platform import CompilationError, Platform
from pypy.translator.platform import host
@@ -102,6 +102,18 @@
res = self.platform.execute(executable)
assert res.out.startswith('4.0')
+ def test_environment_inheritance(self):
+ # make sure that environment is inherited
+ cmd = 'import os; print os.environ["_SOME_VARIABLE_%d"]'
+ res = self.platform.execute('python', ['-c', cmd % 1],
+ env={'_SOME_VARIABLE_1':'xyz'})
+ assert 'xyz' in res.out
+ os.environ['_SOME_VARIABLE_2'] = 'zyz'
+ try:
+ res = self.platform.execute('python', ['-c', cmd % 2])
+ assert 'zyz' in res.out
+ finally:
+ del os.environ['_SOME_VARIABLE_2']
def test_equality():
class X(Platform):
Modified: pypy/branch/parser-compiler/pypy/translator/platform/windows.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/translator/platform/windows.py (original)
+++ pypy/branch/parser-compiler/pypy/translator/platform/windows.py Fri Jul 17 21:55:59 2009
@@ -133,8 +133,9 @@
def _args_for_shared(self, args):
return ['/dll'] + args
- def _link_args_from_eci(self, eci):
- args = super(MsvcPlatform, self)._link_args_from_eci(eci)
+ def _link_args_from_eci(self, eci, standalone):
+ # Windows needs to resolve all symbols even for DLLs
+ args = super(MsvcPlatform, self)._link_args_from_eci(eci, standalone=True)
return args + ['/EXPORT:%s' % symbol for symbol in eci.export_symbols]
def _compile_c_file(self, cc, cfile, compile_args):
More information about the Pypy-commit
mailing list