[pypy-commit] pypy default: Embedding documentation - fixing few typos

2014-04-01 Thread vlukas
Author: Lukas Vacek 
Branch: 
Changeset: r70370:3285a45ff1bd
Date: 2014-03-26 01:11 +
http://bitbucket.org/pypy/pypy/changeset/3285a45ff1bd/

Log:Embedding documentation - fixing few typos

diff --git a/pypy/doc/embedding.rst b/pypy/doc/embedding.rst
--- a/pypy/doc/embedding.rst
+++ b/pypy/doc/embedding.rst
@@ -104,7 +104,7 @@
 Missing PyPy.h
 --
 
-.. note:: PyPy.h is in the nigthly builds and goes to new PyPy releases 
(>2.2.1).
+.. note:: PyPy.h is in the nightly builds and goes to new PyPy releases 
(>2.2.1).
 
 For PyPy <= 2.2.1, you can download PyPy.h from PyPy repository (it has been 
added in commit c4cd6ec):
 
@@ -214,7 +214,7 @@
 void *lib, *func;
 
 rpython_startup_code();
-res = pypy_setup_home("/home/lukas/dev/pypy-2.2.1-src/libpypy-c.so", 
1);
+res = pypy_setup_home("/opt/pypy/bin/libpypy-c.so", 1);
 if (res) {
 printf("Error setting pypy home!\n");
 return 1;
@@ -238,7 +238,9 @@
 Finding pypy_home
 -
 
-Function pypy_setup_home takes one parameter - the path to libpypy. There's 
currently no "clean" way (pkg-config comes to mind) how to find this path. You 
can try the following (GNU-specific) hack (don't forget to link against *dl*):
+Function pypy_setup_home takes one parameter - the path to libpypy. There's 
+currently no "clean" way (pkg-config comes to mind) how to find this path. You 
+can try the following (GNU-specific) hack (don't forget to link against *dl*):
 
 .. code-block:: c
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Merged in vlukas/pypy (pull request #215)

2014-04-01 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r70372:aa9f9b6f0ac3
Date: 2014-04-01 09:25 +0200
http://bitbucket.org/pypy/pypy/changeset/aa9f9b6f0ac3/

Log:Merged in vlukas/pypy (pull request #215)

Updating embedding.rst documentation to match PyPy 2.2.1

diff --git a/pypy/doc/embedding.rst b/pypy/doc/embedding.rst
--- a/pypy/doc/embedding.rst
+++ b/pypy/doc/embedding.rst
@@ -51,6 +51,8 @@
 
 .. function:: int pypy_execute_source_ptr(char* source, void* ptr);
 
+   .. note:: Not available in PyPy <= 2.2.1
+   
Just like the above, except it registers a magic argument in the source
scope as ``c_argument``, where ``void*`` is encoded as Python int.
 
@@ -100,9 +102,29 @@
 
 Worked!
 
+.. note:: If the compilation fails because of missing PyPy.h header file,
+  you are running PyPy <= 2.2.1, please see the section `Missing 
PyPy.h`_.
+
+Missing PyPy.h
+--
+
+.. note:: PyPy.h is in the nightly builds and goes to new PyPy releases 
(>2.2.1).
+
+For PyPy <= 2.2.1, you can download PyPy.h from PyPy repository (it has been 
added in commit c4cd6ec):
+
+.. code-block:: bash
+
+cd /opt/pypy/include
+wget 
https://bitbucket.org/pypy/pypy/raw/c4cd6eca9358066571500ac82aaacfdaa3889e8c/include/PyPy.h
+
+
 More advanced example
 -
 
+.. note:: This example depends on pypy_execute_source_ptr which is not 
available
+  in PyPy <= 2.2.1. You might want to see the alternative example
+  below.
+
 Typically we need something more to do than simply execute source. The 
following
 is a fully fledged example, please consult cffi documentation for details.
 It's a bit longish, but it captures a gist what can be done with the PyPy
@@ -161,6 +183,97 @@
 is that we would pass a struct full of callbacks to ``pypy_execute_source_ptr``
 and fill the structure from Python side for the future use.
 
+Alternative example
+---
+
+As ``pypy_execute_source_ptr`` is not available in PyPy 2.2.1, you might want 
to try 
+an alternative approach which relies on -export-dynamic flag to the GNU 
linker. 
+The downside to this approach is that it is platform dependent.
+
+.. code-block:: c
+
+#include "include/PyPy.h"
+#include 
+
+char source[] = "from cffi import FFI\n\
+ffi = FFI()\n\
+@ffi.callback('int(int)')\n\
+def func(a):\n\
+print 'Got from C %d' % a\n\
+return a * 2\n\
+ffi.cdef('int callback(int (*func)(int));')\n\
+lib = ffi.verify('int callback(int (*func)(int));')\n\
+lib.callback(func)\n\
+print 'finished the Python part'\n\
+";
+
+int callback(int (*func)(int))
+{
+printf("Calling to Python, result: %d\n", func(3));
+}
+
+int main()
+{
+int res;
+void *lib, *func;
+
+rpython_startup_code();
+res = pypy_setup_home("/opt/pypy/bin/libpypy-c.so", 1);
+if (res) {
+printf("Error setting pypy home!\n");
+return 1;
+}
+res = pypy_execute_source(source);
+if (res) {
+printf("Error calling pypy_execute_source!\n");
+}
+return res;
+}
+
+
+Make sure to pass -export-dynamic flag when compiling::
+
+   $ gcc -g -o x x.c -lpypy-c -L. -export-dynamic
+   $ LD_LIBRARY_PATH=. ./x
+   Got from C 3
+   Calling to Python, result: 6
+   finished the Python part
+
+Finding pypy_home
+-
+
+Function pypy_setup_home takes one parameter - the path to libpypy. There's 
+currently no "clean" way (pkg-config comes to mind) how to find this path. You 
+can try the following (GNU-specific) hack (don't forget to link against *dl*):
+
+.. code-block:: c
+
+#if !(_GNU_SOURCE)
+#define _GNU_SOURCE
+#endif
+
+#include 
+#include 
+#include 
+
+// caller should free returned pointer to avoid memleaks
+// returns NULL on error
+char* guess_pypyhome() {
+// glibc-only (dladdr is why we #define _GNU_SOURCE)
+Dl_info info;
+void *_rpython_startup_code = dlsym(0,"rpython_startup_code");
+if (_rpython_startup_code == 0) {
+return 0;
+}
+if (dladdr(_rpython_startup_code, &info) != 0) {
+const char* lib_path = info.dli_fname;
+char* lib_realpath = realpath(lib_path, 0);
+return lib_realpath;
+}
+return 0;
+}
+
+
 Threading
 -
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Embedding documentation updated

2014-04-01 Thread vlukas
Author: Lukas Vacek 
Branch: 
Changeset: r70369:fefe963624fe
Date: 2014-03-26 01:04 +
http://bitbucket.org/pypy/pypy/changeset/fefe963624fe/

Log:Embedding documentation updated

diff --git a/pypy/doc/embedding.rst b/pypy/doc/embedding.rst
--- a/pypy/doc/embedding.rst
+++ b/pypy/doc/embedding.rst
@@ -1,3 +1,4 @@
+
 Embedding PyPy
 --
 
@@ -50,7 +51,7 @@
 
 .. function:: int pypy_execute_source_ptr(char* source, void* ptr);
 
-   .. note:: Not available in <=2.2.1 yet
+   .. note:: Not available in PyPy <= 2.2.1

Just like the above, except it registers a magic argument in the source
scope as ``c_argument``, where ``void*`` is encoded as Python int.
@@ -75,7 +76,6 @@
 
 .. code-block:: c
 
-#include "include/PyPy.h"
 #include 
 
 const char source[] = "print 'hello from pypy'";
@@ -101,9 +101,26 @@
 
 Worked!
 
+Missing PyPy.h
+--
+
+.. note:: PyPy.h is in the nigthly builds and goes to new PyPy releases 
(>2.2.1).
+
+For PyPy <= 2.2.1, you can download PyPy.h from PyPy repository (it has been 
added in commit c4cd6ec):
+
+.. code-block:: bash
+
+cd /opt/pypy/include
+wget 
https://bitbucket.org/pypy/pypy/raw/c4cd6eca9358066571500ac82aaacfdaa3889e8c/include/PyPy.h
+
+
 More advanced example
 -
 
+.. note:: This example depends on pypy_execute_source_ptr which is not 
available
+  in PyPy <= 2.2.1. You might want to see the alternative example
+  below.
+
 Typically we need something more to do than simply execute source. The 
following
 is a fully fledged example, please consult cffi documentation for details.
 It's a bit longish, but it captures a gist what can be done with the PyPy
@@ -162,6 +179,95 @@
 is that we would pass a struct full of callbacks to ``pypy_execute_source_ptr``
 and fill the structure from Python side for the future use.
 
+Alternative example
+---
+
+As ``pypy_execute_source_ptr`` is not available in PyPy 2.2.1, you might want 
to try 
+an alternative approach which relies on -export-dynamic flag to the GNU 
linker. 
+The downside to this approach is that it is platform dependent.
+
+.. code-block:: c
+
+#include "include/PyPy.h"
+#include 
+
+char source[] = "from cffi import FFI\n\
+ffi = FFI()\n\
+@ffi.callback('int(int)')\n\
+def func(a):\n\
+print 'Got from C %d' % a\n\
+return a * 2\n\
+ffi.cdef('int callback(int (*func)(int));')\n\
+lib = ffi.verify('int callback(int (*func)(int));')\n\
+lib.callback(func)\n\
+print 'finished the Python part'\n\
+";
+
+int callback(int (*func)(int))
+{
+printf("Calling to Python, result: %d\n", func(3));
+}
+
+int main()
+{
+int res;
+void *lib, *func;
+
+rpython_startup_code();
+res = pypy_setup_home("/home/lukas/dev/pypy-2.2.1-src/libpypy-c.so", 
1);
+if (res) {
+printf("Error setting pypy home!\n");
+return 1;
+}
+res = pypy_execute_source(source);
+if (res) {
+printf("Error calling pypy_execute_source!\n");
+}
+return res;
+}
+
+
+Make sure to pass -export-dynamic flag when compiling::
+
+   $ gcc -g -o x x.c -lpypy-c -L. -export-dynamic
+   $ LD_LIBRARY_PATH=. ./x
+   Got from C 3
+   Calling to Python, result: 6
+   finished the Python part
+
+Finding pypy_home
+-
+
+Function pypy_setup_home takes one parameter - the path to libpypy. There's 
currently no "clean" way (pkg-config comes to mind) how to find this path. You 
can try the following (GNU-specific) hack (don't forget to link against *dl*):
+
+.. code-block:: c
+
+#if !(_GNU_SOURCE)
+#define _GNU_SOURCE
+#endif
+
+#include 
+#include 
+#include 
+
+// caller should free returned pointer to avoid memleaks
+// returns NULL on error
+char* guess_pypyhome() {
+// glibc-only (dladdr is why we #define _GNU_SOURCE)
+Dl_info info;
+void *_rpython_startup_code = dlsym(0,"rpython_startup_code");
+if (_rpython_startup_code == 0) {
+return 0;
+}
+if (dladdr(_rpython_startup_code, &info) != 0) {
+const char* lib_path = info.dli_fname;
+char* lib_realpath = realpath(lib_path, 0);
+return lib_realpath;
+}
+return 0;
+}
+
+
 Threading
 -
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: embedding.rst edited online with Bitbucket

2014-04-01 Thread vlukas
Author: Lukas Vacek 
Branch: 
Changeset: r70368:4221b74e1e8a
Date: 2014-03-24 23:26 +
http://bitbucket.org/pypy/pypy/changeset/4221b74e1e8a/

Log:embedding.rst edited online with Bitbucket

diff --git a/pypy/doc/embedding.rst b/pypy/doc/embedding.rst
--- a/pypy/doc/embedding.rst
+++ b/pypy/doc/embedding.rst
@@ -1,4 +1,3 @@
-
 Embedding PyPy
 --
 
@@ -51,6 +50,8 @@
 
 .. function:: int pypy_execute_source_ptr(char* source, void* ptr);
 
+   .. note:: Not available in <=2.2.1 yet
+   
Just like the above, except it registers a magic argument in the source
scope as ``c_argument``, where ``void*`` is encoded as Python int.
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: docs: embedding: Fixing simple example to include PyPy.h

2014-04-01 Thread vlukas
Author: Lukas Vacek 
Branch: 
Changeset: r70371:317174d5552a
Date: 2014-03-31 21:33 +0100
http://bitbucket.org/pypy/pypy/changeset/317174d5552a/

Log:docs: embedding: Fixing simple example to include PyPy.h

diff --git a/pypy/doc/embedding.rst b/pypy/doc/embedding.rst
--- a/pypy/doc/embedding.rst
+++ b/pypy/doc/embedding.rst
@@ -76,6 +76,7 @@
 
 .. code-block:: c
 
+#include "include/PyPy.h"
 #include 
 
 const char source[] = "print 'hello from pypy'";
@@ -101,6 +102,9 @@
 
 Worked!
 
+.. note:: If the compilation fails because of missing PyPy.h header file,
+  you are running PyPy <= 2.2.1, please see the section `Missing 
PyPy.h`_.
+
 Missing PyPy.h
 --
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Rename "interpret" to "normal-execution", now that it also includes the

2014-04-01 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r70373:eb3714149402
Date: 2014-04-01 09:34 +0200
http://bitbucket.org/pypy/pypy/changeset/eb3714149402/

Log:Rename "interpret" to "normal-execution", now that it also includes
the execution time in jit-generated machine code.

diff --git a/rpython/tool/logparser.py b/rpython/tool/logparser.py
--- a/rpython/tool/logparser.py
+++ b/rpython/tool/logparser.py
@@ -410,7 +410,7 @@
 total = sum([b for a, b in l])
 for a, b in l:
 if a is None:
-a = 'interpret'
+a = 'normal-execution'
 s = " " * (50 - len(a))
 print >>outfile, a, s, str(b*100/total) + "%"
 if out != '-':
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi default: Update exception args instead of use print on re-raise FFIError

2014-04-01 Thread mozbugbox
Author: mozbugbox 
Branch: 
Changeset: r1485:52c29b6665c2
Date: 2014-04-01 08:29 +0800
http://bitbucket.org/cffi/cffi/changeset/52c29b6665c2/

Log:Update exception args instead of use print on re-raise FFIError

diff --git a/cffi/cparser.py b/cffi/cparser.py
--- a/cffi/cparser.py
+++ b/cffi/cparser.py
@@ -207,7 +207,7 @@
 except api.FFIError as e:
 msg = self._convert_pycparser_error(e, csource)
 if msg:
-print("*** Error: %s" % msg)
+e.args = (e.args[0] + "\n*** Err: %s" % msg,)
 raise
 
 def _parse_decl(self, decl):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi default: Write out buggy line when exception during _internal_parse

2014-04-01 Thread mozbugbox
Author: mozbugbox 
Branch: 
Changeset: r1483:394b200a1724
Date: 2014-03-31 21:10 +0800
http://bitbucket.org/cffi/cffi/changeset/394b200a1724/

Log:Write out buggy line when exception during _internal_parse

diff --git a/cffi/cparser.py b/cffi/cparser.py
--- a/cffi/cparser.py
+++ b/cffi/cparser.py
@@ -128,9 +128,10 @@
 finally:
 if lock is not None:
 lock.release()
-return ast, macros
+# csource will be used to find buggy source text
+return ast, macros, csource
 
-def convert_pycparser_error(self, e, csource):
+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
@@ -142,6 +143,12 @@
 csourcelines = csource.splitlines()
 if 1 <= linenum <= len(csourcelines):
 line = csourcelines[linenum-1]
+return line
+
+def convert_pycparser_error(self, e, csource):
+line = self._convert_pycparser_error(e, csource)
+
+msg = str(e)
 if line:
 msg = 'cannot parse "%s"\n%s' % (line.strip(), msg)
 else:
@@ -160,7 +167,7 @@
 self._packed = prev_packed
 
 def _internal_parse(self, csource):
-ast, macros = self._parse(csource)
+ast, macros, csource = self._parse(csource)
 # add the macros
 for key, value in macros.items():
 value = value.strip()
@@ -176,26 +183,32 @@
 break
 #
 for decl in iterator:
-if isinstance(decl, pycparser.c_ast.Decl):
-self._parse_decl(decl)
-elif isinstance(decl, pycparser.c_ast.Typedef):
-if not decl.name:
-raise api.CDefError("typedef does not declare any name",
-decl)
-if (isinstance(decl.type.type, pycparser.c_ast.IdentifierType)
-and decl.type.type.names == ['__dotdotdot__']):
-realtype = model.unknown_type(decl.name)
-elif (isinstance(decl.type, pycparser.c_ast.PtrDecl) and
-  isinstance(decl.type.type, pycparser.c_ast.TypeDecl) and
-  isinstance(decl.type.type.type,
- pycparser.c_ast.IdentifierType) and
-  decl.type.type.type.names == ['__dotdotdot__']):
-realtype = model.unknown_ptr_type(decl.name)
+try:
+if isinstance(decl, pycparser.c_ast.Decl):
+self._parse_decl(decl)
+elif isinstance(decl, pycparser.c_ast.Typedef):
+if not decl.name:
+raise api.CDefError("typedef does not declare any 
name",
+decl)
+if (isinstance(decl.type.type, 
pycparser.c_ast.IdentifierType)
+and decl.type.type.names == ['__dotdotdot__']):
+realtype = model.unknown_type(decl.name)
+elif (isinstance(decl.type, pycparser.c_ast.PtrDecl) and
+  isinstance(decl.type.type, pycparser.c_ast.TypeDecl) 
and
+  isinstance(decl.type.type.type,
+ pycparser.c_ast.IdentifierType) and
+  decl.type.type.type.names == ['__dotdotdot__']):
+realtype = model.unknown_ptr_type(decl.name)
+else:
+realtype = self._get_type(decl.type, name=decl.name)
+self._declare('typedef ' + decl.name, realtype)
 else:
-realtype = self._get_type(decl.type, name=decl.name)
-self._declare('typedef ' + decl.name, realtype)
-else:
-raise api.CDefError("unrecognized construct", decl)
+raise api.CDefError("unrecognized construct", decl)
+except api.FFIError as e:
+msg = self._convert_pycparser_error(e, csource)
+if msg:
+print("*** Error: %s" % msg)
+raise
 
 def _parse_decl(self, decl):
 node = decl.type
@@ -227,7 +240,7 @@
 self._declare('variable ' + decl.name, tp)
 
 def parse_type(self, cdecl):
-ast, macros = self._parse('void __dummy(\n%s\n);' % cdecl)
+ast, macros = self._parse('void __dummy(\n%s\n);' % cdecl)[:2]
 assert not macros
 exprnode = ast.ext[-1].type.args.params[0]
 if isinstance(exprnode, pycparser.c_ast.ID):
@@ -306,7 +319,8 @@
 if ident == 'void':
 return model.void_type
 if ident == '__dotdotdot__':
-raise api.FFIError('bad usage of "..."')
+raise api.FFIError(':%d: bad usage of "..."'

[pypy-commit] lang-smalltalk storage: Added support for loading weak objects from an image. Important.

2014-04-01 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r733:9f145aa73461
Date: 2014-03-31 21:18 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/9f145aa73461/

Log:Added support for loading weak objects from an image. Important.
--strategy-stats can be used to see how many weak objects are loaded.
Extended the test for weak pointers.

diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -571,7 +571,7 @@
 pointers = g_self.get_pointers()
 # TODO -- Also handle weak objects loaded from images.
 from spyvm.shadow import find_storage_for_objects
-storage = find_storage_for_objects(space, pointers)(space, self, 
len(pointers))
+storage = find_storage_for_objects(space, pointers, 
g_self.isweak())(space, self, len(pointers))
 self.store_shadow(storage)
 self.store_all(space, pointers)
 self.log_storage("Filledin", log_classname=False)
diff --git a/spyvm/shadow.py b/spyvm/shadow.py
--- a/spyvm/shadow.py
+++ b/spyvm/shadow.py
@@ -170,13 +170,13 @@
 def empty_storage(space, w_self, size, weak=False):
 if weak:
 return WeakListStorageShadow(space, w_self, size)
-else:
-if no_specialized_storage:
-return ListStorageShadow(space, w_self, size)
-else:
-return AllNilStorageShadow(space, w_self, size)
+if no_specialized_storage:
+return ListStorageShadow(space, w_self, size)
+return AllNilStorageShadow(space, w_self, size)
 
-def find_storage_for_objects(space, vars):
+def find_storage_for_objects(space, vars, weak=False):
+if weak:
+return WeakListStorageShadow
 if no_specialized_storage:
 return ListStorageShadow
 specialized_strategies = 3
diff --git a/spyvm/squeakimage.py b/spyvm/squeakimage.py
--- a/spyvm/squeakimage.py
+++ b/spyvm/squeakimage.py
@@ -503,8 +503,11 @@
 return self.iswords() and 
self.space.w_Float.is_same_object(self.g_class.w_object)
 
 def ispointers(self):
-return self.format < 5 #TODO, what about compiled methods?
+return self.format < 5
 
+def isweak(self):
+return self.format == 4
+
 def iscompiledmethod(self):
 return 12 <= self.format <= 15
 
@@ -528,7 +531,6 @@
 # the instantiate call circumvents the constructors
 # and makes empty objects
 if self.ispointers():
-# XXX self.format == 4 is weak
 self.w_object = objectmodel.instantiate(model.W_PointersObject)
 elif self.format == 5:
 raise CorruptImageError("Unknown format 5")
diff --git a/spyvm/test/test_model.py b/spyvm/test/test_model.py
--- a/spyvm/test/test_model.py
+++ b/spyvm/test/test_model.py
@@ -419,13 +419,15 @@
 
 @py.test.mark.skipif("socket.gethostname() == 'precise32'")
 def test_weak_pointers():
-w_cls = bootstrap_class(1)
+w_cls = bootstrap_class(2)
 s_cls = w_cls.as_class_get_shadow(space)
 s_cls.instance_kind = WEAK_POINTERS
 
 weak_object = s_cls.new()
 referenced = model.W_SmallInteger(10)
+referenced2 = model.W_SmallInteger(20)
 weak_object.store(space, 0, referenced)
+weak_object.store(space, 1, referenced2)
 
 assert weak_object.fetch(space, 0) is referenced
 del referenced
@@ -433,3 +435,4 @@
 # Thus the reference may linger until the next gc...
 import gc; gc.collect()
 assert weak_object.fetch(space, 0).is_nil(space)
+assert weak_object.fetch(space, 1).value == 20
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage: Added test for interpreter.

2014-04-01 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r732:18eb8c008b4e
Date: 2014-03-31 21:04 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/18eb8c008b4e/

Log:Added test for interpreter.

diff --git a/spyvm/test/test_interpreter.py b/spyvm/test/test_interpreter.py
--- a/spyvm/test/test_interpreter.py
+++ b/spyvm/test/test_interpreter.py
@@ -890,10 +890,23 @@
 s_frame.push(w(fakeliterals(space, "baz")))
 step_in_interp(s_frame)
 array = s_frame.pop()
+assert array.size() == 3
 assert space.unwrap_array(array.at0(space, 0)) == fakeliterals(space, 
"egg")
 assert space.unwrap_array(array.at0(space, 1)) == fakeliterals(space, 
"bar")
 assert space.unwrap_array(array.at0(space, 2)) == fakeliterals(space, 
"baz")
 
+def test_bc_pushNewArrayBytecode_noPopIntoArray(bytecode=pushNewArrayBytecode):
+w_frame, s_frame = new_frame(bytecode + chr(0x02))
+s_frame.push(w("egg"))
+s_frame.push(w("bar"))
+step_in_interp(s_frame)
+array = s_frame.pop()
+assert array.size() == 2
+assert array.at0(space, 0).is_nil(space)
+assert array.at0(space, 1).is_nil(space)
+assert s_frame.pop().as_string() == "bar"
+assert s_frame.pop().as_string() == "egg"
+
 def test_bc_pushNewArray(bytecode=pushNewArrayBytecode):
 w_frame, s_frame = new_frame(bytecode + chr(0x07))
 step_in_interp(s_frame)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi default: Move try ... except outside of a for loop

2014-04-01 Thread mozbugbox
Author: mozbugbox 
Branch: 
Changeset: r1484:3d11d62d6ed9
Date: 2014-04-01 08:16 +0800
http://bitbucket.org/cffi/cffi/changeset/3d11d62d6ed9/

Log:Move try ... except outside of a for loop

diff --git a/cffi/cparser.py b/cffi/cparser.py
--- a/cffi/cparser.py
+++ b/cffi/cparser.py
@@ -182,8 +182,8 @@
 if decl.name == '__dotdotdot__':
 break
 #
-for decl in iterator:
-try:
+try:
+for decl in iterator:
 if isinstance(decl, pycparser.c_ast.Decl):
 self._parse_decl(decl)
 elif isinstance(decl, pycparser.c_ast.Typedef):
@@ -204,11 +204,11 @@
 self._declare('typedef ' + decl.name, realtype)
 else:
 raise api.CDefError("unrecognized construct", decl)
-except api.FFIError as e:
-msg = self._convert_pycparser_error(e, csource)
-if msg:
-print("*** Error: %s" % msg)
-raise
+except api.FFIError as e:
+msg = self._convert_pycparser_error(e, csource)
+if msg:
+print("*** Error: %s" % msg)
+raise
 
 def _parse_decl(self, decl):
 node = decl.type
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage: Fix to make the no_specialized_storage flag work.

2014-04-01 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r731:b645dc5a80e1
Date: 2014-03-31 20:00 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/b645dc5a80e1/

Log:Fix to make the no_specialized_storage flag work.

diff --git a/spyvm/shadow.py b/spyvm/shadow.py
--- a/spyvm/shadow.py
+++ b/spyvm/shadow.py
@@ -65,6 +65,9 @@
 return self._w_self.store_with_new_storage(new_storage, n0, w_val)
 def can_contain(self, w_val):
 return self.static_can_contain(self.space, w_val)
+@staticmethod
+def static_can_contain(space, w_val):
+raise NotImplementedError()
 def do_store(self, n0, w_val):
 raise NotImplementedError()
 def generalized_strategy_for(self, w_val):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage: Enhanced tracing-output of interpreter.

2014-04-01 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r735:1bfa9310d02a
Date: 2014-04-01 10:52 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/1bfa9310d02a/

Log:Enhanced tracing-output of interpreter.

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -18,7 +18,7 @@
 
 def get_printable_location(pc, self, method):
 bc = ord(method.bytes[pc])
-name = method._likely_methodname
+name = method.get_identifier_string()
 return '%d: [%s]%s (%s)' % (pc, hex(bc), BYTECODE_NAMES[bc], name)
 
 
@@ -355,8 +355,8 @@
 def _sendSelector(self, w_selector, argcount, interp,
   receiver, receiverclassshadow):
 if interp.should_trace():
-print "%sSending selector %r to %r with: %r" % (
-interp._last_indent, w_selector.as_repr_string(), receiver,
+print "%sSending selector #%s to %r with: %r" % (
+interp._last_indent, w_selector.as_string(), receiver,
 [self.peek(argcount-1-i) for i in range(argcount)])
 assert argcount >= 0
 
@@ -402,7 +402,7 @@
 
 # 
##
 if interp.trace:
-print '%s%s missing: #%s' % (interp.padding('#'), 
s_frame.short_str(), w_selector.as_repr_string())
+print '%s%s missing: #%s' % (interp.padding('#'), 
s_frame.short_str(), w_selector.as_string())
 if not objectmodel.we_are_translated():
 import pdb; pdb.set_trace()
 
@@ -415,9 +415,9 @@
 func = primitives.prim_holder.prim_table[code]
 # ##
 if interp.trace:
-print "%s-> primitive %d \t(in #%s, named #%s)" % (
+print "%s-> primitive %d \t(in %s, named #%s)" % (
 ' ' * (interp.max_stack_depth - interp.remaining_stack_depth),
-code, self.w_method()._likely_methodname, 
w_selector.as_repr_string())
+code, self.w_method().get_identifier_string(), 
w_selector.as_string())
 try:
 # note: argcount does not include rcvr
 return func(interp, self, argcount, w_method)
@@ -427,7 +427,7 @@
 ' ' * (interp.max_stack_depth - interp.remaining_stack_depth),)
 
 if interp.should_trace(True):
-print "PRIMITIVE FAILED: %d %s" % (w_method.primitive, 
w_selector.as_repr_string())
+print "PRIMITIVE FAILED: %d #%s" % (w_method.primitive, 
w_selector.as_string())
 raise e
 
 
@@ -895,19 +895,19 @@
   receiver, receiverclassshadow):
 options = [False]
 def next(): interp.message_stepping = True; print 'Now continue 
(c).'
-def over(): options[0] = True; print  'Skipping #%s. You still 
need to continue(c).' % w_selector.as_repr_string()
+def over(): options[0] = True; print  'Skipping #%s. You still 
need to continue(c).' % w_selector.as_string()
 def pstack(): print s_context.print_stack()
 if interp.message_stepping:
 if argcount == 0:
-print "-> %s %s" % (receiver.as_repr_string(),
-w_selector.as_repr_string())
+print "-> %s #%s" % (receiver.as_repr_string(),
+w_selector.as_string())
 elif argcount == 1:
-print "-> %s %s %s" % (receiver.as_repr_string(),
-w_selector.as_repr_string(),
+print "-> %s #%s %s" % (receiver.as_repr_string(),
+w_selector.as_string(),
 s_context.peek(0).as_repr_string())
 else:
-print "-> %s %s %r" % (receiver.as_repr_string(),
-w_selector.as_repr_string(),
+print "-> %s #%s %r" % (receiver.as_repr_string(),
+w_selector.as_string(),
 [s_context.peek(argcount-1-i) for i in 
range(argcount)])
 import pdb; pdb.set_trace()
 if options[0]:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage: Refined the compiled_in() method in CompiledMethod.

2014-04-01 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r734:7637f57d242e
Date: 2014-04-01 10:51 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/7637f57d242e/

Log:Refined the compiled_in() method in CompiledMethod.

diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -127,6 +127,12 @@
 """Return True, if the receiver represents the nil object in the given 
Object Space."""
 return self.is_same_object(space.w_nil)
 
+def is_class(self, space):
+""" Return true, if the receiver seems to be a class.
+We can not be completely sure about this (non-class objects might be
+used as class)."""
+return False
+
 def become(self, other):
 """Become swaps two objects.
False means swapping failed"""
@@ -509,12 +515,23 @@
 # Don't construct the ClassShadow here, yet!
 self.w_class = g_self.get_class()
 
+def is_class(self, space):
+# This is a class if it's a Metaclass or an instance of a Metaclass.
+if self.has_class():
+w_Metaclass = space.classtable["w_Metaclass"]
+w_class = self.getclass(space)
+if w_Metaclass.is_same_object(w_class):
+return True
+if w_class.has_class():
+return w_Metaclass.is_same_object(w_class.getclass(space))
+return False
+
 def getclass(self, space):
 return self.w_class
 
 def guess_classname(self):
 if self.has_class():
-if self.w_class.has_shadow():
+if self.w_class.has_space():
 class_shadow = self.class_shadow(self.w_class.space())
 return class_shadow.name
 else:
@@ -580,6 +597,12 @@
 from shadow import WeakListStorageShadow
 return isinstance(self.shadow, WeakListStorageShadow)
 
+def is_class(self, space):
+from spyvm.shadow import ClassShadow
+if isinstance(self.shadow, ClassShadow):
+return True
+return W_AbstractObjectWithClassReference.is_class(self, space)
+
 def assert_shadow(self):
 # Failing the following assert most likely indicates a bug. The shadow 
can only be absent during
 # the bootstrapping sequence. It will be initialized in the fillin() 
method. Before that, it should
@@ -715,6 +738,10 @@
 def has_shadow(self):
 return self._get_shadow() is not None
 
+def has_space(self):
+# The space is accessed through the shadow.
+return self.has_shadow()
+
 def _become(self, w_other):
 assert isinstance(w_other, W_PointersObject)
 self.shadow, w_other.shadow = w_other.shadow, self.shadow
@@ -1258,16 +1285,21 @@
 def compiled_in(self):
 w_compiledin = self.w_compiledin
 if not w_compiledin:
-if self.literals:
-# (Blue book, p 607) All CompiledMethods that contain
-# extended-super bytecodes have the clain which they are found 
as
-# their last literal variable.
-# Last of the literals is an association with compiledin as a 
class
-w_association = self.literals[-1]
-if isinstance(w_association, W_PointersObject) and 
w_association.size() >= 2:
-from spyvm import wrapper
-association = 
wrapper.AssociationWrapper(w_association.space(), w_association)
-w_compiledin = association.value()
+literals = self.literals
+if literals and len(literals) > 0:
+# (Blue book, p 607) Last of the literals is either the 
containing class 
+# or an association with compiledin as a class
+w_candidate = literals[-1]
+if isinstance(w_candidate, W_PointersObject) and 
w_candidate.has_space():
+space = w_candidate.space() # Not pretty to steal the 
space from another object.
+if w_candidate.is_class(space):
+w_compiledin = w_candidate
+elif w_candidate.size() >= 2:
+from spyvm import wrapper
+association = wrapper.AssociationWrapper(space, 
w_candidate)
+w_candidate = association.value()
+if w_candidate.is_class(space):
+w_compiledin = w_candidate
 self.w_compiledin = w_compiledin
 return w_compiledin
 
@@ -1378,29 +1410,11 @@
 return retval + "-\n"
 
 def guess_containing_classname(self):
-from spyvm.shadow import ClassShadow
-guessed_classname = None
-if len(self.literals) > 0:
-w_candidate = self.literals[-1]
-if isinstance(w_candidate, W_PointersObject):
-c_shadow = w_candidate._get_shadow()
-i

[pypy-commit] pypy default: make os.fdopen rpython

2014-04-01 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r70374:495dc5472421
Date: 2014-04-01 11:21 +0200
http://bitbucket.org/pypy/pypy/changeset/495dc5472421/

Log:make os.fdopen rpython

diff --git a/rpython/flowspace/specialcase.py b/rpython/flowspace/specialcase.py
--- a/rpython/flowspace/specialcase.py
+++ b/rpython/flowspace/specialcase.py
@@ -49,6 +49,11 @@
 from rpython.rlib.rfile import create_file
 return ctx.appcall(create_file, *args_w)
 
+@register_flow_sc(os.fdopen)
+def sc_os_fdopen(ctx, *args_w):
+from rpython.rlib.rfile import create_fdopen_rfile
+return ctx.appcall(create_fdopen_rfile, *args_w)
+
 @register_flow_sc(os.tmpfile)
 def sc_os_tmpfile(ctx):
 from rpython.rlib.rfile import create_temp_rfile
diff --git a/rpython/rlib/rfile.py b/rpython/rlib/rfile.py
--- a/rpython/rlib/rfile.py
+++ b/rpython/rlib/rfile.py
@@ -47,6 +47,7 @@
  rffi.INT)
 c_tmpfile = llexternal('tmpfile', [], lltype.Ptr(FILE))
 c_fileno = llexternal(fileno, [lltype.Ptr(FILE)], rffi.INT)
+c_fdopen = llexternal('fdopen', [rffi.INT, rffi.CCHARP], lltype.Ptr(FILE))
 c_ftell = llexternal('ftell', [lltype.Ptr(FILE)], rffi.LONG)
 c_fflush = llexternal('fflush', [lltype.Ptr(FILE)], rffi.INT)
 c_ftruncate = llexternal(ftruncate, [rffi.INT, OFF_T], rffi.INT, macro=True)
@@ -93,6 +94,17 @@
 raise OSError(errno, os.strerror(errno))
 return RFile(res)
 
+def create_fdopen_rfile(fd, mode="r"):
+assert mode is not None
+ll_mode = rffi.str2charp(mode)
+try:
+ll_f = c_fdopen(rffi.cast(rffi.INT, fd), ll_mode)
+if not ll_f:
+errno = rposix.get_errno()
+raise OSError(errno, os.strerror(errno))
+finally:
+lltype.free(ll_mode, flavor='raw')
+return RFile(ll_f)
 
 def create_popen_file(command, type):
 ll_command = rffi.str2charp(command)
diff --git a/rpython/rlib/test/test_rfile.py b/rpython/rlib/test/test_rfile.py
--- a/rpython/rlib/test/test_rfile.py
+++ b/rpython/rlib/test/test_rfile.py
@@ -79,6 +79,22 @@
 f()
 self.interpret(f, [])
 
+def test_fdopen(self):
+fname = str(self.tmpdir.join('file_4a'))
+
+def f():
+f = open(fname, "w")
+new_fno = os.dup(f.fileno())
+f2 = os.fdopen(new_fno, "w")
+f.close()
+f2.write("xxx")
+f2.close()
+
+f()
+assert open(fname).read() == "xxx"
+self.interpret(f, [])
+assert open(fname).read() == "xxx"
+
 def test_fileno(self):
 fname = str(self.tmpdir.join('file_5'))
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: merge

2014-04-01 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r70375:d4d584ff67d3
Date: 2014-04-01 11:22 +0200
http://bitbucket.org/pypy/pypy/changeset/d4d584ff67d3/

Log:merge

diff --git a/pypy/doc/embedding.rst b/pypy/doc/embedding.rst
--- a/pypy/doc/embedding.rst
+++ b/pypy/doc/embedding.rst
@@ -51,6 +51,8 @@
 
 .. function:: int pypy_execute_source_ptr(char* source, void* ptr);
 
+   .. note:: Not available in PyPy <= 2.2.1
+   
Just like the above, except it registers a magic argument in the source
scope as ``c_argument``, where ``void*`` is encoded as Python int.
 
@@ -100,9 +102,29 @@
 
 Worked!
 
+.. note:: If the compilation fails because of missing PyPy.h header file,
+  you are running PyPy <= 2.2.1, please see the section `Missing 
PyPy.h`_.
+
+Missing PyPy.h
+--
+
+.. note:: PyPy.h is in the nightly builds and goes to new PyPy releases 
(>2.2.1).
+
+For PyPy <= 2.2.1, you can download PyPy.h from PyPy repository (it has been 
added in commit c4cd6ec):
+
+.. code-block:: bash
+
+cd /opt/pypy/include
+wget 
https://bitbucket.org/pypy/pypy/raw/c4cd6eca9358066571500ac82aaacfdaa3889e8c/include/PyPy.h
+
+
 More advanced example
 -
 
+.. note:: This example depends on pypy_execute_source_ptr which is not 
available
+  in PyPy <= 2.2.1. You might want to see the alternative example
+  below.
+
 Typically we need something more to do than simply execute source. The 
following
 is a fully fledged example, please consult cffi documentation for details.
 It's a bit longish, but it captures a gist what can be done with the PyPy
@@ -161,6 +183,97 @@
 is that we would pass a struct full of callbacks to ``pypy_execute_source_ptr``
 and fill the structure from Python side for the future use.
 
+Alternative example
+---
+
+As ``pypy_execute_source_ptr`` is not available in PyPy 2.2.1, you might want 
to try 
+an alternative approach which relies on -export-dynamic flag to the GNU 
linker. 
+The downside to this approach is that it is platform dependent.
+
+.. code-block:: c
+
+#include "include/PyPy.h"
+#include 
+
+char source[] = "from cffi import FFI\n\
+ffi = FFI()\n\
+@ffi.callback('int(int)')\n\
+def func(a):\n\
+print 'Got from C %d' % a\n\
+return a * 2\n\
+ffi.cdef('int callback(int (*func)(int));')\n\
+lib = ffi.verify('int callback(int (*func)(int));')\n\
+lib.callback(func)\n\
+print 'finished the Python part'\n\
+";
+
+int callback(int (*func)(int))
+{
+printf("Calling to Python, result: %d\n", func(3));
+}
+
+int main()
+{
+int res;
+void *lib, *func;
+
+rpython_startup_code();
+res = pypy_setup_home("/opt/pypy/bin/libpypy-c.so", 1);
+if (res) {
+printf("Error setting pypy home!\n");
+return 1;
+}
+res = pypy_execute_source(source);
+if (res) {
+printf("Error calling pypy_execute_source!\n");
+}
+return res;
+}
+
+
+Make sure to pass -export-dynamic flag when compiling::
+
+   $ gcc -g -o x x.c -lpypy-c -L. -export-dynamic
+   $ LD_LIBRARY_PATH=. ./x
+   Got from C 3
+   Calling to Python, result: 6
+   finished the Python part
+
+Finding pypy_home
+-
+
+Function pypy_setup_home takes one parameter - the path to libpypy. There's 
+currently no "clean" way (pkg-config comes to mind) how to find this path. You 
+can try the following (GNU-specific) hack (don't forget to link against *dl*):
+
+.. code-block:: c
+
+#if !(_GNU_SOURCE)
+#define _GNU_SOURCE
+#endif
+
+#include 
+#include 
+#include 
+
+// caller should free returned pointer to avoid memleaks
+// returns NULL on error
+char* guess_pypyhome() {
+// glibc-only (dladdr is why we #define _GNU_SOURCE)
+Dl_info info;
+void *_rpython_startup_code = dlsym(0,"rpython_startup_code");
+if (_rpython_startup_code == 0) {
+return 0;
+}
+if (dladdr(_rpython_startup_code, &info) != 0) {
+const char* lib_path = info.dli_fname;
+char* lib_realpath = realpath(lib_path, 0);
+return lib_realpath;
+}
+return 0;
+}
+
+
 Threading
 -
 
diff --git a/rpython/tool/logparser.py b/rpython/tool/logparser.py
--- a/rpython/tool/logparser.py
+++ b/rpython/tool/logparser.py
@@ -410,7 +410,7 @@
 total = sum([b for a, b in l])
 for a, b in l:
 if a is None:
-a = 'interpret'
+a = 'normal-execution'
 s = " " * (50 - len(a))
 print >>outfile, a, s, str(b*100/total) + "%"
 if out != '-':
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage: Fixed compilation.

2014-04-01 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r736:5713bb4e171f
Date: 2014-04-01 11:53 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/5713bb4e171f/

Log:Fixed compilation.

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -18,7 +18,7 @@
 
 def get_printable_location(pc, self, method):
 bc = ord(method.bytes[pc])
-name = method.get_identifier_string()
+name = method.safe_identifier_string()
 return '%d: [%s]%s (%s)' % (pc, hex(bc), BYTECODE_NAMES[bc], name)
 
 
@@ -356,7 +356,7 @@
   receiver, receiverclassshadow):
 if interp.should_trace():
 print "%sSending selector #%s to %r with: %r" % (
-interp._last_indent, w_selector.as_string(), receiver,
+interp._last_indent, w_selector.str_content(), receiver,
 [self.peek(argcount-1-i) for i in range(argcount)])
 assert argcount >= 0
 
@@ -402,7 +402,7 @@
 
 # 
##
 if interp.trace:
-print '%s%s missing: #%s' % (interp.padding('#'), 
s_frame.short_str(), w_selector.as_string())
+print '%s%s missing: #%s' % (interp.padding('#'), 
s_frame.short_str(), w_selector.str_content())
 if not objectmodel.we_are_translated():
 import pdb; pdb.set_trace()
 
@@ -417,7 +417,7 @@
 if interp.trace:
 print "%s-> primitive %d \t(in %s, named #%s)" % (
 ' ' * (interp.max_stack_depth - interp.remaining_stack_depth),
-code, self.w_method().get_identifier_string(), 
w_selector.as_string())
+code, self.w_method().get_identifier_string(), 
w_selector.str_content())
 try:
 # note: argcount does not include rcvr
 return func(interp, self, argcount, w_method)
@@ -427,7 +427,7 @@
 ' ' * (interp.max_stack_depth - interp.remaining_stack_depth),)
 
 if interp.should_trace(True):
-print "PRIMITIVE FAILED: %d #%s" % (w_method.primitive, 
w_selector.as_string())
+print "PRIMITIVE FAILED: %d #%s" % (w_method.primitive, 
w_selector.str_content())
 raise e
 
 
@@ -895,19 +895,19 @@
   receiver, receiverclassshadow):
 options = [False]
 def next(): interp.message_stepping = True; print 'Now continue 
(c).'
-def over(): options[0] = True; print  'Skipping #%s. You still 
need to continue(c).' % w_selector.as_string()
+def over(): options[0] = True; print  'Skipping #%s. You still 
need to continue(c).' % w_selector.str_content()
 def pstack(): print s_context.print_stack()
 if interp.message_stepping:
 if argcount == 0:
 print "-> %s #%s" % (receiver.as_repr_string(),
-w_selector.as_string())
+w_selector.str_content())
 elif argcount == 1:
 print "-> %s #%s %s" % (receiver.as_repr_string(),
-w_selector.as_string(),
+w_selector.str_content(),
 s_context.peek(0).as_repr_string())
 else:
 print "-> %s #%s %r" % (receiver.as_repr_string(),
-w_selector.as_string(),
+w_selector.str_content(),
 [s_context.peek(argcount-1-i) for i in 
range(argcount)])
 import pdb; pdb.set_trace()
 if options[0]:
diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -817,7 +817,7 @@
 return self._size
 
 def str_content(self):
-return "'%s'" % self.as_string()
+return self.as_string()
 
 def as_string(self):
 if self.bytes is not None:
@@ -1301,6 +1301,7 @@
 if w_candidate.is_class(space):
 w_compiledin = w_candidate
 self.w_compiledin = w_compiledin
+assert isinstance(w_compiledin, W_PointersObject)
 return w_compiledin
 
 # === Object Access ===
@@ -1419,6 +1420,19 @@
 def get_identifier_string(self):
 return "%s >> #%s" % (self.guess_containing_classname(), 
self._likely_methodname)
 
+def safe_identifier_string(self):
+if not we_are_translated():
+return self.get_identifier_string()
+# This has the same functionality as get_identifier_string, but 
without calling any
+# methods in order to avoid side effects that prevent translation.
+w_class = self.w_compiledin
+if isinstance(w_class, W_PointersObject):
+from spyvm.shadow import ClassShadow
+s_class = w_class.shadow
+if isinstance(s_class, ClassShadow):
+   

[pypy-commit] pypy default: causes crashes on posix

2014-04-01 Thread mattip
Author: Matti Picus 
Branch: 
Changeset: r70376:d0a0274a6fbe
Date: 2014-04-01 16:39 +0200
http://bitbucket.org/pypy/pypy/changeset/d0a0274a6fbe/

Log:causes crashes on posix

diff --git a/lib_pypy/_ctypes/function.py b/lib_pypy/_ctypes/function.py
--- a/lib_pypy/_ctypes/function.py
+++ b/lib_pypy/_ctypes/function.py
@@ -219,7 +219,6 @@
 if restype is None:
 import ctypes
 restype = ctypes.c_int
-self._argtypes_ = argsl
 self._ptr = self._getfuncptr_fromaddress(self._argtypes_, restype)
 self._check_argtypes_for_fastpath()
 return
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Merged in aliceinwire/pypy (pull request #221)

2014-04-01 Thread rlamy
Author: Ronan Lamy 
Branch: 
Changeset: r70378:e110863e2400
Date: 2014-04-01 20:57 +0100
http://bitbucket.org/pypy/pypy/changeset/e110863e2400/

Log:Merged in aliceinwire/pypy (pull request #221)

fix small typo

diff --git a/pypy/interpreter/app_main.py b/pypy/interpreter/app_main.py
--- a/pypy/interpreter/app_main.py
+++ b/pypy/interpreter/app_main.py
@@ -690,7 +690,7 @@
 
 def setup_bootstrap_path(executable):
 """
-Try to to as little as possible and to have the stdlib in sys.path. In
+Try to do as little as possible and to have the stdlib in sys.path. In
 particular, we cannot use any unicode at this point, because lots of
 unicode operations require to be able to import encodings.
 """
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: fix small typo

2014-04-01 Thread aliceinwire
Author: aliceinwire
Branch: 
Changeset: r70377:f64f5a091463
Date: 2014-04-01 17:50 +0900
http://bitbucket.org/pypy/pypy/changeset/f64f5a091463/

Log:fix small typo

diff --git a/pypy/interpreter/app_main.py b/pypy/interpreter/app_main.py
--- a/pypy/interpreter/app_main.py
+++ b/pypy/interpreter/app_main.py
@@ -690,7 +690,7 @@
 
 def setup_bootstrap_path(executable):
 """
-Try to to as little as possible and to have the stdlib in sys.path. In
+Try to do as little as possible and to have the stdlib in sys.path. In
 particular, we cannot use any unicode at this point, because lots of
 unicode operations require to be able to import encodings.
 """
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: Py3-ify some cpyext tests.

2014-04-01 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: py3k
Changeset: r70379:0f088917abce
Date: 2014-04-01 22:17 +0200
http://bitbucket.org/pypy/pypy/changeset/0f088917abce/

Log:Py3-ify some cpyext tests.

diff --git a/pypy/module/cpyext/test/test_pyerrors.py 
b/pypy/module/cpyext/test/test_pyerrors.py
--- a/pypy/module/cpyext/test/test_pyerrors.py
+++ b/pypy/module/cpyext/test/test_pyerrors.py
@@ -222,14 +222,14 @@
 assert exc_info.value.errno == errno.EBADF
 assert exc_info.value.strerror == os.strerror(errno.EBADF)
 
-def test_SetFromErrnoWithFilenameObject__PyString(self):
+def test_SetFromErrnoWithFilenameObject__PyUnicode(self):
 import errno, os
 
 module = self.import_extension('foo', [
 ("set_from_errno", "METH_NOARGS",
  '''
  errno = EBADF;
- PyObject *filenameObject = 
PyString_FromString("/path/to/file");
+ PyObject *filenameObject = 
PyUnicode_FromString("/path/to/file");
  PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, 
filenameObject);
  Py_DECREF(filenameObject);
  return NULL;
@@ -241,14 +241,14 @@
 assert exc_info.value.errno == errno.EBADF
 assert exc_info.value.strerror == os.strerror(errno.EBADF)
 
-def test_SetFromErrnoWithFilenameObject__PyInt(self):
+def test_SetFromErrnoWithFilenameObject__PyLong(self):
 import errno, os
 
 module = self.import_extension('foo', [
 ("set_from_errno", "METH_NOARGS",
  '''
  errno = EBADF;
- PyObject *intObject = PyInt_FromLong(3);
+ PyObject *intObject = PyLong_FromLong(3);
  PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, 
intObject);
  Py_DECREF(intObject);
  return NULL;
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: complete the other half of f43ca379c4c9, Popen with shell=True passes env properly on win32

2014-04-01 Thread mattip
Author: Matti Picus 
Branch: 
Changeset: r70381:6513cd57d9d5
Date: 2014-04-01 23:36 +0300
http://bitbucket.org/pypy/pypy/changeset/6513cd57d9d5/

Log:complete the other half of f43ca379c4c9, Popen with shell=True
passes env properly on win32

diff --git a/rpython/tool/runsubprocess.py b/rpython/tool/runsubprocess.py
--- a/rpython/tool/runsubprocess.py
+++ b/rpython/tool/runsubprocess.py
@@ -11,6 +11,9 @@
 def run_subprocess(executable, args, env=None, cwd=None):
 return _run(executable, args, env, cwd)
 
+shell_default = False
+if sys.platform == 'win32':
+shell_default = True
 
 def _run(executable, args, env, cwd):   # unless overridden below
 if isinstance(args, str):
@@ -21,7 +24,9 @@
 args = [str(executable)]
 else:
 args = [str(executable)] + args
-shell = False
+# shell=True on unix-like is a known security vulnerability, but
+# on windows shell=True does not properly propogate the env dict
+shell = shell_default
 
 # Just before spawning the subprocess, do a gc.collect().  This
 # should help if we are running on top of PyPy, if the subprocess
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: document merged branch

2014-04-01 Thread mattip
Author: Matti Picus 
Branch: 
Changeset: r70382:a00fc425d947
Date: 2014-04-01 23:38 +0300
http://bitbucket.org/pypy/pypy/changeset/a00fc425d947/

Log:document merged branch

diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -127,3 +127,6 @@
 
 .. branch: win32-fixes4
 fix more tests for win32
+
+.. branch: latest-improve-doc
+Fix broken links in documentation
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k-fix-strategies: branch for fixing/adapting the list/dict/etc strategies that were disabled

2014-04-01 Thread pjenvey
Author: Philip Jenvey 
Branch: py3k-fix-strategies
Changeset: r70383:557b939aefd3
Date: 2014-04-01 13:34 -0700
http://bitbucket.org/pypy/pypy/changeset/557b939aefd3/

Log:branch for fixing/adapting the list/dict/etc strategies that were
disabled while focusing on py3k compat

diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -1192,13 +1192,13 @@
 w_ann = None
 if num_annotations:
 names_w = space.fixedview(self.popvalue())
-w_ann = space.newdict(strdict=True)
+w_ann = space.newdict(strdict=True) # XXX: strdict??
 for i in range(len(names_w) - 1, -1, -1):
 space.setitem(w_ann, names_w[i], self.popvalue())
 defaultarguments = self.popvalues(posdefaults)
 w_kw_defs = None
 if kwdefaults:
-w_kw_defs = space.newdict(strdict=True)
+w_kw_defs = space.newdict(strdict=True) # XXX:
 for i in range(kwdefaults - 1, -1, -1):
 w_name = self.popvalue()
 w_def = self.popvalue()
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
@@ -58,7 +58,7 @@
 #elif instance or strdict or module:
 #assert w_type is None
 #strategy = space.fromcache(BytesDictStrategy)
-elif False and kwargs:
+elif kwargs:
 assert w_type is None
 from pypy.objspace.std.kwargsdict import EmptyKwargsDictStrategy
 strategy = space.fromcache(EmptyKwargsDictStrategy)
@@ -500,7 +500,7 @@
 w_dict.setitem(w_key, w_value)
 
 def setitem_str(self, w_dict, key, w_value):
-self.switch_to_bytes_strategy(w_dict)
+self.switch_to_unicode_strategy(w_dict)
 w_dict.setitem_str(key, w_value)
 
 def delitem(self, w_dict, w_key):
@@ -829,6 +829,7 @@
 def _never_equal_to(self, w_lookup_type):
 return _never_equal_to_string(self.space, w_lookup_type)
 
+"""
 def setitem_str(self, w_dict, key, w_value):
 assert key is not None
 self.unerase(w_dict.dstorage)[key] = w_value
@@ -844,6 +845,7 @@
 def getitem_str(self, w_dict, key):
 assert key is not None
 return self.unerase(w_dict.dstorage).get(key, None)
+"""
 
 def listview_bytes(self, w_dict):
 return self.unerase(w_dict.dstorage).keys()
@@ -896,43 +898,47 @@
 
 # we should implement the same shortcuts as we do for BytesDictStrategy
 
-## def setitem_str(self, w_dict, key, w_value):
-## assert key is not None
-## self.unerase(w_dict.dstorage)[key] = w_value
+def setitem_str(self, w_dict, key, w_value):
+assert key is not None
+self.unerase(w_dict.dstorage)[key.decode('ascii')] = w_value
 
-## def getitem(self, w_dict, w_key):
-## space = self.space
-## # -- This is called extremely often.  Hack for performance --
-## if type(w_key) is space.StringObjectCls:
-## return self.getitem_str(w_dict, w_key.unwrap(space))
-## # -- End of performance hack --
-## return AbstractTypedStrategy.getitem(self, w_dict, w_key)
+def getitem(self, w_dict, w_key):
+space = self.space
+# -- This is called extremely often.  Hack for performance --
+if type(w_key) is space.StringObjectCls:
+#return self.getitem_str(w_dict, w_key.unwrap(space))
+# XXX:
+key = w_key.unwrap(space)
+return self.unerase(w_dict.dstorage).get(key, None)
+# -- End of performance hack --
+return AbstractTypedStrategy.getitem(self, w_dict, w_key)
 
-## def getitem_str(self, w_dict, key):
-## assert key is not None
-## return self.unerase(w_dict.dstorage).get(key, None)
+def getitem_str(self, w_dict, key):
+assert key is not None
+return self.unerase(w_dict.dstorage).get(key.decode('utf-8'), None)
 
 def listview_unicode(self, w_dict):
 return self.unerase(w_dict.dstorage).keys()
 
-## def w_keys(self, w_dict):
-## return self.space.newlist_bytes(self.listview_bytes(w_dict))
+#def w_keys(self, w_dict):
+## XXX: I think we can completely kill w_keys...
+#return self.space.newlist_str(self.listview_str(w_dict))
 
 def wrapkey(space, key):
 return space.wrap(key)
 
-## @jit.look_inside_iff(lambda self, w_dict:
-##  w_dict_unrolling_heuristic(w_dict))
-## def view_as_kwargs(self, w_dict):
-## d = self.unerase(w_dict.dstorage)
-## l = len(d)
-## keys, values = [None] * l, [None] * l
-## i = 0
-## for key, val in d.iteritems():
-## keys[i] = key
-## values[i] = val
-## i += 1
-## return keys, va

[pypy-commit] pypy default: remove read-only files in stdlib tests, also filed issue21128 with cpython

2014-04-01 Thread mattip
Author: Matti Picus 
Branch: 
Changeset: r70384:548126e2b490
Date: 2014-04-02 01:24 +0300
http://bitbucket.org/pypy/pypy/changeset/548126e2b490/

Log:remove read-only files in stdlib tests, also filed issue21128 with
cpython

diff --git a/lib-python/2.7/test/test_argparse.py 
b/lib-python/2.7/test/test_argparse.py
--- a/lib-python/2.7/test/test_argparse.py
+++ b/lib-python/2.7/test/test_argparse.py
@@ -10,6 +10,7 @@
 import tempfile
 import unittest
 import argparse
+import gc
 
 from StringIO import StringIO
 
@@ -47,7 +48,11 @@
 
 def tearDown(self):
 os.chdir(self.old_dir)
-shutil.rmtree(self.temp_dir, True)
+gc.collect()
+for root, dirs, files in os.walk(self.temp_dir, topdown=False):
+for name in files:
+os.chmod(os.path.join(self.temp_dir, name), stat.S_IWRITE)
+shutil.rmtree(self.temp_dir, True)
 
 def create_readonly_file(self, filename):
 file_path = os.path.join(self.temp_dir, filename)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy ast-issue1673: add doc for ast-issue1673 branch in whatsnew-head.rst

2014-04-01 Thread wenzhuman
Author: wenzhuman 
Branch: ast-issue1673
Changeset: r70385:dfd4cc308b91
Date: 2014-04-01 17:38 -0400
http://bitbucket.org/pypy/pypy/changeset/dfd4cc308b91/

Log:add doc for ast-issue1673 branch in whatsnew-head.rst

diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -127,3 +127,7 @@
 
 .. branch: win32-fixes4
 fix more tests for win32
+
+.. branch: ast-issue1673
+fix ast classes __dict__ are always empty problem and fix the ast deepcopy 
issue when 
+there is missing field
\ No newline at end of file
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: merge branch ast-issue1673

2014-04-01 Thread rlamy
Author: Ronan Lamy 
Branch: 
Changeset: r70387:e504b1f999df
Date: 2014-04-01 23:40 +0100
http://bitbucket.org/pypy/pypy/changeset/e504b1f999df/

Log:merge branch ast-issue1673

diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -130,3 +130,7 @@
 
 .. branch: latest-improve-doc
 Fix broken links in documentation
+
+.. branch: ast-issue1673
+fix ast classes __dict__ are always empty problem and fix the ast deepcopy 
issue when 
+there is missing field
\ No newline at end of file
diff --git a/pypy/interpreter/astcompiler/ast.py 
b/pypy/interpreter/astcompiler/ast.py
--- a/pypy/interpreter/astcompiler/ast.py
+++ b/pypy/interpreter/astcompiler/ast.py
@@ -49,13 +49,19 @@
 w_type = space.type(self)
 w_fields = w_type.getdictvalue(space, "_fields")
 for w_name in space.fixedview(w_fields):
-space.setitem(w_dict, w_name,
+try:
+space.setitem(w_dict, w_name,
   space.getattr(self, w_name))
+except OperationError:
+pass
 w_attrs = space.findattr(w_type, space.wrap("_attributes"))
 if w_attrs:
 for w_name in space.fixedview(w_attrs):
-space.setitem(w_dict, w_name,
+try:
+space.setitem(w_dict, w_name,
   space.getattr(self, w_name))
+except OperationError:
+pass
 return space.newtuple([space.type(self),
space.newtuple([]),
w_dict])
@@ -3011,7 +3017,8 @@
 w_self.setdictvalue(space, 'lineno', w_new_value)
 w_self.initialization_state &= ~1
 return
-w_self.deldictvalue(space, 'lineno')
+# need to save the original object too
+w_self.setdictvalue(space, 'lineno', w_new_value)
 w_self.initialization_state |= 1
 
 def stmt_del_lineno(space, w_self):
@@ -3038,7 +3045,8 @@
 w_self.setdictvalue(space, 'col_offset', w_new_value)
 w_self.initialization_state &= ~2
 return
-w_self.deldictvalue(space, 'col_offset')
+# need to save the original object too
+w_self.setdictvalue(space, 'col_offset', w_new_value)
 w_self.initialization_state |= 2
 
 def stmt_del_col_offset(space, w_self):
@@ -3074,7 +3082,8 @@
 w_self.setdictvalue(space, 'name', w_new_value)
 w_self.initialization_state &= ~4
 return
-w_self.deldictvalue(space, 'name')
+# need to save the original object too
+w_self.setdictvalue(space, 'name', w_new_value)
 w_self.initialization_state |= 4
 
 def FunctionDef_del_name(space, w_self):
@@ -3201,7 +3210,8 @@
 w_self.setdictvalue(space, 'name', w_new_value)
 w_self.initialization_state &= ~4
 return
-w_self.deldictvalue(space, 'name')
+# need to save the original object too
+w_self.setdictvalue(space, 'name', w_new_value)
 w_self.initialization_state |= 4
 
 def ClassDef_del_name(space, w_self):
@@ -3665,7 +3675,8 @@
 w_self.setdictvalue(space, 'nl', w_new_value)
 w_self.initialization_state &= ~16
 return
-w_self.deldictvalue(space, 'nl')
+# need to save the original object too
+w_self.setdictvalue(space, 'nl', w_new_value)
 w_self.initialization_state |= 16
 
 def Print_del_nl(space, w_self):
@@ -4571,7 +4582,8 @@
 w_self.setdictvalue(space, 'module', w_new_value)
 w_self.initialization_state &= ~4
 return
-w_self.deldictvalue(space, 'module')
+# need to save the original object too
+w_self.setdictvalue(space, 'module', w_new_value)
 w_self.initialization_state |= 4
 
 def ImportFrom_del_module(space, w_self):
@@ -4620,7 +4632,8 @@
 w_self.setdictvalue(space, 'level', w_new_value)
 w_self.initialization_state &= ~16
 return
-w_self.deldictvalue(space, 'level')
+# need to save the original object too
+w_self.setdictvalue(space, 'level', w_new_value)
 w_self.initialization_state |= 16
 
 def ImportFrom_del_level(space, w_self):
@@ -4938,7 +4951,8 @@
 w_self.setdictvalue(space, 'lineno', w_new_value)
 w_self.initialization_state &= ~1
 return
-w_self.deldictvalue(space, 'lineno')
+# need to save the original object too
+w_self.setdictvalue(space, 'lineno', w_new_value)
 w_self.initialization_state |= 1
 
 def expr_del_lineno(space, w_self):
@@ -4965,7 +4979,8 @@
 w_self.setdictvalue(space, 'col_offset', w_new_value)
 w_self.initialization_state &= ~2
 return
-w_self.deldictvalue(space, 'col_offset')
+# need to save the original object too
+w_self.setdictvalue(space, 'col_offset', w_new_value)
 w_self.initialization_state |= 2
 
 def expr_del_col_offset(space, w_self):
@@ -6292,7 +6307,8 @@
 w_self.setdictvalue(space, 'n', w_new_value)
 w_self

[pypy-commit] pypy ast-issue1673: close branch before merging

2014-04-01 Thread rlamy
Author: Ronan Lamy 
Branch: ast-issue1673
Changeset: r70386:43d5b8ad2ef0
Date: 2014-04-01 23:39 +0100
http://bitbucket.org/pypy/pypy/changeset/43d5b8ad2ef0/

Log:close branch before merging

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


[pypy-commit] pypy stdlib-3.2.5: pypy has no switchinterval and the test passes without.

2014-04-01 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: stdlib-3.2.5
Changeset: r70389:1154666cbe9b
Date: 2014-04-02 00:24 +0200
http://bitbucket.org/pypy/pypy/changeset/1154666cbe9b/

Log:pypy has no switchinterval and the test passes without.

diff --git a/lib-python/3/test/test_concurrent_futures.py 
b/lib-python/3/test/test_concurrent_futures.py
--- a/lib-python/3/test/test_concurrent_futures.py
+++ b/lib-python/3/test/test_concurrent_futures.py
@@ -294,14 +294,16 @@
 event = threading.Event()
 def future_func():
 event.wait()
-oldswitchinterval = sys.getswitchinterval()
-sys.setswitchinterval(1e-6)
+if hasattr(sys, 'setswitchinterval'):
+oldswitchinterval = sys.getswitchinterval()
+sys.setswitchinterval(1e-6)
 try:
 fs = {self.executor.submit(future_func) for i in range(100)}
 event.set()
 futures.wait(fs, return_when=futures.ALL_COMPLETED)
 finally:
-sys.setswitchinterval(oldswitchinterval)
+if hasattr(sys, 'setswitchinterval'):
+sys.setswitchinterval(oldswitchinterval)
 
 
 class ProcessPoolWaitTests(ProcessPoolMixin, WaitTests):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy stdlib-3.2.5: Expat parser now correctly works with unicode input,

2014-04-01 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: stdlib-3.2.5
Changeset: r70392:73ca2fbe4077
Date: 2014-04-02 02:21 +0200
http://bitbucket.org/pypy/pypy/changeset/73ca2fbe4077/

Log:Expat parser now correctly works with unicode input, even when the
XML internal encoding is not UTF8 (CPython issue 17089)

diff --git a/pypy/module/pyexpat/interp_pyexpat.py 
b/pypy/module/pyexpat/interp_pyexpat.py
--- a/pypy/module/pyexpat/interp_pyexpat.py
+++ b/pypy/module/pyexpat/interp_pyexpat.py
@@ -2,6 +2,7 @@
 from pypy.interpreter.typedef import TypeDef, GetSetProperty
 from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
 from pypy.interpreter.error import OperationError, oefmt
+from pypy.interpreter.unicodehelper import encode_utf8
 from rpython.rlib import rgc, jit
 from rpython.rtyper.lltypesystem import rffi, lltype
 from rpython.rtyper.tool import rffi_platform
@@ -348,6 +349,8 @@
 XML_SetUnknownEncodingHandler = expat_external(
 'XML_SetUnknownEncodingHandler',
 [XML_Parser, callback_type, rffi.VOIDP], lltype.Void)
+XML_SetEncoding = expat_external(
+'XML_SetEncoding', [XML_Parser, rffi.CCHARP], rffi.INT)
 
 # Declarations of external functions
 
@@ -622,10 +625,17 @@
 
 # Parse methods
 
-@unwrap_spec(data='bufferstr_or_u', isfinal=bool)
-def Parse(self, space, data, isfinal=False):
+@unwrap_spec(isfinal=bool)
+def Parse(self, space, w_data, isfinal=False):
 """Parse(data[, isfinal])
 Parse XML data.  `isfinal' should be true at end of input."""
+if space.isinstance_w(w_data, space.w_unicode):
+u = w_data.unicode_w(space)
+data = encode_utf8(space, w_data.unicode_w(space))
+# Explicitly set UTF-8 encoding. Return code ignored.
+XML_SetEncoding(self.itself, "utf-8")
+else:
+data = space.bufferstr_w(w_data)
 res = XML_Parse(self.itself, data, len(data), isfinal)
 if self._exc_info:
 e = self._exc_info
@@ -643,9 +653,8 @@
 eof = False
 while not eof:
 w_data = space.call_method(w_file, 'read', space.wrap(2048))
-data = space.bytes_w(w_data)
-eof = len(data) == 0
-w_res = self.Parse(space, data, isfinal=eof)
+eof = space.len_w(w_data) == 0
+w_res = self.Parse(space, w_data, isfinal=eof)
 return w_res
 
 @unwrap_spec(base=str)
diff --git a/pypy/module/pyexpat/test/test_parser.py 
b/pypy/module/pyexpat/test/test_parser.py
--- a/pypy/module/pyexpat/test/test_parser.py
+++ b/pypy/module/pyexpat/test/test_parser.py
@@ -100,7 +100,7 @@
 p.Parse(xml)
 
 def test_python_encoding(self):
-# This name is not knonwn by expat
+# This name is not known by expat
 xml = b"caf\xe9"
 import pyexpat
 p = pyexpat.ParserCreate()
@@ -110,12 +110,21 @@
 p.Parse(xml)
 
 def test_mbcs(self):
-xml = ""
+xml = b""
 import pyexpat
 p = pyexpat.ParserCreate()
 exc = raises(ValueError, p.Parse, xml)
 assert str(exc.value) == "multi-byte encodings are not supported"
 
+def test_parse_str(self):
+xml = "caf\xe9"
+import pyexpat
+p = pyexpat.ParserCreate()
+def gotText(text):
+assert text == "caf\xe9"
+p.CharacterDataHandler = gotText
+p.Parse(xml)
+
 def test_decode_error(self):
 xml = b'Comment \xe7a va ? Tr\xe8s bien ?'
 import pyexpat
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy stdlib-3.2.5: Skip some implementation details.

2014-04-01 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: stdlib-3.2.5
Changeset: r70390:ddc62d7d5716
Date: 2014-04-02 00:59 +0200
http://bitbucket.org/pypy/pypy/changeset/ddc62d7d5716/

Log:Skip some implementation details. One remaining failure in
test_weakref is suspect: __len__() returns -7!

diff --git a/lib-python/3/test/test_functools.py 
b/lib-python/3/test/test_functools.py
--- a/lib-python/3/test/test_functools.py
+++ b/lib-python/3/test/test_functools.py
@@ -197,9 +197,13 @@
 raise IndexError
 
 f = self.thetype(object)
-self.assertRaisesRegex(SystemError,
-"new style getargs format but argument is not a tuple",
-f.__setstate__, BadSequence())
+if support.check_impl_detail(pypy=True):
+# CPython fails, pypy does not :-)
+f.__setstate__(BadSequence())
+else:
+self.assertRaisesRegex(SystemError,
+"new style getargs format but argument is not a tuple",
+f.__setstate__, BadSequence())
 
 class PartialSubclass(functools.partial):
 pass
diff --git a/lib-python/3/test/test_weakref.py 
b/lib-python/3/test/test_weakref.py
--- a/lib-python/3/test/test_weakref.py
+++ b/lib-python/3/test/test_weakref.py
@@ -934,6 +934,7 @@
 n1 = len(dct)
 del it
 gc.collect()
+gc.collect()
 n2 = len(dct)
 # one item may be kept alive inside the iterator
 self.assertIn(n1, (0, 1))
@@ -945,6 +946,7 @@
 def test_weak_valued_len_cycles(self):
 self.check_len_cycles(weakref.WeakValueDictionary, lambda k: (1, k))
 
+@support.impl_detail("PyPy has no cyclic collection", pypy=False)
 def check_len_race(self, dict_type, cons):
 # Extended sanity checks for len() in the face of cyclic collection
 self.addCleanup(gc.set_threshold, *gc.get_threshold())
diff --git a/lib-python/3/test/test_weakset.py 
b/lib-python/3/test/test_weakset.py
--- a/lib-python/3/test/test_weakset.py
+++ b/lib-python/3/test/test_weakset.py
@@ -406,11 +406,13 @@
 n1 = len(s)
 del it
 gc.collect()
+gc.collect()
 n2 = len(s)
 # one item may be kept alive inside the iterator
 self.assertIn(n1, (0, 1))
 self.assertEqual(n2, 0)
 
+@support.impl_detail("PyPy has no cyclic collection", pypy=False)
 def test_len_race(self):
 # Extended sanity checks for len() in the face of cyclic collection
 self.addCleanup(gc.set_threshold, *gc.get_threshold())
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy stdlib-3.2.5: mangle keyword-only argname when loading defaults (CPython issue #14607)

2014-04-01 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: stdlib-3.2.5
Changeset: r70391:a15b2d272f8e
Date: 2014-04-02 01:15 +0200
http://bitbucket.org/pypy/pypy/changeset/a15b2d272f8e/

Log:mangle keyword-only argname when loading defaults (CPython issue
#14607)

diff --git a/pypy/interpreter/astcompiler/codegen.py 
b/pypy/interpreter/astcompiler/codegen.py
--- a/pypy/interpreter/astcompiler/codegen.py
+++ b/pypy/interpreter/astcompiler/codegen.py
@@ -306,7 +306,8 @@
 for i, default in enumerate(args.kw_defaults):
 if default:
 kwonly = args.kwonlyargs[i]
-self.load_const(self.space.wrap(kwonly.arg.decode('utf-8')))
+mangled = self.scope.mangle(kwonly.arg.decode('utf-8'))
+self.load_const(self.space.wrap(mangled))
 default.walkabout(self)
 defaults += 1
 return defaults
diff --git a/pypy/interpreter/test/test_interpreter.py 
b/pypy/interpreter/test/test_interpreter.py
--- a/pypy/interpreter/test/test_interpreter.py
+++ b/pypy/interpreter/test/test_interpreter.py
@@ -347,6 +347,14 @@
 assert l(1, 2, k=10) == 1 + 2 + 10
 """
 
+def test_kwonlyarg_mangling(self):
+"""
+class X:
+def f(self, *, __a=42):
+return __a
+assert X().f() == 42
+"""
+
 def test_extended_unpacking_short(self):
 """
 class Seq:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit