Author: Maciej Fijalkowski <fij...@gmail.com> Branch: Changeset: r66999:91a199b6f1fd Date: 2013-09-18 12:23 +0200 http://bitbucket.org/pypy/pypy/changeset/91a199b6f1fd/
Log: merge diff --git a/lib-python/2.7/uuid.py b/lib-python/2.7/uuid.py --- a/lib-python/2.7/uuid.py +++ b/lib-python/2.7/uuid.py @@ -128,10 +128,10 @@ """ if hex is not None: - if (bytes is not None or bytes_le is not None or fields is not None - or int is not None): - raise TypeError('if the hex argument is given, bytes, bytes_le, fields,' - ' and int need to be None') + if (bytes is not None or bytes_le is not None or + fields is not None or int is not None): + raise TypeError('if the hex argument is given, bytes,' + ' bytes_le, fields, and int need to be None') hex = hex.replace('urn:', '').replace('uuid:', '') hex = hex.strip('{}').replace('-', '') if len(hex) != 32: @@ -139,8 +139,8 @@ int = long(hex, 16) elif bytes_le is not None: if bytes is not None or fields is not None or int is not None: - raise TypeError('if the bytes_le argument is given, bytes, fields,' - ' and int need to be None') + raise TypeError('if the bytes_le argument is given, bytes,' + ' fields, and int need to be None') if len(bytes_le) != 16: raise ValueError('bytes_le is not a 16-char string') bytes = (bytes_le[3] + bytes_le[2] + bytes_le[1] + bytes_le[0] + @@ -150,15 +150,16 @@ struct.unpack('>Q', bytes[8:])[0]) elif bytes is not None: if fields is not None or int is not None: - raise TypeError('if the bytes argument is given, fields' - ' and int need to be None') + raise TypeError('if the bytes argument is given, fields ' + 'and int need to be None') if len(bytes) != 16: raise ValueError('bytes is not a 16-char string') int = (struct.unpack('>Q', bytes[:8])[0] << 64 | struct.unpack('>Q', bytes[8:])[0]) elif fields is not None: if int is not None: - raise TypeError('if the fields argument is given, int needs to be None') + raise TypeError('if the fields argument is given, int needs' + ' to be None') if len(fields) != 6: raise ValueError('fields is not a 6-tuple') (time_low, time_mid, time_hi_version, diff --git a/pypy/doc/faq.rst b/pypy/doc/faq.rst --- a/pypy/doc/faq.rst +++ b/pypy/doc/faq.rst @@ -356,7 +356,7 @@ attempt to point newcomers at existing alternatives, which are more mainstream and where they will get help from many people.* - *If anybody seriously wants to promote RPython anyway, he is welcome + *If anybody seriously wants to promote RPython anyway, they are welcome to: we won't actively resist such a plan. There are a lot of things that could be done to make RPython a better Java-ish language for example, starting with supporting non-GIL-based multithreading, but we @@ -396,8 +396,8 @@ patch the generated machine code. So the position of the core PyPy developers is that if anyone wants to -make an N+1'th attempt with LLVM, he is welcome, and he will receive a -bit of help on the IRC channel, but he is left with the burden of proof +make an N+1'th attempt with LLVM, they are welcome, and will be happy to +provide help in the IRC channel, but they are left with the burden of proof that it works. ---------------------- 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 @@ -81,6 +81,8 @@ .. branch: numpypy-inplace-op .. branch: rewritten-loop-logging .. branch: no-release-gil +.. branch: safe-win-mmap +.. branch: boolean-indexing-cleanup .. branch: nobold-backtrace Work on improving UnionError messages and stack trace displays. 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 @@ -316,7 +316,8 @@ self.storage = storage def create_iter(self, shape=None, backward_broadcast=False): - if shape is None or shape == self.get_shape(): + if shape is None or \ + support.product(shape) <= support.product(self.get_shape()): return iter.ConcreteArrayIterator(self) r = calculate_broadcast_strides(self.get_strides(), self.get_backstrides(), @@ -385,7 +386,8 @@ loop.fill(self, box.convert_to(self.dtype)) def create_iter(self, shape=None, backward_broadcast=False): - if shape is not None and shape != self.get_shape(): + if shape is not None and shape != self.get_shape() and \ + support.product(shape) > support.product(self.get_shape()): r = calculate_broadcast_strides(self.get_strides(), self.get_backstrides(), self.get_shape(), shape, 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 @@ -88,28 +88,22 @@ w_res = W_NDimArray.from_shape(space, res_shape, self.get_dtype(), w_instance=self) return loop.getitem_filter(w_res, self, arr) - def setitem_filter(self, space, idx, value): - from pypy.module.micronumpy.interp_boxes import Box - val = value + 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")) if idx.get_size() > self.get_size(): raise OperationError(space.w_ValueError, space.wrap("index out of range for array")) - idx_iter = idx.create_iter(self.get_shape()) - size = loop.count_all_true_iter(idx_iter, self.get_shape(), idx.get_dtype()) - if len(val.get_shape()) > 0 and val.get_shape()[0] > 1 and size > val.get_shape()[0]: + idx_iter = idx.create_iter() + size = loop.count_all_true_iter(idx_iter, idx.get_shape(), idx.get_dtype()) + 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_shape()[0],size))) - if val.get_shape() == [1]: - box = val.descr_getitem(space, space.wrap(0)) - assert isinstance(box, Box) - val = W_NDimArray(scalar.Scalar(val.get_dtype(), box)) - elif val.get_shape() == [0]: + "the %d output values where the mask is true" % (val.get_size(), size))) + if val.get_shape() == [0]: val.implementation.dtype = self.implementation.dtype - loop.setitem_filter(self, idx, val) + loop.setitem_filter(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 @@ -372,10 +372,10 @@ 'index_dtype'], reds = 'auto') -def setitem_filter(arr, index, value): +def setitem_filter(arr, index, value, size): arr_iter = arr.create_iter() index_iter = index.create_iter(arr.get_shape()) - value_iter = value.create_iter() + value_iter = value.create_iter([size]) shapelen = len(arr.get_shape()) index_dtype = index.get_dtype() arr_dtype = arr.get_dtype() 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 @@ -2355,11 +2355,16 @@ def test_array_indexing_bool_specialcases(self): from numpypy import arange, array a = arange(6) - try: - a[a < 3] = [1, 2] - assert False, "Should not work" - except ValueError: - pass + exc = raises(ValueError,'a[a < 3] = [1, 2]') + assert exc.value[0].find('cannot assign') >= 0 + b = arange(4).reshape(2, 2) + 10 + a[a < 4] = b + assert (a == [10, 11, 12, 13, 4, 5]).all() + b += 10 + c = arange(8).reshape(2, 2, 2) + a[a > 9] = c[:, :, 1] + assert (c[:, :, 1] == [[1, 3], [5, 7]]).all() + assert (a == [1, 3, 5, 7, 4, 5]).all() a = arange(6) a[a > 3] = array([15]) assert (a == [0, 1, 2, 3, 15, 15]).all() diff --git a/rpython/rlib/rmmap.py b/rpython/rlib/rmmap.py --- a/rpython/rlib/rmmap.py +++ b/rpython/rlib/rmmap.py @@ -118,10 +118,16 @@ return unsafe, safe def winexternal(name, args, result, **kwargs): - return rffi.llexternal(name, args, result, + unsafe = rffi.llexternal(name, args, result, compilation_info=CConfig._compilation_info_, calling_conv='win', **kwargs) + safe = rffi.llexternal(name, args, result, + compilation_info=CConfig._compilation_info_, + calling_conv='win', + sandboxsafe=True, releasegil=False, + **kwargs) + return unsafe, safe PTR = rffi.CCHARP @@ -188,32 +194,29 @@ SYSTEM_INFO = config['SYSTEM_INFO'] SYSTEM_INFO_P = lltype.Ptr(SYSTEM_INFO) - GetSystemInfo = winexternal('GetSystemInfo', [SYSTEM_INFO_P], lltype.Void) - GetFileSize = winexternal('GetFileSize', [HANDLE, LPDWORD], DWORD) - GetCurrentProcess = winexternal('GetCurrentProcess', [], HANDLE) - DuplicateHandle = winexternal('DuplicateHandle', [HANDLE, HANDLE, HANDLE, LPHANDLE, DWORD, BOOL, DWORD], BOOL) - CreateFileMapping = winexternal('CreateFileMappingA', [HANDLE, rwin32.LPSECURITY_ATTRIBUTES, DWORD, DWORD, DWORD, LPCSTR], HANDLE) - MapViewOfFile = winexternal('MapViewOfFile', [HANDLE, DWORD, DWORD, DWORD, SIZE_T], LPCSTR)##!!LPVOID) - UnmapViewOfFile = winexternal('UnmapViewOfFile', [LPCSTR], BOOL, - releasegil=False) - FlushViewOfFile = winexternal('FlushViewOfFile', [LPCSTR, SIZE_T], BOOL) - SetFilePointer = winexternal('SetFilePointer', [HANDLE, LONG, PLONG, DWORD], DWORD) - SetEndOfFile = winexternal('SetEndOfFile', [HANDLE], BOOL) - VirtualAlloc = winexternal('VirtualAlloc', + GetSystemInfo, _ = winexternal('GetSystemInfo', [SYSTEM_INFO_P], lltype.Void) + GetFileSize, _ = winexternal('GetFileSize', [HANDLE, LPDWORD], DWORD) + GetCurrentProcess, _ = winexternal('GetCurrentProcess', [], HANDLE) + DuplicateHandle, _ = winexternal('DuplicateHandle', [HANDLE, HANDLE, HANDLE, LPHANDLE, DWORD, BOOL, DWORD], BOOL) + CreateFileMapping, _ = winexternal('CreateFileMappingA', [HANDLE, rwin32.LPSECURITY_ATTRIBUTES, DWORD, DWORD, DWORD, LPCSTR], HANDLE) + MapViewOfFile, _ = winexternal('MapViewOfFile', [HANDLE, DWORD, DWORD, DWORD, SIZE_T], LPCSTR)##!!LPVOID) + _, UnmapViewOfFile_safe = winexternal('UnmapViewOfFile', [LPCSTR], BOOL) + FlushViewOfFile, _ = winexternal('FlushViewOfFile', [LPCSTR, SIZE_T], BOOL) + SetFilePointer, _ = winexternal('SetFilePointer', [HANDLE, LONG, PLONG, DWORD], DWORD) + SetEndOfFile, _ = winexternal('SetEndOfFile', [HANDLE], BOOL) + VirtualAlloc, VirtualAlloc_safe = winexternal('VirtualAlloc', [rffi.VOIDP, rffi.SIZE_T, DWORD, DWORD], rffi.VOIDP) - # VirtualProtect is used in llarena and should not release the GIL - _VirtualProtect = winexternal('VirtualProtect', + _, _VirtualProtect_safe = winexternal('VirtualProtect', [rffi.VOIDP, rffi.SIZE_T, DWORD, LPDWORD], - BOOL, - _nowrapper=True) + BOOL) def VirtualProtect(addr, size, mode, oldmode_ptr): - return _VirtualProtect(addr, + return _VirtualProtect_safe(addr, rffi.cast(rffi.SIZE_T, size), rffi.cast(DWORD, mode), oldmode_ptr) VirtualProtect._annspecialcase_ = 'specialize:ll' - VirtualFree = winexternal('VirtualFree', + VirtualFree, VirtualFree_safe = winexternal('VirtualFree', [rffi.VOIDP, rffi.SIZE_T, DWORD], BOOL) def _get_page_size(): @@ -300,7 +303,7 @@ def unmap(self): if _MS_WINDOWS: - UnmapViewOfFile(self.getptr(0)) + UnmapViewOfFile_safe(self.getptr(0)) elif _POSIX: self.unmap_range(0, self.size) @@ -575,6 +578,7 @@ def getitem(self, index): # simplified version, for rpython + self.check_valid() if index < 0: index += self.size return self.data[index] @@ -846,7 +850,7 @@ case of a sandboxed process """ null = lltype.nullptr(rffi.VOIDP.TO) - res = VirtualAlloc(null, map_size, MEM_COMMIT | MEM_RESERVE, + res = VirtualAlloc_safe(null, map_size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE) if not res: raise MemoryError @@ -858,6 +862,6 @@ alloc._annenforceargs_ = (int,) def free(ptr, map_size): - VirtualFree(ptr, 0, MEM_RELEASE) + VirtualFree_safe(ptr, 0, MEM_RELEASE) # register_external here? diff --git a/rpython/rtyper/lltypesystem/llarena.py b/rpython/rtyper/lltypesystem/llarena.py --- a/rpython/rtyper/lltypesystem/llarena.py +++ b/rpython/rtyper/lltypesystem/llarena.py @@ -535,6 +535,7 @@ else: from rpython.rlib.rmmap import PAGE_READWRITE as newprotect arg = lltype.malloc(LPDWORD.TO, 1, zero=True, flavor='raw') + #does not release the GIL VirtualProtect(rffi.cast(rffi.VOIDP, addr), size, newprotect, arg) # ignore potential errors diff --git a/rpython/rtyper/tool/rffi_platform.py b/rpython/rtyper/tool/rffi_platform.py --- a/rpython/rtyper/tool/rffi_platform.py +++ b/rpython/rtyper/tool/rffi_platform.py @@ -844,6 +844,10 @@ library_dir = '' libraries = ['gc64_dll'] includes = ['gc.h'] + # since config_external_library does not use a platform kwarg, + # somehow using a platform kw arg make the merge fail in + # config_external_library + platform = None else: library_dir = '' libraries = ['gc', 'dl'] _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit