[pypy-commit] pypy numpypy-problems: merge default into branch
mattip
noreply at buildbot.pypy.org
Sat Oct 27 19:29:45 CEST 2012
Author: mattip <matti.picus at gmail.com>
Branch: numpypy-problems
Changeset: r58509:7be0c69a3026
Date: 2012-10-27 19:24 +0200
http://bitbucket.org/pypy/pypy/changeset/7be0c69a3026/
Log: merge default into branch
diff --git a/lib_pypy/pyrepl/readline.py b/lib_pypy/pyrepl/readline.py
--- a/lib_pypy/pyrepl/readline.py
+++ b/lib_pypy/pyrepl/readline.py
@@ -233,7 +233,7 @@
try:
return unicode(line, ENCODING)
except UnicodeDecodeError: # bah, silently fall back...
- return unicode(line, 'utf-8')
+ return unicode(line, 'utf-8', 'replace')
def get_history_length(self):
return self.saved_history_length
diff --git a/lib_pypy/pyrepl/unix_console.py b/lib_pypy/pyrepl/unix_console.py
--- a/lib_pypy/pyrepl/unix_console.py
+++ b/lib_pypy/pyrepl/unix_console.py
@@ -496,7 +496,7 @@
if iscode:
self.__tputs(text)
else:
- os.write(self.output_fd, text.encode(self.encoding))
+ os.write(self.output_fd, text.encode(self.encoding, 'replace'))
del self.__buffer[:]
def __tputs(self, fmt, prog=delayprog):
diff --git a/pypy/annotation/annrpython.py b/pypy/annotation/annrpython.py
--- a/pypy/annotation/annrpython.py
+++ b/pypy/annotation/annrpython.py
@@ -548,7 +548,7 @@
if cell.is_constant():
newcell.const = cell.const
cell = newcell
- cell.knowntypedata = renamed_knowntypedata
+ cell.set_knowntypedata(renamed_knowntypedata)
cells.append(cell)
diff --git a/pypy/annotation/binaryop.py b/pypy/annotation/binaryop.py
--- a/pypy/annotation/binaryop.py
+++ b/pypy/annotation/binaryop.py
@@ -144,7 +144,7 @@
# XXX HACK HACK HACK
bk = getbookkeeper()
if bk is not None: # for testing
- knowntypedata = r.knowntypedata = {}
+ knowntypedata = {}
fn, block, i = bk.position_key
annotator = bk.annotator
@@ -168,6 +168,7 @@
bind(obj2, obj1, 0)
bind(obj1, obj2, 1)
+ r.set_knowntypedata(knowntypedata)
return r
@@ -337,8 +338,7 @@
case = opname in ('gt', 'ge', 'eq')
add_knowntypedata(knowntypedata, case, [op.args[0]],
SomeInteger(nonneg=True, knowntype=tointtype(int1)))
- if knowntypedata:
- r.knowntypedata = knowntypedata
+ r.set_knowntypedata(knowntypedata)
# a special case for 'x < 0' or 'x >= 0',
# where 0 is a flow graph Constant
# (in this case we are sure that it cannot become a r_uint later)
@@ -369,8 +369,7 @@
if hasattr(boo1, 'knowntypedata') and \
hasattr(boo2, 'knowntypedata'):
ktd = merge_knowntypedata(boo1.knowntypedata, boo2.knowntypedata)
- if ktd:
- s.knowntypedata = ktd
+ s.set_knowntypedata(ktd)
return s
def and_((boo1, boo2)):
diff --git a/pypy/annotation/builtin.py b/pypy/annotation/builtin.py
--- a/pypy/annotation/builtin.py
+++ b/pypy/annotation/builtin.py
@@ -188,10 +188,10 @@
variables = [op.args[1]]
for variable in variables:
assert bk.annotator.binding(variable) == s_obj
- r.knowntypedata = {}
-
+ knowntypedata = {}
if not hasattr(typ, '_freeze_') and isinstance(s_type, SomePBC):
- add_knowntypedata(r.knowntypedata, True, variables, bk.valueoftype(typ))
+ add_knowntypedata(knowntypedata, True, variables, bk.valueoftype(typ))
+ r.set_knowntypedata(knowntypedata)
return r
# note that this one either needs to be constant, or we will create SomeObject
diff --git a/pypy/annotation/model.py b/pypy/annotation/model.py
--- a/pypy/annotation/model.py
+++ b/pypy/annotation/model.py
@@ -195,6 +195,10 @@
unsigned = False
def __init__(self):
pass
+ def set_knowntypedata(self, knowntypedata):
+ assert not hasattr(self, 'knowntypedata')
+ if knowntypedata:
+ self.knowntypedata = knowntypedata
class SomeStringOrUnicode(SomeObject):
immutable = True
diff --git a/pypy/annotation/unaryop.py b/pypy/annotation/unaryop.py
--- a/pypy/annotation/unaryop.py
+++ b/pypy/annotation/unaryop.py
@@ -76,7 +76,7 @@
s_obj.is_true_behavior(r)
bk = getbookkeeper()
- knowntypedata = r.knowntypedata = {}
+ knowntypedata = {}
fn, block, i = bk.position_key
op = block.operations[i]
assert op.opname == "is_true" or op.opname == "nonzero"
@@ -86,8 +86,8 @@
if s_obj.can_be_none():
s_nonnone_obj = s_obj.nonnoneify()
add_knowntypedata(knowntypedata, True, [arg], s_nonnone_obj)
+ r.set_knowntypedata(knowntypedata)
return r
-
def nonzero(obj):
return obj.is_true()
diff --git a/pypy/config/translationoption.py b/pypy/config/translationoption.py
--- a/pypy/config/translationoption.py
+++ b/pypy/config/translationoption.py
@@ -118,7 +118,7 @@
("translation.gcrootfinder", DEFL_ROOTFINDER_WITHJIT),
("translation.list_comprehension_operations", True)]),
ChoiceOption("jit_backend", "choose the backend for the JIT",
- ["auto", "x86", "x86-without-sse2", "llvm", 'arm'],
+ ["auto", "x86", "x86-without-sse2", 'arm'],
default="auto", cmdline="--jit-backend"),
ChoiceOption("jit_profiler", "integrate profiler support into the JIT",
["off", "oprofile"],
diff --git a/pypy/jit/backend/detect_cpu.py b/pypy/jit/backend/detect_cpu.py
--- a/pypy/jit/backend/detect_cpu.py
+++ b/pypy/jit/backend/detect_cpu.py
@@ -77,8 +77,6 @@
return "pypy.jit.backend.x86.runner", "CPU_X86_64"
elif backend_name == 'cli':
return "pypy.jit.backend.cli.runner", "CliCPU"
- elif backend_name == 'llvm':
- return "pypy.jit.backend.llvm.runner", "LLVMCPU"
elif backend_name == 'arm':
return "pypy.jit.backend.arm.runner", "CPU_ARM"
elif backend_name == 'armhf':
diff --git a/pypy/module/_cffi_backend/ctypefunc.py b/pypy/module/_cffi_backend/ctypefunc.py
--- a/pypy/module/_cffi_backend/ctypefunc.py
+++ b/pypy/module/_cffi_backend/ctypefunc.py
@@ -4,9 +4,8 @@
import sys
from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.error import wrap_oserror
from pypy.rpython.lltypesystem import lltype, llmemory, rffi
-from pypy.rlib import jit, clibffi, jit_libffi, rposix
+from pypy.rlib import jit, clibffi, jit_libffi
from pypy.rlib.jit_libffi import CIF_DESCRIPTION, CIF_DESCRIPTION_P
from pypy.rlib.jit_libffi import FFI_TYPE, FFI_TYPE_P, FFI_TYPE_PP
from pypy.rlib.jit_libffi import SIZE_OF_FFI_ARG
@@ -152,9 +151,6 @@
if flag == 1:
raw_string = rffi.cast(rffi.CCHARPP, data)[0]
lltype.free(raw_string, flavor='raw')
- elif flag == 2:
- file = rffi.cast(rffi.CCHARPP, data)[0]
- rffi_fclose(file)
lltype.free(buffer, flavor='raw')
return w_res
@@ -169,27 +165,6 @@
assert isinstance(abi, int)
return space.wrap(abi)
-rffi_fdopen = rffi.llexternal("fdopen", [rffi.INT, rffi.CCHARP], rffi.CCHARP)
-rffi_fclose = rffi.llexternal("fclose", [rffi.CCHARP], rffi.INT)
-
-def prepare_file_call_argument(fileobj):
- import os
- space = fileobj.space
- fileobj.direct_flush()
- fd = fileobj.direct_fileno()
- if fd < 0:
- raise OperationError(space.w_ValueError,
- space.wrap("file has no OS file descriptor"))
- try:
- fd2 = os.dup(fd)
- f = rffi_fdopen(fd2, fileobj.mode)
- if not f:
- os.close(fd2)
- raise OSError(rposix.get_errno(), "fdopen failed")
- except OSError, e:
- raise wrap_oserror(space, e)
- return f
-
# ____________________________________________________________
diff --git a/pypy/module/_cffi_backend/ctypeptr.py b/pypy/module/_cffi_backend/ctypeptr.py
--- a/pypy/module/_cffi_backend/ctypeptr.py
+++ b/pypy/module/_cffi_backend/ctypeptr.py
@@ -3,9 +3,11 @@
"""
from pypy.interpreter.error import OperationError, operationerrfmt
+from pypy.interpreter.error import wrap_oserror
from pypy.rpython.lltypesystem import lltype, rffi
from pypy.rlib.objectmodel import keepalive_until_here
from pypy.rlib.rarithmetic import ovfcheck
+from pypy.rlib import rposix
from pypy.module._cffi_backend.ctypeobj import W_CType
from pypy.module._cffi_backend import cdataobj, misc, ctypeprim
@@ -236,6 +238,22 @@
p = rffi.ptradd(cdata, i * self.ctitem.size)
return cdataobj.W_CData(space, p, self)
+ def cast(self, w_ob):
+ if self.is_file:
+ value = self.prepare_file(w_ob)
+ if value:
+ return cdataobj.W_CData(self.space, value, self)
+ return W_CTypePtrBase.cast(self, w_ob)
+
+ def prepare_file(self, w_ob):
+ from pypy.module._file.interp_file import W_File
+ from pypy.module._cffi_backend import ctypefunc
+ ob = self.space.interpclass_w(w_ob)
+ if isinstance(ob, W_File):
+ return prepare_file_argument(self.space, ob)
+ else:
+ return lltype.nullptr(rffi.CCHARP.TO)
+
def _prepare_pointer_call_argument(self, w_init, cdata):
space = self.space
if (space.isinstance_w(w_init, space.w_list) or
@@ -245,11 +263,8 @@
# from a string, we add the null terminator
length = space.int_w(space.len(w_init)) + 1
elif self.is_file:
- from pypy.module._file.interp_file import W_File
- from pypy.module._cffi_backend import ctypefunc
- ob = space.interpclass_w(w_init)
- if isinstance(ob, W_File):
- result = ctypefunc.prepare_file_call_argument(ob)
+ result = self.prepare_file(w_init)
+ if result:
rffi.cast(rffi.CCHARPP, cdata)[0] = result
return 2
return 0
@@ -303,3 +318,31 @@
else:
raise OperationError(space.w_TypeError,
space.wrap("expected a 'cdata struct-or-union' object"))
+
+# ____________________________________________________________
+
+
+rffi_fdopen = rffi.llexternal("fdopen", [rffi.INT, rffi.CCHARP], rffi.CCHARP)
+rffi_fclose = rffi.llexternal("fclose", [rffi.CCHARP], rffi.INT)
+
+class CffiFileObj(object):
+ _immutable_ = True
+ def __init__(self, fd, mode):
+ self.llf = rffi_fdopen(fd, mode)
+ if not self.llf:
+ raise OSError(rposix.get_errno(), "fdopen failed")
+ def close(self):
+ rffi_fclose(self.llf)
+
+def prepare_file_argument(space, fileobj):
+ fileobj.direct_flush()
+ if fileobj.cffi_fileobj is None:
+ fd = fileobj.direct_fileno()
+ if fd < 0:
+ raise OperationError(space.w_ValueError,
+ space.wrap("file has no OS file descriptor"))
+ try:
+ fileobj.cffi_fileobj = CffiFileObj(fd, fileobj.mode)
+ except OSError, e:
+ raise wrap_oserror(space, e)
+ return fileobj.cffi_fileobj.llf
diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py b/pypy/module/_cffi_backend/test/_backend_test_c.py
--- a/pypy/module/_cffi_backend/test/_backend_test_c.py
+++ b/pypy/module/_cffi_backend/test/_backend_test_c.py
@@ -2264,3 +2264,35 @@
e = py.test.raises(TypeError, fputs, b"hello world\n", fw1)
assert str(e.value) == ("initializer for ctype 'struct NOT_FILE *' must "
"be a cdata pointer, not file")
+
+def test_FILE_object():
+ if sys.platform == "win32":
+ py.test.skip("testing FILE not implemented")
+ #
+ BFILE = new_struct_type("_IO_FILE")
+ BFILEP = new_pointer_type(BFILE)
+ BChar = new_primitive_type("char")
+ BCharP = new_pointer_type(BChar)
+ BInt = new_primitive_type("int")
+ BFunc = new_function_type((BCharP, BFILEP), BInt, False)
+ BFunc2 = new_function_type((BFILEP,), BInt, False)
+ ll = find_and_load_library('c')
+ fputs = ll.load_function(BFunc, "fputs")
+ fileno = ll.load_function(BFunc2, "fileno")
+ #
+ import posix
+ fdr, fdw = posix.pipe()
+ fw1 = posix.fdopen(fdw, 'wb', 256)
+ #
+ fw1p = cast(BFILEP, fw1)
+ fw1.write(b"X")
+ fw1.flush()
+ res = fputs(b"hello\n", fw1p)
+ assert res >= 0
+ res = fileno(fw1p)
+ assert res == fdw
+ fw1.close()
+ #
+ data = posix.read(fdr, 256)
+ assert data == b"Xhello\n"
+ posix.close(fdr)
diff --git a/pypy/module/_cffi_backend/test/test_ztranslation.py b/pypy/module/_cffi_backend/test/test_ztranslation.py
--- a/pypy/module/_cffi_backend/test/test_ztranslation.py
+++ b/pypy/module/_cffi_backend/test/test_ztranslation.py
@@ -1,8 +1,21 @@
from pypy.objspace.fake.checkmodule import checkmodule
+from pypy.module._cffi_backend import ctypeptr
+from pypy.rpython.lltypesystem import lltype, rffi
# side-effect: FORMAT_LONGDOUBLE must be built before test_checkmodule()
from pypy.module._cffi_backend import misc
def test_checkmodule():
- checkmodule('_cffi_backend')
+ # prepare_file_argument() is not working without translating the _file
+ # module too
+ def dummy_prepare_file_argument(space, fileobj):
+ return lltype.nullptr(rffi.CCHARP.TO)
+ old = ctypeptr.prepare_file_argument
+ try:
+ ctypeptr.prepare_file_argument = dummy_prepare_file_argument
+ #
+ checkmodule('_cffi_backend')
+ #
+ finally:
+ ctypeptr.prepare_file_argument = old
diff --git a/pypy/module/_file/interp_file.py b/pypy/module/_file/interp_file.py
--- a/pypy/module/_file/interp_file.py
+++ b/pypy/module/_file/interp_file.py
@@ -32,6 +32,7 @@
encoding = None
errors = None
fd = -1
+ cffi_fileobj = None # pypy/module/_cffi_backend
newlines = 0 # Updated when the stream is closed
@@ -148,7 +149,14 @@
del openstreams[stream]
except KeyError:
pass
- stream.close()
+ # close the stream. If cffi_fileobj is None, we close the
+ # underlying fileno too. Otherwise, we leave that to
+ # cffi_fileobj.close().
+ cffifo = self.cffi_fileobj
+ self.cffi_fileobj = None
+ stream.close1(cffifo is None)
+ if cffifo is not None:
+ cffifo.close()
def direct_fileno(self):
self.getstream() # check if the file is still open
diff --git a/pypy/module/micronumpy/interp_ufuncs.py b/pypy/module/micronumpy/interp_ufuncs.py
--- a/pypy/module/micronumpy/interp_ufuncs.py
+++ b/pypy/module/micronumpy/interp_ufuncs.py
@@ -423,6 +423,7 @@
return interp_dtype.get_dtype_cache(space).builtin_dtypes[dtypenum]
+ at jit.unroll_safe
def find_unaryop_result_dtype(space, dt, promote_to_float=False,
promote_bools=False, promote_to_largest=False, allow_complex=True):
if promote_bools and (dt.kind == interp_dtype.BOOLLTR):
diff --git a/pypy/rlib/streamio.py b/pypy/rlib/streamio.py
--- a/pypy/rlib/streamio.py
+++ b/pypy/rlib/streamio.py
@@ -268,6 +268,9 @@
return False
def close(self):
+ self.close1(True)
+
+ def close1(self, closefileno):
pass
def peek(self):
@@ -333,8 +336,9 @@
else:
data = data[n:]
- def close(self):
- os.close(self.fd)
+ def close1(self, closefileno):
+ if closefileno:
+ os.close(self.fd)
if sys.platform == "win32":
def truncate(self, size):
@@ -375,9 +379,10 @@
size = os.fstat(self.fd).st_size
self.mm = mmap.mmap(self.fd, size, access=self.access)
- def close(self):
+ def close1(self, closefileno):
self.mm.close()
- os.close(self.fd)
+ if closefileno:
+ os.close(self.fd)
def tell(self):
return self.pos
@@ -470,7 +475,7 @@
("truncate", [r_longlong]),
("flush", []),
("flushable", []),
- ("close", []),
+ ("close1", [int]),
("peek", []),
("try_to_find_file_descriptor", []),
("getnewlines", []),
@@ -715,7 +720,7 @@
truncate = PassThrough("truncate", flush_buffers=True)
flush = PassThrough("flush", flush_buffers=True)
flushable = PassThrough("flushable", flush_buffers=False)
- close = PassThrough("close", flush_buffers=False)
+ close1 = PassThrough("close1", flush_buffers=False)
try_to_find_file_descriptor = PassThrough("try_to_find_file_descriptor",
flush_buffers=False)
@@ -770,7 +775,7 @@
seek = PassThrough("seek", flush_buffers=True)
truncate = PassThrough("truncate", flush_buffers=True)
flush = PassThrough("flush", flush_buffers=True)
- close = PassThrough("close", flush_buffers=True)
+ close1 = PassThrough("close1", flush_buffers=True)
try_to_find_file_descriptor = PassThrough("try_to_find_file_descriptor",
flush_buffers=False)
@@ -838,7 +843,7 @@
flush = PassThrough("flush", flush_buffers=False)
flushable= PassThrough("flushable", flush_buffers=False)
- close = PassThrough("close", flush_buffers=False)
+ close1 = PassThrough("close1", flush_buffers=False)
try_to_find_file_descriptor = PassThrough("try_to_find_file_descriptor",
flush_buffers=False)
@@ -907,7 +912,7 @@
truncate = PassThrough("truncate", flush_buffers=True)
flush = PassThrough("flush", flush_buffers=False)
flushable= PassThrough("flushable", flush_buffers=False)
- close = PassThrough("close", flush_buffers=False)
+ close1 = PassThrough("close1", flush_buffers=False)
try_to_find_file_descriptor = PassThrough("try_to_find_file_descriptor",
flush_buffers=False)
@@ -1041,7 +1046,7 @@
truncate = PassThrough("truncate", flush_buffers=True)
flush = PassThrough("flush", flush_buffers=True)
flushable = PassThrough("flushable", flush_buffers=False)
- close = PassThrough("close", flush_buffers=False)
+ close1 = PassThrough("close1", flush_buffers=False)
try_to_find_file_descriptor = PassThrough("try_to_find_file_descriptor",
flush_buffers=False)
@@ -1067,7 +1072,7 @@
truncate = PassThrough("truncate", flush_buffers=False)
flush = PassThrough("flush", flush_buffers=False)
flushable = PassThrough("flushable", flush_buffers=False)
- close = PassThrough("close", flush_buffers=False)
+ close1 = PassThrough("close1", flush_buffers=False)
try_to_find_file_descriptor = PassThrough("try_to_find_file_descriptor",
flush_buffers=False)
@@ -1091,7 +1096,7 @@
peek = PassThrough("peek", flush_buffers=False)
flush = PassThrough("flush", flush_buffers=False)
flushable = PassThrough("flushable", flush_buffers=False)
- close = PassThrough("close", flush_buffers=False)
+ close1 = PassThrough("close1", flush_buffers=False)
write = PassThrough("write", flush_buffers=False)
truncate = PassThrough("truncate", flush_buffers=False)
getnewlines= PassThrough("getnewlines",flush_buffers=False)
@@ -1144,7 +1149,7 @@
truncate = PassThrough("truncate", flush_buffers=False)
flush = PassThrough("flush", flush_buffers=False)
flushable = PassThrough("flushable", flush_buffers=False)
- close = PassThrough("close", flush_buffers=False)
+ close1 = PassThrough("close1", flush_buffers=False)
try_to_find_file_descriptor = PassThrough("try_to_find_file_descriptor",
flush_buffers=False)
@@ -1172,6 +1177,6 @@
truncate = PassThrough("truncate", flush_buffers=False)
flush = PassThrough("flush", flush_buffers=False)
flushable = PassThrough("flushable", flush_buffers=False)
- close = PassThrough("close", flush_buffers=False)
+ close1 = PassThrough("close1", flush_buffers=False)
try_to_find_file_descriptor = PassThrough("try_to_find_file_descriptor",
flush_buffers=False)
More information about the pypy-commit
mailing list