@@ -980,7 +980,6 @@ class SizeOf(DefFunction):
980980 __rargs__ = ('intype' , 'stars' )
981981
982982 def __new__ (cls , intype , stars = None , ** kwargs ):
983- stars = stars or ''
984983 if not isinstance (intype , (str , ReservedWord )):
985984 ctype = dtype_to_ctype (intype )
986985 for k , v in ctypes_vector_mapper .items ():
@@ -990,15 +989,40 @@ def __new__(cls, intype, stars=None, **kwargs):
990989 else :
991990 intype = ctypes_to_cstr (ctype )
992991
993- newobj = super ().__new__ (cls , 'sizeof' , arguments = f'{ intype } { stars } ' , ** kwargs )
994- newobj .stars = stars
995- newobj .intype = intype
992+ stars = stars or ''
993+ if not all (c == '*' for c in str (stars )):
994+ raise ValueError ("`stars` must be a string of zero or more `*` characters" )
995+
996+ if not isinstance (intype , (str , ReservedWord )):
997+ intype = ctypes_vector_mapper [intype ].__name__
996998
997- return newobj
999+ return super (). __new__ ( cls , 'sizeof' , arguments = ( intype , stars ), ** kwargs )
9981000
9991001 @property
10001002 def args (self ):
1001- return super ().args [1 ]
1003+ return self ._arguments
1004+
1005+ @property
1006+ def intype (self ):
1007+ return self .arguments [0 ]
1008+
1009+ @cached_property
1010+ def ctype (self ):
1011+ for v in ctypes_vector_mapper .values ():
1012+ if str (self .intype ) == v .__name__ :
1013+ return v
1014+ return self .intype
1015+
1016+ @property
1017+ def stars (self ):
1018+ return self .arguments [1 ]
1019+
1020+ def __str__ (self ):
1021+ try :
1022+ intype = ctypes_to_cstr (self .ctype )
1023+ except TypeError :
1024+ intype = str (self .ctype )
1025+ return f"sizeof({ intype } { self .stars } )"
10021026
10031027
10041028def rfunc (func , item , * args ):
0 commit comments