当前位置: 首页>>代码示例>>Python>>正文


Python CDLL.getfunc方法代码示例

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


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

示例1: test_convert_pointer_args

# 需要导入模块: from pypy.rlib.libffi import CDLL [as 别名]
# 或者: from pypy.rlib.libffi.CDLL import getfunc [as 别名]
    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,代码行数:30,代码来源:test_funcptr.py

示例2: test_by_ordinal

# 需要导入模块: from pypy.rlib.libffi import CDLL [as 别名]
# 或者: from pypy.rlib.libffi.CDLL import getfunc [as 别名]
 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,代码行数:16,代码来源:test_funcptr.py

示例3: test_void_result

# 需要导入模块: from pypy.rlib.libffi import CDLL [as 别名]
# 或者: from pypy.rlib.libffi.CDLL import getfunc [as 别名]
 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,代码行数:16,代码来源:test_funcptr.py

示例4: test_convert_unicode_to_unichar_p

# 需要导入模块: from pypy.rlib.libffi import CDLL [as 别名]
# 或者: from pypy.rlib.libffi.CDLL import getfunc [as 别名]
 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,代码行数:29,代码来源:test_funcptr.py

示例5: test_typed_pointer_args

# 需要导入模块: from pypy.rlib.libffi import CDLL [as 别名]
# 或者: from pypy.rlib.libffi.CDLL import getfunc [as 别名]
    def test_typed_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

        libfoo = CDLL(self.libfoo_name)
        intptr = types.Pointer(types.sint)
        get_dummy = libfoo.getfunc('get_dummy', [], types.sint)
        get_dummy_ptr = libfoo.getfunc('get_dummy_ptr', [], intptr)
        set_val_to_ptr = libfoo.getfunc('set_val_to_ptr', [intptr, types.sint], types.void)
        assert get_dummy() == 0
        ptr = get_dummy_ptr()
        set_val_to_ptr(ptr, 123)
        assert get_dummy() == 123
        set_val_to_ptr(ptr, 0)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:20,代码来源:test_funcptr.py

示例6: test_pointer_args

# 需要导入模块: from pypy.rlib.libffi import CDLL [as 别名]
# 或者: from pypy.rlib.libffi.CDLL import getfunc [as 别名]
 def test_pointer_args(self):
     """
         extern int dummy; // defined in test_void_result 
         DLLEXPORT int* get_dummy_ptr() { return &dummy; }
         DLLEXPORT void set_val_to_ptr(int* ptr, int val) { *ptr = val; }
     """
     from _ffi import CDLL, types
     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()
     set_val_to_ptr(ptr, 123)
     assert get_dummy() == 123
     set_val_to_ptr(ptr, 0)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:20,代码来源:test_funcptr.py

示例7: test_libload_None

# 需要导入模块: from pypy.rlib.libffi import CDLL [as 别名]
# 或者: from pypy.rlib.libffi.CDLL import getfunc [as 别名]
 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,代码行数:11,代码来源:test_funcptr.py

示例8: test_huge_pointer_args

# 需要导入模块: from pypy.rlib.libffi import CDLL [as 别名]
# 或者: from pypy.rlib.libffi.CDLL import getfunc [as 别名]
 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,代码行数:12,代码来源:test_funcptr.py

示例9: test_calling_convention3

# 需要导入模块: from pypy.rlib.libffi import CDLL [as 别名]
# 或者: from pypy.rlib.libffi.CDLL import getfunc [as 别名]
 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,代码行数:12,代码来源:test_funcptr.py

示例10: test_int_args

# 需要导入模块: from pypy.rlib.libffi import CDLL [as 别名]
# 或者: from pypy.rlib.libffi.CDLL import getfunc [as 别名]
 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,代码行数:13,代码来源:test__ffi.py

示例11: test_char_args

# 需要导入模块: from pypy.rlib.libffi import CDLL [as 别名]
# 或者: from pypy.rlib.libffi.CDLL import getfunc [as 别名]
 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,代码行数:14,代码来源:test_funcptr.py

示例12: test_signed_byte_args

# 需要导入模块: from pypy.rlib.libffi import CDLL [as 别名]
# 或者: from pypy.rlib.libffi.CDLL import getfunc [as 别名]
 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,代码行数:15,代码来源:test_funcptr.py

示例13: test_single_float_args

# 需要导入模块: from pypy.rlib.libffi import CDLL [as 别名]
# 或者: from pypy.rlib.libffi.CDLL import getfunc [as 别名]
 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,代码行数:15,代码来源:test_funcptr.py

示例14: test_unsigned_byte_args

# 需要导入模块: from pypy.rlib.libffi import CDLL [as 别名]
# 或者: from pypy.rlib.libffi.CDLL import getfunc [as 别名]
 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,代码行数:15,代码来源:test_funcptr.py

示例15: test_unsigned_short_args

# 需要导入模块: from pypy.rlib.libffi import CDLL [as 别名]
# 或者: from pypy.rlib.libffi.CDLL import getfunc [as 别名]
 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,代码行数:15,代码来源:test_funcptr.py


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