Commit 5225e53d authored by Robert Bradshaw's avatar Robert Bradshaw

sizeof() works on cdef attributes and cimported types

parent e9cbbf22
...@@ -3086,6 +3086,20 @@ class SizeofTypeNode(SizeofNode): ...@@ -3086,6 +3086,20 @@ class SizeofTypeNode(SizeofNode):
subexprs = [] subexprs = []
def analyse_types(self, env): def analyse_types(self, env):
# we may have incorrectly interpreted a dotted name as a type rather than an attribute
# this could be better handled by more uniformly treating types as runtime-available objects
if self.base_type.module_path:
path = self.base_type.module_path
obj = env.lookup(path[0])
if obj.as_module is None:
operand = NameNode(pos=self.pos, name=path[0])
for attr in path[1:]:
operand = AttributeNode(pos=self.pos, obj=operand, attribute=attr)
operand = AttributeNode(pos=self.pos, obj=operand, attribute=self.base_type.name)
self.operand = operand
self.__class__ = SizeofVarNode
self.analyse_types(env)
return
base_type = self.base_type.analyse(env) base_type = self.base_type.analyse(env)
_, arg_type = self.declarator.analyse(base_type, env) _, arg_type = self.declarator.analyse(base_type, env)
self.arg_type = arg_type self.arg_type = arg_type
......
cdef extern from "Python.h":
ctypedef struct PyTypeObject:
pass
ctypedef struct PyObject:
Py_ssize_t ob_refcnt
PyTypeObject *ob_type
cdef extern from "longintrepr.h":
cdef struct _longobject:
int ob_refcnt
PyTypeObject *ob_type
int ob_size
unsigned int *ob_digit
def test(temp = long(0)):
cdef _longobject *l
l = <_longobject *> temp
print sizeof(l.ob_size)
print sizeof(l.ob_digit[0])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment