示例#1
0
 def test_calling_convention2(self):
     if not self.iswin32:
         skip("windows specific")
     from _rawffi.alt import WinDLL, types
     kernel = WinDLL('Kernel32.dll')
     sleep = kernel.getfunc('Sleep', [types.uint], types.void)
     sleep(10)
示例#2
0
        def main(libc_name, n):
            import time
            import os
            from threading import Thread
            #
            if os.name == 'nt':
                from _rawffi.alt import WinDLL, types
                libc = WinDLL('Kernel32.dll')
                sleep = libc.getfunc('Sleep', [types.uint], types.uint)
                delays = [0] * n + [1000]
            else:
                from _rawffi.alt import CDLL, types
                libc = CDLL(libc_name)
                sleep = libc.getfunc('sleep', [types.uint], types.uint)
                delays = [0] * n + [1]
            #
            def loop_of_sleeps(i, delays):
                for delay in delays:
                    sleep(delay)  # ID: sleep

            #
            threads = [
                Thread(target=loop_of_sleeps, args=[i, delays])
                for i in range(5)
            ]
            start = time.time()
            for i, thread in enumerate(threads):
                thread.start()
            for thread in threads:
                thread.join()
            end = time.time()
            return end - start
示例#3
0
 def test_windll_as_integer(self):
     if not self.iswin32:
         skip("windows specific")
     import _rawffi
     from _rawffi.alt import WinDLL
     libm = WinDLL(self.libm_name)
     A = _rawffi.Array('i')
     a = A(1, autofree=True)
     a[0] = libm  # should cast libm to int/long automatically
示例#4
0
 def test_func_fromaddr3(self):
     if not self.iswin32:
         skip("windows specific")
     from _rawffi.alt import WinDLL, types, FuncPtr
     from _rawffi import FUNCFLAG_STDCALL
     kernel = WinDLL('Kernel32.dll')
     sleep_addr = kernel.getaddressindll('Sleep')
     sleep = FuncPtr.fromaddr(sleep_addr, 'sleep', [types.uint], types.void,
                              FUNCFLAG_STDCALL)
     sleep(10)
示例#5
0
 def test_calling_convention1(self):
     if not self.iswin32:
         skip("windows specific")
     from _rawffi.alt import WinDLL, types
     libm = WinDLL(self.libm_name)
     pow = libm.getfunc('pow', [types.double, types.double], types.double)
     try:
         pow(2, 3)
     except ValueError, e:
         assert e.message.startswith('Procedure called with')
示例#6
0
 def test_calling_convention1(self):
     # win64 doesn't have __stdcall
     if not self.iswin32 or self.iswin64:
         skip("windows 32-bit specific")
     from _rawffi.alt import WinDLL, types
     libm = WinDLL(self.libm_name)
     pow = libm.getfunc('pow', [types.double, types.double], types.double)
     try:
         pow(2, 3)
     except ValueError as e:
         assert e.message.startswith('Procedure called with')
     else:
         assert 0, 'test must assert, wrong calling convention'