Author: Alex Gaynor <[email protected]>
Branch:
Changeset: r53295:37194aea258f
Date: 2012-03-11 11:58 -0700
http://bitbucket.org/pypy/pypy/changeset/37194aea258f/
Log: Merged upstrem.
diff --git a/lib-python/modified-2.7/distutils/command/bdist_wininst.py
b/lib-python/modified-2.7/distutils/command/bdist_wininst.py
--- a/lib-python/modified-2.7/distutils/command/bdist_wininst.py
+++ b/lib-python/modified-2.7/distutils/command/bdist_wininst.py
@@ -298,7 +298,8 @@
bitmaplen, # number of bytes in bitmap
)
file.write(header)
- file.write(open(arcname, "rb").read())
+ with open(arcname, "rb") as arcfile:
+ file.write(arcfile.read())
# create_exe()
diff --git a/lib_pypy/_csv.py b/lib_pypy/_csv.py
--- a/lib_pypy/_csv.py
+++ b/lib_pypy/_csv.py
@@ -414,7 +414,7 @@
def _parse_add_char(self, c):
if len(self.field) + len(c) > _field_limit:
- raise Error("field larget than field limit (%d)" % (_field_limit))
+ raise Error("field larger than field limit (%d)" % (_field_limit))
self.field += c
diff --git a/pypy/annotation/builtin.py b/pypy/annotation/builtin.py
--- a/pypy/annotation/builtin.py
+++ b/pypy/annotation/builtin.py
@@ -37,7 +37,11 @@
try:
realresult = func(*args)
except (ValueError, OverflowError):
- return s_ImpossibleValue # no possible answer for this precise input
+ # no possible answer for this precise input. Be conservative
+ # and keep the computation non-constant. Example:
+ # unichr(constant-that-doesn't-fit-16-bits) on platforms where
+ # the underlying Python has sys.maxunicode == 0xffff.
+ return s_result
s_realresult = immutablevalue(realresult)
if not s_result.contains(s_realresult):
raise Exception("%s%r returned %r, which is not contained in %s" % (
diff --git a/pypy/annotation/classdef.py b/pypy/annotation/classdef.py
--- a/pypy/annotation/classdef.py
+++ b/pypy/annotation/classdef.py
@@ -134,12 +134,19 @@
if self.name not in homedef.classdesc.all_enforced_attrs:
self.attr_allowed = False
if not self.readonly:
- raise NoSuchAttrError(homedef, self.name)
+ raise NoSuchAttrError(
+ "setting forbidden attribute %r on %r" % (
+ self.name, homedef))
def modified(self, classdef='?'):
self.readonly = False
if not self.attr_allowed:
- raise NoSuchAttrError(classdef, self.name)
+ raise NoSuchAttrError(
+ "Attribute %r on %r should be read-only.\n" % (self.name,
+ classdef) +
+ "This error can be caused by another 'getattr' that promoted\n"
+ "the attribute here; the list of read locations is:\n" +
+ '\n'.join([str(loc[0]) for loc in self.read_locations]))
class ClassDef(object):
diff --git a/pypy/annotation/description.py b/pypy/annotation/description.py
--- a/pypy/annotation/description.py
+++ b/pypy/annotation/description.py
@@ -398,7 +398,6 @@
cls = pyobj
base = object
baselist = list(cls.__bases__)
- baselist.reverse()
# special case: skip BaseException in Python 2.5, and pretend
# that all exceptions ultimately inherit from Exception instead
@@ -408,17 +407,27 @@
elif baselist == [py.builtin.BaseException]:
baselist = [Exception]
+ mixins_before = []
+ mixins_after = []
for b1 in baselist:
if b1 is object:
continue
if b1.__dict__.get('_mixin_', False):
- self.add_mixin(b1)
+ if base is object:
+ mixins_before.append(b1)
+ else:
+ mixins_after.append(b1)
else:
assert base is object, ("multiple inheritance only
supported "
"with _mixin_: %r" % (cls,))
base = b1
+ if mixins_before and mixins_after:
+ raise Exception("unsupported: class %r has mixin bases both"
+ " before and after the regular base" % (self,))
+ self.add_mixins(mixins_after, check_not_in=base)
+ self.add_mixins(mixins_before)
+ self.add_sources_for_class(cls)
- self.add_sources_for_class(cls)
if base is not object:
self.basedesc = bookkeeper.getdesc(base)
@@ -480,14 +489,30 @@
return
self.classdict[name] = Constant(value)
- def add_mixin(self, base):
- for subbase in base.__bases__:
- if subbase is object:
- continue
- assert subbase.__dict__.get("_mixin_", False), ("Mixin class %r
has non"
- "mixin base class %r" % (base, subbase))
- self.add_mixin(subbase)
- self.add_sources_for_class(base, mixin=True)
+ def add_mixins(self, mixins, check_not_in=object):
+ if not mixins:
+ return
+ A = type('tmp', tuple(mixins) + (object,), {})
+ mro = A.__mro__
+ assert mro[0] is A and mro[-1] is object
+ mro = mro[1:-1]
+ #
+ skip = set()
+ def add(cls):
+ if cls is not object:
+ for base in cls.__bases__:
+ add(base)
+ for name in cls.__dict__:
+ skip.add(name)
+ add(check_not_in)
+ #
+ for base in reversed(mro):
+ assert base.__dict__.get("_mixin_", False), ("Mixin class %r has
non"
+ "mixin base class %r" % (mixins, base))
+ for name, value in base.__dict__.items():
+ if name in skip:
+ continue
+ self.add_source_attribute(name, value, mixin=True)
def add_sources_for_class(self, cls, mixin=False):
for name, value in cls.__dict__.items():
diff --git a/pypy/annotation/test/test_annrpython.py
b/pypy/annotation/test/test_annrpython.py
--- a/pypy/annotation/test/test_annrpython.py
+++ b/pypy/annotation/test/test_annrpython.py
@@ -1,15 +1,12 @@
from __future__ import with_statement
-import autopath
import py.test
import sys
from pypy import conftest
-from pypy.tool.udir import udir
from pypy.annotation import model as annmodel
from pypy.annotation.annrpython import RPythonAnnotator as _RPythonAnnotator
from pypy.translator.translator import graphof as tgraphof
from pypy.annotation import policy
-from pypy.annotation import specialize
from pypy.annotation.listdef import ListDef, ListChangeUnallowed
from pypy.annotation.dictdef import DictDef
from pypy.objspace.flow.model import *
@@ -2431,6 +2428,52 @@
assert isinstance(s.items[1], annmodel.SomeChar)
assert isinstance(s.items[2], annmodel.SomeChar)
+ def test_mixin_first(self):
+ class Mixin(object):
+ _mixin_ = True
+ def foo(self): return 4
+ class Base(object):
+ def foo(self): return 5
+ class Concrete(Mixin, Base):
+ pass
+ def f():
+ return Concrete().foo()
+
+ assert f() == 4
+ a = self.RPythonAnnotator()
+ s = a.build_types(f, [])
+ assert s.const == 4
+
+ def test_mixin_last(self):
+ class Mixin(object):
+ _mixin_ = True
+ def foo(self): return 4
+ class Base(object):
+ def foo(self): return 5
+ class Concrete(Base, Mixin):
+ pass
+ def f():
+ return Concrete().foo()
+
+ assert f() == 5
+ a = self.RPythonAnnotator()
+ s = a.build_types(f, [])
+ assert s.const == 5
+
+ def test_mixin_concrete(self):
+ class Mixin(object):
+ _mixin_ = True
+ def foo(self): return 4
+ class Concrete(Mixin):
+ def foo(self): return 5
+ def f():
+ return Concrete().foo()
+
+ assert f() == 5
+ a = self.RPythonAnnotator()
+ s = a.build_types(f, [])
+ assert s.const == 5
+
def test_multiple_mixins_mro(self):
# an obscure situation, but it occurred in module/micronumpy/types.py
class A(object):
@@ -2510,6 +2553,26 @@
s = a.build_types(f, [int])
assert s.knowntype == int
+ def test_slots_reads(self):
+ class A(object):
+ __slots__ = ()
+ class B(A):
+ def __init__(self, x):
+ self.x = x
+ def f(x):
+ if x:
+ a = A()
+ else:
+ a = B(x)
+ return a.x # should explode here
+
+ a = self.RPythonAnnotator()
+ e = py.test.raises(Exception, a.build_types, f, [int])
+ # this should explode on reading the attribute 'a.x', but it can
+ # sometimes explode on 'self.x = x', which does not make much sense.
+ # But it looks hard to fix in general: we don't know yet during 'a.x'
+ # if the attribute x will be read-only or read-write.
+
def test_unboxed_value(self):
class A(object):
__slots__ = ()
diff --git a/pypy/jit/backend/x86/codebuf.py b/pypy/jit/backend/x86/codebuf.py
--- a/pypy/jit/backend/x86/codebuf.py
+++ b/pypy/jit/backend/x86/codebuf.py
@@ -19,8 +19,8 @@
class MachineCodeBlockWrapper(BlockBuilderMixin,
- codebuilder_cls,
- LocationCodeBuilder):
+ LocationCodeBuilder,
+ codebuilder_cls):
def __init__(self):
self.init_block_builder()
# a list of relative positions; for each position p, the bytes
diff --git a/pypy/module/_ffi/test/test__ffi.py
b/pypy/module/_ffi/test/test__ffi.py
--- a/pypy/module/_ffi/test/test__ffi.py
+++ b/pypy/module/_ffi/test/test__ffi.py
@@ -100,7 +100,10 @@
from _ffi import CDLL, types
libm = CDLL(self.libm_name)
pow_addr = libm.getaddressindll('pow')
- assert pow_addr == self.pow_addr & (sys.maxint*2-1)
+ fff = sys.maxint*2-1
+ if sys.platform == 'win32':
+ fff = sys.maxint*2+1
+ assert pow_addr == self.pow_addr & fff
def test_func_fromaddr(self):
import sys
diff --git a/pypy/module/rctime/interp_time.py
b/pypy/module/rctime/interp_time.py
--- a/pypy/module/rctime/interp_time.py
+++ b/pypy/module/rctime/interp_time.py
@@ -24,6 +24,7 @@
from pypy.module.thread import ll_thread as thread
eci = ExternalCompilationInfo(
+ post_include_bits = ["BOOL pypy_timemodule_setCtrlHandler(HANDLE
event);"],
separate_module_sources=['''
#include <windows.h>
diff --git a/pypy/module/select/interp_kqueue.py
b/pypy/module/select/interp_kqueue.py
--- a/pypy/module/select/interp_kqueue.py
+++ b/pypy/module/select/interp_kqueue.py
@@ -144,66 +144,65 @@
else:
changelist_len = space.len_w(w_changelist)
- with lltype.scoped_alloc(rffi.CArray(kevent), changelist_len) as
changelist, \
- lltype.scoped_alloc(rffi.CArray(kevent), max_events) as
eventlist, \
- lltype.scoped_alloc(timespec) as timeout:
+ with lltype.scoped_alloc(rffi.CArray(kevent), changelist_len) as
changelist:
+ with lltype.scoped_alloc(rffi.CArray(kevent), max_events) as
eventlist:
+ with lltype.scoped_alloc(timespec) as timeout:
- if not space.is_w(w_timeout, space.w_None):
- _timeout = space.float_w(w_timeout)
- if _timeout < 0:
- raise operationerrfmt(space.w_ValueError,
- "Timeout must be None or >= 0, got %s", str(_timeout)
- )
- sec = int(_timeout)
- nsec = int(1e9 * (_timeout - sec))
- rffi.setintfield(timeout, 'c_tv_sec', sec)
- rffi.setintfield(timeout, 'c_tv_nsec', nsec)
- ptimeout = timeout
- else:
- ptimeout = lltype.nullptr(timespec)
+ if not space.is_w(w_timeout, space.w_None):
+ _timeout = space.float_w(w_timeout)
+ if _timeout < 0:
+ raise operationerrfmt(space.w_ValueError,
+ "Timeout must be None or >= 0, got %s",
str(_timeout)
+ )
+ sec = int(_timeout)
+ nsec = int(1e9 * (_timeout - sec))
+ rffi.setintfield(timeout, 'c_tv_sec', sec)
+ rffi.setintfield(timeout, 'c_tv_nsec', nsec)
+ ptimeout = timeout
+ else:
+ ptimeout = lltype.nullptr(timespec)
- if not space.is_w(w_changelist, space.w_None):
- i = 0
- for w_ev in space.listview(w_changelist):
- ev = space.interp_w(W_Kevent, w_ev)
- changelist[i].c_ident = ev.event.c_ident
- changelist[i].c_filter = ev.event.c_filter
- changelist[i].c_flags = ev.event.c_flags
- changelist[i].c_fflags = ev.event.c_fflags
- changelist[i].c_data = ev.event.c_data
- changelist[i].c_udata = ev.event.c_udata
- i += 1
- pchangelist = changelist
- else:
- pchangelist = lltype.nullptr(rffi.CArray(kevent))
+ if not space.is_w(w_changelist, space.w_None):
+ i = 0
+ for w_ev in space.listview(w_changelist):
+ ev = space.interp_w(W_Kevent, w_ev)
+ changelist[i].c_ident = ev.event.c_ident
+ changelist[i].c_filter = ev.event.c_filter
+ changelist[i].c_flags = ev.event.c_flags
+ changelist[i].c_fflags = ev.event.c_fflags
+ changelist[i].c_data = ev.event.c_data
+ changelist[i].c_udata = ev.event.c_udata
+ i += 1
+ pchangelist = changelist
+ else:
+ pchangelist = lltype.nullptr(rffi.CArray(kevent))
- nfds = syscall_kevent(self.kqfd,
- pchangelist,
- changelist_len,
- eventlist,
- max_events,
- ptimeout)
- if nfds < 0:
- raise exception_from_errno(space, space.w_IOError)
- else:
- elist_w = [None] * nfds
- for i in xrange(nfds):
+ nfds = syscall_kevent(self.kqfd,
+ pchangelist,
+ changelist_len,
+ eventlist,
+ max_events,
+ ptimeout)
+ if nfds < 0:
+ raise exception_from_errno(space, space.w_IOError)
+ else:
+ elist_w = [None] * nfds
+ for i in xrange(nfds):
- evt = eventlist[i]
+ evt = eventlist[i]
- w_event = W_Kevent(space)
- w_event.event = lltype.malloc(kevent, flavor="raw")
- w_event.event.c_ident = evt.c_ident
- w_event.event.c_filter = evt.c_filter
- w_event.event.c_flags = evt.c_flags
- w_event.event.c_fflags = evt.c_fflags
- w_event.event.c_data = evt.c_data
- w_event.event.c_udata = evt.c_udata
+ w_event = W_Kevent(space)
+ w_event.event = lltype.malloc(kevent, flavor="raw")
+ w_event.event.c_ident = evt.c_ident
+ w_event.event.c_filter = evt.c_filter
+ w_event.event.c_flags = evt.c_flags
+ w_event.event.c_fflags = evt.c_fflags
+ w_event.event.c_data = evt.c_data
+ w_event.event.c_udata = evt.c_udata
- elist_w[i] = w_event
+ elist_w[i] = w_event
- return space.newlist(elist_w)
-
+ return space.newlist(elist_w)
W_Kqueue.typedef = TypeDef("select.kqueue",
@@ -227,7 +226,7 @@
if self.event:
lltype.free(self.event, flavor="raw")
- @unwrap_spec(filter=int, flags=rffi.r_uint, fflags=rffi.r_uint, data=int,
udata=rffi.r_uint)
+ @unwrap_spec(filter=int, flags='c_uint', fflags='c_uint', data=int,
udata='c_uint')
def descr__init__(self, space, w_ident, filter=KQ_FILTER_READ,
flags=KQ_EV_ADD, fflags=0, data=0, udata=0):
ident = space.c_filedescriptor_w(w_ident)
@@ -246,8 +245,8 @@
r_filter = rffi.cast(lltype.Signed, other.event.c_filter)
l_flags = rffi.cast(lltype.Unsigned, self.event.c_flags)
r_flags = rffi.cast(lltype.Unsigned, other.event.c_flags)
- l_fflags = self.event.c_fflags
- r_fflags = other.event.c_fflags
+ l_fflags = rffi.cast(lltype.Unsigned, self.event.c_fflags)
+ r_fflags = rffi.cast(lltype.Unsigned, other.event.c_fflags)
l_data = self.event.c_data
r_data = other.event.c_data
l_udata = rffi.cast(lltype.Unsigned, self.event.c_udata)
diff --git a/pypy/module/select/test/test_kqueue.py
b/pypy/module/select/test/test_kqueue.py
--- a/pypy/module/select/test/test_kqueue.py
+++ b/pypy/module/select/test/test_kqueue.py
@@ -75,7 +75,7 @@
assert ev == ev
assert ev != other
- bignum = sys.maxsize * 2 + 1
+ bignum = (sys.maxsize * 2 + 1) & 0xffffffff
fd = sys.maxsize
ev = select.kevent(fd, 1, 2, bignum, sys.maxsize, bignum)
assert ev.ident == fd
diff --git a/pypy/translator/c/src/asm_gcc_x86.h
b/pypy/translator/c/src/asm_gcc_x86.h
--- a/pypy/translator/c/src/asm_gcc_x86.h
+++ b/pypy/translator/c/src/asm_gcc_x86.h
@@ -124,10 +124,12 @@
{
//Read the CPU features.
int features;
- asm("mov $1, %%eax\n"
+ asm("movl $1, %%eax\n"
+ "pushl %%ebx\n"
"cpuid\n"
- "mov %%edx, %0"
- : "=g"(features) : : "eax", "ebx", "edx", "ecx");
+ "popl %%ebx\n"
+ "movl %%edx, %0"
+ : "=g"(features) : : "eax", "edx", "ecx");
//Check bits 25 and 26, this indicates SSE2 support
if (((features & (1 << 25)) == 0) || ((features & (1 << 26)) == 0))
diff --git a/testrunner/runner.py b/testrunner/runner.py
--- a/testrunner/runner.py
+++ b/testrunner/runner.py
@@ -24,13 +24,16 @@
#Try to avoid opeing a dialog box if one of the tests causes a system error
import ctypes
winapi = ctypes.windll.kernel32
+ SetErrorMode = winapi.SetErrorMode
+ SetErrorMode.argtypes=[ctypes.c_int]
+
SEM_FAILCRITICALERRORS = 1
SEM_NOGPFAULTERRORBOX = 2
SEM_NOOPENFILEERRORBOX = 0x8000
flags = SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX |
SEM_NOOPENFILEERRORBOX
#Since there is no GetErrorMode, do a double Set
- old_mode = winapi.SetErrorMode(flags)
- winapi.SetErrorMode(old_mode | flags)
+ old_mode = SetErrorMode(flags)
+ SetErrorMode(old_mode | flags)
SIGKILL = SIGTERM = 0
READ_MODE = 'rU'
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit