test_values.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:zippy 作者: securesystemslab 项目源码 文件源码
def test_frozentable(self):
            # Python exports a PyImport_FrozenModules symbol. This is a
            # pointer to an array of struct _frozen entries.  The end of the
            # array is marked by an entry containing a NULL name and zero
            # size.

            # In standard Python, this table contains a __hello__
            # module, and a __phello__ package containing a spam
            # module.
            class struct_frozen(Structure):
                _fields_ = [("name", c_char_p),
                            ("code", POINTER(c_ubyte)),
                            ("size", c_int)]
            FrozenTable = POINTER(struct_frozen)

            ft = FrozenTable.in_dll(pydll, "PyImport_FrozenModules")
            # ft is a pointer to the struct_frozen entries:
            items = []
            for entry in ft:
                # This is dangerous. We *can* iterate over a pointer, but
                # the loop will not terminate (maybe with an access
                # violation;-) because the pointer instance has no size.
                if entry.name is None:
                    break
                items.append((entry.name, entry.size))
            import sys
            if sys.version_info[:2] >= (2, 3):
                expected = [("__hello__", 104), ("__phello__", -104), ("__phello__.spam", 104)]
            else:
                expected = [("__hello__", 100), ("__phello__", -100), ("__phello__.spam", 100)]
            self.assertEqual(items, expected)

            from ctypes import _pointer_type_cache
            del _pointer_type_cache[struct_frozen]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号