[pypy-commit] pypy release-2.2.x: Add os.startfile() using cffi.

2013-11-12 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: release-2.2.x
Changeset: r67970:4a3ba24a561a
Date: 2013-11-12 12:42 +0100
http://bitbucket.org/pypy/pypy/changeset/4a3ba24a561a/

Log:Add os.startfile() using cffi.

diff --git a/pypy/module/posix/__init__.py b/pypy/module/posix/__init__.py
--- a/pypy/module/posix/__init__.py
+++ b/pypy/module/posix/__init__.py
@@ -27,6 +27,7 @@
 'popen2': 'app_posix.popen2',
 'popen3': 'app_posix.popen3',
 'popen4': 'app_posix.popen4',
+'startfile': 'app_startfile.startfile',
 })
 
 if hasattr(os, 'wait'):
diff --git a/pypy/module/posix/app_startfile.py 
b/pypy/module/posix/app_startfile.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/posix/app_startfile.py
@@ -0,0 +1,44 @@
+
+class CFFIWrapper(object):
+def __init__(self):
+import cffi
+ffi = cffi.FFI()
+ffi.cdef(
+HINSTANCE ShellExecuteA(HWND, LPCSTR, LPCSTR, LPCSTR, LPCSTR, INT);
+HINSTANCE ShellExecuteW(HWND, LPCWSTR, LPCWSTR, LPCWSTR, LPCWSTR, INT);
+DWORD GetLastError(void);
+)
+self.NULL = ffi.NULL
+self.cast = ffi.cast
+self.libK = ffi.dlopen(Kernel32.dll)
+self.libS = ffi.dlopen(Shell32.dll)
+self.SW_SHOWNORMAL = 1
+
+_cffi_wrapper = None
+
+
+def startfile(filepath, operation=None):
+global _cffi_wrapper
+if _cffi_wrapper is None:
+_cffi_wrapper = CFFIWrapper()
+w = _cffi_wrapper
+#
+if operation is None:
+operation = w.NULL
+if isinstance(filepath, str):
+if isinstance(operation, unicode):
+operation = operation.encode(ascii)
+rc = w.libS.ShellExecuteA(w.NULL, operation, filepath,
+  w.NULL, w.NULL, w.SW_SHOWNORMAL)
+elif isinstance(filepath, unicode):
+if isinstance(operation, str):
+operation = operation.decode(ascii)
+rc = w.libS.ShellExecuteW(w.NULL, operation, filepath,
+  w.NULL, w.NULL, w.SW_SHOWNORMAL)
+else:
+raise TypeError(argument 1 must be str or unicode)
+rc = int(w.cast(uintptr_t, rc))
+if rc = 32:
+# sorry, no way to get the error message in less than one page of code
+code = w.libK.GetLastError()
+raise WindowsError(code, Error %s % code, filepath)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy release-2.2.x: Add the NOT_RPYTHON comment at the top of the file, although that might

2013-11-12 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: release-2.2.x
Changeset: r67971:7adf80f17ffb
Date: 2013-11-12 12:43 +0100
http://bitbucket.org/pypy/pypy/changeset/7adf80f17ffb/

Log:Add the NOT_RPYTHON comment at the top of the file, although that
might not have any effect any more.

diff --git a/pypy/module/posix/app_startfile.py 
b/pypy/module/posix/app_startfile.py
--- a/pypy/module/posix/app_startfile.py
+++ b/pypy/module/posix/app_startfile.py
@@ -1,3 +1,4 @@
+# NOT_RPYTHON
 
 class CFFIWrapper(object):
 def __init__(self):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy release-2.2.x: Found out that FormatError() is exposed via _rawffi. Would you believe.

2013-11-12 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: release-2.2.x
Changeset: r67972:f262c7a6776c
Date: 2013-11-12 12:51 +0100
http://bitbucket.org/pypy/pypy/changeset/f262c7a6776c/

Log:Found out that FormatError() is exposed via _rawffi. Would you
believe.

diff --git a/pypy/module/posix/app_startfile.py 
b/pypy/module/posix/app_startfile.py
--- a/pypy/module/posix/app_startfile.py
+++ b/pypy/module/posix/app_startfile.py
@@ -40,6 +40,10 @@
 raise TypeError(argument 1 must be str or unicode)
 rc = int(w.cast(uintptr_t, rc))
 if rc = 32:
-# sorry, no way to get the error message in less than one page of code
 code = w.libK.GetLastError()
-raise WindowsError(code, Error %s % code, filepath)
+try:
+import _rawffi
+msg = _rawffi.FormatError(code)
+except ImportError:
+msg = 'Error %s' % code
+raise WindowsError(code, msg, filepath)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi default: Add ffi.getwinerror().

2013-11-12 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r1412:8a16eff7850c
Date: 2013-11-12 13:48 +0100
http://bitbucket.org/cffi/cffi/changeset/8a16eff7850c/

Log:Add ffi.getwinerror().

diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -5227,6 +5227,9 @@
 {set_errno, b_set_errno, METH_VARARGS},
 {newp_handle, b_newp_handle, METH_VARARGS},
 {from_handle, b_from_handle, METH_O},
+#ifdef MS_WIN32
+{getwinerror, b_getwinerror, METH_VARARGS},
+#endif
 {_get_types, b__get_types, METH_NOARGS},
 {_testfunc, b__testfunc, METH_VARARGS},
 {NULL, NULL}/* Sentinel */
diff --git a/c/misc_win32.h b/c/misc_win32.h
--- a/c/misc_win32.h
+++ b/c/misc_win32.h
@@ -80,6 +80,54 @@
 /* else: cannot report the error */
 }
 
+static PyObject *b_getwinerror(PyObject *self, PyObject *args)
+{
+int err = -1;
+int len;
+char *s;
+char *s_buf = NULL; /* Free via LocalFree */
+char s_small_buf[28]; /* Room for Windows Error 0x */
+PyObject *v;
+
+if (!PyArg_ParseTuple(args, |i, err))
+return NULL;
+
+if (err == -1) {
+struct cffi_errno_s *p;
+p = _geterrno_object();
+if (p == NULL)
+return PyErr_NoMemory();
+err = p-saved_lasterror;
+}
+
+len = FormatMessage(
+/* Error API error */
+FORMAT_MESSAGE_ALLOCATE_BUFFER |
+FORMAT_MESSAGE_FROM_SYSTEM |
+FORMAT_MESSAGE_IGNORE_INSERTS,
+NULL,   /* no message source */
+err,
+MAKELANGID(LANG_NEUTRAL,
+SUBLANG_DEFAULT), /* Default language */
+(LPTSTR) s_buf,
+0,  /* size not used */
+NULL);  /* no args */
+if (len==0) {
+/* Only seen this in out of mem situations */
+sprintf(s_small_buf, Windows Error 0x%X, err);
+s = s_small_buf;
+s_buf = NULL;
+} else {
+s = s_buf;
+/* remove trailing cr/lf and dots */
+while (len  0  (s[len-1] = ' ' || s[len-1] == '.'))
+s[--len] = '\0';
+}
+v = Py_BuildValue((is), err, s);
+LocalFree(s_buf);
+return v;
+}
+
 //
 /* Emulate dlopen()co. from the Windows API */
 
diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -2698,6 +2698,16 @@
 #
 res = GetLastError()
 assert res == 42
+#
+SetLastError(2)
+code, message = getwinerror()
+assert code == 2
+assert message == The system cannot find the file specified
+#
+code, message = getwinerror(1155)
+assert code == 1155
+assert message == (No application is associated with the 
+   specified file for this operation)
 
 def test_nonstandard_integer_types():
 for typename in ['int8_t', 'uint8_t', 'int16_t', 'uint16_t', 'int32_t',
diff --git a/cffi/api.py b/cffi/api.py
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -347,6 +347,9 @@
 errno = property(_get_errno, _set_errno, None,
  the value of 'errno' from/to the C calls)
 
+def getwinerror(self, code=-1):
+return self._backend.getwinerror(code)
+
 def _pointer_to(self, ctype):
 from . import model
 with self._lock:
diff --git a/doc/source/index.rst b/doc/source/index.rst
--- a/doc/source/index.rst
+++ b/doc/source/index.rst
@@ -1122,9 +1122,18 @@
 
 ``ffi.errno``: the value of ``errno`` received from the most recent C call
 in this thread, and passed to the following C call, is available via
-reads and writes of the property ``ffi.errno``.  On Windows we also save
-and restore the ``GetLastError()`` value, but to access it you need to
-declare and call the ``GetLastError()`` function as usual.
+reads and writes of the property ``ffi.errno``.
+
+``ffi.getwinerror(code=-1)``: on Windows, in addition to ``errno`` we
+also save and restore the ``GetLastError()`` value across function
+calls.  This function returns this error code as a tuple ``(code,
+message)``, adding a readable message like Python does when raising
+WindowsError.  If the argument ``code`` is given, format that code into
+a message instead of using ``GetLastError()``.  *New in version 0.8.*
+(Note that it is also possible to declare and call the ``GetLastError()``
+function as usual.)
+
+.. versionadded:: 0.8 --- inlined in the previous paragraph
 
 ``ffi.string(cdata, [maxlen])``: return a Python string (or unicode
 string) from the 'cdata'.  *New in version 0.3.*
diff --git a/testing/test_ffi_backend.py b/testing/test_ffi_backend.py
--- a/testing/test_ffi_backend.py
+++ b/testing/test_ffi_backend.py
@@ -194,3 +194,20 @@
 assert p.a[0] == 200
 assert p.a[1] == 300
 assert p.a[2] == 400
+
+@pytest.mark.skipif(sys.platform != 'win32')
+def test_getwinerror(self):
+ffi = FFI()
+code, message = ffi.getwinerror(1155)
+assert code == 1155
+assert 

[pypy-commit] pypy release-2.2.x: Update to cffi/8a16eff7850c.

2013-11-12 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: release-2.2.x
Changeset: r67974:662e4114634e
Date: 2013-11-12 13:55 +0100
http://bitbucket.org/pypy/pypy/changeset/662e4114634e/

Log:Update to cffi/8a16eff7850c.

diff --git a/pypy/module/_cffi_backend/__init__.py 
b/pypy/module/_cffi_backend/__init__.py
--- a/pypy/module/_cffi_backend/__init__.py
+++ b/pypy/module/_cffi_backend/__init__.py
@@ -1,3 +1,4 @@
+import sys
 from pypy.interpreter.mixedmodule import MixedModule
 from rpython.rlib import rdynload
 
@@ -43,6 +44,8 @@
 'FFI_DEFAULT_ABI': 'ctypefunc._get_abi(space, FFI_DEFAULT_ABI)',
 'FFI_CDECL': 'ctypefunc._get_abi(space,FFI_DEFAULT_ABI)',#win32 name
 }
+if sys.platform == 'win32':
+interpleveldefs['getwinerror'] = 'cerrno.getwinerror'
 
 for _name in [RTLD_LAZY, RTLD_NOW, RTLD_GLOBAL, RTLD_LOCAL,
   RTLD_NODELETE, RTLD_NOLOAD, RTLD_DEEPBIND]:
diff --git a/pypy/module/_cffi_backend/cerrno.py 
b/pypy/module/_cffi_backend/cerrno.py
--- a/pypy/module/_cffi_backend/cerrno.py
+++ b/pypy/module/_cffi_backend/cerrno.py
@@ -39,3 +39,14 @@
 def set_errno(space, errno):
 ec = get_errno_container(space)
 ec._cffi_saved_errno = errno
+
+# 
+
+@unwrap_spec(code=int)
+def getwinerror(space, code=-1):
+from rpython.rlib.rwin32 import FormatError
+if code == -1:
+ec = get_errno_container(space)
+code = ec._cffi_saved_LastError
+message = FormatError(code)
+return space.newtuple([space.wrap(code), space.wrap(message)])
diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py 
b/pypy/module/_cffi_backend/test/_backend_test_c.py
--- a/pypy/module/_cffi_backend/test/_backend_test_c.py
+++ b/pypy/module/_cffi_backend/test/_backend_test_c.py
@@ -2687,6 +2687,16 @@
 #
 res = GetLastError()
 assert res == 42
+#
+SetLastError(2)
+code, message = getwinerror()
+assert code == 2
+assert message == The system cannot find the file specified
+#
+code, message = getwinerror(1155)
+assert code == 1155
+assert message == (No application is associated with the 
+   specified file for this operation)
 
 def test_nonstandard_integer_types():
 for typename in ['int8_t', 'uint8_t', 'int16_t', 'uint16_t', 'int32_t',
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy release-2.2.x: Like CPython, strip the message from trailing dots.

2013-11-12 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: release-2.2.x
Changeset: r67973:7ce0a6e10446
Date: 2013-11-12 13:54 +0100
http://bitbucket.org/pypy/pypy/changeset/7ce0a6e10446/

Log:Like CPython, strip the message from trailing dots.

diff --git a/rpython/rlib/rwin32.py b/rpython/rlib/rwin32.py
--- a/rpython/rlib/rwin32.py
+++ b/rpython/rlib/rwin32.py
@@ -216,7 +216,7 @@
 def llimpl_FormatError(code):
 Return a message corresponding to the given Windows error code.
 buf = lltype.malloc(rffi.CCHARPP.TO, 1, flavor='raw')
-
+buf[0] = lltype.nullptr(rffi.CCHARP.TO)
 try:
 msglen = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
@@ -225,17 +225,20 @@
DEFAULT_LANGUAGE,
rffi.cast(rffi.CCHARP, buf),
0, None)
+buflen = intmask(msglen)
 
-if msglen = 2:   # includes the case msglen  0
-return fake_FormatError(code)
+# remove trailing cr/lf and dots
+s_buf = buf[0]
+while buflen  0 and (s_buf[buflen - 1] = ' ' or
+  s_buf[buflen - 1] == '.'):
+buflen -= 1
 
-# FormatMessage always appends \r\n.
-buflen = intmask(msglen - 2)
-assert buflen  0
-
-result = rffi.charpsize2str(buf[0], buflen)
+if buflen = 0:
+result = fake_FormatError(code)
+else:
+result = rffi.charpsize2str(s_buf, buflen)
+finally:
 LocalFree(rffi.cast(rffi.VOIDP, buf[0]))
-finally:
 lltype.free(buf, flavor='raw')
 
 return result
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy release-2.2.x: Import cffi/8a16eff7850c here too

2013-11-12 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: release-2.2.x
Changeset: r67975:edcc6d30feff
Date: 2013-11-12 13:56 +0100
http://bitbucket.org/pypy/pypy/changeset/edcc6d30feff/

Log:Import cffi/8a16eff7850c here too

diff --git a/lib_pypy/cffi/api.py b/lib_pypy/cffi/api.py
--- a/lib_pypy/cffi/api.py
+++ b/lib_pypy/cffi/api.py
@@ -347,6 +347,9 @@
 errno = property(_get_errno, _set_errno, None,
  the value of 'errno' from/to the C calls)
 
+def getwinerror(self, code=-1):
+return self._backend.getwinerror(code)
+
 def _pointer_to(self, ctype):
 from . import model
 with self._lock:
diff --git a/pypy/module/test_lib_pypy/cffi_tests/test_ffi_backend.py 
b/pypy/module/test_lib_pypy/cffi_tests/test_ffi_backend.py
--- a/pypy/module/test_lib_pypy/cffi_tests/test_ffi_backend.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/test_ffi_backend.py
@@ -195,3 +195,20 @@
 assert p.a[0] == 200
 assert p.a[1] == 300
 assert p.a[2] == 400
+
+@pytest.mark.skipif(sys.platform != 'win32')
+def test_getwinerror(self):
+ffi = FFI()
+code, message = ffi.getwinerror(1155)
+assert code == 1155
+assert message == (No application is associated with the 
+   specified file for this operation)
+ffi.cdef(void SetLastError(int);)
+lib = ffi.dlopen(Kernel32.dll)
+lib.SetLastError(2)
+code, message = ffi.getwinerror()
+assert code == 2
+assert message == The system cannot find the file specified
+code, message = ffi.getwinerror(-1)
+assert code == 2
+assert message == The system cannot find the file specified
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy release-2.2.x: Use getwinerror() here

2013-11-12 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: release-2.2.x
Changeset: r67976:7341987b8055
Date: 2013-11-12 13:58 +0100
http://bitbucket.org/pypy/pypy/changeset/7341987b8055/

Log:Use getwinerror() here

diff --git a/pypy/module/posix/app_startfile.py 
b/pypy/module/posix/app_startfile.py
--- a/pypy/module/posix/app_startfile.py
+++ b/pypy/module/posix/app_startfile.py
@@ -11,9 +11,9 @@
 )
 self.NULL = ffi.NULL
 self.cast = ffi.cast
-self.libK = ffi.dlopen(Kernel32.dll)
-self.libS = ffi.dlopen(Shell32.dll)
+self.lib = ffi.dlopen(Shell32.dll)
 self.SW_SHOWNORMAL = 1
+self.getwinerror = ffi.getwinerror
 
 _cffi_wrapper = None
 
@@ -29,21 +29,16 @@
 if isinstance(filepath, str):
 if isinstance(operation, unicode):
 operation = operation.encode(ascii)
-rc = w.libS.ShellExecuteA(w.NULL, operation, filepath,
-  w.NULL, w.NULL, w.SW_SHOWNORMAL)
+rc = w.lib.ShellExecuteA(w.NULL, operation, filepath,
+ w.NULL, w.NULL, w.SW_SHOWNORMAL)
 elif isinstance(filepath, unicode):
 if isinstance(operation, str):
 operation = operation.decode(ascii)
-rc = w.libS.ShellExecuteW(w.NULL, operation, filepath,
-  w.NULL, w.NULL, w.SW_SHOWNORMAL)
+rc = w.lib.ShellExecuteW(w.NULL, operation, filepath,
+ w.NULL, w.NULL, w.SW_SHOWNORMAL)
 else:
 raise TypeError(argument 1 must be str or unicode)
 rc = int(w.cast(uintptr_t, rc))
 if rc = 32:
-code = w.libK.GetLastError()
-try:
-import _rawffi
-msg = _rawffi.FormatError(code)
-except ImportError:
-msg = 'Error %s' % code
+code, msg = w.getwinerror()
 raise WindowsError(code, msg, filepath)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy release-2.2.x: Python 2.6 compatibility

2013-11-12 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: release-2.2.x
Changeset: r67977:3e1a49627e13
Date: 2013-11-12 14:17 +0100
http://bitbucket.org/pypy/pypy/changeset/3e1a49627e13/

Log:Python 2.6 compatibility

diff --git a/rpython/annotator/bookkeeper.py b/rpython/annotator/bookkeeper.py
--- a/rpython/annotator/bookkeeper.py
+++ b/rpython/annotator/bookkeeper.py
@@ -5,7 +5,6 @@
 from __future__ import absolute_import
 
 import sys, types, inspect, weakref
-from collections import OrderedDict
 
 from rpython.flowspace.model import Constant
 from rpython.annotator.model import (SomeOrderedDict,
@@ -371,7 +370,7 @@
 for e in x:
 listdef.generalize(self.immutablevalue(e, False))
 result = SomeList(listdef)
-elif tp is dict or tp is r_dict or tp is OrderedDict:
+elif tp is dict or tp is r_dict or tp is SomeOrderedDict.knowntype:
 if need_const:
 key = Constant(x)
 try:
@@ -413,7 +412,7 @@
 dictdef.generalize_key(self.immutablevalue(ek, False))
 dictdef.generalize_value(self.immutablevalue(ev, False))
 dictdef.seen_prebuilt_key(ek)
-if tp is OrderedDict:
+if tp is SomeOrderedDict.knowntype:
 result = SomeOrderedDict(dictdef)
 else:
 result = SomeDict(dictdef)
diff --git a/rpython/annotator/builtin.py b/rpython/annotator/builtin.py
--- a/rpython/annotator/builtin.py
+++ b/rpython/annotator/builtin.py
@@ -2,7 +2,6 @@
 Built-in functions.
 
 import sys
-from collections import OrderedDict
 
 from rpython.annotator.model import (
 SomeInteger, SomeObject, SomeChar, SomeBool, SomeString, SomeTuple, s_Bool,
@@ -364,7 +363,7 @@
 BUILTIN_ANALYZERS[rpython.rlib.objectmodel.instantiate] = robjmodel_instantiate
 BUILTIN_ANALYZERS[rpython.rlib.objectmodel.r_dict] = robjmodel_r_dict
 BUILTIN_ANALYZERS[rpython.rlib.objectmodel.r_ordereddict] = 
robjmodel_r_ordereddict
-BUILTIN_ANALYZERS[OrderedDict] = lambda : 
SomeOrderedDict(getbookkeeper().getdictdef())
+BUILTIN_ANALYZERS[SomeOrderedDict.knowntype] = lambda : 
SomeOrderedDict(getbookkeeper().getdictdef())
 BUILTIN_ANALYZERS[rpython.rlib.objectmodel.hlinvoke] = robjmodel_hlinvoke
 BUILTIN_ANALYZERS[rpython.rlib.objectmodel.keepalive_until_here] = 
robjmodel_keepalive_until_here
 BUILTIN_ANALYZERS[rpython.rtyper.lltypesystem.llmemory.cast_ptr_to_adr] = 
llmemory_cast_ptr_to_adr
diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py
--- a/rpython/annotator/model.py
+++ b/rpython/annotator/model.py
@@ -32,7 +32,6 @@
 import inspect
 import weakref
 from types import BuiltinFunctionType, MethodType
-from collections import OrderedDict
 
 import rpython
 from rpython.tool import descriptor
@@ -357,7 +356,11 @@
 return '{...%s...}' % (len(const),)
 
 class SomeOrderedDict(SomeDict):
-knowntype = OrderedDict
+try:
+from collections import OrderedDict as knowntype
+except ImportError:# Python 2.6
+class PseudoOrderedDict(dict): pass
+knowntype = PseudoOrderedDict
 
 def method_copy(dct):
 return SomeOrderedDict(dct.dictdef)
diff --git a/rpython/rtyper/rbuiltin.py b/rpython/rtyper/rbuiltin.py
--- a/rpython/rtyper/rbuiltin.py
+++ b/rpython/rtyper/rbuiltin.py
@@ -1,4 +1,3 @@
-from collections import OrderedDict
 
 from rpython.annotator import model as annmodel
 from rpython.flowspace.model import Constant
@@ -750,7 +749,7 @@
 BUILTIN_TYPER[isinstance] = rtype_builtin_isinstance
 BUILTIN_TYPER[hasattr] = rtype_builtin_hasattr
 BUILTIN_TYPER[objectmodel.r_dict] = rtype_r_dict
-BUILTIN_TYPER[OrderedDict] = rtype_ordered_dict
+BUILTIN_TYPER[annmodel.SomeOrderedDict.knowntype] = rtype_ordered_dict
 BUILTIN_TYPER[objectmodel.r_ordereddict] = rtype_ordered_dict
 
 # _
diff --git a/rpython/rtyper/test/test_rordereddict.py 
b/rpython/rtyper/test/test_rordereddict.py
--- a/rpython/rtyper/test/test_rordereddict.py
+++ b/rpython/rtyper/test/test_rordereddict.py
@@ -1,6 +1,9 @@
 
 import py
-from collections import OrderedDict
+try:
+from collections import OrderedDict
+except ImportError: # Python 2.6
+py.test.skip(requires collections.OrderedDict)
 from rpython.rtyper.lltypesystem import lltype, rffi
 from rpython.rtyper.lltypesystem import rordereddict, rstr
 from rpython.rlib.rarithmetic import intmask
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy release-2.2.x: Add an app-level-only test for os.startfile()

2013-11-12 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: release-2.2.x
Changeset: r67978:2cec7296d7fb
Date: 2013-11-12 14:23 +0100
http://bitbucket.org/pypy/pypy/changeset/2cec7296d7fb/

Log:Add an app-level-only test for os.startfile()

diff --git a/pypy/module/posix/test/test_posix2.py 
b/pypy/module/posix/test/test_posix2.py
--- a/pypy/module/posix/test/test_posix2.py
+++ b/pypy/module/posix/test/test_posix2.py
@@ -52,6 +52,7 @@
 
 def setup_class(cls):
 cls.space = space
+cls.w_runappdirect = space.wrap(cls.runappdirect)
 cls.w_posix = space.appexec([], GET_POSIX)
 cls.w_path = space.wrap(str(path))
 cls.w_path2 = space.wrap(str(path2))
@@ -1108,6 +1109,28 @@
 assert False, urandom() always returns the same string
 # Or very unlucky
 
+if hasattr(os, 'startfile'):
+def test_startfile(self):
+if not self.runappdirect:
+skip(should not try to import cffi at app-level)
+startfile = self.posix.startfile
+for t1 in [str, unicode]:
+for t2 in [str, unicode]:
+e = raises(WindowsError, startfile, t1(\\), t2(close))
+assert e.value.args[0] == 1155
+assert e.value.args[1] == (
+No application is associated with the 
+specified file for this operation)
+if len(e.value.args)  2:
+assert e.value.args[2] == t1(\\)
+#
+e = raises(WindowsError, startfile, \\foo\\bar\\baz)
+assert e.value.args[0] == 2
+assert e.value.args[1] == (
+The system cannot find the file specified)
+if len(e.value.args)  2:
+assert e.value.args[2] == \\foo\\bar\\baz
+
 
 class AppTestEnvironment(object):
 def setup_class(cls):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy release-2.2.x: Progress

2013-11-12 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: release-2.2.x
Changeset: r67979:49bfc678ad16
Date: 2013-11-12 14:25 +0100
http://bitbucket.org/pypy/pypy/changeset/49bfc678ad16/

Log:Progress

diff --git a/pypy/doc/release-2.2.0.rst b/pypy/doc/release-2.2.0.rst
--- a/pypy/doc/release-2.2.0.rst
+++ b/pypy/doc/release-2.2.0.rst
@@ -1,9 +1,87 @@
 ===
-PyPy 2.2 - xxx
+PyPy 2.2 - Incrementalism
 ===
 
-GC!
+We're pleased to announce PyPy 2.2, which targets version 2.7.3 of the Python
+language. This release main highlight is the introduction of the incremental
+garbage collector, sponsored by the `Raspberry Pi Foundation`_.
 
+This release also contains several bugfixes and performance improvements. 
 
-numpypy module was removed in favor of an external numpy fork
+You can download the PyPy 2.2 release here:
+
+http://pypy.org/download.html
+
+We would like to thank our donors for the continued support of the PyPy
+project. We showed quite a bit of progress on all three projects (see below)
+and we're slowly running out of funds.
+Please consider donating more so we can finish those projects!  The three
+projects are:
+
+* Py3k (supporting Python 3.x): the release PyPy3 2.2 is imminent.
+
+* STM (software transactional memory): a preview will be released very soon,
+  as soon as we fix a few bugs
+
+* NumPy: the work done is included in the PyPy 2.2 release. More details below.
+
+.. _`Raspberry Pi Foundation`: http://www.raspberrypi.org
+
+What is PyPy?
+=
+
+PyPy is a very compliant Python interpreter, almost a drop-in replacement for
+CPython 2.7. It's fast (`pypy 2.2 and cpython 2.7.2`_ performance comparison)
+due to its integrated tracing JIT compiler.
+
+This release supports x86 machines running Linux 32/64, Mac OS X 64, Windows
+32, or ARM (ARMv6 or ARMv7, with VFPv3).
+
+Work on the native Windows 64 is still stalling, we would welcome a volunteer
+to handle that.
+
+.. _`pypy 2.2 and cpython 2.7.2`: http://speed.pypy.org
+
+Highlights
+==
+
+* Our Garbage Collector is now incremental.  It should avoid almost all 
pauses due
+  to a major collection taking place.  Previously, it would pause the program 
(rarely)
+  to walk all live objects, which could take arbitrarily long if your process 
is using
+  a whole lot of RAM.  Now the same work is done in steps.  This should make 
PyPy
+  more responsive, e.g. in games.  There are still other pauses, from the GC 
and the JIT,
+  but they should be on the order of 5 milliseconds each.
+
+* The JIT counters for hot code were never reset, which meant that a process 
running
+  for long enough would eventually JIT-compile more and more rarely executed 
code.
+  Not only is it useless to compile such code, but as more compiled code means 
more
+  memory used, this gives the impression of a memory leak.  This has been 
tentatively
+  fixed by decreasing the counters from time to time.
+
+* NumPy has been split: now PyPy only contains the core module, called 
``_numpypy``.
+  The ``numpy`` module itself has been moved to 
``https://bitbucket.org/pypy/numpy``.
+  You need to install it separately in a virtualenv with
+  ``pip install git+https://bitbucket.org/pypy/numpy.git``.
+
+* improvements to non-inlined calls
+
+* sys.set_trace is now JITted (think coverage)
+
+* faster json
+
+* improvements in buffer copying
+
+* tk is supported (XXX was already in pypy 2.1 it seems?? maybe not correctly 
packaged?)
+
+* We finally wrote all the missing ``os.xxx()`` functions.  There are a lot of 
strange
+  ones that nobody ever heard about, except those who really need them.
+
+* numpy C API
+
+
+ the core module is included in PyPy 2.2, but you must now install
+  an external fork of numpy from https://bitbucket.org/pypy/numpy
+
+
+removed in favor of an external numpy fork
 at https://bitbucket.org/pypy/numpy
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi default: Ah bah

2013-11-12 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r1413:71a521ed3573
Date: 2013-11-12 14:30 +0100
http://bitbucket.org/cffi/cffi/changeset/71a521ed3573/

Log:Ah bah

diff --git a/testing/test_verify.py b/testing/test_verify.py
--- a/testing/test_verify.py
+++ b/testing/test_verify.py
@@ -711,7 +711,7 @@
  #define BAZ ...\n)
 lib = ffi.verify(#define FOO 42\n
  #define BAR (-44)\n
- #define BAZ 0xLL\n)
+ #define BAZ 0xULL\n)
 assert lib.FOO == 42
 assert lib.BAR == -44
 assert lib.BAZ == 0x
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy release-2.2.x: Import cffi/71a521ed3573

2013-11-12 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: release-2.2.x
Changeset: r67980:729af32ca599
Date: 2013-11-12 14:31 +0100
http://bitbucket.org/pypy/pypy/changeset/729af32ca599/

Log:Import cffi/71a521ed3573

diff --git a/pypy/module/test_lib_pypy/cffi_tests/test_verify.py 
b/pypy/module/test_lib_pypy/cffi_tests/test_verify.py
--- a/pypy/module/test_lib_pypy/cffi_tests/test_verify.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/test_verify.py
@@ -712,7 +712,7 @@
  #define BAZ ...\n)
 lib = ffi.verify(#define FOO 42\n
  #define BAR (-44)\n
- #define BAZ 0xLL\n)
+ #define BAZ 0xULL\n)
 assert lib.FOO == 42
 assert lib.BAR == -44
 assert lib.BAZ == 0x
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi default: Skip half the test with MSVC

2013-11-12 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r1414:8c9468c7c428
Date: 2013-11-12 14:33 +0100
http://bitbucket.org/cffi/cffi/changeset/8c9468c7c428/

Log:Skip half the test with MSVC

diff --git a/testing/test_verify.py b/testing/test_verify.py
--- a/testing/test_verify.py
+++ b/testing/test_verify.py
@@ -1601,6 +1601,8 @@
 (maxulong, -1, ''),
 (-1, 0x, 'U'),
 (-1, maxulong, 'UL')]:
+if c2c and sys.platform == 'win32':
+continue # enums may always be signed with MSVC
 ffi = FFI()
 ffi.cdef(enum foo_e { AA=%s }; % c1)
 e = py.test.raises(VerificationError, ffi.verify,
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy release-2.2.x: Import cffi/8c9468c7c428

2013-11-12 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: release-2.2.x
Changeset: r67981:f3423a62cd09
Date: 2013-11-12 14:33 +0100
http://bitbucket.org/pypy/pypy/changeset/f3423a62cd09/

Log:Import cffi/8c9468c7c428

diff --git a/pypy/module/test_lib_pypy/cffi_tests/test_verify.py 
b/pypy/module/test_lib_pypy/cffi_tests/test_verify.py
--- a/pypy/module/test_lib_pypy/cffi_tests/test_verify.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/test_verify.py
@@ -1602,6 +1602,8 @@
 (maxulong, -1, ''),
 (-1, 0x, 'U'),
 (-1, maxulong, 'UL')]:
+if c2c and sys.platform == 'win32':
+continue # enums may always be signed with MSVC
 ffi = FFI()
 ffi.cdef(enum foo_e { AA=%s }; % c1)
 e = py.test.raises(VerificationError, ffi.verify,
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi default: Carefully write the Python 3 version of getwinerror(). I have no way to

2013-11-12 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r1415:3f83df0a79e3
Date: 2013-11-12 15:00 +0100
http://bitbucket.org/cffi/cffi/changeset/3f83df0a79e3/

Log:Carefully write the Python 3 version of getwinerror(). I have no
way to know if I did a typo there.

diff --git a/c/misc_win32.h b/c/misc_win32.h
--- a/c/misc_win32.h
+++ b/c/misc_win32.h
@@ -80,6 +80,54 @@
 /* else: cannot report the error */
 }
 
+#if PY_MAJOR_VERSION = 3
+static PyObject *b_getwinerror(PyObject *self, PyObject *args)
+{
+int err = -1;
+int len;
+WCHAR *s_buf = NULL; /* Free via LocalFree */
+PyObject *v, *message;
+
+if (!PyArg_ParseTuple(args, |i, err))
+return NULL;
+
+if (err == -1) {
+struct cffi_errno_s *p;
+p = _geterrno_object();
+if (p == NULL)
+return PyErr_NoMemory();
+err = p-saved_lasterror;
+}
+
+len = FormatMessageW(
+/* Error API error */
+FORMAT_MESSAGE_ALLOCATE_BUFFER |
+FORMAT_MESSAGE_FROM_SYSTEM |
+FORMAT_MESSAGE_IGNORE_INSERTS,
+NULL,   /* no message source */
+err,
+MAKELANGID(LANG_NEUTRAL,
+SUBLANG_DEFAULT), /* Default language */
+(LPWSTR) s_buf,
+0,  /* size not used */
+NULL);  /* no args */
+if (len==0) {
+/* Only seen this in out of mem situations */
+message = PyUnicode_FromFormat(Windows Error 0x%X, err);
+} else {
+/* remove trailing cr/lf and dots */
+while (len  0  (s_buf[len-1] = L' ' || s_buf[len-1] == L'.'))
+s_buf[--len] = L'\0';
+message = PyUnicode_FromWideChar(s_buf, len);
+}
+if (message != NULL)
+v = Py_BuildValue((iO), err, message);
+else
+v = NULL;
+LocalFree(s_buf);
+return v;
+}
+#else
 static PyObject *b_getwinerror(PyObject *self, PyObject *args)
 {
 int err = -1;
@@ -127,6 +175,7 @@
 LocalFree(s_buf);
 return v;
 }
+#endif
 
 //
 /* Emulate dlopen()co. from the Windows API */
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Don't crash if no user group is called 'root'.

2013-11-12 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r67982:c151e8359d3a
Date: 2013-11-12 15:18 +0100
http://bitbucket.org/pypy/pypy/changeset/c151e8359d3a/

Log:Don't crash if no user group is called 'root'.

diff --git a/pypy/module/test_lib_pypy/test_grp_extra.py 
b/pypy/module/test_lib_pypy/test_grp_extra.py
--- a/pypy/module/test_lib_pypy/test_grp_extra.py
+++ b/pypy/module/test_lib_pypy/test_grp_extra.py
@@ -10,7 +10,11 @@
 No grp module on this platform)
 
 def test_basic(self):
-g = self.grp.getgrnam(root)
+raises(KeyError, self.grp.getgrnam, dEkLofcG)
+try:
+g = self.grp.getgrnam(root)
+except KeyError:
+return # no 'root' group on OS/X?
 assert g.gr_gid == 0
 assert g.gr_mem == ['root'] or g.gr_mem == []
 assert g.gr_name == 'root'
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy stmgc-c4: fix for threadlocal access. It was missing barriers and push_roots.

2013-11-12 Thread Raemi
Author: Remi Meier remi.me...@gmail.com
Branch: stmgc-c4
Changeset: r67983:73cb960f51c7
Date: 2013-11-12 16:01 +0100
http://bitbucket.org/pypy/pypy/changeset/73cb960f51c7/

Log:fix for threadlocal access. It was missing barriers and push_roots.

diff --git a/TODO b/TODO
--- a/TODO
+++ b/TODO
@@ -1,3 +1,9 @@
+
+
+should stm_thread_local_obj always be read  writeable? would
+a write-barrier in begin_transaction be too much for small
+transactions? should we handle it specially (undolog?)
+
 
 
 looking at trace of fibo.tlc (targettlc.py), there are a lot
diff --git a/rpython/memory/gctransform/stmframework.py 
b/rpython/memory/gctransform/stmframework.py
--- a/rpython/memory/gctransform/stmframework.py
+++ b/rpython/memory/gctransform/stmframework.py
@@ -104,6 +104,7 @@
 gct_stm_perform_transaction = _gct_with_roots_pushed
 gct_stm_allocate_nonmovable_int_adr = _gct_with_roots_pushed
 gct_stm_inspect_abort_info  = _gct_with_roots_pushed
+gct_stm_threadlocalref_set  = _gct_with_roots_pushed
 
 
 class StmRootWalker(BaseRootWalker):
diff --git a/rpython/rtyper/lltypesystem/lloperation.py 
b/rpython/rtyper/lltypesystem/lloperation.py
--- a/rpython/rtyper/lltypesystem/lloperation.py
+++ b/rpython/rtyper/lltypesystem/lloperation.py
@@ -440,7 +440,8 @@
 'stm_weakref_allocate':   LLOp(sideeffects=False, canmallocgc=True),
 
 'stm_threadlocalref_get': LLOp(sideeffects=False),
-'stm_threadlocalref_set': LLOp(),
+'stm_threadlocalref_set': LLOp(canmallocgc=True), # may allocate new array,
+  # see threadlocalref.py
 'stm_threadlocal_get':LLOp(sideeffects=False),
 'stm_threadlocal_set':LLOp(),
 
diff --git a/rpython/translator/stm/funcgen.py 
b/rpython/translator/stm/funcgen.py
--- a/rpython/translator/stm/funcgen.py
+++ b/rpython/translator/stm/funcgen.py
@@ -53,7 +53,14 @@
 
 def stm_barrier(funcgen, op):
 category_change = op.args[0].value
-frm, middle, to = category_change
+# XXX: how to unify the stm_barrier llop generation in
+#  writebarrier.py and threadlocalref.py?
+if isinstance(category_change, str):
+frm, middle, to = category_change
+else: # rstr
+frm, middle, to = (category_change.chars[0],
+   category_change.chars[1],
+   category_change.chars[2])
 assert middle == '2'
 assert frm  to
 if to == 'W':
diff --git a/rpython/translator/stm/threadlocalref.py 
b/rpython/translator/stm/threadlocalref.py
--- a/rpython/translator/stm/threadlocalref.py
+++ b/rpython/translator/stm/threadlocalref.py
@@ -28,13 +28,19 @@
 if not array:
 return lltype.nullptr(rclass.OBJECTPTR.TO)
 else:
+array = llop.stm_barrier(lltype.Ptr(ARRAY), 'A2R', array)
 return array[index]
 #
 def ll_threadlocalref_set(index, newvalue):
 array = llop.stm_threadlocal_get(lltype.Ptr(ARRAY))
 if not array:
-array = lltype.malloc(ARRAY, total)
+array = lltype.malloc(ARRAY, total) # llop may allocate!
 llop.stm_threadlocal_set(lltype.Void, array)
+else:
+array = llop.stm_barrier(lltype.Ptr(ARRAY), 'A2W', array)
+# invalidating other barriers after an llop.threadlocalref_set
+# is not necessary since no other variable should contain
+# a reference to stm_threadlocal_obj
 array[index] = newvalue
 #
 annhelper = annlowlevel.MixLevelHelperAnnotator(t.rtyper)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi default: Test various combinations of calls. Mostly a libffi stress-test.

2013-11-12 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r1416:be9745bbc509
Date: 2013-11-12 16:12 +0100
http://bitbucket.org/cffi/cffi/changeset/be9745bbc509/

Log:Test various combinations of calls. Mostly a libffi stress-test.

diff --git a/testing/test_verify.py b/testing/test_verify.py
--- a/testing/test_verify.py
+++ b/testing/test_verify.py
@@ -1767,3 +1767,87 @@
 ffi.cdef(const int a[];)
 lib = ffi.verify(const int a[5];)
 assert repr(ffi.typeof(lib.a)) == ctype 'int *'
+
+def _test_various_calls(force_libffi):
+cdef_source = 
+int xvalue;
+long long ivalue, rvalue;
+float fvalue;
+double dvalue;
+long double Dvalue;
+signed char tf_bb(signed char x, signed char c);
+unsigned char tf_bB(signed char x, unsigned char c);
+short tf_bh(signed char x, short c);
+unsigned short tf_bH(signed char x, unsigned short c);
+int tf_bi(signed char x, int c);
+unsigned int tf_bI(signed char x, unsigned int c);
+long tf_bl(signed char x, long c);
+unsigned long tf_bL(signed char x, unsigned long c);
+long long tf_bq(signed char x, long long c);
+float tf_bf(signed char x, float c);
+double tf_bd(signed char x, double c);
+long double tf_bD(signed char x, long double c);
+
+if force_libffi:
+cdef_source = (cdef_source
+.replace('tf_', '(*const tf_')
+.replace('(signed char x', ')(signed char x'))
+ffi = FFI()
+ffi.cdef(cdef_source)
+lib = ffi.verify(
+int xvalue;
+long long ivalue, rvalue;
+float fvalue;
+double dvalue;
+long double Dvalue;
+
+#define S(letter)  xvalue = x; letter##value = c; return rvalue;
+
+signed char tf_bb(signed char x, signed char c) { S(i) }
+unsigned char tf_bB(signed char x, unsigned char c) { S(i) }
+short tf_bh(signed char x, short c) { S(i) }
+unsigned short tf_bH(signed char x, unsigned short c) { S(i) }
+int tf_bi(signed char x, int c) { S(i) }
+unsigned int tf_bI(signed char x, unsigned int c) { S(i) }
+long tf_bl(signed char x, long c) { S(i) }
+unsigned long tf_bL(signed char x, unsigned long c) { S(i) }
+long long tf_bq(signed char x, long long c) { S(i) }
+float tf_bf(signed char x, float c) { S(f) }
+double tf_bd(signed char x, double c) { S(d) }
+long double tf_bD(signed char x, long double c) { S(D) }
+)
+lib.rvalue = 0x7182838485868788
+for kind, cname in [('b', 'signed char'),
+('B', 'unsigned char'),
+('h', 'short'),
+('H', 'unsigned short'),
+('i', 'int'),
+('I', 'unsigned int'),
+('l', 'long'),
+('L', 'unsigned long'),
+('q', 'long long'),
+('f', 'float'),
+('d', 'double'),
+('D', 'long double')]:
+sign = +1 if 'unsigned' in cname else -1
+lib.xvalue = 0
+lib.ivalue = 0
+lib.fvalue = 0
+lib.dvalue = 0
+lib.Dvalue = 0
+fun = getattr(lib, 'tf_b' + kind)
+res = fun(-42, sign * 99)
+if kind == 'D':
+res = float(res)
+assert res == int(ffi.cast(cname, 0x7182838485868788))
+assert lib.xvalue == -42
+if kind in 'fdD':
+assert float(getattr(lib, kind + 'value')) == -99.0
+else:
+assert lib.ivalue == sign * 99
+
+def test_various_calls_direct():
+_test_various_calls(force_libffi=False)
+
+def test_various_calls_libffi():
+_test_various_calls(force_libffi=True)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] buildbot default: allow the BUILDJITLINUXARMHF_RARING builder to be forced

2013-11-12 Thread bivab
Author: David Schneider david.schnei...@picle.org
Branch: 
Changeset: r889:2c32efb0fb5d
Date: 2013-11-12 18:26 +0100
http://bitbucket.org/pypy/buildbot/changeset/2c32efb0fb5d/

Log:allow the BUILDJITLINUXARMHF_RARING builder to be forced

diff --git a/bot2/pypybuildbot/arm_master.py b/bot2/pypybuildbot/arm_master.py
--- a/bot2/pypybuildbot/arm_master.py
+++ b/bot2/pypybuildbot/arm_master.py
@@ -136,6 +136,7 @@
 BUILDJITLINUXARM,
 BUILDLINUXARMHF_RASPBIAN,
 BUILDJITLINUXARMHF_RASPBIAN,
+BUILDJITLINUXARMHF_RARING,
 ]
 
 schedulers = [
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: fix this test a bit more strictly

2013-11-12 Thread bdkearns
Author: Brian Kearns bdkea...@gmail.com
Branch: 
Changeset: r67984:b1014f8d559c
Date: 2013-11-12 10:12 -0800
http://bitbucket.org/pypy/pypy/changeset/b1014f8d559c/

Log:fix this test a bit more strictly

diff --git a/pypy/module/test_lib_pypy/test_grp_extra.py 
b/pypy/module/test_lib_pypy/test_grp_extra.py
--- a/pypy/module/test_lib_pypy/test_grp_extra.py
+++ b/pypy/module/test_lib_pypy/test_grp_extra.py
@@ -11,14 +11,18 @@
 
 def test_basic(self):
 raises(KeyError, self.grp.getgrnam, dEkLofcG)
-try:
-g = self.grp.getgrnam(root)
-except KeyError:
-return # no 'root' group on OS/X?
-assert g.gr_gid == 0
-assert g.gr_mem == ['root'] or g.gr_mem == []
-assert g.gr_name == 'root'
-assert isinstance(g.gr_passwd, str)# usually just 'x', don't hope 
:-)
+for name in [root, wheel]:
+try:
+g = self.grp.getgrnam(name)
+except KeyError:
+continue
+assert g.gr_gid == 0
+assert g.gr_mem == ['root'] or g.gr_mem == []
+assert g.gr_name == name
+assert isinstance(g.gr_passwd, str)# usually just 'x', don't 
hope :-)
+break
+else:
+raise
 
 def test_extra(self):
 grp = self.grp
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: update usemodules so it doesn't skip untranslated

2013-11-12 Thread bdkearns
Author: Brian Kearns bdkea...@gmail.com
Branch: 
Changeset: r67985:9c9132e23801
Date: 2013-11-12 13:19 -0500
http://bitbucket.org/pypy/pypy/changeset/9c9132e23801/

Log:update usemodules so it doesn't skip untranslated

diff --git a/pypy/module/test_lib_pypy/test_grp_extra.py 
b/pypy/module/test_lib_pypy/test_grp_extra.py
--- a/pypy/module/test_lib_pypy/test_grp_extra.py
+++ b/pypy/module/test_lib_pypy/test_grp_extra.py
@@ -2,8 +2,7 @@
 
 
 class AppTestGrp:
-
-spaceconfig = dict(usemodules=('_ffi', '_rawffi', 'itertools'))
+spaceconfig = dict(usemodules=('binascii', '_ffi', '_rawffi', 'itertools'))
 
 def setup_class(cls):
 cls.w_grp = import_lib_pypy(cls.space, 'grp',
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy armhf-singlefloat: enable singlefloats on ARMHF

2013-11-12 Thread bivab
Author: David Schneider david.schnei...@picle.org
Branch: armhf-singlefloat
Changeset: r67986:063d0dcda94f
Date: 2013-11-12 09:46 -0600
http://bitbucket.org/pypy/pypy/changeset/063d0dcda94f/

Log:enable singlefloats on ARMHF

diff --git a/rpython/jit/backend/arm/runner.py 
b/rpython/jit/backend/arm/runner.py
--- a/rpython/jit/backend/arm/runner.py
+++ b/rpython/jit/backend/arm/runner.py
@@ -22,7 +22,7 @@
 supports_floats = True
 supports_longlong = False # XXX requires an implementation of
   # read_timestamp that works in user mode
-supports_singlefloats = not detect_hardfloat()
+supports_singlefloats = True
 
 from rpython.jit.backend.arm.arch import JITFRAME_FIXED_SIZE
 all_reg_indexes = range(len(all_regs))
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy armhf-singlefloat: unused

2013-11-12 Thread bivab
Author: David Schneider david.schnei...@picle.org
Branch: armhf-singlefloat
Changeset: r67987:41afcae95cfd
Date: 2013-11-12 09:49 -0600
http://bitbucket.org/pypy/pypy/changeset/41afcae95cfd/

Log:unused

diff --git a/rpython/jit/backend/arm/locations.py 
b/rpython/jit/backend/arm/locations.py
--- a/rpython/jit/backend/arm/locations.py
+++ b/rpython/jit/backend/arm/locations.py
@@ -55,10 +55,6 @@
 type = FLOAT
 width = 2 * WORD
 
-def get_single_precision_regs(self):
-return [VFPRegisterLocation(i) for i in
-[self.value * 2, self.value * 2 + 1]]
-
 def __repr__(self):
 return 'vfp%d' % self.value
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy armhf-singlefloat: handle singlefloats in callbuilder

2013-11-12 Thread bivab
Author: David Schneider david.schnei...@picle.org
Branch: armhf-singlefloat
Changeset: r67990:7bc08fc09a9e
Date: 2013-11-12 12:07 -0600
http://bitbucket.org/pypy/pypy/changeset/7bc08fc09a9e/

Log:handle singlefloats in callbuilder

diff --git a/rpython/jit/backend/arm/callbuilder.py 
b/rpython/jit/backend/arm/callbuilder.py
--- a/rpython/jit/backend/arm/callbuilder.py
+++ b/rpython/jit/backend/arm/callbuilder.py
@@ -227,20 +227,81 @@
 
 class HardFloatCallBuilder(ARMCallbuilder):
 
+next_arg_vfp = 0
+next_arg_svfp = 0
+
+def get_next_vfp(self, tp):
+assert tp in 'fS'
+if self.next_arg_vfp == -1:
+return None
+if tp == 'S':
+i = self.next_arg_svfp
+next_vfp = (i  1) + 1
+if not (i + 1)  1: # i is even
+self.next_arg_vfp = max(self.next_arg_vfp, next_vfp)
+self.next_arg_svfp = self.next_arg_vfp  1
+else:
+self.next_arg_svfp += 1
+self.next_arg_vfp = next_vfp
+lst = r.svfp_argument_regs
+else: # 64bit double
+i = self.next_arg_vfp
+self.next_arg_vfp += 1
+if self.next_arg_svfp  1 == i:
+self.next_arg_svfp = self.next_arg_vfp  1
+lst = r.vfp_argument_regs
+try:
+return lst[i]
+except IndexError:
+self.next_arg_vfp = self.next_arg_svfp = -1
+return None
+
 def prepare_arguments(self):
 non_float_locs = []
 non_float_regs = []
 float_locs = []
 float_regs = []
 stack_args = []
+singlefloats = None
 
 arglocs = self.arglocs
 argtypes = self.argtypes
 
 count = 0  # stack alignment counter
 on_stack = 0
-for arg in arglocs:
-if arg.type != FLOAT:
+for i in range(len(arglocs)):
+argtype = INT
+if i  len(argtypes) and argtypes[i] == 'S':
+argtype = argtypes[i]
+arg = arglocs[i]
+if arg.is_float():
+argtype = FLOAT
+reg = self.get_next_vfp(argtype)
+if reg:
+assert len(float_regs)  len(r.vfp_argument_regs)
+float_locs.append(arg)
+assert reg not in float_regs
+float_regs.append(reg)
+else:  # float argument that needs to go on the stack
+if count % 2 != 0:
+stack_args.append(None)
+count = 0
+on_stack += 1
+stack_args.append(arg)
+on_stack += 2
+elif argtype == 'S':
+# Singlefloat argument
+if singlefloats is None:
+singlefloats = []
+tgt = self.get_next_vfp(argtype)
+if tgt:
+singlefloats.append((arg, tgt))
+else:  # Singlefloat argument that needs to go on the stack
+   # treated the same as a regular core register argument
+count += 1
+on_stack += 1
+stack_args.append(arg)
+else:
 if len(non_float_regs)  len(r.argument_regs):
 reg = r.argument_regs[len(non_float_regs)]
 non_float_locs.append(arg)
@@ -249,18 +310,6 @@
 count += 1
 on_stack += 1
 stack_args.append(arg)
-else:
-if len(float_regs)  len(r.vfp_argument_regs):
-reg = r.vfp_argument_regs[len(float_regs)]
-float_locs.append(arg)
-float_regs.append(reg)
-else:  # float argument that needs to go on the stack
-if count % 2 != 0:
-stack_args.append(None)
-count = 0
-on_stack += 1
-stack_args.append(arg)
-on_stack += 2
 # align the stack
 if count % 2 != 0:
 stack_args.append(None)
@@ -275,13 +324,28 @@
 non_float_locs.append(self.fnloc)
 non_float_regs.append(r.r4)
 self.fnloc = r.r4
+# remap values stored in vfp registers
+remap_frame_layout(self.asm, float_locs, float_regs, r.vfp_ip)
+if singlefloats:
+for src, dest in singlefloats:
+if src.is_float():
+assert 0, 'unsupported case'
+if src.is_stack():
+# use special VLDR for 32bit
+self.asm.regalloc_mov(src, r.ip)
+src = r.ip
+if src.is_imm():
+self.mc.gen_load_int(r.ip.value, src.value)
+src = r.ip
+if 

[pypy-commit] pypy armhf-singlefloat: add single precission VFP register locations

2013-11-12 Thread bivab
Author: David Schneider david.schnei...@picle.org
Branch: armhf-singlefloat
Changeset: r67988:93c961fe1b79
Date: 2013-11-12 09:52 -0600
http://bitbucket.org/pypy/pypy/changeset/93c961fe1b79/

Log:add single precission VFP register locations

diff --git a/rpython/jit/backend/arm/locations.py 
b/rpython/jit/backend/arm/locations.py
--- a/rpython/jit/backend/arm/locations.py
+++ b/rpython/jit/backend/arm/locations.py
@@ -56,7 +56,7 @@
 width = 2 * WORD
 
 def __repr__(self):
-return 'vfp%d' % self.value
+return 'vfp(d%d)' % self.value
 
 def is_core_reg(self):
 return False
@@ -70,6 +70,14 @@
 def is_float(self):
 return True
 
+class SVFPRegisterLocation(VFPRegisterLocation):
+Single Precission VFP Register
+_immutable_ = True
+width = WORD
+type = 'S'
+
+def __repr__(self):
+return 'vfp(s%d)' % self.value
 
 class ImmLocation(AssemblerLocation):
 _immutable_ = True
diff --git a/rpython/jit/backend/arm/registers.py 
b/rpython/jit/backend/arm/registers.py
--- a/rpython/jit/backend/arm/registers.py
+++ b/rpython/jit/backend/arm/registers.py
@@ -1,8 +1,10 @@
 from rpython.jit.backend.arm.locations import VFPRegisterLocation
+from rpython.jit.backend.arm.locations import SVFPRegisterLocation
 from rpython.jit.backend.arm.locations import RegisterLocation
 
 registers = [RegisterLocation(i) for i in range(16)]
 vfpregisters = [VFPRegisterLocation(i) for i in range(16)]
+svfpregisters = [SVFPRegisterLocation(i) for i in range(32)]
 [r0, r1, r2, r3, r4, r5, r6, r7,
 r8, r9, r10, r11, r12, r13, r14, r15] = registers
 
@@ -10,6 +12,10 @@
 [d0, d1, d2, d3, d4, d5, d6, d7,
 d8, d9, d10, d11, d12, d13, d14, d15] = vfpregisters
 
+# single precission VFP registers, 32-bit
+for i in range(32):
+globals()['s%d' % i] = svfpregisters[i]
+
 # aliases for registers
 fp = r11
 ip = r12
@@ -27,6 +33,7 @@
 callee_restored_registers = callee_resp + [pc]
 
 vfp_argument_regs = caller_vfp_resp = [d0, d1, d2, d3, d4, d5, d6, d7]
+svfp_argument_regs = [globals()['s%i' % i] for i in range(16)]
 callee_vfp_resp = [d8, d9, d10, d11, d12, d13, d14, d15]
 
 callee_saved_vfp_registers = callee_vfp_resp
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy armhf-singlefloat: add operations to move between core and single precision VFP registers

2013-11-12 Thread bivab
Author: David Schneider david.schnei...@picle.org
Branch: armhf-singlefloat
Changeset: r67989:3c95419f55a7
Date: 2013-11-12 12:06 -0600
http://bitbucket.org/pypy/pypy/changeset/3c95419f55a7/

Log:add operations to move between core and single precision VFP
registers

diff --git a/rpython/jit/backend/arm/codebuilder.py 
b/rpython/jit/backend/arm/codebuilder.py
--- a/rpython/jit/backend/arm/codebuilder.py
+++ b/rpython/jit/backend/arm/codebuilder.py
@@ -178,6 +178,30 @@
 | (dm  0xF))
 self.write32(instr)
 
+def VMOV_sc(self, dest, src):
+move a single precision vfp register[src] to a core reg[dest]
+self._VMOV_32bit(src, dest, to_arm_register=1)
+
+def VMOV_cs(self, dest, src):
+move a core register[src] to a single precision vfp
+register[dest]
+self._VMOV_32bit(dest, src, to_arm_register=0)
+
+def _VMOV_32bit(self, float_reg, core_reg, to_arm_register, cond=cond.AL):
+This instruction transfers the contents of a single-precision VFP
+   register to an ARM core register, or the contents of an ARM core
+   register to a single-precision VFP register.
+
+instr = (cond  28
+| 0xE  24
+| to_arm_register  20
+| ((float_reg  1)  0xF)  16
+| core_reg  12
+| 0xA  8
+| (float_reg  0x1)  7
+| 1  4)
+self.write32(instr)
+
 def VMOV_cc(self, dd, dm, cond=cond.AL):
 sz = 1  # for 64-bit mode
 instr = (cond  28
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: clean up some numpypy references

2013-11-12 Thread bdkearns
Author: Brian Kearns bdkea...@gmail.com
Branch: 
Changeset: r67991:e85c7e78f011
Date: 2013-11-12 15:25 -0500
http://bitbucket.org/pypy/pypy/changeset/e85c7e78f011/

Log:clean up some numpypy references

diff --git a/pypy/module/micronumpy/interp_dtype.py 
b/pypy/module/micronumpy/interp_dtype.py
--- a/pypy/module/micronumpy/interp_dtype.py
+++ b/pypy/module/micronumpy/interp_dtype.py
@@ -401,7 +401,7 @@
 raise operationerrfmt(space.w_TypeError, msg, w_dtype)
 
 W_Dtype.typedef = TypeDef(dtype,
-__module__ = numpypy,
+__module__ = numpy,
 __new__ = interp2app(descr__new__),
 
 __str__= interp2app(W_Dtype.descr_str),
diff --git a/pypy/module/micronumpy/interp_numarray.py 
b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -338,11 +338,11 @@
 
 Returns an array containing the same data with a new shape.
 
-Refer to `numpypy.reshape` for full documentation.
+Refer to `numpy.reshape` for full documentation.
 
 See Also
 
-numpypy.reshape : equivalent function
+numpy.reshape : equivalent function
 
 args_w, kw_w = __args__.unpack()
 order = NPY_CORDER
@@ -1123,9 +1123,8 @@
 return res
 , filename=__file__).interphook('ptp')
 
-W_NDimArray.typedef = TypeDef(
-ndarray,
-__module__ = numpypy,
+W_NDimArray.typedef = TypeDef(ndarray,
+__module__ = numpy,
 __new__ = interp2app(descr_new_array),
 
 __len__ = interp2app(W_NDimArray.descr_len),
@@ -1391,8 +1390,8 @@
 return box
 
 
-W_FlatIterator.typedef = TypeDef(
-'flatiter',
+W_FlatIterator.typedef = TypeDef(flatiter,
+__module__ = numpy,
 __iter__ = interp2app(W_FlatIterator.descr_iter),
 __getitem__ = interp2app(W_FlatIterator.descr_getitem),
 __setitem__ = interp2app(W_FlatIterator.descr_setitem),
diff --git a/pypy/module/micronumpy/interp_ufuncs.py 
b/pypy/module/micronumpy/interp_ufuncs.py
--- a/pypy/module/micronumpy/interp_ufuncs.py
+++ b/pypy/module/micronumpy/interp_ufuncs.py
@@ -413,7 +413,7 @@
 
 
 W_Ufunc.typedef = TypeDef(ufunc,
-__module__ = numpypy,
+__module__ = numpy,
 
 __call__ = interp2app(W_Ufunc.descr_call),
 __repr__ = interp2app(W_Ufunc.descr_repr),
diff --git a/pypy/module/micronumpy/test/test_dtypes.py 
b/pypy/module/micronumpy/test/test_dtypes.py
--- a/pypy/module/micronumpy/test/test_dtypes.py
+++ b/pypy/module/micronumpy/test/test_dtypes.py
@@ -26,6 +26,7 @@
 assert d.kind == 'b'
 assert dtype(d) is d
 assert dtype('bool') is d
+assert repr(type(d)) == type 'numpy.dtype'
 
 assert dtype('int8').num == 1
 assert dtype('int8').name == 'int8'
diff --git a/pypy/module/micronumpy/test/test_numarray.py 
b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -249,9 +249,11 @@
 return CustomIntObject(value)
 
 def test_ndarray(self):
-from numpypy import ndarray, array, dtype
+from numpy import ndarray, array, dtype, flatiter
 
 assert type(ndarray) is type
+assert repr(ndarray) == type 'numpy.ndarray'
+assert repr(flatiter) == type 'numpy.flatiter'
 assert type(array) is not type
 a = ndarray((2, 3))
 assert a.shape == (2, 3)
diff --git a/pypy/module/micronumpy/test/test_ufuncs.py 
b/pypy/module/micronumpy/test/test_ufuncs.py
--- a/pypy/module/micronumpy/test/test_ufuncs.py
+++ b/pypy/module/micronumpy/test/test_ufuncs.py
@@ -81,7 +81,7 @@
 
 assert isinstance(add, ufunc)
 assert repr(add) == ufunc 'add'
-assert repr(ufunc) == type 'numpypy.ufunc' or repr(ufunc) == 
type 'numpy.ufunc'
+assert repr(ufunc) == type 'numpy.ufunc'
 
 def test_ufunc_attrs(self):
 from numpypy import add, multiply, sin
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy armhf-singlefloat: use single precision operations for casts to and from float

2013-11-12 Thread bivab
Author: David Schneider david.schnei...@picle.org
Branch: armhf-singlefloat
Changeset: r67992:d8b1b0c57e72
Date: 2013-11-12 14:41 -0600
http://bitbucket.org/pypy/pypy/changeset/d8b1b0c57e72/

Log:use single precision operations for casts to and from float

diff --git a/rpython/jit/backend/arm/codebuilder.py 
b/rpython/jit/backend/arm/codebuilder.py
--- a/rpython/jit/backend/arm/codebuilder.py
+++ b/rpython/jit/backend/arm/codebuilder.py
@@ -222,8 +222,16 @@
 self._VCVT(target, source, cond, 0, 1)
 
 def _VCVT(self, target, source, cond, opc2, sz):
-D = 0
-M = 0
+# A8.6.295
+to_integer = (opc2  2)  1
+if to_integer:
+D = target  1
+target = 1
+M = (source  4)  1
+else:
+M = source  1
+source = 1
+D = (target  4)  1
 op = 1
 instr = (cond  28
 | 0xEB8  16
@@ -240,8 +248,8 @@
 
 def _VCVT_single_double(self, target, source, cond, sz):
 # double_to_single = (sz == '1');
-D = 0
-M = 0
+D = target  1 if sz else (target  4)  1
+M = (source  4)  1 if sz else source  1
 instr = (cond  28
 | 0xEB7  16
 | 0xAC  4
diff --git a/rpython/jit/backend/arm/opassembler.py 
b/rpython/jit/backend/arm/opassembler.py
--- a/rpython/jit/backend/arm/opassembler.py
+++ b/rpython/jit/backend/arm/opassembler.py
@@ -1102,17 +1102,16 @@
 arg, res = arglocs
 assert arg.is_vfp_reg()
 assert res.is_core_reg()
-self.mc.VCVT_float_to_int(r.vfp_ip.value, arg.value)
-self.mc.VMOV_rc(res.value, r.ip.value, r.vfp_ip.value)
+self.mc.VCVT_float_to_int(r.svfp_ip.value, arg.value)
+self.mc.VMOV_sc(res.value, r.svfp_ip.value)
 return fcond
 
 def emit_op_cast_int_to_float(self, op, arglocs, regalloc, fcond):
 arg, res = arglocs
 assert res.is_vfp_reg()
 assert arg.is_core_reg()
-self.mc.MOV_ri(r.ip.value, 0)
-self.mc.VMOV_cr(res.value, arg.value, r.ip.value)
-self.mc.VCVT_int_to_float(res.value, res.value)
+self.mc.VMOV_cs(r.svfp_ip.value, arg.value)
+self.mc.VCVT_int_to_float(res.value, r.svfp_ip.value)
 return fcond
 
 emit_op_llong_add = gen_emit_float_op('llong_add', 'VADD_i64')
@@ -1147,15 +1146,14 @@
 arg, res = arglocs
 assert arg.is_vfp_reg()
 assert res.is_core_reg()
-self.mc.VCVT_f64_f32(r.vfp_ip.value, arg.value)
-self.mc.VMOV_rc(res.value, r.ip.value, r.vfp_ip.value)
+self.mc.VCVT_f64_f32(r.svfp_ip.value, arg.value)
+self.mc.VMOV_sc(res.value, r.svfp_ip.value)
 return fcond
 
 def emit_op_cast_singlefloat_to_float(self, op, arglocs, regalloc, fcond):
 arg, res = arglocs
 assert res.is_vfp_reg()
 assert arg.is_core_reg()
-self.mc.MOV_ri(r.ip.value, 0)
-self.mc.VMOV_cr(res.value, arg.value, r.ip.value)
-self.mc.VCVT_f32_f64(res.value, res.value)
+self.mc.VMOV_cs(r.svfp_ip.value, arg.value)
+self.mc.VCVT_f32_f64(res.value, r.svfp_ip.value)
 return fcond
diff --git a/rpython/jit/backend/arm/registers.py 
b/rpython/jit/backend/arm/registers.py
--- a/rpython/jit/backend/arm/registers.py
+++ b/rpython/jit/backend/arm/registers.py
@@ -23,6 +23,7 @@
 lr = r14
 pc = r15
 vfp_ip = d15
+svfp_ip = s31
 
 all_regs = [r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10]
 all_vfp_regs = vfpregisters[:-1]
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: provide flags for scalars also

2013-11-12 Thread bdkearns
Author: Brian Kearns bdkea...@gmail.com
Branch: 
Changeset: r67994:592629fa85f2
Date: 2013-11-12 16:29 -0500
http://bitbucket.org/pypy/pypy/changeset/592629fa85f2/

Log:provide flags for scalars also

diff --git a/pypy/module/micronumpy/interp_boxes.py 
b/pypy/module/micronumpy/interp_boxes.py
--- a/pypy/module/micronumpy/interp_boxes.py
+++ b/pypy/module/micronumpy/interp_boxes.py
@@ -11,6 +11,7 @@
 from rpython.rtyper.lltypesystem import rffi
 from rpython.tool.sourcetools import func_with_new_name
 from pypy.module.micronumpy.arrayimpl.voidbox import VoidBoxStorage
+from pypy.module.micronumpy.interp_flagsobj import W_FlagsObject
 from pypy.interpreter.mixedmodule import MixedModule
 from rpython.rtyper.lltypesystem import lltype
 from rpython.rlib.rstring import StringBuilder
@@ -113,7 +114,7 @@
 
 
 class W_GenericBox(W_Root):
-_attrs_ = []
+_attrs_ = ['w_flags']
 
 def descr__new__(space, w_subtype, __args__):
 raise operationerrfmt(space.w_TypeError,
@@ -292,6 +293,12 @@
 def descr_copy(self, space):
 return self.convert_to(self.get_dtype(space))
 
+w_flags = None
+def descr_get_flags(self, space):
+if self.w_flags is None:
+self.w_flags = W_FlagsObject(self)
+return self.w_flags
+
 class W_BoolBox(W_GenericBox, PrimitiveBox):
 descr__new__, _get_dtype, descr_reduce = new_dtype_getter(bool)
 
@@ -550,6 +557,7 @@
 strides = GetSetProperty(W_GenericBox.descr_get_shape),
 ndim = GetSetProperty(W_GenericBox.descr_get_ndim),
 T = GetSetProperty(W_GenericBox.descr_self),
+flags = GetSetProperty(W_GenericBox.descr_get_flags),
 )
 
 W_BoolBox.typedef = TypeDef(bool_, W_GenericBox.typedef,
diff --git a/pypy/module/micronumpy/test/test_flagsobj.py 
b/pypy/module/micronumpy/test/test_flagsobj.py
--- a/pypy/module/micronumpy/test/test_flagsobj.py
+++ b/pypy/module/micronumpy/test/test_flagsobj.py
@@ -7,7 +7,7 @@
 a = np.array([1,2,3])
 assert repr(type(a.flags)) == type 'numpy.flagsobj'
 
-def test_flags(self):
+def test_array_flags(self):
 import numpy as np
 a = np.array([1,2,3])
 assert a.flags.c_contiguous == True
@@ -15,3 +15,8 @@
 raises(KeyError, a.flags['blah'])
 raises(KeyError, a.flags['C_CONTIGUOUS'] = False)
 raises((TypeError, AttributeError), a.flags.c_contiguous = False)
+
+def test_scalar_flags(self):
+import numpy as np
+a = np.int32(2)
+assert a.flags.c_contiguous == True
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: add basic ndarray.flags object

2013-11-12 Thread bdkearns
Author: Brian Kearns bdkea...@gmail.com
Branch: 
Changeset: r67993:49ca29878cd3
Date: 2013-11-12 16:24 -0500
http://bitbucket.org/pypy/pypy/changeset/49ca29878cd3/

Log:add basic ndarray.flags object

diff --git a/pypy/module/micronumpy/interp_flagsobj.py 
b/pypy/module/micronumpy/interp_flagsobj.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/micronumpy/interp_flagsobj.py
@@ -0,0 +1,45 @@
+from pypy.interpreter.baseobjspace import W_Root
+from pypy.interpreter.typedef import TypeDef, GetSetProperty
+from pypy.interpreter.gateway import interp2app
+from pypy.interpreter.error import OperationError
+
+
+class W_FlagsObject(W_Root):
+def __init__(self, arr):
+self.arr = arr
+
+def descr_get_contiguous(self, space):
+return space.w_True
+
+def descr_get_fortran(self, space):
+return space.w_False
+
+def descr_get_writeable(self, space):
+return space.w_True
+
+def descr_getitem(self, space, w_item):
+key = space.str_w(w_item)
+if key == C or key == CONTIGUOUS or key == C_CONTIGUOUS:
+return self.descr_get_contiguous(space)
+if key == F or key == FORTRAN or key == F_CONTIGUOUS:
+return self.descr_get_fortran(space)
+if key == W or key == WRITEABLE:
+return self.descr_get_writeable(space)
+raise OperationError(space.w_KeyError, space.wrap(
+Unknown flag))
+
+def descr_setitem(self, space, w_item, w_value):
+raise OperationError(space.w_KeyError, space.wrap(
+Unknown flag))
+
+W_FlagsObject.typedef = TypeDef(flagsobj,
+__module__ = numpy,
+__getitem__ = interp2app(W_FlagsObject.descr_getitem),
+__setitem__ = interp2app(W_FlagsObject.descr_setitem),
+
+contiguous = GetSetProperty(W_FlagsObject.descr_get_contiguous),
+c_contiguous = GetSetProperty(W_FlagsObject.descr_get_contiguous),
+f_contiguous = GetSetProperty(W_FlagsObject.descr_get_fortran),
+fortran = GetSetProperty(W_FlagsObject.descr_get_fortran),
+writeable = GetSetProperty(W_FlagsObject.descr_get_writeable),
+)
diff --git a/pypy/module/micronumpy/interp_numarray.py 
b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -9,6 +9,7 @@
 from pypy.module.micronumpy.strides import find_shape_and_elems,\
  get_shape_from_iterable, to_coords, shape_agreement, \
  shape_agreement_multiple
+from pypy.module.micronumpy.interp_flagsobj import W_FlagsObject
 from pypy.module.micronumpy.interp_flatiter import W_FlatIterator
 from pypy.module.micronumpy.appbridge import get_appbridge_cache
 from pypy.module.micronumpy import loop
@@ -610,13 +611,11 @@
 raise OperationError(space.w_NotImplementedError, space.wrap(
 dumps not implemented yet))
 
+w_flags = None
 def descr_get_flags(self, space):
-raise OperationError(space.w_NotImplementedError, space.wrap(
-getting flags not implemented yet))
-
-def descr_set_flags(self, space, w_args):
-raise OperationError(space.w_NotImplementedError, space.wrap(
-setting flags not implemented yet))
+if self.w_flags is None:
+self.w_flags = W_FlagsObject(self)
+return self.w_flags
 
 @unwrap_spec(offset=int)
 def descr_getfield(self, space, w_dtype, offset):
@@ -1203,6 +1202,7 @@
 size = GetSetProperty(W_NDimArray.descr_get_size),
 itemsize = GetSetProperty(W_NDimArray.descr_get_itemsize),
 nbytes = GetSetProperty(W_NDimArray.descr_get_nbytes),
+flags = GetSetProperty(W_NDimArray.descr_get_flags),
 
 fill = interp2app(W_NDimArray.descr_fill),
 tostring = interp2app(W_NDimArray.descr_tostring),
diff --git a/pypy/module/micronumpy/test/test_flagsobj.py 
b/pypy/module/micronumpy/test/test_flagsobj.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/micronumpy/test/test_flagsobj.py
@@ -0,0 +1,17 @@
+from pypy.module.micronumpy.test.test_base import BaseNumpyAppTest
+
+
+class AppTestFlagsObj(BaseNumpyAppTest):
+def test_repr(self):
+import numpy as np
+a = np.array([1,2,3])
+assert repr(type(a.flags)) == type 'numpy.flagsobj'
+
+def test_flags(self):
+import numpy as np
+a = np.array([1,2,3])
+assert a.flags.c_contiguous == True
+assert a.flags['W'] == True
+raises(KeyError, a.flags['blah'])
+raises(KeyError, a.flags['C_CONTIGUOUS'] = False)
+raises((TypeError, AttributeError), a.flags.c_contiguous = False)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Write 'ConstPtr(null)' when we know the constant is null.

2013-11-12 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r67995:4d9da705ae8f
Date: 2013-11-12 23:44 +0100
http://bitbucket.org/pypy/pypy/changeset/4d9da705ae8f/

Log:Write 'ConstPtr(null)' when we know the constant is null. May break
some tests in pypyjit/test_pypy_c.

diff --git a/rpython/jit/metainterp/logger.py b/rpython/jit/metainterp/logger.py
--- a/rpython/jit/metainterp/logger.py
+++ b/rpython/jit/metainterp/logger.py
@@ -103,7 +103,9 @@
 elif isinstance(arg, BoxInt):
 return 'i' + str(mv)
 elif isinstance(arg, self.ts.ConstRef):
-return 'ConstPtr(ptr' + str(mv) + ')'
+if arg.value:
+return 'ConstPtr(ptr' + str(mv) + ')'
+return 'ConstPtr(null)'
 elif isinstance(arg, self.ts.BoxRef):
 return 'p' + str(mv)
 elif isinstance(arg, ConstFloat):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy windows-packaging: add dlls for Tkinter

2013-11-12 Thread mattip
Author: Matti Picus matti.pi...@gmail.com
Branch: windows-packaging
Changeset: r67996:9b968361f205
Date: 2013-11-13 00:41 +0200
http://bitbucket.org/pypy/pypy/changeset/9b968361f205/

Log:add dlls for Tkinter

diff --git a/lib_pypy/_tkinter/tklib.py b/lib_pypy/_tkinter/tklib.py
--- a/lib_pypy/_tkinter/tklib.py
+++ b/lib_pypy/_tkinter/tklib.py
@@ -112,6 +112,10 @@
 incdirs = ['/usr/local/include/tcl8.5', '/usr/local/include/tk8.5', 
'/usr/X11R6/include']
 linklibs = ['tk85', 'tcl85']
 libdirs = ['/usr/local/lib', '/usr/X11R6/lib']
+elif sys.platform == 'win32':
+incdirs = []
+linklibs = ['tcl85', 'tk85']
+libdirs = []
 else:
 incdirs=['/usr/include/tcl']
 linklibs=['tcl', 'tk']
diff --git a/pypy/doc/windows.rst b/pypy/doc/windows.rst
--- a/pypy/doc/windows.rst
+++ b/pypy/doc/windows.rst
@@ -157,6 +157,21 @@
 ms\do_ms.bat
 nmake -f ms\nt.mak install
 
+TkInter module support
+~~
+
+Download tcl from http:://http://www.tcl.tk/software/tcltk/download.html
+Extract tcl85. cd into the ``win`` directory and compile::
+
+nmake -nologo -f makefile.vc release OPTS=symbols,threads
+
+Download tcl from http:://http://www.tcl.tk/software/tcltk/download.html
+Extract tcl85. cd into the ``win`` directory and compile::
+
+set TCLDIR=tcl85_dir
+nmake -nologo -f makefile.vc release OPTS=symbols,threads
+
+
 Using the mingw compiler
 
 
diff --git a/pypy/tool/release/package.py b/pypy/tool/release/package.py
--- a/pypy/tool/release/package.py
+++ b/pypy/tool/release/package.py
@@ -67,18 +67,22 @@
 raise PyPyCNotFound(
 'Bogus path: %r does not exist (see docstring for more info)'
 % (os.path.dirname(str(pypy_c)),))
+win_extras = ['libpypy-c.dll', 'libexpat.dll', 'sqlite3.dll',
+  'libeay32.dll', 'ssleay32.dll']
 subprocess.check_call([str(pypy_c), '-c', 'import _sqlite3'])
 if not sys.platform == 'win32':
 subprocess.check_call([str(pypy_c), '-c', 'import _curses'])
 subprocess.check_call([str(pypy_c), '-c', 'import syslog'])
-if not withouttk:
-try:
-subprocess.check_call([str(pypy_c), '-c', 'import _tkinter'])
-except subprocess.CalledProcessError:
-print sys.stderr, Building Tk bindings failed.
+if not withouttk:
+try:
+subprocess.check_call([str(pypy_c), '-c', 'import _tkinter'])
+except subprocess.CalledProcessError:
+print sys.stderr, Building Tk bindings failed.
 You can either install Tk development headers package or
 add --without-tk option to skip packaging binary CFFI extension.
-sys.exit(1)
+sys.exit(1)
+#Can the dependencies be found from cffi somehow?
+win_extras += ['tk85t.dll', 'tk85.dll', 'tcl85t.dll', 'tcl85.dll']
 if sys.platform == 'win32' and not rename_pypy_c.lower().endswith('.exe'):
 rename_pypy_c += '.exe'
 binaries = [(pypy_c, rename_pypy_c)]
@@ -101,9 +105,7 @@
 
 # Can't rename a DLL: it is always called 'libpypy-c.dll'
 
-for extra in ['libpypy-c.dll',
-  'libexpat.dll', 'sqlite3.dll',
-  'libeay32.dll', 'ssleay32.dll']:
+for extra in win_extras:
 p = pypy_c.dirpath().join(extra)
 if not p.check():
 p = py.path.local.sysfind(extra)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] extradoc extradoc: py3k update #12

2013-11-12 Thread pjenvey
Author: Philip Jenvey pjen...@underboss.org
Branch: extradoc
Changeset: r5109:ea4e00abbf96
Date: 2013-11-12 15:06 -0800
http://bitbucket.org/pypy/extradoc/changeset/ea4e00abbf96/

Log:py3k update #12

diff --git a/blog/draft/py3k-status-update-12.rst 
b/blog/draft/py3k-status-update-12.rst
new file mode 100644
--- /dev/null
+++ b/blog/draft/py3k-status-update-12.rst
@@ -0,0 +1,45 @@
+Py3k status update #12
+--
+
+This is the 12th status update about our work on the `py3k branch`_, which we
+can work on thanks to all of the people who donated_ to the `py3k proposal`_.
+
+Here's an update on the recent progress:
+
+* Thank you to everyone who has provided initial feedback on the PyPy3 2.1 beta
+  1 release. We've gotten a number of bug reports, most of which have been
+  fixed.
+
+* As usual, we're continually keeping up with changes from the default
+  branch. Oftentimes these merges come at a cost (conflicts and or
+  reintegration of py3k changes) but occasionally we get goodies for free, such
+  as the `recent JIT optimizations`_ and `incremental garbage collection`_.
+
+* We've been focusing on re-optimizing Python 2 int sized (machine sized)
+  integers:
+
+We have a couple of known, notable speed regressions in the PyPy3 beta release
+vs regular PyPy. The major one being with Python 2.x int sized (or machine
+sized) integers.
+
+Python 3 drops the distinction between int and long types. CPython 3.x
+accomplishes this by removing the old int type entirely and renaming the long
+type to int. Initially, we've done the same for PyPy3 for the sake of
+simplicity and getting everything working.
+
+However PyPy's JIT is capable of heavily optimizing these machine sized integer
+operations, so this came with a regression in performance in this area.
+
+We're now in the process of solving this. Part of this work also involves some
+house cleaning on these numeric types which will also benefit the default
+branch.
+
+cheers,
+Phil
+
+.. _donated: 
http://morepypy.blogspot.com/2012/01/py3k-and-numpy-first-stage-thanks-to.html
+.. _`py3k proposal`: http://pypy.org/py3donate.html
+.. _`py3k branch`: 
https://bitbucket.org/pypy/pypy/commits/all/tip/branch%28%22py3k%22%29
+
+.. _`recent JIT optimizations`: 
http://morepypy.blogspot.com/2013/10/making-coveragepy-faster-under-pypy.html
+.. _`incremental garbage collection`: 
http://morepypy.blogspot.com/2013/10/incremental-garbage-collector-in-pypy.html
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: document sqlite3.dll version for windows

2013-11-12 Thread mattip
Author: Matti Picus matti.pi...@gmail.com
Branch: 
Changeset: r67997:df0777fb0d9f
Date: 2013-11-13 02:10 +0200
http://bitbucket.org/pypy/pypy/changeset/df0777fb0d9f/

Log:document sqlite3.dll version for windows

diff --git a/pypy/doc/windows.rst b/pypy/doc/windows.rst
--- a/pypy/doc/windows.rst
+++ b/pypy/doc/windows.rst
@@ -118,14 +118,10 @@
 The sqlite3 database library
 
 
-Download http://www.sqlite.org/2013/sqlite-amalgamation-3071601.zip and extract
-it into a directory under the base directory. Also get 
-http://www.sqlite.org/2013/sqlite-dll-win32-x86-3071601.zip and extract the dll
-into the bin directory, and the sqlite3.def into the sources directory.
-Now build the import library so cffi can use the header and dll::
+PyPy uses cffi to interact with sqlite3.dll. Only the dll is needed, the cffi
+wrapper is compiled when the module is imported for the first time.
+The sqlite3.dll should be version 3.6.21 for CPython2.7 compatablility.
 
-lib /DEF:sqlite3.def /OUT:sqlite3.lib
-copy sqlite3.lib path\to\libs
 
 
 The expat XML parser
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: fix missing coerce in setitem_filter

2013-11-12 Thread bdkearns
Author: Brian Kearns bdkea...@gmail.com
Branch: 
Changeset: r67999:63c04f0fba9f
Date: 2013-11-12 19:42 -0500
http://bitbucket.org/pypy/pypy/changeset/63c04f0fba9f/

Log:fix missing coerce in setitem_filter

diff --git a/pypy/module/micronumpy/interp_numarray.py 
b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -125,7 +125,7 @@
 cannot assign %d input values to 
 the %d output values where the mask is true %
 (val.get_size(), size)))
-loop.setitem_filter(self, idx, val, size)
+loop.setitem_filter(space, self, idx, val, size)
 
 def _prepare_array_index(self, space, w_index):
 if isinstance(w_index, W_NDimArray):
diff --git a/pypy/module/micronumpy/loop.py b/pypy/module/micronumpy/loop.py
--- a/pypy/module/micronumpy/loop.py
+++ b/pypy/module/micronumpy/loop.py
@@ -398,7 +398,7 @@
 'index_dtype'],
   reds = 'auto')
 
-def setitem_filter(arr, index, value, size):
+def setitem_filter(space, arr, index, value, size):
 arr_iter = arr.create_iter()
 shapelen = len(arr.get_shape())
 if shapelen  1 and len(index.get_shape())  2:
@@ -414,7 +414,7 @@
   arr_dtype=arr_dtype,
  )
 if index_iter.getitem_bool():
-arr_iter.setitem(value_iter.getitem())
+arr_iter.setitem(arr_dtype.coerce(space, value_iter.getitem()))
 value_iter.next()
 arr_iter.next()
 index_iter.next()
diff --git a/pypy/module/micronumpy/test/test_numarray.py 
b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -511,6 +511,13 @@
 for i in xrange(5):
 assert a[i] == i
 
+def test_setitem_array(self):
+import numpy as np
+a = np.array((-1., 0, 1))/0.
+b = np.array([False, False, True], dtype=bool)
+a[b] = 100
+assert a[2] == 100
+
 def test_setitem_obj_index(self):
 from numpypy import arange
 a = arange(10)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: clean up some formatting

2013-11-12 Thread bdkearns
Author: Brian Kearns bdkea...@gmail.com
Branch: 
Changeset: r67998:bda39936972c
Date: 2013-11-12 19:30 -0500
http://bitbucket.org/pypy/pypy/changeset/bda39936972c/

Log:clean up some formatting

diff --git a/pypy/module/micronumpy/interp_numarray.py 
b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -98,11 +98,11 @@
 
 def getitem_filter(self, space, arr):
 if len(arr.get_shape())  1 and arr.get_shape() != self.get_shape():
-raise OperationError(space.w_ValueError,
- space.wrap(boolean index array should have 1 
dimension))
+raise OperationError(space.w_ValueError, space.wrap(
+boolean index array should have 1 dimension))
 if arr.get_size()  self.get_size():
-raise OperationError(space.w_ValueError,
- space.wrap(index out of range for array))
+raise OperationError(space.w_ValueError, space.wrap(
+index out of range for array))
 size = loop.count_all_true(arr)
 if len(arr.get_shape()) == 1:
 res_shape = [size] + self.get_shape()[1:]
@@ -113,17 +113,18 @@
 
 def setitem_filter(self, space, idx, val):
 if len(idx.get_shape())  1 and idx.get_shape() != self.get_shape():
-raise OperationError(space.w_ValueError,
- space.wrap(boolean index array should have 1 
dimension))
+raise OperationError(space.w_ValueError, space.wrap(
+boolean index array should have 1 dimension))
 if idx.get_size()  self.get_size():
-raise OperationError(space.w_ValueError,
- space.wrap(index out of range for array))
+raise OperationError(space.w_ValueError, space.wrap(
+index out of range for array))
 size = loop.count_all_true(idx)
 if size  val.get_size() and val.get_size() != 1:
-raise OperationError(space.w_ValueError, space.wrap(NumPy boolean 
array indexing assignment 
-cannot assign 
%d input values to 
-the %d output 
values where the mask is true %
-
(val.get_size(), size)))
+raise OperationError(space.w_ValueError, space.wrap(
+NumPy boolean array indexing assignment 
+cannot assign %d input values to 
+the %d output values where the mask is true %
+(val.get_size(), size)))
 loop.setitem_filter(self, idx, val, size)
 
 def _prepare_array_index(self, space, w_index):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: raise coerce conversion errors at app-level

2013-11-12 Thread bdkearns
Author: Brian Kearns bdkea...@gmail.com
Branch: 
Changeset: r68000:d50d27c01818
Date: 2013-11-12 20:20 -0500
http://bitbucket.org/pypy/pypy/changeset/d50d27c01818/

Log:raise coerce conversion errors at app-level

diff --git a/pypy/module/micronumpy/interp_numarray.py 
b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -198,8 +198,7 @@
prefix)
 
 def descr_getitem(self, space, w_idx):
-if (isinstance(w_idx, W_NDimArray) and
-w_idx.get_dtype().is_bool_type()):
+if isinstance(w_idx, W_NDimArray) and w_idx.get_dtype().is_bool_type():
 return self.getitem_filter(space, w_idx)
 try:
 return self.implementation.descr_getitem(space, self, w_idx)
@@ -213,9 +212,11 @@
 self.implementation.setitem_index(space, index_list, w_value)
 
 def descr_setitem(self, space, w_idx, w_value):
-if (isinstance(w_idx, W_NDimArray) and
-w_idx.get_dtype().is_bool_type()):
-self.setitem_filter(space, w_idx, convert_to_array(space, w_value))
+if isinstance(w_idx, W_NDimArray) and w_idx.get_dtype().is_bool_type():
+try:
+self.setitem_filter(space, w_idx, convert_to_array(space, 
w_value))
+except ValueError, e:
+raise OperationError(space.w_ValueError, space.wrap(str(e)))
 return
 try:
 self.implementation.descr_setitem(space, self, w_idx, w_value)
diff --git a/pypy/module/micronumpy/test/test_numarray.py 
b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -2454,6 +2454,23 @@
 assert exc.value[0].find('cannot assign') = 0
 assert (a == [[0, 1], [2, 3], [4, 5]]).all()
 
+def test_nonarray_assignment(self):
+import numpypy as np
+a = np.arange(10)
+b = np.ones(10, dtype=bool)
+r = np.arange(10)
+def assign(a, b, c):
+a[b] = c
+raises(ValueError, assign, a, b, np.nan)
+#raises(ValueError, assign, a, r, np.nan)  # XXX
+import sys
+if '__pypy__' not in sys.builtin_module_names:
+a[b] = np.array(np.nan)
+#a[r] = np.array(np.nan)
+else:
+raises(ValueError, assign, a, b, np.array(np.nan))
+#raises(ValueError, assign, a, r, np.array(np.nan))
+
 def test_copy_kwarg(self):
 from numpypy import array
 x = array([1, 2, 3])
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: support ndarray.reshape(()) to reshape to scalar

2013-11-12 Thread bdkearns
Author: Brian Kearns bdkea...@gmail.com
Branch: 
Changeset: r68001:b89a1dc6a9e1
Date: 2013-11-12 22:32 -0500
http://bitbucket.org/pypy/pypy/changeset/b89a1dc6a9e1/

Log:support ndarray.reshape(()) to reshape to scalar

diff --git a/pypy/module/micronumpy/arrayimpl/concrete.py 
b/pypy/module/micronumpy/arrayimpl/concrete.py
--- a/pypy/module/micronumpy/arrayimpl/concrete.py
+++ b/pypy/module/micronumpy/arrayimpl/concrete.py
@@ -73,6 +73,8 @@
 return SliceArray(self.start, new_strides, new_backstrides,
   new_shape, self, orig_array)
 else:
+if self.get_size() == 1 and len(new_shape) == 0:
+return scalar.Scalar(self.dtype, self.getitem(0))
 return None
 
 def get_view(self, orig_array, dtype, new_shape):
diff --git a/pypy/module/micronumpy/test/test_numarray.py 
b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -710,7 +710,14 @@
 
 def test_reshape(self):
 from numpypy import array, zeros
+for a in [array(1), array([1])]:
+for s in [(), (1,)]:
+b = a.reshape(s)
+assert b.shape == s
+assert (b == [1]).all()
 a = array(range(12))
+exc = raises(ValueError, b = a.reshape(()))
+assert str(exc.value) == total size of new array must be unchanged
 exc = raises(ValueError, b = a.reshape((3, 10)))
 assert str(exc.value) == total size of new array must be unchanged
 b = a.reshape((3, 4))
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit