[pypy-commit] pypy py3k: merge default
bdkearns
noreply at buildbot.pypy.org
Thu Mar 7 12:28:55 CET 2013
Author: Brian Kearns <bdkearns at gmail.com>
Branch: py3k
Changeset: r62175:1d7ef38982ad
Date: 2013-03-07 06:28 -0500
http://bitbucket.org/pypy/pypy/changeset/1d7ef38982ad/
Log: merge default
diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -243,7 +243,7 @@
##########################################
# SQLite version information
-sqlite_version = sqlite.sqlite3_libversion().decode('utf-8')
+sqlite_version = sqlite.sqlite3_libversion().decode('ascii')
class Error(Exception):
pass
@@ -471,9 +471,8 @@
def _begin(self):
statement = c_void_p()
- next_char = c_char_p()
ret = sqlite.sqlite3_prepare_v2(self._db, self.__begin_statement, -1,
- byref(statement), next_char)
+ byref(statement), None)
try:
if ret != SQLITE_OK:
raise self._get_exception(ret)
@@ -496,9 +495,8 @@
obj._reset()
statement = c_void_p()
- next_char = c_char_p()
ret = sqlite.sqlite3_prepare_v2(self._db, b"COMMIT", -1,
- byref(statement), next_char)
+ byref(statement), None)
try:
if ret != SQLITE_OK:
raise self._get_exception(ret)
@@ -526,9 +524,8 @@
cursor._reset = True
statement = c_void_p()
- next_char = c_char_p()
ret = sqlite.sqlite3_prepare_v2(self._db, b"ROLLBACK", -1,
- byref(statement), next_char)
+ byref(statement), None)
try:
if ret != SQLITE_OK:
raise self._get_exception(ret)
@@ -1094,8 +1091,11 @@
num_params_needed = sqlite.sqlite3_bind_parameter_count(self._statement)
if isinstance(params, (tuple, list)) or \
not isinstance(params, dict) and \
- hasattr(params, '__len__') and hasattr(params, '__getitem__'):
- num_params = len(params)
+ hasattr(params, '__getitem__'):
+ try:
+ num_params = len(params)
+ except TypeError:
+ num_params = -1
if num_params != num_params_needed:
raise ProgrammingError("Incorrect number of bindings supplied. "
"The current statement uses %d, and "
@@ -1190,7 +1190,8 @@
desc = []
for i in range(sqlite.sqlite3_column_count(self._statement)):
name = sqlite.sqlite3_column_name(self._statement, i)
- name = name.decode('utf-8').split("[")[0].strip()
+ if name is not None:
+ name = name.decode('utf-8').split("[")[0].strip()
desc.append((name, None, None, None, None, None, None))
return desc
diff --git a/pypy/module/_cffi_backend/cdataobj.py b/pypy/module/_cffi_backend/cdataobj.py
--- a/pypy/module/_cffi_backend/cdataobj.py
+++ b/pypy/module/_cffi_backend/cdataobj.py
@@ -92,20 +92,15 @@
cdata1 = self._cdata
other = space.interpclass_w(w_other)
if isinstance(other, W_CData):
- if requires_ordering:
- if (isinstance(self.ctype, W_CTypePrimitive) or
- isinstance(other.ctype, W_CTypePrimitive)):
- raise OperationError(space.w_TypeError,
- space.wrap("cannot do comparison on a "
- "primitive cdata"))
cdata2 = other._cdata
- elif (misc.is_zero(space, w_other) and
- not isinstance(self.ctype, W_CTypePrimitive)):
- cdata2 = lltype.nullptr(rffi.CCHARP.TO)
else:
return space.w_NotImplemented
if requires_ordering:
+ if (isinstance(self.ctype, W_CTypePrimitive) or
+ isinstance(other.ctype, W_CTypePrimitive)):
+ raise OperationError(space.w_TypeError,
+ space.wrap("cannot do comparison on a primitive cdata"))
cdata1 = rffi.cast(lltype.Unsigned, cdata1)
cdata2 = rffi.cast(lltype.Unsigned, cdata2)
return space.newbool(op(cdata1, cdata2))
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
@@ -156,10 +156,6 @@
space = self.space
ob = space.interpclass_w(w_ob)
if not isinstance(ob, cdataobj.W_CData):
- if misc.is_zero(space, w_ob):
- NULL = lltype.nullptr(rffi.CCHARP.TO)
- rffi.cast(rffi.CCHARPP, cdata)[0] = NULL
- return
raise self._convert_error("cdata pointer", w_ob)
other = ob.ctype
if not isinstance(other, W_CTypePtrBase):
@@ -180,8 +176,8 @@
class W_CTypePointer(W_CTypePtrBase):
- _attrs_ = ['is_file', 'cache_array_type']
- _immutable_fields_ = ['is_file', 'cache_array_type?']
+ _attrs_ = ['cache_array_type']
+ _immutable_fields_ = ['cache_array_type?']
kind = "pointer"
cache_array_type = None
@@ -192,8 +188,6 @@
extra = "(*)" # obscure case: see test_array_add
else:
extra = " *"
- self.is_file = (ctitem.name == "struct _IO_FILE" or
- ctitem.name == "struct $FILE")
W_CTypePtrBase.__init__(self, space, size, extra, 2, ctitem)
def newp(self, w_init):
@@ -245,52 +239,23 @@
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._io.interp_iobase import W_IOBase
- ob = self.space.interpclass_w(w_ob)
- if isinstance(ob, W_IOBase):
- return prepare_iofile_argument(self.space, w_ob)
- else:
- return lltype.nullptr(rffi.CCHARP.TO)
-
def _prepare_pointer_call_argument(self, w_init, cdata):
space = self.space
- if misc.is_zero(space, w_init):
- # Convert 0 to NULL. Note that passing 0 is not ambigous,
- # despite the potential confusion: as a 'T*' argument, 0 means
- # NULL, but as a 'T[]' argument it would mean "array of size 0"
- # --- except that we specifically refuse to interpret numbers
- # as the array size when passing arguments.
- rffi.cast(rffi.CCHARPP, cdata)[0] = lltype.nullptr(rffi.CCHARP.TO)
- return 3
- elif (space.isinstance_w(w_init, space.w_list) or
+ if (space.isinstance_w(w_init, space.w_list) or
space.isinstance_w(w_init, space.w_tuple)):
length = space.int_w(space.len(w_init))
elif (space.isinstance_w(w_init, space.w_unicode) or
space.isinstance_w(w_init, space.w_bytes)):
# from a string, we add the null terminator
length = space.int_w(space.len(w_init)) + 1
- elif self.is_file:
- result = self.prepare_file(w_init)
- if result:
- rffi.cast(rffi.CCHARPP, cdata)[0] = result
- return 2
- return 0
else:
- return 0
+ return False
itemsize = self.ctitem.size
if itemsize <= 0:
if isinstance(self.ctitem, ctypevoid.W_CTypeVoid):
itemsize = 1
else:
- return 0
+ return False
try:
datasize = ovfcheck(length * itemsize)
except OverflowError:
@@ -304,7 +269,7 @@
lltype.free(result, flavor='raw')
raise
rffi.cast(rffi.CCHARPP, cdata)[0] = result
- return 1
+ return True
def convert_argument_from_object(self, cdata, w_ob):
from pypy.module._cffi_backend.ctypefunc import set_mustfree_flag
@@ -312,7 +277,7 @@
ob = space.interpclass_w(w_ob)
result = (not isinstance(ob, cdataobj.W_CData) and
self._prepare_pointer_call_argument(w_ob, cdata))
- if result == 0:
+ if not result:
self.convert_from_object(cdata, w_ob)
set_mustfree_flag(cdata, result)
return result
@@ -342,42 +307,3 @@
if attrchar == 'i': # item
return self.space.wrap(self.ctitem)
return W_CTypePtrBase._fget(self, attrchar)
-
-# ____________________________________________________________
-
-
-rffi_fdopen = rffi.llexternal("fdopen", [rffi.INT, rffi.CCHARP], rffi.CCHARP)
-rffi_setbuf = rffi.llexternal("setbuf", [rffi.CCHARP, rffi.CCHARP], lltype.Void)
-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")
- rffi_setbuf(self.llf, lltype.nullptr(rffi.CCHARP.TO))
-
- def close(self):
- rffi_fclose(self.llf)
-
-
-def prepare_iofile_argument(space, w_fileobj):
- fileobj = space.interpclass_w(w_fileobj)
- from pypy.module._io.interp_iobase import W_IOBase
- assert isinstance(fileobj, W_IOBase)
- space.call_method(w_fileobj, "flush")
- if fileobj.cffi_fileobj is None:
- fd = space.int_w(space.call_method(w_fileobj, "fileno"))
- if fd < 0:
- raise OperationError(space.w_ValueError,
- space.wrap("file has no OS file descriptor"))
- fd = os.dup(fd)
- mode = space.str_w(space.getattr(w_fileobj, space.wrap("mode")))
- try:
- fileobj.cffi_fileobj = CffiFileObj(fd, mode)
- except OSError, e:
- raise wrap_oserror(space, e)
- return fileobj.cffi_fileobj.llf
-
diff --git a/pypy/module/_cffi_backend/misc.py b/pypy/module/_cffi_backend/misc.py
--- a/pypy/module/_cffi_backend/misc.py
+++ b/pypy/module/_cffi_backend/misc.py
@@ -209,9 +209,6 @@
neg_msg = "can't convert negative number to unsigned"
ovf_msg = "long too big to convert"
-def is_zero(space, w_ob):
- return space.isinstance_w(w_ob, space.w_int) and not space.is_true(w_ob)
-
# ____________________________________________________________
class _NotStandardObject(Exception):
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
@@ -387,19 +387,8 @@
assert (x != None) is True
assert (x == ["hello"]) is False
assert (x != ["hello"]) is True
-
-def test_cmp_pointer_with_0():
- p = new_pointer_type(new_primitive_type("int"))
- x = cast(p, 0)
- assert (x == 0) is True
- assert (x != 0) is False
- assert (0 == x) is True
- assert (0 != x) is False
- y = cast(p, 42)
- assert (y == 0) is False
- assert (y != 0) is True
- assert (0 == y) is False
- assert (0 != y) is True
+ y = cast(p, 0)
+ assert (y == None) is False
def test_invalid_indexing():
p = new_primitive_type("int")
@@ -779,7 +768,7 @@
assert s.a2 == 456
assert s.a3 == 0
assert s.p4 == cast(BVoidP, 0)
- assert s.p4 == 0
+ assert s.p4 != 0
#
s = newp(BStructPtr, {'a2': 41122, 'a3': -123})
assert s.a1 == 0
@@ -792,14 +781,11 @@
p = newp(BIntPtr, 14141)
s = newp(BStructPtr, [12, 34, 56, p])
assert s.p4 == p
- s.p4 = 0
- assert s.p4 == 0
+ assert s.p4
#
s = newp(BStructPtr, [12, 34, 56, cast(BVoidP, 0)])
- assert s.p4 == 0
- #
- s = newp(BStructPtr, [12, 34, 56, 0])
assert s.p4 == cast(BVoidP, 0)
+ assert not s.p4
#
py.test.raises(TypeError, newp, BStructPtr, [12, 34, 56, None])
@@ -1017,11 +1003,10 @@
f = cast(BFunc23, _testfunc(23))
res = f(b"foo")
assert res == 1000 * ord(b'f')
- res = f(0) # NULL
- assert res == -42
- res = f(long(0)) # NULL
+ res = f(cast(BVoidP, 0)) # NULL
assert res == -42
py.test.raises(TypeError, f, None)
+ py.test.raises(TypeError, f, 0)
py.test.raises(TypeError, f, 0.0)
def test_call_function_23_bis():
@@ -2503,15 +2488,16 @@
assert len(p) == 4
assert list(p) == [b"f", b"o", b"o", b"\x00"]
-import io
-fdopen_funcs = [io.open]
-try:
- import posix
- fdopen_funcs.append(posix.fdopen)
-except (ImportError, AttributeError): # win32, or py3k
- pass
+# XXX hack
+if sys.version_info >= (3,):
+ try:
+ import posix, io
+ posix.fdopen = io.open
+ except ImportError:
+ pass # win32
def test_FILE():
+ """FILE is not supported natively any more."""
if sys.platform == "win32":
py.test.skip("testing FILE not implemented")
#
@@ -2521,83 +2507,16 @@
BCharP = new_pointer_type(BChar)
BInt = new_primitive_type("int")
BFunc = new_function_type((BCharP, BFILEP), BInt, False)
- BFunc2 = new_function_type((BFILEP, BCharP), BInt, True)
- ll = find_and_load_library('c')
- fputs = ll.load_function(BFunc, "fputs")
- fscanf = ll.load_function(BFunc2, "fscanf")
- #
- for fdopen in fdopen_funcs:
- fdr, fdw = posix.pipe()
- fr1 = fdopen(fdr, 'rb', 256)
- fw1 = fdopen(fdw, 'wb', 256)
- #
- fw1.write(b"X")
- res = fputs(b"hello world\n", fw1)
- assert res >= 0
- fw1.flush() # should not be needed
- #
- p = newp(new_array_type(BCharP, 100), None)
- res = fscanf(fr1, b"%s\n", p)
- assert res == 1
- assert string(p) == b"Xhello"
- fr1.close()
- fw1.close()
-
-def test_FILE_only_for_FILE_arg():
- if sys.platform == "win32":
- py.test.skip("testing FILE not implemented")
- #
- B_NOT_FILE = new_struct_type("NOT_FILE")
- B_NOT_FILEP = new_pointer_type(B_NOT_FILE)
- BChar = new_primitive_type("char")
- BCharP = new_pointer_type(BChar)
- BInt = new_primitive_type("int")
- BFunc = new_function_type((BCharP, B_NOT_FILEP), BInt, False)
ll = find_and_load_library('c')
fputs = ll.load_function(BFunc, "fputs")
#
- for fdopen in fdopen_funcs:
- fdr, fdw = posix.pipe()
- fr1 = fdopen(fdr, 'r')
- fw1 = fdopen(fdw, 'w')
- #
- e = py.test.raises(TypeError, fputs, b"hello world\n", fw1)
- assert str(e.value).startswith(
- "initializer for ctype 'struct NOT_FILE *' must "
- "be a cdata pointer, not ")
-
-def test_FILE_object():
- if sys.platform == "win32":
- py.test.skip("testing FILE not implemented")
- #
- BFILE = new_struct_type("$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")
- #
- for fdopen in fdopen_funcs:
- fdr, fdw = posix.pipe()
- fw1 = 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)
- if fdopen is not io.open and 'PY_DOT_PY' not in globals():
- assert res == fdw
- fw1.close()
- #
- data = posix.read(fdr, 256)
- assert data == b"Xhello\n"
- posix.close(fdr)
+ import posix
+ fdr, fdw = posix.pipe()
+ fr1 = posix.fdopen(fdr, 'rb', 256)
+ fw1 = posix.fdopen(fdw, 'wb', 256)
+ py.test.raises(TypeError, fputs, b"hello world\n", fw1)
+ fr1.close()
+ fw1.close()
def test_GetLastError():
if sys.platform != "win32":
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,20 +1,7 @@
from pypy.objspace.fake.checkmodule import checkmodule
-from pypy.module._cffi_backend import ctypeptr
-from rpython.rtyper.lltypesystem import lltype, rffi
# side-effect: FORMAT_LONGDOUBLE must be built before test_checkmodule()
from pypy.module._cffi_backend import misc
def test_checkmodule():
- # W_CTypePointer.prepare_file() is not working without translating
- # the _io module too
- def dummy_prepare_file(self, w_ob):
- return lltype.nullptr(rffi.CCHARP.TO)
- old = ctypeptr.W_CTypePointer.prepare_file
- try:
- ctypeptr.W_CTypePointer.prepare_file = dummy_prepare_file
- #
- checkmodule('_cffi_backend')
- #
- finally:
- ctypeptr.W_CTypePointer.prepare_file = old
+ checkmodule('_cffi_backend')
diff --git a/pypy/module/_io/interp_iobase.py b/pypy/module/_io/interp_iobase.py
--- a/pypy/module/_io/interp_iobase.py
+++ b/pypy/module/_io/interp_iobase.py
@@ -37,8 +37,6 @@
raise unsupported(space, "File or stream is not seekable")
class W_IOBase(Wrappable):
- cffi_fileobj = None # pypy/module/_cffi_backend
-
def __init__(self, space):
# XXX: IOBase thinks it has to maintain its own internal state in
# `__IOBase_closed` and call flush() by itself, but it is redundant
@@ -108,12 +106,6 @@
def close_w(self, space):
if self._CLOSED():
return
-
- cffifo = self.cffi_fileobj
- self.cffi_fileobj = None
- if cffifo is not None:
- cffifo.close()
-
try:
space.call_method(self, "flush")
finally:
diff --git a/pypy/module/test_lib_pypy/test_sqlite3.py b/pypy/module/test_lib_pypy/test_sqlite3.py
--- a/pypy/module/test_lib_pypy/test_sqlite3.py
+++ b/pypy/module/test_lib_pypy/test_sqlite3.py
@@ -138,6 +138,9 @@
def __getitem__(self, key):
return 2
con.execute('insert into foo(x) values (?)', seq())
+ del seq.__len__
+ with pytest.raises(_sqlite3.ProgrammingError):
+ con.execute('insert into foo(x) values (?)', seq())
with pytest.raises(_sqlite3.ProgrammingError):
con.execute('insert into foo(x) values (?)', {2:2})
with pytest.raises(ValueError) as e:
diff --git a/rpython/memory/gctransform/framework.py b/rpython/memory/gctransform/framework.py
--- a/rpython/memory/gctransform/framework.py
+++ b/rpython/memory/gctransform/framework.py
@@ -7,8 +7,7 @@
from rpython.memory.gctransform.log import log
from rpython.memory.gctransform.support import get_rtti, ll_call_destructor
from rpython.memory.gctransform.transform import GCTransformer
-from rpython.memory.gctypelayout import ll_weakref_deref, WEAKREF, \
- WEAKREFPTR
+from rpython.memory.gctypelayout import ll_weakref_deref, WEAKREF, WEAKREFPTR
from rpython.tool.sourcetools import func_with_new_name
from rpython.translator.backendopt import graphanalyze
from rpython.translator.backendopt.finalizer import FinalizerAnalyzer
@@ -317,7 +316,8 @@
malloc_fast = func_with_new_name(
malloc_fast_meth,
"malloc_fast")
- s_False = annmodel.SomeBool(); s_False.const = False
+ s_False = annmodel.SomeBool()
+ s_False.const = False
self.malloc_fast_ptr = getfn(
malloc_fast,
[s_gc, s_typeid16,
@@ -335,7 +335,8 @@
malloc_varsize_clear_fast = func_with_new_name(
GCClass.malloc_varsize_clear.im_func,
"malloc_varsize_clear_fast")
- s_False = annmodel.SomeBool(); s_False.const = False
+ s_False = annmodel.SomeBool()
+ s_False.const = False
self.malloc_varsize_clear_fast_ptr = getfn(
malloc_varsize_clear_fast,
[s_gc, s_typeid16,
@@ -614,7 +615,7 @@
if self.collect_analyzer.analyze_direct_call(graph):
raise Exception("'no_collect' function can trigger collection:"
" %s" % func)
-
+
if self.write_barrier_ptr:
self.clean_sets = (
find_initializing_stores(self.collect_analyzer, graph))
@@ -1180,7 +1181,7 @@
if self.gcdata.gc.moving_gc and not keep_current_args:
# moving GCs don't borrow, so the caller does not need to keep
# the arguments alive
- livevars = [var for var in hop.livevars_after_op()]
+ livevars = hop.livevars_after_op()
else:
livevars = hop.livevars_after_op() + hop.current_op_keeps_alive()
return livevars
diff --git a/rpython/rtyper/module/ll_termios.py b/rpython/rtyper/module/ll_termios.py
--- a/rpython/rtyper/module/ll_termios.py
+++ b/rpython/rtyper/module/ll_termios.py
@@ -24,17 +24,28 @@
class CConfig:
_compilation_info_ = eci
NCCS = rffi_platform.DefinedConstantInteger('NCCS')
+ _HAVE_STRUCT_TERMIOS_C_ISPEED = rffi_platform.Defined(
+ '_HAVE_STRUCT_TERMIOS_C_ISPEED')
+ _HAVE_STRUCT_TERMIOS_C_OSPEED = rffi_platform.Defined(
+ '_HAVE_STRUCT_TERMIOS_C_OSPEED')
-NCCS = rffi_platform.configure(CConfig)['NCCS']
+c_config = rffi_platform.configure(CConfig)
+NCCS = c_config['NCCS']
TCFLAG_T = rffi.UINT
CC_T = rffi.UCHAR
SPEED_T = rffi.UINT
INT = rffi.INT
+_add = []
+if c_config['_HAVE_STRUCT_TERMIOS_C_ISPEED']:
+ _add.append(('c_ispeed', SPEED_T))
+if c_config['_HAVE_STRUCT_TERMIOS_C_OSPEED']:
+ _add.append(('c_ospeed', SPEED_T))
TERMIOSP = rffi.CStructPtr('termios', ('c_iflag', TCFLAG_T), ('c_oflag', TCFLAG_T),
('c_cflag', TCFLAG_T), ('c_lflag', TCFLAG_T),
- ('c_cc', lltype.FixedSizeArray(CC_T, NCCS)))
+ ('c_line', CC_T),
+ ('c_cc', lltype.FixedSizeArray(CC_T, NCCS)), *_add)
def c_external(name, args, result):
return rffi.llexternal(name, args, result, compilation_info=eci)
More information about the pypy-commit
mailing list