1. Pypy
  2. Untitled project
  3. pypy

Commits

mattip  committed b2be8b8 Merge

merge default into branch

  • Participants
  • Parent commits cc265a9, f772351
  • Branches win_ffi

Comments (0)

Files changed (54)

File lib_pypy/_ctypes/basics.py

View file
         else:
             return self.from_param(as_parameter)
 
-    def get_ffi_param(self, value):
-        cdata = self.from_param(value)
-        return cdata, cdata._to_ffi_param()
-
     def get_ffi_argtype(self):
         if self._ffiargtype:
             return self._ffiargtype

File lib_pypy/_ctypes/function.py

View file
 
     @classmethod
     def _conv_param(cls, argtype, arg):
-        if isinstance(argtype, _CDataMeta):
-            cobj, ffiparam = argtype.get_ffi_param(arg)
-            return cobj, ffiparam, argtype
-        
         if argtype is not None:
             arg = argtype.from_param(arg)
         if hasattr(arg, '_as_parameter_'):

File lib_pypy/ctypes_support.py

View file
 if sys.platform == 'win32':
     import _ffi
     standard_c_lib = ctypes.CDLL('msvcrt', handle=_ffi.get_libc())
+elif sys.platform == 'cygwin':
+    standard_c_lib = ctypes.CDLL(ctypes.util.find_library('cygwin'))
 else:
     standard_c_lib = ctypes.CDLL(ctypes.util.find_library('c'))
 

File pypy/doc/whatsnew-1.9.rst

View file
 .. this is the revision just after the creation of the release-1.8.x branch
 .. startrev: a4261375b359
 
+.. branch: default
+* Working hash function for numpy types.
+
 .. branch: array_equal
 .. branch: better-jit-hooks-2
+Improved jit hooks
 .. branch: faster-heapcache
 .. branch: faster-str-decode-escape
 .. branch: float-bytes
 .. branch: jit-frame-counter
 Put more debug info into resops.
 .. branch: kill-geninterp
+Kill "geninterp", an old attempt to statically turn some fixed
+app-level code to interp-level.
 .. branch: kqueue
 Finished select.kqueue.
 .. branch: kwargsdict-strategy
+Special dictionary strategy for dealing with \*\*kwds. Now having a simple
+proxy ``def f(*args, **kwds): return x(*args, **kwds`` should not make
+any allocations at all.
 .. branch: matrixmath-dot
 numpypy can now handle matrix multiplication.
 .. branch: merge-2.7.2
 cpyext: Better support for PyEval_SaveThread and other PyTreadState_*
 functions.
 .. branch: numppy-flatitter
+flatitier for numpy
 .. branch: numpy-back-to-applevel
+reuse more of original numpy
 .. branch: numpy-concatenate
+concatenation support for numpy
 .. branch: numpy-indexing-by-arrays-bool
+indexing by bool arrays
 .. branch: numpy-record-dtypes
+record dtypes on numpy has been started
 .. branch: numpy-single-jitdriver
 .. branch: numpy-ufuncs2
 .. branch: numpy-ufuncs3
+various refactorings regarding numpy
 .. branch: numpypy-issue1137
 .. branch: numpypy-out
 The "out" argument was added to most of the numypypy functions.
 .. branch: numpypy-ufuncs
 .. branch: pytest
 .. branch: safe-getargs-freelist
+CPyext improvements. For example PyOpenSSL should now work
 .. branch: set-strategies
+Sets now have strategies just like dictionaries. This means a set
+containing only ints will be more compact (and faster)
 .. branch: speedup-list-comprehension
+The simplest case of list comprehension is preallocating the correct size
+of the list. This speeds up select benchmarks quite significantly.
 .. branch: stdlib-unification
 The directory "lib-python/modified-2.7" has been removed, and its
 content merged into "lib-python/2.7".
 Add os.kill to windows even if translating python does not have os.kill
 .. branch: win64-stage1
 .. branch: zlib-mem-pressure
+Memory "leaks" associated with zlib are fixed.
 
 .. branch: ffistruct
 The ``ffistruct`` branch adds a very low level way to express C structures

File pypy/jit/backend/llsupport/gc.py

View file
     def __init__(self, gc_ll_descr):
         self.llop1 = gc_ll_descr.llop1
         self.WB_FUNCPTR = gc_ll_descr.WB_FUNCPTR
-        self.WB_ARRAY_FUNCPTR = gc_ll_descr.WB_ARRAY_FUNCPTR
         self.fielddescr_tid = gc_ll_descr.fielddescr_tid
         #
         GCClass = gc_ll_descr.GCClass
             self.jit_wb_card_page_shift = GCClass.JIT_WB_CARD_PAGE_SHIFT
             self.jit_wb_cards_set_byteofs, self.jit_wb_cards_set_singlebyte = (
                 self.extract_flag_byte(self.jit_wb_cards_set))
+            #
+            # the x86 backend uses the following "accidental" facts to
+            # avoid one instruction:
+            assert self.jit_wb_cards_set_byteofs == self.jit_wb_if_flag_byteofs
+            assert self.jit_wb_cards_set_singlebyte == -0x80
         else:
             self.jit_wb_cards_set = 0
 
         # returns a function with arguments [array, index, newvalue]
         llop1 = self.llop1
         funcptr = llop1.get_write_barrier_from_array_failing_case(
-            self.WB_ARRAY_FUNCPTR)
+            self.WB_FUNCPTR)
         funcaddr = llmemory.cast_ptr_to_adr(funcptr)
         return cpu.cast_adr_to_int(funcaddr)    # this may return 0
 
 
     def _setup_write_barrier(self):
         self.WB_FUNCPTR = lltype.Ptr(lltype.FuncType(
-            [llmemory.Address, llmemory.Address], lltype.Void))
-        self.WB_ARRAY_FUNCPTR = lltype.Ptr(lltype.FuncType(
-            [llmemory.Address, lltype.Signed, llmemory.Address], lltype.Void))
+            [llmemory.Address], lltype.Void))
         self.write_barrier_descr = WriteBarrierDescr(self)
 
     def _make_functions(self, really_not_translated):
             # the GC, and call it immediately
             llop1 = self.llop1
             funcptr = llop1.get_write_barrier_failing_case(self.WB_FUNCPTR)
-            funcptr(llmemory.cast_ptr_to_adr(gcref_struct),
-                    llmemory.cast_ptr_to_adr(gcref_newptr))
+            funcptr(llmemory.cast_ptr_to_adr(gcref_struct))
 
     def can_use_nursery_malloc(self, size):
         return size < self.max_size_of_young_obj

File pypy/jit/backend/test/runner_test.py

View file
         assert not excvalue
 
     def test_cond_call_gc_wb(self):
-        def func_void(a, b):
-            record.append((a, b))
+        def func_void(a):
+            record.append(a)
         record = []
         #
         S = lltype.GcStruct('S', ('tid', lltype.Signed))
-        FUNC = self.FuncType([lltype.Ptr(S), lltype.Ptr(S)], lltype.Void)
+        FUNC = self.FuncType([lltype.Ptr(S)], lltype.Void)
         func_ptr = llhelper(lltype.Ptr(FUNC), func_void)
         funcbox = self.get_funcbox(self.cpu, func_ptr)
         class WriteBarrierDescr(AbstractDescr):
                                    [BoxPtr(sgcref), ConstPtr(tgcref)],
                                    'void', descr=WriteBarrierDescr())
             if cond:
-                assert record == [(s, t)]
+                assert record == [s]
             else:
                 assert record == []
 
     def test_cond_call_gc_wb_array(self):
-        def func_void(a, b, c):
-            record.append((a, b, c))
+        def func_void(a):
+            record.append(a)
         record = []
         #
         S = lltype.GcStruct('S', ('tid', lltype.Signed))
-        FUNC = self.FuncType([lltype.Ptr(S), lltype.Signed, lltype.Ptr(S)],
-                             lltype.Void)
+        FUNC = self.FuncType([lltype.Ptr(S)], lltype.Void)
         func_ptr = llhelper(lltype.Ptr(FUNC), func_void)
         funcbox = self.get_funcbox(self.cpu, func_ptr)
         class WriteBarrierDescr(AbstractDescr):
             jit_wb_if_flag = 4096
             jit_wb_if_flag_byteofs = struct.pack("i", 4096).index('\x10')
             jit_wb_if_flag_singlebyte = 0x10
-            jit_wb_cards_set = 0
-            def get_write_barrier_from_array_fn(self, cpu):
+            jit_wb_cards_set = 0       # <= without card marking
+            def get_write_barrier_fn(self, cpu):
                 return funcbox.getint()
         #
         for cond in [False, True]:
                        [BoxPtr(sgcref), ConstInt(123), BoxPtr(sgcref)],
                        'void', descr=WriteBarrierDescr())
             if cond:
-                assert record == [(s, 123, s)]
+                assert record == [s]
             else:
                 assert record == []
 
     def test_cond_call_gc_wb_array_card_marking_fast_path(self):
-        def func_void(a, b, c):
-            record.append((a, b, c))
+        def func_void(a):
+            record.append(a)
+            if cond == 1:      # the write barrier sets the flag
+                s.data.tid |= 32768
         record = []
         #
         S = lltype.Struct('S', ('tid', lltype.Signed))
                                      ('card6', lltype.Char),
                                      ('card7', lltype.Char),
                                      ('data',  S))
-        FUNC = self.FuncType([lltype.Ptr(S), lltype.Signed, lltype.Ptr(S)],
-                             lltype.Void)
+        FUNC = self.FuncType([lltype.Ptr(S)], lltype.Void)
         func_ptr = llhelper(lltype.Ptr(FUNC), func_void)
         funcbox = self.get_funcbox(self.cpu, func_ptr)
         class WriteBarrierDescr(AbstractDescr):
             jit_wb_if_flag = 4096
             jit_wb_if_flag_byteofs = struct.pack("i", 4096).index('\x10')
             jit_wb_if_flag_singlebyte = 0x10
-            jit_wb_cards_set = 8192
-            jit_wb_cards_set_byteofs = struct.pack("i", 8192).index('\x20')
-            jit_wb_cards_set_singlebyte = 0x20
+            jit_wb_cards_set = 32768
+            jit_wb_cards_set_byteofs = struct.pack("i", 32768).index('\x80')
+            jit_wb_cards_set_singlebyte = -0x80
             jit_wb_card_page_shift = 7
             def get_write_barrier_from_array_fn(self, cpu):
                 return funcbox.getint()
         #
-        for BoxIndexCls in [BoxInt, ConstInt]:
-            for cond in [False, True]:
+        for BoxIndexCls in [BoxInt, ConstInt]*3:
+            for cond in [-1, 0, 1, 2]:
+                # cond=-1:GCFLAG_TRACK_YOUNG_PTRS, GCFLAG_CARDS_SET are not set
+                # cond=0: GCFLAG_CARDS_SET is never set
+                # cond=1: GCFLAG_CARDS_SET is not set, but the wb sets it
+                # cond=2: GCFLAG_CARDS_SET is already set
                 print
                 print '_'*79
                 print 'BoxIndexCls =', BoxIndexCls
-                print 'JIT_WB_CARDS_SET =', cond
+                print 'testing cond =', cond
                 print
                 value = random.randrange(-sys.maxint, sys.maxint)
-                value |= 4096
-                if cond:
-                    value |= 8192
+                if cond >= 0:
+                    value |= 4096
                 else:
-                    value &= ~8192
+                    value &= ~4096
+                if cond == 2:
+                    value |= 32768
+                else:
+                    value &= ~32768
                 s = lltype.malloc(S_WITH_CARDS, immortal=True, zero=True)
                 s.data.tid = value
                 sgcref = rffi.cast(llmemory.GCREF, s.data)
                 self.execute_operation(rop.COND_CALL_GC_WB_ARRAY,
                            [BoxPtr(sgcref), box_index, BoxPtr(sgcref)],
                            'void', descr=WriteBarrierDescr())
-                if cond:
+                if cond in [0, 1]:
+                    assert record == [s.data]
+                else:
                     assert record == []
+                if cond in [1, 2]:
                     assert s.card6 == '\x02'
                 else:
-                    assert record == [(s.data, (9<<7) + 17, s.data)]
                     assert s.card6 == '\x00'
                 assert s.card0 == '\x00'
                 assert s.card1 == '\x00'
                 assert s.card4 == '\x00'
                 assert s.card5 == '\x00'
                 assert s.card7 == '\x00'
+                if cond == 1:
+                    value |= 32768
+                assert s.data.tid == value
 
     def test_force_operations_returning_void(self):
         values = []

File pypy/jit/backend/x86/assembler.py

View file
 from pypy.rlib.jit import AsmInfo
 from pypy.jit.backend.model import CompiledLoopToken
 from pypy.jit.backend.x86.regalloc import (RegAlloc, get_ebp_ofs, _get_scale,
-    gpr_reg_mgr_cls, _valid_addressing_size)
+    gpr_reg_mgr_cls, xmm_reg_mgr_cls, _valid_addressing_size)
 
 from pypy.jit.backend.x86.arch import (FRAME_FIXED_SIZE, FORCE_INDEX_OFS, WORD,
                                        IS_X86_32, IS_X86_64)
         self.float_const_abs_addr = 0
         self.malloc_slowpath1 = 0
         self.malloc_slowpath2 = 0
+        self.wb_slowpath = [0, 0, 0, 0]
         self.memcpy_addr = 0
         self.setup_failure_recovery()
         self._debug = False
         self.memcpy_addr = self.cpu.cast_ptr_to_int(support.memcpy_fn)
         self._build_failure_recovery(False)
         self._build_failure_recovery(True)
+        self._build_wb_slowpath(False)
+        self._build_wb_slowpath(True)
         if self.cpu.supports_floats:
             self._build_failure_recovery(False, withfloats=True)
             self._build_failure_recovery(True, withfloats=True)
+            self._build_wb_slowpath(False, withfloats=True)
+            self._build_wb_slowpath(True, withfloats=True)
             support.ensure_sse2_floats()
             self._build_float_constants()
         self._build_propagate_exception_path()
         rawstart = mc.materialize(self.cpu.asmmemmgr, [])
         self.stack_check_slowpath = rawstart
 
+    def _build_wb_slowpath(self, withcards, withfloats=False):
+        descr = self.cpu.gc_ll_descr.write_barrier_descr
+        if descr is None:
+            return
+        if not withcards:
+            func = descr.get_write_barrier_fn(self.cpu)
+        else:
+            if descr.jit_wb_cards_set == 0:
+                return
+            func = descr.get_write_barrier_from_array_fn(self.cpu)
+            if func == 0:
+                return
+        #
+        # This builds a helper function called from the slow path of
+        # write barriers.  It must save all registers, and optionally
+        # all XMM registers.  It takes a single argument just pushed
+        # on the stack even on X86_64.  It must restore stack alignment
+        # accordingly.
+        mc = codebuf.MachineCodeBlockWrapper()
+        #
+        frame_size = (1 +     # my argument, considered part of my frame
+                      1 +     # my return address
+                      len(gpr_reg_mgr_cls.save_around_call_regs))
+        if withfloats:
+            frame_size += 16     # X86_32: 16 words for 8 registers;
+                                 # X86_64: just 16 registers
+        if IS_X86_32:
+            frame_size += 1      # argument to pass to the call
+        #
+        # align to a multiple of 16 bytes
+        frame_size = (frame_size + (CALL_ALIGN-1)) & ~(CALL_ALIGN-1)
+        #
+        correct_esp_by = (frame_size - 2) * WORD
+        mc.SUB_ri(esp.value, correct_esp_by)
+        #
+        ofs = correct_esp_by
+        if withfloats:
+            for reg in xmm_reg_mgr_cls.save_around_call_regs:
+                ofs -= 8
+                mc.MOVSD_sx(ofs, reg.value)
+        for reg in gpr_reg_mgr_cls.save_around_call_regs:
+            ofs -= WORD
+            mc.MOV_sr(ofs, reg.value)
+        #
+        if IS_X86_32:
+            mc.MOV_rs(eax.value, (frame_size - 1) * WORD)
+            mc.MOV_sr(0, eax.value)
+        elif IS_X86_64:
+            mc.MOV_rs(edi.value, (frame_size - 1) * WORD)
+        mc.CALL(imm(func))
+        #
+        if withcards:
+            # A final TEST8 before the RET, for the caller.  Careful to
+            # not follow this instruction with another one that changes
+            # the status of the CPU flags!
+            mc.MOV_rs(eax.value, (frame_size - 1) * WORD)
+            mc.TEST8(addr_add_const(eax, descr.jit_wb_if_flag_byteofs),
+                     imm(-0x80))
+        #
+        ofs = correct_esp_by
+        if withfloats:
+            for reg in xmm_reg_mgr_cls.save_around_call_regs:
+                ofs -= 8
+                mc.MOVSD_xs(reg.value, ofs)
+        for reg in gpr_reg_mgr_cls.save_around_call_regs:
+            ofs -= WORD
+            mc.MOV_rs(reg.value, ofs)
+        #
+        # ADD esp, correct_esp_by --- but cannot use ADD, because
+        # of its effects on the CPU flags
+        mc.LEA_rs(esp.value, correct_esp_by)
+        mc.RET16_i(WORD)
+        #
+        rawstart = mc.materialize(self.cpu.asmmemmgr, [])
+        self.wb_slowpath[withcards + 2 * withfloats] = rawstart
+
     @staticmethod
     @rgc.no_collect
     def _release_gil_asmgcc(css):
 
     def genop_discard_cond_call_gc_wb(self, op, arglocs):
         # Write code equivalent to write_barrier() in the GC: it checks
-        # a flag in the object at arglocs[0], and if set, it calls the
-        # function remember_young_pointer() from the GC.  The arguments
-        # to the call are in arglocs[:N].  The rest, arglocs[N:], contains
-        # registers that need to be saved and restored across the call.
-        # N is either 2 (regular write barrier) or 3 (array write barrier).
+        # a flag in the object at arglocs[0], and if set, it calls a
+        # helper piece of assembler.  The latter saves registers as needed
+        # and call the function jit_remember_young_pointer() from the GC.
         descr = op.getdescr()
         if we_are_translated():
             cls = self.cpu.gc_ll_descr.has_write_barrier_class()
             assert cls is not None and isinstance(descr, cls)
         #
         opnum = op.getopnum()
-        if opnum == rop.COND_CALL_GC_WB:
-            N = 2
-            func = descr.get_write_barrier_fn(self.cpu)
-            card_marking = False
-        elif opnum == rop.COND_CALL_GC_WB_ARRAY:
-            N = 3
-            func = descr.get_write_barrier_from_array_fn(self.cpu)
-            assert func != 0
-            card_marking = descr.jit_wb_cards_set != 0
-        else:
-            raise AssertionError(opnum)
+        card_marking = False
+        mask = descr.jit_wb_if_flag_singlebyte
+        if opnum == rop.COND_CALL_GC_WB_ARRAY and descr.jit_wb_cards_set != 0:
+            # assumptions the rest of the function depends on:
+            assert (descr.jit_wb_cards_set_byteofs ==
+                    descr.jit_wb_if_flag_byteofs)
+            assert descr.jit_wb_cards_set_singlebyte == -0x80
+            card_marking = True
+            mask = descr.jit_wb_if_flag_singlebyte | -0x80
         #
         loc_base = arglocs[0]
         self.mc.TEST8(addr_add_const(loc_base, descr.jit_wb_if_flag_byteofs),
-                      imm(descr.jit_wb_if_flag_singlebyte))
+                      imm(mask))
         self.mc.J_il8(rx86.Conditions['Z'], 0) # patched later
         jz_location = self.mc.get_relative_pos()
 
         # for cond_call_gc_wb_array, also add another fast path:
         # if GCFLAG_CARDS_SET, then we can just set one bit and be done
         if card_marking:
-            self.mc.TEST8(addr_add_const(loc_base,
-                                         descr.jit_wb_cards_set_byteofs),
-                          imm(descr.jit_wb_cards_set_singlebyte))
-            self.mc.J_il8(rx86.Conditions['NZ'], 0) # patched later
-            jnz_location = self.mc.get_relative_pos()
+            # GCFLAG_CARDS_SET is in this byte at 0x80, so this fact can
+            # been checked by the status flags of the previous TEST8
+            self.mc.J_il8(rx86.Conditions['S'], 0) # patched later
+            js_location = self.mc.get_relative_pos()
         else:
-            jnz_location = 0
+            js_location = 0
 
-        # the following is supposed to be the slow path, so whenever possible
-        # we choose the most compact encoding over the most efficient one.
-        if IS_X86_32:
-            limit = -1      # push all arglocs on the stack
-        elif IS_X86_64:
-            limit = N - 1   # push only arglocs[N:] on the stack
-        for i in range(len(arglocs)-1, limit, -1):
-            loc = arglocs[i]
-            if isinstance(loc, RegLoc):
-                self.mc.PUSH_r(loc.value)
-            else:
-                assert not IS_X86_64 # there should only be regs in arglocs[N:]
-                self.mc.PUSH_i32(loc.getint())
-        if IS_X86_64:
-            # We clobber these registers to pass the arguments, but that's
-            # okay, because consider_cond_call_gc_wb makes sure that any
-            # caller-save registers with values in them are present in
-            # arglocs[N:] too, so they are saved on the stack above and
-            # restored below.
-            if N == 2:
-                callargs = [edi, esi]
-            else:
-                callargs = [edi, esi, edx]
-            remap_frame_layout(self, arglocs[:N], callargs,
-                               X86_64_SCRATCH_REG)
+        # Write only a CALL to the helper prepared in advance, passing it as
+        # argument the address of the structure we are writing into
+        # (the first argument to COND_CALL_GC_WB).
+        helper_num = card_marking
+        if self._regalloc.xrm.reg_bindings:
+            helper_num += 2
+        if self.wb_slowpath[helper_num] == 0:    # tests only
+            assert not we_are_translated()
+            self.cpu.gc_ll_descr.write_barrier_descr = descr
+            self._build_wb_slowpath(card_marking,
+                                    bool(self._regalloc.xrm.reg_bindings))
+            assert self.wb_slowpath[helper_num] != 0
         #
-        # misaligned stack in the call, but it's ok because the write barrier
-        # is not going to call anything more.  Also, this assumes that the
-        # write barrier does not touch the xmm registers.  (Slightly delicate
-        # assumption, given that the write barrier can end up calling the
-        # platform's malloc() from AddressStack.append().  XXX may need to
-        # be done properly)
-        self.mc.CALL(imm(func))
-        if IS_X86_32:
-            self.mc.ADD_ri(esp.value, N*WORD)
-        for i in range(N, len(arglocs)):
-            loc = arglocs[i]
-            assert isinstance(loc, RegLoc)
-            self.mc.POP_r(loc.value)
+        self.mc.PUSH(loc_base)
+        self.mc.CALL(imm(self.wb_slowpath[helper_num]))
 
-        # if GCFLAG_CARDS_SET, then we can do the whole thing that would
-        # be done in the CALL above with just four instructions, so here
-        # is an inline copy of them
         if card_marking:
-            self.mc.JMP_l8(0) # jump to the exit, patched later
-            jmp_location = self.mc.get_relative_pos()
-            # patch the JNZ above
-            offset = self.mc.get_relative_pos() - jnz_location
+            # The helper ends again with a check of the flag in the object.
+            # So here, we can simply write again a 'JNS', which will be
+            # taken if GCFLAG_CARDS_SET is still not set.
+            self.mc.J_il8(rx86.Conditions['NS'], 0) # patched later
+            jns_location = self.mc.get_relative_pos()
+            #
+            # patch the JS above
+            offset = self.mc.get_relative_pos() - js_location
             assert 0 < offset <= 127
-            self.mc.overwrite(jnz_location-1, chr(offset))
+            self.mc.overwrite(js_location-1, chr(offset))
             #
+            # case GCFLAG_CARDS_SET: emit a few instructions to do
+            # directly the card flag setting
             loc_index = arglocs[1]
             if isinstance(loc_index, RegLoc):
-                # choose a scratch register
-                tmp1 = loc_index
-                self.mc.PUSH_r(tmp1.value)
+                if IS_X86_64 and isinstance(loc_base, RegLoc):
+                    # copy loc_index into r11
+                    tmp1 = X86_64_SCRATCH_REG
+                    self.mc.MOV_rr(tmp1.value, loc_index.value)
+                    final_pop = False
+                else:
+                    # must save the register loc_index before it is mutated
+                    self.mc.PUSH_r(loc_index.value)
+                    tmp1 = loc_index
+                    final_pop = True
                 # SHR tmp, card_page_shift
                 self.mc.SHR_ri(tmp1.value, descr.jit_wb_card_page_shift)
                 # XOR tmp, -8
                 # BTS [loc_base], tmp
                 self.mc.BTS(addr_add_const(loc_base, 0), tmp1)
                 # done
-                self.mc.POP_r(tmp1.value)
+                if final_pop:
+                    self.mc.POP_r(loc_index.value)
+                #
             elif isinstance(loc_index, ImmedLoc):
                 byte_index = loc_index.value >> descr.jit_wb_card_page_shift
                 byte_ofs = ~(byte_index >> 3)
                 self.mc.OR8(addr_add_const(loc_base, byte_ofs), imm(byte_val))
             else:
                 raise AssertionError("index is neither RegLoc nor ImmedLoc")
-            # patch the JMP above
-            offset = self.mc.get_relative_pos() - jmp_location
+            #
+            # patch the JNS above
+            offset = self.mc.get_relative_pos() - jns_location
             assert 0 < offset <= 127
-            self.mc.overwrite(jmp_location-1, chr(offset))
-        #
+            self.mc.overwrite(jns_location-1, chr(offset))
+
         # patch the JZ above
         offset = self.mc.get_relative_pos() - jz_location
         assert 0 < offset <= 127

File pypy/jit/backend/x86/regalloc.py

View file
         # or setarrayitem_gc. It avoids loading it twice from the memory.
         arglocs = [self.rm.make_sure_var_in_reg(op.getarg(i), args)
                    for i in range(N)]
-        # add eax, ecx and edx as extra "arguments" to ensure they are
-        # saved and restored.  Fish in self.rm to know which of these
-        # registers really need to be saved (a bit of a hack).  Moreover,
-        # we don't save and restore any SSE register because the called
-        # function, a GC write barrier, is known not to touch them.
-        # See remember_young_pointer() in rpython/memory/gc/generation.py.
-        for v, reg in self.rm.reg_bindings.items():
-            if (reg in self.rm.save_around_call_regs
-                and self.rm.stays_alive(v)):
-                arglocs.append(reg)
         self.PerformDiscard(op, arglocs)
         self.rm.possibly_free_vars_for_op(op)
 

File pypy/jit/backend/x86/rx86.py

View file
         assert rexbyte == 0
     return 0
 
+# REX prefixes: 'rex_w' generates a REX_W, forcing the instruction
+# to operate on 64-bit.  'rex_nw' doesn't, so the instruction operates
+# on 32-bit or less; the complete REX prefix is omitted if unnecessary.
+# 'rex_fw' is a special case which doesn't generate a REX_W but forces
+# the REX prefix in all cases.  It is only useful on instructions which
+# have an 8-bit register argument, to force access to the "sil" or "dil"
+# registers (as opposed to "ah-dh").
 rex_w  = encode_rex, 0, (0x40 | REX_W), None      # a REX.W prefix
 rex_nw = encode_rex, 0, 0, None                   # an optional REX prefix
 rex_fw = encode_rex, 0, 0x40, None                # a forced REX prefix
     AND8_rr = insn(rex_fw, '\x20', byte_register(1), byte_register(2,8), '\xC0')
 
     OR8_rr = insn(rex_fw, '\x08', byte_register(1), byte_register(2,8), '\xC0')
-    OR8_mi = insn(rex_fw, '\x80', orbyte(1<<3), mem_reg_plus_const(1),
+    OR8_mi = insn(rex_nw, '\x80', orbyte(1<<3), mem_reg_plus_const(1),
                   immediate(2, 'b'))
-    OR8_ji = insn(rex_fw, '\x80', orbyte(1<<3), abs_, immediate(1),
+    OR8_ji = insn(rex_nw, '\x80', orbyte(1<<3), abs_, immediate(1),
                   immediate(2, 'b'))
 
     NEG_r = insn(rex_w, '\xF7', register(1), '\xD8')
 
     PUSH_r = insn(rex_nw, register(1), '\x50')
     PUSH_b = insn(rex_nw, '\xFF', orbyte(6<<3), stack_bp(1))
+    PUSH_i8 = insn('\x6A', immediate(1, 'b'))
     PUSH_i32 = insn('\x68', immediate(1, 'i'))
+    def PUSH_i(mc, immed):
+        if single_byte(immed):
+            mc.PUSH_i8(immed)
+        else:
+            mc.PUSH_i32(immed)
 
     POP_r = insn(rex_nw, register(1), '\x58')
     POP_b = insn(rex_nw, '\x8F', orbyte(0<<3), stack_bp(1))

File pypy/jit/backend/x86/test/test_rx86.py

View file
 
 def test_push32():
     cb = CodeBuilder32
-    assert_encodes_as(cb, 'PUSH_i32', (9,), '\x68\x09\x00\x00\x00')
+    assert_encodes_as(cb, 'PUSH_i', (0x10009,), '\x68\x09\x00\x01\x00')
+    assert_encodes_as(cb, 'PUSH_i', (9,), '\x6A\x09')
 
 def test_sub_ji8():
     cb = CodeBuilder32

File pypy/module/_minimal_curses/fficurses.py

View file
 from pypy.rpython.extfunc import register_external
 from pypy.module._minimal_curses import interp_curses
 from pypy.translator.tool.cbuild import ExternalCompilationInfo
+from sys import platform
 
-eci = ExternalCompilationInfo(
-    includes = ['curses.h', 'term.h'],
-    libraries = ['curses'],
-)
+_CYGWIN = platform == 'cygwin'
+
+if _CYGWIN:
+    eci = ExternalCompilationInfo(
+        includes = ['ncurses/curses.h', 'ncurses/term.h'],
+        libraries = ['curses'],
+    )
+else:
+    eci = ExternalCompilationInfo(
+        includes = ['curses.h', 'term.h'],
+        libraries = ['curses'],
+    )
 
 rffi_platform.verify_eci(eci)
 

File pypy/module/_socket/test/test_sock_app.py

View file
         except timeout:
             pass
         t.recv(count)    
-        # test sendall() timeout, be sure to send data larger than the
-        # socket buffer
-        raises(timeout, cli.sendall, 'foobar' * 7000)
+        # test sendall() timeout
+        try:
+            while 1:
+                cli.sendall('foobar' * 70)
+        except timeout:
+            pass
         # done
         cli.close()
         t.close()

File pypy/module/micronumpy/interp_boxes.py

View file
 MIXIN_32 = (int_typedef,) if LONG_BIT == 32 else ()
 MIXIN_64 = (int_typedef,) if LONG_BIT == 64 else ()
 
+
 def new_dtype_getter(name):
     def _get_dtype(space):
         from pypy.module.micronumpy.interp_dtype import get_dtype_cache
         return getattr(get_dtype_cache(space), "w_%sdtype" % name)
+
     def new(space, w_subtype, w_value):
         dtype = _get_dtype(space)
         return dtype.itemtype.coerce_subtype(space, w_subtype, w_value)
     return func_with_new_name(new, name + "_box_new"), staticmethod(_get_dtype)
 
+
 class PrimitiveBox(object):
     _mixin_ = True
 
     def convert_to(self, dtype):
         return dtype.box(self.value)
 
+
 class W_GenericBox(Wrappable):
     _attrs_ = ()
 
     def _binop_right_impl(ufunc_name):
         def impl(self, space, w_other, w_out=None):
             from pypy.module.micronumpy import interp_ufuncs
-            return getattr(interp_ufuncs.get(space), ufunc_name).call(space, 
+            return getattr(interp_ufuncs.get(space), ufunc_name).call(space,
                                                             [w_other, self, w_out])
         return func_with_new_name(impl, "binop_right_%s_impl" % ufunc_name)
 
         w_remainder = self.descr_rmod(space, w_other)
         return space.newtuple([w_quotient, w_remainder])
 
+    def descr_hash(self, space):
+        return space.hash(self.item(space))
+
     def item(self, space):
         return self.get_dtype(space).itemtype.to_builtin_type(space, self)
 
     __abs__ = interp2app(W_GenericBox.descr_abs),
     __invert__ = interp2app(W_GenericBox.descr_invert),
 
+    __hash__ = interp2app(W_GenericBox.descr_hash),
+
     tolist = interp2app(W_GenericBox.item),
 )
 
     __module__ = "numpypy",
     __new__ = interp2app(W_UnicodeBox.descr__new__unicode_box.im_func),
 )
-                                          
+

File pypy/module/micronumpy/interp_numarray.py

View file
         return self.getitem(offset).convert_to(longdtype).item(
             space)
 
+    @jit.unroll_safe
     def descr_item(self, space, w_arg=None):
         if space.is_w(w_arg, space.w_None):
-            if not isinstance(self, Scalar):
-                raise OperationError(space.w_ValueError, space.wrap("index out of bounds"))
-            return self.value.item(space)
+            if isinstance(self, Scalar):
+                return self.value.item(space)
+            if support.product(self.shape) == 1:
+                return self.descr_getitem(space,
+                                          space.newtuple([space.wrap(0) for i
+                                                   in range(len(self.shape))]))
+            raise OperationError(space.w_ValueError,
+                                 space.wrap("index out of bounds"))
         if space.isinstance_w(w_arg, space.w_int):
             if isinstance(self, Scalar):
                 raise OperationError(space.w_ValueError, space.wrap("index out of bounds"))

File pypy/module/micronumpy/test/test_dtypes.py

View file
 
         a = array(range(10), dtype=int64)
         b = array([0] * 10, dtype=int64)
-        for idx in b: a[idx] += 1
+        for idx in b:
+            a[idx] += 1
 
-    def test_hash_int8(self):
-        from _numpypy import int8
+    def test_hash(self):
+        import _numpypy as numpy
+        for tp, value in [
+            (numpy.int8, 4),
+            (numpy.int16, 5),
+            (numpy.uint32, 7),
+            (numpy.int64, 3),
+            (numpy.float32, 2.0),
+            (numpy.float64, 4.32),
+        ]:
+            assert hash(tp(value)) == hash(value)
 
-        hash(int8(0))
-        d = {int8(5):99}
 
-    def test_hash_int16(self):
-        from _numpypy import int16
-
-        hash(int16(0))
-        d = {int16(99):42}
-
-    def test_hash_int32(self):
-        from _numpypy import int32
-
-        hash(int32(0))
-        d = {int32(5):99}
-
-    def test_hash_int64(self):
-        from _numpypy import int64
-
-        hash(int64(0))
-        d = {int64(99):42}
-
-class AppTestTypes(BaseNumpyAppTest):    
+class AppTestTypes(BaseNumpyAppTest):
     def test_abstract_types(self):
         import _numpypy as numpy
         raises(TypeError, numpy.generic, 0)
     def test_various_types(self):
         import _numpypy as numpy
         import sys
-        
+
         assert numpy.int16 is numpy.short
         assert numpy.int8 is numpy.byte
         assert numpy.bool_ is numpy.bool8
 
     def test_mro(self):
         import _numpypy as numpy
-        
+
         assert numpy.int16.__mro__ == (numpy.int16, numpy.signedinteger,
                                        numpy.integer, numpy.number,
                                        numpy.generic, object)
 class AppTestStrUnicodeDtypes(BaseNumpyAppTest):
     def test_str_unicode(self):
         from _numpypy import str_, unicode_, character, flexible, generic
-        
+
         assert str_.mro() == [str_, str, basestring, character, flexible, generic, object]
         assert unicode_.mro() == [unicode_, unicode, basestring, character, flexible, generic, object]
 
         from _numpypy import dtype
         d = dtype({'names': ['a', 'b', 'c'],
                    })
-        
+
 class AppTestNotDirect(BaseNumpyAppTest):
     def setup_class(cls):
         BaseNumpyAppTest.setup_class.im_func(cls)

File pypy/module/micronumpy/test/test_numarray.py

View file
         a = arange(3*2*6).reshape((3,2,6))
         b = arange(3*2*6)[::-1].reshape((2,6,3))
         assert dot(a, b)[2,0,1,2] == 1140
+        assert (dot([[1,2],[3,4]],[5,6]) == [17, 39]).all()
 
     def test_dot_constant(self):
         from _numpypy import array, dot
         assert a[::2].item(1) == 3
         assert (a + a).item(1) == 4
         raises(ValueError, "array(5).item(1)")
+        assert array([1]).item() == 1
 
 class AppTestSupport(BaseNumpyAppTest):
     def setup_class(cls):

File pypy/module/micronumpy/types.py

View file
 from pypy.tool.sourcetools import func_with_new_name
 from pypy.rlib import jit
 
+
 VOID_STORAGE = lltype.Array(lltype.Char, hints={'nolength': True,
                                                 'render_as_void': True})
 degToRad = math.pi / 180.0
 log2 = math.log(2)
-log2e = 1./log2
+log2e = 1. / log2
+
 
 def simple_unary_op(func):
     specialize.argtype(1)(func)
 
 class BaseType(object):
     _attrs_ = ()
-    
+
     def _unimplemented_ufunc(self, *args):
         raise NotImplementedError
 
                                  width, storage, i, offset, value)
         else:
             libffi.array_setitem_T(self.T, width, storage, i, offset, value)
-        
+
 
     def store(self, arr, width, i, offset, box):
         self._write(arr.storage, width, i, offset, self.unbox(box))
 
 class NonNativePrimitive(Primitive):
     _mixin_ = True
-    
+
     def _read(self, storage, width, i, offset):
         if we_are_translated():
             res = libffi.array_getitem(clibffi.cast_type_to_ffitype(self.T),
 
     T = rffi.LONGLONG
     BoxType = interp_boxes.W_Int64Box
-    format_code = "q"    
+    format_code = "q"
 
     _coerce = func_with_new_name(_int64_coerce, '_coerce')
 
 
     T = rffi.FLOAT
     BoxType = interp_boxes.W_Float32Box
-    format_code = "f"    
+    format_code = "f"
 
 class Float64(BaseType, Float):
     _attrs_ = ()
 
 class BaseStringType(object):
     _mixin_ = True
-    
+
     def __init__(self, size=0):
         self.size = size
 
 
     def get_element_size(self):
         return self.size
-    
+
     def read(self, arr, width, i, offset, dtype=None):
         if dtype is None:
             dtype = arr.dtype
         return interp_boxes.W_VoidBox(arr, i + offset, dtype)
 
     @jit.unroll_safe
-    def coerce(self, space, dtype, w_item): 
+    def coerce(self, space, dtype, w_item):
         from pypy.module.micronumpy.interp_numarray import W_NDimArray
 
         if isinstance(w_item, interp_boxes.W_VoidBox):

File pypy/module/rctime/interp_time.py

View file
 
 _POSIX = os.name == "posix"
 _WIN = os.name == "nt"
+_CYGWIN = sys.platform == "cygwin"
+
+_time_zones = []
+if _CYGWIN:
+    _time_zones = ["GMT-12", "GMT-11", "GMT-10", "GMT-9", "GMT-8", "GMT-7",
+                   "GMT-6", "GMT-5", "GMT-4", "GMT-3", "GMT-2", "GMT-1",
+                   "GMT",  "GMT+1", "GMT+2", "GMT+3", "GMT+4", "GMT+5",
+                   "GMT+6",  "GMT+7", "GMT+8", "GMT+9", "GMT+10", "GMT+11",
+                   "GMT+12",  "GMT+13", "GMT+14"]
 
 if _WIN:
     # Interruptible sleeps on Windows:
     CConfig.timeval = platform.Struct("struct timeval",
                                       [("tv_sec", rffi.INT),
                                        ("tv_usec", rffi.INT)])
-    CConfig.tm = platform.Struct("struct tm", [("tm_sec", rffi.INT),
-        ("tm_min", rffi.INT), ("tm_hour", rffi.INT), ("tm_mday", rffi.INT),
-        ("tm_mon", rffi.INT), ("tm_year", rffi.INT), ("tm_wday", rffi.INT),
-        ("tm_yday", rffi.INT), ("tm_isdst", rffi.INT), ("tm_gmtoff", rffi.LONG),
-        ("tm_zone", rffi.CCHARP)])
+    if _CYGWIN:
+        CConfig.tm = platform.Struct("struct tm", [("tm_sec", rffi.INT),
+            ("tm_min", rffi.INT), ("tm_hour", rffi.INT), ("tm_mday", rffi.INT),
+            ("tm_mon", rffi.INT), ("tm_year", rffi.INT), ("tm_wday", rffi.INT),
+            ("tm_yday", rffi.INT), ("tm_isdst", rffi.INT)])
+    else:
+        CConfig.tm = platform.Struct("struct tm", [("tm_sec", rffi.INT),
+            ("tm_min", rffi.INT), ("tm_hour", rffi.INT), ("tm_mday", rffi.INT),
+            ("tm_mon", rffi.INT), ("tm_year", rffi.INT), ("tm_wday", rffi.INT),
+            ("tm_yday", rffi.INT), ("tm_isdst", rffi.INT), ("tm_gmtoff", rffi.LONG),
+            ("tm_zone", rffi.CCHARP)])
 elif _WIN:
     calling_conv = 'win'
     CConfig.tm = platform.Struct("struct tm", [("tm_sec", rffi.INT),
          tzname = rffi.charp2str(tzname_ptr[0]), rffi.charp2str(tzname_ptr[1])
 
     if _POSIX:
-        YEAR = (365 * 24 + 6) * 3600
+        if _CYGWIN:
+            YEAR = (365 * 24 + 6) * 3600
 
-        t = (((c_time(lltype.nullptr(rffi.TIME_TP.TO))) / YEAR) * YEAR)
-        # we cannot have reference to stack variable, put it on the heap
-        t_ref = lltype.malloc(rffi.TIME_TP.TO, 1, flavor='raw')
-        t_ref[0] = rffi.cast(rffi.TIME_T, t)
-        p = c_localtime(t_ref)
-        janzone = -p.c_tm_gmtoff
-        tm_zone = rffi.charp2str(p.c_tm_zone)
-        janname = ["   ", tm_zone][bool(tm_zone)]
-        tt = t + YEAR / 2
-        t_ref[0] = rffi.cast(rffi.TIME_T, tt)
-        p = c_localtime(t_ref)
-        lltype.free(t_ref, flavor='raw')
-        tm_zone = rffi.charp2str(p.c_tm_zone)
-        julyzone = -p.c_tm_gmtoff
-        julyname = ["   ", tm_zone][bool(tm_zone)]
+            # about January 11th
+            t = (((c_time(lltype.nullptr(rffi.TIME_TP.TO))) / YEAR) * YEAR + 10 * 24 * 3600)
+            # we cannot have reference to stack variable, put it on the heap
+            t_ref = lltype.malloc(rffi.TIME_TP.TO, 1, flavor='raw')
+            t_ref[0] = rffi.cast(rffi.TIME_T, t)
+            p = c_localtime(t_ref)
+            q = c_gmtime(t_ref)
+            janzone = (p.c_tm_hour + 24 * p.c_tm_mday) - (q.c_tm_hour + 24 * q.c_tm_mday)
+            if janzone < -12:
+                janname = "   "
+            elif janzone > 14:
+                janname = "   "
+            else:
+                janname = _time_zones[janzone - 12]
+            janzone = janzone * 3600
+            # about July 11th
+            tt = t + YEAR / 2
+            t_ref[0] = rffi.cast(rffi.TIME_T, tt)
+            p = c_localtime(t_ref)
+            q = c_gmtime(t_ref)
+            julyzone = (p.c_tm_hour + 24 * p.c_tm_mday) - (q.c_tm_hour + 24 * q.c_tm_mday)
+            if julyzone < -12:
+                julyname = "   "
+            elif julyzone > 14:
+                julyname = "   "
+            else:
+                julyname = _time_zones[julyzone - 12]
+            julyzone = julyzone * 3600
+            lltype.free(t_ref, flavor='raw')
 
-        if janzone < julyzone:
-            # DST is reversed in the southern hemisphere
-            timezone = julyzone
-            altzone = janzone
-            daylight = int(janzone != julyzone)
-            tzname = [julyname, janname]
+            if janzone < julyzone:
+                # DST is reversed in the southern hemisphere
+                timezone = julyzone
+                altzone = janzone
+                daylight = int(janzone != julyzone)
+                tzname = [julyname, janname]
+            else:
+                timezone = janzone
+                altzone = julyzone
+                daylight = int(janzone != julyzone)
+                tzname = [janname, julyname]
+
         else:
-            timezone = janzone
-            altzone = julyzone
-            daylight = int(janzone != julyzone)
-            tzname = [janname, julyname]
+            YEAR = (365 * 24 + 6) * 3600
+
+            t = (((c_time(lltype.nullptr(rffi.TIME_TP.TO))) / YEAR) * YEAR)
+            # we cannot have reference to stack variable, put it on the heap
+            t_ref = lltype.malloc(rffi.TIME_TP.TO, 1, flavor='raw')
+            t_ref[0] = rffi.cast(rffi.TIME_T, t)
+            p = c_localtime(t_ref)
+            janzone = -p.c_tm_gmtoff
+            tm_zone = rffi.charp2str(p.c_tm_zone)
+            janname = ["   ", tm_zone][bool(tm_zone)]
+            tt = t + YEAR / 2
+            t_ref[0] = rffi.cast(rffi.TIME_T, tt)
+            p = c_localtime(t_ref)
+            lltype.free(t_ref, flavor='raw')
+            tm_zone = rffi.charp2str(p.c_tm_zone)
+            julyzone = -p.c_tm_gmtoff
+            julyname = ["   ", tm_zone][bool(tm_zone)]
+
+            if janzone < julyzone:
+                # DST is reversed in the southern hemisphere
+                timezone = julyzone
+                altzone = janzone
+                daylight = int(janzone != julyzone)
+                tzname = [julyname, janname]
+            else:
+                timezone = janzone
+                altzone = julyzone
+                daylight = int(janzone != julyzone)
+                tzname = [janname, julyname]
 
     _set_module_object(space, "timezone", space.wrap(timezone))
     _set_module_object(space, 'daylight', space.wrap(daylight))
     rffi.setintfield(glob_buf, 'c_tm_yday', tm_yday)
     rffi.setintfield(glob_buf, 'c_tm_isdst', space.int_w(tup_w[8]))
     if _POSIX:
-        # actually never happens, but makes annotator happy
-        glob_buf.c_tm_zone = lltype.nullptr(rffi.CCHARP.TO)
-        rffi.setintfield(glob_buf, 'c_tm_gmtoff', 0)
+        if _CYGWIN:
+            pass
+        else:
+            # actually never happens, but makes annotator happy
+            glob_buf.c_tm_zone = lltype.nullptr(rffi.CCHARP.TO)
+            rffi.setintfield(glob_buf, 'c_tm_gmtoff', 0)
 
     w_accept2dyear = _get_module_object(space, "accept2dyear")
     accept2dyear = space.int_w(w_accept2dyear)

File pypy/module/test_lib_pypy/ctypes_tests/test_functions.py

View file
         assert tf_b(-126) == -42
         assert tf_b._ptr is ptr
 
+    def test_custom_from_param(self):
+        class A(c_byte):
+            @classmethod
+            def from_param(cls, obj):
+                seen.append(obj)
+                return -126
+        tf_b = dll.tf_b
+        tf_b.restype = c_byte
+        tf_b.argtypes = (c_byte,)
+        tf_b.argtypes = [A]
+        seen = []
+        assert tf_b("yadda") == -42
+        assert seen == ["yadda"]
+
     def test_warnings(self):
         import warnings
         warnings.simplefilter("always")

File pypy/objspace/std/test/test_stringobject.py

View file
         assert 'abcdefghiabc'.find('def', 4) == -1
         assert 'abcdef'.find('', 13) == -1
         assert 'abcdefg'.find('def', 5, None) == -1
+        assert 'abcdef'.find('d', 6, 0) == -1
+        assert 'abcdef'.find('d', 3, 3) == -1
+        raises(TypeError, 'abcdef'.find, 'd', 1.0)
 
     def test_index(self):
         from sys import maxint

File pypy/rlib/rope.py

View file
     len2 = subnode.length()
     if stop > len1 or stop == -1:
         stop = len1
+    if stop - start < 0:
+        return -1
     if len2 == 1:
         return find_int(node, subnode.getint(0), start, stop)
     if len2 == 0:
-        if (stop - start) < 0:
-            return -1
         return start
     if len2 > stop - start:
         return -1

File pypy/rlib/rsdl/RIMG.py

-import sys
-from pypy.rpython.lltypesystem import lltype, rffi
-from pypy.rpython.tool import rffi_platform as platform
-from pypy.translator.tool.cbuild import ExternalCompilationInfo
-from pypy.rlib.rsdl import RSDL
-
-
-if sys.platform == 'darwin':
-    eci = ExternalCompilationInfo(
-        includes = ['SDL_image.h'],
-        frameworks = ['SDL_image'],
-        include_dirs = ['/Library/Frameworks/SDL_image.framework/Headers']
-    )
-else:
-    eci = ExternalCompilationInfo(
-        includes=['SDL_image.h'],
-        libraries=['SDL_image'],
-    )
-
-eci = eci.merge(RSDL.eci)
-
-def external(name, args, result):
-    return rffi.llexternal(name, args, result, compilation_info=eci)
-
-Load = external('IMG_Load', [rffi.CCHARP], RSDL.SurfacePtr)

File pypy/rlib/rsdl/RMix.py

-import sys
-from pypy.rpython.lltypesystem import lltype, rffi
-from pypy.rpython.tool import rffi_platform as platform
-from pypy.translator.tool.cbuild import ExternalCompilationInfo
-from pypy.rlib.rsdl import RSDL
-
-
-if sys.platform == 'darwin':
-    eci = ExternalCompilationInfo(
-        includes = ['SDL_mixer.h'],
-        frameworks = ['SDL_mixer'],
-        include_dirs = ['/Library/Frameworks/SDL_Mixer.framework/Headers']
-    )
-else:
-    eci = ExternalCompilationInfo(
-        includes=['SDL_mixer.h'],
-        libraries=['SDL_mixer'],
-    )
-
-eci = eci.merge(RSDL.eci)
-eci = eci.merge(eci)
-eci = eci.merge(eci)
-
-ChunkPtr             = lltype.Ptr(lltype.ForwardReference())
-
-class CConfig:
-    _compilation_info_ = eci
-
-    Chunk              = platform.Struct('Mix_Chunk', [('allocated', rffi.INT),
-                                                       ('abuf', RSDL.Uint8P),
-                                                       ('alen', RSDL.Uint32),
-                                                       ('volume', RSDL.Uint8)])
-
-globals().update(platform.configure(CConfig))
-
-ChunkPtr.TO.become(Chunk)
-
-
-Buffer = rffi.CArray(RSDL.Uint8)
-
-def external(name, args, result):
-    return rffi.llexternal(name, args, result, compilation_info=eci)
-
-OpenAudio           = external('Mix_OpenAudio',
-                               [rffi.INT, RSDL.Uint16, rffi.INT, rffi.INT],
-                               rffi.INT)
-
-CloseAudio          = external('Mix_CloseAudio', [], lltype.Void)
-
-LoadWAV_RW          = external('Mix_LoadWAV_RW',
-                               [RSDL.RWopsPtr, rffi.INT],
-                               ChunkPtr)
-
-def LoadWAV(filename_ccharp):
-    with rffi.scoped_str2charp('rb') as mode:
-        return LoadWAV_RW(RSDL.RWFromFile(filename_ccharp, mode), 1)
-
-
-PlayChannelTimed    = external('Mix_PlayChannelTimed',
-                               [rffi.INT, ChunkPtr, rffi.INT, rffi.INT],
-                               rffi.INT)
-
-def PlayChannel(channel,chunk,loops):
-    return PlayChannelTimed(channel, chunk, loops, -1)
-
-"""Returns zero if the channel is not playing. 
-Otherwise if you passed in -1, the number of channels playing is returned"""
-ChannelPlaying  = external('Mix_Playing', [rffi.INT], rffi.INT)

File pypy/rlib/rsdl/RMix_helper.py

-from pypy.rpython.lltypesystem import lltype, rffi
-from pypy.rlib.rsdl import RMix, RSDL
-from pypy.rpython.tool import rffi_platform as platform
-
-
-def malloc_buffer_chunk(has_own_allocated_buffer, length_bytes, volume):
-    buffer_pointer = lltype.malloc(RMix.Buffer, length_bytes, flavor='raw')
-    return malloc_chunk(has_own_allocated_buffer, length_bytes, volume)
-
-def malloc_chunk(has_own_allocated_buffer, buffer_pointer, length_bytes, volume):
-    """
-    Creates a new Mix_Chunk.
-    has_own_allocated_buffer:  if 1 struct has its own allocated buffer, 
-                                if 0 abuf should not be freed
-    buffer_pointer:             pointer to audio data
-    length_bytes:               length of audio data in bytes
-    volume:                     Per-sample volume, 0-128 (normally 
-                                MIX_MAX_VOLUME after loading)"""
-    p = lltype.malloc(RMix.Chunk, flavor='raw')
-    rffi.setintfield(p, 'c_allocated', has_own_allocated_buffer)
-    rffi.setintfield(p, 'c_abuf', buffer_pointer)
-    rffi.setintfield(p, 'c_alen', length_bytes)
-    rffi.setintfield(p, 'c_volume', volume)
-    return p

File pypy/rlib/rsdl/RSDL.py

-from pypy.rpython.lltypesystem import lltype, rffi
-from pypy.rpython.tool import rffi_platform as platform
-from pypy.rlib.rsdl.constants import _constants
-from pypy.rlib.rsdl.eci import get_rsdl_compilation_info
-from pypy.rlib.objectmodel import we_are_translated
-import py
-import sys
-
-# ------------------------------------------------------------------------------
-
-eci = get_rsdl_compilation_info()
-
-def external(name, args, result):
-    return rffi.llexternal(name, args, result, compilation_info=eci)
-
-# ------------------------------------------------------------------------------
-
-RectPtr             = lltype.Ptr(lltype.ForwardReference())
-SurfacePtr          = lltype.Ptr(lltype.ForwardReference())
-PixelFormatPtr      = lltype.Ptr(lltype.ForwardReference())
-EventPtr            = lltype.Ptr(lltype.ForwardReference())
-KeyboardEventPtr    = lltype.Ptr(lltype.ForwardReference())
-MouseButtonEventPtr = lltype.Ptr(lltype.ForwardReference())
-MouseMotionEventPtr = lltype.Ptr(lltype.ForwardReference())
-KeyPtr              = lltype.Ptr(lltype.ForwardReference())
-RWopsPtr            = lltype.Ptr(lltype.ForwardReference())
-
-# ------------------------------------------------------------------------------
-
-class CConfig:
-    _compilation_info_ = eci
-
-    Uint8  = platform.SimpleType('Uint8',  rffi.INT)
-    Uint16 = platform.SimpleType('Uint16', rffi.INT)
-    Sint16 = platform.SimpleType('Sint16', rffi.INT)
-    Uint32 = platform.SimpleType('Uint32', rffi.INT)
-
-    Rect             = platform.Struct('SDL_Rect', 
-                                    [('x', rffi.INT),
-                                     ('y', rffi.INT),
-                                     ('w', rffi.INT),
-                                     ('h', rffi.INT)])
-    
-    Surface          = platform.Struct('SDL_Surface', 
-                                    [('w', rffi.INT),
-                                     ('h', rffi.INT),
-                                     ('format', PixelFormatPtr),
-                                     ('pitch', rffi.INT),
-                                     ('pixels', rffi.UCHARP)])
-    
-    PixelFormat      = platform.Struct('SDL_PixelFormat',
-                                    [('BitsPerPixel', rffi.INT),
-                                     ('BytesPerPixel', rffi.INT),
-                                     ('Rmask', rffi.INT),
-                                     ('Gmask', rffi.INT),
-                                     ('Bmask', rffi.INT),
-                                     ('Amask', rffi.INT)])
-
-    Event            = platform.Struct('SDL_Event',
-                                    [('type', rffi.INT)])
-    
-    keysym           = platform.Struct('SDL_keysym', 
-                                    [('scancode', rffi.INT),
-                                     ('sym', rffi.INT),
-                                     ('mod', rffi.INT),
-                                     ('unicode', rffi.INT)])
-    
-    KeyboardEvent    = platform.Struct('SDL_KeyboardEvent',
-                                    [('type', rffi.INT),
-                                     ('state', rffi.INT),
-                                     ('keysym', keysym)])
-    
-    MouseButtonEvent = platform.Struct('SDL_MouseButtonEvent',
-                                    [('type', rffi.INT),
-                                     ('button', rffi.INT),
-                                     ('state', rffi.INT),
-                                     ('x', rffi.INT),
-                                     ('y', rffi.INT)])
-    
-    MouseMotionEvent = platform.Struct('SDL_MouseMotionEvent',
-                                    [('type', rffi.INT),
-                                     ('state', rffi.INT),
-                                     ('x', rffi.INT),
-                                     ('y', rffi.INT),
-                                     ('xrel', rffi.INT),
-                                     ('yrel', rffi.INT)])
-    
-    QuitEvent        = platform.Struct('SDL_QuitEvent',
-                                    [('type', rffi.INT)])
-    
-    RWops = platform.Struct('SDL_RWops', [])
-
-# ------------------------------------------------------------------------------
-
-for _prefix, _list in _constants.items():
-    for _name in _list:
-        setattr(CConfig, _name, platform.ConstantInteger(_prefix+_name))
-
-# ------------------------------------------------------------------------------
-
-globals().update(platform.configure(CConfig))
-
-# ------------------------------------------------------------------------------
-
-RectPtr.TO.become(Rect)
-SurfacePtr.TO.become(Surface)
-PixelFormatPtr.TO.become(PixelFormat)
-EventPtr.TO.become(Event)
-KeyboardEventPtr.TO.become(KeyboardEvent)
-MouseButtonEventPtr.TO.become(MouseButtonEvent)
-MouseMotionEventPtr.TO.become(MouseMotionEvent)
-RWopsPtr.TO.become(RWops)
-
-# ------------------------------------------------------------------------------
-
-Uint8P  = lltype.Ptr(lltype.Array(Uint8, hints={'nolength': True}))
-Uint16P = lltype.Ptr(lltype.Array(Uint16, hints={'nolength': True}))
-# need to add signed hint here
-Sint16P = lltype.Ptr(lltype.Array(Sint16, hints={'nolength': True}))
-Uint32P = lltype.Ptr(lltype.Array(Uint32, hints={'nolength': True}))
-
-
-# ------------------------------------------------------------------------------
-
-_Init            = external('SDL_Init', 
-                             [Uint32], 
-                             rffi.INT)
-                                  
-Mac_Init        = external('SDL_Init', 
-                             [Uint32], 
-                             rffi.INT)
-
-Quit             = external('SDL_Quit', [], 
-                            lltype.Void)
-
-SetVideoMode     = external('SDL_SetVideoMode', 
-                             [rffi.INT, rffi.INT, rffi.INT, Uint32],
-                             SurfacePtr)
-
-WM_SetCaption    = external('SDL_WM_SetCaption', 
-                             [rffi.CCHARP, rffi.CCHARP],
-                             lltype.Void)
-
-EnableUNICODE    = external('SDL_EnableUNICODE', 
-                             [rffi.INT], 
-                             rffi.INT)
-
-WaitEvent        = external('SDL_WaitEvent', 
-                             [EventPtr], 
-                             rffi.INT)
-
-PollEvent        = external('SDL_PollEvent',
-                             [EventPtr], 
-                             rffi.INT)
-
-Flip             = external('SDL_Flip', 
-                             [SurfacePtr], 
-                             rffi.INT)
-
-CreateRGBSurface = external('SDL_CreateRGBSurface', 
-                             [Uint32, rffi.INT, rffi.INT, rffi.INT,
-                              Uint32, Uint32, Uint32, Uint32],
-                             SurfacePtr)
-
-LockSurface      = external('SDL_LockSurface', 
-                             [SurfacePtr], 
-                             rffi.INT)
-
-UnlockSurface    = external('SDL_UnlockSurface', 
-                             [SurfacePtr],
-                             lltype.Void)
-
-FreeSurface      = external('SDL_FreeSurface', 
-                             [SurfacePtr],
-                             lltype.Void)
-
-MapRGB           = external('SDL_MapRGB', 
-                             [PixelFormatPtr, Uint8, Uint8,  Uint8], 
-                             Uint32)
-
-GetRGB           = external('SDL_GetRGB',
-                             [Uint32, PixelFormatPtr, Uint8P, Uint8P, Uint8P], 
-                             lltype.Void)
-
-GetRGBA          = external('SDL_GetRGBA', 
-                             [Uint32, PixelFormatPtr, Uint8P, Uint8P, 
-                             Uint8P, Uint8P], 
-                             lltype.Void)
-
-FillRect         = external('SDL_FillRect', 
-                             [SurfacePtr, RectPtr, Uint32], 
-                             rffi.INT)
-
-BlitSurface      = external('SDL_UpperBlit', 
-                             [SurfacePtr, RectPtr, SurfacePtr,  RectPtr], 
-                             rffi.INT)
-
-SetAlpha         = external('SDL_SetAlpha', 
-                             [SurfacePtr, Uint32, Uint8], 
-                             rffi.INT)
-
-SetColorKey      = external('SDL_SetColorKey',
-                            [SurfacePtr, Uint32, Uint32],
-                            rffi.INT)
-
-ShowCursor       = external('SDL_ShowCursor',
-                            [rffi.INT],
-                            rffi.INT)
-
-GetTicks         = external('SDL_GetTicks',
-                            [],
-                            Uint32)
-
-Delay            = external('SDL_Delay',
-                            [Uint32],
-                            lltype.Void)
-
-UpdateRect       = external('SDL_UpdateRect',
-                            [SurfacePtr, rffi.INT, rffi.INT, rffi.INT],
-                            lltype.Void)
-
-GetKeyName       = external('SDL_GetKeyName',
-                            [rffi.INT], 
-                            rffi.CCHARP)
-
-GetError         = external('SDL_GetError',
-                            [],
-                            rffi.CCHARP)
-
-RWFromFile       = external('SDL_RWFromFile',
-                            [rffi.CCHARP, rffi.CCHARP],
-                            RWopsPtr)
-
-# ------------------------------------------------------------------------------
-
-
-if sys.platform == 'darwin':
-    def Init(flags):
-        if not we_are_translated():
-            from AppKit import NSApplication
-            NSApplication.sharedApplication()
-        #CustomApplicationMain(0, " ")
-        return _Init(flags)
-        #Mac_Init()
-else:
-    Init = _Init
-    
-    
-    

File pypy/rlib/rsdl/RSDL_helper.py

-from pypy.rpython.lltypesystem import lltype, rffi
-from pypy.rlib.rsdl import RSDL
-
-def get_rgb(color, format):
-    rgb = lltype.malloc(rffi.CArray(RSDL.Uint8), 3, flavor='raw')
-    try:
-        RSDL.GetRGB(color,
-                    format,
-                    rffi.ptradd(rgb, 0),
-                    rffi.ptradd(rgb, 1),
-                    rffi.ptradd(rgb, 2))
-        r = rffi.cast(lltype.Signed, rgb[0])
-        g = rffi.cast(lltype.Signed, rgb[1])
-        b = rffi.cast(lltype.Signed, rgb[2])
-        result = r, g, b
-    finally:
-        lltype.free(rgb, flavor='raw')
-
-    return result
-
-def get_rgba(color, format):
-    rgb = lltype.malloc(rffi.CArray(RSDL.Uint8), 4, flavor='raw')
-    try:
-        RSDL.GetRGBA(color,
-                    format,
-                    rffi.ptradd(rgb, 0),
-                    rffi.ptradd(rgb, 1),
-                    rffi.ptradd(rgb, 2),
-                    rffi.ptradd(rgb, 3))
-        r = rffi.cast(lltype.Signed, rgb[0])
-        g = rffi.cast(lltype.Signed, rgb[1])
-        b = rffi.cast(lltype.Signed, rgb[2])
-        a = rffi.cast(lltype.Signed, rgb[3])
-        result = r, g, b, a
-    finally:
-        lltype.free(rgb, flavor='raw')
-
-    return result
-
-def get_pixel(image, x, y):
-    """Return the pixel value at (x, y)
-    NOTE: The surface must be locked before calling this!
-    """
-    bpp = rffi.getintfield(image.c_format, 'c_BytesPerPixel')
-    pitch = rffi.getintfield(image, 'c_pitch')
-    # Here p is the address to the pixel we want to retrieve
-    p = rffi.ptradd(image.c_pixels, y * pitch + x * bpp)
-    if bpp == 1:
-        return rffi.cast(RSDL.Uint32, p[0])
-    elif bpp == 2:
-        p = rffi.cast(RSDL.Uint16P, p)
-        return rffi.cast(RSDL.Uint32, p[0])
-    elif bpp == 3:
-        p0 = rffi.cast(lltype.Signed, p[0])
-        p1 = rffi.cast(lltype.Signed, p[1])
-        p2 = rffi.cast(lltype.Signed, p[2])
-        if RSDL.BYTEORDER == RSDL.BIG_ENDIAN:
-            result = p0 << 16 | p1 << 8 | p2
-        else:
-            result = p0 | p1 << 8 | p2 << 16
-        return rffi.cast(RSDL.Uint32, result)
-    elif bpp == 4:
-        p = rffi.cast(RSDL.Uint32P, p)
-        return p[0]
-    else:
-        raise ValueError("bad BytesPerPixel")
-
-def set_pixel(image, x, y, pixel):
-    """Return the pixel value at (x, y)
-    NOTE: The surface must be locked before calling this!
-    """
-    bpp = rffi.getintfield(image.c_format, 'c_BytesPerPixel')
-    pitch = rffi.getintfield(image, 'c_pitch')
-    # Here p is the address to the pixel we want to retrieve
-    p = rffi.ptradd(image.c_pixels, y * pitch + x * bpp)
-    if bpp == 1:
-        p[0] = rffi.cast(rffi.UCHAR,pixel)
-    elif bpp == 2:
-        p = rffi.cast(RSDL.Uint16P, p)
-        p[0] = rffi.cast(RSDL.Uint16,pixel) 
-    elif bpp == 3:
-        if RSDL.BYTEORDER == RSDL.BIG_ENDIAN:
-            p[0] = rffi.cast(rffi.UCHAR,(pixel >> 16) & 0xFF)
-            p[1] = rffi.cast(rffi.UCHAR,(pixel >> 8 ) & 0xFF)
-            p[2] = rffi.cast(rffi.UCHAR,pixel & 0xFF)
-        else:
-            p[0] = rffi.cast(rffi.UCHAR,pixel & 0xFF)
-            p[1] = rffi.cast(rffi.UCHAR,(pixel >> 8 ) & 0xFF)
-            p[2] = rffi.cast(rffi.UCHAR,(pixel >> 16) & 0xFF)
-    elif bpp == 4:
-        p = rffi.cast(RSDL.Uint32P, p)
-        p[0] = rffi.cast(RSDL.Uint32, pixel)
-    else:
-        raise ValueError("bad BytesPerPixel")
-
-def mallocrect(x, y, w, h):
-    p = lltype.malloc(RSDL.Rect, flavor='raw')
-    rffi.setintfield(p, 'c_x', x)
-    rffi.setintfield(p, 'c_y', y)
-    rffi.setintfield(p, 'c_w', w)
-    rffi.setintfield(p, 'c_h', h)
-    return p
-
-def blit_complete_surface(src, dst, x, y):
-    dstrect = mallocrect(x, y, rffi.getintfield(src, 'c_w'), rffi.getintfield(src, 'c_w'))
-    RSDL.BlitSurface(src, lltype.nullptr(RSDL.Rect), dst, dstrect)
-    lltype.free(dstrect, flavor='raw')
-

File pypy/rlib/rsdl/__init__.py

Empty file removed.

File pypy/rlib/rsdl/constants.py

-
-_constants = {
-    'SDL_': [      # constants with the 'SDL_' prefix in C
-        "YV12_OVERLAY",
-        "IYUV_OVERLAY",
-        "YUY2_OVERLAY",
-        "UYVY_OVERLAY",
-        "YVYU_OVERLAY",
-
-        "SWSURFACE",
-        "HWSURFACE",
-        "RESIZABLE",
-        "ASYNCBLIT",
-        "OPENGL",
-        "OPENGLBLIT",
-        "ANYFORMAT",
-        "HWPALETTE",
-        "DOUBLEBUF",
-        "FULLSCREEN",
-        "HWACCEL",
-        "SRCCOLORKEY",
-        "RLEACCELOK",
-        "RLEACCEL",
-        "SRCALPHA",
-        "PREALLOC",
-        "NOFRAME",
-
-        "GL_RED_SIZE",
-        "GL_GREEN_SIZE",
-        "GL_BLUE_SIZE",
-        "GL_ALPHA_SIZE",
-        "GL_BUFFER_SIZE",
-        "GL_DOUBLEBUFFER",
-        "GL_DEPTH_SIZE",
-        "GL_STENCIL_SIZE",
-        "GL_ACCUM_RED_SIZE",
-        "GL_ACCUM_GREEN_SIZE",
-        "GL_ACCUM_BLUE_SIZE",
-        "GL_ACCUM_ALPHA_SIZE",
-        "GL_STEREO",              #if SDL_VERSION_ATLEAST(1, 2, 5)
-        "GL_MULTISAMPLEBUFFERS",  #if SDL_VERSION_ATLEAST(1, 2, 6)
-        "GL_MULTISAMPLESAMPLES",  #if SDL_VERSION_ATLEAST(1, 2, 6)
-
-        "NOEVENT",
-        "ACTIVEEVENT",
-        "KEYDOWN",
-        "KEYUP",
-        "MOUSEMOTION",
-        "MOUSEBUTTONDOWN",
-        "MOUSEBUTTONUP",
-        "BUTTON_LEFT",
-        "BUTTON_MIDDLE", 
-        "BUTTON_RIGHT",
-        "BUTTON_WHEELUP", 
-        "BUTTON_WHEELDOWN", 
-        "JOYAXISMOTION",
-        "JOYBALLMOTION",
-        "JOYHATMOTION",
-        "JOYBUTTONDOWN",
-        "JOYBUTTONUP",
-        "VIDEORESIZE",
-        "VIDEOEXPOSE",
-        "QUIT",
-        "SYSWMEVENT",
-        "USEREVENT",
-        "NUMEVENTS",
-
-        "HAT_CENTERED",
-        "HAT_UP",
-        "HAT_RIGHTUP",
-        "HAT_RIGHT",
-        "HAT_RIGHTDOWN",
-        "HAT_DOWN",
-        "HAT_LEFTDOWN",
-        "HAT_LEFT",
-        "HAT_LEFTUP",
-        
-        "DISABLE",
-        "ENABLE",
-
-        # the following ones are not exposed in Pygame
-        "INIT_VIDEO",
-        "BYTEORDER",
-        "BIG_ENDIAN",
-        "LIL_ENDIAN",
-        ],
-
-    '': [      # constants with no prefix in C
-        "TIMER_RESOLUTION",
-        "AUDIO_U8",
-        "AUDIO_S8",
-        "AUDIO_U16LSB",
-        "AUDIO_S16LSB",
-        "AUDIO_U16MSB",
-        "AUDIO_S16MSB",
-        "AUDIO_U16",
-        "AUDIO_S16",
-        "AUDIO_U16SYS",
-        "AUDIO_S16SYS",
-
-        "KMOD_NONE",
-        "KMOD_LSHIFT",
-        "KMOD_RSHIFT",
-        "KMOD_LCTRL",
-        "KMOD_RCTRL",
-        "KMOD_LALT",
-        "KMOD_RALT",
-        "KMOD_LMETA",
-        "KMOD_RMETA",
-        "KMOD_NUM",
-        "KMOD_CAPS",
-        "KMOD_MODE",
-
-        "KMOD_CTRL",
-        "KMOD_SHIFT",
-        "KMOD_ALT",
-        "KMOD_META",
-        ],
-
-    'SDL': [      # constants with the 'SDL' prefix in C
-        "K_UNKNOWN",
-        "K_FIRST",
-        "K_BACKSPACE",
-        "K_TAB",
-        "K_CLEAR",
-        "K_RETURN",
-        "K_PAUSE",
-        "K_ESCAPE",
-        "K_SPACE",
-        "K_EXCLAIM",
-        "K_QUOTEDBL",
-        "K_HASH",
-        "K_DOLLAR",
-        "K_AMPERSAND",
-        "K_QUOTE",
-        "K_LEFTPAREN",
-        "K_RIGHTPAREN",
-        "K_ASTERISK",
-        "K_PLUS",
-        "K_COMMA",
-        "K_MINUS",
-        "K_PERIOD",
-        "K_SLASH",
-        "K_0",
-        "K_1",
-        "K_2",
-        "K_3",
-        "K_4",
-        "K_5",
-        "K_6",
-        "K_7",
-        "K_8",
-        "K_9",
-        "K_COLON",
-        "K_SEMICOLON",
-        "K_LESS",
-        "K_EQUALS",
-        "K_GREATER",
-        "K_QUESTION",
-        "K_AT",
-        "K_LEFTBRACKET",
-        "K_BACKSLASH",
-        "K_RIGHTBRACKET",
-        "K_CARET",
-        "K_UNDERSCORE",
-        "K_BACKQUOTE",
-        "K_a",
-        "K_b",
-        "K_c",
-        "K_d",
-        "K_e",
-        "K_f",
-        "K_g",
-        "K_h",
-        "K_i",
-        "K_j",
-        "K_k",
-        "K_l",
-        "K_m",
-        "K_n",
-        "K_o",
-        "K_p",
-        "K_q",
-        "K_r",
-        "K_s",
-        "K_t",
-        "K_u",
-        "K_v",
-        "K_w",
-        "K_x",
-        "K_y",
-        "K_z",
-        "K_DELETE",
-
-        "K_KP0",
-        "K_KP1",
-        "K_KP2",
-        "K_KP3",
-        "K_KP4",
-        "K_KP5",
-        "K_KP6",
-        "K_KP7",
-        "K_KP8",
-        "K_KP9",
-        "K_KP_PERIOD",
-        "K_KP_DIVIDE",
-        "K_KP_MULTIPLY",
-        "K_KP_MINUS",
-        "K_KP_PLUS",
-        "K_KP_ENTER",
-        "K_KP_EQUALS",
-        "K_UP",
-        "K_DOWN",
-        "K_RIGHT",
-        "K_LEFT",
-        "K_INSERT",
-        "K_HOME",
-        "K_END",
-        "K_PAGEUP",
-        "K_PAGEDOWN",
-        "K_F1",
-        "K_F2",
-        "K_F3",
-        "K_F4",
-        "K_F5",
-        "K_F6",
-        "K_F7",
-        "K_F8",
-        "K_F9",
-        "K_F10",
-        "K_F11",
-        "K_F12",
-        "K_F13",
-        "K_F14",
-        "K_F15",
-
-        "K_NUMLOCK",
-        "K_CAPSLOCK",