Back to index

python3.2  3.2.2
Public Member Functions
ctypes.test.test_incomplete.MyTestCase Class Reference

The incomplete pointer example from the tutorial. More...

List of all members.

Public Member Functions

def test_incomplete_example

Detailed Description

The incomplete pointer example from the tutorial.

Definition at line 9 of file test_incomplete.py.


Member Function Documentation

Definition at line 11 of file test_incomplete.py.

00011 
00012     def test_incomplete_example(self):
00013         lpcell = POINTER("cell")
00014         class cell(Structure):
00015             _fields_ = [("name", c_char_p),
00016                         ("next", lpcell)]
00017 
00018         SetPointerType(lpcell, cell)
00019 
00020         c1 = cell()
00021         c1.name = b"foo"
00022         c2 = cell()
00023         c2.name = b"bar"
00024 
00025         c1.next = pointer(c2)
00026         c2.next = pointer(c1)
00027 
00028         p = c1
00029 
00030         result = []
00031         for i in range(8):
00032             result.append(p.name)
00033             p = p.next[0]
00034         self.assertEqual(result, [b"foo", b"bar"] * 4)
00035 
00036         # to not leak references, we must clean _pointer_type_cache
00037         from ctypes import _pointer_type_cache
00038         del _pointer_type_cache[cell]

Here is the call graph for this function:


The documentation for this class was generated from the following file: