Author: Alex Gaynor <alex.gay...@gmail.com> Branch: numpy-dtype-alt Changeset: r46897:84d00dc7538b Date: 2011-08-29 12:53 -0400 http://bitbucket.org/pypy/pypy/changeset/84d00dc7538b/
Log: merged default diff --git a/lib_pypy/_ctypes/function.py b/lib_pypy/_ctypes/function.py --- a/lib_pypy/_ctypes/function.py +++ b/lib_pypy/_ctypes/function.py @@ -469,7 +469,8 @@ newargs = [] for argtype, arg in zip(argtypes, args): param = argtype.from_param(arg) - if argtype._type_ == 'P': # special-case for c_void_p + _type_ = getattr(argtype, '_type_', None) + if _type_ == 'P': # special-case for c_void_p param = param._get_buffer_value() elif self._is_primitive(argtype): param = param.value diff --git a/lib_pypy/_ctypes/structure.py b/lib_pypy/_ctypes/structure.py --- a/lib_pypy/_ctypes/structure.py +++ b/lib_pypy/_ctypes/structure.py @@ -169,6 +169,8 @@ def from_address(self, address): instance = StructOrUnion.__new__(self) + if isinstance(address, _rawffi.StructureInstance): + address = address.buffer instance.__dict__['_buffer'] = self._ffistruct.fromaddress(address) return instance diff --git a/pypy/doc/stackless.rst b/pypy/doc/stackless.rst --- a/pypy/doc/stackless.rst +++ b/pypy/doc/stackless.rst @@ -203,14 +203,24 @@ * Coroutines (could be rewritten at app-level) -* Pickling and unpickling continulets (probably not too hard) +* Pickling and unpickling continulets (*) -* Continuing execution of a continulet in a different thread +* Continuing execution of a continulet in a different thread (*) * Automatic unlimited stack (must be emulated__ so far) .. __: `recursion depth limit`_ +(*) Pickling, as well as changing threads, could be implemented by using +a "soft" stack switching mode again. We would get either "hard" or +"soft" switches, similarly to Stackless Python 3rd version: you get a +"hard" switch (like now) when the C stack contains non-trivial C frames +to save, and a "soft" switch (like previously) when it contains only +simple calls from Python to Python. Soft-switched continulets would +also consume a bit less RAM, at the possible expense of making the +switch a bit slower (unsure about that; what is the Stackless Python +experience?). + Recursion depth limit +++++++++++++++++++++ @@ -366,7 +376,7 @@ Thus the notion of coroutine is *not composable*. By opposition, the primitive notion of continulets is composable: if you build two different interfaces on top of it, or have a program that uses twice the -same interface in two parts, then assuming that both part independently +same interface in two parts, then assuming that both parts independently work, the composition of the two parts still works. A full proof of that claim would require careful definitions, but let us diff --git a/pypy/module/__builtin__/__init__.py b/pypy/module/__builtin__/__init__.py --- a/pypy/module/__builtin__/__init__.py +++ b/pypy/module/__builtin__/__init__.py @@ -19,6 +19,7 @@ 'sorted' : 'app_functional.sorted', 'any' : 'app_functional.any', 'all' : 'app_functional.all', + 'sum' : 'app_functional.sum', 'vars' : 'app_inspect.vars', 'dir' : 'app_inspect.dir', @@ -85,7 +86,6 @@ 'enumerate' : 'functional.W_Enumerate', 'min' : 'functional.min', 'max' : 'functional.max', - 'sum' : 'functional.sum', 'map' : 'functional.map', 'zip' : 'functional.zip', 'reduce' : 'functional.reduce', @@ -118,7 +118,7 @@ return module.Module(space, None, w_builtin) builtin = space.interpclass_w(w_builtin) if isinstance(builtin, module.Module): - return builtin + return builtin # no builtin! make a default one. Given them None, at least. builtin = module.Module(space, None) space.setitem(builtin.w_dict, space.wrap('None'), space.w_None) diff --git a/pypy/module/__builtin__/app_functional.py b/pypy/module/__builtin__/app_functional.py --- a/pypy/module/__builtin__/app_functional.py +++ b/pypy/module/__builtin__/app_functional.py @@ -34,3 +34,18 @@ if not x: return False return True + +def sum(sequence, start=0): + """sum(sequence[, start]) -> value + +Returns the sum of a sequence of numbers (NOT strings) plus the value +of parameter 'start' (which defaults to 0). When the sequence is +empty, returns start.""" + if isinstance(start, basestring): + raise TypeError("sum() can't sum strings") + last = start + for x in sequence: + # Very intentionally *not* +=, that would have different semantics if + # start was a mutable type, such as a list + last = last + x + return last \ No newline at end of file diff --git a/pypy/module/__builtin__/functional.py b/pypy/module/__builtin__/functional.py --- a/pypy/module/__builtin__/functional.py +++ b/pypy/module/__builtin__/functional.py @@ -325,27 +325,6 @@ result_w.append(w_res) return result_w -def sum(space, w_sequence, w_start=0): - """sum(sequence[, start]) -> value - -Returns the sum of a sequence of numbers (NOT strings) plus the value -of parameter 'start' (which defaults to 0). When the sequence is -empty, returns start.""" - if space.is_true(space.isinstance(w_start, space.w_basestring)): - msg = "sum() can't sum strings" - raise OperationError(space.w_TypeError, space.wrap(msg)) - w_iter = space.iter(w_sequence) - w_last = w_start - while True: - try: - w_next = space.next(w_iter) - except OperationError, e: - if not e.match(space, space.w_StopIteration): - raise - break - w_last = space.add(w_last, w_next) - return w_last - @unwrap_spec(sequences_w="args_w") def zip(space, sequences_w): """Return a list of tuples, where the nth tuple contains every nth item of diff --git a/pypy/module/bz2/interp_bz2.py b/pypy/module/bz2/interp_bz2.py --- a/pypy/module/bz2/interp_bz2.py +++ b/pypy/module/bz2/interp_bz2.py @@ -351,6 +351,7 @@ self.decompressor = W_BZ2Decompressor(space) self.readlength = r_longlong(0) self.buffer = "" + self.pos = 0 self.finished = False if buffering < 1024: buffering = 1024 # minimum amount of compressed data read at once @@ -385,6 +386,7 @@ self.stream.seek(0, 0) self.decompressor = W_BZ2Decompressor(self.space) self.readlength = r_longlong(0) + self.pos = 0 self.buffer = "" self.finished = False else: @@ -410,15 +412,19 @@ self.space.wrap("compressed file ended before the logical end-of-the-stream was detected")) result = self.space.str_w(w_result) self.readlength += len(result) - result = self.buffer + result + if len(self.buffer) != self.pos: + pos = self.pos + assert pos >= 0 + result = self.buffer[pos:] + result self.buffer = '' + self.pos = 0 return result def read(self, n): # XXX not nice if n <= 0: return '' - while not self.buffer: + while self.pos == len(self.buffer): if self.finished: return "" moredata = self.stream.read(max(self.buffering, n)) @@ -433,17 +439,23 @@ return "" raise self.buffer = self.space.str_w(w_read) - if len(self.buffer) >= n: - result = self.buffer[:n] - self.buffer = self.buffer[n:] + self.pos = 0 + if len(self.buffer) - self.pos >= n: + pos = self.pos + assert pos >= 0 + result = self.buffer[pos:pos + n] + self.pos += n else: result = self.buffer + self.pos = 0 self.buffer = "" self.readlength += len(result) return result def peek(self): - return self.buffer + pos = self.pos + assert pos >= 0 + return self.buffer[pos:] def try_to_find_file_descriptor(self): return self.stream.try_to_find_file_descriptor() diff --git a/pypy/module/pypyjit/test_pypy_c/test_math.py b/pypy/module/pypyjit/test_pypy_c/test_math.py --- a/pypy/module/pypyjit/test_pypy_c/test_math.py +++ b/pypy/module/pypyjit/test_pypy_c/test_math.py @@ -78,6 +78,7 @@ assert loop.match(""" i1 = int_gt(i0, 0) guard_true(i1, descr=...) + guard_not_invalidated(descr=...) f1 = cast_int_to_float(i0) i2 = float_eq(f1, inf) i3 = float_eq(f1, -inf) diff --git a/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c b/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c --- a/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c +++ b/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c @@ -481,6 +481,16 @@ int a, b, c, d, e, f, g, h; } S8I; + + +typedef int (*CALLBACK_RECT)(RECT rect); + +EXPORT(int) call_callback_with_rect(CALLBACK_RECT cb, RECT rect) +{ + return cb(rect); +} + + EXPORT(S8I) ret_8i_func(S8I inp) { inp.a *= 2; diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_callbacks.py b/pypy/module/test_lib_pypy/ctypes_tests/test_callbacks.py --- a/pypy/module/test_lib_pypy/ctypes_tests/test_callbacks.py +++ b/pypy/module/test_lib_pypy/ctypes_tests/test_callbacks.py @@ -150,7 +150,6 @@ class TestMoreCallbacks(BaseCTypesTestChecker): def test_callback_with_struct_argument(self): - py.test.skip("callbacks with struct arguments not implemented yet") class RECT(Structure): _fields_ = [("left", c_int), ("top", c_int), ("right", c_int), ("bottom", c_int)] @@ -167,6 +166,28 @@ assert res == 1111 + def test_callback_from_c_with_struct_argument(self): + import conftest + _ctypes_test = str(conftest.sofile) + dll = CDLL(_ctypes_test) + + class RECT(Structure): + _fields_ = [("left", c_long), ("top", c_long), + ("right", c_long), ("bottom", c_long)] + + proto = CFUNCTYPE(c_int, RECT) + def callback(point): + return point.left+point.top+point.right+point.bottom + + cbp = proto(callback) + rect = RECT(1000,100,10,1) + + call_callback_with_rect = dll.call_callback_with_rect + call_callback_with_rect.restype = c_int + call_callback_with_rect.argtypes = [proto, RECT] + res = call_callback_with_rect(cbp, rect) + assert res == 1111 + def test_callback_unsupported_return_struct(self): class RECT(Structure): _fields_ = [("left", c_int), ("top", c_int), diff --git a/pypy/rlib/_rffi_stacklet.py b/pypy/rlib/_rffi_stacklet.py --- a/pypy/rlib/_rffi_stacklet.py +++ b/pypy/rlib/_rffi_stacklet.py @@ -45,5 +45,5 @@ destroy = llexternal('stacklet_destroy', [thread_handle, handle], lltype.Void) _translate_pointer = llexternal("_stacklet_translate_pointer", - [handle, llmemory.Address], + [llmemory.Address, llmemory.Address], llmemory.Address) diff --git a/pypy/rlib/_stacklet_asmgcc.py b/pypy/rlib/_stacklet_asmgcc.py --- a/pypy/rlib/_stacklet_asmgcc.py +++ b/pypy/rlib/_stacklet_asmgcc.py @@ -30,7 +30,7 @@ p = llmemory.cast_adr_to_ptr(obj, lltype.Ptr(SUSPSTACK)) if not p.handle: return False - self.context = p.handle + self.context = llmemory.cast_ptr_to_adr(p.handle) anchor = p.anchor del p self.curframe = lltype.malloc(WALKFRAME, flavor='raw') @@ -52,7 +52,7 @@ def teardown(self): lltype.free(self.curframe, flavor='raw') lltype.free(self.otherframe, flavor='raw') - self.context = lltype.nullptr(_c.handle.TO) + self.context = llmemory.NULL return llmemory.NULL def next(self, obj, prev): diff --git a/pypy/rpython/memory/gctransform/shadowstack.py b/pypy/rpython/memory/gctransform/shadowstack.py --- a/pypy/rpython/memory/gctransform/shadowstack.py +++ b/pypy/rpython/memory/gctransform/shadowstack.py @@ -3,6 +3,7 @@ from pypy.rpython.annlowlevel import llhelper from pypy.rpython.lltypesystem import lltype, llmemory from pypy.rlib.debug import ll_assert +from pypy.rlib.nonconst import NonConstant from pypy.annotation import model as annmodel @@ -31,7 +32,7 @@ 'root_iterator' in translator._jit2gc): root_iterator = translator._jit2gc['root_iterator'] def jit_walk_stack_root(callback, addr, end): - root_iterator.context = llmemory.NULL + root_iterator.context = NonConstant(llmemory.NULL) gc = self.gc while True: addr = root_iterator.next(gc, addr, end) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit