本文整理汇总了Python中ctypes.POINTER.from_param方法的典型用法代码示例。如果您正苦于以下问题:Python POINTER.from_param方法的具体用法?Python POINTER.from_param怎么用?Python POINTER.from_param使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ctypes.POINTER
的用法示例。
在下文中一共展示了POINTER.from_param方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_byref_pointer
# 需要导入模块: from ctypes import POINTER [as 别名]
# 或者: from ctypes.POINTER import from_param [as 别名]
def test_byref_pointer(self):
from ctypes import c_short, c_uint, c_int, c_long, pointer, POINTER, byref
LPINT = POINTER(c_int)
LPINT.from_param(byref(c_int(42)))
self.assertRaises(TypeError, LPINT.from_param, byref(c_short(22)))
if c_int != c_long:
self.assertRaises(TypeError, LPINT.from_param, byref(c_long(22)))
self.assertRaises(TypeError, LPINT.from_param, byref(c_uint(22)))
示例2: test_byref_pointerpointer
# 需要导入模块: from ctypes import POINTER [as 别名]
# 或者: from ctypes.POINTER import from_param [as 别名]
def test_byref_pointerpointer(self):
# See above
from ctypes import c_short, c_uint, c_int, c_long, pointer, POINTER, byref
LPLPINT = POINTER(POINTER(c_int))
LPLPINT.from_param(byref(pointer(c_int(42))))
raises(TypeError, LPLPINT.from_param, byref(pointer(c_short(22))))
if c_int != c_long:
raises(TypeError, LPLPINT.from_param, byref(pointer(c_long(22))))
raises(TypeError, LPLPINT.from_param, byref(pointer(c_uint(22))))
示例3: test_array_pointers
# 需要导入模块: from ctypes import POINTER [as 别名]
# 或者: from ctypes.POINTER import from_param [as 别名]
def test_array_pointers(self):
from ctypes import c_short, c_uint, c_int, c_long, POINTER
INTARRAY = c_int * 3
ia = INTARRAY()
self.assertEqual(len(ia), 3)
self.assertEqual([ ia[i] for i in range(3) ], [0, 0, 0])
LPINT = POINTER(c_int)
LPINT.from_param((c_int * 3)())
self.assertRaises(TypeError, LPINT.from_param, c_short * 3)
self.assertRaises(TypeError, LPINT.from_param, c_long * 3)
self.assertRaises(TypeError, LPINT.from_param, c_uint * 3)
示例4: test_byref_pointer
# 需要导入模块: from ctypes import POINTER [as 别名]
# 或者: from ctypes.POINTER import from_param [as 别名]
def test_byref_pointer(self):
# The from_param class method of POINTER(typ) classes accepts what is
# returned by byref(obj), it type(obj) == typ
from ctypes import c_short, c_uint, c_int, c_long, pointer, POINTER, byref
LPINT = POINTER(c_int)
LPINT.from_param(byref(c_int(42)))
self.assertRaises(TypeError, LPINT.from_param, byref(c_short(22)))
if c_int != c_long:
self.assertRaises(TypeError, LPINT.from_param, byref(c_long(22)))
self.assertRaises(TypeError, LPINT.from_param, byref(c_uint(22)))
示例5: test_int_pointers
# 需要导入模块: from ctypes import POINTER [as 别名]
# 或者: from ctypes.POINTER import from_param [as 别名]
def test_int_pointers(self):
from ctypes import c_short, c_uint, c_int, c_long, POINTER, pointer
LPINT = POINTER(c_int)
x = LPINT.from_param(pointer(c_int(42)))
self.assertEqual(x.contents.value, 42)
self.assertEqual(LPINT(c_int(42)).contents.value, 42)
self.assertEqual(LPINT.from_param(None), None)
if c_int != c_long:
self.assertRaises(TypeError, LPINT.from_param, pointer(c_long(42)))
self.assertRaises(TypeError, LPINT.from_param, pointer(c_uint(42)))
self.assertRaises(TypeError, LPINT.from_param, pointer(c_short(42)))
return
示例6: test_array_pointers
# 需要导入模块: from ctypes import POINTER [as 别名]
# 或者: from ctypes.POINTER import from_param [as 别名]
def test_array_pointers(self):
from ctypes import c_short, c_uint, c_int, c_long, POINTER
INTARRAY = c_int * 3
ia = INTARRAY()
self.assertEqual(len(ia), 3)
self.assertEqual([ia[i] for i in range(3)], [0, 0, 0])
# Pointers are only compatible with arrays containing items of
# the same type!
LPINT = POINTER(c_int)
LPINT.from_param((c_int*3)())
self.assertRaises(TypeError, LPINT.from_param, c_short*3)
self.assertRaises(TypeError, LPINT.from_param, c_long*3)
self.assertRaises(TypeError, LPINT.from_param, c_uint*3)
示例7: test_int_pointers
# 需要导入模块: from ctypes import POINTER [as 别名]
# 或者: from ctypes.POINTER import from_param [as 别名]
def test_int_pointers(self):
from ctypes import c_short, c_uint, c_int, c_long, POINTER, pointer
LPINT = POINTER(c_int)
## p = pointer(c_int(42))
## x = LPINT.from_param(p)
x = LPINT.from_param(pointer(c_int(42)))
assert x.contents.value == 42
assert LPINT(c_int(42)).contents.value == 42
assert not LPINT.from_param(None)
if c_int != c_long:
raises(TypeError, LPINT.from_param, pointer(c_long(42)))
raises(TypeError, LPINT.from_param, pointer(c_uint(42)))
raises(TypeError, LPINT.from_param, pointer(c_short(42)))
示例8: test_int_pointers
# 需要导入模块: from ctypes import POINTER [as 别名]
# 或者: from ctypes.POINTER import from_param [as 别名]
def test_int_pointers(self):
from ctypes import c_short, c_uint, c_int, c_long, POINTER, pointer
LPINT = POINTER(c_int)
## p = pointer(c_int(42))
## x = LPINT.from_param(p)
x = LPINT.from_param(pointer(c_int(42)))
self.assertEqual(x.contents.value, 42)
self.assertEqual(LPINT(c_int(42)).contents.value, 42)
if not due_to_ironpython_bug("http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=24755"):
self.assertEqual(LPINT.from_param(None), None)
if c_int != c_long:
self.assertRaises(TypeError, LPINT.from_param, pointer(c_long(42)))
self.assertRaises(TypeError, LPINT.from_param, pointer(c_uint(42)))
self.assertRaises(TypeError, LPINT.from_param, pointer(c_short(42)))
示例9: test_pointer_subclasses
# 需要导入模块: from ctypes import POINTER [as 别名]
# 或者: from ctypes.POINTER import from_param [as 别名]
def test_pointer_subclasses(self):
from ctypes import POINTER, c_void_p
Void_pp = POINTER(c_void_p)
class My_void_p(c_void_p):
pass
My_void_pp = POINTER(My_void_p)
o = My_void_pp()
assert Void_pp.from_param(o) is o
示例10: _POINTER
# 需要导入模块: from ctypes import POINTER [as 别名]
# 或者: from ctypes.POINTER import from_param [as 别名]
def _POINTER(cls):
cls = POINTER(cls)
cls.from_param = classmethod(allow_void_p_param(cls.from_param))
cls.get_void_p = get_void_p
return cls
示例11: _RAMPPTR
# 需要导入模块: from ctypes import POINTER [as 别名]
# 或者: from ctypes.POINTER import from_param [as 别名]
def _RAMPPTR(cls):
cls = POINTER(cls)
cls.from_param = classmethod(cast_from_tuple(cls.from_param))
return cls