• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python libffi.CDLL类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pypy.rlib.libffi.CDLL的典型用法代码示例。如果您正苦于以下问题:Python CDLL类的具体用法?Python CDLL怎么用?Python CDLL使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了CDLL类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_convert_pointer_args

    def test_convert_pointer_args(self):
        """
            extern int dummy; // defined in test_void_result 
            DLLEXPORT int* get_dummy_ptr(); // defined in test_pointer_args
            DLLEXPORT void set_val_to_ptr(int* ptr, int val); // ditto
        """
        from _ffi import CDLL, types

        class MyPointerWrapper(object):
            def __init__(self, value):
                self.value = value
            def _as_ffi_pointer_(self, ffitype):
                assert ffitype is types.void_p
                return self.value
        
        libfoo = CDLL(self.libfoo_name)
        get_dummy = libfoo.getfunc('get_dummy', [], types.sint)
        get_dummy_ptr = libfoo.getfunc('get_dummy_ptr', [], types.void_p)
        set_val_to_ptr = libfoo.getfunc('set_val_to_ptr',
                                        [types.void_p, types.sint],
                                        types.void)
        assert get_dummy() == 0
        ptr = get_dummy_ptr()
        assert type(ptr) in (int, long)
        ptr2 = MyPointerWrapper(ptr)
        set_val_to_ptr(ptr2, 123)
        assert get_dummy() == 123
        set_val_to_ptr(ptr2, 0)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:28,代码来源:test_funcptr.py


示例2: test_convert_unicode_to_unichar_p

 def test_convert_unicode_to_unichar_p(self):
     """
         #include <wchar.h>
         DLLEXPORT
         long mystrlen_u(wchar_t* s)
         {
             long len = 0;
             while(*s++)
                 len++;
             return len;
         }
     """
     from _ffi import CDLL, types
     import _rawffi
     libfoo = CDLL(self.libfoo_name)
     mystrlen = libfoo.getfunc('mystrlen_u', [types.unichar_p], types.slong)
     #
     # first, try automatic conversion from strings and unicode
     assert mystrlen('foobar') == 6
     assert mystrlen(u'foobar') == 6
     assert mystrlen(u'ab\u2070') == 3
     # then, try to pass an explicit pointer
     UniCharArray = _rawffi.Array('u')
     mystr = UniCharArray(7, u'foobar')
     assert mystrlen(mystr.buffer) == 6
     mystr.free()
     mystrlen.free_temp_buffers()
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:27,代码来源:test_funcptr.py


示例3: test_func_fromaddr

 def test_func_fromaddr(self):
     from _ffi import CDLL, types, FuncPtr
     libm = CDLL(self.libm_name)
     pow_addr = libm.getaddressindll('pow')
     pow = FuncPtr.fromaddr(pow_addr, 'pow', [types.double, types.double],
                            types.double)
     assert pow(2, 3) == 8
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:7,代码来源:test_funcptr.py


示例4: before

 def before(n, x):
     libc = CDLL(libc_name)
     c_strchr = libc.getpointer('strchr', [types.pointer, types.sint],
                                types.pointer)
     glob.c_strchr = c_strchr
     return (n, None, None, None, None, None,
             None, None, None, None, None, None)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:7,代码来源:test_zrpy_releasegil.py


示例5: test_libload_None

 def test_libload_None(self):
     if self.iswin32:
         skip("unix specific")
     from _ffi import CDLL, types
     # this should return *all* loaded libs, dlopen(NULL)
     dll = CDLL(None)
     # Assume CPython, or PyPy compiled with cpyext
     res = dll.getfunc('Py_IsInitialized', [], types.slong)()
     assert res == 1
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:9,代码来源:test_funcptr.py


示例6: test_getaddressindll

 def test_getaddressindll(self):
     import sys
     from _ffi import CDLL
     libm = CDLL(self.libm_name)
     pow_addr = libm.getaddressindll('pow')
     fff = sys.maxint*2-1
     if sys.platform == 'win32':
         fff = sys.maxint*2+1
     assert pow_addr == self.pow_addr & fff
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:9,代码来源:test_funcptr.py


示例7: test_calling_convention3

 def test_calling_convention3(self):
     if not self.iswin32:
         skip("windows specific")
     from _ffi import CDLL, types
     wrong_kernel = CDLL('Kernel32.dll')
     wrong_sleep = wrong_kernel.getfunc('Sleep', [types.uint], types.void)
     try:
         wrong_sleep(10)
     except ValueError, e:
         assert e.message.startswith('Procedure called with')
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:10,代码来源:test_funcptr.py


示例8: test_huge_pointer_args

 def test_huge_pointer_args(self):
     """
         #include <stdlib.h>
         DLLEXPORT long is_null_ptr(void* ptr) { return ptr == NULL; }
     """
     import sys
     from _ffi import CDLL, types
     libfoo = CDLL(self.libfoo_name)
     is_null_ptr = libfoo.getfunc('is_null_ptr', [types.void_p], types.ulong)
     assert not is_null_ptr(sys.maxint+1)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:10,代码来源:test_funcptr.py


示例9: test_int_args

 def test_int_args(self):
     """
         DLLEXPORT int sum_xy(int x, int y)
         {
             return x+y;
         }
     """
     from _ffi import CDLL, types
     libfoo = CDLL(self.libfoo_name)
     sum_xy = libfoo.getfunc('sum_xy', [types.sint, types.sint], types.sint)
     assert sum_xy(30, 12) == 42
开发者ID:ieure,项目名称:pypy,代码行数:11,代码来源:test__ffi.py


示例10: test_char_args

 def test_char_args(self):
     """
         DLLEXPORT char my_toupper(char x)
         {
             return x - ('a'-'A');
         }
     """
     from _ffi import CDLL, types
     libfoo = CDLL(self.libfoo_name)
     my_toupper = libfoo.getfunc('my_toupper', [types.char],
                                 types.char)
     assert my_toupper('c') == 'C'
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:12,代码来源:test_funcptr.py


示例11: setup_class

 def setup_class(cls):
     space = gettestobjspace(usemodules=('_ffi', '_rawffi'))
     cls.space = space
     cls.w_iswin32 = space.wrap(sys.platform == 'win32')
     cls.w_libfoo_name = space.wrap(cls.prepare_c_example())
     cls.w_libc_name = space.wrap(get_libc_name())
     libm_name = get_libm_name(sys.platform)
     cls.w_libm_name = space.wrap(libm_name)
     libm = CDLL(libm_name)
     pow = libm.getpointer('pow', [], types.void)
     pow_addr = rffi.cast(rffi.LONG, pow.funcsym)
     cls.w_pow_addr = space.wrap(pow_addr)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:12,代码来源:test_funcptr.py


示例12: libffi_stuff

 def libffi_stuff(i, j):
     lib = CDLL(libm_name)
     func = lib.getpointer('fabs', [types.double], types.double)
     res = 0.0
     x = float(j)
     while i > 0:
         jitdriver2.jit_merge_point(i=i, res=res, func=func, x=x)
         promote(func)
         argchain = ArgChain()
         argchain.arg(x)
         res = func.call(argchain, rffi.DOUBLE)
         i -= 1
     return res
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:13,代码来源:test_ztranslation.py


示例13: test_unsigned_short_args

 def test_unsigned_short_args(self):
     """
         DLLEXPORT unsigned short sum_xy_us(unsigned short x, unsigned short y)
         {
             return x+y;
         }
     """
     from _ffi import CDLL, types
     libfoo = CDLL(self.libfoo_name)
     sum_xy = libfoo.getfunc('sum_xy_us', [types.ushort, types.ushort],
                             types.ushort)
     assert sum_xy(32000, 8000) == 40000
     assert sum_xy(60000, 30000) == 90000 % 65536
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:13,代码来源:test_funcptr.py


示例14: test_func_fromaddr2

 def test_func_fromaddr2(self):
     if not self.iswin32:
         skip("windows specific")
     from _ffi import CDLL, types, FuncPtr
     from _rawffi import FUNCFLAG_STDCALL
     libm = CDLL(self.libm_name)
     pow_addr = libm.getaddressindll('pow')
     wrong_pow = FuncPtr.fromaddr(pow_addr, 'pow', 
             [types.double, types.double], types.double, FUNCFLAG_STDCALL)
     try:
         wrong_pow(2, 3) == 8
     except ValueError, e:
         assert e.message.startswith('Procedure called with')
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:13,代码来源:test_funcptr.py


示例15: test_signed_byte_args

 def test_signed_byte_args(self):
     """
         DLLEXPORT signed char sum_xy_sb(signed char x, signed char y)
         {
             return x+y;
         }
     """
     from _ffi import CDLL, types
     libfoo = CDLL(self.libfoo_name)
     sum_xy = libfoo.getfunc('sum_xy_sb', [types.sbyte, types.sbyte],
                             types.sbyte)
     assert sum_xy(10, 20) == 30
     assert sum_xy(100, 28) == -128
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:13,代码来源:test_funcptr.py


示例16: test_single_float_args

 def test_single_float_args(self):
     """
         DLLEXPORT float sum_xy_float(float x, float y)
         {
             return x+y;
         }
     """
     from _ffi import CDLL, types
     libfoo = CDLL(self.libfoo_name)
     sum_xy = libfoo.getfunc('sum_xy_float', [types.float, types.float],
                             types.float)
     res = sum_xy(12.34, 56.78)
     assert res == self.f_12_34_plus_56_78
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:13,代码来源:test_funcptr.py


示例17: test_unsigned_byte_args

 def test_unsigned_byte_args(self):
     """
         DLLEXPORT unsigned char sum_xy_ub(unsigned char x, unsigned char y)
         {
             return x+y;
         }
     """
     from _ffi import CDLL, types
     libfoo = CDLL(self.libfoo_name)
     sum_xy = libfoo.getfunc('sum_xy_us', [types.ubyte, types.ubyte],
                             types.ubyte)
     assert sum_xy(100, 40) == 140
     assert sum_xy(200, 60) == 260 % 256
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:13,代码来源:test_funcptr.py


示例18: test_by_ordinal

 def test_by_ordinal(self):
     """
         int DLLEXPORT AAA_first_ordinal_function()
         {
             return 42;
         }
     """
     if not self.iswin32:
         skip("windows specific")
     from _ffi import CDLL, types
     libfoo = CDLL(self.libfoo_name)
     f_name = libfoo.getfunc('AAA_first_ordinal_function', [], types.sint)
     f_ordinal = libfoo.getfunc(1, [], types.sint)
     assert f_name.getaddr() == f_ordinal.getaddr()
开发者ID:MichaelBlume,项目名称:pypy,代码行数:14,代码来源:test_funcptr.py


示例19: test_unsigned_long_args

 def test_unsigned_long_args(self):
     """
         DLLEXPORT unsigned long sum_xy_ul(unsigned long x, unsigned long y)
         {
             return x+y;
         }
     """
     import sys
     from _ffi import CDLL, types
     libfoo = CDLL(self.libfoo_name)
     sum_xy = libfoo.getfunc('sum_xy_ul', [types.ulong, types.ulong],
                             types.ulong)
     assert sum_xy(sys.maxint, 12) == sys.maxint+12
     assert sum_xy(sys.maxint+1, 12) == sys.maxint+13
开发者ID:ieure,项目名称:pypy,代码行数:14,代码来源:test__ffi.py


示例20: test_void_result

 def test_void_result(self):
     """
         int dummy = 0;
         DLLEXPORT void set_dummy(int val) { dummy = val; }
         DLLEXPORT int get_dummy() { return dummy; }
     """
     from _ffi import CDLL, types
     libfoo = CDLL(self.libfoo_name)
     set_dummy = libfoo.getfunc('set_dummy', [types.sint], types.void)
     get_dummy = libfoo.getfunc('get_dummy', [], types.sint)
     assert get_dummy() == 0
     assert set_dummy(42) is None
     assert get_dummy() == 42
     set_dummy(0)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:14,代码来源:test_funcptr.py



注:本文中的pypy.rlib.libffi.CDLL类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python objectmodel.compute_hash函数代码示例发布时间:2022-05-27
下一篇:
Python jit.we_are_jitted函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap