Created
May 7, 2013 21:44
-
-
Save o11c/5536409 to your computer and use it in GitHub Desktop.
fragment of core.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Type: | |
def __new__(cls, raw, context): | |
''' Deeply magic wrapper that constructs a Type from a C Type*. | |
It will always return the same object as long as it exists, | |
which will actually be an instance of a subclass. | |
''' | |
assert isinstance(raw, _core.Type) | |
assert isinstance(context, Context) | |
assert cls == Type # subclasses must override it | |
if not raw: | |
return None | |
raw_ptr = _c.pointer_value(raw) | |
try: | |
return context.type_cache[raw_ptr] | |
except KeyError: | |
pass | |
kind = _core.GetTypeKind(raw) | |
self = object.__new__(Type.kind_type_map[kind]) | |
context.type_cache[raw_ptr] = self | |
self._raw = raw | |
self._context = context | |
return self |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment