[pypy-commit] pypy default: Fix PyNumber_Check() to:

2016-07-29 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r85901:76db6bbbc6f6
Date: 2016-07-29 10:29 +0200
http://bitbucket.org/pypy/pypy/changeset/76db6bbbc6f6/

Log:Fix PyNumber_Check() to:

- match the behavior of CPython (it returns true for complex
numbers, for example)

- hopefully fix a numpy bug, which might be caused by
PyNumber_Check() causing unexpectedly more C calls, via
space.float_w()

diff --git a/pypy/module/cpyext/number.py b/pypy/module/cpyext/number.py
--- a/pypy/module/cpyext/number.py
+++ b/pypy/module/cpyext/number.py
@@ -20,16 +20,12 @@
 def PyNumber_Check(space, w_obj):
 """Returns 1 if the object o provides numeric protocols, and false 
otherwise.
 This function always succeeds."""
-try:
-space.float_w(w_obj)
+# According to CPython, this means: w_obj is not None, and
+# the type of w_obj has got a method __int__ or __float__.
+if w_obj is None:
+return 0
+if space.lookup(w_obj, '__int__') or space.lookup(w_obj, '__float__'):
 return 1
-except OperationError:
-pass
-try:
-space.int_w(w_obj)
-return 1
-except OperationError:
-pass
 return 0
 
 @cpython_api([PyObject, PyObject], Py_ssize_t, error=-1)
diff --git a/pypy/module/cpyext/test/test_number.py 
b/pypy/module/cpyext/test/test_number.py
--- a/pypy/module/cpyext/test/test_number.py
+++ b/pypy/module/cpyext/test/test_number.py
@@ -15,7 +15,7 @@
 assert api.PyNumber_Check(space.wraplong(-12L))
 assert api.PyNumber_Check(space.wrap(12.1))
 assert not api.PyNumber_Check(space.wrap('12'))
-assert not api.PyNumber_Check(space.wrap(1+3j))
+assert api.PyNumber_Check(space.wrap(1+3j))
 
 def test_number_long(self, space, api):
 w_l = api.PyNumber_Long(space.wrap(123))
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy stmgc-c8: make the previous test correct (use monkeypatch)

2016-07-29 Thread Raemi
Author: Remi Meier 
Branch: stmgc-c8
Changeset: r85902:ab0a5dbd55a0
Date: 2016-07-29 14:37 +0200
http://bitbucket.org/pypy/pypy/changeset/ab0a5dbd55a0/

Log:make the previous test correct (use monkeypatch)

diff --git a/pypy/module/pypystm/test/test_local.py 
b/pypy/module/pypystm/test/test_local.py
--- a/pypy/module/pypystm/test/test_local.py
+++ b/pypy/module/pypystm/test/test_local.py
@@ -13,7 +13,7 @@
 """)
 
 
-def test_direct_call_to_become_inevitable():
+def test_direct_call_to_become_inevitable(monkeypatch):
 # this test directly checks if we call rstm.become_inevitable() in the
 # right places (before modifying the real threadlocal). Could possibly be
 # tested in a better way...
@@ -33,8 +33,8 @@
 call_counter = [0]
 def fake_become_inevitable():
 call_counter[0] += 1
-rstm.become_inevitable = fake_become_inevitable
 
+monkeypatch.setattr(rstm, 'become_inevitable', fake_become_inevitable)
 space = FakeSpace()
 
 l = STMThreadLocals(space)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Hash: turn -1 into -2 without using a condition, to avoid

2016-07-29 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r85903:ac03886bcddb
Date: 2016-07-29 14:52 +0200
http://bitbucket.org/pypy/pypy/changeset/ac03886bcddb/

Log:Hash: turn -1 into -2 without using a condition, to avoid creating a
bridge in the JIT

diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py
--- a/pypy/objspace/descroperation.py
+++ b/pypy/objspace/descroperation.py
@@ -424,29 +424,20 @@
 raise oefmt(space.w_TypeError,
 "'%T' objects are unhashable", w_obj)
 w_result = space.get_and_call_function(w_hash, w_obj)
-w_resulttype = space.type(w_result)
 
 # issue 2346 : returns now -2 for hashing -1 like cpython
-if space.is_w(w_resulttype, space.w_int):
-if space.int_w(w_result) == -1:
-return space.wrap(-2)
-return w_result
-elif space.isinstance_w(w_result, space.w_int):
-# be careful about subclasses of 'int'...
-int_result = space.int_w(w_result)
-if int_result == -1:
-int_result == -2
-return space.wrap(int_result)
+if space.isinstance_w(w_result, space.w_int):
+h = space.int_w(w_result)
 elif space.isinstance_w(w_result, space.w_long):
-# be careful about subclasses of 'long'...
 bigint = space.bigint_w(w_result)
 h = bigint.hash()
-if h == -1:
-h = -2
-return space.wrap(h)
 else:
 raise oefmt(space.w_TypeError,
 "__hash__() should return an int or long")
+# turn -1 into -2 without using a condition, which would
+# create a potential bridge in the JIT
+h -= (h == -1)
+return space.wrap(h)
 
 def cmp(space, w_v, w_w):
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5-async: add __await__ method to Coroutine typedef and redirect it to descr__await__

2016-07-29 Thread plan_rich
Author: Richard Plangger 
Branch: py3.5-async
Changeset: r85904:000728f0465a
Date: 2016-07-29 15:31 +0200
http://bitbucket.org/pypy/pypy/changeset/000728f0465a/

Log:add __await__ method to Coroutine typedef and redirect it to
descr__await__

diff --git a/pypy/interpreter/generator.py b/pypy/interpreter/generator.py
--- a/pypy/interpreter/generator.py
+++ b/pypy/interpreter/generator.py
@@ -319,6 +319,12 @@
 self.running = False
 if self.pycode.co_flags & CO_YIELD_INSIDE_TRY:
 self.register_finalizer(self.space)
+
+def descr__await__(self, space):
+# implement this function:
+# https://github.com/python/cpython/blob/3.5/Objects/genobject.c#L786
+# you need a new CoroutineWrapper object + CoroutineWrapperType
+pass
 
 def descr__reduce__(self, space):
 from pypy.interpreter.mixedmodule import MixedModule
diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py
--- a/pypy/interpreter/typedef.py
+++ b/pypy/interpreter/typedef.py
@@ -811,6 +811,8 @@
 descrmismatch='close'),
 __iter__   = interp2app(Coroutine.descr__iter__,
 descrmismatch='__iter__'),
+__await__  = interp2app(Coroutine.descr__await__,
+descrmismatch='__await__'),
 gi_running = interp_attrproperty('running', cls=Coroutine),
 gi_frame   = GetSetProperty(Coroutine.descr_gi_frame),
 gi_code= GetSetProperty(Coroutine.descr_gi_code),
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: fix Makefile clean, non-optimization for win32

2016-07-29 Thread mattip
Author: mattip 
Branch: 
Changeset: r85905:a34bf4f9993a
Date: 2016-07-29 12:25 -0500
http://bitbucket.org/pypy/pypy/changeset/a34bf4f9993a/

Log:fix Makefile clean, non-optimization for win32

diff --git a/rpython/translator/c/genc.py b/rpython/translator/c/genc.py
--- a/rpython/translator/c/genc.py
+++ b/rpython/translator/c/genc.py
@@ -422,14 +422,11 @@
 mk.definition('PROFOPT', profopt)
 
 rules = [
-('clean', '', 'rm -f $(OBJECTS) $(DEFAULT_TARGET) $(TARGET) 
$(GCMAPFILES) $(ASMFILES) *.gc?? ../module_cache/*.gc??'),
-('clean_noprof', '', 'rm -f $(OBJECTS) $(DEFAULT_TARGET) $(TARGET) 
$(GCMAPFILES) $(ASMFILES)'),
 ('debug', '', '$(MAKE) CFLAGS="$(DEBUGFLAGS) -DRPY_ASSERT" 
debug_target'),
 ('debug_exc', '', '$(MAKE) CFLAGS="$(DEBUGFLAGS) -DRPY_ASSERT 
-DDO_LOG_EXC" debug_target'),
 ('debug_mem', '', '$(MAKE) CFLAGS="$(DEBUGFLAGS) -DRPY_ASSERT 
-DPYPY_USE_TRIVIAL_MALLOC" debug_target'),
 ('llsafer', '', '$(MAKE) CFLAGS="-O2 -DRPY_LL_ASSERT" 
$(DEFAULT_TARGET)'),
 ('lldebug', '', '$(MAKE) CFLAGS="$(DEBUGFLAGS) -DRPY_ASSERT 
-DRPY_LL_ASSERT" debug_target'),
-('lldebug0','', '$(MAKE) CFLAGS="$(DEBUGFLAGS) -O0 
-DMAX_STACK_SIZE=8192000 -DRPY_ASSERT -DRPY_LL_ASSERT" debug_target'),
 ('profile', '', '$(MAKE) CFLAGS="-g -O1 -pg $(CFLAGS) 
-fno-omit-frame-pointer" LDFLAGS="-pg $(LDFLAGS)" $(DEFAULT_TARGET)'),
 ]
 if self.has_profopt():
@@ -443,6 +440,17 @@
 for rule in rules:
 mk.rule(*rule)
 
+if self.translator.platform.name == 'msvc':
+mk.rule('lldebug0','', '$(MAKE) CFLAGS="$(DEBUGFLAGS) -Od 
-DMAX_STACK_SIZE=8192000 -DRPY_ASSERT -DRPY_LL_ASSERT" debug_target'),
+wildcards = '..\*.obj ..\*.pdb ..\*.lib ..\*.dll ..\*.manifest 
..\*.exp *.pch'
+cmd =  r'del /s %s $(DEFAULT_TARGET) $(TARGET) $(GCMAPFILES) 
$(ASMFILES)' % wildcards
+mk.rule('clean', '',  cmd + ' *.gc?? ..\module_cache\*.gc??')
+mk.rule('clean_noprof', '', cmd)
+else:
+mk.rule('lldebug0','', '$(MAKE) CFLAGS="$(DEBUGFLAGS) -O0 
-DMAX_STACK_SIZE=8192000 -DRPY_ASSERT -DRPY_LL_ASSERT" debug_target'),
+mk.rule('clean', '', 'rm -f $(OBJECTS) $(DEFAULT_TARGET) $(TARGET) 
$(GCMAPFILES) $(ASMFILES) *.gc?? ../module_cache/*.gc??')
+mk.rule('clean_noprof', '', 'rm -f $(OBJECTS) $(DEFAULT_TARGET) 
$(TARGET) $(GCMAPFILES) $(ASMFILES)')
+
 #XXX: this conditional part is not tested at all
 if self.config.translation.gcrootfinder == 'asmgcc':
 if self.translator.platform.name == 'msvc':
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: remove define, mistakenly taken from python3

2016-07-29 Thread mattip
Author: mattip 
Branch: 
Changeset: r85907:f623f9884a8f
Date: 2016-07-29 09:05 -0500
http://bitbucket.org/pypy/pypy/changeset/f623f9884a8f/

Log:remove define, mistakenly taken from python3

diff --git a/pypy/module/cpyext/include/pyport.h 
b/pypy/module/cpyext/include/pyport.h
--- a/pypy/module/cpyext/include/pyport.h
+++ b/pypy/module/cpyext/include/pyport.h
@@ -64,13 +64,6 @@
 #   error "Python needs a typedef for Py_uintptr_t in pyport.h."
 #endif /* HAVE_UINTPTR_T */
 
-/* Py_hash_t is the same size as a pointer. */
-#define SIZEOF_PY_HASH_T SIZEOF_SIZE_T
-typedef Py_ssize_t Py_hash_t;
-/* Py_uhash_t is the unsigned equivalent needed to calculate numeric hash. */
-#define SIZEOF_PY_UHASH_T SIZEOF_SIZE_T
-typedef size_t Py_uhash_t;
-
 
 /***
  * stat() and fstat() fiddling *
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: add target for msvc

2016-07-29 Thread mattip
Author: mattip 
Branch: 
Changeset: r85906:fec320c6a9dd
Date: 2016-07-29 05:56 -0500
http://bitbucket.org/pypy/pypy/changeset/fec320c6a9dd/

Log:add target for msvc

diff --git a/rpython/translator/c/genc.py b/rpython/translator/c/genc.py
--- a/rpython/translator/c/genc.py
+++ b/rpython/translator/c/genc.py
@@ -515,7 +515,7 @@
 else:
 mk.definition('DEBUGFLAGS', '-O1 -g')
 if self.translator.platform.name == 'msvc':
-mk.rule('debug_target', '$(DEFAULT_TARGET)', 'rem')
+mk.rule('debug_target', '$(DEFAULT_TARGET) $(WTARGET)', 'rem')
 else:
 mk.rule('debug_target', '$(DEFAULT_TARGET)', '#')
 mk.write()
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: test, fix for missing nb_* slot, what else is missing?

2016-07-29 Thread mattip
Author: mattip 
Branch: 
Changeset: r85908:d67646a1ac41
Date: 2016-07-29 10:10 -0500
http://bitbucket.org/pypy/pypy/changeset/d67646a1ac41/

Log:test, fix for missing nb_* slot, what else is missing?

diff --git a/pypy/module/cpyext/slotdefs.py b/pypy/module/cpyext/slotdefs.py
--- a/pypy/module/cpyext/slotdefs.py
+++ b/pypy/module/cpyext/slotdefs.py
@@ -381,6 +381,7 @@
   ('tp_as_number.c_nb_invert', '__invert__'),
   ('tp_as_number.c_nb_index', '__index__'),
   ('tp_as_number.c_nb_hex', '__hex__'),
+  ('tp_as_number.c_nb_oct', '__oct__'),
   ('tp_str', '__str__'),
   ('tp_repr', '__repr__'),
   ('tp_iter', '__iter__'),
diff --git a/pypy/module/cpyext/test/test_longobject.py 
b/pypy/module/cpyext/test/test_longobject.py
--- a/pypy/module/cpyext/test/test_longobject.py
+++ b/pypy/module/cpyext/test/test_longobject.py
@@ -259,8 +259,19 @@
 ret = PyLong_FromLong(-1);
 Py_DECREF(obj);
 return ret;
+ """),
+("has_oct", "METH_NOARGS",
+ """
+PyObject *ret, *obj = PyLong_FromLong(42);
+if (obj->ob_type->tp_as_number->nb_oct)
+ret = obj->ob_type->tp_as_number->nb_oct(obj);
+else
+ret = PyLong_FromLong(-1);
+Py_DECREF(obj);
+return ret;
  """)])
 assert module.has_sub() == 0
 assert module.has_pow() == 0
 assert module.has_hex() == '0x2aL'
+assert module.has_oct() == '052L'
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: On Python3, errors raised when trying to access obj.__class__ are propagated

2016-07-29 Thread rlamy
Author: Ronan Lamy 
Branch: py3k
Changeset: r85909:190116421221
Date: 2016-07-29 16:23 +0100
http://bitbucket.org/pypy/pypy/changeset/190116421221/

Log:On Python3, errors raised when trying to access obj.__class__ are
propagated

diff --git a/pypy/module/__builtin__/abstractinst.py 
b/pypy/module/__builtin__/abstractinst.py
--- a/pypy/module/__builtin__/abstractinst.py
+++ b/pypy/module/__builtin__/abstractinst.py
@@ -57,8 +57,8 @@
 try:
 w_abstractclass = space.getattr(w_inst, space.wrap('__class__'))
 except OperationError as e:
-if e.async(space):  # ignore most exceptions
-raise
+if not e.match(space, space.w_AttributeError):
+raise   # propagate other errors
 return False
 else:
 return p_abstract_issubclass_w(space, w_abstractclass, w_cls)
@@ -72,8 +72,8 @@
 try:
 w_abstractclass = space.getattr(w_inst, space.wrap('__class__'))
 except OperationError as e:
-if e.async(space):  # ignore most exceptions
-raise
+if not e.match(space, space.w_AttributeError):
+raise   # propagate other errors
 else:
 if w_abstractclass is not space.type(w_inst):
 if space.isinstance_w(w_abstractclass, space.w_type):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: fix tests for py3k (old-style classes)

2016-07-29 Thread rlamy
Author: Ronan Lamy 
Branch: py3k
Changeset: r85910:c2c54266b66d
Date: 2016-07-29 16:51 +0100
http://bitbucket.org/pypy/pypy/changeset/c2c54266b66d/

Log:fix tests for py3k (old-style classes)

diff --git a/pypy/objspace/std/test/test_typeobject.py 
b/pypy/objspace/std/test/test_typeobject.py
--- a/pypy/objspace/std/test/test_typeobject.py
+++ b/pypy/objspace/std/test/test_typeobject.py
@@ -675,7 +675,7 @@
 assert repr(A) == ".A'>"
 A.__module__ = 123
 assert repr(A) == ""
-assert repr(type(type)) == "" 
+assert repr(type(type)) == ""
 assert repr(complex) == ""
 assert repr(property) == ""
 assert repr(TypeError) == ""
@@ -1204,9 +1204,6 @@
 def test_instancecheck(self):
 assert int.__instancecheck__(42) is True
 assert int.__instancecheck__(42.0) is False
-class Foo:
-__class__ = int
-assert int.__instancecheck__(Foo()) is False
 class Bar(object):
 __class__ = int
 assert int.__instancecheck__(Bar()) is True
@@ -1214,9 +1211,6 @@
 def test_subclasscheck(self):
 assert int.__subclasscheck__(bool) is True
 assert int.__subclasscheck__(float) is False
-class Foo:
-__class__ = int
-assert int.__subclasscheck__(Foo) is False
 class Bar(object):
 __class__ = int
 assert int.__subclasscheck__(Bar) is False
@@ -1297,7 +1291,7 @@
 
 assert w_A.w_new_function is None
 assert w_B.w_new_function is None
-assert w_M.w_new_function is None
+assert w_M.w_new_function is None
 
 _, w_object_newdescr = space.lookup_in_type_where(space.w_object,
   '__new__')
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy.org extradoc: Merged in av6/pypy.org (pull request #11)

2016-07-29 Thread rlamy
Author: Ronan Lamy 
Branch: extradoc
Changeset: r772:d9498bbc88bc
Date: 2016-07-29 17:00 +0100
http://bitbucket.org/pypy/pypy.org/changeset/d9498bbc88bc/

Log:Merged in av6/pypy.org (pull request #11)

download: update link to Mercurial

diff --git a/download.html b/download.html
--- a/download.html
+++ b/download.html
@@ -240,7 +240,7 @@
 
 https://bitbucket.org/pypy/pypy/downloads/pypy2-v5.3.1-src.tar.bz2";>pypy2-v5.3.1-src.tar.bz2
 (sources)
 
-Or you can checkout the current trunk using http://mercurial.selenic.com/";>Mercurial (the trunk
+Or you can checkout the current trunk using https://www.mercurial-scm.org/";>Mercurial (the trunk
 usually works and is of course more up-to-date):
 
 hg clone https://bitbucket.org/pypy/pypy
diff --git a/source/download.txt b/source/download.txt
--- a/source/download.txt
+++ b/source/download.txt
@@ -376,7 +376,7 @@
 .. _`greenlets`: http://pypy.readthedocs.org/en/latest/stackless.html#greenlets
 .. _`Windows build instructions`: 
http://doc.pypy.org/en/latest/windows.html#preparing-windows-for-the-large-build
 .. _`shadow stack`: 
http://pypy.readthedocs.org/en/latest/config/translation.gcrootfinder.html
-.. _Mercurial: http://mercurial.selenic.com/
+.. _Mercurial: https://www.mercurial-scm.org/
 
 Packaging
 -
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy null_byte_after_str: Allocate all STRs (including prebuilt ones) with enough space for one

2016-07-29 Thread arigo
Author: Armin Rigo 
Branch: null_byte_after_str
Changeset: r85911:1abc2152f631
Date: 2016-07-29 18:06 +0200
http://bitbucket.org/pypy/pypy/changeset/1abc2152f631/

Log:Allocate all STRs (including prebuilt ones) with enough space for
one extra uninitialized character. Add
rgc.ll_write_final_null_char() to write a NULL character there.

diff --git a/rpython/rlib/rgc.py b/rpython/rlib/rgc.py
--- a/rpython/rlib/rgc.py
+++ b/rpython/rlib/rgc.py
@@ -1268,3 +1268,23 @@
 ptr = lltype.direct_arrayitems(array)
 # ptr is a Ptr(FixedSizeArray(Char, 1)).  Cast it to a rffi.CCHARP
 return rffi.cast(rffi.CCHARP, ptr)
+
+@jit.dont_look_inside
+@no_collect
+@specialize.ll()
+def ll_write_final_null_char(s):
+"""'s' is a low-level STR; writes a NULL character after all the
+other characters in 's'.  Warning, this only works because of
+the 'extra_item_after_alloc' hack inside the definition of STR.
+"""
+PSTR = lltype.typeOf(s)
+_check_final_null_char(PSTR)
+# no GC operation here!
+adr_s = llmemory.cast_ptr_to_adr(s)
+adr_a = adr_s + llmemory.offsetof(PSTR.TO, 'chars')
+adr_a += llmemory.itemoffsetof(PSTR.TO.chars, 0)
+adr_a.char[len(s.chars)] = '\x00'
+
+@specialize.memo()
+def _check_final_null_char(PSTR):
+assert PSTR.TO.chars._hints.get('extra_item_after_alloc', 0) == 1
diff --git a/rpython/rtyper/lltypesystem/llmemory.py 
b/rpython/rtyper/lltypesystem/llmemory.py
--- a/rpython/rtyper/lltypesystem/llmemory.py
+++ b/rpython/rtyper/lltypesystem/llmemory.py
@@ -390,11 +390,23 @@
 else:
 raise Exception("don't know how to take the size of a %r"%TYPE)
 
+@specialize.memo()
+def extra_item_after_alloc(ARRAY):
+assert isinstance(ARRAY, lltype.Array)
+return ARRAY._hints.get('extra_item_after_alloc', 0)
+
 @specialize.arg(0)
 def sizeof(TYPE, n=None):
+"""Return the symbolic size of TYPE.
+For a Struct with no varsized part, it must be called with n=None.
+For an Array or a Struct with a varsized part, it is the number of items.
+There is a special case to return 1 more than requested if the array
+has the hint 'extra_item_after_alloc' set to 1.
+"""
 if n is None:
 return _sizeof_none(TYPE)
 elif isinstance(TYPE, lltype.Array):
+n += extra_item_after_alloc(TYPE)
 return itemoffsetof(TYPE) + _sizeof_none(TYPE.OF) * n
 else:
 return _sizeof_int(TYPE, n)
diff --git a/rpython/rtyper/lltypesystem/rstr.py 
b/rpython/rtyper/lltypesystem/rstr.py
--- a/rpython/rtyper/lltypesystem/rstr.py
+++ b/rpython/rtyper/lltypesystem/rstr.py
@@ -1238,7 +1238,8 @@
 # 
 
 STR.become(GcStruct('rpy_string', ('hash',  Signed),
-('chars', Array(Char, hints={'immutable': True})),
+('chars', Array(Char, hints={'immutable': True,
+'extra_item_after_alloc': 1})),
 adtmeths={'malloc' : staticAdtMethod(mallocstr),
   'empty'  : staticAdtMethod(emptystrfun),
   'copy_contents' : 
staticAdtMethod(copy_string_contents),
diff --git a/rpython/translator/c/node.py b/rpython/translator/c/node.py
--- a/rpython/translator/c/node.py
+++ b/rpython/translator/c/node.py
@@ -253,8 +253,11 @@
 yield '\t' + cdecl(typename, fname) + ';'
 if not self.ARRAY._hints.get('nolength', False):
 yield '\tlong length;'
+varlength = self.varlength
+if varlength is not None:
+varlength += self.ARRAY._hints.get('extra_item_after_alloc', 0)
 line = '%s;' % cdecl(self.itemtypename,
- 'items[%s]' % deflength(self.varlength))
+ 'items[%s]' % deflength(varlength))
 if self.ARRAY.OF is Void:# strange
 line = '/* array of void */'
 if self.ARRAY._hints.get('nolength', False):
diff --git a/rpython/translator/c/test/test_lltyped.py 
b/rpython/translator/c/test/test_lltyped.py
--- a/rpython/translator/c/test/test_lltyped.py
+++ b/rpython/translator/c/test/test_lltyped.py
@@ -1,4 +1,4 @@
-import py
+import py, random
 from rpython.rtyper.lltypesystem.lltype import *
 from rpython.rtyper.lltypesystem import rffi
 from rpython.translator.c.test.test_genc import compile
@@ -255,28 +255,6 @@
 res2 = fn(0)
 assert res1 == res2
 
-def test_null_padding(self):
-py.test.skip("we no longer pad our RPython strings with a final NUL")
-from rpython.rtyper.lltypesystem import llmemory
-from rpython.rtyper.lltypesystem import rstr
-chars_offset = llmemory.FieldOffset(rstr.STR, 'chars') + \
-   llmemory.ArrayItemsOffset(rstr.STR.chars)
-# sadly, there's no way of forcing this to fail if the strings
-# are allocated in a region of memory such that they just
-# happen to get a NUL byte anywa

[pypy-commit] pypy null_byte_after_str: Test with the framework GCs, passing because gctypelayout already uses

2016-07-29 Thread arigo
Author: Armin Rigo 
Branch: null_byte_after_str
Changeset: r85912:8314165f314f
Date: 2016-07-29 18:11 +0200
http://bitbucket.org/pypy/pypy/changeset/8314165f314f/

Log:Test with the framework GCs, passing because gctypelayout already
uses the modified llmemory.sizeof()

diff --git a/rpython/translator/c/test/test_lltyped.py 
b/rpython/translator/c/test/test_lltyped.py
--- a/rpython/translator/c/test/test_lltyped.py
+++ b/rpython/translator/c/test/test_lltyped.py
@@ -1004,7 +1004,6 @@
 
 def test_extra_item_after_alloc(self):
 from rpython.rlib import rgc
-from rpython.rlib.objectmodel import compute_hash
 from rpython.rtyper.lltypesystem import lltype
 from rpython.rtyper.lltypesystem import rstr
 # all STR objects should be allocated with enough space for one
diff --git a/rpython/translator/c/test/test_newgc.py 
b/rpython/translator/c/test/test_newgc.py
--- a/rpython/translator/c/test/test_newgc.py
+++ b/rpython/translator/c/test/test_newgc.py
@@ -3,6 +3,7 @@
 import os
 import sys
 import subprocess
+import random
 
 import py
 
@@ -1468,6 +1469,52 @@
 res = self.run('nursery_hash_base')
 assert res >= 195
 
+def define_extra_item_after_alloc(cls):
+from rpython.rtyper.lltypesystem import rstr
+# all STR objects should be allocated with enough space for
+# one extra char.  Check this with our GCs.  Use strings of 8,
+# 16 and 24 chars because if the extra char is missing,
+# writing to it is likely to cause corruption in nearby
+# structures.
+sizes = [random.choice([8, 16, 24]) for i in range(100)]
+A = lltype.Struct('A', ('x', lltype.Signed))
+prebuilt = [(rstr.mallocstr(sz),
+ lltype.malloc(A, flavor='raw', immortal=True))
+for sz in sizes]
+k = 0
+for i, (s, a) in enumerate(prebuilt):
+a.x = i
+for i in range(len(s.chars)):
+k += 1
+if k == 256:
+k = 1
+s.chars[i] = chr(k)
+
+def check(lst):
+hashes = []
+for i, (s, a) in enumerate(lst):
+assert a.x == i
+rgc.ll_write_final_null_char(s)
+for i, (s, a) in enumerate(lst):
+assert a.x == i # check it was not overwritten
+def fn():
+check(prebuilt)
+lst1 = []
+for i, sz in enumerate(sizes):
+s = rstr.mallocstr(sz)
+a = lltype.malloc(A, flavor='raw')
+a.x = i
+lst1.append((s, a))
+check(lst1)
+for _, a in lst1:
+lltype.free(a, flavor='raw')
+return 42
+return fn
+
+def test_extra_item_after_alloc(self):
+res = self.run('extra_item_after_alloc')
+assert res == 42
+
 
 class TestGenerationalGC(TestSemiSpaceGC):
 gcpolicy = "generation"
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy.org extradoc: download: update link to Mercurial

2016-07-29 Thread av6
Author: Anton Shestakov 
Branch: extradoc
Changeset: r771:8beba15d6a47
Date: 2016-07-20 11:38 +0800
http://bitbucket.org/pypy/pypy.org/changeset/8beba15d6a47/

Log:download: update link to Mercurial

diff --git a/download.html b/download.html
--- a/download.html
+++ b/download.html
@@ -240,7 +240,7 @@
 
 https://bitbucket.org/pypy/pypy/downloads/pypy2-v5.3.1-src.tar.bz2";>pypy2-v5.3.1-src.tar.bz2
 (sources)
 
-Or you can checkout the current trunk using http://mercurial.selenic.com/";>Mercurial (the trunk
+Or you can checkout the current trunk using https://www.mercurial-scm.org/";>Mercurial (the trunk
 usually works and is of course more up-to-date):
 
 hg clone https://bitbucket.org/pypy/pypy
diff --git a/source/download.txt b/source/download.txt
--- a/source/download.txt
+++ b/source/download.txt
@@ -376,7 +376,7 @@
 .. _`greenlets`: http://pypy.readthedocs.org/en/latest/stackless.html#greenlets
 .. _`Windows build instructions`: 
http://doc.pypy.org/en/latest/windows.html#preparing-windows-for-the-large-build
 .. _`shadow stack`: 
http://pypy.readthedocs.org/en/latest/config/translation.gcrootfinder.html
-.. _Mercurial: http://mercurial.selenic.com/
+.. _Mercurial: https://www.mercurial-scm.org/
 
 Packaging
 -
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5-async: Add check in getAwaitableIter for Generator with ITERABLE_COROUTINE flag, fix parameters, switch order of Coroutine and Generator check in pyframe

2016-07-29 Thread raffael_t
Author: Raffael Tfirst 
Branch: py3.5-async
Changeset: r85913:0f9d6b6049cc
Date: 2016-07-29 18:49 +0200
http://bitbucket.org/pypy/pypy/changeset/0f9d6b6049cc/

Log:Add check in getAwaitableIter for Generator with ITERABLE_COROUTINE
flag, fix parameters, switch order of Coroutine and Generator check
in pyframe

diff --git a/pypy/interpreter/generator.py b/pypy/interpreter/generator.py
--- a/pypy/interpreter/generator.py
+++ b/pypy/interpreter/generator.py
@@ -2,6 +2,7 @@
 from pypy.interpreter.error import OperationError, oefmt
 from pypy.interpreter.pyopcode import LoopBlock
 from pypy.interpreter.pycode import CO_YIELD_INSIDE_TRY
+from pypy.interpreter.astcompiler import consts
 from rpython.rlib import jit
 
 
@@ -303,9 +304,13 @@
 break
 block = block.previous
 
-def _GetAwaitableIter(self, o):
+def _GetAwaitableIter(self, space):
+#check if coroutine
+if w_iterable.pycode.co_flags & consts.CO_ITERABLE_COROUTINE:
+return self
 #look at typeobject.c, change to self.space.lookup(w_manager, 
"__await__")
-return o
+res = self.descr__await__(space)
+return self
 
 
 class Coroutine(W_Root):
@@ -324,7 +329,7 @@
 # implement this function:
 # https://github.com/python/cpython/blob/3.5/Objects/genobject.c#L786
 # you need a new CoroutineWrapper object + CoroutineWrapperType
-pass
+return self
 
 def descr__reduce__(self, space):
 from pypy.interpreter.mixedmodule import MixedModule
@@ -577,8 +582,8 @@
 break
 block = block.previous
 
-def _GetAwaitableIter(self, o):
-return o
+def _GetAwaitableIter(self, space):
+return self
 
 
 
diff --git a/pypy/interpreter/pyframe.py b/pypy/interpreter/pyframe.py
--- a/pypy/interpreter/pyframe.py
+++ b/pypy/interpreter/pyframe.py
@@ -240,12 +240,12 @@
 
 def run(self):
 """Start this frame's execution."""
-if self.getcode().co_flags & pycode.CO_GENERATOR:
+if self.getcode().co_flags & pycode.CO_COROUTINE:
+from pypy.interpreter.generator import Coroutine
+return self.space.wrap(Coroutine(self))
+elif self.getcode().co_flags & pycode.CO_GENERATOR:
 from pypy.interpreter.generator import GeneratorIterator
 return self.space.wrap(GeneratorIterator(self))
-elif self.getcode().co_flags & pycode.CO_COROUTINE:
-from pypy.interpreter.generator import Coroutine
-return self.space.wrap(Coroutine(self))
 else:
 return self.execute_frame()
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy null_byte_after_str: Test, and fixes for tests

2016-07-29 Thread arigo
Author: Armin Rigo 
Branch: null_byte_after_str
Changeset: r85914:8c4847b9f717
Date: 2016-07-29 18:46 +0200
http://bitbucket.org/pypy/pypy/changeset/8c4847b9f717/

Log:Test, and fixes for tests

diff --git a/rpython/jit/backend/llsupport/test/ztranslation_test.py 
b/rpython/jit/backend/llsupport/test/ztranslation_test.py
--- a/rpython/jit/backend/llsupport/test/ztranslation_test.py
+++ b/rpython/jit/backend/llsupport/test/ztranslation_test.py
@@ -3,7 +3,7 @@
 from rpython.rlib.jit import JitDriver, unroll_parameters, set_param
 from rpython.rlib.jit import PARAMETERS, dont_look_inside
 from rpython.rlib.jit import promote, _get_virtualizable_token
-from rpython.rlib import jit_hooks, rposix
+from rpython.rlib import jit_hooks, rposix, rgc
 from rpython.rlib.objectmodel import keepalive_until_here
 from rpython.rlib.rthread import ThreadLocalReference, ThreadLocalField
 from rpython.jit.backend.detect_cpu import getcpuclass
@@ -11,7 +11,7 @@
 from rpython.jit.codewriter.policy import StopAtXPolicy
 from rpython.config.config import ConfigError
 from rpython.translator.tool.cbuild import ExternalCompilationInfo
-from rpython.rtyper.lltypesystem import lltype, rffi
+from rpython.rtyper.lltypesystem import lltype, rffi, rstr
 from rpython.rlib.rjitlog import rjitlog as jl
 
 
@@ -29,6 +29,7 @@
 # - floats neg and abs
 # - cast_int_to_float
 # - llexternal with macro=True
+# - extra place for the zero after STR instances
 
 class BasicFrame(object):
 _virtualizable_ = ['i']
@@ -56,7 +57,7 @@
 return ("/home.py",0,0)
 
 jitdriver = JitDriver(greens = [],
-  reds = ['total', 'frame', 'j'],
+  reds = ['total', 'frame', 'prev_s', 'j'],
   virtualizables = ['frame'],
   get_location = get_location)
 def f(i, j):
@@ -68,9 +69,12 @@
 total = 0
 frame = Frame(i)
 j = float(j)
+prev_s = rstr.mallocstr(16)
 while frame.i > 3:
-jitdriver.can_enter_jit(frame=frame, total=total, j=j)
-jitdriver.jit_merge_point(frame=frame, total=total, j=j)
+jitdriver.can_enter_jit(frame=frame, total=total, j=j,
+prev_s=prev_s)
+jitdriver.jit_merge_point(frame=frame, total=total, j=j,
+  prev_s=prev_s)
 _get_virtualizable_token(frame)
 total += frame.i
 if frame.i >= 20:
@@ -82,6 +86,11 @@
 k = myabs1(myabs2(j))
 if k - abs(j):  raise ValueError
 if k - abs(-j): raise ValueError
+s = rstr.mallocstr(16)
+rgc.ll_write_final_null_char(s)
+rgc.ll_write_final_null_char(prev_s)
+if (frame.i & 3) == 0:
+prev_s = s
 return chr(total % 253)
 #
 class Virt2(object):
diff --git a/rpython/rlib/rgc.py b/rpython/rlib/rgc.py
--- a/rpython/rlib/rgc.py
+++ b/rpython/rlib/rgc.py
@@ -1273,17 +1273,20 @@
 @no_collect
 @specialize.ll()
 def ll_write_final_null_char(s):
-"""'s' is a low-level STR; writes a NULL character after all the
-other characters in 's'.  Warning, this only works because of
+"""'s' is a low-level STR; writes a terminating NULL character after
+the other characters in 's'.  Warning, this only works because of
 the 'extra_item_after_alloc' hack inside the definition of STR.
 """
+from rpython.rtyper.lltypesystem import rffi
 PSTR = lltype.typeOf(s)
 _check_final_null_char(PSTR)
-# no GC operation here!
-adr_s = llmemory.cast_ptr_to_adr(s)
-adr_a = adr_s + llmemory.offsetof(PSTR.TO, 'chars')
-adr_a += llmemory.itemoffsetof(PSTR.TO.chars, 0)
-adr_a.char[len(s.chars)] = '\x00'
+n = llmemory.offsetof(PSTR.TO, 'chars')
+n += llmemory.itemoffsetof(PSTR.TO.chars, 0)
+n = llmemory.raw_malloc_usage(n)
+n += len(s.chars)
+# no GC operation from here!
+ptr = rffi.cast(rffi.CCHARP, s)
+ptr[n] = '\x00'
 
 @specialize.memo()
 def _check_final_null_char(PSTR):
diff --git a/rpython/rtyper/lltypesystem/ll2ctypes.py 
b/rpython/rtyper/lltypesystem/ll2ctypes.py
--- a/rpython/rtyper/lltypesystem/ll2ctypes.py
+++ b/rpython/rtyper/lltypesystem/ll2ctypes.py
@@ -250,7 +250,9 @@
 
 if not A._hints.get('nolength'):
 _fields_ = [('length', lentype),
-('items',  max_n * ctypes_item)]
+('items',
+   (max_n + A._hints.get('extra_item_after_alloc', 0))
+   * ctypes_item)]
 else:
 _fields_ = [('items',  max_n * ctypes_item)]
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/

[pypy-commit] pypy null_byte_after_str: rffi.scoped_nonmovingbuffer_final_null

2016-07-29 Thread arigo
Author: Armin Rigo 
Branch: null_byte_after_str
Changeset: r85915:4496557d38d9
Date: 2016-07-29 19:25 +0200
http://bitbucket.org/pypy/pypy/changeset/4496557d38d9/

Log:rffi.scoped_nonmovingbuffer_final_null

diff --git a/rpython/rlib/rgc.py b/rpython/rlib/rgc.py
--- a/rpython/rlib/rgc.py
+++ b/rpython/rlib/rgc.py
@@ -1279,7 +1279,7 @@
 """
 from rpython.rtyper.lltypesystem import rffi
 PSTR = lltype.typeOf(s)
-_check_final_null_char(PSTR)
+assert has_final_null_char(PSTR) == 1
 n = llmemory.offsetof(PSTR.TO, 'chars')
 n += llmemory.itemoffsetof(PSTR.TO.chars, 0)
 n = llmemory.raw_malloc_usage(n)
@@ -1289,5 +1289,5 @@
 ptr[n] = '\x00'
 
 @specialize.memo()
-def _check_final_null_char(PSTR):
-assert PSTR.TO.chars._hints.get('extra_item_after_alloc', 0) == 1
+def has_final_null_char(PSTR):
+return PSTR.TO.chars._hints.get('extra_item_after_alloc', 0)
diff --git a/rpython/rtyper/lltypesystem/rffi.py 
b/rpython/rtyper/lltypesystem/rffi.py
--- a/rpython/rtyper/lltypesystem/rffi.py
+++ b/rpython/rtyper/lltypesystem/rffi.py
@@ -819,6 +819,11 @@
 First bool returned indicates if 'data' was pinned. Second bool 
returned
 indicates if we did a raw alloc because pinning failed. Both bools
 should never be true at the same time.
+
+For strings (not unicodes), the len()th character of the resulting
+raw buffer is available, but not initialized.  Use
+get_nonmovingbuffer_final_null() instead of get_nonmovingbuffer()
+to get a regular null-terminated "char *".
 """
 
 lldata = llstrtype(data)
@@ -829,6 +834,7 @@
 if rgc.pin(data):
 pinned = True
 else:
+count += has_final_null_char(TYPEP)
 buf = lltype.malloc(TYPEP.TO, count, flavor='raw')
 copy_string_to_raw(lldata, buf, 0, count)
 return buf, pinned, True
@@ -846,6 +852,14 @@
 get_nonmovingbuffer._always_inline_ = 'try' # get rid of the returned tuple
 get_nonmovingbuffer._annenforceargs_ = [strtype]
 
+@jit.dont_look_inside
+def get_nonmovingbuffer_final_null(data):
+buf, is_pinned, is_raw = get_nonmovingbuffer(data)
+buf[len(data)] = lastchar
+return buf, is_pinned, is_raw
+get_nonmovingbuffer_final_null._always_inline_ = 'try'
+get_nonmovingbuffer_final_null._annenforceargs_ = [strtype]
+
 # (str, char*, bool, bool) -> None
 # Can't inline this because of the raw address manipulation.
 @jit.dont_look_inside
@@ -947,18 +961,19 @@
 
 return (str2charp, free_charp, charp2str,
 get_nonmovingbuffer, free_nonmovingbuffer,
+get_nonmovingbuffer_final_null,
 alloc_buffer, str_from_buffer, keep_buffer_alive_until_here,
 charp2strn, charpsize2str, str2chararray, str2rawmem,
 )
 
 (str2charp, free_charp, charp2str,
- get_nonmovingbuffer, free_nonmovingbuffer,
+ get_nonmovingbuffer, free_nonmovingbuffer, get_nonmovingbuffer_final_null,
  alloc_buffer, str_from_buffer, keep_buffer_alive_until_here,
  charp2strn, charpsize2str, str2chararray, str2rawmem,
  ) = make_string_mappings(str)
 
 (unicode2wcharp, free_wcharp, wcharp2unicode,
- get_nonmoving_unicodebuffer, free_nonmoving_unicodebuffer,
+ get_nonmoving_unicodebuffer, free_nonmoving_unicodebuffer, __not_usable,
  alloc_unicodebuffer, unicode_from_buffer, keep_unicodebuffer_alive_until_here,
  wcharp2unicoden, wcharpsize2unicode, unicode2wchararray, unicode2rawmem,
  ) = make_string_mappings(unicode)
@@ -1202,6 +1217,19 @@
 __enter__._always_inline_ = 'try'
 __exit__._always_inline_ = 'try'
 
+class scoped_nonmovingbuffer_final_null:
+def __init__(self, data):
+self.data = data
+def __enter__(self):
+self.buf, self.pinned, self.is_raw = (
+get_nonmovingbuffer_final_null(self.data))
+return self.buf
+def __exit__(self, *args):
+free_nonmovingbuffer(self.data, self.buf, self.pinned, self.is_raw)
+__init__._always_inline_ = 'try'
+__enter__._always_inline_ = 'try'
+__exit__._always_inline_ = 'try'
+
 class scoped_nonmoving_unicodebuffer:
 def __init__(self, data):
 self.data = data
diff --git a/rpython/rtyper/lltypesystem/test/test_rffi.py 
b/rpython/rtyper/lltypesystem/test/test_rffi.py
--- a/rpython/rtyper/lltypesystem/test/test_rffi.py
+++ b/rpython/rtyper/lltypesystem/test/test_rffi.py
@@ -835,3 +835,11 @@
 if hasattr(rffi, '__INT128_T'):
 value = 0x
 assert cast(rffi.__INT128_T, r_uint64(value)) == value
+
+def test_scoped_nonmovingbuffer_final_null():
+s = 'bar'
+with scoped_nonmovingbuffer_final_null(s) as buf:
+assert buf[0] == 'b'
+assert buf[1] == 'a'
+assert buf[2] == 'r'
+assert buf[3] == '\x00'
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/ma

[pypy-commit] pypy null_byte_after_str: cffi: tentatively pass the raw address inside RPython strings

2016-07-29 Thread arigo
Author: Armin Rigo 
Branch: null_byte_after_str
Changeset: r85916:f2f9031b0f4b
Date: 2016-07-29 20:11 +0200
http://bitbucket.org/pypy/pypy/changeset/f2f9031b0f4b/

Log:cffi: tentatively pass the raw address inside RPython strings

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
@@ -177,9 +177,12 @@
 if isinstance(argtype, W_CTypePointer):
 data = rffi.ptradd(buffer, cif_descr.exchange_args[i])
 flag = get_mustfree_flag(data)
+raw_cdata = rffi.cast(rffi.CCHARPP, data)[0]
 if flag == 1:
-raw_cdata = rffi.cast(rffi.CCHARPP, data)[0]
 lltype.free(raw_cdata, flavor='raw')
+elif flag >= 4:
+value = args_w[i].str_w(space)
+rffi.free_nonmovingbuffer(value, raw_cdata, chr(flag))
 lltype.free(buffer, flavor='raw')
 keepalive_until_here(args_w)
 return w_res
diff --git a/pypy/module/_cffi_backend/ctypeptr.py 
b/pypy/module/_cffi_backend/ctypeptr.py
--- a/pypy/module/_cffi_backend/ctypeptr.py
+++ b/pypy/module/_cffi_backend/ctypeptr.py
@@ -14,8 +14,8 @@
 
 
 class W_CTypePtrOrArray(W_CType):
-_attrs_= ['ctitem', 'can_cast_anything', 'length']
-_immutable_fields_ = ['ctitem', 'can_cast_anything', 'length']
+_attrs_= ['ctitem', 'can_cast_anything', 'accept_str', 
'length']
+_immutable_fields_ = ['ctitem', 'can_cast_anything', 'accept_str', 
'length']
 length = -1
 
 def __init__(self, space, size, extra, extra_position, ctitem,
@@ -28,6 +28,9 @@
 #  - for functions, it is the return type
 self.ctitem = ctitem
 self.can_cast_anything = could_cast_anything and ctitem.cast_anything
+self.accept_str = (self.can_cast_anything or
+(ctitem.is_primitive_integer and
+ ctitem.size == rffi.sizeof(lltype.Char)))
 
 def is_unichar_ptr_or_array(self):
 return isinstance(self.ctitem, ctypeprim.W_CTypePrimitiveUniChar)
@@ -70,9 +73,7 @@
 pass
 else:
 self._convert_array_from_listview(cdata, space.listview(w_ob))
-elif (self.can_cast_anything or
-  (self.ctitem.is_primitive_integer and
-   self.ctitem.size == rffi.sizeof(lltype.Char))):
+elif self.accept_str:
 if not space.isinstance_w(w_ob, space.w_str):
 raise self._convert_error("str or list or tuple", w_ob)
 s = space.str_w(w_ob)
@@ -262,6 +263,15 @@
 
 def _prepare_pointer_call_argument(self, w_init, cdata):
 space = self.space
+if self.accept_str and space.isinstance_w(w_init, space.w_str):
+# special case to optimize strings passed to a "char *" argument
+# WARNING: this relies on the fact that w_init.str_w() returns
+# always the same object for the same w_init!
+value = w_init.str_w(space)
+buf, buf_flag = rffi.get_nonmovingbuffer_final_null(value)
+rffi.cast(rffi.CCHARPP, cdata)[0] = buf
+return ord(buf_flag)# 4, 5 or 6
+#
 if (space.isinstance_w(w_init, space.w_list) or
 space.isinstance_w(w_init, space.w_tuple)):
 length = space.int_w(space.len(w_init))
diff --git a/pypy/module/_ssl/interp_ssl.py b/pypy/module/_ssl/interp_ssl.py
--- a/pypy/module/_ssl/interp_ssl.py
+++ b/pypy/module/_ssl/interp_ssl.py
@@ -135,7 +135,7 @@
 
 def __init__(self, ctx, protos):
 self.protos = protos
-self.buf, self.pinned, self.is_raw = rffi.get_nonmovingbuffer(protos)
+self.buf, self.bufflag = rffi.get_nonmovingbuffer(protos)
 NPN_STORAGE.set(rffi.cast(lltype.Unsigned, self.buf), self)
 
 # set both server and client callbacks, because the context
@@ -147,7 +147,7 @@
 
 def __del__(self):
 rffi.free_nonmovingbuffer(
-self.protos, self.buf, self.pinned, self.is_raw)
+self.protos, self.buf, self.bufflag)
 
 @staticmethod
 def advertiseNPN_cb(s, data_ptr, len_ptr, args):
@@ -181,7 +181,7 @@
 
 def __init__(self, ctx, protos):
 self.protos = protos
-self.buf, self.pinned, self.is_raw = rffi.get_nonmovingbuffer(protos)
+self.buf, self.bufflag = rffi.get_nonmovingbuffer(protos)
 ALPN_STORAGE.set(rffi.cast(lltype.Unsigned, self.buf), self)
 
 with rffi.scoped_str2charp(protos) as protos_buf:
@@ -193,7 +193,7 @@
 
 def __del__(self):
 rffi.free_nonmovingbuffer(
-self.protos, self.buf, self.pinned, self.is_raw)
+self.protos, self.buf, self.bufflag)
 
 @staticmethod
 def selectALPN_cb(s, out_ptr, outlen_ptr, client, client_len, args):
diff --gi

[pypy-commit] pypy default: Fix tests, now that 'lltype.typeOf(very_large_long)' gives an error

2016-07-29 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r85917:0cafa40b38a9
Date: 2016-07-29 20:25 +0200
http://bitbucket.org/pypy/pypy/changeset/0cafa40b38a9/

Log:Fix tests, now that 'lltype.typeOf(very_large_long)' gives an error

diff --git a/pypy/objspace/std/test/test_stdobjspace.py 
b/pypy/objspace/std/test/test_stdobjspace.py
--- a/pypy/objspace/std/test/test_stdobjspace.py
+++ b/pypy/objspace/std/test/test_stdobjspace.py
@@ -66,17 +66,18 @@
 
 def test_wrap_various_unsigned_types(self):
 import sys
+from rpython.rlib.rarithmetic import r_uint
 from rpython.rtyper.lltypesystem import lltype, rffi
 space = self.space
 value = sys.maxint * 2
-x = rffi.cast(lltype.Unsigned, value)
+x = r_uint(value)
 assert space.eq_w(space.wrap(value), space.wrap(x))
-x = rffi.cast(rffi.UINTPTR_T, value)
+x = rffi.cast(rffi.UINTPTR_T, r_uint(value))
 assert x > 0
 assert space.eq_w(space.wrap(value), space.wrap(x))
 value = 6
-x = rffi.cast(rffi.USHORT, value)
+x = rffi.cast(rffi.USHORT, r_uint(value))
 assert space.eq_w(space.wrap(value), space.wrap(x))
 value = 200
-x = rffi.cast(rffi.UCHAR, value)
+x = rffi.cast(rffi.UCHAR, r_uint(value))
 assert space.eq_w(space.wrap(value), space.wrap(x))
diff --git a/rpython/jit/backend/x86/test/test_regloc.py 
b/rpython/jit/backend/x86/test/test_regloc.py
--- a/rpython/jit/backend/x86/test/test_regloc.py
+++ b/rpython/jit/backend/x86/test/test_regloc.py
@@ -147,7 +147,7 @@
 py.test.skip()
 
 def test_reuse_scratch_register(self):
-base_addr = 0xFEDCBA9876543210
+base_addr = intmask(0xFEDCBA9876543210)
 cb = LocationCodeBuilder64()
 cb.begin_reuse_scratch_register()
 cb.MOV(ecx, heap(base_addr))
@@ -167,7 +167,7 @@
 # 
 
 def test_64bit_address_1(self):
-base_addr = 0xFEDCBA9876543210
+base_addr = intmask(0xFEDCBA9876543210)
 cb = LocationCodeBuilder64()
 cb.CMP(ecx, AddressLoc(ImmedLoc(0), ImmedLoc(0), 0, base_addr))
 # this case is a CMP_rj
@@ -181,7 +181,7 @@
 assert cb.getvalue() == expected_instructions
 
 def test_64bit_address_2(self):
-base_addr = 0xFEDCBA9876543210
+base_addr = intmask(0xFEDCBA9876543210)
 cb = LocationCodeBuilder64()
 cb.MOV(ecx, AddressLoc(ImmedLoc(0), edx, 3, base_addr))
 # this case is a CMP_ra
@@ -195,7 +195,7 @@
 assert cb.getvalue() == expected_instructions
 
 def test_64bit_address_3(self):
-base_addr = 0xFEDCBA9876543210
+base_addr = intmask(0xFEDCBA9876543210)
 cb = LocationCodeBuilder64()
 cb.MOV(ecx, AddressLoc(edx, ImmedLoc(0), 0, base_addr))
 # this case is a CMP_rm
@@ -211,7 +211,7 @@
 assert cb.getvalue() == expected_instructions
 
 def test_64bit_address_4(self):
-base_addr = 0xFEDCBA9876543210
+base_addr = intmask(0xFEDCBA9876543210)
 cb = LocationCodeBuilder64()
 cb.begin_reuse_scratch_register()
 assert cb._reuse_scratch_register is True
@@ -234,7 +234,7 @@
 # 
 
 def test_MOV_64bit_constant_into_r11(self):
-base_constant = 0xFEDCBA9876543210
+base_constant = intmask(0xFEDCBA9876543210)
 cb = LocationCodeBuilder64()
 cb.MOV(r11, imm(base_constant))
 
@@ -245,7 +245,7 @@
 assert cb.getvalue() == expected_instructions
 
 def test_MOV_64bit_constant_into_rax(self):
-base_constant = 0xFEDCBA9876543210
+base_constant = intmask(0xFEDCBA9876543210)
 cb = LocationCodeBuilder64()
 cb.MOV(eax, imm(base_constant))
 
@@ -256,7 +256,7 @@
 assert cb.getvalue() == expected_instructions
 
 def test_MOV_64bit_address_into_r11(self):
-base_addr = 0xFEDCBA9876543210
+base_addr = intmask(0xFEDCBA9876543210)
 cb = LocationCodeBuilder64()
 cb.MOV(r11, heap(base_addr))
 
@@ -270,7 +270,7 @@
 
 def test_MOV_immed32_into_64bit_address_1(self):
 immed = -0x01234567
-base_addr = 0xFEDCBA9876543210
+base_addr = intmask(0xFEDCBA9876543210)
 cb = LocationCodeBuilder64()
 cb.MOV(AddressLoc(ImmedLoc(0), ImmedLoc(0), 0, base_addr),
ImmedLoc(immed))
@@ -286,7 +286,7 @@
 
 def test_MOV_immed32_into_64bit_address_2(self):
 immed = -0x01234567
-base_addr = 0xFEDCBA9876543210
+base_addr = intmask(0xFEDCBA9876543210)
 cb = LocationCodeBuilder64()
 cb.MOV(AddressLoc(ImmedLoc(0), edx, 3, base_addr),
ImmedLoc(immed))
@@ -302,7 +302,7 @@
 
 def test_MOV_immed32_into_64bit_address_3(self):
 immed = -0x01234567
-base_addr = 0xFEDCBA9876543210
+base_addr = intmask(0xFEDCBA987654321

[pypy-commit] pypy py3.5-async: Only call __await__ if it exists

2016-07-29 Thread raffael_t
Author: Raffael Tfirst 
Branch: py3.5-async
Changeset: r85918:5a3b4f095c70
Date: 2016-07-29 22:05 +0200
http://bitbucket.org/pypy/pypy/changeset/5a3b4f095c70/

Log:Only call __await__ if it exists

diff --git a/pypy/interpreter/generator.py b/pypy/interpreter/generator.py
--- a/pypy/interpreter/generator.py
+++ b/pypy/interpreter/generator.py
@@ -309,7 +309,8 @@
 if w_iterable.pycode.co_flags & consts.CO_ITERABLE_COROUTINE:
 return self
 #look at typeobject.c, change to self.space.lookup(w_manager, 
"__await__")
-res = self.descr__await__(space)
+space.lookup(self, "__await__")
+res = space.get_and_call_function(w_enter, None)
 return self
 
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit