rem
stringlengths
0
322k
add
stringlengths
0
2.05M
context
stringlengths
8
228k
expected = """ [i0] jump(1) """ self.optimize_loop(ops, 'Not', expected)
preamble = """ [i0] jump() """ expected = """ [] jump() """ self.optimize_loop(ops, 'Not', expected, preamble)
def test_virtual_constant_isnull(self): ops = """ [i0] p0 = new_with_vtable(ConstClass(node_vtable)) setfield_gc(p0, NULL, descr=nextdescr) p2 = getfield_gc(p0, descr=nextdescr) i1 = ptr_eq(p2, NULL) jump(i1) """ expected = """ [i0] jump(1) """ self.optimize_loop(ops, 'Not', expected)
expected = """ [i0] jump(0)
preamble = """ [i0] jump() """ expected = """ [] jump()
def test_virtual_constant_isnonnull(self): ops = """ [i0] p0 = new_with_vtable(ConstClass(node_vtable)) setfield_gc(p0, ConstPtr(myptr), descr=nextdescr) p2 = getfield_gc(p0, descr=nextdescr) i1 = ptr_eq(p2, NULL) jump(i1) """ expected = """ [i0] jump(0) """ self.optimize_loop(ops, 'Not', expected)
expected = ops self.optimize_loop(ops, 'Not, Not', expected)
preamble = """ [i, p0] i0 = getfield_gc(p0, descr=valuedescr) escape(p0) i1 = int_add(i0, i) jump(i, i1) """ expected = """ [i, i1] p1 = new_with_vtable(ConstClass(node_vtable)) setfield_gc(p1, i1, descr=valuedescr) escape(p1) i2 = int_add(i1, i) jump(i, i2) """ self.optimize_loop(ops, 'Not, Not', expected, preamble)
def test_nonvirtual_2(self): ops = """ [i, p0] i0 = getfield_gc(p0, descr=valuedescr) escape(p0) i1 = int_add(i0, i) p1 = new_with_vtable(ConstClass(node_vtable)) setfield_gc(p1, i1, descr=valuedescr) jump(i, p1) """ expected = ops self.optimize_loop(ops, 'Not, Not', expected)
expected = ops self.optimize_loop(ops, 'Not', expected)
preamble = ops expected = """ [i] jump(i) """ self.optimize_loop(ops, 'Not', expected, preamble)
def test_getfield_gc_nonpure_2(self): ops = """ [i] i1 = getfield_gc(ConstPtr(myptr), descr=valuedescr) jump(i1) """ expected = ops self.optimize_loop(ops, 'Not', expected)
expected = """
preamble = """
def test_varray_alloc_and_set(self): ops = """ [i1] p1 = new_array(2, descr=arraydescr) setarrayitem_gc(p1, 0, 25, descr=arraydescr) i2 = getarrayitem_gc(p1, 1, descr=arraydescr) jump(i2) """ expected = """ [i1] jump(0) """ self.optimize_loop(ops, 'Not', expected)
jump(0) """ self.optimize_loop(ops, 'Not', expected)
jump() """ expected = """ [] jump() """ self.optimize_loop(ops, 'Not', expected, preamble)
def test_varray_alloc_and_set(self): ops = """ [i1] p1 = new_array(2, descr=arraydescr) setarrayitem_gc(p1, 0, 25, descr=arraydescr) i2 = getarrayitem_gc(p1, 1, descr=arraydescr) jump(i2) """ expected = """ [i1] jump(0) """ self.optimize_loop(ops, 'Not', expected)
expected = """ [i0, i1, i2]
preamble = """ [i0, p1] i1 = getarrayitem_gc(p1, 0, descr=arraydescr) i2 = getarrayitem_gc(p1, 1, descr=arraydescr)
def test_varray_2(self): ops = """ [i0, p1] i1 = getarrayitem_gc(p1, 0, descr=arraydescr) i2 = getarrayitem_gc(p1, 1, descr=arraydescr) i3 = int_sub(i1, i2) guard_value(i3, 15) [] p2 = new_array(2, descr=arraydescr) setarrayitem_gc(p2, 1, i0, descr=arraydescr) setarrayitem_gc(p2, 0, 20, descr=arraydescr) jump(i0, p2) "...
jump(i0, 20, i0) """ self.optimize_loop(ops, 'Not, VArray(arraydescr, Not, Not)', expected)
jump(i0) """ expected = """ [i0] i3 = int_sub(20, i0) guard_value(i3, 15) [] jump(5) """ self.optimize_loop(ops, 'Not, Not', expected, preamble)
def test_varray_2(self): ops = """ [i0, p1] i1 = getarrayitem_gc(p1, 0, descr=arraydescr) i2 = getarrayitem_gc(p1, 1, descr=arraydescr) i3 = int_sub(i1, i2) guard_value(i3, 15) [] p2 = new_array(2, descr=arraydescr) setarrayitem_gc(p2, 1, i0, descr=arraydescr) setarrayitem_gc(p2, 0, 20, descr=arraydescr) jump(i0, p2) "...
config.objspace.compiler = "ast"
def target(self, driver, args): driver.exe_name = 'pypy-%(backend)s'
filename = '<codegen %s:%d>' % (fn, lineno)
filename = '<%d-codegen %s:%d>' % (self._counter, fn, lineno)
def compile(self, filename=None, mode='exec', flag=generators.compiler_flag, dont_inherit=0, _genframe=None): """ return compiled code object. if filename is None invent an artificial filename which displays the source/line position of the caller frame. """ if not filename or py.path.local(filename).check(file=0): if _...
filename = '<codegen %r %s:%d>' % (filename, fn, lineno)
filename = '<%d-codegen %r %s:%d>' % (self._counter, filename, fn, lineno) self.__class__._counter += 1
def compile(self, filename=None, mode='exec', flag=generators.compiler_flag, dont_inherit=0, _genframe=None): """ return compiled code object. if filename is None invent an artificial filename which displays the source/line position of the caller frame. """ if not filename or py.path.local(filename).check(file=0): if _...
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, name)
def build_bridge(space): "NOT_RPYTHON" from pypy.module.cpyext.pyobject import make_ref export_symbols = list(FUNCTIONS) + SYMBOLS_C + list(GLOBALS) from pypy.translator.c.database import LowLevelDatabase db = LowLevelDatabase() generate_macros(export_symbols, rename=True, do_deref=True) # Structure declaration code...
total = 0
total = %d
def f(a,b): if a < 0: return -1 return a-b
''', 170, ([], 4999450000L))
''' % startvalue, 170, ([], startvalue + 4999450000L))
def f(a,b): if a < 0: return -1 return a-b
target = target_ofs-arch.PC_OFFSET/2
def B_offs(self, target_ofs, c=cond.AL): target = target_ofs-arch.PC_OFFSET/2 pos = self.currpos() if target_ofs > pos: raise NotImplementedError else: if target >= 0 and target <= 0xFF: pos = self.currpos() target_ofs = pos - target_ofs target = WORD + target_ofs + arch.PC_OFFSET/2 self.SUB_ri(reg.pc.value, reg.pc.val...
pos = self.currpos() target_ofs = pos - target_ofs target = WORD + target_ofs + arch.PC_OFFSET/2
def B_offs(self, target_ofs, c=cond.AL): target = target_ofs-arch.PC_OFFSET/2 pos = self.currpos() if target_ofs > pos: raise NotImplementedError else: if target >= 0 and target <= 0xFF: pos = self.currpos() target_ofs = pos - target_ofs target = WORD + target_ofs + arch.PC_OFFSET/2 self.SUB_ri(reg.pc.value, reg.pc.val...
pos = self.currpos() target_ofs = pos - target_ofs target = WORD + target_ofs + arch.PC_OFFSET/2
target += 2 * WORD
def B_offs(self, target_ofs, c=cond.AL): target = target_ofs-arch.PC_OFFSET/2 pos = self.currpos() if target_ofs > pos: raise NotImplementedError else: if target >= 0 and target <= 0xFF: pos = self.currpos() target_ofs = pos - target_ofs target = WORD + target_ofs + arch.PC_OFFSET/2 self.SUB_ri(reg.pc.value, reg.pc.val...
ResOperation(rop.DEBUG_MERGE_POINT, ['dummy'], None),
ResOperation(rop.DEBUG_MERGE_POINT, ['dummy', 2], None),
def test_get_rid_of_debug_merge_point(self): operations = [ ResOperation(rop.DEBUG_MERGE_POINT, ['dummy'], None), ] gc_ll_descr = self.gc_ll_descr gc_ll_descr.rewrite_assembler(None, operations) assert len(operations) == 0
assert space.unwrap(space.str(w_date)) == '1970-01-01'
date = datetime.date.fromtimestamp(0) assert space.unwrap(space.str(w_date)) == str(date)
def test_fromtimestamp(self, space, api): w_args = space.wrap((0,)) w_date = api.PyDate_FromTimestamp(w_args) assert space.unwrap(space.str(w_date)) == '1970-01-01'
si.hStdInput = startup_info.hStdInput.handle
si.hStdInput = int(startup_info.hStdInput)
def CreateProcess(name, command_line, process_attr, thread_attr, inherit, flags, env, start_dir, startup_info): si = _STARTUPINFO() if startup_info is not None: si.dwFlags = startup_info.dwFlags si.wShowWindow = startup_info.wShowWindow if startup_info.hStdInput: si.hStdInput = startup_info.hStdInput.handle if startup_...
si.hStdOutput = startup_info.hStdOutput.handle
si.hStdOutput = int(startup_info.hStdOutput)
def CreateProcess(name, command_line, process_attr, thread_attr, inherit, flags, env, start_dir, startup_info): si = _STARTUPINFO() if startup_info is not None: si.dwFlags = startup_info.dwFlags si.wShowWindow = startup_info.wShowWindow if startup_info.hStdInput: si.hStdInput = startup_info.hStdInput.handle if startup_...
si.hStdError = startup_info.hStdError.handle
si.hStdError = int(startup_info.hStdError)
def CreateProcess(name, command_line, process_attr, thread_attr, inherit, flags, env, start_dir, startup_info): si = _STARTUPINFO() if startup_info is not None: si.dwFlags = startup_info.dwFlags si.wShowWindow = startup_info.wShowWindow if startup_info.hStdInput: si.hStdInput = startup_info.hStdInput.handle if startup_...
res = _WaitForSingleObject(handle.handle, milliseconds)
res = _WaitForSingleObject(int(handle), milliseconds)
def WaitForSingleObject(handle, milliseconds): res = _WaitForSingleObject(handle.handle, milliseconds) if res < 0: raise WindowsError("Error") return res
res = _GetExitCodeProcess(handle.handle, _byref(code))
res = _GetExitCodeProcess(int(handle), _byref(code))
def GetExitCodeProcess(handle): code = _c_int() res = _GetExitCodeProcess(handle.handle, _byref(code)) if not res: raise WindowsError("Error") return code.value
guard_nonnull(p1) [] guard_class(p1, ConstClass(node_vtable2)) []
guard_nonnull_class(p1, ConstClass(node_vtable2)) []
def test_bug_3(self): ops = """ [p1] guard_nonnull(p1) [] guard_class(p1, ConstClass(node_vtable2)) [] p2 = getfield_gc(p1, descr=nextdescr) guard_nonnull(12) [] guard_class(p2, ConstClass(node_vtable)) [] p3 = getfield_gc(p1, descr=otherdescr) guard_nonnull(12) [] guard_class(p3, ConstClass(node_vtable)) [] setfield_g...
p3a = new_with_vtable(ConstClass(node_vtable)) escape(p3a) setfield_gc(p3, p2, descr=otherdescr) jump(p2a, p3a) """ expected = """ [p2, p3] guard_class(p2, ConstClass(node_vtable)) [] guard_class(p3, ConstClass(node_vtable)) []
def test_bug_3(self): ops = """ [p1] guard_nonnull(p1) [] guard_class(p1, ConstClass(node_vtable2)) [] p2 = getfield_gc(p1, descr=nextdescr) guard_nonnull(12) [] guard_class(p2, ConstClass(node_vtable)) [] p3 = getfield_gc(p1, descr=otherdescr) guard_nonnull(12) [] guard_class(p3, ConstClass(node_vtable)) [] setfield_g...
p2a = new_with_vtable(ConstClass(node_vtable)) jump(p2a, p3a) """ self.optimize_loop(ops, expected)
jump(p3a) """ expected = """ [p3a] p2 = new_with_vtable(ConstClass(node_vtable)) setfield_gc(p3a, p2, descr=otherdescr) p3anew = new_with_vtable(ConstClass(node_vtable)) escape(p3anew) jump(p3anew) """ self.optimize_loop(ops, expected, preamble)
def test_bug_3(self): ops = """ [p1] guard_nonnull(p1) [] guard_class(p1, ConstClass(node_vtable2)) [] p2 = getfield_gc(p1, descr=nextdescr) guard_nonnull(12) [] guard_class(p2, ConstClass(node_vtable)) [] p3 = getfield_gc(p1, descr=otherdescr) guard_nonnull(12) [] guard_class(p3, ConstClass(node_vtable)) [] setfield_g...
if Q >> BITS: raise ValueError("input out of range")
if not objectmodel.we_are_translated(): if Q >> BITS: raise ValueError("input out of range")
def float_unpack(Q, size): """Convert a 32-bit or 64-bit integer created by float_pack into a Python float.""" if size == 8: MIN_EXP = -1021 # = sys.float_info.min_exp MAX_EXP = 1024 # = sys.float_info.max_exp MANT_DIG = 53 # = sys.float_info.mant_dig BITS = 64 elif size == 4: MIN_EXP = -125 # C's FLT_MIN_EXP ...
pass
return False
def note_import_star(self, imp): """Called when a star import is found.""" pass
if op == "-":
elif op == "-":
def f(code, n): pc = 0 while pc < len(code):
if op == "c":
elif op == "c":
def f(code, n): pc = 0 while pc < len(code):
expected = """
preamble = """
def test_mul_ovf(self): ops = """ [i0, i1] i2 = int_and(i0, 255) i3 = int_lt(i1, 5) guard_true(i3) [] i4 = int_gt(i1, -10) guard_true(i4) [] i5 = int_mul_ovf(i2, i1) guard_no_overflow() [] i6 = int_lt(i5, -2550) guard_false(i6) [] i7 = int_ge(i5, 1276) guard_false(i7) [] i8 = int_gt(i5, 126) guard_true(i8) [] jump(i0, ...
self.optimize_loop(ops, expected)
expected = """ [i0, i1] jump(i0, i1) """ self.optimize_loop(ops, expected, preamble)
def test_mul_ovf(self): ops = """ [i0, i1] i2 = int_and(i0, 255) i3 = int_lt(i1, 5) guard_true(i3) [] i4 = int_gt(i1, -10) guard_true(i4) [] i5 = int_mul_ovf(i2, i1) guard_no_overflow() [] i6 = int_lt(i5, -2550) guard_false(i6) [] i7 = int_ge(i5, 1276) guard_false(i7) [] i8 = int_gt(i5, 126) guard_true(i8) [] jump(i0, ...
expected = """
preamble = """
def test_mul_ovf_before(self): ops = """ [i0, i1] i2 = int_and(i0, 255) i22 = int_add(i2, 1) i3 = int_mul_ovf(i22, i1) guard_no_overflow() [] i4 = int_lt(i3, 10) guard_true(i4) [] i5 = int_gt(i3, 2) guard_true(i5) [] i6 = int_lt(i1, 0) guard_false(i6) [] jump(i0, i1) """ expected = """ [i0, i1] i2 = int_and(i0, 255) i2...
jump(i0, i1) """ self.optimize_loop(ops, expected)
jump(i0, i1, i22) """ expected = """ [i0, i1, i22] i3 = int_mul(i22, i1) i4 = int_lt(i3, 10) guard_true(i4) [] i5 = int_gt(i3, 2) guard_true(i5) [] jump(i0, i1, i22) """ self.optimize_loop(ops, expected, preamble)
def test_mul_ovf_before(self): ops = """ [i0, i1] i2 = int_and(i0, 255) i22 = int_add(i2, 1) i3 = int_mul_ovf(i22, i1) guard_no_overflow() [] i4 = int_lt(i3, 10) guard_true(i4) [] i5 = int_gt(i3, 2) guard_true(i5) [] i6 = int_lt(i1, 0) guard_false(i6) [] jump(i0, i1) """ expected = """ [i0, i1] i2 = int_and(i0, 255) i2...
expected = """
preamble = """
def test_sub_ovf_before(self): ops = """ [i0, i1] i2 = int_and(i0, 255) i3 = int_sub_ovf(i2, i1) guard_no_overflow() [] i4 = int_le(i3, 10) guard_true(i4) [] i5 = int_ge(i3, 2) guard_true(i5) [] i6 = int_lt(i1, -10) guard_false(i6) [] i7 = int_gt(i1, 253) guard_false(i7) [] jump(i0, i1) """ expected = """ [i0, i1] i2 =...
jump(i0, i1) """ self.optimize_loop(ops, expected)
jump(i0, i1, i2) """ expected = """ [i0, i1, i2] i3 = int_sub(i2, i1) i4 = int_le(i3, 10) guard_true(i4) [] i5 = int_ge(i3, 2) guard_true(i5) [] jump(i0, i1, i2) """ self.optimize_loop(ops, expected, preamble)
def test_sub_ovf_before(self): ops = """ [i0, i1] i2 = int_and(i0, 255) i3 = int_sub_ovf(i2, i1) guard_no_overflow() [] i4 = int_le(i3, 10) guard_true(i4) [] i5 = int_ge(i3, 2) guard_true(i5) [] i6 = int_lt(i1, -10) guard_false(i6) [] i7 = int_gt(i1, 253) guard_false(i7) [] jump(i0, i1) """ expected = """ [i0, i1] i2 =...
print "AFA CONTINUE", bufSize, retDataSize[0]
def QueryValueEx(space, w_hkey, w_subkey): """value,type_id = QueryValueEx(key, value_name) - Retrieves the type and data for a specified value name associated with an open registry key.
print "AFA OK", bufSize, retDataSize[0]
def QueryValueEx(space, w_hkey, w_subkey): """value,type_id = QueryValueEx(key, value_name) - Retrieves the type and data for a specified value name associated with an open registry key.
rstack.resume_point("CALL_METHOD", f, returns=w_result)
rstack.resume_point("CALL_METHOD", f, w_self, returns=w_result)
def CALL_METHOD(f, oparg, *ignored): # opargs contains the arg, and kwarg count, excluding the implicit 'self' n_args = oparg & 0xff n_kwargs = (oparg >> 8) & 0xff w_self = f.peekvalue(n_args + (2 * n_kwargs)) w_callable = f.peekvalue(n_args + (2 * n_kwargs) + 1) n = n_args + (w_self is not None) if not n_kwargs: try:...
self.mc.MOV_rr(bytes_loc.value, length_loc.value) self._load_address(length_loc, 0, scale, bytes_loc)
self.mc.MOV_ri(r.ip.value, 1<<scale) self.mc.MUL(bytes_loc.value, r.ip.value, length_loc.value)
def _emit_copystrcontent(self, op, regalloc, fcond, is_unicode): # compute the source address args = list(op.getarglist()) base_loc, box = self._ensure_value_is_boxed(args[0], regalloc, args) args.append(box) ofs_loc, box = self._ensure_value_is_boxed(args[2], regalloc, args) args.append(box) assert args[0] is not args...
def _load_address(self, sizereg, baseofs, scale, result, baseloc=None): if baseloc is not None: assert baseloc.is_reg() self.mc.MOV_rr(result.value, baseloc.value) else: self.mc.MOV_ri(result.value, 0) assert sizereg.is_reg() if scale > 0: self.mc.LSL_ri(r.ip.value, sizereg.value, scale) else: self.mc.MOV_rr(r.ip.value...
def _load_address(self, sizereg, baseofs, scale, result, baseloc=None): if baseloc is not None: assert baseloc.is_reg() self.mc.MOV_rr(result.value, baseloc.value) else: self.mc.MOV_ri(result.value, 0) assert sizereg.is_reg() if scale > 0: self.mc.LSL_ri(r.ip.value, sizereg.value, scale) else: self.mc.MOV_rr(r.ip.value...
self._load_address(ofsloc, ofs_items, scale, resloc, baseloc)
self._gen_address(ofsloc, ofs_items, scale, resloc, baseloc) def _gen_address(self, sizereg, baseofs, scale, result, baseloc=None): assert sizereg.is_reg() if scale > 0: scaled_loc = r.ip self.mc.LSL_ri(r.ip.value, sizereg.value, scale) else: scaled_loc = sizereg if baseloc is not None: assert baseloc.is_reg() self.mc...
def _gen_address_inside_string(self, baseloc, ofsloc, resloc, is_unicode): cpu = self.cpu if is_unicode: ofs_items, _, _ = symbolic.get_array_token(rstr.UNICODE, self.cpu.translate_support_code) scale = self._get_unicode_item_scale() else: ofs_items, itemsize, _ = symbolic.get_array_token(rstr.STR, self.cpu.translate_s...
assert type(wrapper_func_kwds) is not str
assert not isinstance(wrapper_func_kwds, str)
def __init__(self, space, pto, method_name, wrapper_func, wrapper_func_kwds, doc, func): self.space = space self.method_name = method_name self.wrapper_func = wrapper_func assert type(wrapper_func_kwds) is not str self.wrapper_func_kwds = wrapper_func_kwds self.doc = doc self.func = func pyo = rffi.cast(PyObject, pto) ...
self.header(shadow).tid = 0
self.header(shadow).tid = self.header(obj).tid typeid = self.get_type_id(obj) if self.is_varsize(typeid): lenofs = self.varsize_offset_to_length(typeid) (shadow + lenofs).signed[0] = (obj + lenofs).signed[0]
def id_or_identityhash(self, gcobj, special_case_prebuilt): """Implement the common logic of id() and identityhash() of an object, given as a GCREF. """ obj = llmemory.cast_ptr_to_adr(gcobj) # if self.is_valid_gc_object(obj): if self.is_in_nursery(obj): # # The object is not a tagged pointer, and it is still in the # n...
lifeline = w_obj.get_pyolifeline()
lifeline = api.lifeline_dict.get(w_obj)
def check_and_print_leaks(self): # check for sane refcnts leaking = False state = self.space.fromcache(State) import gc gc.collect() lost_objects_w = identity_dict() lost_objects_w.update((key, None) for key in self.frozen_refcounts.keys()) for w_obj, obj in state.py_objects_w2r.iteritems(): base_refcnt = self.frozen_r...
self.optimize_strunicode_loop(ops, expected)
self.optimize_strunicode_loop(ops, expected, expected)
def test_bound_strlen(self): ops = """ [p0] i0 = strlen(p0) i1 = int_ge(i0, 0) guard_true(i1) [] jump(p0) """ # The dead strlen will be eliminated be the backend. expected = """ [p0] i0 = strlen(p0) jump(p0) """ self.optimize_strunicode_loop(ops, expected)
libc = CDLL('libc.so.6')
from pypy.rpython.lltypesystem.ll2ctypes import libc_name libc = CDLL(libc_name)
def test_call_to_c_function(self): from pypy.rlib.libffi import CDLL, types, ArgChain libc = CDLL('libc.so.6') c_tolower = libc.getpointer('tolower', [types.uchar], types.sint) argchain = ArgChain().arg(ord('A')) assert c_tolower.call(argchain, rffi.INT) == ord('a')
visit_cmove = binary_insn visit_cmovne = binary_insn visit_cmovg = binary_insn visit_cmovge = binary_insn visit_cmovl = binary_insn visit_cmovle = binary_insn visit_cmova = binary_insn visit_cmovae = binary_insn visit_cmovb = binary_insn visit_cmovbe = binary_insn visit_cmovp = binary_insn visit_cmovnp = binary_insn vi...
for name in ''' e ne g ge l le a ae b be p np s ns o no '''.split(): locals()['visit_cmov' + name] = binary_insn locals()['visit_cmov' + name + 'l'] = binary_insn
def binary_insn(self, line): match = self.r_binaryinsn.match(line) if not match: raise UnrecognizedOperation(line) source = match.group("source") target = match.group("target") if self.r_localvar.match(target): return InsnSetLocal(target, [source]) elif target == self.ESP: raise UnrecognizedOperation(line) else: return...
expr = '%s(%r%s)' %(func.__name__, args, k)
expr = '%s(%r%s)' %(getattr(func, '__name__', func), args, k)
def raises(ExpectedException, *args, **kwargs): """ raise AssertionError, if target code does not raise the expected exception. """ __tracebackhide__ = True assert args if isinstance(args[0], str): code, = args assert isinstance(code, str) frame = sys._getframe(1) loc = frame.f_locals.copy() loc.update(kwargs) #print "...
return _callinfo_for_oopspec[oopspecindex]
try: return _callinfo_for_oopspec[oopspecindex] except KeyError: return None
def callinfo_for_oopspec(oopspecindex): """A function that returns the calldescr and the function address (as an int) of one of the OS_XYZ functions defined above. Don't use this if there might be several implementations of the same OS_XYZ specialized by type, e.g. OS_ARRAYCOPY.""" return _callinfo_for_oopspec[oopspeci...
rstack.resume_point("CALL_METHOD", f, w_self, returns=w_result)
rstack.resume_point("CALL_METHOD", f, returns=w_result)
def CALL_METHOD(f, oparg, *ignored): # opargs contains the arg, and kwarg count, excluding the implicit 'self' n_args = oparg & 0xff n_kwargs = (oparg >> 8) & 0xff w_self = f.peekvalue(n_args + (2 * n_kwargs)) w_callable = f.peekvalue(n_args + (2 * n_kwargs) + 1) n = n_args + (w_self is not None) if not n_kwargs: try:...
skip("not working yet")
def test_new_exception(self): skip("not working yet") mod = self.import_extension('foo', [ ('newexc', 'METH_VARARGS', ''' char *name = PyString_AsString(PyTuple_GetItem(args, 0)); return PyExc_NewException(name, PyTuple_GetItem(args, 1), PyTuple_GetItem(args, 2)); ''' ), ]) raises(SystemError, mod.newexc, "name", Excep...
return PyExc_NewException(name, PyTuple_GetItem(args, 1),
return PyErr_NewException(name, PyTuple_GetItem(args, 1),
def test_new_exception(self): skip("not working yet") mod = self.import_extension('foo', [ ('newexc', 'METH_VARARGS', ''' char *name = PyString_AsString(PyTuple_GetItem(args, 0)); return PyExc_NewException(name, PyTuple_GetItem(args, 1), PyTuple_GetItem(args, 2)); ''' ), ]) raises(SystemError, mod.newexc, "name", Excep...
if 'getitem__Array' in graph.name: if len(inputcells) > 2 and isinstance(inputcells[1], annmodel.SomeInstance) and 'Base' in str(inputcells[1].classdef): import pdb pdb.set_trace() print graph print inputcells
def bindinputargs(self, graph, block, inputcells, called_from_graph=None): if 'getitem__Array' in graph.name: if len(inputcells) > 2 and isinstance(inputcells[1], annmodel.SomeInstance) and 'Base' in str(inputcells[1].classdef): import pdb pdb.set_trace() print graph print inputcells # Create the initial bindings for t...
"""])
"""], export_symbols=['fn_test_result_of_call'])
def test_short_result_of_call_direct(self): # Test that calling a function that returns a CHAR, SHORT or INT, # signed or unsigned, properly gets zero-extended or sign-extended. from pypy.translator.tool.cbuild import ExternalCompilationInfo for RESTYPE in [rffi.SIGNEDCHAR, rffi.UCHAR, rffi.SHORT, rffi.USHORT, rffi.INT...
"""])
"""], export_symbols=['fn_test_result_of_call'])
def test_short_result_of_call_compiled(self): # Test that calling a function that returns a CHAR, SHORT or INT, # signed or unsigned, properly gets zero-extended or sign-extended. from pypy.translator.tool.cbuild import ExternalCompilationInfo for RESTYPE in [rffi.SIGNEDCHAR, rffi.UCHAR, rffi.SHORT, rffi.USHORT, rffi.I...
assert prefix.join('bin', 'pypy-c').check()
assert prefix.join('bin', 'pypy').check()
def test_dir_structure(test='test'): # make sure we have sort of pypy-c pypy_c = py.path.local(pypydir).join('translator', 'goal', 'pypy-c') if not pypy_c.check(): os.system("echo faked_pypy_c> %s" % (pypy_c,)) fake_pypy_c = True else: fake_pypy_c = False try: builddir = package(py.path.local(pypydir).dirpath(), test) ...
assert total0 + total == 10
assert total0 + total == 16
def heuristic(graph): for block in graph.iterblocks(): for op in block.operations: if op.opname in ('malloc',): return inline.inlining_heuristic(graph) return sys.maxint, False
virtuals=True)
not_a_bridge=True)
def optimize_loop(self, ops, spectext, optops): loop = self.parse(ops) # self.loop = loop metainterp_sd = FakeMetaInterpStaticData(self.cpu) if hasattr(self, 'vrefinfo'): metainterp_sd.virtualref_info = self.vrefinfo # # XXX list the exact optimizations that are needed for each test from pypy.jit.metainterp.optimizeopt...
split_one_loop(real_loops, 'Guard5', 'extra')
split_one_loop(real_loops, 'Guard5', 'extra', 1)
def test_split_one_loop(self): real_loops = [FinalBlock(preparse(""" p21 = getfield_gc(p4, descr=<GcPtrFieldDescr 16>) guard_class(p4, 141310752, descr=<Guard51>) [p0, p1] """), None), FinalBlock(preparse(""" p60 = getfield_gc(p4, descr=<GcPtrFieldDescr 16>) guard_nonnull(p60, descr=<Guard5>) [p0, p1] """), None)] spli...
assert real_loops[0].content.startswith("_runCallbacks, file '/tmp/x/twisted-trunk/twisted/internet/defer.py', line 357")
assert real_loops[0].header.startswith("_runCallbacks, file '/tmp/x/twisted-trunk/twisted/internet/defer.py', line 357")
def test_postparse(self): real_loops = [FinalBlock("debug_merge_point('<code object _runCallbacks, file '/tmp/x/twisted-trunk/twisted/internet/defer.py', line 357> #40 POP_TOP')", None)] postprocess(real_loops) assert real_loops[0].content.startswith("_runCallbacks, file '/tmp/x/twisted-trunk/twisted/internet/defer.py'...
s, ord(c), self.fmtpos)
s, ord(c), self.fmtpos - 1)
def unknown_fmtchar(self): space = self.space c = self.fmt[self.fmtpos - 1] if do_unicode: w_defaultencoding = space.call_function( space.sys.get('getdefaultencoding')) w_s = space.call_method(space.wrap(c), "encode", w_defaultencoding, space.wrap('replace')) s = space.str_w(w_s) else: s = c msg = "unsupported format c...
def __init__(self, color=None, width=None, block='█', empty=' '):
def __init__(self, color=None, width=None, block='.', empty=' '):
def __init__(self, color=None, width=None, block='█', empty=' '): """ color -- color name (BLUE GREEN CYAN RED MAGENTA YELLOW WHITE BLACK) width -- bar width (optinal) block -- progress display character (default '█') empty -- bar display character (default ' ') """ if color: self.color = getattr(terminal, color.upper(...
block -- progress display character (default '█')
block -- progress display character (default '.')
def __init__(self, color=None, width=None, block='█', empty=' '): """ color -- color name (BLUE GREEN CYAN RED MAGENTA YELLOW WHITE BLACK) width -- bar width (optinal) block -- progress display character (default '█') empty -- bar display character (default ' ') """ if color: self.color = getattr(terminal, color.upper(...
w_dem = space.newlong(1)
w_den = space.newlong(1)
def float_as_integer_ratio__Float(space, w_float): value = w_float.floatval if isinf(value): w_msg = space.wrap("cannot pass infinity to as_integer_ratio()") raise OperationError(space.w_OverflowError, w_msg) elif isnan(value): w_msg = space.wrap("cannot pass nan to as_integer_ratio()") raise OperationError(space.w_Val...
w_exp = space.lshift(w_dem, w_exp)
w_exp = space.lshift(w_den, w_exp)
def float_as_integer_ratio__Float(space, w_float): value = w_float.floatval if isinf(value): w_msg = space.wrap("cannot pass infinity to as_integer_ratio()") raise OperationError(space.w_OverflowError, w_msg) elif isnan(value): w_msg = space.wrap("cannot pass nan to as_integer_ratio()") raise OperationError(space.w_Val...
w_dem = w_exp
w_den = w_exp
def float_as_integer_ratio__Float(space, w_float): value = w_float.floatval if isinf(value): w_msg = space.wrap("cannot pass infinity to as_integer_ratio()") raise OperationError(space.w_OverflowError, w_msg) elif isnan(value): w_msg = space.wrap("cannot pass nan to as_integer_ratio()") raise OperationError(space.w_Val...
return space.newtuple([space.int(w_num), space.int(w_dem)])
return space.newtuple([space.int(w_num), space.int(w_den)])
def float_as_integer_ratio__Float(space, w_float): value = w_float.floatval if isinf(value): w_msg = space.wrap("cannot pass infinity to as_integer_ratio()") raise OperationError(space.w_OverflowError, w_msg) elif isnan(value): w_msg = space.wrap("cannot pass nan to as_integer_ratio()") raise OperationError(space.w_Val...
self.max_delta = 0.0
self.max_delta = float(r_uint(-1))
def __init__(self, config, read_from_env=False, nursery_size=32*WORD, page_size=16*WORD, arena_size=64*WORD, small_request_threshold=5*WORD, major_collection_threshold=2.5, growth_rate_max=2.5, # for tests card_page_indices=0, large_object=8*WORD, large_object_gcptrs=10*WORD, ArenaCollectionClass=None, **kwds): Movin...
if self.max_delta > 0.0: threshold_max = min(threshold_max, self.next_major_collection_threshold + self.max_delta)
def set_major_threshold_from(self, threshold, reserving_size=0): # Set the next_major_collection_threshold. threshold_max = (self.next_major_collection_threshold * self.growth_rate_max) if self.max_delta > 0.0: threshold_max = min(threshold_max, self.next_major_collection_threshold + self.max_delta) if threshold > thre...
self.get_total_memory_used() * self.major_collection_threshold,
min(total_memory_used * self.major_collection_threshold, total_memory_used + self.max_delta),
def major_collection(self, reserving_size=0): """Do a major collection. Only for when the nursery is empty.""" # debug_start("gc-collect") debug_print() debug_print(".----------- Full collection ------------------") debug_print("| used before collection:") debug_print("| in ArenaCollection: ", self.ac.tot...
assert result == rctime.strftime('%m/%d/%y', t)
assert result == rctime.strftime('%m/%d/%y', tt)
def test_strftime_ext(self): import time as rctime
builder.append(unichr(chr))
builder.append(UNICHR(chr))
def hexescape(builder, s, pos, digits, encoding, errorhandler, message, errors): import sys chr = 0 if pos + digits > len(s): message = "end of string in escape sequence" res, pos = errorhandler(errors, "unicodeescape", message, s, pos-2, len(s)) builder.append(res) else: try: chr = r_uint(int(s[pos:pos+digits], 16)) e...
builder.append(unichr(code))
builder.append(UNICHR(code))
def str_decode_unicode_escape(s, size, errors, final=False, errorhandler=False, unicodedata_handler=None): if errorhandler is None: errorhandler = raise_unicode_exception_decode if size == 0: return u'', 0 builder = UnicodeBuilder(size) pos = 0 while pos < size: ch = s[pos] # Non-escape characters are interpreted as...
def __init__(self, *args): if args: raise Exception
def __init__(self, *args): if args: raise Exception
return [InsnStop(target), InsnCannotFollowEsp()]
return [InsnStop(target)]
def walker(insn, locs): sources = [] for loc in locs: for s in insn.all_sources_of(loc): sources.append(s) for source in sources: m = re.match("DWORD PTR " + self.LABEL, source) if m: reg.append(m.group(1)) if reg: return yield tuple(sources)
res = regalloc.force_allocate_reg(op.result, selected_reg=r.r0)
regalloc.before_call()
def f(self, op, regalloc, fcond): a0 = op.getarg(0) a1 = op.getarg(1) arg1 = regalloc.make_sure_var_in_reg(a0, selected_reg=r.r0, imm_fine=False) arg2 = regalloc.make_sure_var_in_reg(a1, [a0], selected_reg=r.r1, imm_fine=False) assert arg1 == r.r0 assert arg2 == r.r1 res = regalloc.force_allocate_reg(op.result, selecte...
presentation_type = default_type
the_type = default_type
def _parse_spec(self, default_type, default_align): space = self.space self._fill_char = self._lit("\0") self._align = default_align self._alternate = False self._sign = "\0" self._thousands_sep = False self._precision = -1 presentation_type = default_type spec = self.spec if not spec: return True length = len(spec) i ...
i += 1 if self.is_unicode: try: the_type = presentation_type.encode("ascii") except UnicodeEncodeError: raise OperationError(space.w_ValueError, space.wrap("invalid type")) else: the_type = presentation_type
if self.is_unicode: try: the_type = spec[i].encode("ascii") except UnicodeEncodeError: raise OperationError(space.w_ValueError, space.wrap("invalid presentation type")) else: the_type = presentation_type i += 1
def _parse_spec(self, default_type, default_align): space = self.space self._fill_char = self._lit("\0") self._align = default_align self._alternate = False self._sign = "\0" self._thousands_sep = False self._precision = -1 presentation_type = default_type spec = self.spec if not spec: return True length = len(spec) i ...
the_type = spec[i].encode("ascii")
the_type = spec[i].encode("ascii")[0]
def _parse_spec(self, default_type, default_align): space = self.space self._fill_char = self._lit("\0")[0] self._align = default_align self._alternate = False self._sign = "\0" self._thousands_sep = False self._precision = -1 the_type = default_type spec = self.spec if not spec: return True length = len(spec) i = 0 go...
self._adjust_sp(n, fcond=fcond)
self._adjust_sp(n, regalloc, fcond=fcond)
def emit_op_call(self, op, regalloc, fcond): locs = [] # all arguments past the 4th go on the stack # XXX support types other than int (one word types) if op.numargs() > 5: stack_args = op.numargs() - 5 n = stack_args*WORD self._adjust_sp(n, fcond=fcond) for i in range(5, op.numargs()): reg = regalloc.make_sure_var_in_...
if self._ptr is not None:
if self._ptr is not None and argtypes is self._argtypes_:
def _getfuncptr(self, argtypes, restype, thisarg=None): if self._ptr is not None: return self._ptr if restype is None or not isinstance(restype, _CDataMeta): import ctypes restype = ctypes.c_int argshapes = [arg._ffiargshape for arg in argtypes] resshape = restype._ffiargshape if self._buffer is not None: ptr = _rawffi...
w_result = space.wrap(result[0] != '\x00')
x = rffi.cast(lltype.Signed, result[0]) w_result = space.wrap(x != 0)
def PyMember_GetOne(space, obj, w_member): addr = rffi.cast(ADDR, obj) addr += w_member.c_offset member_type = rffi.cast(lltype.Signed, w_member.c_type) for converter in integer_converters: typ, lltyp, _ = converter if typ == member_type: result = rffi.cast(rffi.CArrayPtr(lltyp), addr) if lltyp is rffi.FLOAT: w_result...
return space.w_bool(not self.is_valid())
return space.newbool(not self.is_valid())
def closed_get(space, self): return space.w_bool(not self.is_valid())
return space.w_bool(self.flags & READABLE)
return space.newbool(bool(self.flags & READABLE))
def readable_get(space, self): return space.w_bool(self.flags & READABLE)
return space.w_bool(self.flags & WRITABLE)
return space.newbool(bool(self.flags & WRITABLE))
def writable_get(space, self): return space.w_bool(self.flags & WRITABLE)
raise mp_error(res)
raise mp_error(space, res)
def recv_bytes(self, space, maxlength=PY_SSIZE_T_MAX): self._check_readable(space) if maxlength < 0: raise OperationError(space.w_ValueError, space.wrap("maxlength < 0"))
raise mp_error(res)
raise mp_error(space, res)
def recv_bytes_into(self, space, w_buffer, offset=0): rwbuffer = space.rwbuffer_w(w_buffer) length = rwbuffer.getlength()
raise OperationError(BufferTooShort)
raise BufferTooShort(space)
def recv_bytes_into(self, space, w_buffer, offset=0): rwbuffer = space.rwbuffer_w(w_buffer) length = rwbuffer.getlength()
raise mp_error(res)
raise mp_error(space, res)
def recv(self, space): self._check_readable(space)
base_typedef = TypeDef(
W_BaseConnection.typedef = TypeDef(
def recv(self, space): self._check_readable(space)
def descr_new(space, w_subtype, fd, readable=True, writable=True):
def descr_new_file(space, w_subtype, fd, readable=True, writable=True):
def descr_new(space, w_subtype, fd, readable=True, writable=True): flags = (readable and READABLE) | (writable and WRITABLE)
self._recvall(rffi.cast(rffi.CCHARP, length_ptr), 4) length = length_ptr[0]
self._recvall(space, rffi.cast(rffi.CCHARP, length_ptr), 4) length = intmask(length_ptr[0])
def do_recv_string(self, space, maxlength): length_ptr = lltype.malloc(rffi.CArrayPtr(rffi.UINT).TO, 1, flavor='raw') self._recvall(rffi.cast(rffi.CCHARP, length_ptr), 4) length = length_ptr[0] if length > maxlength: return MP_BAD_MESSAGE_LENGTH
return MP_BAD_MESSAGE_LENGTH
return MP_BAD_MESSAGE_LENGTH, lltype.nullptr(rffi.CCHARP.TO)
def do_recv_string(self, space, maxlength): length_ptr = lltype.malloc(rffi.CArrayPtr(rffi.UINT).TO, 1, flavor='raw') self._recvall(rffi.cast(rffi.CCHARP, length_ptr), 4) length = length_ptr[0] if length > maxlength: return MP_BAD_MESSAGE_LENGTH
self._recvall(self.buffer, length) return length, None
self._recvall(space, self.buffer, length) return length, lltype.nullptr(rffi.CCHARP.TO)
def do_recv_string(self, space, maxlength): length_ptr = lltype.malloc(rffi.CArrayPtr(rffi.UINT).TO, 1, flavor='raw') self._recvall(rffi.cast(rffi.CCHARP, length_ptr), 4) length = length_ptr[0] if length > maxlength: return MP_BAD_MESSAGE_LENGTH
self._recvall(newbuf, length)
self._recvall(space, newbuf, length)
def do_recv_string(self, space, maxlength): length_ptr = lltype.malloc(rffi.CArrayPtr(rffi.UINT).TO, 1, flavor='raw') self._recvall(rffi.cast(rffi.CCHARP, length_ptr), 4) length = length_ptr[0] if length > maxlength: return MP_BAD_MESSAGE_LENGTH
def _recvall(self, buffer, length):
def _recvall(self, space, buffer, length): length = intmask(length)
def _recvall(self, buffer, length): remaining = length while remaining > 0: try: data = os.read(self.fd, remaining) except OSError, e: raise wrap_oserror(space, e) count = len(data) if count == 0: if remaining == length: return MP_END_OF_FILE else: return MP_EARLY_END_OF_FILE # XXX inefficient for i in range(count): bu...
return MP_END_OF_FILE
raise mp_error(space, MP_END_OF_FILE)
def _recvall(self, buffer, length): remaining = length while remaining > 0: try: data = os.read(self.fd, remaining) except OSError, e: raise wrap_oserror(space, e) count = len(data) if count == 0: if remaining == length: return MP_END_OF_FILE else: return MP_EARLY_END_OF_FILE # XXX inefficient for i in range(count): bu...
return MP_EARLY_END_OF_FILE
raise mp_error(space, MP_EARLY_END_OF_FILE)
def _recvall(self, buffer, length): remaining = length while remaining > 0: try: data = os.read(self.fd, remaining) except OSError, e: raise wrap_oserror(space, e) count = len(data) if count == 0: if remaining == length: return MP_END_OF_FILE else: return MP_EARLY_END_OF_FILE # XXX inefficient for i in range(count): bu...