@@ -97,7 +97,7 @@ def __validate_ordinal(d):
97
97
ordinal = None
98
98
99
99
if ordinal != d ['ordinal' ]:
100
- raise Exception ("'ordinal' invalid value: '%s'" % d ['ordinal' ])
100
+ raise Exception ("'ordinal' invalid value: '%s'" % d ['ordinal' ])
101
101
102
102
def __validate_version (d , prefix = "" , base_version = default_version ):
103
103
if 'version' in d :
@@ -333,7 +333,7 @@ def __validate_params(d, tags):
333
333
334
334
if item ['type' ].endswith ("flag_t" ):
335
335
raise Exception (prefix + "'type' must not be '*_flag_t': %s" % item ['type' ])
336
-
336
+
337
337
if type_traits .is_pointer (item ['type' ]) and "_handle_t" in item ['type' ] and "[in]" in item ['desc' ]:
338
338
if not param_traits .is_range (item ):
339
339
raise Exception (prefix + "handle type must include a range(start, end) as part of 'desc'" )
@@ -342,11 +342,11 @@ def __validate_params(d, tags):
342
342
if ver < max_ver :
343
343
raise Exception (prefix + "'version' must be increasing: %s" % item ['version' ])
344
344
max_ver = ver
345
-
345
+
346
346
def __validate_union_tag (d ):
347
347
if d .get ('tag' ) is None :
348
348
raise Exception (f"{ d ['name' ]} must include a 'tag' part of the union." )
349
-
349
+
350
350
try :
351
351
if 'type' not in d :
352
352
raise Exception ("every document must have 'type'" )
@@ -466,7 +466,7 @@ def __filter_desc(d):
466
466
return d
467
467
468
468
flt = []
469
- type = d ['type' ]
469
+ type = d ['type' ]
470
470
if 'enum' == type :
471
471
for e in d ['etors' ]:
472
472
ver = float (e .get ('version' , default_version ))
@@ -706,58 +706,54 @@ def _append(lst, key, val):
706
706
if val and val not in rets [idx ][key ]:
707
707
rets [idx ][key ].append (val )
708
708
709
+ def append_nullchecks (param , accessor : str ):
710
+ if type_traits .is_pointer (param ['type' ]):
711
+ _append (rets , "$X_RESULT_ERROR_INVALID_NULL_POINTER" , "`NULL == %s`" % accessor )
712
+
713
+ elif type_traits .is_funcptr (param ['type' ], meta ):
714
+ _append (rets , "$X_RESULT_ERROR_INVALID_NULL_POINTER" , "`NULL == %s`" % accessor )
715
+
716
+ elif type_traits .is_handle (param ['type' ]) and not type_traits .is_ipc_handle (item ['type' ]):
717
+ _append (rets , "$X_RESULT_ERROR_INVALID_NULL_HANDLE" , "`NULL == %s`" % accessor )
718
+
719
+ def append_enum_checks (param , accessor : str ):
720
+ ptypename = type_traits .base (param ['type' ])
721
+
722
+ prefix = "`"
723
+ if param_traits .is_optional (item ):
724
+ prefix = "`NULL != %s && " % item ['name' ]
725
+
726
+ if re .match (r"stype" , param ['name' ]):
727
+ _append (rets , "$X_RESULT_ERROR_UNSUPPORTED_VERSION" , prefix + "%s != %s`" % (re .sub (r"(\$\w)_(.*)_t.*" , r"\1_STRUCTURE_TYPE_\2" , typename ).upper (), accessor ))
728
+ else :
729
+ if type_traits .is_flags (param ['type' ]) and 'bit_mask' in meta ['enum' ][ptypename ].keys ():
730
+ _append (rets , "$X_RESULT_ERROR_INVALID_ENUMERATION" , prefix + "%s & %s`" % (ptypename .upper ()[:- 2 ]+ "_MASK" , accessor ))
731
+ else :
732
+ _append (rets , "$X_RESULT_ERROR_INVALID_ENUMERATION" , prefix + "%s < %s`" % (meta ['enum' ][ptypename ]['max' ], accessor ))
733
+
709
734
# generate results based on parameters
710
735
for item in obj ['params' ]:
711
736
if param_traits .is_nocheck (item ):
712
737
continue
713
738
714
739
if not param_traits .is_optional (item ):
740
+ append_nullchecks (item , item ['name' ])
741
+
742
+ if type_traits .is_enum (item ['type' ], meta ) and not type_traits .is_pointer (item ['type' ]):
743
+ append_enum_checks (item , item ['name' ])
744
+
745
+ if type_traits .is_descriptor (item ['type' ]) or type_traits .is_properties (item ['type' ]):
715
746
typename = type_traits .base (item ['type' ])
747
+ # walk each entry in the desc for pointers and enums
748
+ for i , m in enumerate (meta ['struct' ][typename ]['members' ]):
749
+ if param_traits .is_nocheck (m ):
750
+ continue
751
+
752
+ if not param_traits .is_optional (m ):
753
+ append_nullchecks (m , "%s->%s" % (item ['name' ], m ['name' ]))
716
754
717
- if type_traits .is_pointer (item ['type' ]):
718
- _append (rets , "$X_RESULT_ERROR_INVALID_NULL_POINTER" , "`NULL == %s`" % item ['name' ])
719
-
720
- elif type_traits .is_funcptr (item ['type' ], meta ):
721
- _append (rets , "$X_RESULT_ERROR_INVALID_NULL_POINTER" , "`NULL == %s`" % item ['name' ])
722
-
723
- elif type_traits .is_handle (item ['type' ]) and not type_traits .is_ipc_handle (item ['type' ]):
724
- _append (rets , "$X_RESULT_ERROR_INVALID_NULL_HANDLE" , "`NULL == %s`" % item ['name' ])
725
-
726
- elif type_traits .is_enum (item ['type' ], meta ):
727
- if type_traits .is_flags (item ['type' ]) and 'bit_mask' in meta ['enum' ][typename ].keys ():
728
- _append (rets , "$X_RESULT_ERROR_INVALID_ENUMERATION" , "`%s & %s`" % (typename .upper ()[:- 2 ]+ "_MASK" , item ['name' ]))
729
- else :
730
- _append (rets , "$X_RESULT_ERROR_INVALID_ENUMERATION" , "`%s < %s`" % (meta ['enum' ][typename ]['max' ], item ['name' ]))
731
-
732
- if type_traits .is_descriptor (item ['type' ]):
733
- # walk each entry in the desc for pointers and enums
734
- for i , m in enumerate (meta ['struct' ][typename ]['members' ]):
735
- if param_traits .is_nocheck (m ):
736
- continue
737
- mtypename = type_traits .base (m ['type' ])
738
-
739
- if type_traits .is_pointer (m ['type' ]) and not param_traits .is_optional ({'desc' : m ['desc' ]}):
740
- _append (rets ,
741
- "$X_RESULT_ERROR_INVALID_NULL_POINTER" ,
742
- "`NULL == %s->%s`" % (item ['name' ], m ['name' ]))
743
-
744
- elif type_traits .is_enum (m ['type' ], meta ):
745
- if re .match (r"stype" , m ['name' ]):
746
- _append (rets , "$X_RESULT_ERROR_UNSUPPORTED_VERSION" , "`%s != %s->stype`" % (re .sub (r"(\$\w)_(.*)_t.*" , r"\1_STRUCTURE_TYPE_\2" , typename ).upper (), item ['name' ]))
747
- else :
748
- if type_traits .is_flags (m ['type' ]) and 'bit_mask' in meta ['enum' ][mtypename ].keys ():
749
- _append (rets , "$X_RESULT_ERROR_INVALID_ENUMERATION" , "`%s & %s->%s`" % (mtypename .upper ()[:- 2 ]+ "_MASK" , item ['name' ], m ['name' ]))
750
- else :
751
- _append (rets , "$X_RESULT_ERROR_INVALID_ENUMERATION" , "`%s < %s->%s`" % (meta ['enum' ][mtypename ]['max' ], item ['name' ], m ['name' ]))
752
-
753
- elif type_traits .is_properties (item ['type' ]):
754
- # walk each entry in the properties
755
- for i , m in enumerate (meta ['struct' ][typename ]['members' ]):
756
- if param_traits .is_nocheck (m ):
757
- continue
758
- if type_traits .is_enum (m ['type' ], meta ):
759
- if re .match (r"stype" , m ['name' ]):
760
- _append (rets , "$X_RESULT_ERROR_UNSUPPORTED_VERSION" , "`%s != %s->stype`" % (re .sub (r"(\$\w)_(.*)_t.*" , r"\1_STRUCTURE_TYPE_\2" , typename ).upper (), item ['name' ]))
755
+ if type_traits .is_enum (m ['type' ], meta ) and not type_traits .is_pointer (m ['type' ]):
756
+ append_enum_checks (m , "%s->%s" % (item ['name' ], m ['name' ]))
761
757
762
758
# finally, append all user entries
763
759
for item in obj .get ('returns' , []):
@@ -823,7 +819,7 @@ def _refresh_enum_meta(obj, meta):
823
819
## remove the existing meta records
824
820
if obj .get ('class' ):
825
821
meta ['class' ][obj ['class' ]]['enum' ].remove (obj ['name' ])
826
-
822
+
827
823
if meta ['enum' ].get (obj ['name' ]):
828
824
del meta ['enum' ][obj ['name' ]]
829
825
## re-generate meta
@@ -851,13 +847,13 @@ def _extend_enums(enum_extensions, specs, meta):
851
847
if not _validate_ext_enum_range (extension , matching_enum ):
852
848
raise Exception (f"Invalid enum values." )
853
849
matching_enum ['etors' ].extend (extension ['etors' ])
854
-
850
+
855
851
_refresh_enum_meta (matching_enum , meta )
856
852
857
853
## Sort the etors
858
854
value = - 1
859
855
def sort_etors (x ):
860
- nonlocal value
856
+ nonlocal value
861
857
value = _get_etor_value (x .get ('value' ), value )
862
858
return value
863
859
matching_enum ['etors' ] = sorted (matching_enum ['etors' ], key = sort_etors )
0 commit comments