[pypy-commit] pypy py3.6: Add a TODO.
Author: Manuel JacobBranch: py3.6 Changeset: r91920:7f4ec0d17965 Date: 2017-07-18 19:59 +0200 http://bitbucket.org/pypy/pypy/changeset/7f4ec0d17965/ Log:Add a TODO. diff --git a/pypy/interpreter/generator.py b/pypy/interpreter/generator.py --- a/pypy/interpreter/generator.py +++ b/pypy/interpreter/generator.py @@ -710,6 +710,7 @@ try: if throwing: if self.w_exc_type is None: +# TODO: add equivalent to CPython's o->agt_gen->ag_closed = 1; w_value = self.async_gen.throw(space.w_GeneratorExit, None, None) if w_value is not None: ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.6: Implement AsyncGenABase.descr_close(). Translation should work again!
Author: Manuel JacobBranch: py3.6 Changeset: r91921:3de6fb333784 Date: 2017-07-19 00:21 +0200 http://bitbucket.org/pypy/pypy/changeset/3de6fb333784/ Log:Implement AsyncGenABase.descr_close(). Translation should work again! diff --git a/pypy/interpreter/generator.py b/pypy/interpreter/generator.py --- a/pypy/interpreter/generator.py +++ b/pypy/interpreter/generator.py @@ -642,7 +642,7 @@ raise def descr_close(self): -XXX +self.state = self.ST_CLOSED def unwrap_value(self, w_value): if isinstance(w_value, AsyncGenValueWrapper): diff --git a/pypy/interpreter/test/test_coroutine.py b/pypy/interpreter/test/test_coroutine.py --- a/pypy/interpreter/test/test_coroutine.py +++ b/pypy/interpreter/test/test_coroutine.py @@ -485,3 +485,17 @@ await a.aclose() raises(RuntimeError, run().send, None) """ + +def test_async_anext_close(self): """ +async def ag(): +yield 42 + +an = ag().__anext__() +an.close() +try: +next(an) +except StopIteration as e: +assert e.value is None +else: +assert False, "didn't raise" +""" ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.6: Add test and implementation for async generator ignoring GeneratorExit.
Author: Manuel JacobBranch: py3.6 Changeset: r91919:958a9c75a085 Date: 2017-07-18 19:56 +0200 http://bitbucket.org/pypy/pypy/changeset/958a9c75a085/ Log:Add test and implementation for async generator ignoring GeneratorExit. diff --git a/pypy/interpreter/generator.py b/pypy/interpreter/generator.py --- a/pypy/interpreter/generator.py +++ b/pypy/interpreter/generator.py @@ -713,7 +713,8 @@ w_value = self.async_gen.throw(space.w_GeneratorExit, None, None) if w_value is not None: -XXX +raise oefmt(space.w_RuntimeError, +"async generator ignored GeneratorExit") else: w_value = self.async_gen.throw(self.w_exc_type, self.w_exc_value, diff --git a/pypy/interpreter/test/test_coroutine.py b/pypy/interpreter/test/test_coroutine.py --- a/pypy/interpreter/test/test_coroutine.py +++ b/pypy/interpreter/test/test_coroutine.py @@ -470,3 +470,18 @@ pass assert raises_generator_exit """ + +def test_async_aclose_ignore_generator_exit(self): """ +async def ag(): +try: +yield +except GeneratorExit: +yield + +async def run(): +a = ag() +async for i in a: +break +await a.aclose() +raises(RuntimeError, run().send, None) +""" ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.6: Add first test for aclose() on async generator and make it pass.
Author: Manuel JacobBranch: py3.6 Changeset: r91918:a52d37ceba11 Date: 2017-07-18 19:35 +0200 http://bitbucket.org/pypy/pypy/changeset/a52d37ceba11/ Log:Add first test for aclose() on async generator and make it pass. diff --git a/pypy/interpreter/generator.py b/pypy/interpreter/generator.py --- a/pypy/interpreter/generator.py +++ b/pypy/interpreter/generator.py @@ -602,7 +602,7 @@ return AsyncGenAThrow(self, w_type, w_val, w_tb) def descr_aclose(self): -XXX +return AsyncGenAThrow(self, None, None, None) class AsyncGenValueWrapper(W_Root): @@ -709,14 +709,30 @@ try: if throwing: -w_value = self.async_gen.throw(self.w_exc_type, - self.w_exc_value, - self.w_exc_tb) +if self.w_exc_type is None: +w_value = self.async_gen.throw(space.w_GeneratorExit, + None, None) +if w_value is not None: +XXX +else: +w_value = self.async_gen.throw(self.w_exc_type, + self.w_exc_value, + self.w_exc_tb) else: w_value = self.async_gen.send_ex(w_arg_or_err) return self.unwrap_value(w_value) except OperationError as e: -self.state = self.ST_CLOSED +if e.match(space, space.w_StopAsyncIteration): +self.state = self.ST_CLOSED +if self.w_exc_type is None: +# When aclose() is called we don't want to propagate +# StopAsyncIteration; just raise StopIteration, signalling +# that 'aclose()' is done. +raise OperationError(space.w_StopIteration, space.w_None) +if e.match(space, space.w_GeneratorExit): +self.state = self.ST_CLOSED +# Ignore this error. +raise OperationError(space.w_StopIteration, space.w_None) raise def descr_throw(self, w_type, w_val=None, w_tb=None): diff --git a/pypy/interpreter/test/test_coroutine.py b/pypy/interpreter/test/test_coroutine.py --- a/pypy/interpreter/test/test_coroutine.py +++ b/pypy/interpreter/test/test_coroutine.py @@ -448,3 +448,25 @@ except StopIteration: assert values == [42] """ + +def test_async_aclose(self): """ +raises_generator_exit = False +async def ag(): +nonlocal raises_generator_exit +try: +yield +except GeneratorExit: +raises_generator_exit = True +raise + +async def run(): +a = ag() +async for i in a: +break +await a.aclose() +try: +run().send(None) +except StopIteration: +pass +assert raises_generator_exit +""" ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy Enable_PGO_for_clang: Enable PGO for CLang
Author: Dodan MihaiBranch: Enable_PGO_for_clang Changeset: r91916:10da3d6507ca Date: 2017-06-14 13:33 +0300 http://bitbucket.org/pypy/pypy/changeset/10da3d6507ca/ Log:Enable PGO for CLang 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 @@ -382,6 +382,80 @@ if self.config.translation.profopt: if self.config.translation.profoptargs is None: raise Exception("No profoptargs specified, neither in the command line, nor in the target. If the target is not PyPy, please specify profoptargs") + +# Set the correct PGO params based on OS and CC +profopt_gen_flag = "" +profopt_use_flag = "" +profopt_merger = "" +profopt_file = "" +llvm_profdata = "" + +cc = self.translator.platform.cc + +# Locate llvm-profdata +if "clang" in cc: +clang_bin = cc +path = os.environ.get("PATH").split(":") +profdata_found = False + +# Try to find it in $PATH (Darwin and Linux) +for dir in path: +bin = "%s/llvm-profdata" % dir +if os.path.isfile(bin): +llvm_profdata = bin +profdata_found = True +break + +# If not found, try to find it where clang is actually installed (Darwin and Linux) +if not profdata_found: +# If the full path is not given, find where clang is located +if not os.path.isfile(clang_bin): +for dir in path: +bin = "%s/%s" % (dir, cc) +if os.path.isfile(bin): +clang_bin = bin +break +# Some systems install clang elsewhere as a symlink to the real path, +# which is where the related llvm tools are located. +if os.path.islink(clang_bin): +clang_bin = os.path.realpath(clang_bin) # the real clang binary +# llvm-profdata must be in the same directory as clang +llvm_profdata = "%s/llvm-profdata" % os.path.dirname(clang_bin) +profdata_found = os.path.isfile(llvm_profdata) + +# If not found, and Darwin is used, try to find it in the development environment +# More: https://apple.stackexchange.com/questions/197053/ +if not profdata_found and sys.platform == 'darwin': +code = os.system("/usr/bin/xcrun -find llvm-profdata 2>/dev/null") +if code == 0: +llvm_profdata = "/usr/bin/xcrun llvm-profdata" +profdata_found = True + +# If everything failed, throw Exception, sorry +if not profdata_found: +raise Exception( +"Error: Cannot perform profopt build because llvm-profdata was not found in PATH. " +"Please add it to PATH and run the translation again.") + +# Set the PGO flags +if "clang" in cc: +# Any changes made here should be reflected in the GCC+Darwin case below +profopt_gen_flag = "-fprofile-instr-generate" +profopt_use_flag = "-fprofile-instr-use=code.profclangd" +profopt_merger = "%s merge -output=code.profclangd *.profclangr" % llvm_profdata +profopt_file = 'LLVM_PROFILE_FILE="code-%p.profclangr"' +elif "gcc" in cc: +if sys.platform == 'darwin': +profopt_gen_flag = "-fprofile-instr-generate" +profopt_use_flag = "-fprofile-instr-use=code.profclangd" +profopt_merger = "%s merge -output=code.profclangd *.profclangr" % llvm_profdata +profopt_file = 'LLVM_PROFILE_FILE="code-%p.profclangr"' +else: +profopt_gen_flag = "-fprofile-generate" +profopt_use_flag = "-fprofile-use -fprofile-correction" +profopt_merger = "true" +profopt_file = "" + if self.config.translation.shared: mk.rule('$(PROFOPT_TARGET)', '$(TARGET) main.o', '$(CC_LINK) $(LDFLAGS_LINK) main.o -L. -l$(SHARED_IMPORT_LIB) -o $@ $(RPATH_FLAGS) -lgcov') @@ -390,10 +464,11 @@ rules.append( ('profopt', '', [ -'$(MAKE) CFLAGS="-fprofile-generate -fPIC $(CFLAGS) -fno-lto" LDFLAGS="-fprofile-generate $(LDFLAGS) -fno-lto" $(PROFOPT_TARGET)', -'%s %s ' % (exe_name,
[pypy-commit] pypy default: Merged in Dodan/pgo_clang_support/Enable_PGO_for_clang (pull request #554)
Author: Carl Friedrich Bolz-TereickBranch: Changeset: r91917:75bf1a95154b Date: 2017-07-18 10:02 + http://bitbucket.org/pypy/pypy/changeset/75bf1a95154b/ Log:Merged in Dodan/pgo_clang_support/Enable_PGO_for_clang (pull request #554) Enable PGO for CLang (there's code in CPython that does the equivalent roughly here: http s://github.com/python/cpython/blob/6b42eb17649bed9615b6e6cecaefdb2f4 6990b2c/configure#L6753 ) 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 @@ -382,6 +382,80 @@ if self.config.translation.profopt: if self.config.translation.profoptargs is None: raise Exception("No profoptargs specified, neither in the command line, nor in the target. If the target is not PyPy, please specify profoptargs") + +# Set the correct PGO params based on OS and CC +profopt_gen_flag = "" +profopt_use_flag = "" +profopt_merger = "" +profopt_file = "" +llvm_profdata = "" + +cc = self.translator.platform.cc + +# Locate llvm-profdata +if "clang" in cc: +clang_bin = cc +path = os.environ.get("PATH").split(":") +profdata_found = False + +# Try to find it in $PATH (Darwin and Linux) +for dir in path: +bin = "%s/llvm-profdata" % dir +if os.path.isfile(bin): +llvm_profdata = bin +profdata_found = True +break + +# If not found, try to find it where clang is actually installed (Darwin and Linux) +if not profdata_found: +# If the full path is not given, find where clang is located +if not os.path.isfile(clang_bin): +for dir in path: +bin = "%s/%s" % (dir, cc) +if os.path.isfile(bin): +clang_bin = bin +break +# Some systems install clang elsewhere as a symlink to the real path, +# which is where the related llvm tools are located. +if os.path.islink(clang_bin): +clang_bin = os.path.realpath(clang_bin) # the real clang binary +# llvm-profdata must be in the same directory as clang +llvm_profdata = "%s/llvm-profdata" % os.path.dirname(clang_bin) +profdata_found = os.path.isfile(llvm_profdata) + +# If not found, and Darwin is used, try to find it in the development environment +# More: https://apple.stackexchange.com/questions/197053/ +if not profdata_found and sys.platform == 'darwin': +code = os.system("/usr/bin/xcrun -find llvm-profdata 2>/dev/null") +if code == 0: +llvm_profdata = "/usr/bin/xcrun llvm-profdata" +profdata_found = True + +# If everything failed, throw Exception, sorry +if not profdata_found: +raise Exception( +"Error: Cannot perform profopt build because llvm-profdata was not found in PATH. " +"Please add it to PATH and run the translation again.") + +# Set the PGO flags +if "clang" in cc: +# Any changes made here should be reflected in the GCC+Darwin case below +profopt_gen_flag = "-fprofile-instr-generate" +profopt_use_flag = "-fprofile-instr-use=code.profclangd" +profopt_merger = "%s merge -output=code.profclangd *.profclangr" % llvm_profdata +profopt_file = 'LLVM_PROFILE_FILE="code-%p.profclangr"' +elif "gcc" in cc: +if sys.platform == 'darwin': +profopt_gen_flag = "-fprofile-instr-generate" +profopt_use_flag = "-fprofile-instr-use=code.profclangd" +profopt_merger = "%s merge -output=code.profclangd *.profclangr" % llvm_profdata +profopt_file = 'LLVM_PROFILE_FILE="code-%p.profclangr"' +else: +profopt_gen_flag = "-fprofile-generate" +profopt_use_flag = "-fprofile-use -fprofile-correction" +profopt_merger = "true" +profopt_file = "" + if self.config.translation.shared: mk.rule('$(PROFOPT_TARGET)', '$(TARGET) main.o', '$(CC_LINK) $(LDFLAGS_LINK) main.o -L. -l$(SHARED_IMPORT_LIB) -o $@ $(RPATH_FLAGS) -lgcov') @@ -390,10 +464,11 @@ rules.append(
[pypy-commit] pypy py3.5-sendmsg-recvmsg: Sendmsg and recvmsg implemented. Some test fail. Some mem leaks
Author: Dodan MihaiBranch: py3.5-sendmsg-recvmsg Changeset: r91915:4396f9d022d5 Date: 2017-07-18 11:25 +0300 http://bitbucket.org/pypy/pypy/changeset/4396f9d022d5/ Log:Sendmsg and recvmsg implemented. Some test fail. Some mem leaks diff --git a/pypy/module/_socket/__init__.py b/pypy/module/_socket/__init__.py --- a/pypy/module/_socket/__init__.py +++ b/pypy/module/_socket/__init__.py @@ -34,6 +34,7 @@ ntohs ntohl htons htonl inet_aton inet_ntoa inet_pton inet_ntop getaddrinfo getnameinfo getdefaulttimeout setdefaulttimeout +CMSG_SPACE CMSG_LEN """.split(): if (name in ('inet_pton', 'inet_ntop', 'socketpair') and diff --git a/pypy/module/_socket/interp_func.py b/pypy/module/_socket/interp_func.py --- a/pypy/module/_socket/interp_func.py +++ b/pypy/module/_socket/interp_func.py @@ -327,6 +327,28 @@ for (family, socktype, protocol, canonname, addr) in lst] return space.newlist(lst1) +@unwrap_spec(size=int) +def CMSG_SPACE(space, size): +if size < 0: +raise oefmt(space.w_OverflowError, +"CMSG_SPACE() argument out of range") +retval = rsocket.CMSG_SPACE(size) +if retval == 0: +raise oefmt(space.w_OverflowError, +"CMSG_SPACE() argument out of range") +return space.newint(retval) + +@unwrap_spec(len=int) +def CMSG_LEN(space, len): +if len < 0: +raise oefmt(space.w_OverflowError, +"CMSG_LEN() argument out of range") +retval = rsocket.CMSG_LEN(len) +if retval == 0: +raise oefmt(space.w_OverflowError, +"CMSG_LEN() argument out of range") +return space.newint(retval) + def getdefaulttimeout(space): """getdefaulttimeout() -> timeout diff --git a/pypy/module/_socket/interp_socket.py b/pypy/module/_socket/interp_socket.py --- a/pypy/module/_socket/interp_socket.py +++ b/pypy/module/_socket/interp_socket.py @@ -285,6 +285,8 @@ except SocketError as e: raise converted_error(space, e) + + def close_w(self, space): """close() @@ -446,6 +448,38 @@ converted_error(space, e, eintr_retry=True) return space.newtuple([space.newbytes(data), w_addr]) +@unwrap_spec(message_size=int, ancbufsize=int, flags=int) +def recvmsg_w(self,space,message_size, ancbufsize = 0, flags = 0): +if (message_size < 0): +raise oefmt(space.w_ValueError, "negative buffer size in recvmsg()") +if ancbufsize < 0: +raise oefmt(space.w_ValueError, "invalid ancillary data buffer length") +try: +tuple = self.sock.recvmsg(message_size, ancbufsize, flags) +message = space.newbytes(tuple[0]) +# print(tuple[0]) +list = [] +for l in tuple[1]: +tup = space.newtuple([space.newint(l[0]), space.newint(l[1]), space.newbytes(l[2])]) +list.append(tup) + +anc = space.newlist(list) + +flag = space.newint(tuple[2]) +if (tuple[3] is not None): +address = addr_as_object(tuple[3], self.sock.fd, space) +else: +address = space.w_None + +rettup = space.newtuple([message, anc, flag, address]) +return rettup +except SocketError as e: +converted_error(space, e, eintr_retry=True) + + + + + @unwrap_spec(data='bufferstr', flags=int) def send_w(self, space, data, flags=0): """send(data[, flags]) -> count @@ -501,6 +535,110 @@ converted_error(space, e, eintr_retry=True) return space.newint(count) +#@unwrap_spec(data='bufferstr', flags = int) +def sendmsg_w(self, space, w_data, w_ancillary=None, w_flags=None ,w_address=None): +"""sendmsg(messages, [ancillaries, [flags, [address]]]) +""" +flags = 0 +if space.is_none(w_flags) is False: +flags = space.int_w(w_flags) + +address = None +if space.is_none(w_address) is False: +address = self.addr_from_object(space, w_address) + +data = [] +if (w_data.typedef.name == 'list'): +for i in w_data.getitems(): +if space.isinstance_w(i,space.w_bytes): +data.append(space.bytes_w(i)) +else: +if (i.typedef.name == 'array.array'): +data.append(space.bytes_w(i.descr_tobytes(space))) +else: +raise oefmt(space.w_TypeError, "a bytes-like object is required") +else: +while True: +try: +if (space.is_generator(w_data) is False): +raise oefmt(space.w_TypeError, "sendmsg(): argument 1 must be iterable") +i = space.next(w_data) +if