[pypy-commit] pypy ppc-jit-backend: Write down the result of tedious investigation

2012-08-22 Thread arigo
Author: Armin Rigo 
Branch: ppc-jit-backend
Changeset: r56787:43f7f50df383
Date: 2012-08-22 10:28 +0200
http://bitbucket.org/pypy/pypy/changeset/43f7f50df383/

Log:Write down the result of tedious investigation

diff --git a/pypy/jit/backend/ppc/ppc_assembler.py 
b/pypy/jit/backend/ppc/ppc_assembler.py
--- a/pypy/jit/backend/ppc/ppc_assembler.py
+++ b/pypy/jit/backend/ppc/ppc_assembler.py
@@ -444,6 +444,9 @@
 # stack still aligned
 mc.call(slowpathaddr)
 
+XXX ^^^ the above call clobbers at least 48(r1), which
+XXX contains the mc.store(r3.value)
+
 with scratch_reg(mc):
 mc.load_imm(r.SCRATCH, self.cpu.pos_exception())
 mc.loadx(r.SCRATCH.value, 0, r.SCRATCH.value)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi win32: cffi on windows, python 32 bit

2012-08-22 Thread mattip
Author: mattip
Branch: win32
Changeset: r864:ce3bab425dd3
Date: 2012-08-22 10:47 +0300
http://bitbucket.org/cffi/cffi/changeset/ce3bab425dd3/

Log:cffi on windows, python 32 bit

___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi win32: nitpick with installation dependencies

2012-08-22 Thread mattip
Author: mattip
Branch: win32
Changeset: r865:1bf05283bb67
Date: 2012-08-22 11:54 +0300
http://bitbucket.org/cffi/cffi/changeset/1bf05283bb67/

Log:nitpick with installation dependencies

diff --git a/doc/source/index.rst b/doc/source/index.rst
--- a/doc/source/index.rst
+++ b/doc/source/index.rst
@@ -79,6 +79,10 @@
 
 * pycparser 2.06 or 2.07: http://code.google.com/p/pycparser/
   (there is a bug in the distribution of 2.08!)
+  
+  note that pycparser in turn relies on `ply`_
+  
+.. _`ply`: http://pypi.python.org/pypi/ply
 
 * a C compiler is required to use CFFI during development, but not to run
   correctly-installed programs that use CFFI.
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi win32: visual studio long double is equivalent to double

2012-08-22 Thread mattip
Author: mattip
Branch: win32
Changeset: r866:6c0bd2e916c5
Date: 2012-08-22 12:53 +0300
http://bitbucket.org/cffi/cffi/changeset/6c0bd2e916c5/

Log:visual studio long double is equivalent to double

diff --git a/testing/test_verify.py b/testing/test_verify.py
--- a/testing/test_verify.py
+++ b/testing/test_verify.py
@@ -104,6 +104,8 @@
 def test_longdouble_precision():
 # Test that we don't loose any precision of 'long double' when
 # passing through Python and CFFI.
+if ffi.sizeof("long double")==ffi.sizeof("double"):
+py.test.skip('"long double" is no more precise than "double"')
 ffi = FFI()
 ffi.cdef("long double step1(long double x);")
 lib = ffi.verify("""
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi win32: whoops

2012-08-22 Thread mattip
Author: mattip
Branch: win32
Changeset: r867:a4a4cfa9d9ce
Date: 2012-08-22 12:55 +0300
http://bitbucket.org/cffi/cffi/changeset/a4a4cfa9d9ce/

Log:whoops

diff --git a/testing/test_verify.py b/testing/test_verify.py
--- a/testing/test_verify.py
+++ b/testing/test_verify.py
@@ -104,9 +104,9 @@
 def test_longdouble_precision():
 # Test that we don't loose any precision of 'long double' when
 # passing through Python and CFFI.
+ffi = FFI()
 if ffi.sizeof("long double")==ffi.sizeof("double"):
 py.test.skip('"long double" is no more precise than "double"')
-ffi = FFI()
 ffi.cdef("long double step1(long double x);")
 lib = ffi.verify("""
 long double step1(long double x)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: add the possibility of doing @enforceargs(foo=int) in case we want to enforce only one specific argument

2012-08-22 Thread antocuni
Author: Antonio Cuni 
Branch: 
Changeset: r56789:d84e1c874bd1
Date: 2012-08-22 11:56 +0200
http://bitbucket.org/pypy/pypy/changeset/d84e1c874bd1/

Log:add the possibility of doing @enforceargs(foo=int) in case we want
to enforce only one specific argument

diff --git a/pypy/rlib/objectmodel.py b/pypy/rlib/objectmodel.py
--- a/pypy/rlib/objectmodel.py
+++ b/pypy/rlib/objectmodel.py
@@ -108,7 +108,7 @@
 
 specialize = _Specialize()
 
-def enforceargs(*types, **kwds):
+def enforceargs(*types_, **kwds):
 """ Decorate a function with forcing of RPython-level types on arguments.
 None means no enforcing.
 
@@ -117,15 +117,16 @@
 typechecking by passing ``typecheck=False`` to @enforceargs.
 """
 typecheck = kwds.pop('typecheck', True)
-if kwds:
-raise TypeError, 'got an unexpected keyword argument: %s' % kwds.keys()
+if types_ and kwds:
+raise TypeError, 'Cannot mix positional arguments and keywords'
+
 if not typecheck:
 def decorator(f):
-f._annenforceargs_ = types
+f._annenforceargs_ = types_
 return f
 return decorator
 #
-def decorator(f): 
+def decorator(f):
 def get_annotation(t):
 from pypy.annotation.signature import annotation
 from pypy.annotation.model import SomeObject
@@ -167,6 +168,10 @@
 # not RPython. Instead, we generate a function with exactly the same
 # argument list
 srcargs, srcvarargs, srckeywords, defaults = inspect.getargspec(f)
+if kwds:
+types = tuple([kwds.get(arg) for arg in srcargs])
+else:
+types = types_
 assert len(srcargs) == len(types), (
 'not enough types provided: expected %d, got %d' %
 (len(types), len(srcargs)))
diff --git a/pypy/rlib/test/test_objectmodel.py 
b/pypy/rlib/test/test_objectmodel.py
--- a/pypy/rlib/test/test_objectmodel.py
+++ b/pypy/rlib/test/test_objectmodel.py
@@ -437,6 +437,12 @@
 return a+b
 assert f(2) == 42
 
+def test_enforceargs_keywords():
+@enforceargs(b=int)
+def f(a, b, c):
+return a+b
+assert f._annenforceargs_ == (None, int, None)
+
 def test_enforceargs_int_float_promotion():
 @enforceargs(float)
 def f(x):
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: this has been checked in by mistake

2012-08-22 Thread antocuni
Author: Antonio Cuni 
Branch: py3k
Changeset: r56790:4e5ad0a67622
Date: 2012-08-22 11:57 +0200
http://bitbucket.org/pypy/pypy/changeset/4e5ad0a67622/

Log:this has been checked in by mistake

diff --git a/pypy/interpreter/test/test_function.py 
b/pypy/interpreter/test/test_function.py
--- a/pypy/interpreter/test/test_function.py
+++ b/pypy/interpreter/test/test_function.py
@@ -31,12 +31,6 @@
 f.__annotations__ = ann
 assert f.__annotations__ is ann
 
-def test_foo(self):
-"""
-def foo(*, kw=3): return kw
-assert foo(kw=42) == 42
-"""
-
 def test_kwdefaults(self):
 """
 def f(*, kw=3): return kw
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: hg merge default

2012-08-22 Thread antocuni
Author: Antonio Cuni 
Branch: py3k
Changeset: r56791:b877003ac5a3
Date: 2012-08-22 11:57 +0200
http://bitbucket.org/pypy/pypy/changeset/b877003ac5a3/

Log:hg merge default

diff --git a/pypy/rlib/objectmodel.py b/pypy/rlib/objectmodel.py
--- a/pypy/rlib/objectmodel.py
+++ b/pypy/rlib/objectmodel.py
@@ -108,7 +108,7 @@
 
 specialize = _Specialize()
 
-def enforceargs(*types, **kwds):
+def enforceargs(*types_, **kwds):
 """ Decorate a function with forcing of RPython-level types on arguments.
 None means no enforcing.
 
@@ -117,15 +117,16 @@
 typechecking by passing ``typecheck=False`` to @enforceargs.
 """
 typecheck = kwds.pop('typecheck', True)
-if kwds:
-raise TypeError, 'got an unexpected keyword argument: %s' % kwds.keys()
+if types_ and kwds:
+raise TypeError, 'Cannot mix positional arguments and keywords'
+
 if not typecheck:
 def decorator(f):
-f._annenforceargs_ = types
+f._annenforceargs_ = types_
 return f
 return decorator
 #
-def decorator(f): 
+def decorator(f):
 def get_annotation(t):
 from pypy.annotation.signature import annotation
 from pypy.annotation.model import SomeObject
@@ -167,6 +168,10 @@
 # not RPython. Instead, we generate a function with exactly the same
 # argument list
 srcargs, srcvarargs, srckeywords, defaults = inspect.getargspec(f)
+if kwds:
+types = tuple([kwds.get(arg) for arg in srcargs])
+else:
+types = types_
 assert len(srcargs) == len(types), (
 'not enough types provided: expected %d, got %d' %
 (len(types), len(srcargs)))
diff --git a/pypy/rlib/test/test_objectmodel.py 
b/pypy/rlib/test/test_objectmodel.py
--- a/pypy/rlib/test/test_objectmodel.py
+++ b/pypy/rlib/test/test_objectmodel.py
@@ -437,6 +437,12 @@
 return a+b
 assert f(2) == 42
 
+def test_enforceargs_keywords():
+@enforceargs(b=int)
+def f(a, b, c):
+return a+b
+assert f._annenforceargs_ == (None, int, None)
+
 def test_enforceargs_int_float_promotion():
 @enforceargs(float)
 def f(x):
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: hg merge

2012-08-22 Thread antocuni
Author: Antonio Cuni 
Branch: 
Changeset: r56792:af6e5e8ca77b
Date: 2012-08-22 11:58 +0200
http://bitbucket.org/pypy/pypy/changeset/af6e5e8ca77b/

Log:hg merge

diff --git a/pypy/jit/backend/test/calling_convention_test.py 
b/pypy/jit/backend/test/calling_convention_test.py
--- a/pypy/jit/backend/test/calling_convention_test.py
+++ b/pypy/jit/backend/test/calling_convention_test.py
@@ -310,9 +310,9 @@
 F = lltype.Float
 S = lltype.SingleFloat
 I = lltype.Signed
-floats = [random.random() - 0.5 for i in range(8)]
-singlefloats = [r_singlefloat(random.random() - 0.5) for i in range(8)]
-ints = [random.randrange(-99, 99) for i in range(8)]
+floats = [random.random() - 0.5 for i in range(20)]
+singlefloats = [r_singlefloat(random.random() - 0.5) for i in 
range(20)]
+ints = [random.randrange(-99, 99) for i in range(20)]
 for repeat in range(100):
 args = []
 argvalues = []
@@ -320,20 +320,23 @@
 local_floats = list(floats)
 local_singlefloats = list(singlefloats)
 local_ints = list(ints)
-for i in range(8):
-case = random.randrange(0, 3)
-if case == 0:
+for i in range(random.randrange(4, 20)):
+case = random.randrange(0, 6)
+if case & 1: boxme = BoxInt
+else:boxme = ConstInt
+if case < 2:
 args.append(F)
-arg = local_floats.pop()
-argslist.append(boxfloat(arg))
-elif case == 1:
+arg = arg1 = local_floats.pop()
+if case & 1: boxme = boxfloat
+else:boxme = constfloat
+elif case < 4:
 args.append(S)
 arg = local_singlefloats.pop()
-argslist.append(BoxInt(longlong.singlefloat2int(arg)))
+arg1 = longlong.singlefloat2int(arg)
 else:
 args.append(I)
-arg = local_ints.pop()
-argslist.append(BoxInt(arg))
+arg = arg1 = local_ints.pop()
+argslist.append(boxme(arg1))
 argvalues.append(arg)
 FUNC = self.FuncType(args, F)
 FPTR = self.Ptr(FUNC)
diff --git a/pypy/jit/backend/x86/assembler.py 
b/pypy/jit/backend/x86/assembler.py
--- a/pypy/jit/backend/x86/assembler.py
+++ b/pypy/jit/backend/x86/assembler.py
@@ -1171,11 +1171,13 @@
 xmm_dst_locs.append(unused_xmm.pop())
 else:
 pass_on_stack.append(loc)
-elif (argtypes is not None and argtypes[i-start] == 'S' and
-  len(unused_xmm) > 0):
+elif argtypes is not None and argtypes[i-start] == 'S':
 # Singlefloat argument
-if singlefloats is None: singlefloats = []
-singlefloats.append((loc, unused_xmm.pop()))
+if len(unused_xmm) > 0:
+if singlefloats is None: singlefloats = []
+singlefloats.append((loc, unused_xmm.pop()))
+else:
+pass_on_stack.append(loc)
 else:
 if len(unused_gpr) > 0:
 src_locs.append(loc)
@@ -1209,6 +1211,9 @@
 # Load the singlefloat arguments from main regs or stack to xmm regs
 if singlefloats is not None:
 for src, dst in singlefloats:
+if isinstance(src, ImmedLoc):
+self.mc.MOV(X86_64_SCRATCH_REG, src)
+src = X86_64_SCRATCH_REG
 self.mc.MOVD(dst, src)
 # Finally remap the arguments in the main regs
 # If x is a register and is in dst_locs, then oups, it needs to
diff --git a/pypy/module/_cffi_backend/test/test_c.py 
b/pypy/module/_cffi_backend/test/test_c.py
--- a/pypy/module/_cffi_backend/test/test_c.py
+++ b/pypy/module/_cffi_backend/test/test_c.py
@@ -1,7 +1,19 @@
 from __future__ import with_statement
 """
 This file is OBSCURE.  Really.  The purpose is to avoid copying and changing
-'test_c.py' from cffi/c/.
+'test_c.py' from cffi/c/ in the original CFFI repository:
+https://bitbucket.org/cffi/cffi
+
+Adding a test here involves:
+1. add a test to cffi/c/test.py
+   - if you need a C function to call, add it into _cffi_backend.c
+ as a testfuncNN().
+2. have it pass when you run 'py.test test_c.py' in cffi
+3. check in and (if you can) push the changes
+4. copy test_c.py into _backend_test.py here, killing the few lines of header
+   - if you added a C function, it goes into _test_lib.c here
+   - if you could complete step 3, try running 'py.test test_file.py' here
+5. make the test pass in pypy ('py.test test_c.py')
 """
 import py, sys, ctypes
 if sys.version_info < (2, 6):

[pypy-commit] pypy py3k: enforce the list of keywords to be unicode

2012-08-22 Thread antocuni
Author: Antonio Cuni 
Branch: py3k
Changeset: r56793:ed66f5af8446
Date: 2012-08-22 12:02 +0200
http://bitbucket.org/pypy/pypy/changeset/ed66f5af8446/

Log:enforce the list of keywords to be unicode

diff --git a/pypy/interpreter/argument.py b/pypy/interpreter/argument.py
--- a/pypy/interpreter/argument.py
+++ b/pypy/interpreter/argument.py
@@ -5,6 +5,7 @@
 from pypy.interpreter.error import OperationError, operationerrfmt
 from pypy.rlib.debug import make_sure_not_resized
 from pypy.rlib import jit
+from pypy.rlib.objectmodel import enforceargs
 
 class Signature(object):
 _immutable_ = True
@@ -114,6 +115,7 @@
 """
 
 ###  Construction  ###
+@enforceargs(keywords=[unicode])
 def __init__(self, space, args_w, keywords=None, keywords_w=None,
  w_stararg=None, w_starstararg=None, keyword_names_w=None):
 self.space = space
diff --git a/pypy/interpreter/test/test_argument.py 
b/pypy/interpreter/test/test_argument.py
--- a/pypy/interpreter/test/test_argument.py
+++ b/pypy/interpreter/test/test_argument.py
@@ -1,4 +1,5 @@
 # -*- coding: utf-8 -*-
+from __future__ import unicode_literals
 import py
 from pypy.interpreter.argument import (Arguments, ArgumentsForTranslation,
 ArgErr, ArgErrUnknownKwds, ArgErrMultipleValues, ArgErrCount, rawshape,
@@ -685,7 +686,7 @@
 assert exc.value.message == "() takes exactly 2 non-keyword 
arguments (0 given)"
 
 def test_unicode_keywords(self):
-"""
+b"""
 def f(**kwargs):
 assert kwargs["美"] == 42
 f(**{"美" : 42})
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy arm-backend-2: this revision contains less \t

2012-08-22 Thread bivab
Author: David Schneider 
Branch: arm-backend-2
Changeset: r56794:8d3a772cc045
Date: 2012-08-22 13:15 +0200
http://bitbucket.org/pypy/pypy/changeset/8d3a772cc045/

Log:this revision contains less \t

diff --git a/pypy/jit/backend/arm/test/test_runner.py 
b/pypy/jit/backend/arm/test/test_runner.py
--- a/pypy/jit/backend/arm/test/test_runner.py
+++ b/pypy/jit/backend/arm/test/test_runner.py
@@ -27,7 +27,7 @@
 # > ../../test/runner_test.py
 
 add_loop_instructions = ['nop', # this is the same as mov r0, r0
-'adds', 'cmp', 'beq', 'b']
+ 'adds', 'cmp', 'beq', 'b']
 bridge_loop_instructions = ['movw', 'movt', 'bx']
 
 def setup_method(self, meth):
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: disable view_as_kwargs for now

2012-08-22 Thread antocuni
Author: Antonio Cuni 
Branch: py3k
Changeset: r56796:ce7935dd0c8d
Date: 2012-08-22 13:16 +0200
http://bitbucket.org/pypy/pypy/changeset/ce7935dd0c8d/

Log:disable view_as_kwargs for now

diff --git a/TODO b/TODO
--- a/TODO
+++ b/TODO
@@ -10,5 +10,6 @@
 re-enable StdObjSpace.listview_str
 
 re-enable the kwargs dict strategy in dictmultiobject.py
+re-enable view_as_kwargs
 
 unskip numpypy tests in module/test_lib_pypy/numpypy/
diff --git a/pypy/objspace/std/dictmultiobject.py 
b/pypy/objspace/std/dictmultiobject.py
--- a/pypy/objspace/std/dictmultiobject.py
+++ b/pypy/objspace/std/dictmultiobject.py
@@ -529,6 +529,7 @@
 @jit.look_inside_iff(lambda self, w_dict:
  w_dict_unrolling_heuristic(w_dict))
 def view_as_kwargs(self, w_dict):
+return (None, None) # XXX: fix me to return unicode keys
 d = self.unerase(w_dict.dstorage)
 l = len(d)
 keys, values = [None] * l, [None] * l
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: missing import

2012-08-22 Thread antocuni
Author: Antonio Cuni 
Branch: py3k
Changeset: r56797:24c49c5d9184
Date: 2012-08-22 13:17 +0200
http://bitbucket.org/pypy/pypy/changeset/24c49c5d9184/

Log:missing import

diff --git a/pypy/interpreter/argument.py b/pypy/interpreter/argument.py
--- a/pypy/interpreter/argument.py
+++ b/pypy/interpreter/argument.py
@@ -120,7 +120,7 @@
 """
 
 ###  Construction  ###
-@enforceargs(keywords=[unicode])
+#@enforceargs(keywords=[unicode])
 def __init__(self, space, args_w, keywords=None, keywords_w=None,
  w_stararg=None, w_starstararg=None, keyword_names_w=None):
 self.space = space
diff --git a/pypy/objspace/flow/flowcontext.py 
b/pypy/objspace/flow/flowcontext.py
--- a/pypy/objspace/flow/flowcontext.py
+++ b/pypy/objspace/flow/flowcontext.py
@@ -11,6 +11,7 @@
 from pypy.objspace.flow.framestate import (FrameState, recursively_unflatten,
 recursively_flatten)
 from pypy.tool.stdlib_opcode import host_bytecode_spec
+from pypy.rlib import jit
 
 class StopFlowing(Exception):
 pass
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: tentative rpython fixes

2012-08-22 Thread antocuni
Author: Antonio Cuni 
Branch: py3k
Changeset: r56795:9cd3aff99129
Date: 2012-08-22 12:06 +0200
http://bitbucket.org/pypy/pypy/changeset/9cd3aff99129/

Log:tentative rpython fixes

diff --git a/pypy/interpreter/argument.py b/pypy/interpreter/argument.py
--- a/pypy/interpreter/argument.py
+++ b/pypy/interpreter/argument.py
@@ -5,6 +5,7 @@
 from pypy.interpreter.error import OperationError, operationerrfmt
 from pypy.rlib.debug import make_sure_not_resized
 from pypy.rlib import jit
+from pypy.rlib.debug import check_annotation
 from pypy.rlib.objectmodel import enforceargs
 
 class Signature(object):
@@ -92,15 +93,19 @@
 raise IndexError
 
 
-def assert_list_of_unicode(value):
-from pypy.rlib.debug import check_annotation
-def checker(ann, bk):
-from pypy.annotation.model import SomeList, SomeUnicodeString
-if not isinstance(ann, SomeList):
-raise TypeError
-if not isinstance(ann.listdef.listitem.s_value, SomeUnicodeString):
-raise TypeError
-check_annotation(value, checker)
+
+def check_list_of_unicode(ann, bk):
+from pypy.annotation.model import (SomeList, SomeUnicodeString,
+   s_None, s_ImpossibleValue)
+if ann is s_None:
+return
+if not isinstance(ann, SomeList):
+raise TypeError
+s_item = ann.listdef.listitem.s_value
+if s_item is s_ImpossibleValue:
+return
+if not isinstance(s_item, SomeUnicodeString):
+raise TypeError
 
 
 class Arguments(object):
@@ -121,7 +126,7 @@
 self.space = space
 assert isinstance(args_w, list)
 self.arguments_w = args_w
-assert_list_of_unicode(keywords)
+check_annotation(keywords, check_list_of_unicode)
 
 self.keywords = keywords
 self.keywords_w = keywords_w
@@ -197,7 +202,7 @@
 # unpack the ** arguments
 space = self.space
 keywords, values_w = space.view_as_kwargs(w_starstararg)
-assert_list_of_unicode(keywords)
+check_annotation(keywords, check_list_of_unicode)
 if keywords is not None: # this path also taken for empty dicts
 if self.keywords is None:
 self.keywords = keywords
diff --git a/pypy/module/__builtin__/compiling.py 
b/pypy/module/__builtin__/compiling.py
--- a/pypy/module/__builtin__/compiling.py
+++ b/pypy/module/__builtin__/compiling.py
@@ -6,7 +6,7 @@
 from pypy.interpreter.error import OperationError
 from pypy.interpreter.astcompiler import consts, ast
 from pypy.interpreter.gateway import unwrap_spec
-from pypy.interpreter.argument import Arguments, assert_list_of_unicode
+from pypy.interpreter.argument import Arguments, check_annotation, 
check_list_of_unicode
 from pypy.interpreter.nestedscope import Cell
 
 @unwrap_spec(filename=str, mode=str, flags=int, dont_inherit=int, optimize=int)
@@ -114,7 +114,7 @@
 def build_class(space, w_func, w_name, __args__):
 bases_w, kwds_w = __args__.unpack()
 w_bases = space.newtuple(bases_w)
-w_meta = kwds_w.pop('metaclass', None)
+w_meta = kwds_w.pop(u'metaclass', None)
 if w_meta is None:
 if bases_w:
 w_meta = space.type(bases_w[0])
@@ -129,7 +129,7 @@
 w_namespace = space.newdict()
 else:
 keywords = kwds_w.keys()
-assert_list_of_unicode(keywords)
+check_annotation(keywords, check_list_of_unicode)
 args = Arguments(space, 
  args_w=[w_name, w_bases],
  keywords=keywords,
@@ -137,7 +137,7 @@
 w_namespace = space.call_args(w_prep, args)
 w_cell = space.call_function(w_func, w_namespace)
 keywords = kwds_w.keys()
-assert_list_of_unicode(keywords)
+check_annotation(keywords, check_list_of_unicode)
 args = Arguments(space,
  args_w=[w_name, w_bases, w_namespace],
  keywords=keywords,
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: don't complain if we pass None to something which expects unicode or str

2012-08-22 Thread antocuni
Author: Antonio Cuni 
Branch: py3k
Changeset: r56798:230a83193f7a
Date: 2012-08-22 13:44 +0200
http://bitbucket.org/pypy/pypy/changeset/230a83193f7a/

Log:don't complain if we pass None to something which expects unicode or
str

diff --git a/pypy/rlib/objectmodel.py b/pypy/rlib/objectmodel.py
--- a/pypy/rlib/objectmodel.py
+++ b/pypy/rlib/objectmodel.py
@@ -129,10 +129,13 @@
 def decorator(f):
 def get_annotation(t):
 from pypy.annotation.signature import annotation
-from pypy.annotation.model import SomeObject
+from pypy.annotation.model import SomeObject, SomeStringOrUnicode
 if isinstance(t, SomeObject):
 return t
-return annotation(t)
+s_result = annotation(t)
+if isinstance(s_result, SomeStringOrUnicode):
+return s_result.__class__(can_be_None=True)
+return s_result
 def get_type_descr_of_argument(arg):
 # we don't want to check *all* the items in list/dict: we assume
 # they are already homogeneous, so we only check the first
diff --git a/pypy/rlib/test/test_objectmodel.py 
b/pypy/rlib/test/test_objectmodel.py
--- a/pypy/rlib/test/test_objectmodel.py
+++ b/pypy/rlib/test/test_objectmodel.py
@@ -450,6 +450,12 @@
 # in RPython there is an implicit int->float promotion
 assert f(42) == 42
 
+def test_enforceargs_None_string():
+@enforceargs(str, unicode)
+def f(a, b):
+return a, b
+assert f(None, None) == (None, None)
+
 def test_enforceargs_complex_types():
 @enforceargs([int], {str: int})
 def f(a, b):
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: enforce the parameters of Signature() to be unicode

2012-08-22 Thread antocuni
Author: Antonio Cuni 
Branch: py3k
Changeset: r56799:a5e20b0caee4
Date: 2012-08-22 14:19 +0200
http://bitbucket.org/pypy/pypy/changeset/a5e20b0caee4/

Log:enforce the parameters of Signature() to be unicode

diff --git a/pypy/interpreter/argument.py b/pypy/interpreter/argument.py
--- a/pypy/interpreter/argument.py
+++ b/pypy/interpreter/argument.py
@@ -12,6 +12,7 @@
 _immutable_fields_ = ["argnames[*]", "kwonlyargnames[*]"]
 __slots__ = ("argnames", "kwonlyargnames", "varargname", "kwargname")
 
+@enforceargs(None, [unicode], unicode, unicode, [unicode])
 def __init__(self, argnames, varargname=None, kwargname=None, 
kwonlyargnames=None):
 self.argnames = argnames
 self.varargname = varargname
diff --git a/pypy/interpreter/gateway.py b/pypy/interpreter/gateway.py
--- a/pypy/interpreter/gateway.py
+++ b/pypy/interpreter/gateway.py
@@ -171,8 +171,8 @@
 argname = self.orig_arg()
 assert app_sig.varargname is None,(
 "built-in function %r has conflicting rest args specs" % self.func)
-app_sig.varargname = 'args'
-app_sig.kwargname = 'keywords'
+app_sig.varargname = u'args'
+app_sig.kwargname = u'keywords'
 
 def visit_args_w(self, el, app_sig):
 argname = self.orig_arg()
diff --git a/pypy/interpreter/pycode.py b/pypy/interpreter/pycode.py
--- a/pypy/interpreter/pycode.py
+++ b/pypy/interpreter/pycode.py
@@ -19,6 +19,11 @@
 from pypy.rlib.objectmodel import compute_hash, we_are_translated
 from pypy.tool.stdlib_opcode import opcodedesc, HAVE_ARGUMENT
 
+def to_unicode(s):
+if s is None:
+return None
+return unicode(s)
+
 # helper
 
 def unpack_str_tuple(space,w_str_tuple):
@@ -61,6 +66,11 @@
 argcount += 1
 else:
 kwargname = None
+
+argnames = map(to_unicode, argnames)
+varargname = to_unicode(varargname)
+kwargname = to_unicode(kwargname)
+kwonlyargs = map(to_unicode, kwonlyargs)
 return Signature(argnames, varargname, kwargname, kwonlyargs)
 
 class PyCode(eval.Code):
diff --git a/pypy/objspace/std/dictmultiobject.py 
b/pypy/objspace/std/dictmultiobject.py
--- a/pypy/objspace/std/dictmultiobject.py
+++ b/pypy/objspace/std/dictmultiobject.py
@@ -611,7 +611,7 @@
 class ObjectIteratorImplementation(_UnwrappedIteratorMixin, 
IteratorImplementation):
 pass
 
-init_signature = Signature(['seq_or_map'], None, 'kwargs')
+init_signature = Signature([u'seq_or_map'], None, u'kwargs')
 init_defaults = [None]
 
 def update1(space, w_dict, w_data):
diff --git a/pypy/objspace/std/fake.py b/pypy/objspace/std/fake.py
--- a/pypy/objspace/std/fake.py
+++ b/pypy/objspace/std/fake.py
@@ -147,7 +147,7 @@
 assert callable(cpy_callable), cpy_callable
 
 def signature(self):
-return argument.Signature([], 'args', 'kwds')
+return argument.Signature([], u'args', u'kwds')
 
 def funcrun(self, func, args):
 frame = func.space.createframe(self, func.w_func_globals,
diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py
--- a/pypy/objspace/std/listobject.py
+++ b/pypy/objspace/std/listobject.py
@@ -1059,7 +1059,7 @@
 
 # ___
 
-init_signature = Signature(['sequence'], None, None)
+init_signature = Signature([u'sequence'], None, None)
 init_defaults = [None]
 
 def init__List(space, w_list, __args__):
diff --git a/pypy/objspace/std/setobject.py b/pypy/objspace/std/setobject.py
--- a/pypy/objspace/std/setobject.py
+++ b/pypy/objspace/std/setobject.py
@@ -1377,7 +1377,7 @@
 
 iter__Frozenset = iter__Set
 
-init_signature = Signature(['some_iterable'], None, None)
+init_signature = Signature([u'some_iterable'], None, None)
 init_defaults = [None]
 def init__Set(space, w_set, __args__):
 w_iterable, = __args__.parse_obj(
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: merge heads

2012-08-22 Thread antocuni
Author: Antonio Cuni 
Branch: py3k
Changeset: r56800:e8678fb55920
Date: 2012-08-22 14:25 +0200
http://bitbucket.org/pypy/pypy/changeset/e8678fb55920/

Log:merge heads

diff --git a/TODO b/TODO
--- a/TODO
+++ b/TODO
@@ -10,5 +10,6 @@
 re-enable StdObjSpace.listview_str
 
 re-enable the kwargs dict strategy in dictmultiobject.py
+re-enable view_as_kwargs
 
 unskip numpypy tests in module/test_lib_pypy/numpypy/
diff --git a/pypy/interpreter/argument.py b/pypy/interpreter/argument.py
--- a/pypy/interpreter/argument.py
+++ b/pypy/interpreter/argument.py
@@ -5,6 +5,7 @@
 from pypy.interpreter.error import OperationError, operationerrfmt
 from pypy.rlib.debug import make_sure_not_resized
 from pypy.rlib import jit
+from pypy.rlib.debug import check_annotation
 from pypy.rlib.objectmodel import enforceargs
 
 class Signature(object):
@@ -93,15 +94,19 @@
 raise IndexError
 
 
-def assert_list_of_unicode(value):
-from pypy.rlib.debug import check_annotation
-def checker(ann, bk):
-from pypy.annotation.model import SomeList, SomeUnicodeString
-if not isinstance(ann, SomeList):
-raise TypeError
-if not isinstance(ann.listdef.listitem.s_value, SomeUnicodeString):
-raise TypeError
-check_annotation(value, checker)
+
+def check_list_of_unicode(ann, bk):
+from pypy.annotation.model import (SomeList, SomeUnicodeString,
+   s_None, s_ImpossibleValue)
+if ann is s_None:
+return
+if not isinstance(ann, SomeList):
+raise TypeError
+s_item = ann.listdef.listitem.s_value
+if s_item is s_ImpossibleValue:
+return
+if not isinstance(s_item, SomeUnicodeString):
+raise TypeError
 
 
 class Arguments(object):
@@ -116,13 +121,13 @@
 """
 
 ###  Construction  ###
-@enforceargs(keywords=[unicode])
+#@enforceargs(keywords=[unicode])
 def __init__(self, space, args_w, keywords=None, keywords_w=None,
  w_stararg=None, w_starstararg=None, keyword_names_w=None):
 self.space = space
 assert isinstance(args_w, list)
 self.arguments_w = args_w
-assert_list_of_unicode(keywords)
+check_annotation(keywords, check_list_of_unicode)
 
 self.keywords = keywords
 self.keywords_w = keywords_w
@@ -198,7 +203,7 @@
 # unpack the ** arguments
 space = self.space
 keywords, values_w = space.view_as_kwargs(w_starstararg)
-assert_list_of_unicode(keywords)
+check_annotation(keywords, check_list_of_unicode)
 if keywords is not None: # this path also taken for empty dicts
 if self.keywords is None:
 self.keywords = keywords
diff --git a/pypy/module/__builtin__/compiling.py 
b/pypy/module/__builtin__/compiling.py
--- a/pypy/module/__builtin__/compiling.py
+++ b/pypy/module/__builtin__/compiling.py
@@ -6,7 +6,7 @@
 from pypy.interpreter.error import OperationError
 from pypy.interpreter.astcompiler import consts, ast
 from pypy.interpreter.gateway import unwrap_spec
-from pypy.interpreter.argument import Arguments, assert_list_of_unicode
+from pypy.interpreter.argument import Arguments, check_annotation, 
check_list_of_unicode
 from pypy.interpreter.nestedscope import Cell
 
 @unwrap_spec(filename=str, mode=str, flags=int, dont_inherit=int, optimize=int)
@@ -114,7 +114,7 @@
 def build_class(space, w_func, w_name, __args__):
 bases_w, kwds_w = __args__.unpack()
 w_bases = space.newtuple(bases_w)
-w_meta = kwds_w.pop('metaclass', None)
+w_meta = kwds_w.pop(u'metaclass', None)
 if w_meta is None:
 if bases_w:
 w_meta = space.type(bases_w[0])
@@ -129,7 +129,7 @@
 w_namespace = space.newdict()
 else:
 keywords = kwds_w.keys()
-assert_list_of_unicode(keywords)
+check_annotation(keywords, check_list_of_unicode)
 args = Arguments(space, 
  args_w=[w_name, w_bases],
  keywords=keywords,
@@ -137,7 +137,7 @@
 w_namespace = space.call_args(w_prep, args)
 w_cell = space.call_function(w_func, w_namespace)
 keywords = kwds_w.keys()
-assert_list_of_unicode(keywords)
+check_annotation(keywords, check_list_of_unicode)
 args = Arguments(space,
  args_w=[w_name, w_bases, w_namespace],
  keywords=keywords,
diff --git a/pypy/objspace/flow/flowcontext.py 
b/pypy/objspace/flow/flowcontext.py
--- a/pypy/objspace/flow/flowcontext.py
+++ b/pypy/objspace/flow/flowcontext.py
@@ -11,6 +11,7 @@
 from pypy.objspace.flow.framestate import (FrameState, recursively_unflatten,
 recursively_flatten)
 from pypy.tool.stdlib_opcode import host_bytecode_spec
+from pypy.rlib import jit
 
 class StopFlowing(Exception):
 pass
diff --git a/pypy/objspace/std/dictmultiobject.py 
b/pypy/objspace/std/dictmultiobject.py
--- a/pypy/objspace/std/dictmultiobject.py
+++ b/pypy/

[pypy-commit] pypy py3k: one more place where to pass unicode to Signature()

2012-08-22 Thread antocuni
Author: Antonio Cuni 
Branch: py3k
Changeset: r56802:6a591d00373a
Date: 2012-08-22 14:31 +0200
http://bitbucket.org/pypy/pypy/changeset/6a591d00373a/

Log:one more place where to pass unicode to Signature()

diff --git a/pypy/annotation/description.py b/pypy/annotation/description.py
--- a/pypy/annotation/description.py
+++ b/pypy/annotation/description.py
@@ -182,7 +182,7 @@
 if signature is None:
 if hasattr(pyobj, '_generator_next_method_of_'):
 from pypy.interpreter.argument import Signature
-signature = Signature(['entry']) # haack
+signature = Signature([u'entry']) # haack
 defaults = ()
 else:
 signature = cpython_code_signature(pyobj.func_code)
diff --git a/pypy/translator/generator.py b/pypy/translator/generator.py
--- a/pypy/translator/generator.py
+++ b/pypy/translator/generator.py
@@ -178,7 +178,7 @@
Constant(AssertionError("bad generator class"))],
   graph.exceptblock))
 graph.startblock = regular_entry_block
-graph.signature = Signature(['entry'])
+graph.signature = Signature([u'entry'])
 graph.defaults = ()
 checkgraph(graph)
 eliminate_empty_blocks(graph)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: one more place where to pass unicode to Signature()

2012-08-22 Thread antocuni
Author: Antonio Cuni 
Branch: py3k
Changeset: r56804:bd3326f15584
Date: 2012-08-22 14:35 +0200
http://bitbucket.org/pypy/pypy/changeset/bd3326f15584/

Log:one more place where to pass unicode to Signature()

diff --git a/pypy/translator/test/test_generator.py 
b/pypy/translator/test/test_generator.py
--- a/pypy/translator/test/test_generator.py
+++ b/pypy/translator/test/test_generator.py
@@ -111,7 +111,7 @@
 graph.show()
 # XXX how to test directly that the graph is correct?  :-(
 assert len(graph.startblock.inputargs) == 1
-assert graph.signature == Signature(['entry'])
+assert graph.signature == Signature([u'entry'])
 assert graph.defaults == ()
 
 def test_tweak_generator_graph(self):
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: one more place where to pass unicode to Signature()

2012-08-22 Thread antocuni
Author: Antonio Cuni 
Branch: py3k
Changeset: r56801:f860431bfa26
Date: 2012-08-22 14:30 +0200
http://bitbucket.org/pypy/pypy/changeset/f860431bfa26/

Log:one more place where to pass unicode to Signature()

diff --git a/pypy/annotation/specialize.py b/pypy/annotation/specialize.py
--- a/pypy/annotation/specialize.py
+++ b/pypy/annotation/specialize.py
@@ -37,7 +37,7 @@
 newstartblock.operations.append(newtup)
 newstartblock.closeblock(Link(argscopy, graph.startblock))
 graph.startblock = newstartblock
-argnames = argnames + ['.star%d' % i for i in range(nb_extra_args)]
+argnames = argnames + [u'.star%d' % i for i in 
range(nb_extra_args)]
 graph.signature = Signature(argnames)
 # note that we can mostly ignore defaults: if nb_extra_args > 0, 
 # then defaults aren't applied.  if nb_extra_args == 0, then this 
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: fix Signature()/unicode also here

2012-08-22 Thread antocuni
Author: Antonio Cuni 
Branch: py3k
Changeset: r56803:3b7e2e228239
Date: 2012-08-22 14:34 +0200
http://bitbucket.org/pypy/pypy/changeset/3b7e2e228239/

Log:fix Signature()/unicode also here

diff --git a/pypy/interpreter/test/test_gateway.py 
b/pypy/interpreter/test/test_gateway.py
--- a/pypy/interpreter/test/test_gateway.py
+++ b/pypy/interpreter/test/test_gateway.py
@@ -22,24 +22,24 @@
gateway.W_Root,
gateway.W_Root,
'args_w'])
-assert code.signature() == argument.Signature(['x', 'y'], 'hello', 
None)
+assert code.signature() == argument.Signature([u'x', u'y'], u'hello', 
None)
 def d(self, w_boo):
 pass
 code = gateway.BuiltinCode(d, unwrap_spec= ['self',
gateway.W_Root], 
self_type=gateway.Wrappable)
-assert code.signature() == argument.Signature(['self', 'boo'], None, 
None)
+assert code.signature() == argument.Signature([u'self', u'boo'], None, 
None)
 def e(space, w_x, w_y, __args__):
 pass
 code = gateway.BuiltinCode(e, unwrap_spec=[gateway.ObjSpace,
gateway.W_Root,
gateway.W_Root,
gateway.Arguments])
-assert code.signature() == argument.Signature(['x', 'y'], 'args', 
'keywords')
+assert code.signature() == argument.Signature([u'x', u'y'], u'args', 
u'keywords')
 
 def f(space, index):
 pass
 code = gateway.BuiltinCode(f, unwrap_spec=[gateway.ObjSpace, "index"])
-assert code.signature() == argument.Signature(["index"], None, None)
+assert code.signature() == argument.Signature([u"index"], None, None)
 
 
 def test_call(self):
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy speedup-unpackiterable: close merged branch

2012-08-22 Thread fijal
Author: Maciej Fijalkowski 
Branch: speedup-unpackiterable
Changeset: r56806:ccacb43719a4
Date: 2012-08-22 15:30 +0200
http://bitbucket.org/pypy/pypy/changeset/ccacb43719a4/

Log:close merged branch

___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Merge speedup-unpackiterable branch. This creates a jit code for each type

2012-08-22 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r56805:d56db4a267d5
Date: 2012-08-22 15:30 +0200
http://bitbucket.org/pypy/pypy/changeset/d56db4a267d5/

Log:Merge speedup-unpackiterable branch. This creates a jit code for
each type of iterable that goes to unpackiterable.

diff --git a/pypy/interpreter/argument.py b/pypy/interpreter/argument.py
--- a/pypy/interpreter/argument.py
+++ b/pypy/interpreter/argument.py
@@ -301,10 +301,7 @@
 if num_kwds:
 # kwds_mapping maps target indexes in the scope (minus 
input_argcount)
 # to positions in the keywords_w list
-cnt = (co_argcount - input_argcount)
-if cnt < 0:
-cnt = 0
-kwds_mapping = [0] * cnt
+kwds_mapping = [0] * (co_argcount - input_argcount)
 # initialize manually, for the JIT :-(
 for i in range(len(kwds_mapping)):
 kwds_mapping[i] = -1
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -20,6 +20,9 @@
 
 UINT_MAX_32_BITS = r_uint(4294967295)
 
+unpackiterable_driver = jit.JitDriver(name = 'unpackiterable',
+  greens = ['tp'],
+  reds = ['items', 'w_iterator'])
 
 class W_Root(object):
 """This is the abstract root class of all wrapped objects that live
@@ -224,6 +227,23 @@
 def __spacebind__(self, space):
 return self
 
+class W_InterpIterable(W_Root):
+def __init__(self, space, w_iterable):
+self.w_iter = space.iter(w_iterable)
+self.space = space
+
+def __iter__(self):
+return self
+
+def next(self):
+space = self.space
+try:
+return space.next(self.w_iter)
+except OperationError, e:
+if not e.match(space, space.w_StopIteration):
+raise
+raise StopIteration
+
 class InternalSpaceCache(Cache):
 """A generic cache for an object space.  Arbitrary information can
 be attached to the space by defining a function or class 'f' which
@@ -831,6 +851,9 @@
   expected_length)
 return lst_w[:] # make the resulting list resizable
 
+def iteriterable(self, w_iterable):
+return W_InterpIterable(self, w_iterable)
+
 @jit.dont_look_inside
 def _unpackiterable_unknown_length(self, w_iterator, w_iterable):
 # Unpack a variable-size list of unknown length.
@@ -851,7 +874,11 @@
 except MemoryError:
 items = [] # it might have lied
 #
+tp = self.type(w_iterator)
 while True:
+unpackiterable_driver.jit_merge_point(tp=tp,
+  w_iterator=w_iterator,
+  items=items)
 try:
 w_item = self.next(w_iterator)
 except OperationError, e:
diff --git a/pypy/jit/metainterp/warmspot.py b/pypy/jit/metainterp/warmspot.py
--- a/pypy/jit/metainterp/warmspot.py
+++ b/pypy/jit/metainterp/warmspot.py
@@ -14,6 +14,7 @@
 from pypy.rlib.debug import fatalerror
 from pypy.rlib.rstackovf import StackOverflow
 from pypy.translator.simplify import get_functype
+from pypy.translator.backendopt import removenoops
 from pypy.translator.unsimplify import call_final_function
 
 from pypy.jit.metainterp import history, pyjitpl, gc, memmgr
@@ -260,6 +261,10 @@
 graph = copygraph(graph)
 [jmpp] = find_jit_merge_points([graph])
 graph.startblock = support.split_before_jit_merge_point(*jmpp)
+# XXX this is incredibly obscure, but this is sometiems necessary
+# so we don't explode in checkgraph. for reasons unknown this
+# is not contanied within simplify_graph
+removenoops.remove_same_as(graph)
 # a crash in the following checkgraph() means that you forgot
 # to list some variable in greens=[] or reds=[] in JitDriver,
 # or that a jit_merge_point() takes a constant as an argument.
diff --git a/pypy/module/itertools/test/test_itertools.py 
b/pypy/module/itertools/test/test_itertools.py
--- a/pypy/module/itertools/test/test_itertools.py
+++ b/pypy/module/itertools/test/test_itertools.py
@@ -88,6 +88,13 @@
 list(it)
 assert repr(it) == "repeat('foobar', 0)"
 
+def test_repeat_len(self):
+import itertools
+
+r = itertools.repeat('a', 15)
+r.next()
+raises(TypeError, "len(itertools.repeat('xkcd'))")
+
 def test_takewhile(self):
 import itertools
 
diff --git a/pypy/objspace/std/celldict.py b/pypy/objspace/std/celldict.py
--- a/pypy/objspace/std/celldict.py
+++ b/pypy/objspace/std/celldict.py
@@ -4,7 +4,7 @@
 """
 
 from pypy.interpreter.baseobjspace import W_Root
-from pypy.objspace.std.dictmultiobject import IteratorImp

[pypy-commit] cffi win32: clarify skip messages

2012-08-22 Thread mattip
Author: mattip
Branch: win32
Changeset: r868:3522aa063595
Date: 2012-08-22 17:43 +0300
http://bitbucket.org/cffi/cffi/changeset/3522aa063595/

Log:clarify skip messages

diff --git a/testing/test_verify.py b/testing/test_verify.py
--- a/testing/test_verify.py
+++ b/testing/test_verify.py
@@ -273,7 +273,7 @@
 ffi.verify("struct foo_s { char x; int y; long *z; };")
 #
 if sys.platform == 'win32':
-py.test.skip("XXX fixme: only gives warnings")
+py.test.skip("XXX fixme: only gives warnings - need to add /WX flag")
 for real in [
 "struct foo_s { char x; int y; int *z; };",
 "struct foo_s { char x; long *z; int y; };",
@@ -346,7 +346,7 @@
 
 def test_struct_float_vs_int():
 if sys.platform == 'win32':
-py.test.skip("XXX fixme: only gives warnings")
+py.test.skip("XXX fixme: only gives warnings - need to add /WX flag")
 for typename in all_signed_integer_types:
 for real in all_float_types:
 _check_field_match(typename, real, expect_mismatch=True)
@@ -665,7 +665,7 @@
 
 def test_varargs_exact():
 if sys.platform == 'win32':
-py.test.skip("XXX fixme: only gives warnings")
+py.test.skip("XXX fixme: only gives warnings - need to add /WX flag")
 ffi = FFI()
 ffi.cdef("int foo(int x, ...);")
 py.test.raises(VerificationError, ffi.verify, """
@@ -809,7 +809,7 @@
 assert lib.foo_func(lib.BB) == "BB"
 
 def test_callback_calling_convention():
-py.test.skip("later")
+py.test.skip("pycparser parses c99 only with no compiler-specific 
extensions")
 if sys.platform != 'win32':
 py.test.skip("Windows only")
 ffi = FFI()
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi default: Give an earlier error message when trying to declare a function

2012-08-22 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r870:ede1d10ba97c
Date: 2012-08-22 18:56 +0200
http://bitbucket.org/cffi/cffi/changeset/ede1d10ba97c/

Log:Give an earlier error message when trying to declare a function
using exactly '(...)' as the argument list. It's not valid C.

diff --git a/cffi/cparser.py b/cffi/cparser.py
--- a/cffi/cparser.py
+++ b/cffi/cparser.py
@@ -244,7 +244,11 @@
 params[-1].type.type.names == ['__dotdotdot__'])
 if ellipsis:
 params.pop()
-if (len(params) == 1 and
+if not params:
+raise api.CDefError(
+"%s: a function with only '(...)' as argument"
+" is not correct C" % (funcname or 'in expression'))
+elif (len(params) == 1 and
 isinstance(params[0].type, pycparser.c_ast.TypeDecl) and
 isinstance(params[0].type.type, pycparser.c_ast.IdentifierType)
 and list(params[0].type.type.names) == ['void']):
diff --git a/testing/test_parsing.py b/testing/test_parsing.py
--- a/testing/test_parsing.py
+++ b/testing/test_parsing.py
@@ -177,3 +177,10 @@
 assert C.foo.BType == ', False>'
 ffi.cdef("long foo(void);", override=True)
 assert C.foo.BType == ', False>'
+
+def test_cannot_have_only_variadic_part():
+# this checks that we get a sensible error if we try "int foo(...);"
+ffi = FFI()
+e = py.test.raises(CDefError, ffi.cdef, "int foo(...);")
+assert str(e.value) == \
+   "foo: a function with only '(...)' as argument is not correct C"
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: improve the error message

2012-08-22 Thread antocuni
Author: Antonio Cuni 
Branch: py3k
Changeset: r56807:7a6f1cc7
Date: 2012-08-22 17:15 +0200
http://bitbucket.org/pypy/pypy/changeset/7a6f1cc7/

Log:improve the error message

diff --git a/pypy/rlib/objectmodel.py b/pypy/rlib/objectmodel.py
--- a/pypy/rlib/objectmodel.py
+++ b/pypy/rlib/objectmodel.py
@@ -163,8 +163,8 @@
 #
 s_argtype = get_annotation(get_type_descr_of_argument(arg))
 if not s_expected.contains(s_argtype):
-msg = "%s argument number %d must be of type %s" % (
-f.func_name, i+1, expected_type)
+msg = "%s argument %r must be of type %s" % (
+f.func_name, srcargs[i], expected_type)
 raise TypeError, msg
 #
 # we cannot simply wrap the function using *args, **kwds, because it's
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: don't complain if we pass None to something which expects unicode or str

2012-08-22 Thread antocuni
Author: Antonio Cuni 
Branch: 
Changeset: r56808:1ce7beebfd5f
Date: 2012-08-22 13:44 +0200
http://bitbucket.org/pypy/pypy/changeset/1ce7beebfd5f/

Log:don't complain if we pass None to something which expects unicode or
str

diff --git a/pypy/rlib/objectmodel.py b/pypy/rlib/objectmodel.py
--- a/pypy/rlib/objectmodel.py
+++ b/pypy/rlib/objectmodel.py
@@ -129,10 +129,13 @@
 def decorator(f):
 def get_annotation(t):
 from pypy.annotation.signature import annotation
-from pypy.annotation.model import SomeObject
+from pypy.annotation.model import SomeObject, SomeStringOrUnicode
 if isinstance(t, SomeObject):
 return t
-return annotation(t)
+s_result = annotation(t)
+if isinstance(s_result, SomeStringOrUnicode):
+return s_result.__class__(can_be_None=True)
+return s_result
 def get_type_descr_of_argument(arg):
 # we don't want to check *all* the items in list/dict: we assume
 # they are already homogeneous, so we only check the first
diff --git a/pypy/rlib/test/test_objectmodel.py 
b/pypy/rlib/test/test_objectmodel.py
--- a/pypy/rlib/test/test_objectmodel.py
+++ b/pypy/rlib/test/test_objectmodel.py
@@ -450,6 +450,12 @@
 # in RPython there is an implicit int->float promotion
 assert f(42) == 42
 
+def test_enforceargs_None_string():
+@enforceargs(str, unicode)
+def f(a, b):
+return a, b
+assert f(None, None) == (None, None)
+
 def test_enforceargs_complex_types():
 @enforceargs([int], {str: int})
 def f(a, b):
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: improve the error message

2012-08-22 Thread antocuni
Author: Antonio Cuni 
Branch: 
Changeset: r56809:699b45a65495
Date: 2012-08-22 17:15 +0200
http://bitbucket.org/pypy/pypy/changeset/699b45a65495/

Log:improve the error message

diff --git a/pypy/rlib/objectmodel.py b/pypy/rlib/objectmodel.py
--- a/pypy/rlib/objectmodel.py
+++ b/pypy/rlib/objectmodel.py
@@ -163,8 +163,8 @@
 #
 s_argtype = get_annotation(get_type_descr_of_argument(arg))
 if not s_expected.contains(s_argtype):
-msg = "%s argument number %d must be of type %s" % (
-f.func_name, i+1, expected_type)
+msg = "%s argument %r must be of type %s" % (
+f.func_name, srcargs[i], expected_type)
 raise TypeError, msg
 #
 # we cannot simply wrap the function using *args, **kwds, because it's
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: fix test

2012-08-22 Thread antocuni
Author: Antonio Cuni 
Branch: 
Changeset: r56810:c624f0e4d488
Date: 2012-08-22 17:17 +0200
http://bitbucket.org/pypy/pypy/changeset/c624f0e4d488/

Log:fix test

diff --git a/pypy/rlib/test/test_objectmodel.py 
b/pypy/rlib/test/test_objectmodel.py
--- a/pypy/rlib/test/test_objectmodel.py
+++ b/pypy/rlib/test/test_objectmodel.py
@@ -427,7 +427,7 @@
 assert f.foo == 'foo'
 assert f(1, 'hello', 42) == (1, 'hello', 42)
 exc = py.test.raises(TypeError, "f(1, 2, 3)")
-assert exc.value.message == "f argument number 2 must be of type "
+assert exc.value.message == "f argument 'b' must be of type "
 py.test.raises(TypeError, "f('hello', 'world', 3)")
 
 
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: merge heads

2012-08-22 Thread antocuni
Author: Antonio Cuni 
Branch: 
Changeset: r56811:773c11368fb7
Date: 2012-08-22 18:52 +0200
http://bitbucket.org/pypy/pypy/changeset/773c11368fb7/

Log:merge heads

diff --git a/pypy/interpreter/argument.py b/pypy/interpreter/argument.py
--- a/pypy/interpreter/argument.py
+++ b/pypy/interpreter/argument.py
@@ -301,10 +301,7 @@
 if num_kwds:
 # kwds_mapping maps target indexes in the scope (minus 
input_argcount)
 # to positions in the keywords_w list
-cnt = (co_argcount - input_argcount)
-if cnt < 0:
-cnt = 0
-kwds_mapping = [0] * cnt
+kwds_mapping = [0] * (co_argcount - input_argcount)
 # initialize manually, for the JIT :-(
 for i in range(len(kwds_mapping)):
 kwds_mapping[i] = -1
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -20,6 +20,9 @@
 
 UINT_MAX_32_BITS = r_uint(4294967295)
 
+unpackiterable_driver = jit.JitDriver(name = 'unpackiterable',
+  greens = ['tp'],
+  reds = ['items', 'w_iterator'])
 
 class W_Root(object):
 """This is the abstract root class of all wrapped objects that live
@@ -224,6 +227,23 @@
 def __spacebind__(self, space):
 return self
 
+class W_InterpIterable(W_Root):
+def __init__(self, space, w_iterable):
+self.w_iter = space.iter(w_iterable)
+self.space = space
+
+def __iter__(self):
+return self
+
+def next(self):
+space = self.space
+try:
+return space.next(self.w_iter)
+except OperationError, e:
+if not e.match(space, space.w_StopIteration):
+raise
+raise StopIteration
+
 class InternalSpaceCache(Cache):
 """A generic cache for an object space.  Arbitrary information can
 be attached to the space by defining a function or class 'f' which
@@ -831,6 +851,9 @@
   expected_length)
 return lst_w[:] # make the resulting list resizable
 
+def iteriterable(self, w_iterable):
+return W_InterpIterable(self, w_iterable)
+
 @jit.dont_look_inside
 def _unpackiterable_unknown_length(self, w_iterator, w_iterable):
 # Unpack a variable-size list of unknown length.
@@ -851,7 +874,11 @@
 except MemoryError:
 items = [] # it might have lied
 #
+tp = self.type(w_iterator)
 while True:
+unpackiterable_driver.jit_merge_point(tp=tp,
+  w_iterator=w_iterator,
+  items=items)
 try:
 w_item = self.next(w_iterator)
 except OperationError, e:
diff --git a/pypy/jit/metainterp/warmspot.py b/pypy/jit/metainterp/warmspot.py
--- a/pypy/jit/metainterp/warmspot.py
+++ b/pypy/jit/metainterp/warmspot.py
@@ -14,6 +14,7 @@
 from pypy.rlib.debug import fatalerror
 from pypy.rlib.rstackovf import StackOverflow
 from pypy.translator.simplify import get_functype
+from pypy.translator.backendopt import removenoops
 from pypy.translator.unsimplify import call_final_function
 
 from pypy.jit.metainterp import history, pyjitpl, gc, memmgr
@@ -260,6 +261,10 @@
 graph = copygraph(graph)
 [jmpp] = find_jit_merge_points([graph])
 graph.startblock = support.split_before_jit_merge_point(*jmpp)
+# XXX this is incredibly obscure, but this is sometiems necessary
+# so we don't explode in checkgraph. for reasons unknown this
+# is not contanied within simplify_graph
+removenoops.remove_same_as(graph)
 # a crash in the following checkgraph() means that you forgot
 # to list some variable in greens=[] or reds=[] in JitDriver,
 # or that a jit_merge_point() takes a constant as an argument.
diff --git a/pypy/module/itertools/test/test_itertools.py 
b/pypy/module/itertools/test/test_itertools.py
--- a/pypy/module/itertools/test/test_itertools.py
+++ b/pypy/module/itertools/test/test_itertools.py
@@ -88,6 +88,13 @@
 list(it)
 assert repr(it) == "repeat('foobar', 0)"
 
+def test_repeat_len(self):
+import itertools
+
+r = itertools.repeat('a', 15)
+r.next()
+raises(TypeError, "len(itertools.repeat('xkcd'))")
+
 def test_takewhile(self):
 import itertools
 
diff --git a/pypy/objspace/std/celldict.py b/pypy/objspace/std/celldict.py
--- a/pypy/objspace/std/celldict.py
+++ b/pypy/objspace/std/celldict.py
@@ -4,7 +4,7 @@
 """
 
 from pypy.interpreter.baseobjspace import W_Root
-from pypy.objspace.std.dictmultiobject import IteratorImplementation
+from pypy.objspace.std.dictmultiobject import create_iterator_classes
 from pypy.objspace.std.dictmultiob

[pypy-commit] cffi default: Windows: don't muck with LastError in b_get_errno()

2012-08-22 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r869:af978ad0a0a8
Date: 2012-08-22 18:55 +0200
http://bitbucket.org/cffi/cffi/changeset/af978ad0a0a8/

Log:Windows: don't muck with LastError in b_get_errno() and
b_set_errno()

diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -197,6 +197,8 @@
 # else
 #  include "misc_thread.h"
 # endif
+# define save_errno_only  save_errno
+# define restore_errno_only   restore_errno
 #endif
 
 #ifdef HAVE_WCHAR_H
@@ -4044,7 +4046,7 @@
 static PyObject *b_get_errno(PyObject *self, PyObject *noarg)
 {
 int err;
-restore_errno();
+restore_errno_only();
 err = errno;
 errno = 0;
 return PyInt_FromLong(err);
@@ -4056,7 +4058,7 @@
 if (!PyArg_ParseTuple(args, "i:set_errno", &i))
 return NULL;
 errno = i;
-save_errno();
+save_errno_only();
 errno = 0;
 Py_INCREF(Py_None);
 return Py_None;
diff --git a/c/misc_win32.h b/c/misc_win32.h
--- a/c/misc_win32.h
+++ b/c/misc_win32.h
@@ -45,6 +45,18 @@
 /* else: cannot report the error */
 }
 
+static void save_errno_only(void)
+{
+int current_err = errno;
+struct cffi_errno_s *p;
+
+p = _geterrno_object();
+if (p != NULL) {
+p->saved_errno = current_err;
+}
+/* else: cannot report the error */
+}
+
 static void restore_errno(void)
 {
 struct cffi_errno_s *p;
@@ -57,6 +69,16 @@
 /* else: cannot report the error */
 }
 
+static void restore_errno_only(void)
+{
+struct cffi_errno_s *p;
+
+p = _geterrno_object();
+if (p != NULL) {
+errno = p->saved_errno;
+}
+/* else: cannot report the error */
+}
 
 //
 /* Emulate dlopen()&co. from the Windows API */
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi default: Give a better error message than pycparser's default one

2012-08-22 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r871:78e101dc0f74
Date: 2012-08-22 19:20 +0200
http://bitbucket.org/cffi/cffi/changeset/78e101dc0f74/

Log:Give a better error message than pycparser's default one on
ParseErrors

diff --git a/cffi/cparser.py b/cffi/cparser.py
--- a/cffi/cparser.py
+++ b/cffi/cparser.py
@@ -1,6 +1,6 @@
 
 from . import api, model
-import pycparser, weakref, re
+import pycparser.c_parser, weakref, re
 
 _r_comment = re.compile(r"/\*.*?\*/|//.*?$", re.DOTALL | re.MULTILINE)
 _r_define  = re.compile(r"^\s*#\s*define\s+([A-Za-z_][A-Za-z_0-9]*)\s+(.*?)$",
@@ -61,9 +61,30 @@
 csource, macros = _preprocess(csource)
 csourcelines.append(csource)
 csource = '\n'.join(csourcelines)
-ast = _get_parser().parse(csource)
+try:
+ast = _get_parser().parse(csource)
+except pycparser.c_parser.ParseError, e:
+self.convert_pycparser_error(e, csource)
 return ast, macros
 
+def convert_pycparser_error(self, e, csource):
+# xxx look for ":NUM:" at the start of str(e) and try to interpret
+# it as a line number
+line = None
+msg = str(e)
+if msg.startswith(':') and ':' in msg[1:]:
+linenum = msg[1:msg.find(':',1)]
+if linenum.isdigit():
+linenum = int(linenum, 10)
+csourcelines = csource.splitlines()
+if 1 <= linenum <= len(csourcelines):
+line = csourcelines[linenum-1]
+if line:
+msg = 'cannot parse "%s"\n%s' % (line, msg)
+else:
+msg = 'parse error\n%s' % (msg,)
+raise api.CDefError(msg)
+
 def parse(self, csource, override=False):
 prev_override = self._override
 try:
diff --git a/testing/test_parsing.py b/testing/test_parsing.py
--- a/testing/test_parsing.py
+++ b/testing/test_parsing.py
@@ -1,4 +1,4 @@
-import py, sys
+import py, sys, re
 from cffi import FFI, FFIError, CDefError, VerificationError
 
 class FakeBackend(object):
@@ -184,3 +184,8 @@
 e = py.test.raises(CDefError, ffi.cdef, "int foo(...);")
 assert str(e.value) == \
"foo: a function with only '(...)' as argument is not correct C"
+
+def test_parse_error():
+ffi = FFI()
+e = py.test.raises(CDefError, ffi.cdef, " x y z ")
+assert re.match(r'cannot parse " x y z "\n:\d+:', str(e.value))
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi default: Test and fix: don't allow 'void' as the type of a function argument.

2012-08-22 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r872:b3678ddd1d27
Date: 2012-08-22 19:50 +0200
http://bitbucket.org/cffi/cffi/changeset/b3678ddd1d27/

Log:Test and fix: don't allow 'void' as the type of a function argument.

diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -3184,7 +3184,7 @@
 else if (ct->ct_flags & (CT_POINTER|CT_ARRAY|CT_FUNCTIONPTR)) {
 return &ffi_type_pointer;
 }
-else if (ct->ct_flags & CT_VOID) {
+else if ((ct->ct_flags & CT_VOID) && is_result_type) {
 return &ffi_type_void;
 }
 
diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -773,6 +773,11 @@
 BFunc = new_function_type((BInt, BInt), BVoid, False)
 assert repr(BFunc) == ""
 
+def test_function_void_arg():
+BVoid = new_void_type()
+BInt = new_primitive_type("int")
+py.test.raises(TypeError, new_function_type, (BVoid,), BInt, False)
+
 def test_call_function_0():
 BSignedChar = new_primitive_type("signed char")
 BFunc0 = new_function_type((BSignedChar, BSignedChar), BSignedChar, False)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Import the changes. Fix the latest test.

2012-08-22 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r56812:028b65a5a45f
Date: 2012-08-22 19:57 +0200
http://bitbucket.org/pypy/pypy/changeset/028b65a5a45f/

Log:Import the changes. Fix the latest test.

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
@@ -229,7 +229,7 @@
 W_CTypePrimitiveFloat._get_ffi_type = _primfloat_ffi_type
 W_CTypePrimitiveLongDouble._get_ffi_type= _primlongdouble_ffi_type
 W_CTypePtrBase._get_ffi_type= _ptr_ffi_type
-W_CTypeVoid._get_ffi_type   = _void_ffi_type
+#W_CTypeVoid._get_ffi_type  = _void_ffi_type -- special-cased
 # --
 
 
@@ -251,7 +251,9 @@
 return result
 
 
-def fb_fill_type(self, ctype):
+def fb_fill_type(self, ctype, is_result_type):
+if is_result_type and isinstance(ctype, W_CTypeVoid):
+return clibffi.ffi_type_void
 return ctype._get_ffi_type(self)
 
 def fb_struct_ffi_type(self, ctype):
@@ -281,7 +283,7 @@
 raise OperationError(space.w_NotImplementedError,
 space.wrap("cannot pass as argument a struct "
"with bit fields"))
-ffi_subtype = self.fb_fill_type(cf.ctype)
+ffi_subtype = self.fb_fill_type(cf.ctype, False)
 if elements:
 elements[i] = ffi_subtype
 
@@ -322,11 +324,11 @@
 self.atypes = rffi.cast(FFI_TYPE_PP, atypes)
 
 # next comes the result type data
-self.rtype = self.fb_fill_type(self.fresult)
+self.rtype = self.fb_fill_type(self.fresult, True)
 
 # next comes each argument's type data
 for i, farg in enumerate(self.fargs):
-atype = self.fb_fill_type(farg)
+atype = self.fb_fill_type(farg, False)
 if self.atypes:
 self.atypes[i] = atype
 
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
@@ -8,6 +8,11 @@
 readbuf = str
 bufchar = lambda x: x
 bytechr = chr
+class U(object):
+def __add__(self, other):
+return eval('u'+repr(other).replace(r'\\u', r'\u')
+   .replace(r'\\U', r'\U'))
+u = U()
 else:
 type_or_class = "class"
 long = int
@@ -18,6 +23,7 @@
 readbuf = lambda buf: buf.tobytes()
 bufchar = ord
 bytechr = lambda n: bytes([n])
+u = ""
 
 def size_of_int():
 BInt = new_primitive_type("int")
@@ -92,7 +98,7 @@
 py.test.raises(TypeError, cast, p, None)
 assert long(cast(p, min - 1)) == max
 assert int(cast(p, b'\x08')) == 8
-assert int(cast(p, u'\x08')) == 8
+assert int(cast(p, u+'\x08')) == 8
 for name in ['char', 'short', 'int', 'long', 'long long']:
 p = new_primitive_type('unsigned ' + name)
 size = sizeof(p)
@@ -103,7 +109,7 @@
 assert int(cast(p, max + 1)) == 0
 assert long(cast(p, -1)) == max
 assert int(cast(p, b'\xFE')) == 254
-assert int(cast(p, u'\xFE')) == 254
+assert int(cast(p, u+'\xFE')) == 254
 
 def test_no_float_on_int_types():
 p = new_primitive_type('long')
@@ -136,7 +142,7 @@
 assert cast(p, -1.1) != cast(p, -1.1)
 assert repr(float(cast(p, -0.0))) == '-0.0'
 assert float(cast(p, b'\x09')) == 9.0
-assert float(cast(p, u'\x09')) == 9.0
+assert float(cast(p, u+'\x09')) == 9.0
 assert float(cast(p, True)) == 1.0
 py.test.raises(TypeError, cast, p, None)
 
@@ -286,12 +292,12 @@
 assert p[0] == b'A'
 py.test.raises(TypeError, newp, BPtr, 65)
 py.test.raises(TypeError, newp, BPtr, b"foo")
-py.test.raises(TypeError, newp, BPtr, u"foo")
+py.test.raises(TypeError, newp, BPtr, u+"foo")
 c = cast(BChar, b'A')
 assert str(c) == repr(c)
 assert int(c) == ord(b'A')
 py.test.raises(TypeError, cast, BChar, b'foo')
-py.test.raises(TypeError, cast, BChar, u'foo')
+py.test.raises(TypeError, cast, BChar, u+'foo')
 
 def test_reading_pointer_to_pointer():
 BVoidP = new_pointer_type(new_void_type())
@@ -763,6 +769,11 @@
 BFunc = new_function_type((BInt, BInt), BVoid, False)
 assert repr(BFunc) == ""
 
+def test_function_void_arg():
+BVoid = new_void_type()
+BInt = new_primitive_type("int")
+py.test.raises(TypeError, new_function_type, (BVoid,), BInt, False)
+
 def test_call_function_0():
 BSignedChar = new_primitive_type("signed char")
 BFunc0 = new_function_type((BSignedChar, BSignedChar), BSignedChar, False)
@@ -846,7 +857,7 @@
 #
 py.test.raises(TypeError, f, 123456)
 py.test.raises(TypeError, f, "foo")
-py.test.raises(TypeError, f, u"bar")
+py.test.raises(TypeError

[pypy-commit] cffi win32: add __stdcall test

2012-08-22 Thread mattip
Author: mattip 
Branch: win32
Changeset: r873:f3e4f01be0b4
Date: 2012-08-22 22:20 +0300
http://bitbucket.org/cffi/cffi/changeset/f3e4f01be0b4/

Log:add __stdcall test

diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -4202,6 +4202,17 @@
 return ptr->a1 + ptr->a2;
 }
 
+#ifdef MS_WIN32
+#define stdcall __stdcall
+#else
+#define sdcall 
+#endif
+
+static int stdcall _testfunc21(int a, int b)
+{
+return a+b;
+}
+
 static PyObject *b__testfunc(PyObject *self, PyObject *args)
 {
 /* for testing only */
@@ -4231,6 +4242,7 @@
 case 18: f = &_testfunc18; break;
 case 19: f = &_testfunc19; break;
 case 20: f = &_testfunc20; break;
+case 21: f = &_testfunc21; break;
 default:
 PyErr_SetNone(PyExc_ValueError);
 return NULL;
diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -905,6 +905,13 @@
 BSShort = new_primitive_type("short")
 assert f(3, cast(BSChar, -3), cast(BUChar, 200), cast(BSShort, -5)) == 192
 
+def test_call_function_21():
+BInt = new_primitive_type("int")
+BFunc21 = new_function_type((BInt, BInt), BInt, False)
+f = cast(BFunc21, _testfunc(21))
+assert f(40, 2) == 42
+assert f(-100, -100) == -200
+
 def test_cannot_call_with_a_autocompleted_struct():
 BSChar = new_primitive_type("signed char")
 BDouble = new_primitive_type("double")
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi win32: merge default into branch

2012-08-22 Thread mattip
Author: mattip 
Branch: win32
Changeset: r874:4b70a2b6ac68
Date: 2012-08-22 22:20 +0300
http://bitbucket.org/cffi/cffi/changeset/4b70a2b6ac68/

Log:merge default into branch

diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -197,6 +197,8 @@
 # else
 #  include "misc_thread.h"
 # endif
+# define save_errno_only  save_errno
+# define restore_errno_only   restore_errno
 #endif
 
 #ifdef HAVE_WCHAR_H
@@ -3182,7 +3184,7 @@
 else if (ct->ct_flags & (CT_POINTER|CT_ARRAY|CT_FUNCTIONPTR)) {
 return &ffi_type_pointer;
 }
-else if (ct->ct_flags & CT_VOID) {
+else if ((ct->ct_flags & CT_VOID) && is_result_type) {
 return &ffi_type_void;
 }
 
@@ -4044,7 +4046,7 @@
 static PyObject *b_get_errno(PyObject *self, PyObject *noarg)
 {
 int err;
-restore_errno();
+restore_errno_only();
 err = errno;
 errno = 0;
 return PyInt_FromLong(err);
@@ -4056,7 +4058,7 @@
 if (!PyArg_ParseTuple(args, "i:set_errno", &i))
 return NULL;
 errno = i;
-save_errno();
+save_errno_only();
 errno = 0;
 Py_INCREF(Py_None);
 return Py_None;
diff --git a/c/misc_win32.h b/c/misc_win32.h
--- a/c/misc_win32.h
+++ b/c/misc_win32.h
@@ -45,6 +45,18 @@
 /* else: cannot report the error */
 }
 
+static void save_errno_only(void)
+{
+int current_err = errno;
+struct cffi_errno_s *p;
+
+p = _geterrno_object();
+if (p != NULL) {
+p->saved_errno = current_err;
+}
+/* else: cannot report the error */
+}
+
 static void restore_errno(void)
 {
 struct cffi_errno_s *p;
@@ -57,6 +69,16 @@
 /* else: cannot report the error */
 }
 
+static void restore_errno_only(void)
+{
+struct cffi_errno_s *p;
+
+p = _geterrno_object();
+if (p != NULL) {
+errno = p->saved_errno;
+}
+/* else: cannot report the error */
+}
 
 //
 /* Emulate dlopen()&co. from the Windows API */
diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -773,6 +773,11 @@
 BFunc = new_function_type((BInt, BInt), BVoid, False)
 assert repr(BFunc) == ""
 
+def test_function_void_arg():
+BVoid = new_void_type()
+BInt = new_primitive_type("int")
+py.test.raises(TypeError, new_function_type, (BVoid,), BInt, False)
+
 def test_call_function_0():
 BSignedChar = new_primitive_type("signed char")
 BFunc0 = new_function_type((BSignedChar, BSignedChar), BSignedChar, False)
diff --git a/cffi/cparser.py b/cffi/cparser.py
--- a/cffi/cparser.py
+++ b/cffi/cparser.py
@@ -1,6 +1,6 @@
 
 from . import api, model
-import pycparser, weakref, re
+import pycparser.c_parser, weakref, re
 
 _r_comment = re.compile(r"/\*.*?\*/|//.*?$", re.DOTALL | re.MULTILINE)
 _r_define  = re.compile(r"^\s*#\s*define\s+([A-Za-z_][A-Za-z_0-9]*)\s+(.*?)$",
@@ -61,9 +61,30 @@
 csource, macros = _preprocess(csource)
 csourcelines.append(csource)
 csource = '\n'.join(csourcelines)
-ast = _get_parser().parse(csource)
+try:
+ast = _get_parser().parse(csource)
+except pycparser.c_parser.ParseError, e:
+self.convert_pycparser_error(e, csource)
 return ast, macros
 
+def convert_pycparser_error(self, e, csource):
+# xxx look for ":NUM:" at the start of str(e) and try to interpret
+# it as a line number
+line = None
+msg = str(e)
+if msg.startswith(':') and ':' in msg[1:]:
+linenum = msg[1:msg.find(':',1)]
+if linenum.isdigit():
+linenum = int(linenum, 10)
+csourcelines = csource.splitlines()
+if 1 <= linenum <= len(csourcelines):
+line = csourcelines[linenum-1]
+if line:
+msg = 'cannot parse "%s"\n%s' % (line, msg)
+else:
+msg = 'parse error\n%s' % (msg,)
+raise api.CDefError(msg)
+
 def parse(self, csource, override=False):
 prev_override = self._override
 try:
@@ -244,7 +265,11 @@
 params[-1].type.type.names == ['__dotdotdot__'])
 if ellipsis:
 params.pop()
-if (len(params) == 1 and
+if not params:
+raise api.CDefError(
+"%s: a function with only '(...)' as argument"
+" is not correct C" % (funcname or 'in expression'))
+elif (len(params) == 1 and
 isinstance(params[0].type, pycparser.c_ast.TypeDecl) and
 isinstance(params[0].type.type, pycparser.c_ast.IdentifierType)
 and list(params[0].type.type.names) == ['void']):
diff --git a/testing/test_parsing.py b/testing/test_parsing.py
--- a/testing/test_parsing.py
+++ b/testing/test_parsing.py
@@ -1,4 +1,4 @@
-import py, sys
+import py, sys, re
 from cffi import FFI, FFIError, CDefError, VerificationError
 
 class FakeBackend(object):
@@ -177,3 

[pypy-commit] pypy vref-copy: slow progress

2012-08-22 Thread fijal
Author: Maciej Fijalkowski 
Branch: vref-copy
Changeset: r56813:6112dd6a9ff6
Date: 2012-08-22 22:36 +0200
http://bitbucket.org/pypy/pypy/changeset/6112dd6a9ff6/

Log:slow progress

diff --git a/pypy/jit/metainterp/compile.py b/pypy/jit/metainterp/compile.py
--- a/pypy/jit/metainterp/compile.py
+++ b/pypy/jit/metainterp/compile.py
@@ -2,7 +2,7 @@
 from pypy.rpython.lltypesystem import lltype
 from pypy.rpython.ootypesystem import ootype
 from pypy.objspace.flow.model import Constant, Variable
-from pypy.rlib.objectmodel import we_are_translated
+from pypy.rlib.objectmodel import we_are_translated, specialize
 from pypy.rlib.debug import debug_start, debug_stop, debug_print
 from pypy.rlib import rstack
 from pypy.rlib.jit import JitDebugInfo, Counters
@@ -638,6 +638,12 @@
 self.copy_all_attributes_into(res)
 return res
 
+@specialize.arg(2)
+def read_field_from_resume(cpu, token, fieldname):
+faildescr = cpu.force(token)
+assert isinstance(faildescr, ResumeGuardForcedDescr)
+return faildescr.handle_async_field_read(token, fieldname)
+
 class ResumeGuardForcedDescr(ResumeGuardDescr):
 
 def __init__(self, metainterp_sd, jitdriver_sd):
@@ -686,6 +692,13 @@
 # future failure of the GUARD_NOT_FORCED
 self.save_data(force_token, all_virtuals)
 
+@specialize.arg(2)
+def handle_async_field_read(self, force_token, fieldname):
+from pypy.jit.metainterp.resume import read_field_from_resumedata
+metainterp_sd = self.metainterp_sd
+ginfo = self.jitdriver_sd.greenfield_info
+return read_field_from_resumedata(metainterp_sd, self, ginfo)
+
 def save_data(self, key, value):
 globaldata = self.metainterp_sd.globaldata
 if we_are_translated():
diff --git a/pypy/jit/metainterp/resume.py b/pypy/jit/metainterp/resume.py
--- a/pypy/jit/metainterp/resume.py
+++ b/pypy/jit/metainterp/resume.py
@@ -793,6 +793,9 @@
 resumereader.done()
 return resumereader.liveboxes, virtualizable_boxes, virtualref_boxes
 
+def read_field_from_resumedata(metainterp, storage, greenfield_info):
+xxx
+
 class ResumeDataBoxReader(AbstractResumeDataReader):
 unique_id = lambda: None
 
diff --git a/pypy/jit/metainterp/virtualref.py 
b/pypy/jit/metainterp/virtualref.py
--- a/pypy/jit/metainterp/virtualref.py
+++ b/pypy/jit/metainterp/virtualref.py
@@ -36,11 +36,19 @@
 def _freeze_(self):
 return True
 
-def _find_type_of_virtualref(self):
+def _find_type_of_virtualref(self, graphs):
 # XXX limitation is that we can only have one type
+T = None
 for graph in graphs:
 for block in graph.iterblocks():
 for op in block.operations:
+if op.opname == 'jit_record_vref':
+new_T = op.args[0].concretetype
+if T is None:
+T = new_T
+else:
+assert T == new_T, "Different vref types %s and 
%s" % (T, new_T)
+self._vref_T = T
 
 def replace_force_virtual_with_call(self, graphs):
 # similar to rvirtualizable2.replace_force_virtualizable_with_call().
@@ -48,7 +56,7 @@
 c_is_virtual_ptr = None
 c_getfield_ptrs = {} # fieldname -> function
 force_virtual_count = 0
-self._find_type_of_virtualref()
+self._find_type_of_virtualref(graphs)
 for graph in graphs:
 for block in graph.iterblocks():
 for op in block.operations:
@@ -158,9 +166,19 @@
 def get_vref_getfield_fnptr(self, name, RES_TP):
 def read_virtual_field(inst):
 if inst.typeptr != self.jit_virtual_ref_vtable:
-lltype.cast_ptr(
-xxx
-xxx
+inst = lltype.cast_pointer(self._vref_T, inst)
+return getattr(inst, 'inst_' + name)
+vref = lltype.cast_pointer(lltype.Ptr(self.JIT_VIRTUAL_REF), inst)
+token = vref.virtual_token
+if token == self.TOKEN_TRACING_RESCALL or token == self.TOKEN_NONE:
+# not a virtual at all, just pretending to be one
+forced = lltype.cast_pointer(self._vref_T, vref.forced)
+return getattr(forced, 'inst_' + name)
+else: 
+assert not vref.forced
+from pypy.jit.metainterp.compile import read_field_from_resume
+return read_field_from_resume(self.cpu, token, name)
+
 FUNC = lltype.FuncType([rclass.OBJECTPTR], RES_TP)
 funcptr = self.warmrunnerdesc.helper_func(
 lltype.Ptr(FUNC),
diff --git a/pypy/rpython/lltypesystem/opimpl.py 
b/pypy/rpython/lltypesystem/opimpl.py
--- a/pypy/rpython/lltypesystem/opimpl.py
+++ b/pypy/rpython/lltypesystem/opimpl.py
@@ -570,6 +570,9 @@
 def op_jit_record_known_class(x, y):
 pass
 
+def op_jit_record_vref(x):
+pass
+
 def op_get_group_member(TYPE, grpp

[pypy-commit] pypy ppc-jit-backend: Import LR_BC_OFFSET and use it for MINIFRAME_SIZE LR offset.

2012-08-22 Thread edelsohn
Author: edelsohn
Branch: ppc-jit-backend
Changeset: r56814:1a335bc6665e
Date: 2012-08-22 20:54 -0400
http://bitbucket.org/pypy/pypy/changeset/1a335bc6665e/

Log:Import LR_BC_OFFSET and use it for MINIFRAME_SIZE LR offset. In
_build_stack_check_slowpath, allocate MAX_REG_PARAMS area and
allocate separate save area for PARAM_REGS.

diff --git a/pypy/jit/backend/ppc/ppc_assembler.py 
b/pypy/jit/backend/ppc/ppc_assembler.py
--- a/pypy/jit/backend/ppc/ppc_assembler.py
+++ b/pypy/jit/backend/ppc/ppc_assembler.py
@@ -9,7 +9,7 @@
   FPR_SAVE_AREA, 
NONVOLATILES_FLOAT,
   FLOAT_INT_CONVERSION, 
FORCE_INDEX,
   SIZE_LOAD_IMM_PATCH_SP,
-  FORCE_INDEX_OFS)
+  FORCE_INDEX_OFS, LR_BC_OFFSET)
 from pypy.jit.backend.ppc.helper.assembler import Saved_Volatiles
 from pypy.jit.backend.ppc.helper.regalloc import _check_imm_arg
 import pypy.jit.backend.ppc.register as r
@@ -417,9 +417,12 @@
 mc = PPCBuilder()
 
 # make small frame to store data (parameter regs + LR + SCRATCH) in
-# there
-SAVE_AREA = len(r.PARAM_REGS)
-frame_size = (BACKCHAIN_SIZE + SAVE_AREA) * WORD
+# there.  Allocate additional fixed save area for PPC64.
+PARAM_AREA = len(r.PARAM_REGS)
+FIXED_AREA = BACKCHAIN_SIZE
+if IS_PPC_64:
+FIXED_AREA += MAX_REG_PARAMS
+frame_size = (FIXED_AREA + PARAM_AREA) * WORD
 
 # align the SP
 MINIFRAME_SIZE = BACKCHAIN_SIZE * WORD
@@ -436,7 +439,7 @@
 
 # save parameter registers
 for i, reg in enumerate(r.PARAM_REGS):
-mc.store(reg.value, r.SP.value, (i + BACKCHAIN_SIZE) * WORD)
+mc.store(reg.value, r.SP.value, (i + FIXED_AREA) * WORD)
 
 # use SP as single parameter for the call
 mc.mr(r.r3.value, r.SP.value)
@@ -444,9 +447,6 @@
 # stack still aligned
 mc.call(slowpathaddr)
 
-XXX ^^^ the above call clobbers at least 48(r1), which
-XXX contains the mc.store(r3.value)
-
 with scratch_reg(mc):
 mc.load_imm(r.SCRATCH, self.cpu.pos_exception())
 mc.loadx(r.SCRATCH.value, 0, r.SCRATCH.value)
@@ -459,7 +459,7 @@
 
 # restore parameter registers
 for i, reg in enumerate(r.PARAM_REGS):
-mc.load(reg.value, r.SP.value, (i + BACKCHAIN_SIZE) * WORD)
+mc.load(reg.value, r.SP.value, (i + FIXED_AREA) * WORD)
 
 # restore LR
 mc.restore_LR_from_caller_frame(frame_size)
@@ -484,9 +484,7 @@
 # are interrupting the function.
 
 # restore link register out of preprevious frame
-offset_LR = frame_size + MINIFRAME_SIZE + WORD
-if IS_PPC_64:
-offset_LR += WORD
+offset_LR = frame_size + MINIFRAME_SIZE + LR_BC_OFFSET
 
 with scratch_reg(mc):
 mc.load(r.SCRATCH.value, r.SP.value, offset_LR)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy improve-rbigint: Revert changes to rshift, and change a test so it fails, and fix it. All tests should now pass

2012-08-22 Thread Stian Andreassen
Author: Stian Andreassen
Branch: improve-rbigint
Changeset: r56815:31d713444087
Date: 2012-08-23 06:15 +0200
http://bitbucket.org/pypy/pypy/changeset/31d713444087/

Log:Revert changes to rshift, and change a test so it fails, and fix it.
All tests should now pass

diff --git a/pypy/rlib/rbigint.py b/pypy/rlib/rbigint.py
--- a/pypy/rlib/rbigint.py
+++ b/pypy/rlib/rbigint.py
@@ -21,7 +21,6 @@
 #SHIFT = (LONG_BIT // 2) - 1
 if SUPPORT_INT128:
 SHIFT = 63
-BASE = long(1 << SHIFT)
 UDIGIT_TYPE = r_ulonglong
 if LONG_BIT >= 64:
 UDIGIT_MASK = intmask
@@ -36,14 +35,13 @@
 UNSIGNED_TYPE = rffi.ULONGLONG
 else:
 SHIFT = 31
-BASE = int(1 << SHIFT)
 UDIGIT_TYPE = r_uint
 UDIGIT_MASK = intmask
 STORE_TYPE = lltype.Signed
 UNSIGNED_TYPE = lltype.Unsigned
 LONG_TYPE = rffi.LONGLONG
 
-MASK = BASE - 1
+MASK = int((1 << SHIFT) - 1)
 FLOAT_MULTIPLIER = float(1 << SHIFT)
 
 # Debugging digit array access.
@@ -762,27 +760,24 @@
 elif int_other == 0:
 return self
 if self.sign == -1 and not dont_invert:
-a1 = self.invert()
-a2 = a1.rshift(int_other)
-return a2.invert()
+a = self.invert().rshift(int_other)
+return a.invert()
 
-wordshift = int_other // SHIFT
+wordshift = int_other / SHIFT
 newsize = self.numdigits() - wordshift
 if newsize <= 0:
 return NULLRBIGINT
 
 loshift = int_other % SHIFT
 hishift = SHIFT - loshift
-# Not 100% sure here, but the reason why it won't be a problem is 
because
-# int is max 63bit, same as our SHIFT now.
-#lomask = UDIGIT_MASK((UDIGIT_TYPE(1) << hishift) - 1)
-#himask = MASK ^ lomask
+lomask = (1 << hishift) - 1
+himask = MASK ^ lomask
 z = rbigint([NULLDIGIT] * newsize, self.sign, newsize)
 i = 0
 while i < newsize:
-newdigit = (self.udigit(wordshift) >> loshift) #& lomask
+newdigit = (self.digit(wordshift) >> loshift) & lomask
 if i+1 < newsize:
-newdigit += (self.udigit(wordshift+1) << hishift) #& himask
+newdigit |= (self.digit(wordshift+1) << hishift) & himask
 z.setdigit(i, newdigit)
 i += 1
 wordshift += 1
@@ -1408,7 +1403,6 @@
 if not size:
 size = pin.numdigits()
 size -= 1
-
 while size >= 0:
 rem = (rem << SHIFT) | pin.widedigit(size)
 hi = rem // n
@@ -1438,7 +1432,7 @@
 x[m-1], and the remaining carry (0 or 1) is returned.
 Python adaptation: x is addressed relative to xofs!
 """
-carry = r_uint(0)
+carry = UDIGIT_TYPE(0)
 
 assert m >= n
 i = _load_unsigned_digit(xofs)
@@ -1463,7 +1457,7 @@
 far as x[m-1], and the remaining borrow (0 or 1) is returned.
 Python adaptation: x is addressed relative to xofs!
 """
-borrow = r_uint(0)
+borrow = UDIGIT_TYPE(0)
 
 assert m >= n
 i = _load_unsigned_digit(xofs)
@@ -1559,13 +1553,17 @@
 """ Now v->ob_digit[size_v-1] < w->ob_digit[size_w-1], so quotient has
 at most (and usually exactly) k = size_v - size_w digits. """
 k = size_v - size_w
+if k == 0:
+return NULLRBIGINT, v1
+
 assert k > 0
 a = rbigint([NULLDIGIT] * k, 1, k)
 
-wm1 = w.digit(abs(size_w-1))
+wm1 = w.widedigit(abs(size_w-1))
 wm2 = w.widedigit(abs(size_w-2))
 
-j = size_v
+j = size_v - 1
+k -= 1
 while k >= 0:
 assert j >= 0
 """ inner loop: divide vk[0:size_w+1] by w0[0:size_w], giving
@@ -1575,17 +1573,15 @@
 if j >= size_v:
 vtop = 0
 else:
-vtop = v.digit(j)
+vtop = v.widedigit(j)
 assert vtop <= wm1
 vv = (vtop << SHIFT) | v.widedigit(abs(j-1))
-q = UDIGIT_MASK(vv / wm1)
+q = vv / wm1
 r = vv - wm1 * q
 while wm2 * q > ((r << SHIFT) | v.widedigit(abs(j-2))):
 q -= 1
 r += wm1
-if r > MASK:
-break
-
+
 assert q < MASK
 
 # subtract q*w0[0:size_w] from vk[0:size_w+1]
@@ -1609,9 +1605,10 @@
 q -= 1
 
 # store quotient digit
+a.setdigit(k, q)
 k -= 1
 j -= 1
-a.setdigit(k, q)
+
 
 carry = _v_rshift(w, v, size_w, d)
 assert carry == 0
diff --git a/pypy/rlib/test/test_rbigint.py b/pypy/rlib/test/test_rbigint.py
--- a/pypy/rlib/test/test_rbigint.py
+++ b/pypy/rlib/test/test_rbigint.py
@@ -547,7 +547,7 @@
 Rx = 1 << 130
 Rx2 = 1 << 150
 Ry = 1 << 127
-Ry2 = 1<< 130
+Ry2 = 1<< 150
 for i in range(10):
 x = long(randint(Rx, Rx2))
 y = long(randint(Ry, Ry2))
___
pypy-commit mailing list
pypy-commit@python.org
h